#pragma once #include "DeviceComplexJsonCommand.h" #include "WriteCableInfoCommand.h" #include "UsbDeviceManager.h" #include "ComplexCommandCreateMultidata.h" namespace Incart::DeviceWebApi { class WriteCableInfoJsonCommand final : public DeviceComplexJsonCommand { private: Usb::ByteCommandQueue* const m_commandQueue; Usb::UsbDeviceCommandSet* const m_usbDeviceCommands; public: WriteCableInfoJsonCommand(std::shared_ptr description, Usb::UsbDeviceManager* const usbDeviceManager) : DeviceComplexJsonCommand(description) , m_commandQueue(usbDeviceManager->getCommandQueue()) , m_usbDeviceCommands(usbDeviceManager->getCommandSet()) { } WriteCableInfoJsonCommand(Usb::UsbDeviceManager* const usbDeviceManager) : WriteCableInfoJsonCommand(createCommandDescription(), usbDeviceManager) { } public: static std::shared_ptr createCommandDescription() { return std::make_shared("WriteCableInfo", std::make_shared(std::vector>{ std::make_shared("Version", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("CableRegime", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("CableType", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("CableNumber", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("SetupCounter", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("DateOfCreate", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("BeginUsageDate", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("LastInstallDate", Net::WebApi::EJsonCommandUnitType::String) }), 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(); Usb::CableInfo cableInfo; cableInfo.Version = static_cast(jsonMap["Version"].toInt()); cableInfo.CableRegime = static_cast(jsonMap["CableRegime"].toInt()); cableInfo.CableType = static_cast(jsonMap["CableType"].toInt()); cableInfo.CableNumber = static_cast(jsonMap["CableNumber"].toInt()); cableInfo.SetupCounter = static_cast(jsonMap["SetupCounter"].toInt()); cableInfo.DateOfCreate = jsonMap["DateOfCreate"].toDate(); cableInfo.BeginUsageDate = jsonMap["BeginUsageDate"].toDate(); cableInfo.LastInstallDate = jsonMap["LastInstallDate"].toDate(); std::shared_ptr commandData = std::make_shared>(m_commandQueue->generateUid(), cableInfo); std::shared_ptr command = std::dynamic_pointer_cast(m_usbDeviceCommands->createComplexCommand(launchedCommandInfo->name, commandData)); m_executedCommands[command.get()] = command; connect(command.get(), &DeviceComplexCommands::WriteCableInfoCommand::answerIsReady, this, &WriteCableInfoJsonCommand::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