device configuration prepared

This commit is contained in:
Wolfgang Hottgenroth 2020-12-01 12:20:02 +01:00
parent 24f2d0a01d
commit 0ed710e652
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -43,7 +43,7 @@ typedef struct {
} cmd_t; } cmd_t;
static void sendString(char *buf) { static void sendString(const char *buf) {
send(CMD_SOCK, (uint8_t*)buf, strlen(buf)); send(CMD_SOCK, (uint8_t*)buf, strlen(buf));
} }
@ -163,6 +163,13 @@ static bool showConfigCmd(uint8_t argc, char **args) {
return retCode; return retCode;
} }
static bool restartCmd(uint8_t argc, char **args) {
HAL_NVIC_SystemReset();
// you want come here ...
return true;
}
const static cmd_t COMMANDS[] = { const static cmd_t COMMANDS[] = {
{ .name = "globalStats", .cmdFunc = globalStatsCmd, { .name = "globalStats", .cmdFunc = globalStatsCmd,
.help = \ .help = \
@ -199,6 +206,11 @@ const static cmd_t CONFIG_COMMANDS[] = {
.help = \ .help = \
"show ................................. Show the configuration\n\r" "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 } { .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" \ "config ............................... Enter configuration mode\n\r" \
"disable .............................. Disable admin/config 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 GOODBYE_MSG[] = "Good bye\n\r";
const static char OK_MSG[] = "OK\n\r"; const static char OK_MSG[] = "OK\n\r";
const static char FAILED_MSG[] = "Failed\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; messageToSend = (uint8_t*)GOODBYE_MSG;
retCode = -1; retCode = -1;
} else if (0 == strcmp(cmd, "help")) { } 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; uint8_t cmdIdx = 0;
while (true) { while (true) {
cmd_t command = commands[cmdIdx]; cmd_t command = commands[cmdIdx];
if (0 == strcmp("END_OF_CMDS", command.name)) { if (0 == strcmp("END_OF_CMDS", command.name)) {
break; break;
} }
send(CMD_SOCK, (uint8_t*)command.help, strlen(command.help)); sendString(command.help);
cmdIdx++; cmdIdx++;
} }
messageToSend = NULL; messageToSend = NULL;
@ -278,6 +300,7 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
} else if (0 == strcmp(cmd, "disable")) { } else if (0 == strcmp(cmd, "disable")) {
coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode"); coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode");
adminMode = false; adminMode = false;
configMode = false;
retCode = 3; retCode = 3;
} else if (0 == strcmp(cmd, "config")) { } else if (0 == strcmp(cmd, "config")) {
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode"); coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");