From 976d477da227c64d7bcb76bcac113636822c0ff7 Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Sun, 17 Nov 2024 15:42:10 -0800 Subject: [PATCH 1/4] Miscellaneous Omnipod code improvements & cleanup + Remove unneeded & redundant didSend() & didReceive() message logging + Improved and additional PodState debugDescription display for insulin values + Improved pod suspend testing when updating delivery status + Update suspended, bolusing, tempBasalRunning, extendedBolusRunning definitions for better efficency and clarity using @dnzxy suggestion on OmniBLE PR #123 --- OmniKit/OmnipodCommon/Pod.swift | 37 +++++++++++++++++--- OmniKit/PumpManager/OmnipodPumpManager.swift | 2 -- OmniKit/PumpManager/PodState.swift | 6 ++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/OmniKit/OmnipodCommon/Pod.swift b/OmniKit/OmnipodCommon/Pod.swift index 2acaf2c..dc19a5f 100644 --- a/OmniKit/OmnipodCommon/Pod.swift +++ b/OmniKit/OmnipodCommon/Pod.swift @@ -54,7 +54,7 @@ public struct Pod { // Supported basal rates // Eros minimum scheduled basal rate is 0.05 U/H while for Dash supports 0 U/H. - // Would need to have this value based on productID to be able to share this with Eros. + // Would need to have this value based on productID to be able to share this file with DASH. public static let supportedBasalRates: [Double] = (1...600).map { Double($0) / Double(pulsesPerUnit) } // Supported temp basal rates @@ -113,19 +113,46 @@ public enum DeliveryStatus: UInt8, CustomStringConvertible { case extendedBolusAndTempBasal = 10 public var suspended: Bool { - return self == .suspended || self == .priming || self == .extendedBolusWhileSuspended + // returns true if both the tempBasal and basal bits are clear + let suspendedStates: Set = [ + .suspended, + .priming, + .extendedBolusWhileSuspended, + ] + return suspendedStates.contains(self) } public var bolusing: Bool { - return self == .bolusInProgress || self == .bolusAndTempBasal || self == .extendedBolusRunning || self == .extendedBolusAndTempBasal || self == .priming || self == .extendedBolusWhileSuspended + // returns true if either the immediateBolus or extendedBolus bits are set + let bolusingStates: Set = [ + .priming, + .bolusInProgress, + .bolusAndTempBasal, + .extendedBolusWhileSuspended, + .extendedBolusRunning, + .extendedBolusAndTempBasal, + ] + return bolusingStates.contains(self) } public var tempBasalRunning: Bool { - return self == .tempBasalRunning || self == .bolusAndTempBasal || self == .extendedBolusAndTempBasal + // returns true if the tempBasal bit is set + let tempBasalRunningStates: Set = [ + .tempBasalRunning, + .bolusAndTempBasal, + .extendedBolusAndTempBasal, + ] + return tempBasalRunningStates.contains(self) } public var extendedBolusRunning: Bool { - return self == .extendedBolusRunning || self == .extendedBolusAndTempBasal || self == .extendedBolusWhileSuspended + // returns true if the extendedBolus bit is set + let extendedBolusRunningStates: Set = [ + .extendedBolusWhileSuspended, + .extendedBolusRunning, + .extendedBolusAndTempBasal, + ] + return extendedBolusRunningStates.contains(self) } public var description: String { diff --git a/OmniKit/PumpManager/OmnipodPumpManager.swift b/OmniKit/PumpManager/OmnipodPumpManager.swift index 630074c..a422d15 100644 --- a/OmniKit/PumpManager/OmnipodPumpManager.swift +++ b/OmniKit/PumpManager/OmnipodPumpManager.swift @@ -2448,12 +2448,10 @@ extension OmnipodPumpManager: PumpManager { extension OmnipodPumpManager: MessageLogger { func didSend(_ message: Data) { - log.default("didSend: %{public}@", message.hexadecimalString) self.logDeviceCommunication(message.hexadecimalString, type: .send) } func didReceive(_ message: Data) { - log.default("didReceive: %{public}@", message.hexadecimalString) self.logDeviceCommunication(message.hexadecimalString, type: .receive) } diff --git a/OmniKit/PumpManager/PodState.swift b/OmniKit/PumpManager/PodState.swift index b330fe1..ad396fe 100644 --- a/OmniKit/PumpManager/PodState.swift +++ b/OmniKit/PumpManager/PodState.swift @@ -300,7 +300,7 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl if deliveryStatus.tempBasalRunning && unfinalizedTempBasal == nil { // active temp basal that we aren't tracking // unfinalizedTempBasal = UnfinalizedDose(tempBasalRate: 0, startTime: Date(), duration: .minutes(30), isHighTemp: false, scheduledCertainty: .certain, insulinType: insulinType) } - if deliveryStatus != .suspended && isSuspended { // active basal that we aren't tracking + if !deliveryStatus.suspended && isSuspended { // active basal that we aren't tracking let resumeStartTime = Date() suspendState = .resumed(resumeStartTime) unfinalizedResume = UnfinalizedDose(resumeStartTime: resumeStartTime, scheduledCertainty: .certain, insulinType: insulinType) @@ -555,7 +555,7 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl "* expiresAt: \(String(reflecting: expiresAt))", "* podTime: \(podTime.timeIntervalStr)", "* podTimeUpdated: \(String(reflecting: podTimeUpdated))", - "* setupUnitsDelivered: \(String(reflecting: setupUnitsDelivered))", + "* setupUnitsDelivered: \(setupUnitsDelivered == nil ? "?" : setupUnitsDelivered!.twoDecimals) U", "* piVersion: \(piVersion)", "* pmVersion: \(pmVersion)", "* lot: \(lot)", @@ -568,6 +568,8 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl "* unfinalizedResume: \(String(describing: unfinalizedResume))", "* finalizedDoses: \(String(describing: finalizedDoses))", "* activeAlertsSlots: \(alertSetString(alertSet: activeAlertSlots))", + "* delivered: \(lastInsulinMeasurements == nil ? "?" : lastInsulinMeasurements!.delivered.twoDecimals) U", + "* reservoirLevel: \(lastInsulinMeasurements == nil || lastInsulinMeasurements!.reservoirLevel == nil || lastInsulinMeasurements!.reservoirLevel == Pod.reservoirLevelAboveThresholdMagicNumber ? "50+" : lastInsulinMeasurements!.reservoirLevel!.twoDecimals) U", "* messageTransportState: \(String(describing: messageTransportState))", "* setupProgress: \(setupProgress)", "* primeFinishTime: \(String(describing: primeFinishTime))", From ef98bb10fce8602ea9526a88fd8d26bf28a4f176 Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Tue, 19 Nov 2024 23:53:47 -0800 Subject: [PATCH 2/4] Add missing pod suspend test improvement and log type change to PumpManager --- OmniKit/PumpManager/OmnipodPumpManager.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OmniKit/PumpManager/OmnipodPumpManager.swift b/OmniKit/PumpManager/OmnipodPumpManager.swift index a422d15..734bc52 100644 --- a/OmniKit/PumpManager/OmnipodPumpManager.swift +++ b/OmniKit/PumpManager/OmnipodPumpManager.swift @@ -1871,7 +1871,7 @@ extension OmnipodPumpManager: PumpManager { }) if let podState = self.state.podState, podState.isSuspended || podState.lastDeliveryStatusReceived?.suspended == true { - self.log.error("Not enacting bolus because podState or last status received indicates pod is suspended") + self.log.info("Not enacting bolus because podState or last status received indicates pod is suspended") completion(.deviceState(PodCommsError.podSuspended)) return } @@ -2053,7 +2053,7 @@ extension OmnipodPumpManager: PumpManager { return } - guard status.deliveryStatus != .suspended else { + guard !status.deliveryStatus.suspended else { self.log.info("Canceling temp basal because status return indicates pod is suspended!") completion(.communication(PodCommsError.podSuspended)) return From c0bdf81e62be1613ed756d0c131c86f3cd2d5df0 Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Tue, 3 Dec 2024 11:03:19 -0800 Subject: [PATCH 3/4] Improved commenting on constants that vary from Eros and Dash --- OmniKit/OmnipodCommon/Pod.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OmniKit/OmnipodCommon/Pod.swift b/OmniKit/OmnipodCommon/Pod.swift index dc19a5f..286303e 100644 --- a/OmniKit/OmnipodCommon/Pod.swift +++ b/OmniKit/OmnipodCommon/Pod.swift @@ -53,15 +53,15 @@ public struct Pod { public static let reservoirCapacity: Double = 200 // Supported basal rates - // Eros minimum scheduled basal rate is 0.05 U/H while for Dash supports 0 U/H. - // Would need to have this value based on productID to be able to share this file with DASH. + // Eros minimum scheduled basal rate is 0.05 U/H while Dash supports 0 U/H. public static let supportedBasalRates: [Double] = (1...600).map { Double($0) / Double(pulsesPerUnit) } // Supported temp basal rates + // Both Eros and Dash support a minimum temp basal rate of 0 U/H. public static let supportedTempBasalRates: [Double] = (0...600).map { Double($0) / Double(pulsesPerUnit) } - // The internal basal rate used for non-Eros pods - // Would need to have this value based on productID to be able to share this file with Eros. + // The internal basal rate used for zero basal rates + // Eros uses 0.0 while Dash uses a near zero rate public static let zeroBasalRate: Double = 0.0 // Maximum number of basal schedule entries supported From 22dd0e970e09bf7d34454e63d0ca9d58fb6362d0 Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Tue, 3 Dec 2024 16:31:13 -0800 Subject: [PATCH 4/4] Update comments to use U/hr instead of U/H for better consistency --- OmniKit/OmnipodCommon/Pod.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OmniKit/OmnipodCommon/Pod.swift b/OmniKit/OmnipodCommon/Pod.swift index 286303e..c5b32e7 100644 --- a/OmniKit/OmnipodCommon/Pod.swift +++ b/OmniKit/OmnipodCommon/Pod.swift @@ -53,11 +53,11 @@ public struct Pod { public static let reservoirCapacity: Double = 200 // Supported basal rates - // Eros minimum scheduled basal rate is 0.05 U/H while Dash supports 0 U/H. + // Eros minimum scheduled basal rate is 0.05 U/hr while Dash supports 0 U/hr. public static let supportedBasalRates: [Double] = (1...600).map { Double($0) / Double(pulsesPerUnit) } // Supported temp basal rates - // Both Eros and Dash support a minimum temp basal rate of 0 U/H. + // Both Eros and Dash support a minimum temp basal rate of 0 U/hr. public static let supportedTempBasalRates: [Double] = (0...600).map { Double($0) / Double(pulsesPerUnit) } // The internal basal rate used for zero basal rates