From b05cbc1fdf43327ccfe33394affd26cd951a2da0 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Mon, 20 Dec 2021 10:36:17 +0000 Subject: [PATCH 1/2] Correct <+> command any serial --- DCCEXParser.cpp | 2 +- DCCEXParser.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 38bac2f..fcbf28c 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -550,7 +550,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) if (atCommandCallback && !ringStream) { DCCWaveform::mainTrack.setPowerMode(POWERMODE::OFF); DCCWaveform::progTrack.setPowerMode(POWERMODE::OFF); - atCommandCallback(stream,com); + atCommandCallback((HardwareSerial *)stream,com); return; } break; diff --git a/DCCEXParser.h b/DCCEXParser.h index 6baeeaa..c298908 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -23,7 +23,7 @@ #include "RingStream.h" typedef void (*FILTER_CALLBACK)(Print * stream, byte & opcode, byte & paramCount, int16_t p[]); -typedef void (*AT_COMMAND_CALLBACK)(Print * stream,const byte * command); +typedef void (*AT_COMMAND_CALLBACK)(HardwareSerial * stream,const byte * command); struct DCCEXParser { From 0912ad484a8d7ff3a0ffaaae49738a61369d701d Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 21 Dec 2021 09:14:27 +0000 Subject: [PATCH 2/2] less broadcast noise Avoids erroneous broadcast of all slots with no loco on ESTOP. Avoids sending states and to withrottles --- CommandDistributor.cpp | 15 +++++++++------ CommandDistributor.h | 2 +- DCC.cpp | 8 ++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 38fafff..a9a98e1 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -55,7 +55,7 @@ void CommandDistributor::forget(byte clientId) { } -void CommandDistributor::broadcast() { +void CommandDistributor::broadcast(bool includeWithrottleClients) { broadcastBufferWriter->write((byte)'\0'); /* Boadcast to Serials */ @@ -70,6 +70,7 @@ void CommandDistributor::broadcast() { /* loop through ring clients */ for (byte clientId=0; clientIdmark(clientId); broadcastBufferWriter->printBuffer(ring); ring->commit(); @@ -84,12 +85,14 @@ void CommandDistributor::broadcast() { // Redirect ring output ditrect to Serial #define broadcastBufferWriter &Serial // and ignore the internal broadcast call. - void CommandDistributor::broadcast() {} + void CommandDistributor::broadcast(bool includeWithrottleClients) { + (void)includeWithrottleClients; + } #endif void CommandDistributor::broadcastSensor(int16_t id, bool on ) { StringFormatter::send(broadcastBufferWriter,F("<%c %d>\n"), on?'Q':'q', id); - broadcast(); + broadcast(false); } void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) { @@ -100,14 +103,14 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) { #if defined(WIFI_ON) | defined(ETHERNET_ON) StringFormatter::send(broadcastBufferWriter,F("PTA%c%d\n"), isClosed?'2':'4', id); #endif - broadcast(); + broadcast(true); } void CommandDistributor::broadcastLoco(byte slot) { DCC::LOCO * sp=&DCC::speedTable[slot]; StringFormatter::send(broadcastBufferWriter,F("\n"), sp->loco,slot,sp->speedCode,sp->functions); - broadcast(); + broadcast(false); #if defined(WIFI_ON) | defined(ETHERNET_ON) WiThrottle::markForBroadcast(sp->loco); #endif @@ -128,7 +131,7 @@ void CommandDistributor::broadcastPower() { StringFormatter::send(broadcastBufferWriter, F("\nPPA%c\n"),state,reason, main?'1':'0'); LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason); - broadcast(); + broadcast(true); } diff --git a/CommandDistributor.h b/CommandDistributor.h index e855e51..43e4fff 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -31,7 +31,7 @@ public : static void broadcastPower(); static void forget(byte clientId); private: - static void broadcast(); + static void broadcast(bool includeWithrottleClients); static RingStream * ring; static RingStream * broadcastBufferWriter; static byte ringClient; diff --git a/DCC.cpp b/DCC.cpp index 4469aa1..f5a6764 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -665,8 +665,12 @@ void DCC::updateLocoReminder(int loco, byte speedCode) { if (loco==0) { // broadcast stop/estop but dont change direction for (int reg = 0; reg < MAX_LOCOS; reg++) { - speedTable[reg].speedCode = (speedTable[reg].speedCode & 0x80) | (speedCode & 0x7f); - CommandDistributor::broadcastLoco(reg); + if (speedTable[reg].loco==0) continue; + byte newspeed=(speedTable[reg].speedCode & 0x80) | (speedCode & 0x7f); + if (speedTable[reg].speedCode != newspeed) { + speedTable[reg].speedCode = newspeed; + CommandDistributor::broadcastLoco(reg); + } } return; }