1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 23:56:13 +01:00

BugFix + DCC_ENABLED set <s> not replying but <R> ok

This commit is contained in:
Gregor Baues 2020-10-26 10:52:47 +01:00
parent 77f0b99f8d
commit a355cc74a0
4 changed files with 26 additions and 20 deletions

View File

@ -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

View File

@ -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"), \

View File

@ -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

View File

@ -26,7 +26,7 @@
#include "NetworkConfig.h"
#include "NetworkInterface.h"
// #define DCCEX_ENABLED
#define DCCEX_ENABLED
typedef enum
{