From e28a9a5d96437eeecea680b4fe91ad31cb07932c Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Sat, 24 Jun 2023 23:41:58 +0200 Subject: [PATCH] DecoderProtocol: removed Auto/Custom, added None see #72 --- server/src/enum/decoderprotocol.hpp | 37 ------------------- server/src/hardware/decoder/decoder.cpp | 2 +- server/src/hardware/decoder/decoder.hpp | 2 +- .../hardware/decoder/decodercontroller.cpp | 10 ++--- .../hardware/decoder/decodercontroller.hpp | 2 +- .../interface/dccplusplusinterface.cpp | 3 -- server/src/hardware/protocol/ecos/kernel.cpp | 4 +- .../src/hardware/protocol/loconet/kernel.cpp | 2 +- .../protocol/traintasticdiy/kernel.cpp | 2 - .../hardware/protocol/z21/serverkernel.cpp | 2 - .../hardware/throttle/hardwarethrottle.cpp | 2 - server/src/lua/enums.hpp | 2 +- .../src/traintastic/enum/decoderprotocol.hpp | 18 ++++++--- shared/src/traintastic/enum/logmessage.hpp | 1 - shared/translations/de-de.json | 8 ---- shared/translations/en-us.json | 8 ---- shared/translations/it-it.json | 8 ---- shared/translations/nl-nl.json | 8 ---- 18 files changed, 22 insertions(+), 99 deletions(-) delete mode 100644 server/src/enum/decoderprotocol.hpp diff --git a/server/src/enum/decoderprotocol.hpp b/server/src/enum/decoderprotocol.hpp deleted file mode 100644 index 402a78f5..00000000 --- a/server/src/enum/decoderprotocol.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * server/src/enum/decoderprotocol.hpp - * - * This file is part of the traintastic source code. - * - * Copyright (C) 2019-2020,2022 Reinder Feenstra - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef TRAINTASTIC_SERVER_ENUM_DECODERPROTOCOL_HPP -#define TRAINTASTIC_SERVER_ENUM_DECODERPROTOCOL_HPP - -#include -#include - -inline constexpr std::array decoderProtocolValues{{ - DecoderProtocol::Auto, - DecoderProtocol::DCC, - DecoderProtocol::Motorola, - DecoderProtocol::Selectrix, - DecoderProtocol::Custom, -}}; - -#endif diff --git a/server/src/hardware/decoder/decoder.cpp b/server/src/hardware/decoder/decoder.cpp index f5d45c33..142861a2 100644 --- a/server/src/hardware/decoder/decoder.cpp +++ b/server/src/hardware/decoder/decoder.cpp @@ -67,7 +67,7 @@ Decoder::Decoder(World& world, std::string_view _id) : } return false; }}, - protocol{this, "protocol", DecoderProtocol::Auto, PropertyFlags::ReadWrite | PropertyFlags::Store, + protocol{this, "protocol", DecoderProtocol::None, PropertyFlags::ReadWrite | PropertyFlags::Store, [this](const DecoderProtocol& value) { if(value == DecoderProtocol::DCC && DCC::isLongAddress(address)) diff --git a/server/src/hardware/decoder/decoder.hpp b/server/src/hardware/decoder/decoder.hpp index b71cd57e..7c4621ca 100644 --- a/server/src/hardware/decoder/decoder.hpp +++ b/server/src/hardware/decoder/decoder.hpp @@ -26,7 +26,7 @@ #include #include "../../core/idobject.hpp" #include "../../core/objectproperty.hpp" -#include "../../enum/decoderprotocol.hpp" +#include #include "../../enum/direction.hpp" #include "decodercontroller.hpp" #include "decoderfunctions.hpp" diff --git a/server/src/hardware/decoder/decodercontroller.cpp b/server/src/hardware/decoder/decodercontroller.cpp index 4dfa062d..18840efe 100644 --- a/server/src/hardware/decoder/decodercontroller.cpp +++ b/server/src/hardware/decoder/decodercontroller.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021-2022 Reinder Feenstra + * Copyright (C) 2021-2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,9 +42,7 @@ DecoderController::DecoderController(IdObject& interface, DecoderListColumn colu bool DecoderController::addDecoder(Decoder& decoder) { - if(decoder.protocol != DecoderProtocol::Auto && findDecoder(decoder) != m_decoders.end()) - return false; - if(findDecoder(DecoderProtocol::Auto, decoder.address) != m_decoders.end()) + if(findDecoder(decoder) != m_decoders.end()) return false; m_decoders.emplace_back(decoder.shared_ptr()); @@ -64,13 +62,11 @@ bool DecoderController::removeDecoder(Decoder& decoder) return false; } -const std::shared_ptr& DecoderController::getDecoder(DecoderProtocol protocol, uint16_t address, bool dccLongAddress, bool fallbackToProtocolAuto) +const std::shared_ptr& DecoderController::getDecoder(DecoderProtocol protocol, uint16_t address, bool dccLongAddress) { auto it = findDecoder(protocol, address, dccLongAddress); if(it != m_decoders.end()) return *it; - if(fallbackToProtocolAuto && protocol != DecoderProtocol::Auto && (it = findDecoder(DecoderProtocol::Auto, address)) != m_decoders.end()) - return *it; return Decoder::null; } diff --git a/server/src/hardware/decoder/decodercontroller.hpp b/server/src/hardware/decoder/decodercontroller.hpp index ca4a9e6f..0b13fc49 100644 --- a/server/src/hardware/decoder/decodercontroller.hpp +++ b/server/src/hardware/decoder/decodercontroller.hpp @@ -72,7 +72,7 @@ class DecoderController [[nodiscard]] bool addDecoder(Decoder& decoder); [[nodiscard]] bool removeDecoder(Decoder& decoder); - const std::shared_ptr& getDecoder(DecoderProtocol protocol, uint16_t address, bool dccLongAddress = false, bool fallbackToProtocolAuto = false); + const std::shared_ptr& getDecoder(DecoderProtocol protocol, uint16_t address, bool dccLongAddress = false);//, bool fallbackToProtocolAuto = false); virtual void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) = 0; }; diff --git a/server/src/hardware/interface/dccplusplusinterface.cpp b/server/src/hardware/interface/dccplusplusinterface.cpp index 6691cea4..743955b1 100644 --- a/server/src/hardware/interface/dccplusplusinterface.cpp +++ b/server/src/hardware/interface/dccplusplusinterface.cpp @@ -282,9 +282,6 @@ void DCCPlusPlusInterface::check() const void DCCPlusPlusInterface::checkDecoder(const Decoder& decoder) const { - 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); diff --git a/server/src/hardware/protocol/ecos/kernel.cpp b/server/src/hardware/protocol/ecos/kernel.cpp index 1ebf2959..c5da8f29 100644 --- a/server/src/hardware/protocol/ecos/kernel.cpp +++ b/server/src/hardware/protocol/ecos/kernel.cpp @@ -67,7 +67,7 @@ static constexpr DecoderProtocol toDecoderProtocol(LocomotiveProtocol value) case LocomotiveProtocol::MMFKT: break; } - return DecoderProtocol::Custom; + return DecoderProtocol::None; } Kernel::Kernel(const Config& config, bool simulation) @@ -264,7 +264,7 @@ Locomotive* Kernel::getLocomotive(DecoderProtocol protocol, uint16_t address, ui auto* l = dynamic_cast(item.second.get()); return l && - (protocol == DecoderProtocol::Auto || protocol == toDecoderProtocol(l->protocol())) && + protocol == toDecoderProtocol(l->protocol()) && address == l->address() && (speedSteps == 0 || speedSteps == l->speedSteps()); }); diff --git a/server/src/hardware/protocol/loconet/kernel.cpp b/server/src/hardware/protocol/loconet/kernel.cpp index d8226b3c..beda5442 100644 --- a/server/src/hardware/protocol/loconet/kernel.cpp +++ b/server/src/hardware/protocol/loconet/kernel.cpp @@ -1317,7 +1317,7 @@ void Kernel::clearLocoSlot(uint8_t slot) std::shared_ptr Kernel::getDecoder(uint16_t address) { assert(isEventLoopThread()); - return m_decoderController->getDecoder(DecoderProtocol::DCC, address, DCC::isLongAddress(address), true); + return m_decoderController->getDecoder(DecoderProtocol::DCC, address, DCC::isLongAddress(address)); } void Kernel::setIOHandler(std::unique_ptr handler) diff --git a/server/src/hardware/protocol/traintasticdiy/kernel.cpp b/server/src/hardware/protocol/traintasticdiy/kernel.cpp index e4825314..c04134f0 100644 --- a/server/src/hardware/protocol/traintasticdiy/kernel.cpp +++ b/server/src/hardware/protocol/traintasticdiy/kernel.cpp @@ -476,8 +476,6 @@ std::shared_ptr Kernel::getDecoder(uint16_t address, bool longAddress) std::shared_ptr decoder; if(longAddress) decoder = decoderList.getDecoder(DecoderProtocol::DCC, address, longAddress); - if(!decoder) - decoder = decoderList.getDecoder(DecoderProtocol::Auto, address); if(!decoder) decoder = decoderList.getDecoder(address); return decoder; diff --git a/server/src/hardware/protocol/z21/serverkernel.cpp b/server/src/hardware/protocol/z21/serverkernel.cpp index 3eeaf2d9..69a83863 100644 --- a/server/src/hardware/protocol/z21/serverkernel.cpp +++ b/server/src/hardware/protocol/z21/serverkernel.cpp @@ -334,8 +334,6 @@ LanSystemStateDataChanged ServerKernel::getLanSystemStateDataChanged() const std::shared_ptr ServerKernel::getDecoder(uint16_t address, bool longAddress) const { auto decoder = m_decoderList->getDecoder(DecoderProtocol::DCC, address, longAddress); - if(!decoder) - decoder = m_decoderList->getDecoder(DecoderProtocol::Auto, address); if(!decoder) decoder = m_decoderList->getDecoder(address); return decoder; diff --git a/server/src/hardware/throttle/hardwarethrottle.cpp b/server/src/hardware/throttle/hardwarethrottle.cpp index 5bbb825d..c7eeb7d9 100644 --- a/server/src/hardware/throttle/hardwarethrottle.cpp +++ b/server/src/hardware/throttle/hardwarethrottle.cpp @@ -54,8 +54,6 @@ Throttle::AcquireResult HardwareThrottle::acquire(DecoderProtocol protocol, uint auto& decoderList = *m_world.decoders.value(); auto decoder = decoderList.getDecoder(protocol, address, isDCCLongAddress); - if(!decoder) - decoder = decoderList.getDecoder(DecoderProtocol::Auto, address); if(!decoder) decoder = decoderList.getDecoder(address); if(!decoder) diff --git a/server/src/lua/enums.hpp b/server/src/lua/enums.hpp index a04526e0..ab434ef1 100644 --- a/server/src/lua/enums.hpp +++ b/server/src/lua/enums.hpp @@ -25,7 +25,7 @@ #include #include "enum.hpp" -#include "../../src/enum/decoderprotocol.hpp" +#include #include "../../src/enum/direction.hpp" #include "../../src/enum/directioncontrolstate.hpp" #include diff --git a/shared/src/traintastic/enum/decoderprotocol.hpp b/shared/src/traintastic/enum/decoderprotocol.hpp index 25219d7f..25858eff 100644 --- a/shared/src/traintastic/enum/decoderprotocol.hpp +++ b/shared/src/traintastic/enum/decoderprotocol.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2022 Reinder Feenstra + * Copyright (C) 2019-2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,26 +24,32 @@ #define TRAINTASTIC_SHARED_TRAINTASTIC_ENUM_DECODERPROTOCOL_HPP #include +#include #include "enum.hpp" enum class DecoderProtocol : uint8_t { - Auto = 0, + None = 0, DCC = 1, Motorola = 2, //MFX = 3, Selectrix = 4, //FMZ = 5, - Custom = 255, }; -TRAINTASTIC_ENUM(DecoderProtocol, "decoder_protocol", 5, +TRAINTASTIC_ENUM(DecoderProtocol, "decoder_protocol", 4, { - {DecoderProtocol::Auto, "auto"}, + {DecoderProtocol::None, "none"}, {DecoderProtocol::DCC, "dcc"}, {DecoderProtocol::Motorola, "motorola"}, {DecoderProtocol::Selectrix, "selectrix"}, - {DecoderProtocol::Custom, "custom"}, }); +inline constexpr std::array decoderProtocolValues{{ + DecoderProtocol::None, + DecoderProtocol::DCC, + DecoderProtocol::Motorola, + DecoderProtocol::Selectrix, +}}; + #endif diff --git a/shared/src/traintastic/enum/logmessage.hpp b/shared/src/traintastic/enum/logmessage.hpp index 7687c616..954b00a6 100644 --- a/shared/src/traintastic/enum/logmessage.hpp +++ b/shared/src/traintastic/enum/logmessage.hpp @@ -191,7 +191,6 @@ enum class LogMessage : uint32_t C1012_UNKNOWN_CLASS_X_CANT_RECREATE_OBJECT_X = LogMessageOffset::critical + 1012, C1013_CANT_LOAD_WORLD_SAVED_WITH_NEWER_VERSION_REQUIRES_AT_LEAST_X = LogMessageOffset::critical + 1013, C2001_ADDRESS_ALREADY_USED_AT_X = LogMessageOffset::critical + 2001, - C2002_DCCPLUSPLUS_ONLY_SUPPORTS_THE_DCC_PROTOCOL = LogMessageOffset::critical + 2002, C2003_DCCPLUSPLUS_DOESNT_SUPPORT_DCC_LONG_ADDRESSES_BELOW_128 = LogMessageOffset::critical + 2003, C2004_CANT_GET_FREE_SLOT = LogMessageOffset::critical + 2004, C9999_X = LogMessageOffset::critical + 9999, diff --git a/shared/translations/de-de.json b/shared/translations/de-de.json index 6cf0c713..1e6681a9 100644 --- a/shared/translations/de-de.json +++ b/shared/translations/de-de.json @@ -2111,14 +2111,6 @@ "reference": "", "comment": "" }, - { - "term": "message:C2002", - "definition": "DCC++ unterst\u00fctzt nur das DCC-Protokoll", - "context": "", - "term_plural": "", - "reference": "", - "comment": "" - }, { "term": "message:C2003", "definition": "DCC++ unterst\u00fctzt keine langen DCC-Adressen unter 128", diff --git a/shared/translations/en-us.json b/shared/translations/en-us.json index 71cde01d..905275bd 100644 --- a/shared/translations/en-us.json +++ b/shared/translations/en-us.json @@ -2111,14 +2111,6 @@ "reference": "", "comment": "" }, - { - "term": "message:C2002", - "definition": "DCC++ only supports the DCC protocol", - "context": "", - "term_plural": "", - "reference": "", - "comment": "" - }, { "term": "message:C2003", "definition": "DCC++ doesn't support DCC long addresses below 128", diff --git a/shared/translations/it-it.json b/shared/translations/it-it.json index a3bf9769..cad55819 100644 --- a/shared/translations/it-it.json +++ b/shared/translations/it-it.json @@ -2111,14 +2111,6 @@ "reference": "", "comment": "" }, - { - "term": "message:C2002", - "definition": "DCC++ supporta solo il protocollo DCC", - "context": "", - "term_plural": "", - "reference": "", - "comment": "" - }, { "term": "message:C2003", "definition": "DCC++ non supporta indirizzi estesi DCC inferiori a 128", diff --git a/shared/translations/nl-nl.json b/shared/translations/nl-nl.json index c751398c..ff88d718 100644 --- a/shared/translations/nl-nl.json +++ b/shared/translations/nl-nl.json @@ -2111,14 +2111,6 @@ "reference": "", "comment": "" }, - { - "term": "message:C2002", - "definition": "DCC++ ondersteund alleen het DCC protocol", - "context": "", - "term_plural": "", - "reference": "", - "comment": "" - }, { "term": "message:C2003", "definition": "DCC++ ondersteund geen lange adressen onder de 128",