#pragma once #include "ComplexCommand.h" #include "ByteCommandQueue.h" #include "ReadNumberCommand.h" #include "ByteArrayProvider.h" namespace Incart::DeviceComplexCommands { class MicroMonReadNumberCommand : public ReadNumberCommand { private: Usb::ByteCommandQueue* m_commandQueue; public: MicroMonReadNumberCommand(uint32_t uid, Usb::ByteCommandQueue* commandQueue) : ReadNumberCommand(uid) , m_commandQueue(commandQueue) { } public: std::shared_ptr execute() override { std::shared_ptr command = std::make_shared("ReadNumber", m_commandQueue->generateUid(), std::vector{ 0x7e, 0x00, 0x00, 0x16, 0xff, 0xff, 0xbd }); connect(command.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonReadNumberCommand::handleAnswerIsReady); m_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; uint32_t number = 0; if (status != Usb::DeviceCommand::EStatus::OK) { statusInfo = Usb::DeviceCommandStatusCreator::create(answer, status); } else if (answer.size() < 11) { statusInfo = std::make_shared>>(Usb::DeviceCommand::EStatus::WRONG_FRAME_FORMAT, answer); } else { number = Common::ByteArrayProvider::getDWordFromArray(&answer[0], answer.size(), 4); statusInfo = std::make_shared(Usb::DeviceCommand::EStatus::OK); } emit answerIsReady(this, number, statusInfo); } }; } // namespace Incart::DeviceComplexCommands