#pragma once #include "UsbDeviceManager.h" #include "ReadCalibrationPointCommand.h" #include "DeviceComplexJsonCommand.h" #include "ReadExternAccCalibrationPointsCommand.h" #include "ComplexCommandCreateData.h" namespace Incart::DeviceWebApi { class ReadExternAccCalibrationPointsJsonCommand final : public DeviceComplexJsonCommand { private: Usb::ByteCommandQueue* const m_commandQueue; Usb::UsbDeviceCommandSet* const m_usbDeviceCommands; public: ReadExternAccCalibrationPointsJsonCommand(std::shared_ptr description, Usb::UsbDeviceManager* const usbDeviceManager) : DeviceComplexJsonCommand(description) , m_commandQueue(usbDeviceManager->getCommandQueue()) , m_usbDeviceCommands(usbDeviceManager->getCommandSet()) { } ReadExternAccCalibrationPointsJsonCommand(Usb::UsbDeviceManager* const usbDeviceManager) : ReadExternAccCalibrationPointsJsonCommand(createCommandDescription(), usbDeviceManager) { } public: static std::shared_ptr createCommandDescription() { return std::make_shared("ReadExternAccCalibrationPoints", std::make_shared(), std::make_shared(std::vector>{ std::make_shared("PointIndex", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("ChannelType", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("ChannelNumber", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("AdcValue", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("PhysicalValue", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("Range", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("IsValid", Net::WebApi::EJsonCommandUnitType::String) }) ); } std::shared_ptr execute(std::shared_ptr launchedCommandInfo) override { //Common::JTerminal() << __PRETTY_FUNCTION__; uid = launchedCommandInfo->uid; std::shared_ptr commandData = std::make_shared>(m_commandQueue->generateUid()); std::shared_ptr command = std::dynamic_pointer_cast(m_usbDeviceCommands->createComplexCommand(launchedCommandInfo->name, commandData)); m_executedCommands[command.get()] = command; connect(command.get(), &DeviceComplexCommands::ReadExternAccCalibrationPointsCommand::answerIsReady, this, &ReadExternAccCalibrationPointsJsonCommand::handleCommandAnswerIsReady); return executeCommand(command); } private slots: void handleCommandAnswerIsReady(Usb::ComplexCommand* command, std::vector calibrationPoints, std::shared_ptr status) { removeExecutedCommand(command); emit answerIsReady(this, packCalibrationInfoToJson(calibrationPoints), DeviceWebApi::JsonCommandStatusCreator::create(status)); } private: QJsonDocument packCalibrationInfoToJson(const std::vector& calibrationPoints) { QJsonArray pntArray; for (auto it = calibrationPoints.begin(); it != calibrationPoints.end(); it++) { pntArray.append(packCalibrationPointInfoToJson(*it)); } QJsonObject out({{"CalibrationPoints", pntArray}}); return QJsonDocument(out); } QJsonObject packCalibrationPointInfoToJson(const Usb::CalibrationPoint& point) { QJsonObject out({ {"PointIndex", QString::number(static_cast(point.PointIndex))}, {"ChannelType", QString::number(static_cast(point.ChannelType))}, {"ChannelNumber", QString::number(static_cast(point.ChannelNumber))}, {"AdcValue", QString::number(static_cast(point.AdcValue))}, {"PhysicalValue", QString::number(static_cast(point.PhysicalValue))}, {"Range", QString::number(static_cast(point.Range))}, {"IsValid", (point.IsValid ? "true" : "false")} }); return out; } }; } // namespace Incart::DeviceWebApi