From f13e4ccae414ca04d5c4b07a1d6e7e93bbc992b5 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Wed, 4 Aug 2021 23:51:51 +0200 Subject: [PATCH] DCC++: added check on load if decoders are configured properly --- .../en-us/messages/critical.md | 15 +++++++++++++ .../en-us/messages/warning.md | 15 +++++++++++++ .../commandstation/commandstation.cpp | 13 ++++++++++++ .../commandstation/commandstation.hpp | 4 +++- .../commandstation/dccplusplusserial.cpp | 6 ++++++ .../commandstation/dccplusplusserial.hpp | 1 + server/src/hardware/decoder/decoder.hpp | 1 + .../protocol/dccplusplus/dccplusplus.cpp | 21 +++++++++++++++++++ .../protocol/dccplusplus/dccplusplus.hpp | 2 ++ 9 files changed, 77 insertions(+), 1 deletion(-) diff --git a/manual/traintasticmanual/en-us/messages/critical.md b/manual/traintasticmanual/en-us/messages/critical.md index 2c79dd15..d64a3940 100644 --- a/manual/traintasticmanual/en-us/messages/critical.md +++ b/manual/traintasticmanual/en-us/messages/critical.md @@ -32,6 +32,21 @@ TODO TODO + +## C2002: DCC++ only supports the DCC protocol {#c2002} + +**Cause:** The selected decoder protocol isn't supported by the DCC++ command station. + +**Solution:** Change the decoder protocol to *DCC* or *Auto*. + + +## C2003: DCC++ doesn't support DCC long addresses below 128 {#c2003} + +**Cause:** The DCC++ command station considers all addresses below 128 a DCC short address. + +**Solution:** Change the locomotive decoder address. + + ## C9999: *message* {#c9999} Custom critical message generated by a [Lua script](../scripting.md). diff --git a/manual/traintasticmanual/en-us/messages/warning.md b/manual/traintasticmanual/en-us/messages/warning.md index abf47c9f..50aa3206 100644 --- a/manual/traintasticmanual/en-us/messages/warning.md +++ b/manual/traintasticmanual/en-us/messages/warning.md @@ -18,6 +18,21 @@ TODO TODO +## W2002: Command station doesn't support functions above F*number* {#w2002} + +**Cause:** The command station or interface can't control these function, e.g. due hardware or protocol limitations. + +**Solution:** Check if command station is setup properly, some command stations have options which specify how to control additional functions. +If not, remapping decoder functions or using a different command station is the only solution. + + +## W2003: Command station doesn't support *number* speed steps, using *number* {#w2003} + +**Cause:** The command station or interface can't control decoders using *number* speed steps, e.g. due hardware or protocol limitations. + +**Solution:** The number of speed steps that can be used is determinded by the command station or interface. Changing the decoders speed steps to *Auto* should usally work. + + ## W9999: *message* {#w9999} Custom warning message generated by a [Lua script](../scripting.md). diff --git a/server/src/hardware/commandstation/commandstation.cpp b/server/src/hardware/commandstation/commandstation.cpp index 1defdeb1..a7aecfbc 100644 --- a/server/src/hardware/commandstation/commandstation.cpp +++ b/server/src/hardware/commandstation/commandstation.cpp @@ -84,6 +84,13 @@ CommandStation::CommandStation(const std::weak_ptr& world, std::string_vi m_interfaceItems.add(notes); } +void CommandStation::loaded() +{ + IdObject::loaded(); + + checkAllDecoders(); +} + void CommandStation::addToWorld() { IdObject::addToWorld(); @@ -159,6 +166,12 @@ void CommandStation::powerOnChanged(bool value) controller->powerOnChanged(value); } +void CommandStation::checkAllDecoders() const +{ + for(const auto& decoder : *decoders) + checkDecoder(*decoder); +} + void CommandStation::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) { for(auto& controller : *controllers) diff --git a/server/src/hardware/commandstation/commandstation.hpp b/server/src/hardware/commandstation/commandstation.hpp index 48347b59..90961229 100644 --- a/server/src/hardware/commandstation/commandstation.hpp +++ b/server/src/hardware/commandstation/commandstation.hpp @@ -37,13 +37,15 @@ class CommandStation : public IdObject friend class ::Decoder; protected: + void loaded() override; void addToWorld() final; void worldEvent(WorldState state, WorldEvent event) override; virtual bool setOnline(bool& value) = 0; virtual void emergencyStopChanged(bool value); virtual void powerOnChanged(bool value); - //virtual bool isDecoderSupported(Decoder& decoder) const = 0; + void checkAllDecoders() const; + virtual void checkDecoder(const Decoder& decoder) const {} virtual void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber); void restoreSpeed(); diff --git a/server/src/hardware/commandstation/dccplusplusserial.cpp b/server/src/hardware/commandstation/dccplusplusserial.cpp index f0ae1258..9d172bd9 100644 --- a/server/src/hardware/commandstation/dccplusplusserial.cpp +++ b/server/src/hardware/commandstation/dccplusplusserial.cpp @@ -52,6 +52,12 @@ void DCCPlusPlusSerial::powerOnChanged(bool value) dccPlusPlus->powerOnChanged(value); } +void DCCPlusPlusSerial::checkDecoder(const Decoder& decoder) const +{ + CommandStation::checkDecoder(decoder); + dccPlusPlus->checkDecoder(decoder); +} + void DCCPlusPlusSerial::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) { CommandStation::decoderChanged(decoder, changes, functionNumber); diff --git a/server/src/hardware/commandstation/dccplusplusserial.hpp b/server/src/hardware/commandstation/dccplusplusserial.hpp index e315f259..7262fe66 100644 --- a/server/src/hardware/commandstation/dccplusplusserial.hpp +++ b/server/src/hardware/commandstation/dccplusplusserial.hpp @@ -31,6 +31,7 @@ class DCCPlusPlusSerial : public SerialCommandStation protected: void emergencyStopChanged(bool value) final; void powerOnChanged(bool value) final; + void checkDecoder(const Decoder& decoder) const; void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) final; bool send(std::string_view message); diff --git a/server/src/hardware/decoder/decoder.hpp b/server/src/hardware/decoder/decoder.hpp index 3067529a..7a30c001 100644 --- a/server/src/hardware/decoder/decoder.hpp +++ b/server/src/hardware/decoder/decoder.hpp @@ -52,6 +52,7 @@ class Decoder : public IdObject CLASS_ID("decoder") CREATE(Decoder) + static constexpr uint8_t speedStepsAuto = 0; static constexpr float throttleMin = 0; static constexpr float throttleStop = throttleMin; static constexpr float throttleMax = 1; diff --git a/server/src/hardware/protocol/dccplusplus/dccplusplus.cpp b/server/src/hardware/protocol/dccplusplus/dccplusplus.cpp index 74e03cbd..f52d3f51 100644 --- a/server/src/hardware/protocol/dccplusplus/dccplusplus.cpp +++ b/server/src/hardware/protocol/dccplusplus/dccplusplus.cpp @@ -104,6 +104,27 @@ void DCCPlusPlus::powerOnChanged(bool value) send(Ex::powerOff()); } +void DCCPlusPlus::checkDecoder(const Decoder& decoder) const +{ + assert(m_commandStation); + + if(decoder.protocol != DecoderProtocol::Auto && decoder.protocol != DecoderProtocol::DCC) + Log::log(decoder, LogMessage::C2002_DCCPLUSPLUS_ONLY_SUPPORTS_THE_DCC_PROTOCOL); + + if(decoder.protocol == DecoderProtocol::DCC && decoder.address <= 127 && decoder.longAddress) + Log::log(decoder, LogMessage::C2003_DCCPLUSPLUS_DOESNT_SUPPORT_DCC_LONG_ADDRESSES_BELOW_128); + + if(decoder.speedSteps != Decoder::speedStepsAuto && decoder.speedSteps != speedSteps) + Log::log(decoder, LogMessage::W2003_COMMAND_STATION_DOESNT_SUPPORT_X_SPEEDSTEPS_USING_X, decoder.speedSteps.value(), speedSteps.value()); + + for(const auto& function : *decoder.functions) + if(function->number > functionNumberMax) + { + Log::log(decoder, LogMessage::W2002_COMMAND_STATION_DOESNT_SUPPORT_FUNCTIONS_ABOVE_FX, functionNumberMax); + break; + } +} + void DCCPlusPlus::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) { if(has(changes, DecoderChangeFlags::EmergencyStop | DecoderChangeFlags::Throttle | DecoderChangeFlags::Direction)) diff --git a/server/src/hardware/protocol/dccplusplus/dccplusplus.hpp b/server/src/hardware/protocol/dccplusplus/dccplusplus.hpp index 94277267..4866537f 100644 --- a/server/src/hardware/protocol/dccplusplus/dccplusplus.hpp +++ b/server/src/hardware/protocol/dccplusplus/dccplusplus.hpp @@ -60,6 +60,8 @@ class DCCPlusPlus : public SubObject void emergencyStopChanged(bool value); void powerOnChanged(bool value); + + void checkDecoder(const Decoder& decoder) const; void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber); };