This commit is contained in:
2020-11-17 12:01:15 +01:00
parent ccf6982b62
commit 23568db1b5
8 changed files with 137 additions and 165 deletions

View File

@ -148,7 +148,7 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
configMode = false;
}
coloredMsg(LOG_YELLOW, "cec, cmdLine is %s", cmdLine);;
coloredMsg(LOG_YELLOW, false, "cec, cmdLine is %s", cmdLine);;
#define MAX_NUM_OF_ARGS 8
char *args[MAX_NUM_OF_TASKS];
@ -164,7 +164,7 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
char *cmd = args[0];
int8_t retCode = 0;
coloredMsg(LOG_YELLOW, "cec, cmd is %s, number of arguments %d", cmd, argc);
coloredMsg(LOG_YELLOW, false, "cec, cmd is %s, number of arguments %d", cmd, argc);
if (0 == strcmp(cmd, "quit")) {
messageToSend = GOODBYE_MSG;
@ -182,11 +182,11 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
}
messageToSend = NULL;
} else if (0 == strcmp(cmd, "enable")) {
coloredMsg(LOG_YELLOW, "cec, enable config mode");
coloredMsg(LOG_YELLOW, true, "cec, enable config mode");
configMode = true;
retCode = 1;
} else if (0 == strcmp(cmd, "disable")) {
coloredMsg(LOG_YELLOW, "cec, disable config mode");
coloredMsg(LOG_YELLOW, true, "cec, disable config mode");
configMode = false;
retCode = 2;
} else {
@ -241,13 +241,13 @@ void cmdHandlerEngine(void *handle) {
if (isNetworkAvailable()) {
switch (state) {
case CH_INIT:
coloredMsg(LOG_YELLOW, "che, initializing socket");
coloredMsg(LOG_YELLOW, false, "che, initializing socket");
res = socket(CMD_SOCK, Sn_MR_TCP, cmdPort, SF_IO_NONBLOCK);
coloredMsg(LOG_YELLOW, "che, socket returns %d", res);
coloredMsg(LOG_YELLOW, false, "che, socket returns %d", res);
if (res == CMD_SOCK) {
coloredMsg(LOG_YELLOW, "che, socket is initialized");
coloredMsg(LOG_YELLOW, false, "che, socket is initialized");
state = CH_LISTEN;
} else {
state = CH_ERROR;
@ -255,13 +255,13 @@ void cmdHandlerEngine(void *handle) {
break;
case CH_LISTEN:
coloredMsg(LOG_YELLOW, "che, listening");
coloredMsg(LOG_YELLOW, false, "che, listening");
res = listen(CMD_SOCK);
coloredMsg(LOG_YELLOW, "che, listen returns %d", res);
coloredMsg(LOG_YELLOW, false, "che, listen returns %d", res);
if (res == SOCK_OK) {
coloredMsg(LOG_YELLOW, "che, ok, waiting for established");
coloredMsg(LOG_YELLOW, false, "che, ok, waiting for established");
state = CH_WAITING;
} else {
state = CH_ERROR;
@ -269,28 +269,26 @@ void cmdHandlerEngine(void *handle) {
break;
case CH_WAITING:
//coloredMsg(LOG_YELLOW, "che, waiting for established");
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_LISTEN) {
coloredMsg(LOG_YELLOW, "che, socket state is 0x%02x", sockState);
coloredMsg(LOG_YELLOW, false, "che, socket state is 0x%02x", sockState);
}
if (sockState == SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, "che, connection is established");
coloredMsg(LOG_YELLOW, true, "che, connection is established");
state = CH_BANNER;
}
break;
case CH_BANNER:
coloredMsg(LOG_YELLOW, "che, send banner");
coloredMsg(LOG_YELLOW, false, "che, send banner");
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, "che sockState is 0x%02x when trying to send banner", sockState);
coloredMsg(LOG_YELLOW, true, "che sockState is 0x%02x when trying to send banner", sockState);
state = CH_DISCONNECT;
} else {
resultSend = send(CMD_SOCK, banner, strlen(banner));
coloredMsg(LOG_YELLOW, "che, sent banner, send returns 0x%02x", resultSend);
coloredMsg(LOG_YELLOW, false, "che, sent banner, send returns 0x%02x", resultSend);
prompt = defaultPrompt;
resetConfigMode = true;
state = CH_PROMPT;
@ -298,14 +296,14 @@ void cmdHandlerEngine(void *handle) {
break;
case CH_PROMPT:
coloredMsg(LOG_YELLOW, "che send prompt");
coloredMsg(LOG_YELLOW, false, "che send prompt");
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, "che sockState is 0x%02x when trying to send promt", sockState);
coloredMsg(LOG_YELLOW, true, "che sockState is 0x%02x when trying to send promt", sockState);
state = CH_DISCONNECT;
} else {
resultSend = send(CMD_SOCK, prompt, strlen(prompt));
coloredMsg(LOG_YELLOW, "che, sent prompt %s, send returns 0x%02x", prompt, resultSend);
coloredMsg(LOG_YELLOW, false, "che, sent prompt %s, send returns 0x%02x", prompt, resultSend);
state = CH_RECEIVE;
}
break;
@ -313,17 +311,15 @@ void cmdHandlerEngine(void *handle) {
case CH_RECEIVE:
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, "che sockState is 0x%02x when trying to receive something", sockState);
coloredMsg(LOG_YELLOW, true, "che sockState is 0x%02x when trying to receive something", sockState);
state = CH_DISCONNECT;
} else {
// coloredMsg(LOG_YELLOW, "che, now waiting for some input");
receivedOctets = getSn_RX_RSR(CMD_SOCK);
// coloredMsg(LOG_YELLOW, "che, getSn_RxMAX returns %d", res16);
if (receivedOctets > 0) {
memset(receiveBuffer, 0, sizeof(receiveBuffer));
resultRecv = recv(CMD_SOCK, receiveBuffer, sizeof(receiveBuffer));
coloredMsg(LOG_YELLOW, "che, recv returns 0x%02x", resultRecv);
coloredMsg(LOG_YELLOW, false, "che, recv returns 0x%02x", resultRecv);
if (resultRecv > 0) {
if ((receiveBuffer[strlen(receiveBuffer) - 1] == 0x0a) ||
(receiveBuffer[strlen(receiveBuffer) - 1] == 0x0d)) {
@ -333,7 +329,7 @@ void cmdHandlerEngine(void *handle) {
(receiveBuffer[strlen(receiveBuffer) - 1] == 0x0d)) {
receiveBuffer[strlen(receiveBuffer) - 1] = 0;
}
coloredMsg(LOG_YELLOW, "che, received: %s", receiveBuffer);
coloredMsg(LOG_YELLOW, false, "che, received: %s", receiveBuffer);
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetConfigMode);
resetConfigMode = false;
switch (resCEC) {
@ -358,25 +354,25 @@ void cmdHandlerEngine(void *handle) {
break;
case CH_DISCONNECT:
coloredMsg(LOG_YELLOW, "che, close our end");
coloredMsg(LOG_YELLOW, true, "che, close our end");
resultDisconnect = disconnect(CMD_SOCK);
coloredMsg(LOG_YELLOW, "che, disconnect returns 0x%02x", resultDisconnect);
coloredMsg(LOG_YELLOW, true, "che, disconnect returns 0x%02x", resultDisconnect);
state = CH_DISCONNECT_WAIT;
break;
case CH_DISCONNECT_WAIT:
coloredMsg(LOG_YELLOW, "che, waiting after disconnect");
coloredMsg(LOG_YELLOW, false, "che, waiting after disconnect");
sockState = getSn_SR(CMD_SOCK);
coloredMsg(LOG_YELLOW, "che, sockState is 0x%02x", sockState);
coloredMsg(LOG_YELLOW, false, "che, sockState is 0x%02x", sockState);
if (sockState == SOCK_CLOSED) {
coloredMsg(LOG_YELLOW, "che, socket is closed now");
coloredMsg(LOG_YELLOW, true, "che, socket is closed now");
state = CH_INIT;
}
break;
case CH_ERROR:
coloredMsg(LOG_YELLOW, "che, error state, will stop here");
coloredMsg(LOG_YELLOW, true, "che, error state, will stop here");
schDel(cmdHandlerEngine, NULL);
break;
}