#pragma once #include "ComplexCommand.h" #include "ByteCommandQueue.h" #include "GetWritingStateCommand.h" #include "ByteArrayProvider.h" #include "UsbDeviceManager.h" namespace Incart::DeviceComplexCommands { class MicroMonGetWritingStateCommand : public GetWritingStateCommand { private: Usb::UsbDeviceManager* const m_usbDeviceManager; public: MicroMonGetWritingStateCommand(uint32_t uid, Usb::UsbDeviceManager* const usbDeviceManager) : GetWritingStateCommand(uid) , m_usbDeviceManager(usbDeviceManager) { } public: std::shared_ptr execute() override { std::vector commandBytes; std::shared_ptr commandInfo = std::make_shared("ReadWritingState", m_usbDeviceManager->getCommandQueue()->generateUid(), std::vector()); 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, &MicroMonGetWritingStateCommand::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; EWritingState state = EWritingState::Dialog; if (status != Usb::DeviceCommand::EStatus::OK) { statusInfo = Usb::DeviceCommandStatusCreator::create(answer, status); } else if ((answer.size() != 8) || ((answer[4] != 1) && (answer[4] != 2))) { statusInfo = std::make_shared>>(Usb::DeviceCommand::EStatus::WRONG_FRAME_FORMAT, answer); } else { if (answer[4] == 2) { state = EWritingState::Writing; } statusInfo = std::make_shared(Usb::DeviceCommand::EStatus::OK); } emit answerIsReady(this, state, statusInfo); } }; } // namespace Incart::DeviceComplexCommands