From 31f89ad4c4701c3137dca6826f81adb3b4c22f33 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Fri, 28 Mar 2025 22:47:13 +0100 Subject: [PATCH] Added broadcast for (extended) accessory commands. see: https://github.com/DCC-EX/CommandStation-EX/issues/444 --- CommandDistributor.cpp | 8 ++++++++ CommandDistributor.h | 2 ++ DCC.cpp | 3 +++ DCCEXParser.cpp | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index cdfbe2d..d64e19e 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -152,6 +152,14 @@ void CommandDistributor::broadcastSensor(int16_t id, bool on ) { broadcastReply(COMMAND_TYPE, F("<%c %d>\n"), on?'Q':'q', id); } +void CommandDistributor::broadcastAccessory(int16_t address, byte port, bool gate, bool on) { + broadcastReply(COMMAND_TYPE, F("\n"), address, port, gate?'1':'0', on?'1':'0'); +} + +void CommandDistributor::broadcastExtendedAccessory(int16_t address, int16_t value) { + broadcastReply(COMMAND_TYPE, F("\n"), address, value); +} + void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) { // For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed; // The string below contains serial and Withrottle protocols which should diff --git a/CommandDistributor.h b/CommandDistributor.h index d86b87f..308e8f7 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -49,6 +49,8 @@ public : static void broadcastLoco(byte slot); static void broadcastForgetLoco(int16_t loco); static void broadcastSensor(int16_t id, bool value); + static void broadcastAccessory(int16_t address, byte port, bool gate, bool on); + static void broadcastExtendedAccessory(int16_t address, int16_t value); static void broadcastTurnout(int16_t id, bool isClosed); static void broadcastTurntable(int16_t id, uint8_t position, bool moving); static void broadcastClockTime(int16_t time, int8_t rate); diff --git a/DCC.cpp b/DCC.cpp index a5eafec..5ebb108 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -307,10 +307,12 @@ void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) { #if defined(EXRAIL_ACTIVE) RMFT2::activateEvent(address<<2|port,gate); #endif + CommandDistributor::broadcastAccessory(address, port, gate, true); } if (onoff != 1) { b[1] &= ~0x08; // set C to 0 DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat off packet three times + CommandDistributor::broadcastAccessory(address, port, gate, false); } } @@ -362,6 +364,7 @@ whole range of the 11 bits sent to track. | ((address & 0x03)<<1); // mask 2 bits, shift up 1 b[2]=value; DCCWaveform::mainTrack.schedulePacket(b, sizeof(b), repeats); + CommandDistributor::broadcastExtendedAccessory(address, value); return true; } diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 6bec5fb..219bd5e 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -92,7 +92,7 @@ Once a new OPCODE is decided upon, update this list. W, Write CV x, X, Invalid command response - y, + y, Accessory/extended accessory broadcast Y, Output broadcast z, Direct output Z, Output configuration/control