Skip to content

Commit

Permalink
Updates for persistent device log (#592)
Browse files Browse the repository at this point in the history
* Updates for persistent device log

* Bump cartfile revs for dev
  • Loading branch information
ps2 authored Mar 29, 2020
1 parent 95429e2 commit 7406784
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "LoopKit/LoopKit" ~> 3.0
github "LoopKit/LoopKit" "dev"
github "LoopKit/MKRingProgressView" "appex-safe"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "LoopKit/LoopKit" "v3.0"
github "LoopKit/LoopKit" "8bc6e4b4ed4d8a7e98d8dcf539238b98c83ed3d1"
github "LoopKit/MKRingProgressView" "f548a5c64832be2d37d7c91b5800e284887a2a0a"
93 changes: 0 additions & 93 deletions OmniKit/PumpManager/MessageLog.swift

This file was deleted.

19 changes: 12 additions & 7 deletions OmniKit/PumpManager/OmnipodPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ public class OmnipodPumpManager: RileyLinkPumpManager {
observer.pumpManager(self, didUpdate: status, oldStatus: oldStatus)
}
}

private func logDeviceCommunication(_ message: String, type: DeviceLogEntryType = .send) {
var podAddress = "noPod"
if let podState = self.state.podState {
podAddress = String(format:"%04X", podState.address)
}
self.pumpDelegate.notify { (delegate) in
delegate?.deviceManager(self, logEventForDeviceIdentifier: podAddress, type: type, message: message, completion: nil)
}
}

private let pumpDelegate = WeakSynchronizedDelegate<PumpManagerDelegate>()

Expand Down Expand Up @@ -431,7 +441,6 @@ extension OmnipodPumpManager {
self.podComms.messageLogger = self

state.podState = nil
state.messageLog.erase()
state.expirationReminderDate = nil
}

