#pragma once #include "UsbDeviceManager.h" #include "StopWritingCommand.h" namespace Incart::DeviceComplexCommands { class MicroMonStopWritingCommand final : public StopWritingCommand { public: private: Usb::UsbDeviceManager* const m_usbDeviceManager; public: MicroMonStopWritingCommand(uint32_t uid, Usb::UsbDeviceManager* const usbDeviceManager) : StopWritingCommand(uid) , m_usbDeviceManager(usbDeviceManager) { } public: std::shared_ptr execute() override { std::vector commandBytes; std::shared_ptr commandInfo = std::make_shared("WriteRecordMode", m_usbDeviceManager->getCommandQueue()->generateUid(), std::vector{static_cast(0x01)}); Usb::DeviceCommand::EStatus status = m_usbDeviceManager->getCommandSet()->createCommandBytes(commandInfo, commandBytes); if (status != Usb::DeviceCommand::EStatus::OK) { return Usb::DeviceCommandStatusCreator::create({}, status); } Usb::ByteCommandQueue* commandQueue = m_usbDeviceManager->getCommandQueue(); std::shared_ptr command = std::make_shared(commandInfo->name, commandInfo->uid, std::move(commandBytes)); connect(command.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonStopWritingCommand::handleAnswerIsReady); commandQueue->enqueue(command); return std::make_shared(Usb::DeviceCommand::EStatus::OK); } private slots: void handleAnswerIsReady(std::shared_ptr /*command*/, std::vector answer, int32_t status) { std::shared_ptr statusInfo; uint8_t result = 0; if (status != Usb::DeviceCommand::EStatus::OK) { statusInfo = Usb::DeviceCommandStatusCreator::create(answer, status); } else if (answer.size() != 8) { statusInfo = std::make_shared>>(Usb::DeviceCommand::EStatus::WRONG_FRAME_FORMAT, answer); } else { result = answer[4]; statusInfo = std::make_shared(Usb::DeviceCommand::EStatus::OK); } emit answerIsReady(this, result, statusInfo); } }; } // namespace Incart::DeviceComplexCommands