diff --git a/lib/src/miscale.dart b/lib/src/miscale.dart index ab2e47a..696633d 100644 --- a/lib/src/miscale.dart +++ b/lib/src/miscale.dart @@ -25,7 +25,9 @@ // // STORED HISTORY (both scales) — on [kMiScaleHistoryChar], notify + write: // host `01 ` how many records for this user -// scale `01 ` +// scale `01 ` (the XMTZC05HM appends four more bytes, +// seen as `01 00 00 00` after a request for +// user 1; their meaning is not established) // host `02` send them (skipped when count is 0) // scale records: 10-byte Scale 2 records, or 13-byte frames laid out as // 0x2A9C on the composition scale; a notification of one byte or @@ -144,9 +146,14 @@ List miScaleHistoryRequest(int userId) => [ (userId >> 24) & 0xff, ]; -/// The record count in the scale's `01 ` answer, or null. +/// The record count in the scale's `01 ` answer, or null. The +/// Mi Body Composition Scale 2 (XMTZC05HM) answers with 7 bytes: the same +/// three, then four more (seen as `01 00 00 00` after a request for user 1; +/// whether that is the user id is not established, so it is not validated). int? miScaleHistoryCount(List b) => - b.length == 3 && b[0] == 0x01 ? b[1] | (b[2] << 8) : null; + (b.length == 3 || b.length == 7) && b[0] == 0x01 + ? b[1] | (b[2] << 8) + : null; const List kMiScaleHistorySend = [0x02]; diff --git a/test/thermometer_scale_test.dart b/test/thermometer_scale_test.dart index b90ea3d..86904f4 100644 --- a/test/thermometer_scale_test.dart +++ b/test/thermometer_scale_test.dart @@ -141,6 +141,11 @@ void main() { expect(miScaleHistoryRequest(0x01020304), [1, 4, 3, 2, 1]); expect(miScaleHistoryCount([0x01, 0x02, 0x01]), 258); expect(miScaleHistoryCount([0x01, 0x02]), isNull); + // Captured from a real XMTZC05HM: counts 2, 3 and 4 (tail 01 00 00 00). + expect(miScaleHistoryCount([1, 2, 0, 1, 0, 0, 0]), 2); + expect(miScaleHistoryCount([1, 3, 0, 1, 0, 0, 0]), 3); + expect(miScaleHistoryCount([1, 4, 0, 1, 0, 0, 0]), 4); + expect(miScaleHistoryCount([1, 2, 0, 1, 0]), isNull); expect(miScaleHistoryDone([0x03]), isTrue); expect(miScaleHistoryDone([]), isTrue); expect(miScaleHistoryDone([0x03, 0]), isFalse);