From 6d7d01b1b5157fd8a610a766e6fad59a8f0903c7 Mon Sep 17 00:00:00 2001 From: Gregor Baues Date: Mon, 9 Nov 2020 17:00:24 +0100 Subject: [PATCH] Renamed Enum value UDP to UDPR because of class name clash --- CommandStation-EX.ino | 2 +- EthernetSetup.cpp | 2 +- NetworkInterface.h | 2 +- Transport.cpp | 6 +++--- Transport.h | 33 ++++++++++++++++++++++++++++++++- TransportProcessor.cpp | 2 -- TransportProcessor.h | 28 +--------------------------- WifiSetup.cpp | 4 ++-- 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index c3a6cb7..e2e9922 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -80,7 +80,7 @@ void setup() // wifi.setup(WIFI, TCP, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME)); // wifi.setup(WIFI, TCP, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME, 2323) - eth1.setup(ETHERNET, UDP); // ETHERNET, UDP on Port 2560 + eth1.setup(ETHERNET, UDPR); // ETHERNET, UDP on Port 2560 // eth1.setup(ETHERNET, TCP); // ETHERNET, UDP on Port 2560 eth2.setup(ETHERNET, TCP, 23); // ETHERNET, TCP on Port 23 for the CLI // eth1.setup(ETHERNET, TCP, 8888); // ETHERNET, TCP on Port 8888 diff --git a/EthernetSetup.cpp b/EthernetSetup.cpp index 890deeb..f6ce2b1 100644 --- a/EthernetSetup.cpp +++ b/EthernetSetup.cpp @@ -61,7 +61,7 @@ byte EthernetSetup::setup() INFO(F("Network Protocol: [%s]"), protocol ? "UDP" : "TCP"); switch (protocol) { - case UDP: + case UDPR: { udp = new EthernetUDP(); byte udpState = udp->begin(port); diff --git a/NetworkInterface.h b/NetworkInterface.h index cb63b4c..29c0d9b 100644 --- a/NetworkInterface.h +++ b/NetworkInterface.h @@ -25,7 +25,7 @@ typedef enum protocolType { TCP, - UDP, + UDPR, // UDP clashes with a class name in the network stack MQTT } protocolType; diff --git a/Transport.cpp b/Transport.cpp index c05f277..fbdead6 100644 --- a/Transport.cpp +++ b/Transport.cpp @@ -42,7 +42,7 @@ template void Transport::loop() { switch (protocol) { - case UDP: + case UDPR: { udpHandler(udp); break; @@ -106,14 +106,14 @@ void Transport::udpHandler(U* udp) udp->read(t->buffer, MAX_ETH_BUFFER); t->buffer[packetSize] = 0; // terminate buffer - t->readStream(&connections[0], false); // there is only one connection for UDP; reading into the buffer has been done + t->readStream(&connections[0], false ); // there is only one connection for UDP; reading into the buffer has been done memset(t->buffer, 0, MAX_ETH_BUFFER); // reset PacktBuffer return; // send the reply // udp.beginPacket(udp.remoteIP(), udp.remotePort()); - // parse(&udp, (byte *)buffer, true); //////////// Put into the TransportProcessor + // parse(&udp, (byte *)buffer, true); //////////// Put into the TransportProcessor Attn the default udp TX buffer on ethernet is 24 on wifi its 256 ?? // udp.endPacket(); } return; diff --git a/Transport.h b/Transport.h index 9438721..68bde4c 100644 --- a/Transport.h +++ b/Transport.h @@ -27,6 +27,36 @@ #include "NetworkInterface.h" #include "TransportProcessor.h" + +typedef enum +{ + DCCEX, // if char[0] = < opening bracket the client should be a JMRI / DCC EX client_h + WITHROTTLE, // + HTTP, // If char[0] = G || P || D; if P then char [1] = U || O || A + N_DIAG, // '#' send form a telnet client as FIRST message will then reroute all DIAG messages to that client whilst being able to send jmri type commands + UNKNOWN_PROTOCOL +} appProtocol; + +// Needed forward declarations +struct Connection; +class TransportProcessor; + +using appProtocolCallback = void (*)(Connection* c, TransportProcessor* t); + +struct Connection +{ + uint8_t id; // initalized when the pool is setup + Client *client; // idem + char overflow[MAX_OVERFLOW]; // idem + appProtocol p; // dynamically determined upon message reception; first message wins + char delimiter = '\0'; // idem + bool isProtocolDefined = false; // idem + appProtocolCallback appProtocolHandler; // idem +}; + + + + template class Transport: public AbstractTransport { @@ -34,7 +64,7 @@ private: C clients[MAX_SOCK_NUM]; // Client objects created by the connectionPool Connection connections[MAX_SOCK_NUM]; // All the connections build by the connectionPool bool connected = false; - TransportProcessor* t; // pointer to the object which handles the incomming flow + TransportProcessor* t; // pointer to the object which handles the incomming/outgoing flow void udpHandler(U* udp); // Reads from a Udp socket - todo add incomming queue for processing when the flow is faster than we can process commands void tcpSessionHandler(S* server); // tcpSessionHandler -> connections are maintained open until close by the client @@ -42,6 +72,7 @@ private: void connectionPool(U* udp); // allocates the UDP Sockets at setup time and creates the Connection public: + uint8_t id; uint16_t port; uint8_t protocol; // TCP or UDP diff --git a/TransportProcessor.cpp b/TransportProcessor.cpp index 5abb382..c4c4768 100644 --- a/TransportProcessor.cpp +++ b/TransportProcessor.cpp @@ -66,8 +66,6 @@ void sendWiThrottleToDCC(Connection *c, TransportProcessor *t, bool blocking) // STRINGIFY(__FILE__); DBG(F("WiThrottle [%x:%x] parsing: [%e]"), wt, _buffer, t->command); - - wt->parse(&streamer, (byte *)t->command); // get the response; not all commands will produce a reply if (streamer.count() != -1) { diff --git a/TransportProcessor.h b/TransportProcessor.h index 0c1386d..fd3675f 100644 --- a/TransportProcessor.h +++ b/TransportProcessor.h @@ -24,37 +24,11 @@ #include #include "RingStream.h" - +#include "Transport.h" #include "NetworkConfig.h" #include "NetworkInterface.h" -typedef enum -{ - DCCEX, // if char[0] = < opening bracket the client should be a JMRI / DCC EX client_h - WITHROTTLE, // - HTTP, // If char[0] = G || P || D; if P then char [1] = U || O || A - N_DIAG, // '#' send form a telnet client as FIRST message will then reroute all DIAG messages to that client whilst being able to send jmri type commands - UNKNOWN_PROTOCOL -} appProtocol; - -// Needed forward declarations -struct Connection; -class TransportProcessor; - -using appProtocolCallback = void (*)(Connection* c, TransportProcessor* t); - -struct Connection -{ - uint8_t id; // initalized when the pool is setup - Client *client; // idem - char overflow[MAX_OVERFLOW]; // idem - appProtocol p; // dynamically determined upon message reception; first message wins - char delimiter = '\0'; // idem - bool isProtocolDefined = false; // idem - appProtocolCallback appProtocolHandler; // idem -}; - class TransportProcessor { private: diff --git a/WifiSetup.cpp b/WifiSetup.cpp index 2ee11d8..78b25d1 100644 --- a/WifiSetup.cpp +++ b/WifiSetup.cpp @@ -44,7 +44,7 @@ bool WifiSetup::setup() { switch (protocol) { - case UDP: + case UDPR: { INFO(F("\nUDP over Wifi is not yet supported\n")); connected = false; @@ -97,7 +97,7 @@ bool WifiSetup::setup() { dnsip = WiFi.dnsServer1(); INFO(F("DNS server IP address: [%d.%d.%d.%d] "), dnsip[0], dnsip[1], dnsip[2], dnsip[3]); INFO(F("Number of connections: [%d]"), maxConnections); - if( protocol == UDP ) return 0; // no server here as we use UDP + if( protocol == UDPR ) return 0; // no server here as we use UDP return true; } // something went wrong