Skip to content

Commit

Permalink
Updated DeviceRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Mar 31, 2018
1 parent 918bbda commit 5789264
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Package.pins
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 10 additions & 14 deletions Sources/BluetoothLinux/DeviceRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Bluetooth
public extension HostController {

/// Sends a command to the device and waits for a response.
func deviceRequest<CP: HCICommandParameter, EP: HCIEventParameter>(_ commandParameter: CP, _ eventParameterType: EP.Type, timeout: Int = HCI.defaultTimeout) throws -> EP {
func deviceRequest<CP: HCICommandParameter, EP: HCIEventParameter>(_ commandParameter: CP, _ eventParameterType: EP.Type, timeout: HCICommandTimeout = .default) throws -> EP {

let command = CP.command

Expand All @@ -39,7 +39,7 @@ public extension HostController {

/*
@inline(__always)
func deviceRequest<C: HCICommand, EP: HCIEventParameter>(command: C, eventParameterType: EP.Type, timeout: Int = HCI.defaultTimeout) throws -> EP {
func deviceRequest<C: HCICommand, EP: HCIEventParameter>(command: C, eventParameterType: EP.Type, timeout: HCICommandTimeout = .default) throws -> EP {

let opcode = (command.rawValue, C.opcodeGroupField.rawValue)

Expand All @@ -54,7 +54,7 @@ public extension HostController {
}

@inline(__always)
func deviceRequest<CP: HCICommandParameter, E: HCIEvent>(commandParameter: CP, event: E, verifyStatusByte: Bool = true, timeout: Int = HCI.defaultTimeout) throws {
func deviceRequest<CP: HCICommandParameter, E: HCIEvent>(commandParameter: CP, event: E, verifyStatusByte: Bool = true, timeout: HCICommandTimeout = .default) throws {

let command = CP.command

Expand All @@ -77,7 +77,7 @@ public extension HostController {
}

@inline(__always)
func deviceRequest<C: HCICommand, E: HCIEvent>(command: C, event: E, verifyStatusByte: Bool = true, timeout: Int = HCI.defaultTimeout) throws {
func deviceRequest<C: HCICommand, E: HCIEvent>(command: C, event: E, verifyStatusByte: Bool = true, timeout: HCICommandTimeout = .default) throws {

let opcode = (command.rawValue, C.opcodeGroupField.rawValue)

Expand All @@ -98,7 +98,7 @@ public extension HostController {
*/

/// Send a command to the controller and wait for response.
func deviceRequest<C: HCICommand>(_ command: C, timeout: Int = HCI.defaultTimeout) throws {
func deviceRequest<C: HCICommand>(_ command: C, timeout: HCICommandTimeout = .default) throws {

let data = try HCISendRequest(internalSocket,
command: command,
Expand All @@ -113,7 +113,7 @@ public extension HostController {

}

func deviceRequest<CP: HCICommandParameter>(_ commandParameter: CP, timeout: Int = HCI.defaultTimeout) throws {
func deviceRequest<CP: HCICommandParameter>(_ commandParameter: CP, timeout: HCICommandTimeout = .default) throws {

let data = try HCISendRequest(internalSocket,
command: CP.command,
Expand All @@ -128,7 +128,7 @@ public extension HostController {
else { throw HCIError(rawValue: statusByte)! }
}

func deviceRequest <Return: HCICommandReturnParameter> (_ commandReturnType : Return.Type, timeout: Int = HCI.defaultTimeout) throws -> Return {
func deviceRequest <Return: HCICommandReturnParameter> (_ commandReturnType : Return.Type, timeout: HCICommandTimeout = .default) throws -> Return {

let data = try HCISendRequest(internalSocket,
command: commandReturnType.command,
Expand All @@ -148,7 +148,7 @@ public extension HostController {
}

/// Sends a command to the device and waits for a response with return parameter values.
func deviceRequest <CP: HCICommandParameter, Return: HCICommandReturnParameter> (_ commandParameter: CP, _ commandReturnType : Return.Type, timeout: Int) throws -> Return {
func deviceRequest <CP: HCICommandParameter, Return: HCICommandReturnParameter> (_ commandParameter: CP, _ commandReturnType : Return.Type, timeout: HCICommandTimeout = .default) throws -> Return {

assert(CP.command.opcode == Return.command.opcode)

Expand Down Expand Up @@ -179,14 +179,10 @@ internal func HCISendRequest <Command: HCICommand> (_ 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()
Expand Down
4 changes: 2 additions & 2 deletions Sources/BluetoothLinux/HostController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Tests/BluetoothLinuxTests/iBeaconTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 5789264

Please sign in to comment.