From 5789264625082397a162cf0f8485de24f48b6552 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 31 Mar 2018 11:00:29 -0500 Subject: [PATCH] Updated DeviceRequest --- Package.pins | 2 +- Sources/BluetoothLinux/DeviceRequest.swift | 24 ++++++++------------ Sources/BluetoothLinux/HostController.swift | 4 ++-- Tests/BluetoothLinuxTests/iBeaconTests.swift | 6 ++--- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Package.pins b/Package.pins index 9590a61..5dc29f1 100644 --- a/Package.pins +++ b/Package.pins @@ -5,7 +5,7 @@ "package": "Bluetooth", "reason": null, "repositoryURL": "https://github.com/PureSwift/Bluetooth.git", - "version": "1.7.0" + "version": "1.7.2" } ], "version": 1 diff --git a/Sources/BluetoothLinux/DeviceRequest.swift b/Sources/BluetoothLinux/DeviceRequest.swift index f08e749..785d075 100644 --- a/Sources/BluetoothLinux/DeviceRequest.swift +++ b/Sources/BluetoothLinux/DeviceRequest.swift @@ -18,7 +18,7 @@ import Bluetooth public extension HostController { /// Sends a command to the device and waits for a response. - func deviceRequest(_ commandParameter: CP, _ eventParameterType: EP.Type, timeout: Int = HCI.defaultTimeout) throws -> EP { + func deviceRequest(_ commandParameter: CP, _ eventParameterType: EP.Type, timeout: HCICommandTimeout = .default) throws -> EP { let command = CP.command @@ -39,7 +39,7 @@ public extension HostController { /* @inline(__always) - func deviceRequest(command: C, eventParameterType: EP.Type, timeout: Int = HCI.defaultTimeout) throws -> EP { + func deviceRequest(command: C, eventParameterType: EP.Type, timeout: HCICommandTimeout = .default) throws -> EP { let opcode = (command.rawValue, C.opcodeGroupField.rawValue) @@ -54,7 +54,7 @@ public extension HostController { } @inline(__always) - func deviceRequest(commandParameter: CP, event: E, verifyStatusByte: Bool = true, timeout: Int = HCI.defaultTimeout) throws { + func deviceRequest(commandParameter: CP, event: E, verifyStatusByte: Bool = true, timeout: HCICommandTimeout = .default) throws { let command = CP.command @@ -77,7 +77,7 @@ public extension HostController { } @inline(__always) - func deviceRequest(command: C, event: E, verifyStatusByte: Bool = true, timeout: Int = HCI.defaultTimeout) throws { + func deviceRequest(command: C, event: E, verifyStatusByte: Bool = true, timeout: HCICommandTimeout = .default) throws { let opcode = (command.rawValue, C.opcodeGroupField.rawValue) @@ -98,7 +98,7 @@ public extension HostController { */ /// Send a command to the controller and wait for response. - func deviceRequest(_ command: C, timeout: Int = HCI.defaultTimeout) throws { + func deviceRequest(_ command: C, timeout: HCICommandTimeout = .default) throws { let data = try HCISendRequest(internalSocket, command: command, @@ -113,7 +113,7 @@ public extension HostController { } - func deviceRequest(_ commandParameter: CP, timeout: Int = HCI.defaultTimeout) throws { + func deviceRequest(_ commandParameter: CP, timeout: HCICommandTimeout = .default) throws { let data = try HCISendRequest(internalSocket, command: CP.command, @@ -128,7 +128,7 @@ public extension HostController { else { throw HCIError(rawValue: statusByte)! } } - func deviceRequest (_ commandReturnType : Return.Type, timeout: Int = HCI.defaultTimeout) throws -> Return { + func deviceRequest (_ commandReturnType : Return.Type, timeout: HCICommandTimeout = .default) throws -> Return { let data = try HCISendRequest(internalSocket, command: commandReturnType.command, @@ -148,7 +148,7 @@ public extension HostController { } /// Sends a command to the device and waits for a response with return parameter values. - func deviceRequest (_ commandParameter: CP, _ commandReturnType : Return.Type, timeout: Int) throws -> Return { + func deviceRequest (_ commandParameter: CP, _ commandReturnType : Return.Type, timeout: HCICommandTimeout = .default) throws -> Return { assert(CP.command.opcode == Return.command.opcode) @@ -179,14 +179,10 @@ internal func HCISendRequest (_ deviceDescriptor: CInt, commandParameterData: [UInt8] = [], event: UInt8 = 0, eventParameterLength: Int = 0, - timeout: Int = HCI.defaultTimeout) throws -> [UInt8] { - - // assertions - assert(timeout >= 0, "Negative timeout value") - assert(timeout <= Int(Int32.max), "Timeout > Int32.max") + timeout: HCICommandTimeout = .default) throws -> [UInt8] { // initialize variables - var timeout = timeout + var timeout = timeout.rawValue let opcodePacked = command.opcode.littleEndian var eventBuffer = [UInt8](repeating: 0, count: HCI.maximumEventSize) var oldFilter = HCIFilter() diff --git a/Sources/BluetoothLinux/HostController.swift b/Sources/BluetoothLinux/HostController.swift index cb47ee0..1f59343 100644 --- a/Sources/BluetoothLinux/HostController.swift +++ b/Sources/BluetoothLinux/HostController.swift @@ -22,13 +22,13 @@ public final class HostController: BluetoothHostControllerInterface { public typealias Identifier = UInt16 // MARK: - Properties - + /// The device identifier of the Bluetooth controller. public let identifier: Identifier /// The Bluetooth Address of the controller. public let address: Address - + // MARK: - Internal Properties internal let internalSocket: CInt diff --git a/Tests/BluetoothLinuxTests/iBeaconTests.swift b/Tests/BluetoothLinuxTests/iBeaconTests.swift index 24a42c9..83d75ef 100644 --- a/Tests/BluetoothLinuxTests/iBeaconTests.swift +++ b/Tests/BluetoothLinuxTests/iBeaconTests.swift @@ -30,9 +30,9 @@ final class iBeaconTests: XCTestCase { let rssi: Int8 = -29 var adverstisementDataParameter = beaconAdvertisementData(Array(identifier.data), - CInt(major).littleEndian, - CInt(minor).littleEndian, - CInt(rssi).littleEndian) + CInt(major), + CInt(minor), + CInt(rssi)) var parameterBytes = [UInt8].init(repeating: 0, count: Int(adverstisementDataParameter.length))