#pragma once #include "DeviceComplexJsonCommand.h" #include "WriteEcgModeCommand.h" #include "UsbDeviceManager.h" #include "EcgModeConverter.h" #include "ComplexCommandCreateMultidata.h" namespace Incart::DeviceWebApi { class WriteEcgModeJsonCommand final : public DeviceComplexJsonCommand { private: Usb::ByteCommandQueue* const m_commandQueue; Usb::UsbDeviceCommandSet* const m_usbDeviceCommands; public: WriteEcgModeJsonCommand(std::shared_ptr description, Usb::UsbDeviceManager* const usbDeviceManager) : DeviceComplexJsonCommand(description) , m_commandQueue(usbDeviceManager->getCommandQueue()) , m_usbDeviceCommands(usbDeviceManager->getCommandSet()) { } WriteEcgModeJsonCommand(Usb::UsbDeviceManager* const usbDeviceManager) : WriteEcgModeJsonCommand(createCommandDescription(), usbDeviceManager) { } public: static std::shared_ptr createCommandDescription() { return std::make_shared("WriteEcgMode", std::make_shared(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; QString cableModeName = launchedCommandInfo->data.toString().toLower(); Usb::UsbDevice::EEcgMode cableMode = Usb::EcgModeConverter::fromText(cableModeName); std::cout << __PRETTY_FUNCTION__ << " Mode=" << cableModeName.toUtf8().constData() << std::endl; std::shared_ptr commandData = std::make_shared>(m_commandQueue->generateUid(), cableMode); std::shared_ptr command = std::dynamic_pointer_cast(m_usbDeviceCommands->createComplexCommand(launchedCommandInfo->name, commandData)); m_executedCommands[command.get()] = command; connect(command.get(), &DeviceComplexCommands::WriteEcgModeCommand::answerIsReady, this, &WriteEcgModeJsonCommand::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