From 527797f9e92ad6af2a969986f709e850498c1c65 Mon Sep 17 00:00:00 2001 From: Ryan Arana Date: Thu, 23 Feb 2017 15:57:55 -0800 Subject: [PATCH 01/11] Make `pod spec lint` pass --- xDripG5.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xDripG5.podspec b/xDripG5.podspec index 8374f388..6800708f 100644 --- a/xDripG5.podspec +++ b/xDripG5.podspec @@ -14,7 +14,7 @@ Please note this project is neither created nor backed by Dexcom, Inc. Use of th s.homepage = "https://github.com/LoopKit/xDripG5" s.license = 'MIT' s.author = { "Nathan Racklyeft" => "loudnate@gmail.com" } - s.source = { :git => "https://github.com/LoopKit/xDripG5.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/LoopKit/xDripG5.git", :tag => "v" + s.version.to_s } s.platform = :ios, '9.3' s.requires_arc = true From 92057e82f7c46194b053224d3f924ed488d56996 Mon Sep 17 00:00:00 2001 From: pi4ohhi7 Date: Thu, 1 Jun 2017 18:27:56 -0500 Subject: [PATCH 02/11] Auth bug fixes --- xDripG5/AESCrypt.m | 2 +- xDripG5/Messages/AuthRequestTxMessage.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xDripG5/AESCrypt.m b/xDripG5/AESCrypt.m index 1c3850b6..1a0df4a1 100644 --- a/xDripG5/AESCrypt.m +++ b/xDripG5/AESCrypt.m @@ -13,7 +13,7 @@ @implementation AESCrypt + (NSData *)encryptData:(NSData *)data usingKey:(NSData *)key error:(NSError * _Nullable __autoreleasing *)error { - NSMutableData *dataOut = [[NSMutableData alloc] initWithCapacity:16]; + NSMutableData *dataOut = [NSMutableData dataWithLength: data.length + kCCBlockSizeAES128]; CCCryptorStatus status = CCCrypt(kCCEncrypt, kCCAlgorithmAES, diff --git a/xDripG5/Messages/AuthRequestTxMessage.swift b/xDripG5/Messages/AuthRequestTxMessage.swift index 8b27c5c5..30b163b4 100644 --- a/xDripG5/Messages/AuthRequestTxMessage.swift +++ b/xDripG5/Messages/AuthRequestTxMessage.swift @@ -19,7 +19,7 @@ struct AuthRequestTxMessage: TransmitterTxMessage { NSUUID().getBytes(&UUIDBytes) - singleUseToken = Data(bytes: UUIDBytes) + singleUseToken = Data(bytes: UUIDBytes[0..<8]) } var byteSequence: [Any] { From 821737269f4a101d5249f503cbbf3c8cb6a8a8f1 Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sat, 13 Jan 2018 22:32:00 +1100 Subject: [PATCH 03/11] change auth method to write then read, rather than notify --- xDripG5/BluetoothManager.swift | 13 +++++ xDripG5/Transmitter.swift | 98 ++++++++++++++++------------------ 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/xDripG5/BluetoothManager.swift b/xDripG5/BluetoothManager.swift index e1f133c1..8f1b012f 100644 --- a/xDripG5/BluetoothManager.swift +++ b/xDripG5/BluetoothManager.swift @@ -156,6 +156,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate Thread.sleep(forTimeInterval: 2) self.scanForPeripheral() + } } @@ -299,6 +300,18 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate return characteristic.value ?? Data() } + func waitForTime(timeout: TimeInterval = 2) { + operationLock.lock() + + operationLock.wait(until: Date(timeIntervalSinceNow: timeout)) + + defer { + operationLock.unlock() + } + + return + } + // MARK: - Accessors var isScanning: Bool { diff --git a/xDripG5/Transmitter.swift b/xDripG5/Transmitter.swift index 1fe3f65a..b1e9806a 100644 --- a/xDripG5/Transmitter.swift +++ b/xDripG5/Transmitter.swift @@ -168,79 +168,71 @@ public final class Transmitter: BluetoothManagerDelegate { // MARK: - Helpers private func authenticate() throws { - if let data = try? bluetoothManager.readValueForCharacteristicAndWait(.Authentication), - let status = AuthStatusRxMessage(data: data), status.authenticated == 1 && status.bonded == 1 - { - NSLog("Transmitter already authenticated.") - } else { - do { - try bluetoothManager.setNotifyEnabledAndWait(true, forCharacteristicUUID: .Authentication) - } catch let error { - throw TransmitterError.authenticationError("Error enabling notification: \(error)") - } + let authMessage = AuthRequestTxMessage() + let data: Data - let authMessage = AuthRequestTxMessage() - let data: Data + do { + _ = try bluetoothManager.writeValueAndWait(authMessage.data, forCharacteristicUUID: .Authentication) + data = try bluetoothManager.readValueForCharacteristicAndWait(.Authentication, expectingFirstByte: AuthChallengeRxMessage.opcode) + } catch let error { + throw TransmitterError.authenticationError("Error writing transmitter challenge: \(error)") + } + + guard let response = AuthChallengeRxMessage(data: data) else { + throw TransmitterError.authenticationError("Unable to parse auth challenge: \(data)") + } + guard response.tokenHash == self.calculateHash(authMessage.singleUseToken) else { + throw TransmitterError.authenticationError("Transmitter failed auth challenge") + } + + if let challengeHash = self.calculateHash(response.challenge) { + let data: Data do { - data = try bluetoothManager.writeValueAndWait(authMessage.data, forCharacteristicUUID: .Authentication, expectingFirstByte: AuthChallengeRxMessage.opcode) + _ = try bluetoothManager.writeValueAndWait(AuthChallengeTxMessage(challengeHash: challengeHash).data, forCharacteristicUUID: .Authentication) + data = try bluetoothManager.readValueForCharacteristicAndWait(.Authentication, expectingFirstByte: AuthStatusRxMessage.opcode) } catch let error { - throw TransmitterError.authenticationError("Error writing transmitter challenge: \(error)") + throw TransmitterError.authenticationError("Error writing challenge response: \(error)") } - guard let response = AuthChallengeRxMessage(data: data) else { - throw TransmitterError.authenticationError("Unable to parse auth challenge: \(data)") + guard let response = AuthStatusRxMessage(data: data) else { + throw TransmitterError.authenticationError("Unable to parse auth status: \(data)") } - guard response.tokenHash == self.calculateHash(authMessage.singleUseToken) else { - throw TransmitterError.authenticationError("Transmitter failed auth challenge") + guard response.authenticated == 1 else { + throw TransmitterError.authenticationError("Transmitter rejected auth challenge") } - if let challengeHash = self.calculateHash(response.challenge) { - let data: Data + if response.bonded != 0x1 { do { - data = try bluetoothManager.writeValueAndWait(AuthChallengeTxMessage(challengeHash: challengeHash).data, forCharacteristicUUID: .Authentication, expectingFirstByte: AuthStatusRxMessage.opcode) + _ = try bluetoothManager.writeValueAndWait(KeepAliveTxMessage(time: 25).data, forCharacteristicUUID: .Authentication) } catch let error { - throw TransmitterError.authenticationError("Error writing challenge response: \(error)") + throw TransmitterError.authenticationError("Error writing keep-alive for bond: \(error)") } - guard let response = AuthStatusRxMessage(data: data) else { - throw TransmitterError.authenticationError("Unable to parse auth status: \(data)") + let data: Data + do { + _ = try bluetoothManager.writeValueAndWait(BondRequestTxMessage().data, forCharacteristicUUID: .Authentication) + } catch let error { + throw TransmitterError.authenticationError("Error writing bond request: \(error)") } - guard response.authenticated == 1 else { - throw TransmitterError.authenticationError("Transmitter rejected auth challenge") + // Wait for the OS dialog to pop-up before continuing. + bluetoothManager.waitForTime(timeout: 5) + + do { + data = try bluetoothManager.readValueForCharacteristicAndWait(.Authentication, expectingFirstByte: AuthStatusRxMessage.opcode) + } catch let error { + throw TransmitterError.authenticationError("Error reading status after bond request: \(error)") } - if response.bonded != 0x1 { - do { - _ = try bluetoothManager.writeValueAndWait(KeepAliveTxMessage(time: 25).data, forCharacteristicUUID: .Authentication) - } catch let error { - throw TransmitterError.authenticationError("Error writing keep-alive for bond: \(error)") - } - - let data: Data - do { - // Wait for the OS dialog to pop-up before continuing. - data = try bluetoothManager.writeValueAndWait(BondRequestTxMessage().data, forCharacteristicUUID: .Authentication, timeout: 15, expectingFirstByte: AuthStatusRxMessage.opcode) - } catch let error { - throw TransmitterError.authenticationError("Error writing bond request: \(error)") - } - - guard let response = AuthStatusRxMessage(data: data) else { - throw TransmitterError.authenticationError("Unable to parse auth status: \(data)") - } - - guard response.bonded == 0x1 else { - throw TransmitterError.authenticationError("Transmitter failed to bond") - } + guard let response = AuthStatusRxMessage(data: data) else { + throw TransmitterError.authenticationError("Unable to parse auth status: \(data)") } - } - do { - try bluetoothManager.setNotifyEnabledAndWait(false, forCharacteristicUUID: .Authentication) - } catch let error { - throw TransmitterError.authenticationError("Error disabling notification: \(error)") + guard response.bonded == 0x1 else { + throw TransmitterError.authenticationError("Transmitter failed to bond") + } } } } From 256d59ba3135530f363683938af241c1eab7d4b8 Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sat, 13 Jan 2018 23:28:45 +1100 Subject: [PATCH 04/11] get Example app working --- Example/Podfile | 1 + Example/Podfile.lock | 6 +++--- Example/xDripG5.xcodeproj/project.pbxproj | 16 +++++++++++++--- Example/xDripG5/ViewController.swift | 8 ++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Example/Podfile b/Example/Podfile index 396887bb..08010e5e 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -1,4 +1,5 @@ source 'https://github.com/CocoaPods/Specs.git' +platform :ios, '10.3' use_frameworks! target 'xDripG5_Example' do diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 9d30a5a1..64437fff 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - xDripG5: 8779a4f495fd8eb81a3d75457afe9b95fb52f61d + xDripG5: 3dc95570b79136c8f7c58216c3e591aff60e6242 -PODFILE CHECKSUM: 6b30cba971694d5258509315fb52eb645c9bc5e3 +PODFILE CHECKSUM: c62f3fcb344335d79abdcccea268615000e8801b -COCOAPODS: 1.1.0.rc.2 +COCOAPODS: 1.3.1 diff --git a/Example/xDripG5.xcodeproj/project.pbxproj b/Example/xDripG5.xcodeproj/project.pbxproj index 02b5616c..cf8a06c5 100644 --- a/Example/xDripG5.xcodeproj/project.pbxproj +++ b/Example/xDripG5.xcodeproj/project.pbxproj @@ -202,13 +202,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-xDripG5_Example-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 2FC4228A9369221D367ED688 /* [CP] Copy Pods Resources */ = { @@ -232,9 +235,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-xDripG5_Example/Pods-xDripG5_Example-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/xDripG5/xDripG5.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/xDripG5.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -381,9 +387,11 @@ isa = XCBuildConfiguration; baseConfigurationReference = F3147B948B4F90A741304461 /* Pods-xDripG5_Example.debug.xcconfig */; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = xDripG5/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.xDripG5-Example"; @@ -397,9 +405,11 @@ isa = XCBuildConfiguration; baseConfigurationReference = CFBD776BFE02F42998A8820B /* Pods-xDripG5_Example.release.xcconfig */; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = xDripG5/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.xDripG5-Example"; diff --git a/Example/xDripG5/ViewController.swift b/Example/xDripG5/ViewController.swift index faef5334..d3318351 100644 --- a/Example/xDripG5/ViewController.swift +++ b/Example/xDripG5/ViewController.swift @@ -68,9 +68,9 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate if let text = textField.text { let newString = text.replacingCharacters(in: range.rangeOfString(text), with: string) - if newString.characters.count > 6 { + if newString.count > 6 { return false - } else if newString.characters.count == 6 { + } else if newString.count == 6 { AppDelegate.sharedDelegate.transmitter?.ID = newString UserDefaults.standard.transmitterID = newString @@ -129,8 +129,8 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate private extension NSRange { func rangeOfString(_ string: String) -> Range { - let startIndex = string.characters.index(string.startIndex, offsetBy: location) - let endIndex = string.characters.index(startIndex, offsetBy: length) + let startIndex = string.index(string.startIndex, offsetBy: location) + let endIndex = string.index(startIndex, offsetBy: length) return startIndex.. Date: Sun, 14 Jan 2018 09:55:21 +1100 Subject: [PATCH 05/11] fix message 'characters has been deprecated' --- Example/xDripG5/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/xDripG5/ViewController.swift b/Example/xDripG5/ViewController.swift index d3318351..35c27737 100644 --- a/Example/xDripG5/ViewController.swift +++ b/Example/xDripG5/ViewController.swift @@ -86,7 +86,7 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate } func textFieldDidEndEditing(_ textField: UITextField) { - if textField.text?.characters.count != 6 { + if textField.text?.count != 6 { textField.text = UserDefaults.standard.transmitterID } } From 7c0da5226f7ebc4bba2c2b02b6dd1614da5224d2 Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sun, 14 Jan 2018 09:56:29 +1100 Subject: [PATCH 06/11] fix 'UIWindow.rootViewController must be used from main thread only' --- Example/xDripG5/AppDelegate.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Example/xDripG5/AppDelegate.swift b/Example/xDripG5/AppDelegate.swift index f230f6d9..c988adc5 100644 --- a/Example/xDripG5/AppDelegate.swift +++ b/Example/xDripG5/AppDelegate.swift @@ -73,24 +73,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { }() func transmitter(_ transmitter: Transmitter, didError error: Error) { - if let vc = window?.rootViewController as? TransmitterDelegate { - DispatchQueue.main.async { + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didError: error) } } } func transmitter(_ transmitter: Transmitter, didRead glucose: Glucose) { - if let vc = window?.rootViewController as? TransmitterDelegate { - DispatchQueue.main.async { + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didRead: glucose) } } } func transmitter(_ transmitter: Transmitter, didReadUnknownData data: Data) { - if let vc = window?.rootViewController as? TransmitterDelegate { - DispatchQueue.main.async { + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didReadUnknownData: data) } } From 5577b256a71b0bf81a5f6c1bd0deac59db044808 Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sun, 14 Jan 2018 10:04:26 +1100 Subject: [PATCH 07/11] set deployment target to 10.3 --- xDripG5.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xDripG5.podspec b/xDripG5.podspec index 6800708f..15135232 100644 --- a/xDripG5.podspec +++ b/xDripG5.podspec @@ -16,7 +16,7 @@ Please note this project is neither created nor backed by Dexcom, Inc. Use of th s.author = { "Nathan Racklyeft" => "loudnate@gmail.com" } s.source = { :git => "https://github.com/LoopKit/xDripG5.git", :tag => "v" + s.version.to_s } - s.platform = :ios, '9.3' + s.platform = :ios, '10.3' s.requires_arc = true s.source_files = ['xDripG5/**/*.swift', 'xDripG5/AESCrypt.{h,m}', 'Pod/*.h'] From cdac2ccef76f7e019f921c452aa91c135c42020a Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sun, 14 Jan 2018 10:41:20 +1100 Subject: [PATCH 08/11] update Podfile.lock --- Example/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 64437fff..606de109 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - xDripG5: 3dc95570b79136c8f7c58216c3e591aff60e6242 + xDripG5: 92588b5d1d31b337673af62bb433e503001356ae PODFILE CHECKSUM: c62f3fcb344335d79abdcccea268615000e8801b From 206c2f032748af980a6690bc18b67a38857ca61a Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sun, 14 Jan 2018 11:08:29 +1100 Subject: [PATCH 09/11] remove newline --- xDripG5/BluetoothManager.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/xDripG5/BluetoothManager.swift b/xDripG5/BluetoothManager.swift index 8f1b012f..84db2bb3 100644 --- a/xDripG5/BluetoothManager.swift +++ b/xDripG5/BluetoothManager.swift @@ -156,7 +156,6 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate Thread.sleep(forTimeInterval: 2) self.scanForPeripheral() - } } From 0d0a6c9a2eb8367b10f065e8b3a2e5931beb0722 Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Sun, 14 Jan 2018 21:26:27 +1100 Subject: [PATCH 10/11] check that bluetooth operations have completed before wait --- xDripG5/BluetoothManager.swift | 6 +++++- xDripG5/Transmitter.swift | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/xDripG5/BluetoothManager.swift b/xDripG5/BluetoothManager.swift index 84db2bb3..2ba18569 100644 --- a/xDripG5/BluetoothManager.swift +++ b/xDripG5/BluetoothManager.swift @@ -299,7 +299,11 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate return characteristic.value ?? Data() } - func waitForTime(timeout: TimeInterval = 2) { + func waitForTime(timeout: TimeInterval = 2) throws { + guard manager.state == .poweredOn && operationConditions.isEmpty, let peripheral = peripheral else { + throw BluetoothManagerError.notReady + } + operationLock.lock() operationLock.wait(until: Date(timeIntervalSinceNow: timeout)) diff --git a/xDripG5/Transmitter.swift b/xDripG5/Transmitter.swift index b1e9806a..4147bab6 100644 --- a/xDripG5/Transmitter.swift +++ b/xDripG5/Transmitter.swift @@ -218,7 +218,11 @@ public final class Transmitter: BluetoothManagerDelegate { } // Wait for the OS dialog to pop-up before continuing. - bluetoothManager.waitForTime(timeout: 5) + do { + try bluetoothManager.waitForTime(timeout: 5) + } catch let error { + throw TransmitterError.authenticationError("Error waiting for bond request response: \(error)") + } do { data = try bluetoothManager.readValueForCharacteristicAndWait(.Authentication, expectingFirstByte: AuthStatusRxMessage.opcode) From 664fd8e9fcbf53ca8db4126ccbab68a06d93a69b Mon Sep 17 00:00:00 2001 From: Paul Dickens Date: Wed, 14 Feb 2018 00:02:07 +1100 Subject: [PATCH 11/11] change default timeouts --- xDripG5/BluetoothManager.swift | 8 ++++---- xDripG5/Messages/SensorRxMessage.swift | 9 +++++++++ xDripG5/Messages/SensorTxMessage.swift | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 xDripG5/Messages/SensorRxMessage.swift create mode 100644 xDripG5/Messages/SensorTxMessage.swift diff --git a/xDripG5/BluetoothManager.swift b/xDripG5/BluetoothManager.swift index 2ba18569..debde275 100644 --- a/xDripG5/BluetoothManager.swift +++ b/xDripG5/BluetoothManager.swift @@ -175,7 +175,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate /// Any error surfaced during the active operation private var operationError: Error? - func readValueForCharacteristicAndWait(_ UUID: CGMServiceCharacteristicUUID, timeout: TimeInterval = 2, expectingFirstByte firstByte: UInt8? = nil) throws -> Data { + func readValueForCharacteristicAndWait(_ UUID: CGMServiceCharacteristicUUID, timeout: TimeInterval = 10, expectingFirstByte firstByte: UInt8? = nil) throws -> Data { guard manager.state == .poweredOn && operationConditions.isEmpty, let peripheral = peripheral else { throw BluetoothManagerError.notReady } @@ -206,7 +206,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate return characteristic.value ?? Data() } - func setNotifyEnabledAndWait(_ enabled: Bool, forCharacteristicUUID UUID: CGMServiceCharacteristicUUID, timeout: TimeInterval = 2) throws { + func setNotifyEnabledAndWait(_ enabled: Bool, forCharacteristicUUID UUID: CGMServiceCharacteristicUUID, timeout: TimeInterval = 10) throws { guard manager.state == .poweredOn && operationConditions.isEmpty, let peripheral = peripheral else { throw BluetoothManagerError.notReady } @@ -264,7 +264,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate return characteristic.value ?? Data() } - func writeValueAndWait(_ value: Data, forCharacteristicUUID UUID: CGMServiceCharacteristicUUID, timeout: TimeInterval = 2, expectingFirstByte firstByte: UInt8? = nil) throws -> Data { + func writeValueAndWait(_ value: Data, forCharacteristicUUID UUID: CGMServiceCharacteristicUUID, timeout: TimeInterval = 10, expectingFirstByte firstByte: UInt8? = nil) throws -> Data { guard manager.state == .poweredOn && operationConditions.isEmpty, let peripheral = peripheral else { throw BluetoothManagerError.notReady } @@ -299,7 +299,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate return characteristic.value ?? Data() } - func waitForTime(timeout: TimeInterval = 2) throws { + func waitForTime(timeout: TimeInterval = 10) throws { guard manager.state == .poweredOn && operationConditions.isEmpty, let peripheral = peripheral else { throw BluetoothManagerError.notReady } diff --git a/xDripG5/Messages/SensorRxMessage.swift b/xDripG5/Messages/SensorRxMessage.swift new file mode 100644 index 00000000..d41bc2fd --- /dev/null +++ b/xDripG5/Messages/SensorRxMessage.swift @@ -0,0 +1,9 @@ +// +// SensorRxMessage.swift +// xDripG5 +// +// Created by Renee on 04/02/2018. +// Copyright © 2018 LoopKit Authors. All rights reserved. +// + +import Foundation diff --git a/xDripG5/Messages/SensorTxMessage.swift b/xDripG5/Messages/SensorTxMessage.swift new file mode 100644 index 00000000..0799d82c --- /dev/null +++ b/xDripG5/Messages/SensorTxMessage.swift @@ -0,0 +1,9 @@ +// +// SensorTxMessage.swift +// xDripG5 +// +// Created by Renee on 04/02/2018. +// Copyright © 2018 LoopKit Authors. All rights reserved. +// + +import Foundation