refactor some variables names related to heartbeat
- also update package version for CryptoSwift
This commit is contained in:
parent
9571aa1982
commit
d97528b04c
|
@ -42,8 +42,8 @@ class WatchStateModel: NSObject, ObservableObject {
|
|||
@Published var sensorMaxAgeInMinutes: Double = 14400
|
||||
@Published var timeStampOfLastFollowerConnection: Date = Date()
|
||||
@Published var secondsUntilFollowerDisconnectWarning: Int = 90
|
||||
@Published var lastHeartBeatTimeStamp: Date = Date()
|
||||
@Published var heartbeatShowDisconnectedTimeInSeconds: Int = 90
|
||||
@Published var timeStampOfLastHeartBeat: Date = Date()
|
||||
@Published var secondsUntilHeartBeatDisconnectWarning: Int = 90
|
||||
@Published var isMaster: Bool = true
|
||||
@Published var followerDataSourceType: FollowerDataSourceType = .nightscout
|
||||
@Published var followerBackgroundKeepAliveType: FollowerBackgroundKeepAliveType = .normal
|
||||
|
@ -216,7 +216,7 @@ class WatchStateModel: NSObject, ObservableObject {
|
|||
/// if no heartbeat, just return the standard gray colour for the keep alive type icon
|
||||
func getFollowerBackgroundKeepAliveColor() -> Color {
|
||||
if followerBackgroundKeepAliveType == .heartbeat {
|
||||
if let timeDifferenceInSeconds = Calendar.current.dateComponents([.second], from: lastHeartBeatTimeStamp, to: Date()).second, timeDifferenceInSeconds > heartbeatShowDisconnectedTimeInSeconds {
|
||||
if let timeDifferenceInSeconds = Calendar.current.dateComponents([.second], from: timeStampOfLastHeartBeat, to: Date()).second, timeDifferenceInSeconds > secondsUntilHeartBeatDisconnectWarning {
|
||||
return .red
|
||||
} else {
|
||||
return .green
|
||||
|
@ -266,8 +266,8 @@ class WatchStateModel: NSObject, ObservableObject {
|
|||
sensorMaxAgeInMinutes = watchState.sensorMaxAgeInMinutes ?? 0
|
||||
timeStampOfLastFollowerConnection = watchState.timeStampOfLastFollowerConnection ?? .distantPast
|
||||
secondsUntilFollowerDisconnectWarning = watchState.secondsUntilFollowerDisconnectWarning ?? 70// give it some more time compared to the iOS app
|
||||
lastHeartBeatTimeStamp = watchState.lastHeartBeatTimeStamp ?? .distantPast
|
||||
heartbeatShowDisconnectedTimeInSeconds = watchState.heartbeatShowDisconnectedTimeInSeconds ?? 5
|
||||
timeStampOfLastHeartBeat = watchState.timeStampOfLastHeartBeat ?? .distantPast
|
||||
secondsUntilHeartBeatDisconnectWarning = watchState.secondsUntilHeartBeatDisconnectWarning ?? 5
|
||||
isMaster = watchState.isMaster ?? true
|
||||
followerDataSourceType = FollowerDataSourceType(rawValue: watchState.followerDataSourceTypeRawValue ?? 0) ?? .nightscout
|
||||
followerBackgroundKeepAliveType = FollowerBackgroundKeepAliveType(rawValue: watchState.followerBackgroundKeepAliveTypeRawValue ?? 0) ?? .normal
|
||||
|
@ -333,7 +333,7 @@ class WatchStateModel: NSObject, ObservableObject {
|
|||
debugString += "\nFollower conn.: \(timeStampOfLastFollowerConnection.formatted(date: .omitted, time: .standard))"
|
||||
|
||||
if followerBackgroundKeepAliveType == .heartbeat {
|
||||
debugString += "\nLast hearbeat: \(lastHeartBeatTimeStamp.formatted(date: .omitted, time: .standard))"
|
||||
debugString += "\nLast hearbeat: \(timeStampOfLastHeartBeat.formatted(date: .omitted, time: .standard))"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
|
||||
"state" : {
|
||||
"revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e",
|
||||
"version" : "1.8.0"
|
||||
"revision" : "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c",
|
||||
"version" : "1.8.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@ class DexcomG7HeartbeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
private let log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryHeartBeatG7)
|
||||
|
||||
/// when was the last heartbeat
|
||||
private var lastHeartBeatTimeStamp: Date
|
||||
private var timeStampOfLastHeartBeat: Date
|
||||
|
||||
// MARK: - Initialization
|
||||
/// - parameters:
|
||||
|
@ -48,7 +48,7 @@ class DexcomG7HeartbeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
}
|
||||
|
||||
// initially last heartbeat was never (ie 1 1 1970)
|
||||
self.lastHeartBeatTimeStamp = Date(timeIntervalSince1970: 0)
|
||||
self.timeStampOfLastHeartBeat = Date(timeIntervalSince1970: 0)
|
||||
|
||||
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_G7, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_G7)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_G7, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_G7, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
|
||||
|
||||
|
@ -66,11 +66,11 @@ class DexcomG7HeartbeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
}
|
||||
|
||||
// this is the trigger for calling the heartbeat
|
||||
if (Date()).timeIntervalSince(lastHeartBeatTimeStamp) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
if (Date()).timeIntervalSince(timeStampOfLastHeartBeat) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
|
||||
lastHeartBeatTimeStamp = Date()
|
||||
timeStampOfLastHeartBeat = Date()
|
||||
|
||||
UserDefaults.standard.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
UserDefaults.standard.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
|
||||
// wait for a second to allow the official app to upload to LibreView before triggering the heartbeat announcement to the delegate
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
|
@ -85,11 +85,11 @@ class DexcomG7HeartbeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
super.centralManager(central, didDisconnectPeripheral: peripheral, error: error)
|
||||
|
||||
// this is the trigger for calling the heartbeat
|
||||
if (Date()).timeIntervalSince(lastHeartBeatTimeStamp) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
if (Date()).timeIntervalSince(timeStampOfLastHeartBeat) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
|
||||
lastHeartBeatTimeStamp = Date()
|
||||
timeStampOfLastHeartBeat = Date()
|
||||
|
||||
UserDefaults.standard.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
UserDefaults.standard.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
|
||||
// no need to wait for a second, because the disconnect usually happens about 1' seconds after connect
|
||||
// this case is for when a follower would be using an expired Dexcom G7 as a heartbeat
|
||||
|
|
|
@ -28,7 +28,7 @@ class Libre3HeartBeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
private let log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryHeartBeatLibre3)
|
||||
|
||||
/// when was the last heartbeat
|
||||
private var lastHeartBeatTimeStamp: Date
|
||||
private var timeStampOfLastHeartBeat: Date
|
||||
|
||||
// MARK: - Initialization
|
||||
/// - parameters:
|
||||
|
@ -47,7 +47,7 @@ class Libre3HeartBeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
}
|
||||
|
||||
// initially last heartbeat was never (ie 1 1 1970)
|
||||
self.lastHeartBeatTimeStamp = Date(timeIntervalSince1970: 0)
|
||||
self.timeStampOfLastHeartBeat = Date(timeIntervalSince1970: 0)
|
||||
|
||||
// using nil as servicesCBUUIDs, that works.
|
||||
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_Libre3, servicesCBUUIDs: nil, CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Libre3, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Libre3, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
|
||||
|
@ -61,11 +61,11 @@ class Libre3HeartBeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
super.centralManager(central, didConnect: peripheral)
|
||||
|
||||
// this is the trigger for calling the heartbeat
|
||||
if (Date()).timeIntervalSince(lastHeartBeatTimeStamp) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
if (Date()).timeIntervalSince(timeStampOfLastHeartBeat) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
|
||||
lastHeartBeatTimeStamp = Date()
|
||||
timeStampOfLastHeartBeat = Date()
|
||||
|
||||
UserDefaults.standard.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
UserDefaults.standard.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
|
||||
// wait for a second to allow the official app to upload to LibreView before triggering the heartbeat announcement to the delegate
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
|
@ -83,11 +83,11 @@ class Libre3HeartBeatBluetoothTransmitter: BluetoothTransmitter {
|
|||
}
|
||||
|
||||
// this is the trigger for calling the heartbeat
|
||||
if (Date()).timeIntervalSince(lastHeartBeatTimeStamp) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
if (Date()).timeIntervalSince(timeStampOfLastHeartBeat) > ConstantsHeartBeat.minimumTimeBetweenTwoHeartBeats {
|
||||
|
||||
lastHeartBeatTimeStamp = Date()
|
||||
timeStampOfLastHeartBeat = Date()
|
||||
|
||||
UserDefaults.standard.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
UserDefaults.standard.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
|
||||
// wait for a second to allow the official app to upload to LibreView before triggering the heartbeat announcement to the delegate
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class OmniPodHeartBeatTransmitter: BluetoothTransmitter {
|
|||
private let log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryHeartBeatOmnipod)
|
||||
|
||||
/// when was the last heartbeat
|
||||
private var lastHeartBeatTimeStamp: Date
|
||||
private var timeStampOfLastHeartBeat: Date
|
||||
|
||||
// MARK: - Initialization
|
||||
/// - parameters:
|
||||
|
@ -49,7 +49,7 @@ class OmniPodHeartBeatTransmitter: BluetoothTransmitter {
|
|||
}
|
||||
|
||||
// initially last heartbeat was never (ie 1 1 1970)
|
||||
self.lastHeartBeatTimeStamp = Date(timeIntervalSince1970: 0)
|
||||
self.timeStampOfLastHeartBeat = Date(timeIntervalSince1970: 0)
|
||||
|
||||
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_OmniPod, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_OmniPod)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_OmniPod, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_OmniPod, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
|
||||
|
||||
|
@ -61,9 +61,9 @@ class OmniPodHeartBeatTransmitter: BluetoothTransmitter {
|
|||
|
||||
super.centralManager(central, didConnect: peripheral)
|
||||
|
||||
lastHeartBeatTimeStamp = Date()
|
||||
timeStampOfLastHeartBeat = Date()
|
||||
|
||||
UserDefaults.standard.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
UserDefaults.standard.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
|
||||
// wait for a second to allow the official app to upload to LibreView before triggering the heartbeat announcement to the delegate
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
|
@ -77,9 +77,9 @@ class OmniPodHeartBeatTransmitter: BluetoothTransmitter {
|
|||
|
||||
super.peripheral(peripheral, didUpdateValueFor: characteristic, error: error)
|
||||
|
||||
lastHeartBeatTimeStamp = Date()
|
||||
timeStampOfLastHeartBeat = Date()
|
||||
|
||||
UserDefaults.standard.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
UserDefaults.standard.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
|
||||
// wait for a second to allow the official app to upload to LibreView before triggering the heartbeat announcement to the delegate
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
|
|
|
@ -6,13 +6,13 @@ enum ConstantsHeartBeat {
|
|||
static let minimumTimeBetweenTwoHeartBeats = TimeInterval(30)
|
||||
|
||||
/// how many seconds should pass since the previous Libre 3 BLE heartbeat until we show it as disconnected (i.e. having missed a heartbeat)
|
||||
static let heartbeatShowDisconnectedTimeInSecondsLibre3: Double = 70
|
||||
static let secondsUntilHeartBeatDisconnectWarningLibre3: Double = 70
|
||||
|
||||
/// how many seconds should pass since the previous Dexcom G7 heartbeat until we show it as disconnected (i.e. having missed a heartbeat)
|
||||
static let heartbeatShowDisconnectedTimeInSecondsDexcomG7: Double = 60 * 5.5
|
||||
static let secondsUntilHeartBeatDisconnectWarningDexcomG7: Double = 60 * 5.5
|
||||
|
||||
/// how many seconds should pass since the previous OmniPod heartbeat until we show it as disconnected (i.e. having missed a heartbeat)
|
||||
static let heartbeatShowDisconnectedTimeInSecondsOmniPod: Double = 60 * 5.5
|
||||
static let secondsUntilHeartBeatDisconnectWarningOmniPod: Double = 60 * 5.5
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -393,9 +393,9 @@ extension UserDefaults {
|
|||
|
||||
// heartbeat
|
||||
/// the last heartbeat connection timestamp
|
||||
case lastHeartBeatTimeStamp = "lastHeartBeatTimeStamp"
|
||||
case timeStampOfLastHeartBeat = "timeStampOfLastHeartBeat"
|
||||
/// how many seconds since the last heartbeat before we raise a disconnection warning
|
||||
case heartbeatShowDisconnectedTimeInSeconds = "heartbeatShowDisconnectedTimeInSeconds"
|
||||
case secondsUntilHeartBeatDisconnectWarning = "secondsUntilHeartBeatDisconnectWarning"
|
||||
|
||||
}
|
||||
|
||||
|
@ -2188,22 +2188,22 @@ extension UserDefaults {
|
|||
// MARK: - Heartbeat
|
||||
|
||||
/// timestamp of last successful connection to follower service
|
||||
@objc dynamic var lastHeartBeatTimeStamp: Date? {
|
||||
@objc dynamic var timeStampOfLastHeartBeat: Date? {
|
||||
get {
|
||||
return object(forKey: Key.lastHeartBeatTimeStamp.rawValue) as? Date
|
||||
return object(forKey: Key.timeStampOfLastHeartBeat.rawValue) as? Date
|
||||
}
|
||||
set {
|
||||
set(newValue, forKey: Key.lastHeartBeatTimeStamp.rawValue)
|
||||
set(newValue, forKey: Key.timeStampOfLastHeartBeat.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
/// how many seconds should be considered as the maximum since the last heartbeat before we show a warning/error?
|
||||
var heartbeatShowDisconnectedTimeInSeconds: Double? {
|
||||
var secondsUntilHeartBeatDisconnectWarning: Double? {
|
||||
get {
|
||||
return double(forKey: Key.heartbeatShowDisconnectedTimeInSeconds.rawValue)
|
||||
return double(forKey: Key.secondsUntilHeartBeatDisconnectWarning.rawValue)
|
||||
}
|
||||
set {
|
||||
set(newValue, forKey: Key.heartbeatShowDisconnectedTimeInSeconds.rawValue)
|
||||
set(newValue, forKey: Key.secondsUntilHeartBeatDisconnectWarning.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,9 +97,9 @@ public final class WatchManager: NSObject, ObservableObject {
|
|||
self.watchState.sensorMaxAgeInMinutes = (UserDefaults.standard.activeSensorMaxSensorAgeInDays ?? 0) * 24 * 60
|
||||
|
||||
// let's set the state values if we're using a heartbeat
|
||||
if let lastHeartBeatTimeStamp = UserDefaults.standard.lastHeartBeatTimeStamp, let heartbeatShowDisconnectedTimeInSeconds = UserDefaults.standard.heartbeatShowDisconnectedTimeInSeconds {
|
||||
self.watchState.heartbeatShowDisconnectedTimeInSeconds = Int(heartbeatShowDisconnectedTimeInSeconds)
|
||||
self.watchState.lastHeartBeatTimeStamp = lastHeartBeatTimeStamp
|
||||
if let timeStampOfLastHeartBeat = UserDefaults.standard.timeStampOfLastHeartBeat, let secondsUntilHeartBeatDisconnectWarning = UserDefaults.standard.secondsUntilHeartBeatDisconnectWarning {
|
||||
self.watchState.secondsUntilHeartBeatDisconnectWarning = Int(secondsUntilHeartBeatDisconnectWarning)
|
||||
self.watchState.timeStampOfLastHeartBeat = timeStampOfLastHeartBeat
|
||||
}
|
||||
|
||||
// let's set the follower server connection values if we're using follower mode
|
||||
|
|
|
@ -27,7 +27,7 @@ struct WatchState: Codable {
|
|||
var followerBackgroundKeepAliveTypeRawValue: Int?
|
||||
var timeStampOfLastFollowerConnection: Date?
|
||||
var secondsUntilFollowerDisconnectWarning: Int?
|
||||
var lastHeartBeatTimeStamp: Date?
|
||||
var heartbeatShowDisconnectedTimeInSeconds: Int?
|
||||
var timeStampOfLastHeartBeat: Date?
|
||||
var secondsUntilHeartBeatDisconnectWarning: Int?
|
||||
var disableComplications: Bool?
|
||||
}
|
||||
|
|
|
@ -917,7 +917,7 @@ final class RootViewController: UIViewController, ObservableObject {
|
|||
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.followerBackgroundKeepAliveType.rawValue, options: .new, context: nil)
|
||||
|
||||
// add observer for the last heartbeat timestamp in order to update the UI
|
||||
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.lastHeartBeatTimeStamp.rawValue, options: .new, context: nil)
|
||||
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.timeStampOfLastHeartBeat.rawValue, options: .new, context: nil)
|
||||
|
||||
// setup delegate for UNUserNotificationCenter
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
|
@ -1691,7 +1691,7 @@ final class RootViewController: UIViewController, ObservableObject {
|
|||
|
||||
}
|
||||
|
||||
case UserDefaults.Key.lastHeartBeatTimeStamp:
|
||||
case UserDefaults.Key.timeStampOfLastHeartBeat:
|
||||
updateDataSourceInfo(animate: false)
|
||||
|
||||
default:
|
||||
|
@ -3337,17 +3337,17 @@ final class RootViewController: UIViewController, ObservableObject {
|
|||
// using bluetoothPeripheralType here so that whenever bluetoothPeripheralType is extended with new cases, we don't forget to handle them
|
||||
switch bluetoothPeripheral.bluetoothPeripheralType() {
|
||||
case .Libre3HeartBeatType:
|
||||
UserDefaults.standard.heartbeatShowDisconnectedTimeInSeconds = ConstantsHeartBeat.heartbeatShowDisconnectedTimeInSecondsLibre3
|
||||
UserDefaults.standard.secondsUntilHeartBeatDisconnectWarning = ConstantsHeartBeat.secondsUntilHeartBeatDisconnectWarningLibre3
|
||||
case .DexcomG7HeartBeatType:
|
||||
UserDefaults.standard.heartbeatShowDisconnectedTimeInSeconds = ConstantsHeartBeat.heartbeatShowDisconnectedTimeInSecondsDexcomG7
|
||||
UserDefaults.standard.secondsUntilHeartBeatDisconnectWarning = ConstantsHeartBeat.secondsUntilHeartBeatDisconnectWarningDexcomG7
|
||||
case .OmniPodHeartBeatType:
|
||||
UserDefaults.standard.heartbeatShowDisconnectedTimeInSeconds = ConstantsHeartBeat.heartbeatShowDisconnectedTimeInSecondsOmniPod
|
||||
UserDefaults.standard.secondsUntilHeartBeatDisconnectWarning = ConstantsHeartBeat.secondsUntilHeartBeatDisconnectWarningOmniPod
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if let lastHeartBeatTimeStamp = UserDefaults.standard.lastHeartBeatTimeStamp, let heartbeatShowDisconnectedTimeInSeconds = UserDefaults.standard.heartbeatShowDisconnectedTimeInSeconds, lastHeartBeatTimeStamp > Date().addingTimeInterval(-heartbeatShowDisconnectedTimeInSeconds) {
|
||||
if let timeStampOfLastHeartBeat = UserDefaults.standard.timeStampOfLastHeartBeat, let secondsUntilHeartBeatDisconnectWarning = UserDefaults.standard.secondsUntilHeartBeatDisconnectWarning, timeStampOfLastHeartBeat > Date().addingTimeInterval(-secondsUntilHeartBeatDisconnectWarning) {
|
||||
dataSourceKeepAliveImageOutlet.tintColor = .systemGreen
|
||||
} else {
|
||||
dataSourceKeepAliveImageOutlet.tintColor = .systemRed
|
||||
|
|
Loading…
Reference in New Issue