This commit is contained in:
Alvin-lyq 2026-04-29 13:09:30 +08:00
parent 49993af206
commit 64237aebe7

View File

@ -27,10 +27,16 @@ public:
void subData(const uint8_t* sub_address, int& index) void subData(const uint8_t* sub_address, int& index)
{ {
int dataLength = getLength(m_type);
uint32_t dataSize = getDataSize() - index; // 简单的XOR校验
uint32_t protocolSize = checkXor(&sub_address[index] , dataSize); uint8_t check_sum = 0;
if(protocolSize == 44) for (int i = 0; i < dataLength - 1; ++i)
{
check_sum ^= sub_address[i];
}
if (check_sum == sub_address[dataLength - 1])
{ {
int16_t middle; int16_t middle;
uint32_t tmpU32; uint32_t tmpU32;
@ -49,9 +55,7 @@ public:
m_pubAsensingMsg.temperature = middle * 200.0 / 32768; m_pubAsensingMsg.temperature = middle * 200.0 / 32768;
// time // time
tmpU32 = toValue<uint32_t>(sub_address, sub_index); tmpU32 = toValue<uint32_t>(sub_address, sub_index);
m_pubAsensingMsg.imu_time_stamp = (double)tmpU32 / 4000; m_pubAsensingMsg.time = (double)tmpU32 / 4000;
// status
m_pubAsensingMsg.status = toValue<uint8_t>(sub_address, sub_index);
/* msg header */ /* msg header */
m_pubAsensingMsg.header.frame_id = m_frameId; m_pubAsensingMsg.header.frame_id = m_frameId;
@ -102,7 +106,7 @@ public:
isPrint = true; isPrint = true;
} }
} }
index += protocolSize; index += dataLength;
} }
else else
{ {