simplest stub

This commit is contained in:
Edward Emelianov 2024-05-30 21:08:33 +03:00
parent bfb659e234
commit 166ab97fe7
6 changed files with 116 additions and 15 deletions

BIN
F1:F103/FX3U/fx3u.bin Executable file

Binary file not shown.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 12.0.2, 2024-03-05T15:35:05. -->
<!-- Written by QtCreator 13.0.1, 2024-05-30T20:03:33. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -106,8 +106,8 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
@ -119,8 +119,8 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
@ -135,8 +135,8 @@
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
@ -155,6 +155,7 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>

View File

@ -77,7 +77,10 @@ int main(void){
char *str;
int g = usart_getline(&str);
if(g < 0) usart_send("USART IN buffer overflow!\n");
else if(g > 0) cmd_parser(str);
else if(g > 0){
const char *ans = cmd_parser(str);
if(ans) usart_send(ans);
}
}
return 0;
}

View File

@ -28,6 +28,7 @@ flags_t flags = {
.can_monitor = 0
};
/*
static void printans(int res){
if(res) usart_send("OK");
else usart_send("FAIL");
@ -44,11 +45,96 @@ static void isetter(int(*fn)(int32_t), char* str){
if(str == getint(str, &d)) printans(FALSE);
else printans(fn(d));
}
*/
// parno - number of parameter (or -1); cargs - string with arguments (after '=') (==NULL for getter), iarg - integer argument
static int goodstub(const char *cmd, int parno, const char *carg, int32_t iarg){
usart_send("cmd="); usart_send(cmd);
usart_send(", parno="); usart_send(i2str(parno));
usart_send(", args="); usart_send(carg);
usart_send(", intarg="); usart_send(i2str(iarg)); newline();
return RET_GOOD;
}
typedef struct{
int (*fn)(const char*, int, const char*, int32_t);
const char *cmd;
const char *help;
} commands;
static commands cmdlist[] = {
{goodstub, "stub", "simple stub"},
{NULL, "Different commands", NULL},
// {adcval, "ADC", "get ADCx value (without x - for all)"},
// {adcvoltage, "ADCv", "get ADCx voltage (without x - for all)"},
// {mcut, "mcut", "get MCU temperature"},
{NULL, NULL, NULL}
};
static void printhelp(){
commands *c = cmdlist;
usart_send("https://github.com/eddyem/stm32samples/tree/master/F1:F103/FX3U#" BUILD_NUMBER " @ " BUILD_DATE "\n");
while(c->cmd){
if(!c->fn){ // header
usart_send("\n ");
usart_send(c->cmd);
usart_putchar(':');
}else{
usart_send(c->cmd);
usart_send(" - ");
usart_send(c->help);
}
newline();
++c;
}
}
/**
* @brief parsecmd - parse text commands over RS-232
* @param str - input string
* @return answer code
*/
static int parsecmd(const char *str){
char cmd[CMD_MAXLEN + 1];
//USB_sendstr("cmd="); USB_sendstr(str); USB_sendstr("__\n");
if(!str || !*str) return RET_CMDNOTFOUND;
int i = 0;
while(*str > '@' && i < CMD_MAXLEN){ cmd[i++] = *str++; }
cmd[i] = 0;
int parno = -1;
int32_t iarg = __INT32_MAX__;
if(*str){
uint32_t N;
const char *nxt = getnum(str, &N);
if(nxt != str) parno = (int) N;
str = strchr(str, '=');
if(str){
str = omit_spaces(++str);
getint(str, &iarg);
}
}else str = NULL;
commands *c = cmdlist;
while(c->cmd){
if(strcmp(c->cmd, cmd) == 0){
if(!c->fn) return RET_CMDNOTFOUND;
return c->fn(cmd, parno, str, iarg);
}
++c;
}
return RET_CMDNOTFOUND;
}
/**
* @brief cmd_parser - command parsing
* @param txt - buffer with commands & data
*/
void cmd_parser(char *txt){
(void)txt;
const char *cmd_parser(const char *txt){
int ret = parsecmd(txt);
switch(ret){
case RET_WRONGPARNO: return "Wrong parameter number\n"; break;
case RET_CMDNOTFOUND: printhelp(); return NULL; break;
case RET_WRONGARG: return "Wrong command parameters\n"; break;
case RET_GOOD: return NULL; break;
default: return "FAIL\n"; break;
}
}

View File

@ -21,7 +21,19 @@
#include <stm32f1.h>
#include "hardware.h"
#define BUFSZ (64)
#ifndef _U_
#define _U_ __attribute__((__unused__))
#endif
#define CMD_MAXLEN (32)
enum{
RET_WRONGPARNO = -3, // wrong parameter number
RET_CMDNOTFOUND = -2, // command not found
RET_WRONGARG = -1, // wrong argument
RET_GOOD = 0, // all OK
RET_BAD = 1 // something wrong
};
typedef struct{
uint32_t can_monitor : 1;
@ -36,5 +48,4 @@ extern flags_t flags;
#define DBG(str)
#endif
void cmd_parser(char *buf);
const char *cmd_parser(const char *txt);

View File

@ -1,2 +1,2 @@
#define BUILD_NUMBER "5"
#define BUILD_DATE "2024-05-29"
#define BUILD_NUMBER "20"
#define BUILD_DATE "2024-05-30"