From a355cc74a06539e80fa7c7c04a594b81994c3710 Mon Sep 17 00:00:00 2001 From: Gregor Baues Date: Mon, 26 Oct 2020 10:52:47 +0100 Subject: [PATCH] BugFix + DCC_ENABLED set not replying but ok --- CommandStation-EX.ino | 6 +++--- MotorDrivers.h | 2 +- TransportProcessor.cpp | 36 +++++++++++++++++++++--------------- TransportProcessor.h | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 402da2b..1d8a001 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -18,7 +18,7 @@ DCCEXParser serialParser; // (0) Declare NetworkInterfaces -NetworkInterface wifi; +// NetworkInterface wifi; NetworkInterface eth; // (0) Declared NetworkInterfaces @@ -70,7 +70,7 @@ void setup() DIAG(F("\nFree RAM before network init: [%d]\n"),freeMemory()); DIAG(F("\nNetwork Setup In Progress ...\n")); - wifi.setup(WIFI); // WIFI, TCP on Port 2560 + // wifi.setup(WIFI); // WIFI, TCP on Port 2560 eth.setup(ETHERNET, TCP, 8888); // ETHERNET, TCP on Port 8888 eth.setHttpCallback(httpRequestHandler); // HTTP callback @@ -100,7 +100,7 @@ void loop() // (3) Start Loop NetworkInterface - wifi.loop(); + // wifi.loop(); eth.loop(); // (3) End Loop NetworkInterface diff --git a/MotorDrivers.h b/MotorDrivers.h index 3695e0a..ffd84eb 100644 --- a/MotorDrivers.h +++ b/MotorDrivers.h @@ -21,7 +21,7 @@ const byte UNUSED_PIN = 255; // Arduino standard Motor Shield #define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \ new MotorDriver(3, 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN), \ - new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, 2000, UNUSED_PIN) + new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A2, 2.99, 2000, UNUSED_PIN) // Pololu Motor Shield #define POLOLU_MOTOR_SHIELD F("POLOLU_MOTOR_SHIELD"), \ diff --git a/TransportProcessor.cpp b/TransportProcessor.cpp index b778add..7a3b058 100644 --- a/TransportProcessor.cpp +++ b/TransportProcessor.cpp @@ -52,25 +52,30 @@ uint8_t diagNetworkClient = 0; void sendToDCC(Connection *c, TransportProcessor* t, bool blocking) { - static MemStream *streamer = new MemStream((byte *)command, MAX_ETH_BUFFER, MAX_ETH_BUFFER, true); + char * _command = t->command; - DIAG(F("DCC parsing: [%e]\n"), command); + static MemStream *streamer = new MemStream((byte *)_command, MAX_ETH_BUFFER, MAX_ETH_BUFFER, true); + + DIAG(F("DCC parsing: [%e]\n"), _command); // as we use buffer for recv and send we have to reset the write position streamer->setBufferContentPosition(0, 0); - ethParser.parse(streamer, (byte *)t->command, true); // set to true to that the execution in DCC is sync + ethParser.parse(streamer, (byte *)_command, true); // set to true to that the execution in DCC is sync if (streamer->available() == 0) { - DIAG(F("No response\n")); + if (c->client->connected()) + { + c->client->write((byte *)F("No response\n"), streamer->available()); + } } else { - command[streamer->available()] = '\0'; // mark end of buffer, so it can be used as a string later - DIAG(F("Response: %s\n"), t->command); + _command[streamer->available()] = '\0'; // mark end of buffer, so it can be used as a string later + DIAG(F("Response: %s\n"), _command); if (c->client->connected()) { - c->client->write((byte *)t->command, streamer->available()); + c->client->write((byte *)_command, streamer->available()); } } } @@ -252,16 +257,17 @@ appProtocol setAppProtocol(char a, char b, Connection *c) void processStream(Connection *c, TransportProcessor *t) { uint8_t i, j, k, l = 0; - uint8_t *_buffer = t->buffer; + uint8_t* _buffer = t->buffer; + char* _command = t->command; DIAG(F("\nBuffer: [%e]\n"), _buffer); - memset(t->command, 0, MAX_JMRI_CMD); // clear out the command + memset(_command, 0, MAX_JMRI_CMD); // clear out the command // copy overflow into the command if ((i = strlen(c->overflow)) != 0) { // DIAG(F("\nCopy overflow to command: %e"), c->overflow); - strncpy(t->command, c->overflow, i); + strncpy(_command, c->overflow, i); k = i; } // reset the overflow @@ -290,21 +296,21 @@ void processStream(Connection *c, TransportProcessor *t) } // breakup the buffer using its changed length i = 0; - k = strlen(t->command); // current length of the command buffer telling us where to start copy in + k = strlen(_command); // current length of the command buffer telling us where to start copy in l = strlen((char *)_buffer); // DIAG(F("\nCommand buffer: [%s]:[%d:%d:%d]\n"), command, i, l, k ); while (i < l) { // DIAG(F("\nl: %d k: %d , i: %d"), l, k, i); - t->command[k] = _buffer[i]; + _command[k] = _buffer[i]; if (_buffer[i] == c->delimiter) { // closing bracket need to fix if there is none before an opening bracket ? - t->command[k + 1] = '\0'; + _command[k + 1] = '\0'; - DIAG(F("Command: [%d:%e]\n"), _rseq[c->id], t->command); + DIAG(F("Command: [%d:%e]\n"), _rseq[c->id], _command); #ifdef DCCEX_ENABLED - sendToDCC(c, command, true); + sendToDCC(c, t, true); #else sendReply(c, t); #endif diff --git a/TransportProcessor.h b/TransportProcessor.h index b68bed4..de5759c 100644 --- a/TransportProcessor.h +++ b/TransportProcessor.h @@ -26,7 +26,7 @@ #include "NetworkConfig.h" #include "NetworkInterface.h" -// #define DCCEX_ENABLED +#define DCCEX_ENABLED typedef enum {