From 3d2ab5c7916cc4822aca5315642f4ecbbcb05651 Mon Sep 17 00:00:00 2001 From: Johan Degraeve Date: Sun, 12 Jan 2020 20:49:43 +0100 Subject: [PATCH] fix #57 , crash at moment reading is received, for Dexcom G5, undo changes done in commit f25b5f13e634398232a2bd0c5fd7e524ffae3d6f --- .../CGM/Dexcom/G5/G5Messages/NSData+CRC.swift | 2 +- .../G5/G5Messages/SensorDataRxMessage.swift | 4 ++-- xdrip/Extensions/Data.swift | 22 +++++++++++-------- xdrip/Supporting Files/Info.plist | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/NSData+CRC.swift b/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/NSData+CRC.swift index 7f725cea4..b635a1168 100644 --- a/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/NSData+CRC.swift +++ b/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/NSData+CRC.swift @@ -50,7 +50,7 @@ extension UInt8 { extension Data { var isCRCValid: Bool { - return dropLast(2).crc16 == suffix(2).toInt(position: 0, length: 2) + return dropLast(2).crc16 == suffix(2).toInt() } func appendingCRC() -> Data { diff --git a/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/SensorDataRxMessage.swift b/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/SensorDataRxMessage.swift index c43cbedcd..94a724632 100644 --- a/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/SensorDataRxMessage.swift +++ b/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/G5Messages/SensorDataRxMessage.swift @@ -18,9 +18,9 @@ struct SensorDataRxMessage: TransmitterRxMessage { status = data[1] timestamp = Date() - let filteredAsUint32:UInt32 = data.uint32(position: 6) + let filteredAsUint32:UInt32 = data[6..<10].toInt() filtered = Double(filteredAsUint32) - let unfilteredAsUint32:UInt32 = data.uint32(position: 10) + let unfilteredAsUint32:UInt32 = data[10..<14].toInt() unfiltered = Double(unfilteredAsUint32) } } diff --git a/xdrip/Extensions/Data.swift b/xdrip/Extensions/Data.swift index a9b76cdd7..aedc59c62 100644 --- a/xdrip/Extensions/Data.swift +++ b/xdrip/Extensions/Data.swift @@ -51,7 +51,7 @@ extension Data { func uint64 (position:Int)-> UInt64 { let start = position let end = start.advanced(by: 8) - let number: UInt64 = self.subdata(in: start.. UInt32 { let start = position let end = start.advanced(by: 4) - let number: UInt32 = self.subdata(in: start.. UInt16 { let start = position let end = start.advanced(by: 2) - let number: UInt16 = self.subdata(in: start.. UInt8 { let start = position let end = start.advanced(by: 1) - let number: UInt8 = self.subdata(in: start.. Int { - let start = position - let end = start.advanced(by: length) - let number: Int = self.subdata(in: start..(_: T.Type) -> T { + return self.withUnsafeBytes { (bytes: UnsafePointer) in + return T(littleEndian: bytes.pointee) + } + } + + func toInt() -> T { + return to(T.self) } mutating func append(_ newElement: T) { diff --git a/xdrip/Supporting Files/Info.plist b/xdrip/Supporting Files/Info.plist index f70eecef3..6dfe6219b 100644 --- a/xdrip/Supporting Files/Info.plist +++ b/xdrip/Supporting Files/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 3153 + 3157 LSRequiresIPhoneOS NSAppTransportSecurity