1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +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;
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

View File

@ -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;
};

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;
@ -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() {

View File

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

View File

@ -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();

View File

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

View File

@ -22,7 +22,7 @@
#include <avr/pgmspace.h>
#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();
}
}