#pragma once #include "LsbChannelInfo.h" #include "ReadInnerChannelsLsbCommand.h" #include "ReadInnerChannelsCalibrationCommand.h" #include "MicroMonCalibrationInfoCreators.h" #include "DeviceChannelTypeStringParser.h" #include namespace Incart::DeviceComplexCommands { class MicroMonReadInnerChannelsLsbCommand final : public Usb::ReadInnerChannelsLsbCommand { private: Usb::ByteCommandQueue* const m_commandQueue; std::unordered_map m_channelsLsbInfo; public: MicroMonReadInnerChannelsLsbCommand(uint32_t uid, const std::unordered_map& channelsLsbInfo, Usb::ByteCommandQueue* const commandQueue) : Usb::ReadInnerChannelsLsbCommand(uid) , m_commandQueue(commandQueue) , m_channelsLsbInfo(channelsLsbInfo) { } public: std::shared_ptr execute() override { std::shared_ptr command = std::make_shared(m_commandQueue->generateUid(), m_commandQueue); addExecutedInnerCommand(command); connect(command.get(), &ReadInnerChannelsCalibrationCommand::answerIsReady, this, &MicroMonReadInnerChannelsLsbCommand::handleAnswerIsReady); return executeCommand(command); } private slots: void handleAnswerIsReady(Usb::ComplexCommand* command, std::vector> calibrationInfo_, std::shared_ptr status) { removeExecutedInnerCommand(command); std::unordered_map> calibrationInfo; if (status->status != Usb::DeviceCommand::EStatus::OK) { emit answerIsReady(this, calibrationInfo, status); return; } /* int k = 0; for (auto it = m_channelsLsbInfo.begin(); it != m_channelsLsbInfo.end(); ++it,++k) { std::cout << "m_channelsLsbInfo[" << k << "] " << static_cast(it->first.type) << " " << static_cast(it->first.sourceType) << " | " << static_cast(it->second.channelType) << std::endl; } */ for (auto it = calibrationInfo_.begin(); it != calibrationInfo_.end(); ++it) { uint8_t channelType = (*it)->getChannelType(); auto channelMappedInfo = getChannelMappedInfo(channelType); if (channelMappedInfo.first.type != DevicesInfo::EDeviceChannelType::Unknown) { std::shared_ptr calibInfoCreator = std::dynamic_pointer_cast(channelMappedInfo.second.calibrationInfoCreator); std::vector channelCalibrationInfo; size_t channelCount = channelMappedInfo.second.signalCount; std::vector& calibrationPoints = (*it)->getCalibrationPoints(); for (size_t i = 0; i < channelCount; ++i) { channelCalibrationInfo.push_back(calibInfoCreator->createCalibrationInfo(static_cast(i), calibrationPoints)); } calibrationInfo[channelMappedInfo.first] = channelCalibrationInfo; } } emit answerIsReady(this, calibrationInfo, std::make_shared(Usb::DeviceCommand::EStatus::OK)); } private: std::pair getChannelMappedInfo(uint8_t channelType_) { for (auto it = m_channelsLsbInfo.begin(); it != m_channelsLsbInfo.end(); ++it) { if ((it->second.channelType == channelType_) && (it->first.source == DevicesInfo::EDeviceChannelSourceType::Device)) { return std::pair(it->first, it->second); } } return std::pair({DevicesInfo::EDeviceChannelType::Unknown, DevicesInfo::EDeviceChannelSourceType::Unknown}, {}); } }; } // namespace Incart::DeviceComplexCommands