From 3cc2e51ad9c5d1e163d64959c6ea6b9213c77d99 Mon Sep 17 00:00:00 2001 From: wellenvogel Date: Sun, 12 Nov 2023 19:55:57 +0100 Subject: [PATCH] simple forward from socket to serial for sertest --- lib/sertesttask/SerTestTask.cpp | 41 +++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/sertesttask/SerTestTask.cpp b/lib/sertesttask/SerTestTask.cpp index 9f6f2bed..b62a46d5 100644 --- a/lib/sertesttask/SerTestTask.cpp +++ b/lib/sertesttask/SerTestTask.cpp @@ -1,15 +1,48 @@ #include "SerTestTask.h" #include "GwHardware.h" +#include #ifdef SERTEST +WiFiServer listener(10111); +const size_t BUFSIZE=10240; void sertest(GwApi *api){ GwLog *logger=api->getLogger(); LOG_DEBUG(GwLog::LOG,"ser test task started"); Serial2.begin(api->getConfig()->getInt(GwConfigDefinitions::serialBaud), SERIAL_8N1,-1,GWSERIAL_RX); + listener.begin(); + uint8_t *buffer=new uint8_t[BUFSIZE+1]; while (true){ - const char * T="SERTESTXXX"; - LOG_DEBUG(GwLog::LOG,"sending %s",T); - Serial2.println(T); - delay(1000); + WiFiClient client = listener.available(); + if (client) { + if (client.connected()) { + LOG_DEBUG(GwLog::LOG,"SerTest Connected to client"); + while (true){ + if (! client.connected()){ + break; + } + int avail=client.available(); + if (avail){ + size_t rd=client.readBytes(buffer,avail); + if (rd > 0){ + LOG_DEBUG(GwLog::DEBUG,"SerTest read %d bytes",(int)rd); + size_t wr=Serial2.write(buffer,rd); + LOG_DEBUG(GwLog::DEBUG,"SerTest written %d bytes",(int)wr); + + } + else{ + delay(50); + } + } + else{ + delay(50); + } + } + } + + // close the connection: + LOG_DEBUG(GwLog::LOG,"SerTest closing connection"); + client.stop(); + } + delay(50); } vTaskDelete(NULL); return;