1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00
CommandStation-EX/WifiInboundHandler.h
Asbelos 11e22c5d1d Working Wifi ringbuffer implementation
Notice 1kb output buffer
Aslo no need to copy command in Withrottle
2020-10-13 17:37:40 +01:00

61 lines
1.6 KiB
C++

#ifndef WifiInboundHandler_h
#define WifiInboundHandler_h
#include "RingStream.h"
#include "DIAG.h"
class WifiInboundHandler {
public:
static void setup(Stream * ESStream);
static void loop();
private:
static WifiInboundHandler * singleton;
enum INBOUND_STATE {
INBOUND_BUSY, // keep calling in loop()
INBOUND_IDLE // Nothing happening, outbound may xcall CIPSEND
};
enum LOOP_STATE {
ANYTHING, // ready for +IPD, n CLOSED, n CONNECTED, busy etc...
SKIPTOEND, // skip to newline
// +IPD,client,length:data
IPD, // got +
IPD1, // got +I
IPD2, // got +IP
IPD3, // got +IPD
IPD4_CLIENT, // got +IPD, reading cient id
IPD5, // got +IPD,c
IPD6_LENGTH, // got +IPD,c, reading length
IPD_DATA, // got +IPD,c,ll,: collecting data
GOT_CLIENT_ID, // clientid prefix to CONNECTED / CLOSED
GOT_CLIENT_ID2, // clientid prefix to CONNECTED / CLOSED
GOT_CLIENT_ID3 // clientid prefix to CONNECTED / CLOSED
};
WifiInboundHandler(Stream * ESStream);
void loop1();
INBOUND_STATE loop2();
Stream * wifiStream;
static const int INBOUND_RING = 200;
static const int OUTBOUND_RING = 1024;
RingStream * inboundRing;
RingStream * outboundRing;
LOOP_STATE loopState=ANYTHING;
int runningClientId; // latest client inbound processing data or CLOSE
int dataLength; // dataLength of +IPD
int clientPendingCIPSEND=-1;
int currentReplySize;
bool pendingCipsend;
};
#endif