#pragma once #include "ByteCommand.h" #include "CalibrationPoint.h" #include "ComplexCommand.h" #include "ByteCommandQueue.h" namespace Incart::DeviceComplexCommands { class ReadCalibrationPointCommand : public Usb::ComplexCommand { Q_OBJECT private: uint8_t m_pointIndex; uint8_t m_channelType; uint8_t m_channelNumber; bool m_isExternal; Usb::ByteCommandQueue* m_commandQueue; public: ReadCalibrationPointCommand(uint32_t uid, uint8_t _pointIndex, uint8_t _channelType, uint8_t _channelNumber, bool _isExternal, Usb::ByteCommandQueue* commandQueue, QObject* _parent = nullptr) : Usb::ComplexCommand("ReadCalibrationPoint", uid, _parent), m_pointIndex(_pointIndex), m_channelType(_channelType), m_channelNumber(_channelNumber), m_isExternal(_isExternal), m_commandQueue(commandQueue) { } signals: void answerIsReady(Usb::ComplexCommand* command, Usb::CalibrationPoint calibrationPoint, std::shared_ptr status); public: std::shared_ptr execute() override { uint8_t commandByte = m_isExternal ? 0x22 : 0x21; std::shared_ptr byteCommand = std::make_shared("ReadCalibrationPoint", m_commandQueue->generateUid(), std::vector{ 0x7e, 0x04, 0x00, commandByte, 0x00, m_channelType, m_channelNumber, m_pointIndex, 0xff, 0xff, 0xbd}); connect(byteCommand.get(), &Usb::ByteCommand::answerIsReady, this, &ReadCalibrationPointCommand::handleAnswerIsReady); m_commandQueue->enqueue(byteCommand); return std::make_shared(Usb::DeviceCommand::EStatus::OK); } private slots: void handleAnswerIsReady(std::shared_ptr /*command*/, std::vector _answer, int32_t status) { if (status != Usb::DeviceCommand::EStatus::OK) { emit answerIsReady(this, Usb::CalibrationPoint(), Usb::DeviceCommandStatusCreator::create(_answer, status)); return; } uint32_t adcValue = static_cast(Common::ByteArrayProvider::ulongFromArray(_answer, 6)); double physicalValue = static_cast(Common::ByteArrayProvider::intThreeBytesFromArray(_answer, 10)); int8_t range = static_cast(_answer[13]); Usb::CalibrationPoint point(m_pointIndex, m_channelType, m_channelNumber, adcValue, physicalValue, range); point.IsValid = (static_cast(_answer[5]) != 0); emit answerIsReady(this, point, std::make_shared(Usb::DeviceCommand::EStatus::OK)); } }; } // namespace Incart::DeviceComplexCommands