42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
|
|
#include "LOGIC/Lgc_Consumer.h"
|
|||
|
|
|
|||
|
|
void Lgc_Consumer_Func_Parse(const QByteArray& ByteArray, Lgc_Consumer_Struct_Result* p_Result)
|
|||
|
|
{
|
|||
|
|
// 当前调用链内部固定传有效结果对象,这里直接清成默认状态。
|
|||
|
|
*p_Result = Lgc_Consumer_Struct_Result();
|
|||
|
|
|
|||
|
|
// DRI 这轮没有交上来数据时,直接给出提示。
|
|||
|
|
if (ByteArray.isEmpty())
|
|||
|
|
{
|
|||
|
|
p_Result->TextExplain = QStringLiteral("Consumer 端口没有收到数据。");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 第 0 字节不是 0x03,就说明这不是 Consumer 包。
|
|||
|
|
if (static_cast<quint8>(ByteArray.at(0)) != Mid_Enum_ReportId_Consumer)
|
|||
|
|
{
|
|||
|
|
p_Result->TextExplain = QStringLiteral("这不是 report id 0x03。");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
p_Result->IsMatch = true;
|
|||
|
|
|
|||
|
|
// 当前固件里的 0x03 包固定就是 3 字节。
|
|||
|
|
if (ByteArray.size() != MID_CONST_PACKET_SIZE_CONSUMER)
|
|||
|
|
{
|
|||
|
|
p_Result->TextExplain = QStringLiteral("0x03 包长度不对。");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
p_Result->IsLengthOk = true;
|
|||
|
|
|
|||
|
|
// 第 1、2 字节按 little-endian 规则还原成 16 位 usage。
|
|||
|
|
p_Result->Usage =
|
|||
|
|
static_cast<quint8>(ByteArray.at(1)) |
|
|||
|
|
(static_cast<quint16>(static_cast<quint8>(ByteArray.at(2))) << 8);
|
|||
|
|
|
|||
|
|
// 当前项目里只保留简短解释,避免调试日志过于冗长。
|
|||
|
|
p_Result->TextExplain = QStringLiteral("0x03 Consumer:%1")
|
|||
|
|
.arg(Mid_Func_GetConsumerUsageText(p_Result->Usage));
|
|||
|
|
}
|