From cf1b4778a16c0d1380fd022b46e20cec1e1f11af Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Mon, 3 Jun 2024 08:31:17 -0400 Subject: [PATCH] Device: RADMoon2ZL: Add TC10 commands --- CMakeLists.txt | 1 + api/icsneocpp/event.cpp | 3 + communication/decoder.cpp | 4 + communication/message/tc10statusmessage.cpp | 31 ++++++++ device/device.cpp | 78 ++++++++++++++++++- include/icsneo/api/event.h | 1 + include/icsneo/communication/command.h | 3 + .../icsneo/communication/message/message.h | 3 +- .../communication/message/tc10statusmessage.h | 40 ++++++++++ include/icsneo/device/device.h | 9 +++ .../icsneo/device/tree/radmoon2/radmoon2zl.h | 2 + 11 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 communication/message/tc10statusmessage.cpp create mode 100644 include/icsneo/communication/message/tc10statusmessage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1ee2b..d769479 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,7 @@ set(SRC_FILES communication/message/ethphymessage.cpp communication/message/linmessage.cpp communication/message/livedatamessage.cpp + communication/message/tc10statusmessage.cpp communication/packet/flexraypacket.cpp communication/packet/canpacket.cpp communication/packet/a2bpacket.cpp diff --git a/api/icsneocpp/event.cpp b/api/icsneocpp/event.cpp index af0d910..fd26018 100644 --- a/api/icsneocpp/event.cpp +++ b/api/icsneocpp/event.cpp @@ -73,6 +73,7 @@ static constexpr const char* VALUE_NOT_YET_PRESENT = "The value is not yet prese static constexpr const char* TIMEOUT = "The timeout was reached."; static constexpr const char* WIVI_NOT_SUPPORTED = "Wireless neoVI functions are not supported on this device."; static constexpr const char* RESTRICTED_ENTRY_FLAG = "Attempted to set a restricted flag in a Root Directory entry."; +static constexpr const char* NOT_SUPPORTED = "The requested feature is not supported."; // Device Errors static constexpr const char* POLLING_MESSAGE_OVERFLOW = "Too many messages have been recieved for the polling message buffer, some have been lost!"; @@ -221,6 +222,8 @@ const char* APIEvent::DescriptionForType(Type type) { return WIVI_NOT_SUPPORTED; case Type::RestrictedEntryFlag: return RESTRICTED_ENTRY_FLAG; + case Type::NotSupported: + return NOT_SUPPORTED; // Device Errors case Type::PollingMessageOverflow: diff --git a/communication/decoder.cpp b/communication/decoder.cpp index f0c4241..9825e0c 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -17,6 +17,7 @@ #include "icsneo/communication/message/livedatamessage.h" #include "icsneo/communication/message/diskdatamessage.h" #include "icsneo/communication/message/hardwareinfo.h" +#include "icsneo/communication/message/tc10statusmessage.h" #include "icsneo/communication/command.h" #include "icsneo/device/device.h" #include "icsneo/communication/packet/canpacket.h" @@ -289,6 +290,9 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptrdata, report); return true; + case ExtendedCommand::GetTC10Status: + result = TC10StatusMessage::DecodeToMessage(packet->data); + return true; default: // No defined handler, treat this as a RawMessage break; diff --git a/communication/message/tc10statusmessage.cpp b/communication/message/tc10statusmessage.cpp new file mode 100644 index 0000000..60d82bb --- /dev/null +++ b/communication/message/tc10statusmessage.cpp @@ -0,0 +1,31 @@ +#include "icsneo/communication/message/tc10statusmessage.h" +#include "icsneo/communication/command.h" + +using namespace icsneo; + +#pragma pack(push, 2) +struct Header { + ExtendedCommand command; + uint16_t length; +}; + +struct Packet { + Header header; + TC10WakeStatus wakeStatus; + TC10SleepStatus sleepStatus; +}; +#pragma pack(pop) + +std::shared_ptr TC10StatusMessage::DecodeToMessage(const std::vector& bytestream) { + if(bytestream.size() < sizeof(Packet)) { + return nullptr; + } + const Packet* packet = (Packet*)bytestream.data(); + if (packet->header.command != ExtendedCommand::GetTC10Status) { + return nullptr; + } + if (packet->header.length < sizeof(Packet) - sizeof(Header)) { + return nullptr; + } + return std::make_shared(packet->wakeStatus, packet->sleepStatus); +} diff --git a/device/device.cpp b/device/device.cpp index 57d0677..2b689ef 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -3179,4 +3179,80 @@ std::optional Device::getVSADiskSize() { return std::nullopt; } return diskSize; -} \ No newline at end of file +} + +bool Device::requestTC10Wake(Network::NetID network) { + if(!supportsTC10()) { + report(APIEvent::Type::NotSupported, APIEvent::Severity::Error); + return false; + } + std::vector args(sizeof(network)); + *(Network::NetID*)args.data() = network; + auto msg = com->waitForMessageSync([&] { + return com->sendCommand(ExtendedCommand::RequestTC10Wake, args); + }, std::make_shared(Message::Type::ExtendedResponse), std::chrono::milliseconds(1000)); + + if(!msg) { + report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); + return false; + } + + auto resp = std::static_pointer_cast(msg); + if(!resp) { + report(APIEvent::Type::UnexpectedResponse, APIEvent::Severity::Error); + return false; + } + + return resp->response == ExtendedResponse::OK; +} + +bool Device::requestTC10Sleep(Network::NetID network) { + if(!supportsTC10()) { + report(APIEvent::Type::NotSupported, APIEvent::Severity::Error); + return false; + } + std::vector args(sizeof(network)); + *(Network::NetID*)args.data() = network; + auto msg = com->waitForMessageSync([&] { + return com->sendCommand(ExtendedCommand::RequestTC10Sleep, args); + }, std::make_shared(Message::Type::ExtendedResponse), std::chrono::milliseconds(1000)); + + if(!msg) { + report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); + return false; + } + + auto typed = std::static_pointer_cast(msg); + if(!typed) { + report(APIEvent::Type::UnexpectedResponse, APIEvent::Severity::Error); + return false; + } + + return typed->response == ExtendedResponse::OK; +} + +std::optional Device::getTC10Status(Network::NetID network) { + if(!supportsTC10()) { + report(APIEvent::Type::NotSupported, APIEvent::Severity::Error); + return std::nullopt; + } + std::vector args(sizeof(network)); + *(Network::NetID*)args.data() = network; + auto msg = com->waitForMessageSync([&] { + return com->sendCommand(ExtendedCommand::GetTC10Status, args); + }, std::make_shared(Message::Type::TC10Status), std::chrono::milliseconds(1000)); + + if(!msg) { + report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); + return std::nullopt; + } + + auto typed = std::static_pointer_cast(msg); + + if(!typed) { + report(APIEvent::Type::UnexpectedResponse, APIEvent::Severity::Error); + return std::nullopt; + } + + return *typed; +} diff --git a/include/icsneo/api/event.h b/include/icsneo/api/event.h index f8b9526..bfc3da2 100644 --- a/include/icsneo/api/event.h +++ b/include/icsneo/api/event.h @@ -50,6 +50,7 @@ public: Timeout = 0x1014, WiVINotSupported = 0x1015, RestrictedEntryFlag = 0x1016, + NotSupported = 0x1017, // Device Events PollingMessageOverflow = 0x2000, diff --git a/include/icsneo/communication/command.h b/include/icsneo/communication/command.h index 3f985ba..1fb96fb 100644 --- a/include/icsneo/communication/command.h +++ b/include/icsneo/communication/command.h @@ -56,6 +56,9 @@ enum class ExtendedCommand : uint16_t { SetRootFSEntryFlags = 0x0027, GenericBinaryInfo = 0x0030, LiveData = 0x0035, + RequestTC10Wake = 0x003D, + RequestTC10Sleep = 0x003E, + GetTC10Status = 0x003F, }; enum class ExtendedResponse : int32_t { diff --git a/include/icsneo/communication/message/message.h b/include/icsneo/communication/message/message.h index f5ff894..7c5be97 100644 --- a/include/icsneo/communication/message/message.h +++ b/include/icsneo/communication/message/message.h @@ -38,7 +38,8 @@ public: SupportedFeatures = 0x800d, GenericBinaryStatus = 0x800e, LiveData = 0x800f, - HardwareInfo = 0x8010 + HardwareInfo = 0x8010, + TC10Status = 0x8011, }; Message(Type t) : type(t) {} diff --git a/include/icsneo/communication/message/tc10statusmessage.h b/include/icsneo/communication/message/tc10statusmessage.h new file mode 100644 index 0000000..baba024 --- /dev/null +++ b/include/icsneo/communication/message/tc10statusmessage.h @@ -0,0 +1,40 @@ +#ifndef __TC10STATUSMESSAGE_H +#define __TC10STATUSMESSAGE_H + +#ifdef __cplusplus + +#include "icsneo/communication/message/message.h" + +#include + +namespace icsneo +{ + +enum class TC10WakeStatus : uint8_t { + NoWakeReceived, + WakeReceived, +}; + +enum class TC10SleepStatus : uint8_t { + NoSleepReceived, + SleepReceived, + SleepFailed, + SleepAborted, +}; + +class TC10StatusMessage : public Message { +public: + static std::shared_ptr DecodeToMessage(const std::vector& bytestream); + + TC10StatusMessage(const TC10WakeStatus& wakeStatus, const TC10SleepStatus& sleepStatus) : + Message(Type::TC10Status), wakeStatus(wakeStatus), sleepStatus(sleepStatus) {} + + const TC10WakeStatus wakeStatus; + const TC10SleepStatus sleepStatus; +}; + +} + +#endif // __cplusplus + +#endif diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index e0f326e..dc1ce01 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -37,6 +37,7 @@ #include "icsneo/communication/message/hardwareinfo.h" #include "icsneo/communication/message/extendeddatamessage.h" #include "icsneo/communication/message/livedatamessage.h" +#include "icsneo/communication/message/tc10statusmessage.h" #include "icsneo/communication/packet/genericbinarystatuspacket.h" #include "icsneo/communication/packet/livedatapacket.h" #include "icsneo/device/extensions/flexray/controller.h" @@ -722,6 +723,14 @@ public: virtual bool supportsComponentVersions() const { return false; } + virtual bool supportsTC10() const { return false; } + + bool requestTC10Wake(Network::NetID network); + + bool requestTC10Sleep(Network::NetID network); + + std::optional getTC10Status(Network::NetID network); + protected: bool online = false; int messagePollingCallbackID = 0; diff --git a/include/icsneo/device/tree/radmoon2/radmoon2zl.h b/include/icsneo/device/tree/radmoon2/radmoon2zl.h index c56eade..f441c70 100644 --- a/include/icsneo/device/tree/radmoon2/radmoon2zl.h +++ b/include/icsneo/device/tree/radmoon2/radmoon2zl.h @@ -18,6 +18,8 @@ public: bool supportsComponentVersions() const override { return true; } + bool supportsTC10() const override { return true; } + protected: RADMoon2ZL(neodevice_t neodevice, const driver_factory_t& makeDriver) : RADMoon2Base(neodevice) { initialize(makeDriver);