2020-10-22 19:25:20 +02:00
/*
* © 2020 , Gregor Baues . All rights reserved .
*
* This is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* It is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with CommandStation . If not , see < https : //www.gnu.org/licenses/>.
*/
# ifndef TransportProcessor_h
# define TransportProcessor_h
# include <Arduino.h>
# include <Ethernet.h>
# include <WiFiEspAT.h>
2020-10-26 10:29:40 +01:00
# include "NetworkConfig.h"
# include "NetworkInterface.h"
2020-10-23 21:30:56 +02:00
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
2020-10-22 19:25:20 +02:00
UNKNOWN_PROTOCOL
} appProtocol ;
2020-10-26 10:29:40 +01:00
// Needed forward declarations
2020-10-22 19:25:20 +02:00
struct Connection ;
2020-10-26 10:29:40 +01:00
class TransportProcessor ;
using appProtocolCallback = void ( * ) ( Connection * c , TransportProcessor * t ) ;
2020-10-22 19:25:20 +02:00
2020-10-23 21:30:56 +02:00
struct Connection
{
2020-10-27 21:33:16 +01:00
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
2020-10-22 19:25:20 +02:00
} ;
2020-10-23 21:30:56 +02:00
class TransportProcessor
2020-10-22 19:25:20 +02:00
{
2020-10-23 21:30:56 +02:00
private :
# ifdef DCCEX_ENABLED
2020-10-26 10:29:40 +01:00
void sendToDCC ( Connection * c , TransportProcessor * t , bool blocking ) ;
2020-10-23 21:30:56 +02:00
# endif
2020-10-22 19:25:20 +02:00
public :
2020-10-26 10:29:40 +01:00
NetworkInterface * nwi ;
uint8_t buffer [ MAX_ETH_BUFFER ] ;
char command [ MAX_JMRI_CMD ] ;
2020-10-23 21:30:56 +02:00
void readStream ( Connection * c ) ; // reads incomming packets and hands over to the commandHandle for taking the stream apart for commands
2020-10-22 19:25:20 +02:00
TransportProcessor ( ) { } ;
~ TransportProcessor ( ) { } ;
} ;
# endif // !Transport_h