cmdHandler started

This commit is contained in:
Wolfgang Hottgenroth 2020-11-15 23:51:48 +01:00
parent b9e1baee5b
commit 961e5a73aa
No known key found for this signature in database
GPG Key ID: 656C88C7C1734267
8 changed files with 27 additions and 102 deletions

View File

@ -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 \

View File

@ -0,0 +1,9 @@
#ifndef _CMDHANDLER_H_
#define _CMDHANDLER_H_
#include <stdint.h>
void cmdHandlerInit();
#endif /* _CMDHANDLER_H_ */

View File

@ -1,9 +0,0 @@
#ifndef _HTTPTEST_H_
#define _HTTPTEST_H_
#include <stdint.h>
void httpTestInit();
#endif /* _HTTPTEST_H_ */

View File

@ -1,9 +0,0 @@
#ifndef _TCPTEST_H_
#define _TCPTEST_H_
#include <stdint.h>
void tcpTestInit();
#endif /* _TCPTEST_H_ */

View File

@ -1,4 +1,4 @@
#include <tcpTest.h>
#include <cmdHandler.h>
#include <stdint.h>
#include <stdbool.h>
@ -12,12 +12,12 @@
#include <wizHelper.h>
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);
}

View File

@ -1,64 +0,0 @@
#include <httpTest.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <socket.h>
#include <httpServer.h>
#include <logger.h>
#include <PontCoopScheduler.h>
#include <wizHelper.h>
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);
}

View File

@ -18,7 +18,8 @@
#include <eeprom.h>
#include <wizHelper.h>
#include <mqttComm.h>
// #include <httpTest.h>
#include <cmdHandler.h>
void my_setup_1() {
schInit();
@ -193,7 +194,7 @@ void my_setup_2() {
wizInit();
mqttCommInit();
// httpTestInit();
cmdHandlerInit();
frontendInit();
frontendSetThreshold(240);

View File

@ -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;
const uint8_t CMD_SOCK = 2;