-
-
Notifications
You must be signed in to change notification settings - Fork 89
lefun ring/band: pairs and connects, reports nothing yet #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abdulsaheel
wants to merge
5
commits into
main
Choose a base branch
from
lefun-protocol
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+637
−36
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45c0dab
lefun ring/band: pairs, connects, banks raw bytes only
abdulsaheel a7290a8
lefun: extend the two registry-coverage tests
abdulsaheel 2127edb
lefun: don't drop an unrelated device's live sync on forget
abdulsaheel fbd1197
lefun: repin protocol to the branch that actually has the wire module
abdulsaheel e5dec4d
lefun: fix stale secondary-link cap comment, add host test coverage
abdulsaheel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // A Lefun-protocol OEM ring/band as a [BandAdapter]: no auth, one bounded | ||
| // battery poll, bank every frame the radio hands back. | ||
| // | ||
| // NOTHING HERE HAS MET HARDWARE (ASSUMPTIONS R6). The envelope and the | ||
| // battery report are the only things `protocol`'s `lefun.dart` decodes with | ||
| // any confidence — steps, sleep and PPG all ride the same envelope under | ||
| // their own report codes and have no decoder there, so `signals` is | ||
| // `const {}` and every frame is archived verbatim rather than turned into a | ||
| // value. | ||
| // | ||
| // A BOUNDED POLL, NOT A LIVE SESSION. Unlike a chest strap this device has no | ||
| // per-second stream to hold a link open for — the one thing worth asking for | ||
| // is battery, and everything else worth banking is whatever the ring pushes | ||
| // on its own in the few seconds after that ask. So `run()` writes one | ||
| // request, waits out [replyTimeout], and ends — the host tears the link down | ||
| // once the stream closes, the same way `oura.dart`'s one-shot drain does. | ||
| // | ||
| // ponytail: no GET_ACTIVITY_DATA / GET_SLEEP_DATA / GET_PPG_DATA request | ||
| // builders here, even though their request bodies (a single day-index or | ||
| // PPG-type byte) are simple. Their RESPONSE layouts are not decoded by this | ||
| // file, so requesting them would only bank more undecoded bytes for a | ||
| // question nobody has asked yet — add them when someone verifies a response | ||
| // shape against real hardware. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:openstrap_protocol/openstrap_protocol.dart'; | ||
|
|
||
| import '_registry.dart'; | ||
| import 'adapter.dart'; | ||
| import 'signals.dart'; | ||
|
|
||
| /// The adapter. Not const: [replyTimeout] is overridable so a test does not | ||
| /// have to sit through the real wait. | ||
| class LefunAdapter extends BandAdapter { | ||
| /// How long to hold the link open after the battery request, banking | ||
| /// whatever arrives on the notify characteristic in that window. | ||
| final Duration replyTimeout; | ||
|
|
||
| LefunAdapter({this.replyTimeout = const Duration(seconds: 5)}); | ||
|
|
||
| @override | ||
| BandEntry get entry => kLefun; | ||
|
|
||
| /// NOTHING. See the module doc for why battery — the one report this file | ||
| /// decodes — is not a signal either: it is device state, not a | ||
| /// physiological reading, and it reaches the host as a [BandNote]. | ||
| @override | ||
| Map<InputSignal, Duration> get signals => const {}; | ||
|
|
||
| @override | ||
| Stream<BandEvent> run(BandLink link) async* { | ||
| final raw = <Uint8List>[]; | ||
| int? batteryPct; | ||
| final sub = link.notify(kLefunNotifyChar).listen((rec) { | ||
| final f = parseLefunFrame(rec.$2); | ||
| if (f == null) return; | ||
| // Every frame archived verbatim, decoded or not (owner rulings R1-R3): | ||
| // steps, sleep and PPG all ride this same envelope with no decoder | ||
| // here, and the bytes are banked now so one written later can be run | ||
| // over them. | ||
| raw.add(Uint8List.fromList(rec.$2)); | ||
| if (f.report == kLefunReportBattery) { | ||
| batteryPct = decodeLefunBattery(f.params) ?? batteryPct; | ||
| } | ||
| }); | ||
| try { | ||
| if (!await link.write(kLefunWriteChar, buildLefunFrame(kLefunReportBattery))) { | ||
| link.log('lefun: battery request refused.'); | ||
| } else { | ||
| await Future<void>.delayed(replyTimeout); | ||
| } | ||
| if (batteryPct case final pct?) yield BandNote('battery', pct); | ||
| if (raw.isNotEmpty) yield SampleBatch(const [], raw: raw); | ||
| } finally { | ||
| await sub.cancel(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.