#pragma once #include "FrameDecoder.h" namespace Incart::Usb { // Создан для приема кадров Асс кабеля для приборов 7ой серии class CableFrameDecoder final: public FrameDecoder { using ChannelTypeInfo = DevicesInfo::DeviceChannelTypeInfo; using ChannelType = DevicesInfo::EDeviceChannelType; using ChannelSource = DevicesInfo::EDeviceChannelSourceType; public: CableFrameDecoder() : FrameDecoder("Cable") { m_data.push_back(AdcChannelData{ ChannelTypeInfo{ ChannelType::Acc, ChannelSource::Cable }, 3 }); } protected: bool isValidFrame(const std::vector& frame) override { if (frame.size() != 7 + 3*4 + 2) { return false; } int32_t z0 = static_cast(frame[0]); int32_t z1 = static_cast(frame[1]); int32_t z2 = static_cast(frame[2]); int32_t z3 = static_cast(frame[3]); int32_t sign = z0 | (z1<<8) | (z2<<16) | (z3<<24); return sign == static_cast(0x81000E7E); } uint32_t getFrameNumber(const std::vector& frame) override { int p = 4 + 3 * 4; uint32_t z0 = static_cast(frame[p++]); uint32_t z1 = static_cast(frame[p++]); uint32_t ret = ( z0 | (z1<<8)); return ret; } bool hasButtonLabel(const std::vector& /*frame*/) override { return false; } void parseData(const std::vector& frame) override { auto& data = m_data[0].getData(); for(int ch = 0; ch < 3; ++ch) { data[ch] = getAdcValue(frame, ch); } } int32_t getAdcValue(const std::vector& frame, int n) { int p = 4 + 3 * n; if ((p < 0) | (p > (4 + 3 * 4))) return 0; // непонятно, что тут делать uint32_t z0 = static_cast(frame[p++]); uint32_t z1 = static_cast(frame[p++]); uint32_t z2 = static_cast(frame[p++]); uint32_t z3 = 0; if ((z2&0x80) != 0) z3 = static_cast(0xFF000000); int32_t res = static_cast(z0 | (z1<<8) | (z2<<16) | z3); return res; } }; } // namespace Incart::Usb