ecos: implemented handling ECoS get info response
Dieser Commit ist enthalten in:
Ursprung
94fd800443
Commit
048b00bc44
@ -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";
|
||||
|
||||
@ -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 <cassert>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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 <traintastic/enum/tristate.hpp>
|
||||
#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<uint8_t>;
|
||||
using ApplicationVersion = Version::MajorMinorPatch<uint8_t>;
|
||||
using HardwareVersion = Version::MajorMinor<uint8_t>;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren