#pragma once #include "DeviceComplexJsonCommand.h" #include "SetTimeCommand.h" #include "ComplexCommandCreateMultidata.h" #include "UsbDeviceManager.h" namespace Incart::DeviceWebApi { class SetTimeJsonCommand final : public DeviceComplexJsonCommand { private: Usb::ByteCommandQueue* const m_commandQueue; Usb::UsbDeviceCommandSet* const m_usbDeviceCommands; public: SetTimeJsonCommand(std::shared_ptr description, Usb::UsbDeviceManager* const usbDeviceManager) : DeviceComplexJsonCommand(description) , m_commandQueue(usbDeviceManager->getCommandQueue()) , m_usbDeviceCommands(usbDeviceManager->getCommandSet()) { } SetTimeJsonCommand(Usb::UsbDeviceManager* const usbDeviceManager) : SetTimeJsonCommand(createCommandDescription(), usbDeviceManager) { } public: static std::shared_ptr createCommandDescription() { return std::make_shared("SetTime", std::make_shared(std::vector>{ std::make_shared("Year", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("Month", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("Day", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("Hours", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("Minutes", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("Seconds", Net::WebApi::EJsonCommandUnitType::Int) }), std::make_shared() ); } std::shared_ptr execute(std::shared_ptr launchedCommandInfo_) override { std::shared_ptr launchedCommandInfo = std::dynamic_pointer_cast(launchedCommandInfo_); uid = launchedCommandInfo->uid; if (launchedCommandInfo->data.isNull()) { std::cout << __PRETTY_FUNCTION__ << " json object interpretation error" << std::endl; return DeviceWebApi::JsonCommandStatusCreator::create(Usb::DeviceCommand::EStatus::BAD_DATA); } QVariantMap jsonMap = launchedCommandInfo->data.toMap(); Common::DateTimeObject dateTime{ static_cast(jsonMap["Year"].toUInt()), static_cast(jsonMap["Month"].toUInt()), static_cast(jsonMap["Day"].toUInt()), static_cast(jsonMap["Hours"].toUInt()), static_cast(jsonMap["Minutes"].toUInt()), static_cast(jsonMap["Seconds"].toUInt()) }; std::shared_ptr commandData = std::make_shared>(m_commandQueue->generateUid(), dateTime); std::shared_ptr command = std::dynamic_pointer_cast(m_usbDeviceCommands->createComplexCommand(launchedCommandInfo->name, commandData)); m_executedCommands[command.get()] = command; connect(command.get(), &DeviceComplexCommands::SetTimeCommand::answerIsReady, this, &SetTimeJsonCommand::handleAnswerIsReady); return executeCommand(command); } private slots: void handleAnswerIsReady(Usb::ComplexCommand* command, std::shared_ptr status) { removeExecutedCommand(command); emit answerIsReady(this, QJsonDocument(), DeviceWebApi::JsonCommandStatusCreator::create(status)); } }; } // namespace Incart::DeviceWebApi