From b3d47f2ae514a535404f3b26431e2c9ce5da51fd Mon Sep 17 00:00:00 2001 From: Keith Nash Date: Fri, 16 May 2025 19:36:27 +0000 Subject: [PATCH] Communication: Add LogDataMessage --- CMakeLists.txt | 1 + communication/decoder.cpp | 10 +++++++ communication/message/logdatamessage.cpp | 12 +++++++++ device/device.cpp | 8 ++++++ include/icsneo/communication/command.h | 1 + .../communication/message/logdatamessage.h | 26 +++++++++++++++++++ .../icsneo/communication/message/message.h | 1 + include/icsneo/communication/network.h | 1 + include/icsneo/device/device.h | 2 ++ include/icsneo/icsneocpp.h | 1 + 10 files changed, 63 insertions(+) create mode 100644 communication/message/logdatamessage.cpp create mode 100644 include/icsneo/communication/message/logdatamessage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 85b1eff..4e581ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,7 @@ set(SRC_FILES communication/message/ethphymessage.cpp communication/message/linmessage.cpp communication/message/livedatamessage.cpp + communication/message/logdatamessage.cpp communication/message/tc10statusmessage.cpp communication/message/gptpstatusmessage.cpp communication/message/ethernetstatusmessage.cpp diff --git a/communication/decoder.cpp b/communication/decoder.cpp index 101777f..ce59267 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -16,6 +16,7 @@ #include "icsneo/communication/message/mdiomessage.h" #include "icsneo/communication/message/extendeddatamessage.h" #include "icsneo/communication/message/livedatamessage.h" +#include "icsneo/communication/message/logdatamessage.h" #include "icsneo/communication/message/diskdatamessage.h" #include "icsneo/communication/message/hardwareinfo.h" #include "icsneo/communication/message/tc10statusmessage.h" @@ -491,7 +492,16 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptr(std::move(packet->data)); return true; } + case Network::NetID::Data_To_Host: { + result = LogDataMessage::DecodeToMessage(packet->data); + if(!result) { + report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning); + return false; + } + return true; + } default: + break; } break; diff --git a/communication/message/logdatamessage.cpp b/communication/message/logdatamessage.cpp new file mode 100644 index 0000000..15ac89a --- /dev/null +++ b/communication/message/logdatamessage.cpp @@ -0,0 +1,12 @@ +#include "icsneo/communication/message/logdatamessage.h" +#include + +using namespace icsneo; + +std::shared_ptr LogDataMessage::DecodeToMessage(const std::vector& bytestream) { + if(bytestream.size() % 2 != 0) + return nullptr; + const auto* begin = (char16_t*)bytestream.data(); + const auto* end = begin + (bytestream.size() / sizeof(char16_t)); + return std::make_shared(std::wstring(begin,end)); +} \ No newline at end of file diff --git a/device/device.cpp b/device/device.cpp index c477ec7..77630e0 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -405,6 +405,14 @@ bool Device::close() { return com->close(); } +bool Device::enableLogData() { + return com->sendCommand(Command::EnableLogData, true); +} + +bool Device::disableLogData() { + return com->sendCommand(Command::EnableLogData, false); +} + bool Device::goOnline() { if(!enableNetworkCommunication(true)) return false; diff --git a/include/icsneo/communication/command.h b/include/icsneo/communication/command.h index d2efd15..a457bc7 100644 --- a/include/icsneo/communication/command.h +++ b/include/icsneo/communication/command.h @@ -38,6 +38,7 @@ enum class Command : uint8_t { FlexRayControl = 0xF3, CoreMiniPreload = 0xF4, // Previously known as RED_CMD_COREMINI_PRELOAD PHYControlRegisters = 0xEF, + EnableLogData = 0xF6, }; enum class ExtendedCommand : uint16_t { diff --git a/include/icsneo/communication/message/logdatamessage.h b/include/icsneo/communication/message/logdatamessage.h new file mode 100644 index 0000000..481054e --- /dev/null +++ b/include/icsneo/communication/message/logdatamessage.h @@ -0,0 +1,26 @@ +#ifndef __LOGDATAMESSAGE_H_ +#define __LOGDATAMESSAGE_H_ + +#ifdef __cplusplus + +#include "icsneo/communication/message/message.h" +#include +#include + +namespace icsneo { + +class LogDataMessage : public RawMessage { +public: + static std::shared_ptr DecodeToMessage(const std::vector& bytestream); + + LogDataMessage(std::wstring logDataString) : + RawMessage(Message::Type::LogData, Network::NetID::Data_To_Host), logMessage(logDataString) {} + + std::wstring logMessage; +}; + +} + +#endif // __cplusplus + +#endif \ No newline at end of file diff --git a/include/icsneo/communication/message/message.h b/include/icsneo/communication/message/message.h index 27f79c5..86bcb92 100644 --- a/include/icsneo/communication/message/message.h +++ b/include/icsneo/communication/message/message.h @@ -44,6 +44,7 @@ public: AppError = 0x8012, GPTPStatus = 0x8013, EthernetStatus = 0x8014, + LogData = 0x8015, }; Message(Type t) : type(t) {} diff --git a/include/icsneo/communication/network.h b/include/icsneo/communication/network.h index 06acda7..a9cf93a 100644 --- a/include/icsneo/communication/network.h +++ b/include/icsneo/communication/network.h @@ -583,6 +583,7 @@ public: case NetID::RED_GET_RTC: case NetID::DiskData: case NetID::RED_App_Error: + case NetID::Data_To_Host: return Type::Internal; case NetID::Invalid: case NetID::Any: diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index e126b1a..6667464 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -151,6 +151,8 @@ public: virtual bool isDisconnected() const { return com->isDisconnected(); } virtual bool goOnline(); virtual bool goOffline(); + virtual bool enableLogData(); + virtual bool disableLogData(); enum class PreloadReturn : uint8_t { diff --git a/include/icsneo/icsneocpp.h b/include/icsneo/icsneocpp.h index cad9ca1..2d000a8 100644 --- a/include/icsneo/icsneocpp.h +++ b/include/icsneo/icsneocpp.h @@ -20,6 +20,7 @@ #include "icsneo/communication/message/a2bmessage.h" #include "icsneo/communication/message/linmessage.h" #include "icsneo/communication/message/mdiomessage.h" +#include "icsneo/communication/message/logdatamessage.h" #include "icsneo/communication/message/callback/streamoutput/a2bwavoutput.h"