mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
fix: stop lpp zero tail
ref:
This commit is contained in:
@@ -25,6 +25,14 @@ class CayenneLppParser {
|
|||||||
|
|
||||||
int fieldCount = 0;
|
int fieldCount = 0;
|
||||||
while (reader.hasRemaining) {
|
while (reader.hasRemaining) {
|
||||||
|
if (fieldCount > 0 && _isZeroPaddedTail(data, reader.remainingBytesCount)) {
|
||||||
|
debugPrint(
|
||||||
|
' Detected zero-padded telemetry tail, stopping parse at position '
|
||||||
|
'${data.length - reader.remainingBytesCount}',
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fieldCount++;
|
fieldCount++;
|
||||||
debugPrint(
|
debugPrint(
|
||||||
@@ -250,6 +258,14 @@ class CayenneLppParser {
|
|||||||
return ((voltage - 3.0) / 1.2) * 100.0;
|
return ((voltage - 3.0) / 1.2) * 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _isZeroPaddedTail(Uint8List data, int remainingBytes) {
|
||||||
|
final start = data.length - remainingBytes;
|
||||||
|
for (int i = start; i < data.length; i++) {
|
||||||
|
if (data[i] != 0) return false;
|
||||||
|
}
|
||||||
|
return remainingBytes > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Create Cayenne LPP data for GPS location
|
/// Create Cayenne LPP data for GPS location
|
||||||
/// Standard Cayenne LPP GPS format (type 0x88):
|
/// Standard Cayenne LPP GPS format (type 0x88):
|
||||||
/// - Latitude: 3 bytes, signed 24-bit, big-endian, × 10000
|
/// - Latitude: 3 bytes, signed 24-bit, big-endian, × 10000
|
||||||
|
|||||||
@@ -410,6 +410,24 @@ void main() {
|
|||||||
expect(decoded.batteryMilliVolts, closeTo(3850, 1));
|
expect(decoded.batteryMilliVolts, closeTo(3850, 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('stops parsing at zero-padded telemetry tail', () {
|
||||||
|
final payload = Uint8List.fromList([
|
||||||
|
0x01, 0x74, 0x01, 0x5F, // voltage 3.51V
|
||||||
|
0x01, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00,
|
||||||
|
]);
|
||||||
|
|
||||||
|
final decoded = CayenneLppParser.parse(payload);
|
||||||
|
|
||||||
|
expect(decoded.batteryMilliVolts, closeTo(3510, 1));
|
||||||
|
expect(decoded.batteryPercentage, closeTo(42.5, 0.1));
|
||||||
|
expect(decoded.gpsLocation, isNotNull);
|
||||||
|
expect(decoded.gpsLocation!.latitude, 0.0);
|
||||||
|
expect(decoded.gpsLocation!.longitude, 0.0);
|
||||||
|
expect(decoded.extraSensorData?['digital_input_0'], isNull);
|
||||||
|
});
|
||||||
|
|
||||||
test('empty data returns empty telemetry', () {
|
test('empty data returns empty telemetry', () {
|
||||||
final empty = Uint8List(0);
|
final empty = Uint8List(0);
|
||||||
final decoded = CayenneLppParser.parse(empty);
|
final decoded = CayenneLppParser.parse(empty);
|
||||||
|
|||||||
Reference in New Issue
Block a user