cmd handler stuff
This commit is contained in:
@ -30,14 +30,27 @@ typedef enum {
|
|||||||
|
|
||||||
// returns 0 to continue waiting for input
|
// returns 0 to continue waiting for input
|
||||||
// returns -1 to close the connection
|
// returns -1 to close the connection
|
||||||
int8_t cmdExecuteCommand(uint8_t *cmd) {
|
// returns 1 to toggle to config mode
|
||||||
|
// returns 2 to toggle back to default mode
|
||||||
|
int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) {
|
||||||
const static uint8_t GOODBYE_MSG[] = "Good bye\n\r";
|
const static uint8_t GOODBYE_MSG[] = "Good bye\n\r";
|
||||||
|
static bool configMode = false;
|
||||||
|
|
||||||
|
if (resetConfigMode) {
|
||||||
|
configMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
int8_t retCode = 0;
|
int8_t retCode = 0;
|
||||||
coloredMsg(LOG_YELLOW, "cec, cmd is %s", cmd);
|
coloredMsg(LOG_YELLOW, "cec, cmd is %s", cmd);
|
||||||
if (0 == strcmp(cmd, "quit")) {
|
if (0 == strcmp(cmd, "quit")) {
|
||||||
send(CMD_SOCK, GOODBYE_MSG, sizeof(GOODBYE_MSG));
|
send(CMD_SOCK, GOODBYE_MSG, sizeof(GOODBYE_MSG));
|
||||||
retCode = -1;
|
retCode = -1;
|
||||||
|
} else if (0 == strcmp(cmd, "enable")) {
|
||||||
|
configMode = true;
|
||||||
|
retCode = 1;
|
||||||
|
} else if (0 == strcmp(cmd, "disable")) {
|
||||||
|
configMode = false;
|
||||||
|
retCode = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retCode;
|
return retCode;
|
||||||
@ -47,6 +60,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 uint8_t banner[] = \
|
static uint8_t banner[] = \
|
||||||
"MBGW3\n\r" \
|
"MBGW3\n\r" \
|
||||||
@ -65,6 +79,7 @@ void cmdHandlerEngine(void *handle) {
|
|||||||
int32_t resultRecv;
|
int32_t resultRecv;
|
||||||
uint8_t resultDisconnect;
|
uint8_t resultDisconnect;
|
||||||
|
|
||||||
|
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case CH_INIT:
|
case CH_INIT:
|
||||||
@ -119,6 +134,7 @@ void cmdHandlerEngine(void *handle) {
|
|||||||
resultSend = send(CMD_SOCK, banner, strlen(banner));
|
resultSend = send(CMD_SOCK, banner, strlen(banner));
|
||||||
coloredMsg(LOG_YELLOW, "che, sent banner, send returns 0x%02x", resultSend);
|
coloredMsg(LOG_YELLOW, "che, sent banner, send returns 0x%02x", resultSend);
|
||||||
prompt = defaultPrompt;
|
prompt = defaultPrompt;
|
||||||
|
resetConfigMode = true;
|
||||||
state = CH_PROMPT;
|
state = CH_PROMPT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -160,10 +176,23 @@ void cmdHandlerEngine(void *handle) {
|
|||||||
receiveBuffer[strlen(receiveBuffer) - 1] = 0;
|
receiveBuffer[strlen(receiveBuffer) - 1] = 0;
|
||||||
}
|
}
|
||||||
coloredMsg(LOG_YELLOW, "che, received: %s", receiveBuffer);
|
coloredMsg(LOG_YELLOW, "che, received: %s", receiveBuffer);
|
||||||
if (-1 == cmdExecuteCommand(receiveBuffer)) {
|
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetConfigMode);
|
||||||
state = CH_DISCONNECT;
|
resetConfigMode = false;
|
||||||
} else {
|
switch (resCEC) {
|
||||||
state = CH_PROMPT;
|
case 0:
|
||||||
|
state = CH_PROMPT;
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
state = CH_DISCONNECT;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
prompt = elevatedPrompt;
|
||||||
|
state = CH_PROMPT;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
prompt = defaultPrompt;
|
||||||
|
state = CH_PROMPT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user