Skip to content

Add CGM sensor error reporting customization (cgm_sensor_notes) - #84

Open
bjorkert wants to merge 2 commits into
mainfrom
cgm_sensor_notes
Open

Add CGM sensor error reporting customization (cgm_sensor_notes)#84
bjorkert wants to merge 2 commits into
mainfrom
cgm_sensor_notes

Conversation

@bjorkert

Copy link
Copy Markdown
Member

Adds a customization that reports abnormal Dexcom sensor states to Nightscout as Note treatments: sensor issue, sensor failure, session failure, expiry, excess noise, calibration errors and unrecognized states, for G7 and G5/G6. It mirrors what I did for Trio in bjorkert/Trio feat/cgm-sensor-status-notes, and uses the same note wording so records from both apps read alike.

One note per episode. A problem is reported when it starts and then stays quiet while it persists. A reading the sensor's own kit calls reliable closes the open episodes, so a problem that clears and comes back is reported again. Warmup, a stopped or ended session and an uncalibrated sensor are neither recovery nor fault, and leave open episodes untouched. Episodes are keyed by kind, so a sensor drifting between two flavours of one failure reports once, and they are cleared when a sensor session starts, so a replacement sensor that fails during warmup still reports.

The notes ride the CGM event pipeline Loop already has, from the CGM manager delegate through CgmEventStore and RemoteDataServicesManager to NightscoutService, which owns persistence and upload retry. That keeps the Loop app itself untouched, and no .pbxproj is edited either. The patch adds no files and changes four Swift files, in CGMBLEKit, G7SensorKit, LoopKit and NightscoutService. Those hook points are identical on main, dev and next-dev, so the single patch file covers all three branches. Nothing here changes dosing, glucose handling or what the app displays.

The LoopWorkspace scheme builds on next-dev and on main. The patch applies and reverses cleanly on both, and it coexists with profiles, basal_lock, negative_insulin, now_line and 2hlollipop in either order.

Abnormal Dexcom sensor states are uploaded to Nightscout as Note
treatments: sensor issue, sensor failure, session failure, expiry,
excess noise, calibration errors and unrecognized states, for G7 and
G5/G6.

One note per episode. A problem is reported when it starts and stays
quiet while it persists. A reading the sensor's own kit calls reliable
closes the open episodes, so a problem that clears and returns is
reported again. Warmup, a stopped or ended session and an uncalibrated
sensor leave open episodes untouched. Episodes are keyed by kind, and
are cleared when a sensor session starts.

The notes ride the CGM event pipeline Loop already has, from the CGM
manager delegate through CgmEventStore and RemoteDataServicesManager to
NightscoutService, which owns persistence and upload retry. The Loop app
and every .pbxproj are left alone. The patch adds no files and edits four
Swift files in CGMBLEKit, G7SensorKit, LoopKit and NightscoutService,
whose hook points are identical on main, dev and next-dev, so one patch
file serves all three branches.
Both Dexcom kits re-derive the sensor session start from the phone's
clock on every reading, so consecutive readings of one session differ by
the transport delay. Comparing those dates for equality treated every
reading as a new session and cleared the open episodes, so a persisting
fault produced a note every five minutes.

A session counts as new when its start differs from the tracked one by
more than fifteen minutes, far above the jitter and far below the gap
between two real sessions. The first date seen for a session is the one
kept, so the jitter cannot accumulate.

The G5/G6 event joins the array the manager already builds, so it passes
through the same future-dated event filter and arrives in the same
delegate call as a sensor start. Episodes are written back only when they
change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant