From 9633e77c0a33a9a48c819623a961d73454b91dbd Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 16 Aug 2022 19:22:19 +0200 Subject: [PATCH] move mark/commit into CommandDistributor::parse() --- CommandDistributor.cpp | 21 ++++++++++++++++++--- EthernetInterface.cpp | 2 -- GITHUB_SHA.h | 2 +- WifiESP32.cpp | 3 --- WifiInboundHandler.cpp | 6 ------ version.h | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 1dbcc6e..c4538cb 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -69,13 +69,28 @@ void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * stream clients[clientId]=WITHROTTLE_TYPE; } + // mark buffer that is sent to parser + ring->mark(clientId); + // When type is known, send the string // to the right parser - if (clients[clientId] == COMMAND_TYPE) + if (clients[clientId] == COMMAND_TYPE) { DCCEXParser::parse(stream, buffer, ring); - else if (clients[clientId] == WITHROTTLE_TYPE) + } else if (clients[clientId] == WITHROTTLE_TYPE) { WiThrottle::getThrottle(clientId)->parse(ring, buffer); + } + if (ring->peekTargetMark()!=RingStream::NO_CLIENT) { + // The commit call will either write the length bytes + // OR rollback to the mark because the reply is empty + // or the command generated more output than fits in + // the buffer + if (!ring->commit()) { + DIAG(F("OUTBOUND FULL processing cmd:%s"),buffer); + } + } else { + DIAG(F("CD parse: was alredy committed")); //XXX Could have been committed by broadcastClient?! + } } void CommandDistributor::forget(byte clientId) { @@ -111,7 +126,7 @@ void CommandDistributor::broadcastToClients(clientType type) { ring->commit(); } } - if (ring->peekTargetMark()!=RingStream::NO_CLIENT) { + if (ring->peekTargetMark() == RingStream::NO_CLIENT) { //DIAG(F("CD postmark client %d"), rememberClient); ring->mark(rememberClient); } diff --git a/EthernetInterface.cpp b/EthernetInterface.cpp index 48f9002..f8c6146 100644 --- a/EthernetInterface.cpp +++ b/EthernetInterface.cpp @@ -163,9 +163,7 @@ void EthernetInterface::loop() buffer[count] = '\0'; // terminate the string properly if (Diag::ETHERNET) DIAG(F(",count=%d:%e"), socket,buffer); // execute with data going directly back - outboundRing->mark(socket); CommandDistributor::parse(socket,buffer,outboundRing); - outboundRing->commit(); return; // limit the amount of processing that takes place within 1 loop() cycle. } } diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 56000ec..42079cb 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "PORTX-HAL-20220813" +#define GITHUB_SHA "PORTX-HAL-20220816" diff --git a/WifiESP32.cpp b/WifiESP32.cpp index 95de764..f00d6f4 100644 --- a/WifiESP32.cpp +++ b/WifiESP32.cpp @@ -264,10 +264,7 @@ void WifiESP::loop() { cmd[i]=clients[clientId].wifi.read(); } cmd[len]=0; - outboundRing->mark(clientId); CommandDistributor::parse(clientId,cmd,outboundRing); - if (outboundRing->peekTargetMark()!=RingStream::NO_CLIENT) - outboundRing->commit(); } } } // all clients diff --git a/WifiInboundHandler.cpp b/WifiInboundHandler.cpp index a509409..2a8ec28 100644 --- a/WifiInboundHandler.cpp +++ b/WifiInboundHandler.cpp @@ -84,13 +84,7 @@ void WifiInboundHandler::loop1() { cmd[count]=0; if (Diag::WIFI) DIAG(F("%e"),cmd); - outboundRing->mark(clientId); // remember start of outbound data CommandDistributor::parse(clientId,cmd,outboundRing); - // The commit call will either write the lenbgth bytes - // OR rollback to the mark because the reply is empty or commend generated more than fits the buffer - if (!outboundRing->commit()) { - DIAG(F("OUTBOUND FULL processing cmd:%s"),cmd); - } return; } } diff --git a/version.h b/version.h index a5d336f..6e743e1 100644 --- a/version.h +++ b/version.h @@ -4,7 +4,7 @@ #include "StringFormatter.h" -#define VERSION "4.2.1 rc1" +#define VERSION "4.2.2 rc1" // 4.2.1 ESP32 alpha // Ready for alpha test on ESP32. Track switching with <=> untested // Send DCC signal on MAIN