diff --git a/cube/User/Src/cmdHandler.c b/cube/User/Src/cmdHandler.c index 0bafd3d..a4626d3 100644 --- a/cube/User/Src/cmdHandler.c +++ b/cube/User/Src/cmdHandler.c @@ -31,7 +31,7 @@ typedef enum { } chState_t; -typedef bool (*cmdFunc_t)(char *cmdLine); +typedef bool (*cmdFunc_t)(uint8_t argc, char **args); typedef struct { bool requiredConfigMode; @@ -42,13 +42,13 @@ typedef struct { // clear statistics -bool clearCmd(char *cmdLine) { +bool clearCmd(uint8_t argc, char **args) { t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 }; mbusCommSetStats(zeroedStats); return true; } -bool globalStatsCmd(char *cmdLine) { +bool globalStatsCmd(uint8_t argc, char **args) { t_mbusCommStats *stats = mbusCommGetStats(); char buf[256]; sprintf(buf, \ @@ -103,9 +103,21 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) { 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; - char *cmd = strtok(cmdLine, " "); - coloredMsg(LOG_YELLOW, "cec, cmdLine is %s, cmd is %s", cmdLine, cmd); + coloredMsg(LOG_YELLOW, "cec, cmd is %s, number of arguments %d", cmd, argc); + if (0 == strcmp(cmd, "quit")) { messageToSend = GOODBYE_MSG; retCode = -1; @@ -140,7 +152,7 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) { if (command.requiredConfigMode && !configMode) { messageToSend = REQUIRES_CONFIG_MODE_MGS; } else { - messageToSend = command.cmdFunc(cmd) ? OK_MSG : FAILED_MSG; + messageToSend = command.cmdFunc(argc, args) ? OK_MSG : FAILED_MSG; } } cmdIdx++;