cmd handler stuff
This commit is contained in:
@ -16,6 +16,22 @@ extern const uint8_t CMD_SOCK;
|
|||||||
|
|
||||||
const uint16_t cmdPort = 2000;
|
const uint16_t cmdPort = 2000;
|
||||||
|
|
||||||
|
|
||||||
|
// returns 0 to continue waiting for input
|
||||||
|
// returns -1 to close the connection
|
||||||
|
int8_t cmdExecuteCommand(uint8_t *cmd) {
|
||||||
|
const static uint8_t GOODBYE_MSG[] = "Good bye\n\r";
|
||||||
|
|
||||||
|
int8_t retCode = 0;
|
||||||
|
coloredMsg(LOG_YELLOW, "cec, cmd is %s", cmd);
|
||||||
|
if (0 == strcmp(cmd, "quit")) {
|
||||||
|
send(CMD_SOCK, GOODBYE_MSG, sizeof(GOODBYE_MSG));
|
||||||
|
retCode = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retCode;
|
||||||
|
}
|
||||||
|
|
||||||
void cmdHandlerEngine(void *handle) {
|
void cmdHandlerEngine(void *handle) {
|
||||||
static uint8_t receiveBuffer[256];
|
static uint8_t receiveBuffer[256];
|
||||||
|
|
||||||
@ -107,13 +123,16 @@ void cmdHandlerEngine(void *handle) {
|
|||||||
coloredMsg(LOG_YELLOW, "che, recv returns 0x%02x", resultRecv);
|
coloredMsg(LOG_YELLOW, "che, recv returns 0x%02x", resultRecv);
|
||||||
if (resultRecv > 0) {
|
if (resultRecv > 0) {
|
||||||
coloredMsg(LOG_YELLOW, "che, received: %s", receiveBuffer);
|
coloredMsg(LOG_YELLOW, "che, received: %s", receiveBuffer);
|
||||||
|
if (-1 == cmdExecuteCommand(receiveBuffer)) {
|
||||||
|
state = 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
coloredMsg(LOG_YELLOW, "che, client closing, close our end too");
|
coloredMsg(LOG_YELLOW, "che, close our end");
|
||||||
resultDisconnect = disconnect(CMD_SOCK);
|
resultDisconnect = disconnect(CMD_SOCK);
|
||||||
coloredMsg(LOG_YELLOW, "che, disconnect returns 0x%02x", resultDisconnect);
|
coloredMsg(LOG_YELLOW, "che, disconnect returns 0x%02x", resultDisconnect);
|
||||||
state = 6;
|
state = 6;
|
||||||
@ -135,8 +154,6 @@ void cmdHandlerEngine(void *handle) {
|
|||||||
schDel(cmdHandlerEngine, NULL);
|
schDel(cmdHandlerEngine, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
coloredMsg(LOG_YELLOW, "che, network not yet ready");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +110,6 @@ void mqttCommHandler(void *handle) {
|
|||||||
schAdd(mqttCommHandler, NULL, 60000, 100);
|
schAdd(mqttCommHandler, NULL, 60000, 100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
coloredMsg(LOG_YELLOW, "mqch, network not yet ready");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user