From b32f58da388b7ca288826b646decdbba2f7379cd Mon Sep 17 00:00:00 2001 From: Jonathan Schwartz Date: Wed, 12 Oct 2022 10:50:34 -0400 Subject: [PATCH] Device: Add new method to mark collections as uploaded in CM root directory --- device/device.cpp | 42 +++++++++++++++++++++++++- include/icsneo/communication/command.h | 1 + include/icsneo/device/device.h | 2 ++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/device/device.cpp b/device/device.cpp index db261c9..a2aed43 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -7,6 +7,7 @@ #include "icsneo/communication/packet/wivicommandpacket.h" #include "icsneo/communication/message/wiviresponsemessage.h" #include "icsneo/communication/message/scriptstatusmessage.h" +#include "icsneo/communication/message/extendedresponsemessage.h" #include #include #include @@ -1537,4 +1538,43 @@ std::optional Device::sendEthPhyMsg(const EthPhyMessage& message, return std::nullopt; } return std::make_optional(*retMsg); -} \ No newline at end of file +} + +std::optional Device::SetCollectionUploaded(uint32_t collectionEntryByteAddress) +{ + if (!supportsWiVI()) + { + report(APIEvent::Type::WiVINotSupported, APIEvent::Severity::EventWarning); + return std::nullopt; + } + + auto timeout = std::chrono::milliseconds(2500); + std::vector args( + {(uint8_t)(collectionEntryByteAddress & 0xFF), + (uint8_t)((collectionEntryByteAddress >> 8) & 0xFF), + (uint8_t)((collectionEntryByteAddress >> 16) & 0xFF), + (uint8_t)((collectionEntryByteAddress >> 24) & 0xFF)}); + std::shared_ptr response = com->waitForMessageSync( + [this, args](){ return com->sendCommand(ExtendedCommand::SetUploadedFlag, args); }, + std::make_shared(Message::Type::ExtendedResponse), timeout); + if (!response) + { + report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); + return std::nullopt; + } + auto retMsg = std::static_pointer_cast(response); + if (!retMsg) + { + // TODO fix this error + report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); + return std::make_optional(false); + } + bool success = retMsg->response == ExtendedResponse::OK; + if (!success) + { + // TODO fix this error + report(APIEvent::Type::Unknown, APIEvent::Severity::EventWarning); + } + // Valid device with a properly formed respose, return success + return std::make_optional(success); +} diff --git a/include/icsneo/communication/command.h b/include/icsneo/communication/command.h index b671b93..bbf8a23 100644 --- a/include/icsneo/communication/command.h +++ b/include/icsneo/communication/command.h @@ -46,6 +46,7 @@ enum class ExtendedCommand : uint16_t { StartDHCPServer = 0x0016, StopDHCPServer = 0x0017, Reboot = 0x001C, + SetUploadedFlag = 0x0027, }; enum class ExtendedResponse : int32_t { diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 5479ece..5b0d74a 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -505,6 +505,8 @@ public: std::optional sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); + std::optional SetCollectionUploaded(uint32_t collectionEntryByteAddress); + std::shared_ptr com; std::unique_ptr settings;