rename config mode to admin mode

This commit is contained in:
Wolfgang Hottgenroth 2020-11-28 22:33:15 +01:00
parent 518abe4e1c
commit 76ff0d8e24
No known key found for this signature in database
GPG Key ID: 656C88C7C1734267

View File

@ -35,7 +35,7 @@ typedef enum {
typedef bool (*cmdFunc_t)(uint8_t argc, char **args); typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
typedef struct { typedef struct {
bool requiredConfigMode; bool requiredAdminMode;
char name[16]; char name[16];
char help[512]; char help[512];
cmdFunc_t cmdFunc; cmdFunc_t cmdFunc;
@ -106,18 +106,18 @@ bool loopEnableCmd(uint8_t argc, char **args) {
} }
const static cmd_t COMMANDS[] = { const static cmd_t COMMANDS[] = {
{ .requiredConfigMode = true, .name = "clear", .cmdFunc = clearCmd, { .requiredAdminMode = true, .name = "clear", .cmdFunc = clearCmd,
.help = \ .help = \
"clear ................................ Clears the global Meterbus\n\r" \ "clear ................................ Clears the global Meterbus\n\r" \
" statistics\n\r" \ " statistics\n\r" \
" Required configuration mode\n\r" " Required configuration mode\n\r"
}, },
{ .requiredConfigMode = true, .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd, { .requiredAdminMode = true, .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd,
.help = \ .help = \
"mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \ "mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \
" communication\n\r" " communication\n\r"
}, },
{ .requiredConfigMode = true, .name = "loopEnable", .cmdFunc = loopEnableCmd, { .requiredAdminMode = true, .name = "loopEnable", .cmdFunc = loopEnableCmd,
.help = \ .help = \
"loopEnable true|false ................ Enables or disables the loop.\n\r" \ "loopEnable true|false ................ Enables or disables the loop.\n\r" \
" Disable Meterbus communication\n\r" \ " Disable Meterbus communication\n\r" \
@ -125,12 +125,12 @@ const static cmd_t COMMANDS[] = {
" for a longer time, otherwise the\n\r" \ " for a longer time, otherwise the\n\r" \
" request will enable it again\n\r" " request will enable it again\n\r"
}, },
{ .requiredConfigMode = false, .name = "globalStats", .cmdFunc = globalStatsCmd, { .requiredAdminMode = false, .name = "globalStats", .cmdFunc = globalStatsCmd,
.help = \ .help = \
"globalStats .......................... Show the global statistics\n\r" \ "globalStats .......................... Show the global statistics\n\r" \
" counters requestCnt and errorCnt\n\r" " counters requestCnt and errorCnt\n\r"
}, },
{ .requiredConfigMode = false, .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL } { .requiredAdminMode = false, .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
}; };
@ -138,25 +138,25 @@ const static cmd_t COMMANDS[] = {
// returns -1 to close the connection // returns -1 to close the connection
// returns 1 to toggle to config mode // returns 1 to toggle to config mode
// returns 2 to toggle back to default mode // returns 2 to toggle back to default mode
int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) { int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetAdminMode) {
const static char HELP_MSG[] = \ const static char HELP_MSG[] = \
"Usage\n\r" \ "Usage\n\r" \
"\n\r" \ "\n\r" \
"help ................................. Show this help page\n\r" \ "help ................................. Show this help page\n\r" \
"quit ................................. Terminate the console session\n\r" \ "quit ................................. Terminate the console session\n\r" \
"enable ............................... Enable configuration mode\n\r" \ "enable ............................... Enable admin mode\n\r" \
"disable .............................. Disable configuration mode\n\r" \ "disable .............................. Disable admin mode\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";
const static char REQUIRES_CONFIG_MODE_MGS[] = "Not executed, requires config mode\n\r"; const static char REQUIRES_ADMIN_MODE_MGS[] = "Not executed, requires admin mode\n\r";
uint8_t *messageToSend = NULL; uint8_t *messageToSend = NULL;
static bool configMode = false; static bool adminMode = false;
if (resetConfigMode) { if (resetAdminMode) {
configMode = false; adminMode = false;
} }
coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);; coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);;
@ -193,12 +193,12 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
} }
messageToSend = NULL; messageToSend = NULL;
} else if (0 == strcmp(cmd, "enable")) { } else if (0 == strcmp(cmd, "enable")) {
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode"); coloredMsg(LOG_YELLOW, true, "ch cec enable admin mode");
configMode = true; adminMode = true;
retCode = 1; retCode = 1;
} else if (0 == strcmp(cmd, "disable")) { } else if (0 == strcmp(cmd, "disable")) {
coloredMsg(LOG_YELLOW, true, "ch cec disable config mode"); coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode");
configMode = false; adminMode = false;
retCode = 2; retCode = 2;
} else { } else {
uint8_t cmdIdx = 0; uint8_t cmdIdx = 0;
@ -208,8 +208,8 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
break; break;
} }
if (0 == strcmp(cmd, command.name)) { if (0 == strcmp(cmd, command.name)) {
if (command.requiredConfigMode && !configMode) { if (command.requiredAdminMode && !adminMode) {
messageToSend = (uint8_t*)REQUIRES_CONFIG_MODE_MGS; messageToSend = (uint8_t*)REQUIRES_ADMIN_MODE_MGS;
} else { } else {
messageToSend = command.cmdFunc(argc, args) ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG; messageToSend = command.cmdFunc(argc, args) ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG;
} }
@ -229,7 +229,7 @@ void cmdHandlerEngine(void *handle) {
static uint8_t receiveBuffer[256]; static uint8_t receiveBuffer[256];
static chState_t state = CH_INIT; static chState_t state = CH_INIT;
static bool resetConfigMode = false; static bool resetAdminMode = false;
static char banner[] = \ static char banner[] = \
"MBGW3\n\r" \ "MBGW3\n\r" \
@ -301,7 +301,7 @@ void cmdHandlerEngine(void *handle) {
resultSend = send(CMD_SOCK, (uint8_t*)banner, strlen(banner)); resultSend = send(CMD_SOCK, (uint8_t*)banner, strlen(banner));
coloredMsg(LOG_YELLOW, false, "ch che sent banner, send returns 0x%02x", resultSend); coloredMsg(LOG_YELLOW, false, "ch che sent banner, send returns 0x%02x", resultSend);
prompt = defaultPrompt; prompt = defaultPrompt;
resetConfigMode = true; resetAdminMode = true;
state = CH_PROMPT; state = CH_PROMPT;
} }
break; break;
@ -341,8 +341,8 @@ void cmdHandlerEngine(void *handle) {
receiveBuffer[strlen((char*)receiveBuffer) - 1] = 0; receiveBuffer[strlen((char*)receiveBuffer) - 1] = 0;
} }
coloredMsg(LOG_YELLOW, false, "ch che received: %s", receiveBuffer); coloredMsg(LOG_YELLOW, false, "ch che received: %s", receiveBuffer);
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetConfigMode); int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetAdminMode);
resetConfigMode = false; resetAdminMode = false;
switch (resCEC) { switch (resCEC) {
case 0: case 0:
state = CH_PROMPT; state = CH_PROMPT;