fix #81 Constant BG sent to NightScout when Libre-2 expires

This commit is contained in:
Johan Degraeve 2020-04-08 20:48:44 +02:00
parent 3f9add9c34
commit a538e280f6
8 changed files with 43 additions and 12 deletions

View File

@ -85,6 +85,7 @@
F821CF9522ADB0D7005C1E43 /* HealthKitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF9422ADB0D7005C1E43 /* HealthKitManager.swift */; };
F821CF9722AE589E005C1E43 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F821CF9622AE589E005C1E43 /* HealthKit.framework */; };
F821CF9D22AEF483005C1E43 /* BGReadingSpeaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF9C22AEF483005C1E43 /* BGReadingSpeaker.swift */; };
F8252867243E50FE0067AF77 /* ConstantsLibre.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8252866243E50FE0067AF77 /* ConstantsLibre.swift */; };
F8297F46238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8297F44238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift */; };
F8297F4E238DCAD800D74D66 /* BluetoothPeripheralsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8297F4B238DCAD800D74D66 /* BluetoothPeripheralsViewController.swift */; };
F8297F4F238DCAD800D74D66 /* BluetoothPeripheralNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8297F4C238DCAD800D74D66 /* BluetoothPeripheralNavigationController.swift */; };
@ -249,7 +250,6 @@
F8E3C3AD21FE551C00907A04 /* DexcomCalibrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E3C3AC21FE551C00907A04 /* DexcomCalibrator.swift */; };
F8EA6C8221B723BC0082976B /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EA6C8121B723BC0082976B /* Date.swift */; };
F8EA6CA921BBE3010082976B /* UniqueId.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EA6CA821BBE3010082976B /* UniqueId.swift */; };
F8EEDD5222FECE3800D2D610 /* ConstantsLibreOOP.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EEDD5122FECE3800D2D610 /* ConstantsLibreOOP.swift */; };
F8EEDD5422FF685400D2D610 /* NSMutableURLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EEDD5322FF685400D2D610 /* NSMutableURLRequest.swift */; };
F8EEDD552300136F00D2D610 /* DexcomShareTestResult.strings in Resources */ = {isa = PBXBuildFile; fileRef = F8EEDD572300136F00D2D610 /* DexcomShareTestResult.strings */; };
F8EEDD6423020FAD00D2D610 /* NoCalibrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EEDD6323020FAD00D2D610 /* NoCalibrator.swift */; };
@ -397,6 +397,7 @@
F821CF9622AE589E005C1E43 /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; };
F821CF9822AE589E005C1E43 /* xdrip.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = xdrip.entitlements; sourceTree = "<group>"; };
F821CF9C22AEF483005C1E43 /* BGReadingSpeaker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BGReadingSpeaker.swift; sourceTree = "<group>"; };
F8252866243E50FE0067AF77 /* ConstantsLibre.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstantsLibre.swift; sourceTree = "<group>"; };
F8297F41238C3A6400D74D66 /* xdrip v5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "xdrip v5.xcdatamodel"; sourceTree = "<group>"; };
F8297F44238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BluetoothPeripheralManaging.swift; sourceTree = "<group>"; };
F8297F4B238DCAD800D74D66 /* BluetoothPeripheralsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BluetoothPeripheralsViewController.swift; sourceTree = "<group>"; };
@ -712,7 +713,6 @@
F8EA6C8121B723BC0082976B /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
F8EA6CA821BBE3010082976B /* UniqueId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueId.swift; sourceTree = "<group>"; };
F8EBB030239701DA0058B0D4 /* xdrip v6.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "xdrip v6.xcdatamodel"; sourceTree = "<group>"; };
F8EEDD5122FECE3800D2D610 /* ConstantsLibreOOP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsLibreOOP.swift; sourceTree = "<group>"; };
F8EEDD5322FF685400D2D610 /* NSMutableURLRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSMutableURLRequest.swift; sourceTree = "<group>"; };
F8EEDD562300136F00D2D610 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/DexcomShareTestResult.strings; sourceTree = "<group>"; };
F8EEDD582300138500D2D610 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/DexcomShareTestResult.strings; sourceTree = "<group>"; };
@ -1560,6 +1560,7 @@
F8EA6C7D21B70DEA0082976B /* Constants */ = {
isa = PBXGroup;
children = (
F8252866243E50FE0067AF77 /* ConstantsLibre.swift */,
F8A1585022EDB597007F5B5D /* ConstantsBGGraphBuilder.swift */,
F8A1585222EDB602007F5B5D /* ConstantsBloodGlucose.swift */,
F856CE5A22EDC8E50083E436 /* ConstantsBluetoothPairing.swift */,
@ -1572,7 +1573,6 @@
F8A1587222EDC893007F5B5D /* ConstantsDexcomShare.swift */,
F80859262364355F00F3829D /* ConstantsGlucoseChart.swift */,
F8A1586622EDB8BF007F5B5D /* ConstantsHomeView.swift */,
F8EEDD5122FECE3800D2D610 /* ConstantsLibreOOP.swift */,
F8A1585E22EDB81E007F5B5D /* ConstantsLog.swift */,
F8A389C723203E3E0010F405 /* ConstantsM5Stack.swift */,
F8A1586A22EDB967007F5B5D /* ConstantsMaster.swift */,
@ -2305,6 +2305,7 @@
F8E3A2A923D906C200E5E98A /* WatchManager.swift in Sources */,
F8B3A80A227A3D11004BA588 /* TextsAlertTypeSettings.swift in Sources */,
F8F9721823A5915900C3F17D /* CGMBlueReaderTransmitter.swift in Sources */,
F8252867243E50FE0067AF77 /* ConstantsLibre.swift in Sources */,
F8A1586D22EDB9BE007F5B5D /* ConstantsDexcomFollower.swift in Sources */,
F8F9720923A5915900C3F17D /* AESCrypt.m in Sources */,
F830992E23C7D756005741DF /* WatlaaBluetoothTransmitterMaster+CGMTransmitter.swift in Sources */,
@ -2344,7 +2345,6 @@
F8F9724723A69A8000C3F17D /* BluetoothPeripheralCategory.swift in Sources */,
F8B3A79522635A25004BA588 /* AlertType+CoreDataProperties.swift in Sources */,
F8B3A84C227F090E004BA588 /* SettingsViewController.swift in Sources */,
F8EEDD5222FECE3800D2D610 /* ConstantsLibreOOP.swift in Sources */,
F8F9720B23A5915900C3F17D /* SensorDataRxMessage.swift in Sources */,
F816E10C2437EA8E009EE65B /* BlueReader+CoreDataClass.swift in Sources */,
F8AC426021ADEBD60078C348 /* RootViewController.swift in Sources */,

View File

@ -93,8 +93,8 @@ class CGMBubbleTransmitter:BluetoothTransmitter, CGMTransmitter {
self.webOOPEnabled = webOOPEnabled ?? false
// initialize oopWebToken and oopWebSite
self.oopWebToken = oopWebToken ?? ConstantsLibreOOP.token
self.oopWebSite = oopWebSite ?? ConstantsLibreOOP.site
self.oopWebToken = oopWebToken ?? ConstantsLibre.token
self.oopWebSite = oopWebSite ?? ConstantsLibre.site
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_Bubble)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Bubble, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Bubble, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)

View File

@ -97,8 +97,8 @@ class CGMMiaoMiaoTransmitter:BluetoothTransmitter, CGMTransmitter {
self.webOOPEnabled = webOOPEnabled ?? false
// initialize oopWebToken and oopWebSite
self.oopWebToken = oopWebToken ?? ConstantsLibreOOP.token
self.oopWebSite = oopWebSite ?? ConstantsLibreOOP.site
self.oopWebToken = oopWebToken ?? ConstantsLibre.token
self.oopWebSite = oopWebSite ?? ConstantsLibre.site
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_MiaoMiao)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_MiaoMiao, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_MiaoMiao, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)

