diff --git a/server/src/hardware/protocol/ecos/messages.hpp b/server/src/hardware/protocol/ecos/messages.hpp index 04f7980e..73fed845 100644 --- a/server/src/hardware/protocol/ecos/messages.hpp +++ b/server/src/hardware/protocol/ecos/messages.hpp @@ -59,14 +59,17 @@ struct ObjectId struct Option { static constexpr std::string_view addr = "addr"; + static constexpr std::string_view applicationVersion = "ApplicationVersion"; static constexpr std::string_view dir = "dir"; static constexpr std::string_view duration = "duration"; static constexpr std::string_view go = "go"; + static constexpr std::string_view hardwareVersion = "HardwareVersion"; static constexpr std::string_view info = "info"; static constexpr std::string_view mode = "mode"; static constexpr std::string_view name = "name"; static constexpr std::string_view ports = "ports"; static constexpr std::string_view protocol = "protocol"; + static constexpr std::string_view protocolVersion = "ProtocolVersion"; static constexpr std::string_view speedStep = "speedstep"; static constexpr std::string_view state = "state"; static constexpr std::string_view status = "status"; diff --git a/server/src/hardware/protocol/ecos/object/ecos.cpp b/server/src/hardware/protocol/ecos/object/ecos.cpp index ac7c2fc0..09dbd214 100644 --- a/server/src/hardware/protocol/ecos/object/ecos.cpp +++ b/server/src/hardware/protocol/ecos/object/ecos.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021 Reinder Feenstra + * Copyright (C) 2021-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 @@ -24,6 +24,8 @@ #include #include "../kernel.hpp" #include "../messages.hpp" +#include "../../../../utils/rtrim.hpp" +#include "../../../../utils/stripprefix.hpp" namespace ECoS { @@ -66,7 +68,23 @@ bool ECoS::receiveReply(const Reply& reply) { if(reply.options[0] == Option::info) { - //! @todo + // read model: + for(auto line : reply.lines) + { + line = stripPrefix(rtrim(line, '\r'), "1 "); + if(line == "ECoS") + { + m_model = Model::ECoS; + break; + } + if(line == "ECoS2") + { + m_model = Model::ECoS2; + break; + } + } + + // other values are read by update() } } } @@ -93,4 +111,20 @@ void ECoS::stop() send(set(m_id, {Option::stop})); } +void ECoS::update(std::string_view option, std::string_view value) +{ + if(option == Option::applicationVersion) + { + Version::fromChars(value, m_applicationVersion); + } + else if(option == Option::hardwareVersion) + { + Version::fromChars(value, m_hardwareVersion); + } + else if(option == Option::protocolVersion) + { + Version::fromChars(value, m_protocolVersion); + } +} + } diff --git a/server/src/hardware/protocol/ecos/object/ecos.hpp b/server/src/hardware/protocol/ecos/object/ecos.hpp index 90815576..8edf7285 100644 --- a/server/src/hardware/protocol/ecos/object/ecos.hpp +++ b/server/src/hardware/protocol/ecos/object/ecos.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021 Reinder Feenstra + * Copyright (C) 2021-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 @@ -25,6 +25,7 @@ #include "object.hpp" #include +#include "../../../../utils/version.hpp" namespace ECoS { @@ -32,12 +33,36 @@ class Kernel; class ECoS final : public Object { + public: + enum class Model + { + Unknown = 0, + ECoS = 1, + ECoS2 = 2, + }; + + using ProtocolVersion = Version::MajorMinor; + using ApplicationVersion = Version::MajorMinorPatch; + using HardwareVersion = Version::MajorMinor; + private: + Model m_model = Model::Unknown; + ProtocolVersion m_protocolVersion; + ApplicationVersion m_applicationVersion; + HardwareVersion m_hardwareVersion; TriState m_go = TriState::Undefined; + protected: + void update(std::string_view option, std::string_view value) final; + public: ECoS(Kernel& kernel); + Model model() const { return m_model; } + ProtocolVersion protocolVersion() const { return m_protocolVersion; } + ApplicationVersion applicationVersion() const { return m_applicationVersion; } + HardwareVersion hardwareVersion() const { return m_hardwareVersion; } + bool receiveReply(const Reply& reply) final; bool receiveEvent(const Event& event) final;