cmd handler stuff

This commit is contained in:
2020-11-16 14:07:29 +01:00
parent 873f26bf4d
commit d88b0726ab
2 changed files with 20 additions and 5 deletions

View File

@ -16,6 +16,22 @@ extern const uint8_t CMD_SOCK;
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) {
static uint8_t receiveBuffer[256];
@ -107,13 +123,16 @@ void cmdHandlerEngine(void *handle) {
coloredMsg(LOG_YELLOW, "che, recv returns 0x%02x", resultRecv);
if (resultRecv > 0) {
coloredMsg(LOG_YELLOW, "che, received: %s", receiveBuffer);
if (-1 == cmdExecuteCommand(receiveBuffer)) {
state = 5;
}
}
}
}
break;
case 5:
coloredMsg(LOG_YELLOW, "che, client closing, close our end too");
coloredMsg(LOG_YELLOW, "che, close our end");
resultDisconnect = disconnect(CMD_SOCK);
coloredMsg(LOG_YELLOW, "che, disconnect returns 0x%02x", resultDisconnect);
state = 6;
@ -135,8 +154,6 @@ void cmdHandlerEngine(void *handle) {
schDel(cmdHandlerEngine, NULL);
break;
}
} else {
coloredMsg(LOG_YELLOW, "che, network not yet ready");
}
}

View File

@ -110,8 +110,6 @@ void mqttCommHandler(void *handle) {
schAdd(mqttCommHandler, NULL, 60000, 100);
break;
}
} else {
coloredMsg(LOG_YELLOW, "mqch, network not yet ready");
}
}