Dexcom G6 v2, for test only
This commit is contained in:
parent
5daf3b85e1
commit
809955f837
|
@ -6,8 +6,10 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
|
|||
|
||||
// MARK: - properties
|
||||
|
||||
/// scaling factor, for DexcomG5 this will be 1, for DexcomG6 it will be 34
|
||||
var scalingFactor = 1.0
|
||||
/// G5 or G6 transmitter firmware version - only used internally, if nil then it was never received
|
||||
///
|
||||
/// created public because inheriting classes need it
|
||||
var firmwareVersion:String?
|
||||
|
||||
// MARK: UUID's
|
||||
|
||||
|
@ -83,9 +85,6 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
|
|||
/// is G5 reset necessary or not
|
||||
private var G5ResetRequested:Bool
|
||||
|
||||
// G5 transmitter firmware version - only used internally, if nil then it was never received
|
||||
private var transmitterVersion:String?
|
||||
|
||||
// actual device address
|
||||
private var actualDeviceAddress:String?
|
||||
|
||||
|
@ -171,6 +170,20 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
|
|||
|
||||
// MARK: public functions
|
||||
|
||||
/// scale the rawValue, dependent on transmitter version G5 , G6 --
|
||||
/// for G6, there's two possible scaling factors, depending on the firmware version. For G5 there's only one, firmware version independent
|
||||
/// - parameters:
|
||||
/// - firmwareVersion : for G6, the scaling factor is firmware dependent. Parameter created optional although it is known at the moment the function is used
|
||||
/// - the value to be scaled
|
||||
/// this function can be override in CGMG6Transmitter, which can then return the scalingFactor , firmware dependent
|
||||
func scaleRawValue(firmwareVersion: String?, rawValue: Double) -> Double {
|
||||
|
||||
// for G5, the scaling is independent of the firmwareVersion
|
||||
// and there's no scaling to do
|
||||
return rawValue
|
||||
|
||||
}
|
||||
|
||||
// MARK: CBCentralManager overriden functions
|
||||
|
||||
override func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
|
||||
|
@ -401,7 +414,7 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
|
|||
|
||||
if let sensorDataRxMessage = SensorDataRxMessage(data: value) {
|
||||
|
||||
if transmitterVersion != nil {
|
||||
if firmwareVersion != nil {
|
||||
|
||||
// transmitterversion was already recceived, let's see if we need to get the batterystatus
|
||||
if Date() > Date(timeInterval: Constants.DexcomG5.batteryReadPeriodInHours * 60 * 60, since: timeStampOfLastBatteryReading) {
|
||||
|
@ -435,8 +448,11 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
|
|||
os_log(" last reading was less than 1 minute ago, ignoring", log: log, type: .info)
|
||||
} else {
|
||||
timeStampOfLastG5Reading = Date()
|
||||
let glucoseData = RawGlucoseData(timeStamp: sensorDataRxMessage.timestamp, glucoseLevelRaw: sensorDataRxMessage.unfiltered * scalingFactor, glucoseLevelFiltered: sensorDataRxMessage.filtered * scalingFactor)
|
||||
|
||||
let glucoseData = RawGlucoseData(timeStamp: sensorDataRxMessage.timestamp, glucoseLevelRaw: scaleRawValue(firmwareVersion: firmwareVersion, rawValue: sensorDataRxMessage.unfiltered), glucoseLevelFiltered: scaleRawValue(firmwareVersion: firmwareVersion, rawValue: sensorDataRxMessage.unfiltered))
|
||||
|
||||
var glucoseDataArray = [glucoseData]
|
||||
|
||||
cgmTransmitterDelegate?.cgmTransmitterInfoReceived(glucoseData: &glucoseDataArray, transmitterBatteryInfo: nil, sensorState: nil, sensorTimeInMinutes: nil, firmware: nil, hardware: nil, hardwareSerialNumber: nil, bootloader: nil, sensorSerialNumber: nil)
|
||||
}
|
||||
}
|
||||
|
@ -546,9 +562,12 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
|
|||
|
||||
private func processTransmitterVersionRxMessage(value:Data) {
|
||||
if let transmitterVersionRxMessage = TransmitterVersionRxMessage(data: value) {
|
||||
|
||||
cgmTransmitterDelegate?.cgmTransmitterInfoReceived(glucoseData: &emptyArray, transmitterBatteryInfo: nil, sensorState: nil, sensorTimeInMinutes: nil, firmware: transmitterVersionRxMessage.firmwareVersion.hexEncodedString(), hardware: nil, hardwareSerialNumber: nil, bootloader: nil, sensorSerialNumber: nil)
|
||||
|
||||
// assign transmitterVersion
|
||||
transmitterVersion = transmitterVersionRxMessage.firmwareVersion.hexEncodedString()
|
||||
firmwareVersion = transmitterVersionRxMessage.firmwareVersion.hexEncodedString()
|
||||
|
||||
} else {
|
||||
os_log("transmitterVersionRxMessage is nil", log: log, type: .error)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ import Foundation
|
|||
|
||||
class CGMG6Transmitter: CGMG5Transmitter {
|
||||
|
||||
/// scaling factor for G6 firmware version 1
|
||||
private let G6v1ScalingFactor = 34.0
|
||||
|
||||
/// - parameters:
|
||||
/// - address: if already connected before, then give here the address that was received during previous connect, if not give nil
|
||||
/// - transmitterID: expected transmitterID, 6 characters
|
||||
|
@ -10,7 +13,28 @@ class CGMG6Transmitter: CGMG5Transmitter {
|
|||
// call super.init
|
||||
super.init(address: address, transmitterID: transmitterID, delegate: delegate)
|
||||
|
||||
scalingFactor = 34.0
|
||||
}
|
||||
|
||||
override func scaleRawValue(firmwareVersion: String?, rawValue: Double) -> Double {
|
||||
|
||||
if let firmwareVersion = firmwareVersion {
|
||||
if firmwareVersion.startsWith("1") {
|
||||
|
||||
// G6-v1
|
||||
return rawValue * G6v1ScalingFactor;
|
||||
|
||||
} else {
|
||||
|
||||
// G6-v2
|
||||
return (rawValue - 1151395987) / 113432;
|
||||
}
|
||||
} else {
|
||||
|
||||
// assumed G6-v1, although firmwareVersion will normally not be nil
|
||||
return rawValue * G6v1ScalingFactor;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue