#pragma once #include "ComplexCommand.h" #include "ByteCommandQueue.h" #include "ReadCableVersionCommand.h" #include "ByteArrayProvider.h" namespace Incart::DeviceComplexCommands { class MicroMonReadCableVersionCommand final : public ReadCableVersionCommand { private: Usb::ByteCommandQueue* const m_commandQueue; public: MicroMonReadCableVersionCommand(uint32_t uid, Usb::ByteCommandQueue* const commandQueue) : ReadCableVersionCommand(uid), m_commandQueue(commandQueue) { } public: std::shared_ptr execute() override { //JTerminal() << __PRETTY_FUNCTION__; std::shared_ptr command = std::make_shared("ReadCableVersion", m_commandQueue->generateUid(), std::vector{ 0x7e, 0x01, 0x00, 0x1E, 0x00, 0xff, 0xff, 0xbd }); connect(command.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonReadCableVersionCommand::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) { CableVersion cableVersion; std::shared_ptr statusInfo; if (status != Usb::DeviceCommand::EStatus::OK) { statusInfo = Usb::DeviceCommandStatusCreator::create(answer, status); } else if (answer.size() != 23) { statusInfo = std::make_shared>>(Usb::DeviceCommand::EStatus::WRONG_FRAME_FORMAT, answer); } else { cableVersion.HardwareVersion = (uint8_t)answer[4]; cableVersion.SoftwareVersion = Common::ByteArrayProvider::getWordFromArray(answer, 5); for (int i = 0; i < 12; i++) { cableVersion.Uid.push_back(answer[7+i]); } cableVersion.UidCrc = (uint8_t)answer[19]; statusInfo = std::make_shared(Usb::DeviceCommand::EStatus::OK); } emit answerIsReady(this, cableVersion, statusInfo); } }; } // namespace Incart::DeviceComplexCommands