mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
Ethernet UDP working
This commit is contained in:
parent
6d7d01b1b5
commit
34fe1256e7
|
@ -82,7 +82,7 @@ void setup()
|
|||
|
||||
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
|
||||
// eth2.setup(ETHERNET, TCP, 23); // ETHERNET, TCP on Port 23 for the CLI
|
||||
// eth1.setup(ETHERNET, TCP, 8888); // ETHERNET, TCP on Port 8888
|
||||
// wifi.setup(WIFI, TCP); // WIFI on Port 2560
|
||||
// eth1.setHttpCallback(httpRequestHandler); // HTTP callback
|
||||
|
|
|
@ -73,7 +73,7 @@ byte EthernetSetup::setup()
|
|||
}
|
||||
else
|
||||
{
|
||||
ERR(F("\nUDP failed to start"));
|
||||
ERR(F("UDP failed to start"));
|
||||
connected = false;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -27,12 +27,15 @@ extern uint8_t diagNetworkClient;
|
|||
|
||||
template<class S, class C, class U>
|
||||
bool Transport<S,C,U>::setup(NetworkInterface *nw) {
|
||||
t = new TransportProcessor();
|
||||
|
||||
if (protocol == TCP) {
|
||||
connectionPool(server); // server should have started here so create the connection pool only for TCP though
|
||||
t->udp = 0;
|
||||
} else {
|
||||
connectionPool(udp);
|
||||
t->udp = udp;
|
||||
}
|
||||
t = new TransportProcessor();
|
||||
t->nwi = nw; // The TransportProcessor needs to know which Interface he is connected to
|
||||
connected = true; // server & clients which will recieve/send data have all e setup and are available
|
||||
return true;
|
||||
|
@ -49,7 +52,7 @@ void Transport<S,C,U>::loop() {
|
|||
};
|
||||
case TCP:
|
||||
{
|
||||
DBG(F("Transport: %s\n"), this->transport == WIFI ? "WIFI" : "ETHERNET");
|
||||
DBG(F("Transport: %s"), this->transport == WIFI ? "WIFI" : "ETHERNET");
|
||||
tcpSessionHandler(server);
|
||||
};
|
||||
case MQTT:
|
||||
|
@ -69,7 +72,7 @@ void Transport<S, C, U>::connectionPool(S *server)
|
|||
connections[i].client = &clients[i];
|
||||
memset(connections[i].overflow, 0, MAX_OVERFLOW);
|
||||
connections[i].id = i;
|
||||
TRC(F("\nTCP Connection pool: [%d:%x]"), i, connections[i].client);
|
||||
TRC(F("TCP Connection pool: [%d:%x]"), i, connections[i].client);
|
||||
}
|
||||
}
|
||||
template<class S, class C, class U>
|
||||
|
@ -82,7 +85,7 @@ void Transport<S, C, U>::connectionPool(U *udp)
|
|||
memset(connections[i].overflow, 0, MAX_OVERFLOW);
|
||||
connections[i].id = i;
|
||||
|
||||
TRC(F("\nUDP Connection pool: [%d:%x]"), i, connections[i].client);
|
||||
TRC(F("UDP Connection pool: [%d:%x]"), i, udp);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -99,7 +102,7 @@ void Transport<S, C, U>::udpHandler(U* udp)
|
|||
int packetSize = udp->parsePacket();
|
||||
if (packetSize > 0)
|
||||
{
|
||||
TRC(F("\nReceived packet of size:[%d]"), packetSize);
|
||||
TRC(F("Received packet of size:[%d]"), packetSize);
|
||||
IPAddress remote = udp->remoteIP();
|
||||
char portBuffer[6];
|
||||
TRC(F("From: [%d.%d.%d.%d: %s]"), remote[0], remote[1], remote[2], remote[3], utoa(udp->remotePort(), portBuffer, 10)); // DIAG has issues with unsigend int's so go through utoa
|
||||
|
|
|
@ -59,23 +59,28 @@ RingStream streamer(512); // buffer into which to feed the commands for handling
|
|||
|
||||
void sendWiThrottleToDCC(Connection *c, TransportProcessor *t, bool blocking)
|
||||
{
|
||||
// streamer.printStream();
|
||||
|
||||
byte *_buffer = streamer.getBuffer();
|
||||
memset(_buffer, 0, 512); // clear out the _buffer
|
||||
WiThrottle *wt = WiThrottle::getThrottle(c->id); // get a throttle for the Connection; will be created if it doesn't exist
|
||||
|
||||
// STRINGIFY(__FILE__);
|
||||
DBG(F("WiThrottle [%x:%x] parsing: [%e]"), wt, _buffer, t->command);
|
||||
TRC(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)
|
||||
{
|
||||
dumpRingStreamBuffer(_buffer, 512);
|
||||
if (c->client->connected())
|
||||
{
|
||||
TRC(F("UDP %x"), t->udp);
|
||||
|
||||
if ( t->udp != 0) {
|
||||
TRC(F("Sending UDP WiThrottle response ..."));
|
||||
t->udp->beginPacket(t->udp->remoteIP(), t->udp->remotePort());
|
||||
t->udp->write(_buffer, strlen((char *)_buffer));
|
||||
t->udp->endPacket();
|
||||
} else if (c->client->connected()) {
|
||||
c->client->write(_buffer, strlen((char *)_buffer));
|
||||
}
|
||||
}
|
||||
// streamer.printStream();
|
||||
streamer.resetStream();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,9 @@ private:
|
|||
void sendToDCC(Connection *c, TransportProcessor* t, bool blocking);
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
UDP *udp; // need to carry the single UDP server instance over to the processor for sending packest
|
||||
NetworkInterface *nwi;
|
||||
uint8_t buffer[MAX_ETH_BUFFER];
|
||||
char command[MAX_JMRI_CMD];
|
||||
|
|
Loading…
Reference in New Issue
Block a user