Device: Add new method to mark collections as uploaded in CM root directory

add-device-sharing
Jonathan Schwartz 2022-10-12 10:50:34 -04:00
parent 0101467154
commit b32f58da38
3 changed files with 44 additions and 1 deletions

View File

@ -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 <string.h>
#include <iostream>
#include <sstream>
@ -1537,4 +1538,43 @@ std::optional<EthPhyMessage> Device::sendEthPhyMsg(const EthPhyMessage& message,
return std::nullopt;
}
return std::make_optional<EthPhyMessage>(*retMsg);
}
}
std::optional<bool> 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<uint8_t> args(
{(uint8_t)(collectionEntryByteAddress & 0xFF),
(uint8_t)((collectionEntryByteAddress >> 8) & 0xFF),
(uint8_t)((collectionEntryByteAddress >> 16) & 0xFF),
(uint8_t)((collectionEntryByteAddress >> 24) & 0xFF)});
std::shared_ptr<Message> response = com->waitForMessageSync(
[this, args](){ return com->sendCommand(ExtendedCommand::SetUploadedFlag, args); },
std::make_shared<MessageFilter>(Message::Type::ExtendedResponse), timeout);
if (!response)
{
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
return std::nullopt;
}
auto retMsg = std::static_pointer_cast<ExtendedResponseMessage>(response);
if (!retMsg)
{
// TODO fix this error
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
return std::make_optional<bool>(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<bool>(success);
}

View File

@ -46,6 +46,7 @@ enum class ExtendedCommand : uint16_t {
StartDHCPServer = 0x0016,
StopDHCPServer = 0x0017,
Reboot = 0x001C,
SetUploadedFlag = 0x0027,
};
enum class ExtendedResponse : int32_t {

View File

@ -505,6 +505,8 @@ public:
std::optional<EthPhyMessage> sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
std::optional<bool> SetCollectionUploaded(uint32_t collectionEntryByteAddress);
std::shared_ptr<Communication> com;
std::unique_ptr<IDeviceSettings> settings;