Continue to write USB protocol documentation and fix bugs in code.

This commit is contained in:
2024-08-16 12:37:11 +03:00
parent 018f0d4b33
commit b10fb37c58
19 changed files with 321 additions and 65 deletions

View File

@@ -170,14 +170,13 @@ static char *fnname(const char *cmd){
static const char *fhdr =
"int parsecmd(const char *str){\n\
char cmd[CMD_MAXLEN + 1];\n\
if(!str || !*str) return RET_CMDNOTFOUND;\n\
int i = 0;\n\
while(*str > '@' && i < CMD_MAXLEN){ cmd[i++] = *str++; }\n\
cmd[i] = 0;\n\
while(*str > '@' && i < CMD_MAXLEN){ lastcmd[i++] = *str++; }\n\
lastcmd[i] = 0;\n\
while(*str && *str <= ' ') ++str;\n\
char *args = (char*) str;\n\
uint32_t h = hashf(cmd);\n\
uint32_t h = hashf(lastcmd);\n\
switch(h){\n\n"
;
static const char *ffooter =
@@ -195,12 +194,15 @@ static const char *headercontent =
#endif\n\n\
#define CMD_MAXLEN (32)\n\n\
enum{\n\
RET_HELP = -3,\n\
RET_CMDNOTFOUND = -2,\n\
RET_WRONGCMD = -1,\n\
RET_BAD = 0,\n\
RET_GOOD = 1\n\
RET_GOOD = 0,\n\
RET_BAD = 1\n\
};\n\n\
int parsecmd(const char *cmdwargs);\n\n";
int parsecmd(const char *cmdwargs);\n\n\
extern char lastcmd[];\n\n";
static const char *sw =
" case CMD_%s:\n\
return fn_%s(h, args);\n\
@@ -213,7 +215,8 @@ static const char *srchdr =
#include \"%s\"\n\n\
#ifndef WAL\n\
#define WAL __attribute__ ((weak, alias (\"__f1\")))\n\
#endif\n\nstatic int __f1(uint32_t _U_ h, char _U_ *a){return 1;}\n\n"
#endif\n\nstatic int __f1(uint32_t _U_ h, char _U_ *a){return 1;}\n\n\
char lastcmd[CMD_MAXLEN + 1];\n\n"
;
static void build(strhash *H, int hno, int hlen){

View File

@@ -8,10 +8,10 @@
#define WAL __attribute__ ((weak, alias ("__f1")))
#endif
char lastcmd[CMD_MAXLEN + 1];
static int __f1(uint32_t _U_ h, char _U_ *a){return 1;}
char lastcmd[CMD_MAXLEN + 1];
int fn_abspos(uint32_t _U_ hash, char _U_ *args) WAL; // "abspos" (3056382221)
int fn_accel(uint32_t _U_ hash, char _U_ *args) WAL; // "accel" (1490521981)
@@ -76,6 +76,8 @@ int fn_gpio(uint32_t _U_ hash, char _U_ *args) WAL; // "gpio" (4286324660)
int fn_gpioconf(uint32_t _U_ hash, char _U_ *args) WAL; // "gpioconf" (1309721562)
int fn_help(uint32_t _U_ hash, char _U_ *args) WAL; // "help" (4288288686)
int fn_maxspeed(uint32_t _U_ hash, char _U_ *args) WAL; // "maxspeed" (1498078812)
int fn_maxsteps(uint32_t _U_ hash, char _U_ *args) WAL; // "maxsteps" (1506667002)
@@ -244,6 +246,9 @@ int parsecmd(const char *str){
case CMD_GPIOCONF:
return fn_gpioconf(h, args);
break;
case CMD_HELP:
return fn_help(h, args);
break;
case CMD_MAXSPEED:
return fn_maxspeed(h, args);
break;

View File

@@ -5,10 +5,11 @@
#define CMD_MAXLEN (32)
enum{
RET_HELP = -3,
RET_CMDNOTFOUND = -2,
RET_WRONGCMD = -1,
RET_BAD = 0,
RET_GOOD = 1
RET_GOOD = 0,
RET_BAD = 1
};
int parsecmd(const char *cmdwargs);
@@ -47,6 +48,7 @@ extern char lastcmd[];
#define CMD_GOTOZ (3178103736)
#define CMD_GPIO (4286324660)
#define CMD_GPIOCONF (1309721562)
#define CMD_HELP (4288288686)
#define CMD_MAXSPEED (1498078812)
#define CMD_MAXSTEPS (1506667002)
#define CMD_MCUT (4022718)

View File

@@ -30,6 +30,7 @@
"gotozN - find zero position & refresh counters\n"
"gpioconfN* - GS GPIO configuration (0 - PUin, 1 - PPout, 2 - ODout), N=0..2\n"
"gpioN* - GS GPIO values, N=0..2\n"
"help - print this help\n"
"maxspeedN - GS max speed (steps per sec)\n"
"maxstepsN - GS max steps (from zero ESW)\n"
"mcut - G MCU T\n"

View File

@@ -8,3 +8,5 @@ gcc hdr.c test.c strfunc.c -o test
./test "esw45 = some text"
./test "goto 55 = "
./test "stop 3256"
./test "mcut"

BIN
F3:F303/Multistepper/hashgen/test Executable file

Binary file not shown.

View File

@@ -7,9 +7,9 @@
static int noargs(uint32_t hash){
switch(hash){
case CMD_REBOOT: printf("REBOOT\n"); break;
case CMD_RESET: printf("REBOOT\n"); break;
case CMD_TIME: printf("TIME!\n"); break;
case CMD_TEMP: printf("Temp\n"); break;
case CMD_MCUT: printf("Temp\n"); break;
default: printf("Unknown hash 0x%x\n", hash); return 0;
}
return 1;
@@ -30,7 +30,7 @@ static int withparno(uint32_t hash, char *args){
switch(hash){
case CMD_ESW: fname = "ESW"; break;
case CMD_GOTO: fname = "GOTO"; break;
case CMD_POS: fname = "POS"; break;
case CMD_ABSPOS: fname = "ABSPOS"; break;
case CMD_STOP: fname = "STOP"; break;
default: fname = "unknown";
}

View File

@@ -30,6 +30,7 @@ goto
gotoz
gpioconf
gpio
help
maxspeed
maxsteps
mcut