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