From 8f584a4dbc5ec5f192b34fbe33d9d74a034ec180 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Thu, 20 Oct 2022 23:02:28 +0200 Subject: [PATCH] loconet: report warning if slot isn't usable, stop sending fast clock sync if slot isn't usable --- .../src/hardware/protocol/loconet/kernel.cpp | 29 ++++++++++++++++++- .../src/hardware/protocol/loconet/kernel.hpp | 1 + .../hardware/protocol/loconet/settings.cpp | 18 +++++++++++- shared/src/traintastic/enum/logmessage.hpp | 3 ++ shared/translations/en-us.txt | 3 ++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/server/src/hardware/protocol/loconet/kernel.cpp b/server/src/hardware/protocol/loconet/kernel.cpp index 9cc5a8d2..b6b570db 100644 --- a/server/src/hardware/protocol/loconet/kernel.cpp +++ b/server/src/hardware/protocol/loconet/kernel.cpp @@ -518,6 +518,33 @@ void Kernel::receive(const Message& message) Log::log(m_logId, LogMessage::C2004_CANT_GET_FREE_SLOT); }); } + else if(longAck.respondingOpCode() == OPC_RQ_SL_DATA && longAck.ack1 == 0 && lastSentMessage().opCode == OPC_RQ_SL_DATA) + { + const uint8_t slot = static_cast(lastSentMessage()).slot; + + if(isLocoSlot(slot)) + { + EventLoop::call( + [this, slot]() + { + Log::log(m_logId, LogMessage::W2006_COMMAND_STATION_DOES_NOT_SUPPORT_LOCO_SLOT_X, slot); + }); + } + else if(slot == SLOT_FAST_CLOCK) + { + m_fastClockSupported = false; + if(m_config.fastClockSyncEnabled) + stopFastClockSyncTimer(); + + EventLoop::call( + [this, stoppedFastClockSyncTimer=m_config.fastClockSyncEnabled]() + { + Log::log(m_logId, LogMessage::W2007_COMMAND_STATION_DOES_NOT_SUPPORT_THE_FAST_CLOCK_SLOT); + if(stoppedFastClockSyncTimer) + Log::log(m_logId, LogMessage::N2003_STOPPED_SENDING_FAST_CLOCK_SYNC); + }); + } + } else if(m_lncvActive && m_onLNCVReadResponse && longAck.respondingOpCode() == OPC_IMM_PACKET && longAck.ack1 == 0x7F && Uhlenbrock::LNCVWrite::check(lastSentMessage())) @@ -1120,7 +1147,7 @@ void Kernel::stopFastClockSyncTimer() void Kernel::fastClockSyncTimerExpired(const boost::system::error_code& ec) { - if(ec || !m_config.fastClockSyncEnabled) + if(ec || !m_config.fastClockSyncEnabled || !m_fastClockSupported) return; send(RequestSlotData(SLOT_FAST_CLOCK)); diff --git a/server/src/hardware/protocol/loconet/kernel.hpp b/server/src/hardware/protocol/loconet/kernel.hpp index b0bd0507..e95c049d 100644 --- a/server/src/hardware/protocol/loconet/kernel.hpp +++ b/server/src/hardware/protocol/loconet/kernel.hpp @@ -141,6 +141,7 @@ class Kernel std::function m_onIdle; boost::asio::steady_timer m_fastClockSyncTimer; + bool m_fastClockSupported = true; bool m_lncvActive = false; uint16_t m_lncvModuleId = 0; diff --git a/server/src/hardware/protocol/loconet/settings.cpp b/server/src/hardware/protocol/loconet/settings.cpp index fc3cf741..d85a07bf 100644 --- a/server/src/hardware/protocol/loconet/settings.cpp +++ b/server/src/hardware/protocol/loconet/settings.cpp @@ -57,6 +57,7 @@ Settings::Settings(Object& _parent, std::string_view parentPropertyName) Attributes::addMinMax(locomotiveSlots, SLOT_LOCO_MIN, SLOT_LOCO_MAX); m_interfaceItems.add(locomotiveSlots); + Attributes::addEnabled(fastClockSyncEnabled, true); //Attributes::addGroup(fastClockSyncEnabled, Group::fastClockSync); m_interfaceItems.add(fastClockSyncEnabled); @@ -109,6 +110,7 @@ void Settings::commandStationChanged(LocoNetCommandStation value) { const bool isCustom = (value == LocoNetCommandStation::Custom); + // locomotive slots: switch(value) { case LocoNetCommandStation::Custom: @@ -123,8 +125,22 @@ void Settings::commandStationChanged(LocoNetCommandStation value) locomotiveSlots = 32; break; } - Attributes::setEnabled(locomotiveSlots, isCustom); + + // fast clock: + switch(value) + { + case LocoNetCommandStation::Custom: + case LocoNetCommandStation::DigikeijsDR5000: + Attributes::setEnabled(fastClockSyncEnabled, true); + break; + + case LocoNetCommandStation::UhlenbrockIntellibox: + case LocoNetCommandStation::UhlenbrockIBCOM: + fastClockSyncEnabled = false; + Attributes::setEnabled(fastClockSyncEnabled, false); + break; + } } } diff --git a/shared/src/traintastic/enum/logmessage.hpp b/shared/src/traintastic/enum/logmessage.hpp index 4aeec5d8..08752f5f 100644 --- a/shared/src/traintastic/enum/logmessage.hpp +++ b/shared/src/traintastic/enum/logmessage.hpp @@ -110,6 +110,7 @@ enum class LogMessage : uint32_t N1026_IMPORTED_WORLD_SUCCESSFULLY = LogMessageOffset::notice + 1026, N2001_SIMULATION_NOT_SUPPORTED = LogMessageOffset::notice + 2001, N2002_NO_RESPONSE_FROM_LNCV_MODULE_X_WITH_ADDRESS_X = LogMessageOffset::notice + 2002, + N2003_STOPPED_SENDING_FAST_CLOCK_SYNC = LogMessageOffset::notice + 2003, N9001_STARTING_SCRIPT = LogMessageOffset::notice + 9001, N9999_X = LogMessageOffset::notice + 9999, @@ -122,6 +123,8 @@ enum class LogMessage : uint32_t W2003_COMMAND_STATION_DOESNT_SUPPORT_X_SPEEDSTEPS_USING_X = LogMessageOffset::warning + 2003, W2004_INPUT_ADDRESS_X_IS_INVALID = LogMessageOffset::warning + 2004, W2005_OUTPUT_ADDRESS_X_IS_INVALID = LogMessageOffset::warning + 2005, + W2006_COMMAND_STATION_DOES_NOT_SUPPORT_LOCO_SLOT_X = LogMessageOffset::warning + 2006, + W2007_COMMAND_STATION_DOES_NOT_SUPPORT_THE_FAST_CLOCK_SLOT = LogMessageOffset::warning + 2007, W2018_TIMEOUT_NO_ECHO_WITHIN_X_MS = LogMessageOffset::warning + 2018, W9999_X = LogMessageOffset::warning + 9999, diff --git a/shared/translations/en-us.txt b/shared/translations/en-us.txt index 6391e3bc..5e3e79db 100644 --- a/shared/translations/en-us.txt +++ b/shared/translations/en-us.txt @@ -392,6 +392,7 @@ message:N1025=Exported world successfully message:N1026=Imported world successfully message:N2001=Simulation not supported message:N2002=No response from LNCV module %1 with address %2 +message:N2003=Stopped sending fast clock sync message:N9001=Starting script message:N9999=%1 message:W1001=Discovery disabled, only allowed on port %1 @@ -402,6 +403,8 @@ message:W2002=Command station doesn't support functions above F%1 message:W2003=Command station doesn't support %1 speedsteps using %2 message:W2004=Input address %1 is invalid message:W2005=Output address %1 is invalid +message:W2006=Command station does not support loco slot %1 +message:W2007=Command station does not support the fast clock slot message:W2018=Timeout, no echo within %1ms message:W9999=%1