1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

Passing outbound Ring to Withrottle

This will allow Withrottle to send to other clients and broadcast messages.
This commit is contained in:
Asbelos 2020-10-26 13:31:51 +00:00
parent 6833d82789
commit 8ff947f895
7 changed files with 20 additions and 8 deletions

View File

@ -22,7 +22,7 @@
DCCEXParser * CommandDistributor::parser=0; 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 (buffer[0] == '<') {
if (!parser) parser = new DCCEXParser(); if (!parser) parser = new DCCEXParser();
parser->parse(streamer, buffer, true); // tell JMRI parser that ACKS are blocking because we can't handle the async parser->parse(streamer, buffer, true); // tell JMRI parser that ACKS are blocking because we can't handle the async

View File

@ -19,11 +19,12 @@
#ifndef CommandDistributor_h #ifndef CommandDistributor_h
#define CommandDistributor_h #define CommandDistributor_h
#include "DCCEXParser.h" #include "DCCEXParser.h"
#include "RingStream.h"
class CommandDistributor { class CommandDistributor {
public : public :
static void parse(byte clientId,byte* buffer, Print * streamer); static void parse(byte clientId,byte* buffer, RingStream * streamer);
private: private:
static DCCEXParser * parser; static DCCEXParser * parser;
}; };

View File

@ -99,7 +99,7 @@ WiThrottle::~WiThrottle() {
} }
} }
void WiThrottle::parse(Print & stream, byte * cmdx) { void WiThrottle::parse(RingStream & stream, byte * cmdx) {
byte * cmd=cmdx; byte * cmd=cmdx;
@ -334,10 +334,18 @@ int WiThrottle::WiTToDCCSpeed(int WiTSpeed) {
return WiTSpeed + 1; //offset others by 1 return WiTSpeed + 1; //offset others by 1
} }
void WiThrottle::loop() { void WiThrottle::loop(RingStream & stream) {
// for each WiThrottle, check the heartbeat // for each WiThrottle, check the heartbeat
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle) for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
wt->checkHeartbeat(); 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() { void WiThrottle::checkHeartbeat() {

View File

@ -19,6 +19,7 @@
#ifndef WiThrottle_h #ifndef WiThrottle_h
#define WiThrottle_h #define WiThrottle_h
#include "RingStream.h"
struct MYLOCO { struct MYLOCO {
char throttle; //indicates which throttle letter on client, often '0','1' or '2' char throttle; //indicates which throttle letter on client, often '0','1' or '2'
@ -27,8 +28,8 @@ struct MYLOCO {
class WiThrottle { class WiThrottle {
public: public:
static void loop(); static void loop(RingStream & stream);
void parse(Print & stream, byte * cmd); void parse(RingStream & stream, byte * cmd);
static WiThrottle* getThrottle( int wifiClient); static WiThrottle* getThrottle( int wifiClient);
static bool annotateLeftRight; static bool annotateLeftRight;
private: private:

View File

@ -31,6 +31,8 @@ void WifiInboundHandler::loop1() {
// First handle all inbound traffic events because they will block the sending // First handle all inbound traffic events because they will block the sending
if (loop2()!=INBOUND_IDLE) return; if (loop2()!=INBOUND_IDLE) return;
WiThrottle::loop(outboundRing);
// if nothing is already CIPSEND pending, we can CIPSEND one reply // if nothing is already CIPSEND pending, we can CIPSEND one reply
if (clientPendingCIPSEND<0) { if (clientPendingCIPSEND<0) {
int next=outboundRing->read(); int next=outboundRing->read();

View File

@ -2,6 +2,7 @@
#define WifiInboundHandler_h #define WifiInboundHandler_h
#include "RingStream.h" #include "RingStream.h"
#include "WiThrottle.h"
#include "DIAG.h" #include "DIAG.h"
class WifiInboundHandler { class WifiInboundHandler {

View File

@ -22,7 +22,7 @@
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "DIAG.h" #include "DIAG.h"
#include "StringFormatter.h" #include "StringFormatter.h"
#include "WiThrottle.h"
#include "WifiInboundHandler.h" #include "WifiInboundHandler.h"
const char PROGMEM READY_SEARCH[] = "\r\nready\r\n"; 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() { void WifiInterface::loop() {
if (connected) { if (connected) {
WiThrottle::loop();
WifiInboundHandler::loop(); WifiInboundHandler::loop();
} }
} }