Repository navigation
Fixed decoding & comments for some O5 reset pod fault cases - #229
Conversation
ps2
left a comment
There was a problem hiding this comment.
The new $07ff check can't match. The line above it masks the high byte to 2 bits:
let bolusPulsesNotDelivered = (UInt(encodedData[3] & 0x3) << 8) | UInt(encodedData[4])so the largest value it can produce is 0x3ff. A raw 07 ff decodes to 0x3ff, which is still 51.15 U, and != 0x07ff is always true. Nothing goes wrong today, because the guard in UnfinalizedDose.cancel already ignores the value (the #227 tests pass either way). But this PR doesn't change anything yet.
There are two ways to fix it:
- Compare the masked value against
0x3ff. 1023 pulses is more than any bolus, so mapping it to 0 is safe. - Read the whole word and compare it before masking:
let bolusNotDeliveredWord = encodedData[3...4].toBigEndian(UInt16.self) self.bolusNotDelivered = bolusNotDeliveredWord == 0x07ff ? 0 : Double(bolusNotDeliveredWord & 0x3ff) / Pod.pulsesPerUnit
A DetailedStatus decoding test would catch this. The status from testFaultBolusNotDeliveredLargerThanTheBolusCountsItDelivered (0216020d0007ff0508001800640000006900001900000000) should decode to bolusNotDelivered == 0.
The fault-time comment change looks right to me. Small typo in the PR description: $07fff.
|
Thanks Pete! Guess we reused code from StatusResponse that was extracting only certain bits here. I went with using full word to test for the known illegal value as well as the same code structure as the fault time illegal value handling. We could add more specific testing here (e.g., this value shouldn't be more than the number of pulses for the largest possible bolus size (which I believe would be 30U immediate + 30U extended), but I believe that it's better to only map the obviously known illegal values in the DetailedStatus decode created by reset faults (just like we don't try to enforce that the reported fault time must be <= 80 hours) instead of trying to apply too many semantics at this level. |
ps2
left a comment
There was a problem hiding this comment.
Thanks, Joe. The full-word check works now: the reset-fault status from #227 (0216020d0007ff…) decodes to bolusNotDelivered == 0. The fault-time comment is right.
I traced every use of bolusNotDelivered, and dosing comes out the same as before. On a reset fault, assumeBolusDeliveredUntilNow() finalizes the bolus first, and every other path ignores a value larger than the bolus. So in practice the change shows up in the Read Pod Status screen and the logs. That also makes dropping the & 0x3 mask fine.
One small thing: the comment in testResetFaultBeforeBolusEndAssumesDeliveryUntilNow still says "the $3FF sigil in bolus not delivered". It could now say $07FF, decoded as 0.
Typo in the PR description: "assume the worse case" should be "worst".
|
Updated testResetFaultBeforeBolusEndAssumesDeliveryUntilNow() comment and PR description as per feedback. Thanks Pete. |
marionbarker
left a comment
There was a problem hiding this comment.
Approve by Claude code review, diff review (LGTM) and test build against Loop main or with suitable adjustment, next-dev.
Claude analysis of O5 reset pod faults showed that for in some cases the bolus not delivered word will be reported as an illegal $07ff instead of as $0000. It was also found the O5 fault-time can be reported as either $0000 or the previously known $ffff. See coments on pod PR #32 for details.
This PR updates the fault decoding in DetailedStatus to check for an illegal $07ff bolus pulses not delivered value and maps it to 0 (i.e., assume the worst case that any in-progress bolus was fully delivered before the pod fault). It also updates the commenting on the fault time handling to correctly document the pod types that can return an illegal $ffff (both Eros and O5) and a dubious $0000 (both DASH and O5) fault-time values for reset faults.