App tour¶
Bench hardware only. Never connect TwiistOff to a pump that is attached to a person.
Screens¶
Bottom tabs
| Tab | What it does |
|---|---|
| Connect | A Permissions missing card while an Android permission the app needs is not allowed (Permissions and files). Previous session: the remembered pump, the automatic reconnect's stages as they run (connect, registration, arm, first status, readiness), Reconnect, Stop, the Reconnect at start-up switch and Forget this pump (Pairing and setup §8.3). Then one gated block per step: Scan → Connect → Bond (label PIN) → MTU 247 → Registration check → Arm (key) → Ready. Likely pumps are highlighted with a badge for each reason they matched (serial-shaped name, manufacturer ID 0x026B). Once armed, if the first status shows the pump not configured (configurationState ≠ 0x1FFF) or not primed, the app opens the Cassette set-up wizard by itself (pairing mode clears both). |
| Monitor | The live decoded status: reservoir, battery, basal, pump state (per bit), alarms / alerts / notices, what the pump is sounding (byte 91), configuration (0x1FFF = configured), the pump's loop status (ring colour, gray reason, calculation stage), the pump firmware (RIS messages / events versions, flagged when untested), closed loop, readiness ("can deliver" vs "is delivering"). |
| Deliver | Standard bolus with live "delivered of requested" progress, plus STOP and suspend. |
| Adjust | Temp basal in U/h (0x8102) or % of the basal pattern (0x8101, 0–200 %), cancel, suspend / resume basal, and the pump's closed-loop switch. The switch writes the stored closed-loop setting (0x8009); Loop ON… asks for a confirmation first. |
| Menu | Links to the pages below, the session export and the Reconnect at start-up switch (the same setting as on Connect). |
From the Menu
| Page | What it does |
|---|---|
| Cassette set-up | The wizard for putting a cassette on, one step at a time from where the pump actually is: Attach (self-test) → Fill (declare the volume, default 300 U) → Prime with the live volume and a DROPS — STOP button → Prime complete (or prime more) → Configure pump (all 20 settings, with a per-write report) → Verify → Start basal at a chosen rate → optional cannula fill. On a set-up pump it offers Change cassette…; on an unprimed one, Start a new-cassette set-up. Pairing and setup §5. |
| Set-up & recovery wizards | The recovery hub: the pump's blocking conditions, the cassette set-up, and the seven wizards (Configure pump, Alarm recovery, Battery change, Pump restarted, New phone or reinstall, Cassette-change mode, Change delivery limits), with the one the pump's state calls for marked suggested now. Each wizard lists its steps (done / now / waiting / later), says what to do physically, and offers the real choices (same cassette or a new one; line fixed or infusion set changed). Setup and recovery §6.3. |
| Therapy settings | All 20 settings the app writes to the pump, each with its stored value, its opcode and a NOT WRITTEN mark until the pump is known to hold it (it accepted the write, or a verify answering 01 proves it; an import of the values the pump holds marks nothing). Saving a value stores it, writes that one setting and re-verifies. Verify, Write N unwritten, Change delivery limits (the pump takes new limits only with basal stopped; while basal runs an unchanged limits setting is not rewritten), Rewrite all settings to the pump (Configure), Export to file / Share / Import file / Paste (moving settings between phones), the bench defaults and bench replay presets, the closed-loop switch, Read loop config from the pump and Sync pump clock. |
| Pattern editor (from Therapy settings) | One 48-slot pattern (basal, insulin sensitivity, carb ratio, glucose target low / high) as half-hour slots from midnight in real units: tap a slot, or Set a range… (e.g. 00:00 to 24:00 for all day). The basal editor shows the daily total and the max basal. Nothing is sent until Save and write (one settings write, then a re-verify). |
| Pump Menu | Reservoir, insulin remaining, battery; Suspend Insulin Delivery / Resume basal (verify + start); Fill Cannula 0.70 U and its stop; Cassette Change (opens the cassette set-up wizard), Battery Change (opens the battery-change wizard) and a link to all wizards; Correct volume (0x8002); Forget pump. |
| History | The pump's own event log, decoded into readable rows and cached locally. |
| Permissions & files | Each Android permission the app needs (Bluetooth, notifications, ignore battery optimisation, background use, alarms & reminders) with a button that fixes it and Send a test notification; the data folder (logs/, exports/) with a Share button per file; and an optional folder the files are copied to. Permissions and files. |
| Advanced / Bench (behind a confirmation) | Pump tools (opens first): session details as GET /pump/state shows them (command path, last restart, therapy number, RIS versions with the untested-firmware warning, byte 90 and 91, resetCount), Re-arm with the stored key, Alarm reset, Silence alarms, clear an alert or notice by mask, the battery-change and cassette-change commands on their own, a therapy command with an explicit therapy number, and the observation log. Then the raw command panel, GATT explorer (bonding controls, subscribe, read/write), provisioning blob review/write/readback, session log and REST bridge info. |
Activity line. Under the bottom buttons on every screen: the pump command(s) running right now
(startBasal 0x8100: sent, waiting for the pump), then the result for a few seconds (accepted, refused:
why, no answer, not sent: why), then No command running · last: …. Commands sent over REST show there
too, and so do arms and same-link re-arms. Tap it for the recent commands with their times and results.
Failure alert. When a command fails the app says why, in plain words, on whatever page is open: a
refusal by the pump shows the pump's own message with its code (Pump rejected the command. (5101)) and
what the code means (for example "not allowed in the pump's current state"); no answer says the command
may or may not have run and was not resent; a command the app held back says which condition held it
and what to do; and when the pump keeps not answering after the automatic re-arm, it says to press
Reconnect. OK closes it. GET /pump/activity returns the same.
Banners. Above every screen: the automatic reconnect while it runs (its stage and try) and a
Reconnect failed banner with a Reconnect button when it gives up; Automatic reconnect turned
itself off (with the reason, Turn back on and Keep off) when the pump no longer matched this
phone's session; one banner per active pump condition (for example alarm, alarm
sounding, restart re-arm, cassette-change mode, reattach the cassette, no cassette, self-test running,
not primed, not configured, closed loop on, stale status, basal stopped, zero temp basal, alerts,
notices, low battery, low reservoir), each with its next action and a one-tap fix where there
is one (Fix… opens the wizard, Set up, Connect, Resume…, Clear, LOOP OFF); the
running bolus, prime and temp basal banners with their STOP buttons; and a clock-skew banner with
Sync clock. The conditions are the same table the delivery gate and GET /pump/conditions use
(State model).
Rules the UI follows: stop actions are one tap everywhere and never gated; anything that starts or
changes delivery asks for confirmation and is gated on the condition table and on the command path
being proven since the last arm or reboot. Every REST capability has a page in the app, and the
wizards call the same SetupRunner methods as the REST routes. A field the pump has not reported shows
"not reported", never a made-up number.
What the app does, in short¶
- Bonds as a normal LE Secure Connections peer with the 6-digit label PIN.
- Speaks the sealed command channel: HKDF-SHA256 keys, AES-CCM, truncated HMAC-SHA256 auth, CRC-16, packet and message numbering, therapy numbers (Crypto and transport).
- Sends each therapy command once and reports
ACCEPTED,NACKED,OUTCOME_UNKNOWNorNOT_SENT; a reply only counts if it carries the request's sequence number and opcode. - Detects a pump reboot (an
e5332023re-key notification, or the status stream restarting), re-arms on the same link, proves the command path with a read-only log read, and only then allows therapy commands again. - Holds the only copy of the pump's therapy settings (the pump cannot read them back), writes all 20 in
one Configure pump run, and checks them with
verifyTherapySettings. - Logs every BLE event, command, payload and response (NACKs decoded) and exports a session as one text file (Bonding and export).
Project layout¶
app/src/main/kotlin/com/infusionset/twiistoff/
ble/ PumpBleManager (BLE wrapper), BondManager (passkey + bond state), GATT model, MTU policy
crypto/ HKDF-SHA256 and AES-CCM (RFC 3610)
protocol/ Frame codec (TwiistChannel), opcode / NACK / status / alarm tables (ProtocolStatus),
alarm/alert text (PumpMessages), log-record names (EventTypes), payload builders,
status-push decoders (StatusPushes)
pump/ PumpLink (session, numbering, commands, reboot detection + re-arm), ReplyRouter,
TherapyCommand (send-once outcomes), PumpReadiness, PairingFlow + SetupRunner (setup
stage order and recovery commands shared by UI and REST), PumpSettings + SettingsStore
(the 20 stored settings, encoders, the 42-byte record, export / import),
PumpConditions (the blocking table), RecoveryWizards, RisGate (firmware gates),
SettingsLogReader, PumpHistoryStore (SQLite), ReplacementData (provisioning blob),
observe/ (observe-first instrumentation)
bridge/ Debug-only loopback REST bridge
export/ One-file session report + share sheet
ui/ Jetpack Compose: nav/, pages/, safety/, components/
log/ In-app log buffer
system/ Android permissions (AppPermissions, PhoneChecks), the data folder and its daily log file
(DataFolder, AppFiles, FileLogTree), the optional chosen folder (FolderCopy)
analytics/ No-op analytics (nothing collected or sent)
app/src/test/ Unit tests (synthetic keys; decrypted telemetry and log records as vectors)
tools/ smoke.sh live smoke test