View File

@ -22,7 +22,7 @@ class LibreOOPClient {
// MARK: - properties
private static let filePath: String = NSHomeDirectory() + ConstantsLibreOOP.filePathForParameterStorage
private static let filePath: String = NSHomeDirectory() + ConstantsLibre.filePathForParameterStorage
/// for trace
private static let log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryLibreOOPClient)

View File

@ -1,5 +1,5 @@
/// constants related to Libre OOP
enum ConstantsLibreOOP {
enum ConstantsLibre {
/// is web oop enabled by default yes or no
static let defaultWebOOPEnabled = false
@ -13,4 +13,9 @@ enum ConstantsLibreOOP {
/// calibration parameters will be stored locally on disk, this is the path
static let filePathForParameterStorage = "/Documents/LibreSensorParameters"
/// maximum age Libre 1
///
/// taking one hour spare. To avoid that there's a wrong value used eg in case the user manually starts the sensor and doesn't set the time correctly
static let maximumAgeLibre1InMinutes: Double = 20880.0 - 60.0
}

View File

@ -18,7 +18,7 @@ public class BLEPeripheral: NSManagedObject {
self.alias = alias
self.parameterUpdateNeededAtNextConnect = false
webOOPEnabled = ConstantsLibreOOP.defaultWebOOPEnabled
webOOPEnabled = ConstantsLibre.defaultWebOOPEnabled
}

View File

@ -139,4 +139,9 @@ enum Texts_HomeView {
static let dexcomBatteryTooLow: String = {
return NSLocalizedString("dexcomBatteryTooLow", tableName: filename, bundle: Bundle.main, value: "Transmitter battery too low !", comment: "Error message in case Dexcom G5 (and G6?) battery is too low. This is deteced by wrong G5 values 2096896")
}()
static let sensorAge14Days: String = {
return NSLocalizedString("sensorAge14Days", tableName: filename, bundle: Bundle.main, value: "Sensor has reached maximum age.", comment: "Error message shown in pop up, when sensor age has reached 14.5 days")
}()
}

View File

@ -200,7 +200,7 @@ final class RootViewController: UIViewController {
/// current value of webOPEnabled, default false
/// - used to detect changes in the value
private var webOOPEnabled = ConstantsLibreOOP.defaultWebOOPEnabled
private var webOOPEnabled = ConstantsLibre.defaultWebOOPEnabled
// MARK: - View Life Cycle
@ -474,6 +474,27 @@ final class RootViewController: UIViewController {
// also for cases where calibration is not needed, we go through this code
if let activeSensor = activeSensor, let calibrator = calibrator, let bgReadingsAccessor = bgReadingsAccessor {
// assuming it's a 14 day sensor (as 10 day sensor is not supported), if it's a Libre sensor and age > 14.5 days, then don't process the readings
if cgmTransmitter.cgmTransmitterType().sensorType() == .Libre{
debuglogging("activeSensor.startDate = " + activeSensor.startDate.description(with: .current))
debuglogging("activeSensor.startDate.timeIntervalSinceNow = " + activeSensor.startDate.timeIntervalSinceNow.description)
debuglogging(" ConstantsLibre.maximumAgeLibre1InMinutes * 60 " + (ConstantsLibre.maximumAgeLibre1InMinutes * 60).description)
guard abs(activeSensor.startDate.timeIntervalSinceNow) < ConstantsLibre.maximumAgeLibre1InMinutes * 60 else {
trace("sensor older than %{public}@ minutes. Readings will not be processed.", log: log, category: ConstantsLog.categoryRootView, type: .info, ConstantsLibre.maximumAgeLibre1InMinutes)
self.present(UIAlertController(title: Texts_Common.warning, message: Texts_HomeView.sensorAge14Days, actionHandler: nil), animated: true, completion: nil)
return
}
}
// initialize help variables
var latest3BgReadings = bgReadingsAccessor.getLatestBgReadings(limit: 3, howOld: nil, forSensor: activeSensor, ignoreRawData: false, ignoreCalculatedValue: false)
var lastCalibrationsForActiveSensorInLastXDays = calibrationsAccessor.getLatestCalibrations(howManyDays: 4, forSensor: activeSensor)