From c2f92db2174aab8803e03176adda449df82ef12e Mon Sep 17 00:00:00 2001 From: HVBT Dev Date: Tue, 28 Jul 2026 01:35:04 +0530 Subject: [PATCH] Calibrate S300 tail RPM decode --- lib/core/protocol/s300_parser.dart | 5 +++-- test/s300_parser_test.dart | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/core/protocol/s300_parser.dart b/lib/core/protocol/s300_parser.dart index 5665e13..b3593cd 100644 --- a/lib/core/protocol/s300_parser.dart +++ b/lib/core/protocol/s300_parser.dart @@ -45,8 +45,9 @@ SensorState parseS300(Uint8List frame, {bool validateChecksum = true}) { final bool hasTailPayload = _hasS300TailPayload(frame); final int rpmRaw = hasTailPayload ? _readUint16LE(frame, 82) : _readUint16BE(frame, 2); - final double rpm = - (hasTailPayload ? rpmRaw : rpmRaw - 256).clamp(0, 12000).toDouble(); + final double rpm = (hasTailPayload ? rpmRaw - 1089 : rpmRaw - 256) + .clamp(0, 12000) + .toDouble(); // VSS: bytes 5..6 little-endian pulse period. final int vssRaw = _readUint16LE(frame, 5); diff --git a/test/s300_parser_test.dart b/test/s300_parser_test.dart index 3de83f2..4ac6682 100644 --- a/test/s300_parser_test.dart +++ b/test/s300_parser_test.dart @@ -190,7 +190,8 @@ void main() { expect(isS300PlaceholderFrame(frame), isTrue); }); - test('uses tail payload RPM for S300 Bluetooth prefix frames', () { + test('uses calibrated tail payload RPM for S300 Bluetooth prefix frames', + () { final frame = Uint8List(128); final prefix = [ 0x1B, @@ -219,7 +220,7 @@ void main() { frame[127] = calculateNeg8(frame.sublist(0, 127)); final state = parseS300(frame); - expect(state.rpm, equals(3122.0)); + expect(state.rpm, equals(2033.0)); }); }); }