diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 4d13f40..4496692 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -22,7 +22,7 @@ DCCEXParser * CommandDistributor::parser=0; -void CommandDistributor::parse(byte clientId,byte * buffer, Print * streamer) { +void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * streamer) { if (buffer[0] == '<') { if (!parser) parser = new DCCEXParser(); parser->parse(streamer, buffer, true); // tell JMRI parser that ACKS are blocking because we can't handle the async diff --git a/CommandDistributor.h b/CommandDistributor.h index 2bec81b..155ada0 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -19,11 +19,12 @@ #ifndef CommandDistributor_h #define CommandDistributor_h #include "DCCEXParser.h" +#include "RingStream.h" class CommandDistributor { public : - static void parse(byte clientId,byte* buffer, Print * streamer); + static void parse(byte clientId,byte* buffer, RingStream * streamer); private: static DCCEXParser * parser; }; diff --git a/WiThrottle.cpp b/WiThrottle.cpp index ac503a0..95ea07e 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -99,7 +99,7 @@ WiThrottle::~WiThrottle() { } } -void WiThrottle::parse(Print & stream, byte * cmdx) { +void WiThrottle::parse(RingStream & stream, byte * cmdx) { byte * cmd=cmdx; @@ -334,10 +334,18 @@ int WiThrottle::WiTToDCCSpeed(int WiTSpeed) { return WiTSpeed + 1; //offset others by 1 } -void WiThrottle::loop() { +void WiThrottle::loop(RingStream & stream) { // for each WiThrottle, check the heartbeat for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle) wt->checkHeartbeat(); + + // TODO... any broadcasts to be done + /* MUST follow this model in this loop. + * stream->mark(); + * send 1 digit client id, and any data + * stream->commit() + */ + } void WiThrottle::checkHeartbeat() { diff --git a/WiThrottle.h b/WiThrottle.h index c1b5bba..fe06cfe 100644 --- a/WiThrottle.h +++ b/WiThrottle.h @@ -19,6 +19,7 @@ #ifndef WiThrottle_h #define WiThrottle_h +#include "RingStream.h" struct MYLOCO { char throttle; //indicates which throttle letter on client, often '0','1' or '2' @@ -27,8 +28,8 @@ struct MYLOCO { class WiThrottle { public: - static void loop(); - void parse(Print & stream, byte * cmd); + static void loop(RingStream & stream); + void parse(RingStream & stream, byte * cmd); static WiThrottle* getThrottle( int wifiClient); static bool annotateLeftRight; private: diff --git a/WifiInboundHandler.cpp b/WifiInboundHandler.cpp index 6aa8738..a13e789 100644 --- a/WifiInboundHandler.cpp +++ b/WifiInboundHandler.cpp @@ -31,6 +31,8 @@ void WifiInboundHandler::loop1() { // First handle all inbound traffic events because they will block the sending if (loop2()!=INBOUND_IDLE) return; + WiThrottle::loop(outboundRing); + // if nothing is already CIPSEND pending, we can CIPSEND one reply if (clientPendingCIPSEND<0) { int next=outboundRing->read(); diff --git a/WifiInboundHandler.h b/WifiInboundHandler.h index e947bdb..953b08d 100644 --- a/WifiInboundHandler.h +++ b/WifiInboundHandler.h @@ -2,6 +2,7 @@ #define WifiInboundHandler_h #include "RingStream.h" +#include "WiThrottle.h" #include "DIAG.h" class WifiInboundHandler { diff --git a/WifiInterface.cpp b/WifiInterface.cpp index c751cab..74018b9 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -22,7 +22,7 @@ #include #include "DIAG.h" #include "StringFormatter.h" -#include "WiThrottle.h" + #include "WifiInboundHandler.h" const char PROGMEM READY_SEARCH[] = "\r\nready\r\n"; @@ -295,7 +295,6 @@ bool WifiInterface::checkForOK( const unsigned int timeout, const char * waitfor void WifiInterface::loop() { if (connected) { - WiThrottle::loop(); WifiInboundHandler::loop(); } }