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
2 changes: 1 addition & 1 deletion decode_parity_cases.json

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions lib/src/live.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ RealtimeRrResult? realtimeRr(String hex) {
final first = cntOff + 1;
for (int i = 0; i < n && first + 2 * i + 2 <= b.length; i++) {
final v = view.getInt16(first + 2 * i, Endian.little);
if (v > 0) rrMs.add(v);
// Same physiological range records.dart and control.dart gate on — a
// misaligned or corrupted slot should not reach live HRV/breathing
// compute as a beat just because this decoder forgot to check it too.
if (v >= kMinRrMs && v <= kMaxRrMs) rrMs.add(v);
}
return rrMs.isNotEmpty ? RealtimeRrResult(ts, rrMs) : null;
}
Expand Down Expand Up @@ -334,8 +337,13 @@ DecodedSample? decodeRecord(String hex) {
return DecodedSample(
ts: d.tsEpoch,
hr: d.hr,
activity: 0,
stepsInc: 0,
// This record family carries no IMU stepping window at all — that is
// "no usable IMU data", the same absence [DecodedSample.activity]'s
// doc comment describes for a truncated R10, not a measured 0.0/0.
// Fabricating zero here is the exact bug this decoder family was just
// fixed to stop making for R10.
activity: null,
stepsInc: null,
wristOn: d.hr > 0,
recType: recType,
);
Expand Down
50 changes: 50 additions & 0 deletions test/decode_guards_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ void main() {
// decodeRecord never invents a timestamp for a layout we cannot read.
expect(decodeRecord(_patched(_goodV24, {1: 11})), isNull);
});

test('the routed historical family reports null activity/steps, not 0/0',
() {
// v7/v9/v12/v18/v24 carry no IMU stepping window at all — that is the
// same "no usable IMU data" absence as a truncated R10, not a measured
// zero-motion reading. Fabricating 0 here silently misreports "this
// record type cannot say" as "the wrist was still".
for (final version in [9, 12, 18, 24]) {
final s = decodeRecord(_patched(_goodV24, {1: version}))!;
expect(s.activity, isNull, reason: 'v$version activity');
expect(s.stepsInc, isNull, reason: 'v$version stepsInc');
}
});
});

// ── 4. parseRealtimeHr reads every declared R-R slot ─────────────────────
Expand Down Expand Up @@ -251,6 +264,43 @@ void main() {
});
});

// ── 4b. live.dart realtimeRr shares the same physiological RR bound ──────
group('realtimeRr is bounded like parseRealtimeHr', () {
test('out-of-range slot values are dropped, in-range ones kept', () {
// 5ms (12,000bpm) and 3000ms are outside kMinRrMs..kMaxRrMs; a
// misaligned/corrupted 0x28 frame must not hand these to live HRV
// compute just because realtimeRr forgot the bound control.dart and
// records.dart both apply.
final f = _realtimeHrFrame(
ts: 1775395266,
hr: 62,
declaredCount: 4,
rrMs: [800, 5, 3000, 830],
);
expect(realtimeRr(_hex(f))!.rrMs, [800, 830]);
});

test('a frame with only out-of-range values yields no result at all', () {
final f = _realtimeHrFrame(
ts: 1775395266,
hr: 62,
declaredCount: 2,
rrMs: [5, 32000],
);
expect(realtimeRr(_hex(f)), isNull);
});

test('it still agrees with parseRealtimeHr once both are bounded', () {
final f = _realtimeHrFrame(
ts: 1775395266,
hr: 62,
declaredCount: 4,
rrMs: [800, 5, 3000, 830],
);
expect(realtimeRr(_hex(f))!.rrMs, parseRealtimeHr(f)!.rrMs);
});
});

// ── 5. GET_ALARM_TIME dispatches on the on-wire alarm form ───────────────
group('GET_ALARM_TIME form dispatch', () {
const epoch = 1775395266;
Expand Down
Loading