adjusted, but too few SPIs

This commit is contained in:
2021-01-09 23:32:01 +01:00
parent 6671348d22
commit e9914f5bb1
37 changed files with 10253 additions and 744 deletions

View File

@ -91,7 +91,7 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
commands = getConfigCommands();
}
coloredMsg(LOG_YELLOW, true, "ch cec cmdLine is %s", cmdLine);;
coloredMsg(LOG_YELLOW, "ch cec cmdLine is %s", cmdLine);;
#define MAX_NUM_OF_ARGS 8
char *args[MAX_NUM_OF_TASKS];
@ -107,7 +107,7 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
char *cmd = args[0];
int8_t retCode = 0;
coloredMsg(LOG_YELLOW, true, "ch cec cmd is %s, number of arguments %d", cmd, argc);
coloredMsg(LOG_YELLOW, "ch cec cmd is %s, number of arguments %d", cmd, argc);
if (0 == strcmp(cmd, "quit")) {
messageToSend = (uint8_t*)GOODBYE_MSG;
@ -128,16 +128,16 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
}
messageToSend = NULL;
} else if (0 == strcmp(cmd, "enable")) {
coloredMsg(LOG_YELLOW, true, "ch cec enable admin mode");
coloredMsg(LOG_YELLOW, "ch cec enable admin mode");
adminMode = true;
retCode = 1;
} else if (0 == strcmp(cmd, "disable")) {
coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode");
coloredMsg(LOG_YELLOW, "ch cec disable admin mode");
adminMode = false;
configMode = false;
retCode = 3;
} else if (0 == strcmp(cmd, "config")) {
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");
coloredMsg(LOG_YELLOW, "ch cec enable config mode");
configMode = true;
retCode = 2;
} else {
@ -157,7 +157,7 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
}
if (messageToSend) {
coloredMsg(LOG_YELLOW, true, "ch cec command finally returns %s", messageToSend);
coloredMsg(LOG_YELLOW, "ch cec command finally returns %s", messageToSend);
send(CMD_SOCK, messageToSend, strlen((char*)messageToSend));
}
@ -192,13 +192,13 @@ static void cmdHandlerEngine(void *handle) {
if (isNetworkAvailable()) {
switch (state) {
case CH_INIT:
coloredMsg(LOG_YELLOW, false, "ch che initializing socket");
coloredMsg(LOG_YELLOW, "ch che initializing socket");
res = socket(CMD_SOCK, Sn_MR_TCP, cmdPort, SF_IO_NONBLOCK);
coloredMsg(LOG_YELLOW, false, "ch che socket returns %d", res);
coloredMsg(LOG_YELLOW, "ch che socket returns %d", res);
if (res == CMD_SOCK) {
coloredMsg(LOG_YELLOW, false, "ch che socket is initialized");
coloredMsg(LOG_YELLOW, "ch che socket is initialized");
state = CH_LISTEN;
} else {
state = CH_ERROR;
@ -206,13 +206,13 @@ static void cmdHandlerEngine(void *handle) {
break;
case CH_LISTEN:
coloredMsg(LOG_YELLOW, false, "ch che listening");
coloredMsg(LOG_YELLOW, "ch che listening");
res = listen(CMD_SOCK);
coloredMsg(LOG_YELLOW, false, "ch che listen returns %d", res);
coloredMsg(LOG_YELLOW, "ch che listen returns %d", res);
if (res == SOCK_OK) {
coloredMsg(LOG_YELLOW, false, "ch che ok, waiting for established");
coloredMsg(LOG_YELLOW, "ch che ok, waiting for established");
state = CH_WAITING;
} else {
state = CH_ERROR;
@ -222,25 +222,25 @@ static void cmdHandlerEngine(void *handle) {
case CH_WAITING:
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_LISTEN) {
coloredMsg(LOG_YELLOW, false, "ch che socket state is 0x%02x", sockState);
coloredMsg(LOG_YELLOW, "ch che socket state is 0x%02x", sockState);
state = CH_DISCONNECT;
}
if (sockState == SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, true, "ch che connection is established");
coloredMsg(LOG_YELLOW, "ch che connection is established");
state = CH_BANNER;
}
break;
case CH_BANNER:
coloredMsg(LOG_YELLOW, false, "ch che send banner");
coloredMsg(LOG_YELLOW, "ch che send banner");
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send banner", sockState);
coloredMsg(LOG_YELLOW, "ch che sockState is 0x%02x when trying to send banner", sockState);
state = CH_DISCONNECT;
} else {
resultSend = send(CMD_SOCK, (uint8_t*)banner, strlen(banner));
coloredMsg(LOG_YELLOW, false, "ch che sent banner, send returns 0x%02x", resultSend);
coloredMsg(LOG_YELLOW, "ch che sent banner, send returns 0x%02x", resultSend);
prompt = defaultPrompt;
resetSpecialModes = true;
state = CH_PROMPT;
@ -248,14 +248,14 @@ static void cmdHandlerEngine(void *handle) {
break;
case CH_PROMPT:
coloredMsg(LOG_YELLOW, false, "ch che send prompt");
coloredMsg(LOG_YELLOW, "ch che send prompt");
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send promt", sockState);
coloredMsg(LOG_YELLOW, "ch che sockState is 0x%02x when trying to send promt", sockState);
state = CH_DISCONNECT;
} else {
sendFormatString("%s %s", getConfig()->deviceName, prompt);
coloredMsg(LOG_YELLOW, false, "ch che sent prompt %s %s", getConfig()->deviceName, prompt);
coloredMsg(LOG_YELLOW, "ch che sent prompt %s %s", getConfig()->deviceName, prompt);
state = CH_RECEIVE;
}
break;
@ -263,7 +263,7 @@ static void cmdHandlerEngine(void *handle) {
case CH_RECEIVE:
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_ESTABLISHED) {
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to receive something", sockState);
coloredMsg(LOG_YELLOW, "ch che sockState is 0x%02x when trying to receive something", sockState);
state = CH_DISCONNECT;
} else {
receivedOctets = getSn_RX_RSR(CMD_SOCK);
@ -271,7 +271,7 @@ static void cmdHandlerEngine(void *handle) {
if (receivedOctets > 0) {
memset(receiveBuffer, 0, sizeof(receiveBuffer));
resultRecv = recv(CMD_SOCK, receiveBuffer, sizeof(receiveBuffer));
coloredMsg(LOG_YELLOW, false, "ch che recv returns 0x%02x", resultRecv);
coloredMsg(LOG_YELLOW, "ch che recv returns 0x%02x", resultRecv);
if (resultRecv > 0) {
if ((receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0a) ||
(receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0d)) {
@ -281,7 +281,7 @@ static void cmdHandlerEngine(void *handle) {
(receiveBuffer[strlen((char*)receiveBuffer) - 1] == 0x0d)) {
receiveBuffer[strlen((char*)receiveBuffer) - 1] = 0;
}
coloredMsg(LOG_YELLOW, false, "ch che received: %s", receiveBuffer);
coloredMsg(LOG_YELLOW, "ch che received: %s", receiveBuffer);
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetSpecialModes);
resetSpecialModes = false;
switch (resCEC) {
@ -310,29 +310,29 @@ static void cmdHandlerEngine(void *handle) {
break;
case CH_DISCONNECT:
coloredMsg(LOG_YELLOW, true, "ch che close our end");
coloredMsg(LOG_YELLOW, "ch che close our end");
resultDisconnect = disconnect(CMD_SOCK);
coloredMsg(LOG_YELLOW, true, "ch che disconnect returns 0x%02x", resultDisconnect);
coloredMsg(LOG_YELLOW, "ch che disconnect returns 0x%02x", resultDisconnect);
state = CH_DISCONNECT_WAIT;
break;
case CH_DISCONNECT_WAIT:
//coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
//coloredMsg(LOG_YELLOW, "ch che waiting after disconnect");
sockState = getSn_SR(CMD_SOCK);
//coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
//coloredMsg(LOG_YELLOW, "ch che sockState is 0x%02x", sockState);
if (sockState == SOCK_CLOSED) {
coloredMsg(LOG_YELLOW, true, "ch che socket is closed now");
coloredMsg(LOG_YELLOW, "ch che socket is closed now");
state = CH_INIT;
}
break;
case CH_ERROR:
coloredMsg(LOG_YELLOW, true, "ch che error state, will stop here");
coloredMsg(LOG_YELLOW, "ch che error state, will stop here");
schDel(cmdHandlerEngine, NULL);
state = CH_INIT;
schAdd(cmdHandlerEngine, NULL, 5000, 100);
coloredMsg(LOG_YELLOW, true, "ch che restart command handler engine in 5s");
coloredMsg(LOG_YELLOW, "ch che restart command handler engine in 5s");
break;
}
}