From f6115ba207536b77daae5630dd823e5629e89a3b Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Sun, 23 Jul 2023 00:50:14 +0200 Subject: [PATCH] marklin_can: added Ping reply message see #11 --- .../hardware/protocol/marklincan/messages.cpp | 34 +++++++++++ .../hardware/protocol/marklincan/messages.hpp | 58 ++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/server/src/hardware/protocol/marklincan/messages.cpp b/server/src/hardware/protocol/marklincan/messages.cpp index 7e1df484..e3a9fc71 100644 --- a/server/src/hardware/protocol/marklincan/messages.cpp +++ b/server/src/hardware/protocol/marklincan/messages.cpp @@ -251,6 +251,14 @@ std::string toString(const Message& message) case Command::Ping: s.append("Ping"); + if(message.dlc == 8) + { + const auto& pingReply = static_cast(message); + s.append(" ").append(UID::toString(pingReply.uid())); + s.append(" software_version=").append(std::to_string(pingReply.softwareVersionMajor())).append(".").append(std::to_string(pingReply.softwareVersionMinor())); + s.append(" device_id=0x").append(toHex(static_cast(pingReply.deviceId()))); + s.append(" (").append(toString(pingReply.deviceId())).append(")"); + } break; case Command::Update: @@ -295,4 +303,30 @@ std::string toString(const Message& message) return s; } +std::string_view toString(MarklinCAN::DeviceId value) +{ + switch(value) + { + case DeviceId::GleisFormatProzessorOrBooster: + return "Gleis Format Prozessor 60213,60214 / Booster 60173, 60174"; + + case DeviceId::Gleisbox: + return "Gleisbox 60112 und 60113"; + + case DeviceId::Connect6021: + return "Connect 6021 Art-Nr.60128"; + + case DeviceId::MS2: + return "MS 2 60653, Txxxxx"; + + case DeviceId::WirelessDevices: + return "Wireless Devices"; + + case DeviceId::CS2GUI: + return "CS2-GUI (Master)"; + } + assert(false); + return {}; +} + } diff --git a/server/src/hardware/protocol/marklincan/messages.hpp b/server/src/hardware/protocol/marklincan/messages.hpp index 3c74baea..35681ba5 100644 --- a/server/src/hardware/protocol/marklincan/messages.hpp +++ b/server/src/hardware/protocol/marklincan/messages.hpp @@ -83,6 +83,16 @@ enum class SystemSubCommand : uint8_t ModelClock = 0x20, }; +enum class DeviceId : uint16_t +{ + GleisFormatProzessorOrBooster= 0x0000, //!< Gleis Format Prozessor 60213,60214 / Booster 60173, 60174 + Gleisbox = 0x0010, //!< Gleisbox 60112 und 60113 + Connect6021 = 0x0020, //!< Connect 6021 Art-Nr.60128 + MS2 = 0x0030, //!< MS 2 60653, Txxxxx + WirelessDevices = 0xFFE0, //!< Wireless Devices + CS2GUI = 0xFFFF //!< CS2-GUI (Master) +}; + struct Message { static constexpr uint32_t responseMask = 0x00010000; @@ -638,6 +648,52 @@ struct FeedbackState : FeedbackMessage } }; +struct Ping : Message +{ + Ping() + : Message(Command::Ping, false) + { + } +}; + +struct PingReply : UidMessage +{ + PingReply(uint32_t uid) + : UidMessage(Command::Ping, true, uid) + { + dlc = 8; + } + + uint8_t softwareVersionMajor() const + { + return data[4]; + } + + uint8_t softwareVersionMinor() const + { + return data[5]; + } + + void setSoftwareVersion(uint8_t major, uint8_t minor) + { + data[4] = major; + data[5] = minor; + } + + DeviceId deviceId() const + { + return static_cast(to16(data[7], data[6])); + } + + void setDeviceId(DeviceId value) + { + data[6] = high8(static_cast(value)); + data[7] = low8(static_cast(value)); + } +}; + +std::string_view toString(MarklinCAN::DeviceId value); + } -#endif \ No newline at end of file +#endif