From 961e5a73aa80f7ba0e3082b2b287ae6726fb4a6e Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 15 Nov 2020 23:51:48 +0100 Subject: [PATCH] cmdHandler started --- cube/Makefile | 2 +- cube/User/Inc/cmdHandler.h | 9 ++++ cube/User/Inc/httpTest.h | 9 ---- cube/User/Inc/tcpTest.h | 9 ---- cube/User/Src/{tcpTest.c => cmdHandler.c} | 26 ++++----- cube/User/Src/httpTest.c | 64 ----------------------- cube/User/Src/main2.c | 5 +- cube/User/Src/ports.c | 5 +- 8 files changed, 27 insertions(+), 102 deletions(-) create mode 100644 cube/User/Inc/cmdHandler.h delete mode 100644 cube/User/Inc/httpTest.h delete mode 100644 cube/User/Inc/tcpTest.h rename cube/User/Src/{tcpTest.c => cmdHandler.c} (80%) delete mode 100644 cube/User/Src/httpTest.c diff --git a/cube/Makefile b/cube/Makefile index cf38ef1..6b0c250 100644 --- a/cube/Makefile +++ b/cube/Makefile @@ -37,7 +37,7 @@ BUILD_DIR = build ###################################### # C sources C_SOURCES = \ -User/Src/httpTest.c User/Src/mqttComm.c User/Src/tcpTest.c User/Src/ports.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \ +User/Src/mqttComm.c User/Src/cmdHandler.c User/Src/ports.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \ libmbus/mbus/mbus-protocol.c \ Core/Src/main.c \ Core/Src/gpio.c \ diff --git a/cube/User/Inc/cmdHandler.h b/cube/User/Inc/cmdHandler.h new file mode 100644 index 0000000..41e14c0 --- /dev/null +++ b/cube/User/Inc/cmdHandler.h @@ -0,0 +1,9 @@ +#ifndef _CMDHANDLER_H_ +#define _CMDHANDLER_H_ + +#include + +void cmdHandlerInit(); + + +#endif /* _CMDHANDLER_H_ */ diff --git a/cube/User/Inc/httpTest.h b/cube/User/Inc/httpTest.h deleted file mode 100644 index 45c65fb..0000000 --- a/cube/User/Inc/httpTest.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _HTTPTEST_H_ -#define _HTTPTEST_H_ - -#include - -void httpTestInit(); - - -#endif /* _HTTPTEST_H_ */ diff --git a/cube/User/Inc/tcpTest.h b/cube/User/Inc/tcpTest.h deleted file mode 100644 index e3dabed..0000000 --- a/cube/User/Inc/tcpTest.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _TCPTEST_H_ -#define _TCPTEST_H_ - -#include - -void tcpTestInit(); - - -#endif /* _TCPTEST_H_ */ diff --git a/cube/User/Src/tcpTest.c b/cube/User/Src/cmdHandler.c similarity index 80% rename from cube/User/Src/tcpTest.c rename to cube/User/Src/cmdHandler.c index e78fbe6..b828f70 100644 --- a/cube/User/Src/tcpTest.c +++ b/cube/User/Src/cmdHandler.c @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -12,12 +12,12 @@ #include -extern const uint8_t TCPTEST_SOCK; +extern const uint8_t CMD_SOCK; uint8_t remoteAddr[] = { 172, 16, 3, 31 }; uint16_t remotePort = 5000; -void tcpTestHandler(void *handle) { +void cmdHandler(void *handle) { static uint8_t state = 0; int8_t res = 0; int16_t res16 = 0; @@ -30,10 +30,10 @@ void tcpTestHandler(void *handle) { case 0: coloredMsg(LOG_YELLOW, "tth, initializing socket"); - res = socket(TCPTEST_SOCK, Sn_MR_TCP, 12345, SF_IO_NONBLOCK); + res = socket(CMD_SOCK, Sn_MR_TCP, 12345, SF_IO_NONBLOCK); coloredMsg(LOG_YELLOW, "tth, socket returns %d", res); - if (res == TCPTEST_SOCK) { + if (res == CMD_SOCK) { coloredMsg(LOG_YELLOW, "tth, socket is initialized"); state = 1; } else { @@ -44,7 +44,7 @@ void tcpTestHandler(void *handle) { case 1: coloredMsg(LOG_YELLOW, "tth, connecting"); - res = connect(TCPTEST_SOCK, remoteAddr, remotePort); + res = connect(CMD_SOCK, remoteAddr, remotePort); coloredMsg(LOG_YELLOW, "tth, connect returns %d", res); if (res == SOCK_BUSY) { @@ -58,7 +58,7 @@ void tcpTestHandler(void *handle) { case 2: coloredMsg(LOG_YELLOW, "tth, waiting for established"); - uint8_t sockState = getSn_SR(TCPTEST_SOCK); + uint8_t sockState = getSn_SR(CMD_SOCK); coloredMsg(LOG_YELLOW, "tth, socket state is 0x%02x", sockState); if (sockState == SOCK_ESTABLISHED) { @@ -70,7 +70,7 @@ void tcpTestHandler(void *handle) { case 3: coloredMsg(LOG_YELLOW, "tth, now sending something"); - res32 = send(TCPTEST_SOCK, message, strlen(message)); + res32 = send(CMD_SOCK, message, strlen(message)); coloredMsg(LOG_YELLOW, "tth, sent a message, send returns 0x%02x", res32); state = 4; @@ -78,13 +78,13 @@ void tcpTestHandler(void *handle) { case 4: // coloredMsg(LOG_YELLOW, "tth, now waiting for some input"); - res16 = getSn_RX_RSR(TCPTEST_SOCK); + res16 = getSn_RX_RSR(CMD_SOCK); // coloredMsg(LOG_YELLOW, "tth, getSn_RxMAX returns %d", res16); if (res16 > 0) { uint8_t *buf = (uint8_t*) malloc(res16); memset(buf, 0, res16); - res32 = recv(TCPTEST_SOCK, buf, res16); + res32 = recv(CMD_SOCK, buf, res16); coloredMsg(LOG_YELLOW, "tth, recv returns 0x%02x", res32); if (res32 > 0) { coloredMsg(LOG_YELLOW, "tth, received: %d, %s", res32, buf); @@ -96,7 +96,7 @@ void tcpTestHandler(void *handle) { case 255: coloredMsg(LOG_YELLOW, "tth, error state, will stop here"); - schDel(tcpTestHandler, NULL); + schDel(cmdHandler, NULL); break; } } else { @@ -104,6 +104,6 @@ void tcpTestHandler(void *handle) { } } -void tcpTestInit() { - schAdd(tcpTestHandler, NULL, 0, 100); +void cmdHandlerInit() { + schAdd(cmdHandler, NULL, 0, 100); } \ No newline at end of file diff --git a/cube/User/Src/httpTest.c b/cube/User/Src/httpTest.c deleted file mode 100644 index 4167187..0000000 --- a/cube/User/Src/httpTest.c +++ /dev/null @@ -1,64 +0,0 @@ -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - - -extern const uint8_t HTTP_SOCK_1; -extern const uint8_t HTTP_SOCK_2; -extern const uint8_t HTTP_SOCK_3; -#define MAX_HTTPSOCK 3 -uint8_t HTTPTEST_SOCKS[] = { 3, 4, 5 }; - -#define DATA_BUF_SIZE 1024 -uint8_t RX_BUF[DATA_BUF_SIZE], TX_BUF[DATA_BUF_SIZE]; - -static uint8_t webpath[] = "hello"; -static uint8_t message[] = "Hello World!\n\r"; - - -void httpTestHandler(void *handle) { - static uint8_t state = 0; - if (isNetworkAvailable()) { - switch (state) { - case 0: - coloredMsg(LOG_YELLOW, "hth, initializing server"); - - httpServer_init(TX_BUF, RX_BUF, MAX_HTTPSOCK, HTTPTEST_SOCKS); - reg_httpServer_webContent(webpath, message); - state = 1; - break; - - case 1: - coloredMsg(LOG_YELLOW, "hth, running"); - state = 2; - break; - - case 2: - for (uint8_t i = 0; i < MAX_HTTPSOCK; i++) { - httpServer_run(i); - } - break; - - case 255: - coloredMsg(LOG_YELLOW, "hth, error state, will stop here"); - schDel(httpTestHandler, NULL); - break; - } - } else { - coloredMsg(LOG_YELLOW, "hth, network not yet ready"); - } -} - -void httpTestInit() { - schAdd(httpTestHandler, NULL, 0, 100); -} \ No newline at end of file diff --git a/cube/User/Src/main2.c b/cube/User/Src/main2.c index fc6c779..073362c 100644 --- a/cube/User/Src/main2.c +++ b/cube/User/Src/main2.c @@ -18,7 +18,8 @@ #include #include #include -// #include +#include + void my_setup_1() { schInit(); @@ -193,7 +194,7 @@ void my_setup_2() { wizInit(); mqttCommInit(); -// httpTestInit(); + cmdHandlerInit(); frontendInit(); frontendSetThreshold(240); diff --git a/cube/User/Src/ports.c b/cube/User/Src/ports.c index 6e388cf..973fe8b 100644 --- a/cube/User/Src/ports.c +++ b/cube/User/Src/ports.c @@ -6,7 +6,4 @@ const uint8_t DHCP_SOCK = 0; const uint8_t MQTT_SOCK = 1; -const uint8_t TCPTEST_SOCK = 2; -const uint8_t HTTP_SOCK_1 = 3; -const uint8_t HTTP_SOCK_2 = 4; -const uint8_t HTTP_SOCK_3 = 5; \ No newline at end of file +const uint8_t CMD_SOCK = 2;