From 0ed710e6529ddbdaed931b96834fe70d70f8369c Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 1 Dec 2020 12:20:02 +0100 Subject: [PATCH] device configuration prepared --- cube/User/Src/cmdHandler.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cube/User/Src/cmdHandler.c b/cube/User/Src/cmdHandler.c index 6bf45a8..5df35f3 100644 --- a/cube/User/Src/cmdHandler.c +++ b/cube/User/Src/cmdHandler.c @@ -43,7 +43,7 @@ typedef struct { } cmd_t; -static void sendString(char *buf) { +static void sendString(const char *buf) { send(CMD_SOCK, (uint8_t*)buf, strlen(buf)); } @@ -163,6 +163,13 @@ static bool showConfigCmd(uint8_t argc, char **args) { return retCode; } +static bool restartCmd(uint8_t argc, char **args) { + HAL_NVIC_SystemReset(); + // you want come here ... + return true; +} + + const static cmd_t COMMANDS[] = { { .name = "globalStats", .cmdFunc = globalStatsCmd, .help = \ @@ -199,6 +206,11 @@ const static cmd_t CONFIG_COMMANDS[] = { .help = \ "show ................................. Show the configuration\n\r" }, + { .name = "restart", .cmdFunc = restartCmd, + .help = \ + "restart .............................. Restart the system,\n\r" \ + " Required to reload config\n\r" + }, { .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL } }; @@ -218,6 +230,13 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) { "config ............................... Enter configuration mode\n\r" \ "disable .............................. Disable admin/config mode\n\r" \ ; + const static char CONFIG_INTRO_MSG[] = \ + "In configuration mode each command changing the configuration\n\r" \ + "will save changes directly to the EEPROM.\n\r" \ + "However, the system will only consider these changes after a\n\r" \ + "restart since only in this sitution the EEPROM is read.\n\r" \ + "\n\r" \ + ; const static char GOODBYE_MSG[] = "Good bye\n\r"; const static char OK_MSG[] = "OK\n\r"; const static char FAILED_MSG[] = "Failed\n\r"; @@ -260,14 +279,17 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) { messageToSend = (uint8_t*)GOODBYE_MSG; retCode = -1; } else if (0 == strcmp(cmd, "help")) { - send(CMD_SOCK, (uint8_t*)HELP_MSG, strlen(HELP_MSG)); + if (configMode) { + sendString(CONFIG_INTRO_MSG); + } + sendString(HELP_MSG); uint8_t cmdIdx = 0; while (true) { cmd_t command = commands[cmdIdx]; if (0 == strcmp("END_OF_CMDS", command.name)) { break; } - send(CMD_SOCK, (uint8_t*)command.help, strlen(command.help)); + sendString(command.help); cmdIdx++; } messageToSend = NULL; @@ -278,6 +300,7 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) { } else if (0 == strcmp(cmd, "disable")) { coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode"); adminMode = false; + configMode = false; retCode = 3; } else if (0 == strcmp(cmd, "config")) { coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");