diff --git a/library.properties b/library.properties index e2fcdf9..740ad30 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=DCCEXProtocol -version=0.0.10 +version=0.0.11 author=Peter Cole, Peter Akers maintainer=Peter Cole, Peter Akers sentence=DCC-EX Native Protocol implementation diff --git a/src/DCCEXProtocol.cpp b/src/DCCEXProtocol.cpp index 471e0a6..0d16ec5 100644 --- a/src/DCCEXProtocol.cpp +++ b/src/DCCEXProtocol.cpp @@ -97,6 +97,8 @@ void DCCEXProtocol::check() { if (r=='>') { if (DCCEXInbound::parse(_cmdBuffer)) { // Process stuff here + _console->print("<== "); + _console->println(_cmdBuffer); _processCommand(); } // Clear buffer after use @@ -560,7 +562,7 @@ void DCCEXProtocol::_processCommand() { break; case 'p': // Power broadcast - if (DCCEXInbound::isTextParameter(0) || DCCEXInbound::getParameterCount()!=1) break; + if (DCCEXInbound::isTextParameter(0) || DCCEXInbound::getParameterCount()>2) break; _processTrackPower(); break; @@ -1111,7 +1113,7 @@ void DCCEXProtocol::_processTurntableBroadcast() { // // Track management methods void DCCEXProtocol::_processTrackPower() { - // console->println(F("processTrackPower()")); + // _console->println(F("processTrackPower()")); if (_delegate) { TrackPower state = PowerUnknown; if (DCCEXInbound::getNumber(0)==PowerOff) { @@ -1119,9 +1121,20 @@ void DCCEXProtocol::_processTrackPower() { } else if (DCCEXInbound::getNumber(0)==PowerOn) { state = PowerOn; } + // _console->print(F("processTrackPower(): state: ")); + // _console->println(state); + + if (DCCEXInbound::getParameterCount()==2) { + int _track = DCCEXInbound::getNumber(1); + // _console->print("processTrackPower(): 2nd : "); + // _console->println(_track); + _delegate->receivedIndividualTrackPower(state,_track); + + if (DCCEXInbound::getNumber(1) != 2698315) { return;} // not equal "MAIN" + } _delegate->receivedTrackPower(state); } - // console->println(F("processTrackPower(): end")); + // _console->print(F("processTrackPower(): end")); } void DCCEXProtocol::_processTrackType() { diff --git a/src/DCCEXProtocol.h b/src/DCCEXProtocol.h index efbcf56..4d78c65 100644 --- a/src/DCCEXProtocol.h +++ b/src/DCCEXProtocol.h @@ -31,6 +31,8 @@ /* Version information: +0.0.11 - support for individual track power receivedIndividualTrackPower(TrackPower state, int track) + - imporved logic for overall track power 0.0.10 - Add support for broadcast messages 0.0.9 - if loco is selected by address and that loco is in the roster (with the same DCC Address), updated and send speed commands for both 0.0.8 - No functional changes, add cross-platform and unit testing capabilities (credit to higaski) @@ -140,10 +142,15 @@ class DCCEXProtocolDelegate { /// @param loco Pointer to the loco object virtual void receivedLocoUpdate(Loco* loco) {} - /// @brief Notify when a track power state change is received + /// @brief Notify when the global track power state change is received /// @param state Power state received (PowerOff|PowerOn|PowerUnknown) virtual void receivedTrackPower(TrackPower state) {} + /// @brief Notify when an individual track power state change is received + /// @param state Power state received (PowerOff|PowerOn|PowerUnknown) + /// @param track which track changed 65=A..72=H | 2698315=MAIN | 2788330=PROG | 2183=DC | 71999=DCX + virtual void receivedIndividualTrackPower(TrackPower state, int track) {} + /// @brief Notify when a track type change is received /// @param track track that changed /// @param type type received (MAIN|PROG|DC|DCX|NONE)