Skip to content

Commit

Permalink
fix #57 , crash at moment reading is received, for Dexcom G5, undo ch…
Browse files Browse the repository at this point in the history
…anges done in commit f25b5f1
  • Loading branch information
JohanDegraeve committed Jan 12, 2020
1 parent b32e129 commit 3d2ab5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
22 changes: 13 additions & 9 deletions xdrip/Extensions/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,43 @@ extension Data {
func uint64 (position:Int)-> UInt64 {
let start = position
let end = start.advanced(by: 8)
let number: UInt64 = self.subdata(in: start..<end).withUnsafeBytes { $0.load(as: UInt64.self)}
let number: UInt64 = self.subdata(in: start..<end).toInt()
return number
}

///takes 4 bytes starting at position and converts to Uint32
func uint32 (position:Int)-> UInt32 {
let start = position
let end = start.advanced(by: 4)
let number: UInt32 = self.subdata(in: start..<end).withUnsafeBytes { $0.load(as: UInt32.self) }
let number: UInt32 = self.subdata(in: start..<end).toInt()
return number
}

///takes 2 bytes starting at position and converts to Uint16
func uint16 (position:Int)-> UInt16 {
let start = position
let end = start.advanced(by: 2)
let number: UInt16 = self.subdata(in: start..<end).withUnsafeBytes { $0.load(as: UInt16.self) }
let number: UInt16 = self.subdata(in: start..<end).toInt()
return number
}

///takes 1 byte starting at position and converts to Uint8
func uint8 (position:Int)-> UInt8 {
let start = position
let end = start.advanced(by: 1)
let number: UInt8 = self.subdata(in: start..<end).withUnsafeBytes { $0.load(as: UInt8.self) }
let number: UInt8 = self.subdata(in: start..<end).toInt()
return number
}

func toInt (position: Int, length: Int) -> Int {
let start = position
let end = start.advanced(by: length)
let number: Int = self.subdata(in: start..<end).withUnsafeBytes { $0.load(as: Int.self) }
return number
//source Data.Swift CGMBLEKit
func to<T: FixedWidthInteger>(_: T.Type) -> T {
return self.withUnsafeBytes { (bytes: UnsafePointer<T>) in
return T(littleEndian: bytes.pointee)
}
}

func toInt<T: FixedWidthInteger>() -> T {
return to(T.self)
}

mutating func append<T: FixedWidthInteger>(_ newElement: T) {
Expand Down
2 changes: 1 addition & 1 deletion xdrip/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>3153</string>
<string>3157</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down

0 comments on commit 3d2ab5c

Please sign in to comment.