#pragma once #include "ComplexCommand.h" #include "ByteCommandQueue.h" #include "ReadCableExistCommand.h" #include namespace Incart::DeviceComplexCommands { class MicroMonReadCableExistCommand final : public Usb::ReadCableExistCommand { private: Usb::ByteCommandQueue* const m_commandQueue; public: MicroMonReadCableExistCommand(uint32_t uid, Usb::ByteCommandQueue* const commandQueue) : Usb::ReadCableExistCommand(uid), m_commandQueue(commandQueue) { } public: std::shared_ptr execute() override { //JTerminal() << __PRETTY_FUNCTION__; std::shared_ptr command = std::make_shared("ReadCableExist", m_commandQueue->generateUid(), std::vector{ 0x7e, 0x01, 0x00, 0x09, 0x00, 0xff, 0xff, 0xbd }); connect(command.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonReadCableExistCommand::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) { bool isExist = false; std::shared_ptr statusInfo; 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 { isExist = ((uint32_t)answer[4] & (uint32_t)0x01) != 0; //std::cout << __PRETTY_FUNCTION__ << " " << static_cast(isExist) << std::endl; statusInfo = std::make_shared(Usb::DeviceCommand::EStatus::OK); } emit answerIsReady(this, isExist, statusInfo); } }; } // namespace Incart::DeviceComplexCommands