diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 75542d9..3d96e78 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -870,27 +870,33 @@ int LegacyDLLExport icsneoGetDeviceSettingsType(void *hObject, EPlasmaIonVnetCha return 1; } -int LegacyDLLExport icsneoSetDeviceSettings(void *hObject, SDeviceSettings *pSettings, int iNumBytes, int bSaveToEEPROM, EPlasmaIonVnetChannel_t vnetSlot) +int LegacyDLLExport icsneoSetDeviceSettings(void* hObject, SDeviceSettings* pSettings, int iNumBytes, int bSaveToEEPROM, EPlasmaIonVnetChannel_t vnetSlot) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = (neodevice_t*)hObject; + + const size_t offset = size_t(&pSettings->Settings) - size_t(pSettings); if (bSaveToEEPROM) - return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); - - return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); + return icsneo_settingsApplyStructure(device, &pSettings->Settings, iNumBytes - offset); + else + return icsneo_settingsApplyStructureTemporary(device, &pSettings->Settings, iNumBytes - offset); } -int LegacyDLLExport icsneoGetDeviceSettings(void *hObject, SDeviceSettings *pSettings, int iNumBytes, EPlasmaIonVnetChannel_t vnetSlot) +int LegacyDLLExport icsneoGetDeviceSettings(void* hObject, SDeviceSettings* pSettings, int iNumBytes, EPlasmaIonVnetChannel_t vnetSlot) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = (neodevice_t*)hObject; - return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes); + if (icsneoGetDeviceSettingsType(hObject, vnetSlot, &pSettings->DeviceSettingType) == 0) + return false; + + const size_t offset = size_t(&pSettings->Settings) - size_t(pSettings); + return !!icsneo_settingsReadStructure(device, &pSettings->Settings, iNumBytes - offset); } int LegacyDLLExport icsneoSetBitRateEx(void *hObject, unsigned long BitRate, int NetworkID, int iOptions) diff --git a/communication/decoder.cpp b/communication/decoder.cpp index d2538b1..bff2cb5 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -115,7 +115,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; } @@ -124,8 +125,6 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptr(); 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; @@ -139,6 +138,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 695cc3d..0a1b2f1 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; }; } diff --git a/include/icsneo/icsneolegacy.h b/include/icsneo/icsneolegacy.h index 3988382..e71173d 100644 --- a/include/icsneo/icsneolegacy.h +++ b/include/icsneo/icsneolegacy.h @@ -5,6 +5,7 @@ #include "icsneo/platform/tchar.h" #include +#include typedef uint8_t byte; // Typedef helper for the following include #include "icsneo/icsnVC40.h" // Definitions for structs @@ -166,4 +167,4 @@ extern int LegacyDLLExport icsneoDisableBitSmash(void* hObject, unsigned int res } // extern "C" #endif -#endif \ No newline at end of file +#endif