fix(iot-gateway): 兼容设备端消息体长度计算不准确的问题

修改 JT808 解码器,采用更宽松的消息体长度处理策略:
- 使用实际可用的长度(expected 与 actual 取最小值)
- 将长度差异日志降为 DEBUG 级别
- 继续解析消息而不是直接丢弃

原因:部分设备端计算消息体长度时存在偏差,导致位置上报等消息被跳过。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
lzh
2026-01-22 10:10:09 +08:00
parent 177350830a
commit 4cd520ab78

View File

@@ -56,18 +56,16 @@ public class Jt808Decoder {
return ret;
}
if (expectedBodyLength > actualAvailableLength) {
log.warn("[bytes2PackageData][消息体长度不匹配: 头部声明={}, 实际可用={}, 数据总长度={}, 消息ID=0x{}]",
expectedBodyLength, actualAvailableLength, data.length,
// 使用实际可用的长度处理(兼容设备端长度计算不准确的情况)
int actualBodyLength = Math.min(expectedBodyLength, actualAvailableLength);
if (expectedBodyLength != actualAvailableLength) {
log.debug("[bytes2PackageData][消息体长度差异: 头部声明={}, 实际可用={}, 使用={}, 消息ID=0x{}]",
expectedBodyLength, actualAvailableLength, actualBodyLength,
Integer.toHexString(msgHeader.getId()));
// 使用 null 标记长度不匹配(区别于合法的空消息体如心跳)
ret.setBodyBytes(null);
ret.setCheckSum(data[data.length - 1]);
return ret;
}
byte[] bodyBytes = new byte[msgHeader.getBodyLength()];
System.arraycopy(data, msgBodyByteStartIndex, bodyBytes, 0, bodyBytes.length);
byte[] bodyBytes = new byte[actualBodyLength];
System.arraycopy(data, msgBodyByteStartIndex, bodyBytes, 0, actualBodyLength);
ret.setBodyBytes(bodyBytes);
// 3. 解析校验码