From 68715d515d382a8b02596718bc469c2f20cddf9a Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Sun, 22 Aug 2021 13:09:48 -0400 Subject: [PATCH] Decoder: Allow older ResetStatus packets without voltage or temperature --- communication/decoder.cpp | 9 ++++++--- .../icsneo/communication/message/resetstatusmessage.h | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/communication/decoder.cpp b/communication/decoder.cpp index 4cbe7b3..cc655e2 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -91,7 +91,8 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptrnetwork.getNetID()) { case Network::NetID::Reset_Status: { - if(packet->data.size() < sizeof(HardwareResetStatusPacket)) { + // We can deal with not having the last two fields (voltage and temperature) + if(packet->data.size() < (sizeof(HardwareResetStatusPacket) - (sizeof(uint16_t) * 2))) { report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error); return false; } @@ -101,8 +102,6 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptrnetwork = packet->network; msg->mainLoopTime = data->main_loop_time_25ns * 25; msg->maxMainLoopTime = data->max_main_loop_time_25ns * 25; - msg->busVoltage = data->busVoltage; - msg->deviceTemperature = data->deviceTemperature; msg->justReset = data->status.just_reset; msg->comEnabled = data->status.com_enabled; msg->cmRunning = data->status.cm_is_running; @@ -116,6 +115,10 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptrcmTooBig = data->status.cm_too_big; msg->hidUsbState = data->status.hidUsbState; msg->fpgaUsbState = data->status.fpgaUsbState; + if(packet->data.size() >= sizeof(HardwareResetStatusPacket)) { + msg->busVoltage = data->busVoltage; + msg->deviceTemperature = data->deviceTemperature; + } result = msg; return true; } diff --git a/include/icsneo/communication/message/resetstatusmessage.h b/include/icsneo/communication/message/resetstatusmessage.h index 2784cba..c83c848 100644 --- a/include/icsneo/communication/message/resetstatusmessage.h +++ b/include/icsneo/communication/message/resetstatusmessage.h @@ -5,6 +5,7 @@ #include "icsneo/communication/message/main51message.h" #include "icsneo/communication/command.h" +#include "icsneo/platform/optional.h" #include namespace icsneo { @@ -28,8 +29,8 @@ public: bool cmTooBig; bool hidUsbState; bool fpgaUsbState; - uint16_t busVoltage; - uint16_t deviceTemperature; + icsneo::optional busVoltage; + icsneo::optional deviceTemperature; }; }