cmd handler stuff

This commit is contained in:
Wolfgang Hottgenroth 2020-11-16 16:13:20 +01:00
parent ebfcba13bb
commit 06ee315f11
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -31,7 +31,7 @@ typedef enum {
} chState_t; } chState_t;
typedef bool (*cmdFunc_t)(char *cmdLine); typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
typedef struct { typedef struct {
bool requiredConfigMode; bool requiredConfigMode;
@ -42,13 +42,13 @@ typedef struct {
// clear statistics // clear statistics
bool clearCmd(char *cmdLine) { bool clearCmd(uint8_t argc, char **args) {
t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 }; t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 };
mbusCommSetStats(zeroedStats); mbusCommSetStats(zeroedStats);
return true; return true;
} }
bool globalStatsCmd(char *cmdLine) { bool globalStatsCmd(uint8_t argc, char **args) {
t_mbusCommStats *stats = mbusCommGetStats(); t_mbusCommStats *stats = mbusCommGetStats();
char buf[256]; char buf[256];
sprintf(buf, \ sprintf(buf, \
@ -103,9 +103,21 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
configMode = false; configMode = false;
} }
coloredMsg(LOG_YELLOW, "cec, cmdLine is %s", cmdLine);;
#define MAX_NUM_OF_ARGS 8
char *args[MAX_NUM_OF_TASKS];
uint8_t argc = 0;
char *inCmdLine = cmdLine;
do {
args[argc++] = strtok(inCmdLine, " ");
inCmdLine = NULL;
} while (args[argc - 1] != NULL);
char *cmd = args[0];
int8_t retCode = 0; int8_t retCode = 0;
char *cmd = strtok(cmdLine, " "); coloredMsg(LOG_YELLOW, "cec, cmd is %s, number of arguments %d", cmd, argc);
coloredMsg(LOG_YELLOW, "cec, cmdLine is %s, cmd is %s", cmdLine, cmd);
if (0 == strcmp(cmd, "quit")) { if (0 == strcmp(cmd, "quit")) {
messageToSend = GOODBYE_MSG; messageToSend = GOODBYE_MSG;
retCode = -1; retCode = -1;
@ -140,7 +152,7 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
if (command.requiredConfigMode && !configMode) { if (command.requiredConfigMode && !configMode) {
messageToSend = REQUIRES_CONFIG_MODE_MGS; messageToSend = REQUIRES_CONFIG_MODE_MGS;
} else { } else {
messageToSend = command.cmdFunc(cmd) ? OK_MSG : FAILED_MSG; messageToSend = command.cmdFunc(argc, args) ? OK_MSG : FAILED_MSG;
} }
} }
cmdIdx++; cmdIdx++;