Skip to content
Closed
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
1 change: 0 additions & 1 deletion lib/openstrap_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export 'src/commands.dart'
cmdDisableAlarm,
kDefaultAlarmHaptics,
gen5ClientHello,
cmdGetDataRangeGen5,
cmdSendHistoricalGen5,
cmdSetClockGen5,
cmdGetClockGen5,
Expand Down
12 changes: 6 additions & 6 deletions lib/src/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ Uint8List cmdSetClock(int seq,
return buildCommand(seq, Cmd.setClock, payload, profile);
}

Uint8List cmdGetDataRange(int seq) =>
buildCommand(seq, Cmd.getDataRange, const [0x00]);
/// GET_DATA_RANGE (0x22) — shared opcode, envelope + payload differ by
/// profile: gen4 takes a `[0x00]` body, gen5 expects an EMPTY payload (see
/// control.dart's dual-profile decoder for this opcode).
Uint8List cmdGetDataRange(int seq, {BandProfile profile = BandProfile.gen4}) =>
buildCommand(seq, Cmd.getDataRange,
profile.isGen5 ? const [] : const [0x00], profile);
Uint8List cmdReportVersionInfo(int seq) =>
buildCommand(seq, Cmd.reportVersionInfo, const []);

Expand Down Expand Up @@ -602,10 +606,6 @@ Uint8List cmdDisableAlarm(int seq,
Uint8List gen5ClientHello({int seq = 1}) =>
buildCommand(seq, Cmd.getHello, const [0x01], BandProfile.gen5);

/// gen5 GET_DATA_RANGE (0x22) with the EMPTY payload gen5 expects.
Uint8List cmdGetDataRangeGen5(int seq) =>
buildCommand(seq, Cmd.getDataRange, const [], BandProfile.gen5);

/// gen5 SEND_HISTORICAL_DATA (0x16) with the EMPTY payload gen5 expects — the
/// command that starts the flash drain.
Uint8List cmdSendHistoricalGen5(int seq) =>
Expand Down
3 changes: 2 additions & 1 deletion test/doc_conformance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void main() {
// zeros — any real body byte here would be a doc deviation.
expect(c.inner.length, 4);
expect(c.inner[3], 0, reason: 'alignment padding, not a body byte');
final r = parseFrame(cmdGetDataRangeGen5(1), profile: BandProfile.gen5)!;
final r = parseFrame(
cmdGetDataRange(1, profile: BandProfile.gen5), profile: BandProfile.gen5)!;
expect(r.inner[2], 34);
expect(r.inner.length, 4);
expect(r.inner[3], 0, reason: 'alignment padding, not a body byte');
Expand Down
9 changes: 9 additions & 0 deletions test/whoop_protocol_update_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ void main() {
expect(frame.inner, [0x23, 0x06, 0x22, 0x00]);
});

test('cmdGetDataRange(profile: gen5) frames with the gen5 envelope', () {
final frame = parseFrame(
cmdGetDataRange(0x07, profile: BandProfile.gen5),
profile: BandProfile.gen5)!;
expect(frame.valid, isTrue);
// gen5 body is empty — inner is [type][seq][opcode] padded to /4.
expect(frame.inner, [0x23, 0x07, 0x22, 0x00]);
});

test('cmdSetClock builds the WHOOP-exact 8-byte sec+subsec payload', () {
// Fixed instant: sec = 0x12345678, millis = 500.
// subsec = 500 * 32768 ~/ 1000 = 16384 = 0x4000 (u16 LE, then 2 zero pad).
Expand Down
Loading