#pragma once #include "ByteCommandQueue.h" #include "WriteCableSetupCounterCommand.h" namespace Incart::DeviceComplexCommands { class MicroMonWriteCableSetupCounterCommand final : public WriteCableSetupCounterCommand { Q_OBJECT private: uint32_t m_setupCounter; Usb::ByteCommandQueue* const m_commandQueue; public: MicroMonWriteCableSetupCounterCommand(uint32_t uid, uint32_t setupCounter, Usb::ByteCommandQueue* const commandQueue) : WriteCableSetupCounterCommand(uid) , m_setupCounter(setupCounter) , m_commandQueue(commandQueue) { } public: std::shared_ptr execute() override { std::shared_ptr setupCounterCommand = std::make_shared("WriteSetupCounter", m_commandQueue->generateUid(), std::vector{ 0x7e, 0x05, 0x00, 0x1e, 0x06, static_cast(m_setupCounter & 0x000000ff), static_cast(m_setupCounter & 0x0000ff00), static_cast(m_setupCounter & 0x00ff0000), static_cast(m_setupCounter & 0xff000000), 0xff, 0xff, 0xbd }, 4000); connect(setupCounterCommand.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonWriteCableSetupCounterCommand::handleSetupCounterAnswerIsReady); m_commandQueue->enqueue(setupCounterCommand); return std::make_shared(Usb::DeviceCommand::EStatus::OK); } private slots: void handleSetupCounterAnswerIsReady(std::shared_ptr /*command*/, std::vector answer, int32_t status) { std::cout << __PRETTY_FUNCTION__ << std::endl; if (status != Usb::DeviceCommand::EStatus::OK) { emit answerIsReady(this, Usb::DeviceCommandStatusCreator::create(answer, status)); return; } std::shared_ptr cableResetCommand = std::make_shared("ResetCable", m_commandQueue->generateUid(), std::vector{ 0x7e, 0x01, 0x00, 0x1e, 0x0b, 0xff, 0xff, 0xbd }, 4000); connect(cableResetCommand.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonWriteCableSetupCounterCommand::handleCableResetAnswerIsReady); m_commandQueue->enqueue(cableResetCommand); } void handleCableResetAnswerIsReady(std::shared_ptr /*command*/, std::vector answer, int32_t status) { std::cout << __PRETTY_FUNCTION__ << std::endl; if (status != Usb::DeviceCommand::EStatus::OK) { emit answerIsReady(this, Usb::DeviceCommandStatusCreator::create(answer, status)); } else { // ждем пока прибор запишет информацию в кабель и перезапустит работу с ним QTimer::singleShot(2000, this, [this, answer, status](){ emit answerIsReady(this, Usb::DeviceCommandStatusCreator::create(answer, status)); }); } } }; } // namespace Incart::DeviceComplexCommands