#pragma once #include "SetPelCommand.h" #include "UsbDeviceManager.h" namespace Incart::DeviceComplexCommands { class MicroMonSetPelCommand : public SetPelCommand { private: bool m_isReoOn; bool m_isPelOn; Usb::UsbDeviceManager* m_usbDeviceManager; public: MicroMonSetPelCommand(uint32_t uid, bool isPelOn, Usb::UsbDeviceManager* deviceManager) : SetPelCommand(uid) , m_isPelOn(isPelOn) , m_usbDeviceManager(deviceManager) { } public: std::shared_ptr execute() override { std::cout << __FUNCTION__ << " (1)" << std::endl; if (m_usbDeviceManager->getIsReoAndPelRead()) { std::cout << __FUNCTION__ << " (2)" << std::endl; m_isReoOn = m_usbDeviceManager->getIsReoOn(); writePel(); } else { std::cout << __FUNCTION__ << " (3)" << std::endl; std::vector commandBytes; Usb::ByteCommandQueue* commandQueue = m_usbDeviceManager->getCommandQueue(); std::shared_ptr commandInfo = std::make_shared("ReadReoAndPel", commandQueue->generateUid(), std::vector()); m_usbDeviceManager->getCommandSet()->createCommandBytes(commandInfo, commandBytes); std::shared_ptr readReoPelCommand = std::make_shared(commandInfo->name, commandInfo->uid, commandBytes); connect(readReoPelCommand.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonSetPelCommand::handleReadReoPelAnswerIsReady); commandQueue->enqueue(readReoPelCommand); } return std::make_shared(Usb::DeviceCommand::EStatus::OK); } private slots: void handleReadReoPelAnswerIsReady(std::shared_ptr /*command*/, std::vector answer, int32_t status) { std::cout << __FUNCTION__ << " (4)" << std::endl; if (status != Usb::DeviceCommand::EStatus::OK) { std::cout << __FUNCTION__ << " (5)" << std::endl; emit answerIsReady(this, Usb::DeviceCommandStatusCreator::create(answer, status)); return; } std::cout << __FUNCTION__ << " (6)" << std::endl; m_isReoOn = answer[5] == 1; m_usbDeviceManager->setIsReoOn(m_isReoOn); writePel(); } private: void writePel() { std::cout << __FUNCTION__ << " (7)" << std::endl; std::vector commandBytes; std::vector commandData(3); commandData[0] = 0x27; commandData[1] = m_isReoOn ? 0x01: 0x00; commandData[2] = m_isPelOn ? 0x01: 0x00; Usb::ByteCommandQueue* commandQueue = m_usbDeviceManager->getCommandQueue(); std::shared_ptr commandInfo = std::make_shared("WriteReoAndPel", commandQueue->generateUid(), commandData); m_usbDeviceManager->getCommandSet()->createCommandBytes(commandInfo, commandBytes); std::shared_ptr writeReoPelCommand = std::make_shared(commandInfo->name, commandInfo->uid, commandBytes); connect(writeReoPelCommand.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonSetPelCommand::handleWriteReoPelAnswerIsReady); commandQueue->enqueue(writeReoPelCommand); } void handleWriteReoPelAnswerIsReady(std::shared_ptr /*command*/, std::vector answer, int32_t status) { std::cout << __FUNCTION__ << " (8)" << std::endl; emit answerIsReady(this, Usb::DeviceCommandStatusCreator::create(answer, status)); } }; } // namespace Incart::DeviceComplexCommands