From a1accec79af3b83f77db3f2e41cba5ae318190e2 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 13 Dec 2023 10:55:58 +0100 Subject: [PATCH 1/3] add repeats to function packets that are not reminded in accordance with accessory packets --- DCC.cpp | 26 ++++++++++++++++---------- DCC.h | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index 60c07df..0c5148a 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -122,7 +122,7 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) { DCCWaveform::mainTrack.schedulePacket(b, nB, 0); } -void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) { +void DCC::setFunctionInternal(int cab, byte byte1, byte byte2, byte count) { // DIAG(F("setFunctionInternal %d %x %x"),cab,byte1,byte2); byte b[4]; byte nB = 0; @@ -133,7 +133,7 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) { if (byte1!=0) b[nB++] = byte1; b[nB++] = byte2; - DCCWaveform::mainTrack.schedulePacket(b, nB, 0); + DCCWaveform::mainTrack.schedulePacket(b, nB, count); } // returns speed steps 0 to 127 (1 == emergency stop) @@ -619,33 +619,39 @@ bool DCC::issueReminder(int reg) { break; case 1: // remind function group 1 (F0-F4) if (flags & FN_GROUP_1) - setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4)); // 100D DDDD -#ifdef DISABLE_FUNCTION_REMINDERS +#ifndef DISABLE_FUNCTION_REMINDERS + setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4),0); // 100D DDDD +#else + setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4),2); flags&= ~FN_GROUP_1; // dont send them again #endif break; case 2: // remind function group 2 F5-F8 if (flags & FN_GROUP_2) - setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F)); // 1011 DDDD -#ifdef DISABLE_FUNCTION_REMINDERS +#ifndef DISABLE_FUNCTION_REMINDERS + setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F),0); // 1011 DDDD +#else + setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F),2); flags&= ~FN_GROUP_2; // dont send them again #endif break; case 3: // remind function group 3 F9-F12 if (flags & FN_GROUP_3) - setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F)); // 1010 DDDD -#ifdef DISABLE_FUNCTION_REMINDERS +#ifndef DISABLE_FUNCTION_REMINDERS + setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F),0); // 1010 DDDD +#else + setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F),2); flags&= ~FN_GROUP_3; // dont send them again #endif break; case 4: // remind function group 4 F13-F20 if (flags & FN_GROUP_4) - setFunctionInternal(loco,222, ((functions>>13)& 0xFF)); + setFunctionInternal(loco,222, ((functions>>13)& 0xFF),2); flags&= ~FN_GROUP_4; // dont send them again break; case 5: // remind function group 5 F21-F28 if (flags & FN_GROUP_5) - setFunctionInternal(loco,223, ((functions>>21)& 0xFF)); + setFunctionInternal(loco,223, ((functions>>21)& 0xFF),2); flags&= ~FN_GROUP_5; // dont send them again break; } diff --git a/DCC.h b/DCC.h index 74b4e77..3bf0cf5 100644 --- a/DCC.h +++ b/DCC.h @@ -109,7 +109,7 @@ private: static byte loopStatus; static void setThrottle2(uint16_t cab, uint8_t speedCode); static void updateLocoReminder(int loco, byte speedCode); - static void setFunctionInternal(int cab, byte fByte, byte eByte); + static void setFunctionInternal(int cab, byte fByte, byte eByte, byte count); static bool issueReminder(int reg); static int lastLocoReminder; static int highestUsedReg; From 18116a391c5fa0a54c58fc976b1872157e927dd5 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 13 Dec 2023 11:40:15 +0100 Subject: [PATCH 2/3] move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions --- CommandDistributor.cpp | 4 ++-- DCCEXParser.cpp | 2 -- EXRAIL2.cpp | 5 ----- TrackManager.cpp | 8 ++++++++ WiThrottle.cpp | 2 -- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 6770e7a..e8404de 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -283,7 +283,7 @@ void CommandDistributor::broadcastPower() { //DIAG(F("m=%d p=%d j=%d"), main, prog, join); const FSH * reason=F(""); if (join) { - reason = F("JOIN"); + reason = F(" JOIN"); // with space at start so we can append without space broadcastReply(COMMAND_TYPE, F("\n"),reason); } else { if (main) { @@ -303,7 +303,7 @@ void CommandDistributor::broadcastPower() { broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state); #endif - LCD(2,F("Power %S %S"),state=='1'?F("On"): ( state=='0'? F("Off") : F("SC") ),reason); + LCD(2,F("Power %S%S"),state=='1'?F("On"): ( state=='0'? F("Off") : F("SC") ),reason); } void CommandDistributor::broadcastRaw(clientType type, char * msg) { diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index f3cdfb2..aefed4c 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -587,7 +587,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) } else break; // will reply } - CommandDistributor::broadcastPower(); //TrackManager::streamTrackState(NULL,t); return; @@ -619,7 +618,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) } else break; // will reply } - CommandDistributor::broadcastPower(); return; } diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 3e55620..cc3269b 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -414,7 +414,6 @@ void RMFT2::driveLoco(byte speed) { power on appropriate track if DC or main if dcc if (TrackManager::getMainPowerMode()==POWERMODE::OFF) { TrackManager::setMainPower(POWERMODE::ON); - CommandDistributor::broadcastPower(); } **********/ @@ -642,7 +641,6 @@ void RMFT2::loop2() { case OPCODE_POWEROFF: TrackManager::setPower(POWERMODE::OFF); TrackManager::setJoin(false); - CommandDistributor::broadcastPower(); break; case OPCODE_SET_POWER: @@ -837,12 +835,10 @@ void RMFT2::loop2() { case OPCODE_JOIN: TrackManager::setPower(POWERMODE::ON); TrackManager::setJoin(true); - CommandDistributor::broadcastPower(); break; case OPCODE_UNJOIN: TrackManager::setJoin(false); - CommandDistributor::broadcastPower(); break; case OPCODE_READ_LOCO1: // READ_LOCO is implemented as 2 separate opcodes @@ -870,7 +866,6 @@ void RMFT2::loop2() { case OPCODE_POWERON: TrackManager::setMainPower(POWERMODE::ON); TrackManager::setJoin(false); - CommandDistributor::broadcastPower(); break; case OPCODE_START: diff --git a/TrackManager.cpp b/TrackManager.cpp index 7d2b36b..4a501a1 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -489,10 +489,13 @@ std::vectorTrackManager::getMainDrivers() { // Set track power for all tracks with this mode void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermode) { + bool didChange=false; FOR_EACH_TRACK(t) { MotorDriver *driver=track[t]; TRACK_MODE trackmodeOfTrack = driver->getMode(); if (trackmodeToMatch & trackmodeOfTrack) { + if (powermode != driver->getPower()) + didChange=true; if (powermode == POWERMODE::ON) { if (trackmodeOfTrack & TRACK_MODE_DC) { driver->setBrake(true); // DC starts with brake on @@ -507,12 +510,15 @@ void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermod driver->setPower(powermode); } } + if (didChange) + CommandDistributor::broadcastPower(); } // Set track power for this track, inependent of mode void TrackManager::setTrackPower(POWERMODE powermode, byte t) { MotorDriver *driver=track[t]; TRACK_MODE trackmode = driver->getMode(); + POWERMODE oldpower = driver->getPower(); if (trackmode & TRACK_MODE_NONE) { driver->setBrake(true); // Track is unused. Brake is good to have. powermode = POWERMODE::OFF; // Track is unused. Force it to OFF @@ -530,6 +536,8 @@ void TrackManager::setTrackPower(POWERMODE powermode, byte t) { } } driver->setPower(powermode); + if (oldpower != driver->getPower()) + CommandDistributor::broadcastPower(); } // returns state of the one and only prog track diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 4eb0a25..244dfd8 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -150,7 +150,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) { DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF); */ - CommandDistributor::broadcastPower(); } #if defined(EXRAIL_ACTIVE) else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate @@ -496,7 +495,6 @@ void WiThrottle::getLocoCallback(int16_t locoid) { TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away DIAG(F("LocoCallback commit success")); stashStream->commit(); - CommandDistributor::broadcastPower(); } void WiThrottle::sendIntro(Print* stream) { From 1881d4c9ad0c5e2eeba2ef1643dd7ead1f5de7ed Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 13 Dec 2023 11:41:57 +0100 Subject: [PATCH 3/3] version 5.2.15 --- GITHUB_SHA.h | 2 +- version.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 23c6a6e..0a5110a 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202311270714Z" +#define GITHUB_SHA "devel-202312131041Z" diff --git a/version.h b/version.h index a6265d8..b74cbd2 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.14" +#define VERSION "5.2.15" +// 5.2.15 - move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions +// - add repeats to function packets that are not reminded in accordance with accessory packets // 5.2.14 - Reminder window DCC packet optimization // - Optional #define DISABLE_FUNCTION_REMINDERS // 5.2.13 - EXRAIL STEALTH