Expand Down Expand Up @@ -1601,16 +1610,12 @@ extension OmnipodPumpManager: PumpManager {
extension OmnipodPumpManager: MessageLogger {
func didSend(_ message: Data) {
log.default("didSend: %{public}@", message.hexadecimalString)
setState { (state) in
state.messageLog.record(MessageLogEntry(messageDirection: .send, timestamp: Date(), data: message))
}
self.logDeviceCommunication(message.hexadecimalString, type: .send)
}

func didReceive(_ message: Data) {
log.default("didReceive: %{public}@", message.hexadecimalString)
setState { (state) in
state.messageLog.record(MessageLogEntry(messageDirection: .receive, timestamp: Date(), data: message))
}
self.logDeviceCommunication(message.hexadecimalString, type: .receive)
}
}

Expand Down
8 changes: 0 additions & 8 deletions OmniKit/PumpManager/OmnipodPumpManagerState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public struct OmnipodPumpManagerState: RawRepresentable, Equatable {

public var rileyLinkConnectionManagerState: RileyLinkConnectionManagerState?

public var messageLog = MessageLog()

public var unstoredDoses: [UnfinalizedDose]

public var expirationReminderDate: Date?
Expand Down Expand Up @@ -115,10 +113,6 @@ public struct OmnipodPumpManagerState: RawRepresentable, Equatable {
rileyLinkConnectionManagerState: rileyLinkConnectionManagerState
)

if let rawMessageLog = rawValue["messageLog"] as? MessageLog.RawValue, let messageLog = MessageLog(rawValue: rawMessageLog) {
self.messageLog = messageLog
}

if let expirationReminderDate = rawValue["expirationReminderDate"] as? Date {
self.expirationReminderDate = expirationReminderDate
} else if let expiresAt = podState?.expiresAt {
Expand All @@ -139,7 +133,6 @@ public struct OmnipodPumpManagerState: RawRepresentable, Equatable {
"version": OmnipodPumpManagerState.version,
"timeZone": timeZone.secondsFromGMT(),
"basalSchedule": basalSchedule.rawValue,
"messageLog": messageLog.rawValue,
"unstoredDoses": unstoredDoses.map { $0.rawValue },
"confirmationBeeps": confirmationBeeps,
]
Expand Down Expand Up @@ -193,7 +186,6 @@ extension OmnipodPumpManagerState: CustomDebugStringConvertible {
"* confirmationBeeps: \(String(describing: confirmationBeeps))",
String(reflecting: podState),
String(reflecting: rileyLinkConnectionManagerState),
String(reflecting: messageLog),
].joined(separator: "\n")
}
}
4 changes: 0 additions & 4 deletions RileyLink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@
C143031A1C9A610B00A40450 /* GetBatteryCarelinkMessageBodyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C14303191C9A610B00A40450 /* GetBatteryCarelinkMessageBodyTests.swift */; };
C145BF9F2219F37200A977CB /* Comparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C145BF9D2219F2EC00A977CB /* Comparable.swift */; };
C145BFA4221BBA7F00A977CB /* SuspendResumeMessageBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = C145BFA3221BBA7E00A977CB /* SuspendResumeMessageBody.swift */; };
C14B42FA21FF78840073A836 /* MessageLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C14B42F921FF78840073A836 /* MessageLog.swift */; };
C14CD28E21B5872D00F259DB /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1EAD6BA1C826B92006DBA60 /* Data.swift */; };
C14D2B051C9F5D5800C98E4C /* TempBasalDurationPumpEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C14D2B041C9F5D5800C98E4C /* TempBasalDurationPumpEvent.swift */; };
C14D2B091C9F5EDA00C98E4C /* ChangeTempBasalTypePumpEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C14D2B081C9F5EDA00C98E4C /* ChangeTempBasalTypePumpEvent.swift */; };
Expand Down Expand Up @@ -1280,7 +1279,6 @@
C14303191C9A610B00A40450 /* GetBatteryCarelinkMessageBodyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetBatteryCarelinkMessageBodyTests.swift; sourceTree = "<group>"; };
C145BF9D2219F2EC00A977CB /* Comparable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Comparable.swift; sourceTree = "<group>"; };
C145BFA3221BBA7E00A977CB /* SuspendResumeMessageBody.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SuspendResumeMessageBody.swift; sourceTree = "<group>"; };
C14B42F921FF78840073A836 /* MessageLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageLog.swift; sourceTree = "<group>"; };
C14D2B041C9F5D5800C98E4C /* TempBasalDurationPumpEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TempBasalDurationPumpEvent.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
C14D2B081C9F5EDA00C98E4C /* ChangeTempBasalTypePumpEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ChangeTempBasalTypePumpEvent.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
C14FFC491D3AF1AC0049CF85 /* JournalEntryInsulinMarkerPumpEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JournalEntryInsulinMarkerPumpEvent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2554,7 +2552,6 @@
C1FFAF97213323E600C50C1D /* OmnipodPumpManager.swift */,
C13BD63D21402A88006D7F19 /* PodInsulinMeasurements.swift */,
C1FFAF9D213323E700C50C1D /* PodState.swift */,
C14B42F921FF78840073A836 /* MessageLog.swift */,
);
path = PumpManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -4064,7 +4061,6 @@
C1FFAFCC213323E900C50C1D /* CancelDeliveryCommand.swift in Sources */,
C16E190D224EA33000DD9B9D /* PodDoseProgressEstimator.swift in Sources */,
C11F6B7E21C9646300752BBC /* FaultConfigCommand.swift in Sources */,
C14B42FA21FF78840073A836 /* MessageLog.swift in Sources */,
C1FFAFCA213323E900C50C1D /* GetStatusCommand.swift in Sources */,
E9EDD475215AFFF300A103D1 /* PodInfoFault.swift in Sources */,
C13BD63E21402A88006D7F19 /* PodInsulinMeasurements.swift in Sources */,
Expand Down

0 comments on commit 7406784

Please sign in to comment.