Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/src/control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,15 @@ class Gen5HelloInfo {

/// Parse EXACTLY the response body (no header). Returns null when the body is
/// shorter than the [semanticBodyLen] the fixed-offset parser needs — a short
/// body is a failed/foreign reply, never a partially-filled hello — or when
/// the body does not announce hello revision 1, since every offset below is
/// revision-1-specific and reading them out of an unknown revision would
/// invent an identity rather than decode one.
/// body is a failed/foreign reply, never a partially-filled hello. The
/// revision byte is recorded in [helloRevision] but is not a gate: the
/// official parser reads the fixed revision-1 offsets regardless of its
/// value.
///
/// Callers should additionally gate on the command-response STATUS byte; a
/// non-success reply leaves the body unpopulated (see [parseCommandResponse]).
static Gen5HelloInfo? parse(Uint8List body) {
if (body.length < semanticBodyLen) return null;
if (body[0] != 1) return null; // revision-1 map only
String cstr(int start, int end) {
final sb = StringBuffer();
for (int i = start; i < end && i < body.length; i++) {
Expand Down
11 changes: 9 additions & 2 deletions test/gen5_historical_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,17 @@ void main() {
}
});

test('an unknown hello revision is refused, not read at rev-1 offsets', () {
test('a non-1 hello revision still parses at the fixed offsets', () {
// The revision byte is recorded, not a gate — the official parser reads
// the fixed offsets regardless of its value.
final body = gen5HelloBody();
body[0] = 2; // some future revision
expect(Gen5HelloInfo.parse(body), isNull);
final h = Gen5HelloInfo.parse(body)!;
expect(h.helloRevision, 2);
expect(h.batteryPct, 90);
expect(h.serial, '5AG0000001');
expect(h.firmwareVersion, '50.40.1.0');
expect(h.wristOn, isTrue);
});

test('an out-of-range battery is omitted, never clamped', () {
Expand Down
Loading