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: 2 additions & 0 deletions app/src/main/java/com/pulseloop/ring/JringDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ class JringSyncEngine(
// 0x0E device modes, from the vendor app (RingEncoder.makeDeviceModeCommand).
override fun powerOff() { writer?.enqueue(encoder.makeDeviceModeCommand(JringDeviceMode.POWER_OFF)) }
override fun factoryReset() { writer?.enqueue(encoder.makeDeviceModeCommand(JringDeviceMode.FACTORY_RESET)) }
override val historyPassRunning: Boolean get() = historySync.isRunning

override fun restartDevice(): Boolean {
writer?.enqueue(encoder.makeDeviceModeCommand(JringDeviceMode.RESTART))
return true
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/pulseloop/ring/WearableDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ interface RingSyncEngine {
* reconnecting only. Never implement this with a guessed opcode (AGENTS.md).
*/
fun restartDevice(): Boolean = false

/**
* Whether a multi-step history pass is still in flight, so the background worker can hold the
* link until it finishes instead of cutting it at a fixed time. Families that don't page their
* history report false and keep the worker's fixed window.
*/
val historyPassRunning: Boolean get() = false
/** Push user anthropometrics (age/sex/height/weight) so on-device BP/sugar/calorie
* algorithms have real inputs. No-op if unsupported. */
fun setUserInfo(ageYears: Int, isMale: Boolean, heightCm: Int, weightKg: Int) {}
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/pulseloop/service/RingSyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class RingSyncWorker(

companion object {
private const val WORK_NAME = "ring_background_sync"
private const val SYNC_TIMEOUT_SECONDS = 45L
private const val SYNC_TIMEOUT_SECONDS = 150L
/** How long past the fixed window to wait for a paged history pass to finish (jring: up to
* six requests per day, three days on a fresh connection, measured at ~50 s). */
private const val HISTORY_PASS_EXTRA_MS = 90_000L
private const val TAG = "RingSyncWorker"

@Volatile
Expand Down Expand Up @@ -132,6 +135,16 @@ class RingSyncWorker(
delay(1000L)
if (isAppForeground()) return@withTimeout Result.success()
}
// A paged history pass (jring's per-day chain of offline logs) outlasts the fixed
// window: a 2026-11-12 export showed every background pass cut at ~15 s, before
// temperature, SpO₂, the sensor log or workouts were asked for. Hold the link
// while it runs, bounded.
var extra = 0L
while (bleClient.syncEngine?.historyPassRunning == true && extra < HISTORY_PASS_EXTRA_MS) {
delay(1000L)
extra += 1000L
if (isAppForeground()) return@withTimeout Result.success()
}

// Health Connect export trigger (Phase 1): the background sync has streamed its
// data — run the (debounced) export pass. The foreground path triggers the same
Expand Down
15 changes: 15 additions & 0 deletions docs/jring-56ff-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ PulseLoop's decoder (2026-11-11). Two changes came out of it:
The rest are settings acknowledgements, ECG (bit 9, not set on the owner's ring), or watch-only
features (dials, contacts, AI, Wi-Fi). There is nothing left to import.

**Confirmed on the owner's ring (2.16.3 export, 2026-11-12).** Every new request was answered:
- **Frames:** `0x39` 127, `0x40` 54 and `0x55` 85 frames carried data, and none decoded as
`unknown`.
- **Order:** each day ran in the vendor's order (10 → 16 → 39 → 40 → 55 → 25).
- **Full-day replies:** today's `0x40` stream ran up to an empty 23:45 frame, so the ring sends
the whole day, future slots included. That frame ended the leg at once, as designed.
- **Workouts:** `0x25` answered one empty frame per day, because no workout was recorded in sport
mode. The slot layout is still unconfirmed.
- **Late frames:** one `0x55` frame arrived 2 ms after its 23:45 frame. It was already in flight,
was decoded anyway, and is harmless because the import is idempotent.
- **Background syncs:** this export also showed every background sync cut at about 15 s, before
the offline logs were reached. `RingSyncWorker` disconnected on a fixed timer, so it now holds
the link while `RingSyncEngine.historyPassRunning` is true, for up to 90 s more. The whole
chain for three days took about 50 s in the foreground.

Imported since 2.16.2 as a third step per day in `JringHistorySync` (activity/sleep → HR → `0x55`),
decoded by `RingDecoder.decodeSensorHistory`. Same rules as the vendor: BP only when both halves
are non-zero, every other value only when non-zero.
Expand Down
Loading