Setup and recovery¶
Bench hardware only. Everything here can start or change insulin delivery. Use it only with pump hardware that is not connected to any living subject. See bench testing.
6. Therapy settings and the delivery gate¶
The condition for delivery is the pump's configuration state, not an in-session 0x800F
(measured live with temporary basal 0x8102 / 0x8101 and startBasal 0x8100). In a fresh
sealed session on a configured pump (configurationState = 0x1FFF) a temp basal and a
stop/resume of basal were accepted before any verifyTherapySettings was sent in that session.
A battery-reset pump (configurationState = 0x0000) refuses delivery commands with NACK 0x13ED
NackBadSequence; writing the therapy settings (the 20 writes in §6.0) drives 0x0000 → 0x1FFF, after
which delivery works. 0x800F still answers 00/01 and is a useful read-only settings-match
confirmation, but do not retry a refused delivery command on 0x800F alone: read pumpStatus bytes
86-89 first.
The pump cannot report its therapy settings back. The only copy is the one the app keeps, so the
values written and the values verified must come from the same record. TwiistOff keeps one record of
every setting it writes (pump/PumpSettings.kt, persisted by pump/SettingsStore.kt); the configure
writes, each settings editor and the verify record are all built from it.
6.0 Configure: the 20 settings writes¶
"Configure pump" writes every setting once, in this order (the order that took a bench pump from
configurationState 0 to 0x1FFF). Every write is a Therapy command: the value below follows the
2-byte therapy number. Multi-byte values are little-endian; UE2 = 0.01 U (or 0.01 U/h), E2 =
mg/dL × 100.
| # | Opcode | Setting | Value bytes | Value layout | In the verify record |
|---|---|---|---|---|---|
| 1 | 0x8000 | pump-idle alert | 2 | u16 minutes (15, 30 or 60 accepted; "off" has no known encoding) |
no |
| 2 | 0x8004 | low-insulin alert | 2 | u16 UE2; 0 = off, max 100.00 U (verify does not compare it) |
yes |
| 3 | 0x8007 | walk-away alert | 1 | u8 minutes; 0 = off (10 and 15 accepted) |
yes |
| 4 | 0x8008 | one-button bolus | 1 | u8 0 / 1 |
yes |
| 5 | 0x8016 | pump audio | 2 | u8 quiet mode, u8 level (1 low, 2 medium, 3 high) |
quiet mode only |
| 6 | 0x8011 | CGM signal-loss alert | 3 | u16 minutes, u8 enabled |
enabled flag |
| 7 | 0x8012 | CGM low-glucose alert | 3 | u16 E2, u8 enabled |
yes |
| 8 | 0x8013 | CGM high-glucose alert | 3 | u16 E2, u8 enabled |
yes |
| 9 | 0x8014 | glucose display range | 4 | u16 low E2, u16 high E2 |
yes |
| 10 | 0x8017 | cassette-change reminder | 2 | u8 enabled, u8 hours (48–72) |
no |
| 11 | 0x801F | CGM sleep schedule | 9 | u16 start minute, u16 end minute, u16 low E2, u16 high E2, u8 on. TwiistOff sends a fixed value: 22:00–06:00, 70 / 250 mg/dL, schedule off |
no |
| 12 | 0x8700 | loop targets | 10 | u16 E2 each: safety limit, pre-meal low, pre-meal high, workout low, workout high |
yes |
| 13 | 0x8009 | closed loop | 1 | u8 0 / 1 |
no |
| 14 | 0x8019 | basal pattern | 100 | 48 × u16 UE2 per hour ‖ u16 max basal UE2 ‖ CRC16 |
CRC |
| 15 | 0x801B | insulin sensitivity pattern | 98 | 48 × u16 (mg/dL per U × 100) ‖ CRC16 |
CRC |
| 16 | 0x801D | carb ratio pattern | 100 | 48 × u16 (g per U × 10) ‖ CRC16 ‖ u16 max basal UE2 |
CRC |
| 17 | 0x800D | glucose target pattern | 196 | low block: 48 × u16 E2 ‖ CRC16, then high block: 48 × u16 E2 ‖ CRC16 |
both CRCs |
| 18 | 0x800A | delivery limits | 4 | u16 max basal UE2, u16 max bolus UE2 |
yes |
| 19 | 0x800C | insulin model | 1 | u8 1 = rapid-acting adult curve, 0 = child curve |
yes |
| 20 | 0x8310 | CGM info | 52 | all zero (no CGM) | no |
Patterns. Each pattern is 48 half-hour slots from midnight (slot for a clock time: hour × 2 +
(minute ≥ 30)). The CRC is CRC-16/MCRF4XX over the 96 value bytes of one block, little-endian on
the wire. The basal and carb-ratio messages both carry the max basal rate, in different places.
While basal runs the pump accepts every one of these writes except 0x800A delivery limits, which it refuses
0x13ED even with unchanged values (the limits stay as they were and verify still answers 01). Once basal is stopped
it is accepted (verify 01), so a limits change is stopBasal → 0x800A → verify → startBasal.
What a configure run does in TwiistOff (SetupRunner.configure):
- Refused before anything is sent when the session is not armed, no status has arrived, the pump is in cassette-change mode or is priming, a condition blocks settings writes (§6.4), or a stored value is out of bounds.
- One write at a time, 400 ms apart, each sent once. A refused write (NACK) is recorded and the run goes on, so the report shows exactly which writes landed. A write whose answer is lost (outcome unknown) or that could not be sent ends the run; the operator decides whether to run it again.
- A write whose firmware gate is above the pump's firmware is not sent; it is skipped and reported (firmware gates: Command catalogue).
- Then it waits up to 12 s for
configurationStateto reach0x1FFFand sendsverifyTherapySettings. - While basal runs it never sends
0x800A. When the pump is known to hold the stored limits they are reported "unchanged, not rewritten". When the stored limits differ from the pump's, the whole run is refused before anything is sent. When it is not known (a new phone), the other writes go out and the closing verify decides:01means the pump holds the limits too.
Editing one setting stores the new value and writes only the settings whose wire value changed (delivery limits first when they changed, because the basal and carb-ratio messages carry the max basal rate), then re-verifies. A limits change while basal runs is stored but not sent: the Change delivery limits wizard (§6.3) writes it with basal stopped.
"Not written". For each setting TwiistOff keeps the value the pump last confirmed: a write it
accepted, or a verify 01. A verify 01 proves the 11 settings it compares whole: the four patterns
(through their CRCs), the delivery limits, the loop targets, the CGM low and high alerts, the display
range, one-button bolus and the insulin model. The pump answers 01 whatever the low-insulin and
walk-away fields hold, and the record carries only part of the audio and CGM signal-loss settings and
none of the other five, so those nine are confirmed only by a write. A setting whose stored value the
pump is not known to hold is marked "not written": after an edit whose write failed, a preset, or an
import with values other than the confirmed ones (on a new phone, all 20 until the verify and writes).
Bounds TwiistOff applies before writing: max basal 0.05–22.00 U/h; max bolus 0.05–25.00 U; every basal slot at or below the max basal; insulin sensitivity 1–400 mg/dL per U; carb ratio 1.0–150.0 g per U; glucose targets 60–250 mg/dL with each slot's low at or below its high; other glucose values 40–400 mg/dL (CGM low below CGM high, display low below display high, pre-meal and workout low at or below high); reminder hours 48–72; audio level 1–3; insulin model 0 or 1.
Defaults (used for a value the app has never stored): pump-idle alert 15 min, low-insulin alert 20 U, walk-away off, one-button bolus on, quiet mode off, audio level low, CGM signal-loss alert off (40 min), CGM low alert on at 70 mg/dL, CGM high alert on at 250 mg/dL, display range 70–180 mg/dL, cassette-change reminder on at 72 h, loop targets safety 79 / pre-meal 80–80 / workout 120–140 mg/dL, closed loop off, basal 2.00 U/h all day, insulin sensitivity 18 mg/dL per U, carb ratio 3.1 g per U, glucose targets 90 mg/dL at 00:00 and 100 mg/dL for every other slot, max basal 5.00 U/h, max bolus 5.00 U, adult insulin model. The bench replay preset differs in: low-insulin alert off, one-button bolus off, audio level high, CGM signal-loss alert on, cassette-change reminder off (49 h), max basal 22.00 U/h, max bolus 6.00 U. Load it when a pump already holds those values and should not be rewritten.
The verify record (0x800F)¶
The 0x800F payload is a fixed 42-byte record (no therapy-number prefix — this is a Simple command), 25 little-endian fields:
u16 basalPatternCrc16 | u16 carbRatioCrc16 | u16 isfCrc16 | u16 lowTargetCrc16 | u16 highTargetCrc16
| u16 maxBasalRate_UE2 | u16 maxBolus_UE2 | u16 lowInsulinAlert_UE2
| u16 glucoseSafetyLimit | u16 preMealLow | u16 preMealHigh | u16 workoutLow | u16 workoutHigh
| u8 insulinModel | u8 oneButtonBolus | u8 walkawayTimeout | u8 unused
| u8 pumpQuietMode | u8 cgmSignalLossEnabled | u8 lowAlertEnabled | u8 highAlertEnabled
| u16 lowAlertSetting | u16 highAlertSetting | u16 displayLower | u16 displayUpper
The answer (0x808F) is one byte: 01 = the pump holds exactly these settings, 00 = they differ.
startBasal (0x8100) is a Therapy command carrying the same 42 bytes after its therapy number:
therapyNumber(2) || 42-byte record = 44 bytes. The pump-idle alert, cassette-change reminder, CGM
sleep schedule, closed loop, audio level and CGM info are not in the record, so verify cannot see them.
Set-change sequence (verified)¶
stopBasal → cassetteChange → resetPrime → setStartingCassetteVolume
→ startPrime → stopPrime → primeComplete
→ (settings writes as needed)
→ verifyTherapySettings → startBasal
→ (optional) startCannulaFill
- Volume and prime commands do not require cassette-change mode: on a fresh pump with a
self-tested cassette (
0x0029, not in cassette-change mode)resetPrime, fill and prime are all accepted. In cassette-change mode (0x0400) before a restart a fill is refused0x13ED; after a restart (battery change) the same sequence is accepted. Cassette-change mode is entered bycassetteChange 0x8804or by the pump itself when a cassette is removed, and is cleared only by a restart. - The pump has no fill sensor: it counts delivered volume down from a volume you declare
(
setStartingCassetteVolume0x8003; 300 U = wire0x7530= 30000 in 0.01 U units). Byte order matters — a swapped0x3075tells the pump ~124 U. The pump shows 10 U less than the declared fill (300 U reads as 290.00 U).adjustStartingCassetteVolume0x8002 (u16UE2) corrects the starting volume of the attached cassette. - Prime complete is accepted only at priming state 3.
pumpStatusbyte 79 is 2 while priming; afterstopPrimeit is 3 (primingInactiveMinVolumeMet) when the pump's minimum prime volume was reached, or 1 (primingInactiveMinVolumeNotMet) when it was stopped too early. At 1, prime more (startCassettePrimeagain) until drops form, then stop. The prime runs at about 0.35 U per second until stopped. - Cannula fill is optional and user-chosen.
- A lingering alert can block commands without looking like the cause; clear it first
(
clearPumpAlert0x0400). An alarm is different: it is not cleared byclearPumpAlert, and recovery goes through a restart (§6.2). - No command starts the self-test. Attaching a cassette (outside cassette-change mode) starts it
within one status push:
pumpState 0x0001 → 0x0009, byte 15 ramps to 100 % in ~11 s →0x0029. - The cassette barcode, if any, is app-side only — the pump never sees it.
TwiistOff's Cassette set-up wizard walks this sequence (Pairing and setup §5).
6.1 Fresh pair → running¶
✅ Verified on the bench 2026-12-02. The whole path, walked on saline from a fresh-paired pump with no cassette and configurationState 0:
(no command) attach cassette pumpState 0x0001 -> 0x0009 (self-test) -> 0x0029, ~11 s
0x8903 resetPrime token -> 0x8983
0x8003 setStartingCassetteVolume token + 30 75 (300 U) -> reservoir reads 290.00 U
0x8900 startCassettePrime token priming 2; ~1.76 U per ~5 s push
0x8901 stopPrime token priming 3 (pump flags minimum volume met)
0x8902 primeComplete token pumpState 0x0029 -> 0x0039 (+ prime done)
0x800F verifyTherapySettings 42 B -> 00 (unconfigured)
20 settings writes, each token-prefixed and answered consumed || next:
0x8000 0x8004 0x8007 0x8008 0x8016 0x8011 0x8012 0x8013 0x8014 0x8017
0x801F 0x8700 0x8009 0x8019 0x801B 0x801D 0x800D 0x800A 0x800C 0x8310
configurationState 0 -> 0x1F31 -> 0x1F7F -> 0x1FFF;
pumpState 0x0039 -> 0x007B
0x800F verifyTherapySettings -> 01
0x8100 startBasal token + 42 B -> accepted; pumpIdle alert clears; basal 2.00 U/h
primeCompletesets prime-done, and also therapy-ready if the pump is already configured; on an unconfigured pump therapy-ready arrives with the last settings write instead.- TwiistOff: the Cassette set-up wizard and the
/setup/*routes run this path, with Configure pump (§6.0) as its own step between prime complete and start basal.
6.2 Alarm recovery: cassette removal and occlusion¶
✅ Verified on the bench 2026-12-02.
| Situation | What the pump does |
|---|---|
| Cassette removed while delivering | 0x007B → 0x0433 (enters cassette-change mode itself), alarm baseDetached, basal stopped, byte 90 = 1. Silent for 10 min, then it sounds (byte 91 → 4) |
| Cassette removed with basal stopped | 0x0433, no alarm |
| Cassette reattached, no restart | 0x043B, alarm stays, no self-test; startBasal → 0x13F7 fail-safe; a fill → 0x13ED |
| Occlusion (bolus into a blocked line) | after ~50 s: alarm occlusion + alert bolusStopped, basal and bolus stopped, cassette-change mode, byte 90 = 1 — the same state as a removal |
alarmReset 0x0D00 + therapy number, byte 90 = 1 |
accepted; the pump restarts: alarm cleared, resetCount +1, status seq → 1; configuration, reservoir record, cassette age and prime-done kept; the attached cassette self-tests by itself (~10 s) → 0x007B |
alarmReset with no alarm (byte 90 = 0) |
0x13ED, no restart, delivery unaffected |
| Battery change | always a restart (the battery sits under the cassette); configuration, reservoir, cassette age, clock kept; change mode cleared |
| Pairing mode (cassette off + battery pull, to bond a phone) | restart; configuration cleared (configurationState 0) and prime-done cleared; reservoir record and cassette age kept. Before delivery the pump needs the full set-up again: prime, every therapy setting written, verify 01, startBasal |
Because the app's stored settings are the only copy, they must all be written again after a
pairing-mode entry, and a different phone or a reinstalled app must hold the same values the pump has
(import the export from the old phone, or rewrite them), or verifyTherapySettings answers 00.
Recovery on the same cassette needs no fill and no prime: alarmReset (or a battery change) →
restart + self-test → re-arm on the same link (§2.1 of BLE and session)
→ verifyTherapySettings 01 → startBasal. Verified twice after a removal and once after an
occlusion (delivery confirmed by the reservoir counting down). New cassette: resetPrime → fill
→ prime → primeComplete → verify → startBasal. So "the cassette was removed" is an offer
point (same cassette → resume; new cassette or infusion set → full new-cassette set-up), not "prime
required".
Battery change keeping the cassette: stopBasal → batteryChange 0x8805 (therapy number only)
before the battery comes out → swap the battery, attach the same cassette → restart, reconnect and
arm (the link drops), self-test → adjustStartingCassetteVolume 0x8002 only if the reservoir shown is
wrong, sent with the cassette's fill volume (the pump subtracts 10 U and what was delivered since the fill;
sending the remaining amount would subtract the delivered insulin twice) → verify → startBasal. No prime. What 0x8805 itself does on the pump is ⛔ TBD (accepted
once on the bench; it reset the self-test); the restart is what clears the pump's state.
6.3 Recovery wizards¶
TwiistOff has one wizard per recovery (pump/RecoveryWizards.kt). Each step is computed from the
pump's live state plus the operator's recorded answers, so a wizard opened at any moment starts where
the pump actually is. The app's Recovery pages and GET /recovery show the same plan, and every
button calls the same SetupRunner method as its REST route. A restart is recognised when resetCount
has gone up since the wizard began (or a restart was detected).
Configure pump — the pump has no settings, or different ones.
connected and armed
-> write this app's settings, all 20 (or first import the export from the phone that configured
the pump, or load the bench replay preset) -> configurationState 0x1FFF
-> verify 0x800F = 01
-> start basal
Alarm recovery — cassette removed while delivering, or line blocked.
what happened (Silence the alarm while it sounds)
-> fix the cause, then reset the alarm: alarmReset 0x0D00 (only while byte 90 = 1;
otherwise the alarm needs a battery change: open Battery change)
-> the pump restarts -> re-arm on the same link (automatic) -> cassette attached and self-tested
-> same cassette or a new one?
same -> line fixed, or infusion set changed?
line fixed -> verify 01 -> start basal (no fill, no prime)
set changed -> new-cassette set-up
new -> new-cassette set-up: fill, prime, prime complete, configure if needed, verify, start basal
Battery change — keep the cassette, swap the battery.
connected and armed
-> Suspend Insulin Delivery (stopBasal 0x8103); the change command is refused while basal runs
-> batteryChange 0x8805 (sent only on RIS messages 13.54 or later; below that the wizard stops
here and sends nothing)
-> remove the cassette, swap the battery, attach the SAME cassette
-> the pump restarts (keeps its settings and reservoir record); reconnect and arm
-> cassette attached and self-tested
-> same cassette or a new one? (new -> new-cassette set-up)
-> correct the cassette volume (0x8002), only if the reservoir shown is wrong
(the value is the cassette's fill volume, not what is left)
-> verify 01 -> start basal
What 0x8805 does on the pump itself is not yet confirmed on the bench; the restart is what matters.
Pump restarted — the session stopped answering after a restart.
restart detected -> re-arm on the same link (automatic; "Re-arm now" when it failed)
-> an alarm is active? open Alarm recovery
-> verify 01 -> start basal
New phone or reinstall.
connect and bond this phone
(a new phone bonds through pairing mode, which clears the pump's settings and prime, so a full
cassette set-up follows; a reinstall on a phone that is still bonded only needs the key)
-> enter the pump's key (LTSS, 16 bytes as 32 hex characters; stored on this phone only)
-> arm
-> bring the settings over: import the export from the old phone, then verify
(or Configure when the pump is unconfigured or verify answers 00)
-> cassette set-up when the pump is not primed or not configured
-> start basal
Cassette-change mode — pumpState 0x0400. Delivery is stopped and the pump does not self-test a
cassette until it restarts; nothing else leaves this mode.
in cassette-change mode
-> alarm active: reset the alarm (the pump restarts)
no alarm: battery change (remove the cassette, swap the battery, attach the cassette)
-> the pump restarts -> re-arm -> cassette attached and self-tested
-> same cassette or a new one? -> verify 01 -> start basal (new -> new-cassette set-up)
Change delivery limits — the pump refuses setDeliveryLimits 0x800A with 0x13ED while basal
runs, and accepts it with basal stopped. Opened from Therapy settings (Change delivery limits).
connected and armed
-> new delivery limits: not known whether the pump holds them? verify first (01 = nothing to change)
-> Suspend Insulin Delivery (stopBasal 0x8103); skipped when basal is already stopped,
waits while a bolus runs
-> write the limits (0x800A) and every setting still marked unwritten, limits first
-> verify 01 -> start basal
Outside this wizard, TwiistOff never sends 0x800A while basal runs: Configure and the settings writes
leave an unchanged limits setting alone (verify still answers 01) and refuse a changed one with nothing
sent.
A new-cassette set-up (chosen in a wizard, or started from the cassette set-up page) does not trust the old cassette's prime-done bit: fill and prime must be sent by the app again.
6.4 What each pump condition blocks¶
TwiistOff turns the live status into a list of conditions (pump/PumpConditions.kt). Each condition
blocks some kinds of command and names the wizard that resolves it. The delivery gate, the banners,
the wizards and the REST bridge (GET /pump/conditions) all read this one table, so a command is
refused for the same stated reason everywhere.
Kinds of command: stop, read, alarm reset, silence alarm, clear alert / notice, settings write, change (cassette or battery change), fill, prime, prime complete, and the four delivery starts: start basal, temp basal, bolus, cannula fill.
| Condition | When | Blocks | Wizard |
|---|---|---|---|
| Not connected | no BLE link | everything | Connect |
| No key | not armed and no key (LTSS) stored | everything | New phone |
| Not armed | connected, key stored, not armed | everything | Connect |
| No status | armed, no pumpStatus yet |
everything except stops and reads | — |
| Status stale | last pumpStatus older than 8 s |
everything except stops and reads | — |
| Restart re-arm | command path held after a restart | everything except reads | Pump restarted |
| Alarm | alarm bits ≠ 0 | delivery starts, fill, prime, prime complete, settings writes | Alarm recovery |
| Cassette-change mode | pumpState 0x0400 |
delivery starts, fill, prime, prime complete, settings writes | Cassette-change mode |
| No cassette | cassette-attached bit 0x0008 clear (outside change mode) |
delivery starts, fill, prime, prime complete | Cassette set-up |
| Reattach the cassette | alert bit 0 reattachCassette or bit 5 checkPumpAndCassette |
delivery starts, fill, prime | Cassette set-up |
| Self-test running | byte 15 between 1 and 99 % | delivery starts, fill, prime, prime complete | — |
| Priming | priming state 2 or 5 | delivery starts, fill, prime, settings writes, change | Cassette set-up |
| Not primed | cassette attached, prime-done bit 0x0010 clear |
delivery starts | Cassette set-up |
| Not configured | configurationState ≠ 0x1FFF |
delivery starts | Configure pump |
| Closed loop on | the pump's closed loop is enabled (status byte 44 = 0) | delivery starts | turn the loop off |
| Bolus running (warning) | delivered volume still moving toward the requested one | bolus, cannula fill, prime, change | — |
| Temp basal running (info) | a temp basal is active | temp basal | — |
| Basal stopped (warning) | basal rate 0 with no temp basal; the pump refuses a bolus or a temp basal (0x13ED) until startBasal |
bolus, temp basal | Resume basal |
| Alarm sounding, alert, notice, zero temp basal, battery ≤ 15 %, reservoir at or below the low-insulin threshold | — | nothing (warnings) | Alarm recovery for a sounding alarm |
Rules of the table:
- Stops are never blocked by a pump condition. Stop basal, stop bolus, stop prime, cancel temp basal and stop cannula fill are refused only when nothing can be sent at all (not connected, not armed, or the command path held while the app re-arms after a restart).
- Reads are never blocked (status, log, verify).
- A condition whose pump behaviour is unknown fails closed for delivery and settings writes.
- Alarm reset, silence and clear alert / notice are blocked only by the link conditions (connected,
armed, fresh status, command path).
alarmResetis additionally sent only while status byte 90 = 1. - The cassette-change and battery-change commands are also refused while basal runs: stop basal first.