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
5 changes: 4 additions & 1 deletion OmniBLE/OmnipodCommon/UnfinalizedDose.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public struct UnfinalizedDose: RawRepresentable, Equatable, CustomStringConverti
case .bolus:
let oldRate = rate
if let remaining = remaining {
units = units - remaining
// Guard against negative bolus if incorrectly called a 2nd time or with a bad remaining
if remaining <= units {
units -= remaining
}
} else {
units = oldRate * newDuration.hours
}
Expand Down
18 changes: 15 additions & 3 deletions OmniBLE/PumpManager/PodCommsSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,14 @@ public class PodCommsSession {
} else {
podState.activeTime = fault.faultEventTimeSinceActivation
}
handleCancelDosing(deliveryType: .all, bolusNotDelivered: fault.bolusNotDelivered)
let derivedStatusResponse = StatusResponse(detailedStatus: fault)
if podState.unacknowledgedCommand != nil {
// Process the pending unacknowledgeCommnd to handle any pending doses matters for an unacknowledged
// command before calling handleCancelDosing() to deal with the final dosing adjustments from pod fault.
// N.B., recoverUnacknowledgedCommand() skips using bolusNotDelivered for a stopProgram with a faulted pod.
recoverUnacknowledgedCommand(using: derivedStatusResponse)
}
handleCancelDosing(deliveryType: .all, bolusNotDelivered: derivedStatusResponse.bolusNotDelivered)
podState.updateFromStatusResponse(derivedStatusResponse, at: currentDate)
}
log.error("Pod Fault: %@", String(describing: fault))
Expand Down Expand Up @@ -338,6 +341,11 @@ public class PodCommsSession {


if let fault = response.fault {
if podState.unacknowledgedCommand != nil && blocksToSend[0].blockType != .getStatus {
// Clear the unacknowledgedCommand for this attempted non-getStatus command since
// it was for this send and thus it was actually acknowledged -- with a pod fault.
podState.unacknowledgedCommand = nil
}
try throwPodFault(fault: fault) // always throws
}

Expand Down Expand Up @@ -981,7 +989,9 @@ public class PodCommsSession {
}
case .stopProgram(let stopProgram, _, let commandDate, _):
if stopProgram.contains(.bolus), let bolus = podState.unfinalizedBolus, !bolus.isFinished(at: commandDate) {
podState.unfinalizedBolus?.cancel(at: commandDate, withRemaining: podStatus.bolusNotDelivered)
// If the pod is faulted, don't use bolusNotDelivered as this will be handled in handlePodFault()
let bolusNotDelivered = podState.isFaulted ? 0 : podStatus.bolusNotDelivered
podState.unfinalizedBolus?.cancel(at: commandDate, withRemaining: bolusNotDelivered)
}
if stopProgram.contains(.tempBasal), let tempBasal = podState.unfinalizedTempBasal, !tempBasal.isFinished(at: commandDate) {
podState.unfinalizedTempBasal?.cancel(at: commandDate)
Expand Down Expand Up @@ -1026,7 +1036,9 @@ public class PodCommsSession {
case .stopProgram(let stopProgram, _, let commandDate, _):
if stopProgram.contains(.bolus), let bolus = podState.unfinalizedBolus, !bolus.isFinished(at: commandDate) {
if !deliveryStatus.bolusing {
podState.unfinalizedBolus?.cancel(at: commandDate, withRemaining: podStatus.bolusNotDelivered)
// If the pod is faulted, don't use bolusNotDelivered as this will be handled in handlePodFault()
let bolusNotDelivered = podState.isFaulted ? 0 : podStatus.bolusNotDelivered
podState.unfinalizedBolus?.cancel(at: commandDate, withRemaining: bolusNotDelivered)
podStatusMatched = true
}
}
Expand Down