Skip to content

Commit

Permalink
Merge pull request #21 from PureSwift/GATTClient
Browse files Browse the repository at this point in the history
- 5688f1c Implemented *Discover Characteristics by UUID*
- 9386d64 Improved performance with `BitMaskOptionSet`
  • Loading branch information
colemancda authored Dec 11, 2017
2 parents 5de29e2 + c7b15c0 commit 7c8c11c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 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.5.0"
"version": "1.5.2"
}
],
"version": 1
Expand Down
26 changes: 14 additions & 12 deletions Sources/BluetoothLinux/GATTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,11 @@ public final class GATTClient {
foundData: [],
completion: completion)

if let uuid = uuid {



} else {

let pdu = ATTReadByTypeRequest(startHandle: service.handle,
endHandle: service.end,
attributeType: attributeType.uuid)

send(pdu) { [unowned self] in self.readByType($0, operation: operation) }
}
let pdu = ATTReadByTypeRequest(startHandle: service.handle,
endHandle: service.end,
attributeType: attributeType.uuid)

send(pdu) { [unowned self] in self.readByType($0, operation: operation) }
}

// MARK: - Callbacks
Expand Down Expand Up @@ -386,6 +379,14 @@ public final class GATTClient {
handle: (handle, declaration.valueHandle))

operation.foundData.append(characteristic)

// if we specified a UUID to be searched,
// then call completion if it matches
if let operationUUID = operation.uuid {

guard characteristic.uuid != operationUUID
else { operation.success(); return }
}
}

// get more if possible
Expand All @@ -408,6 +409,7 @@ public final class GATTClient {

} else {

// end of service
operation.success()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/BluetoothLinux/GATTDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ public extension GATTDatabase {

public let uuid: BluetoothUUID

public let permissions: [Permission]
public let permissions: BitMaskOptionSet<Permission>

public var value: Data

/// Defualt initializer
fileprivate init(handle: UInt16,
uuid: BluetoothUUID,
value: Data = Data(),
permissions: [Permission] = []) {
permissions: BitMaskOptionSet<Permission> = []) {

self.handle = handle
self.uuid = uuid
Expand Down
3 changes: 2 additions & 1 deletion Sources/BluetoothLinux/GATTServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public final class GATTServer {
else { fatalError("Could not add PDU to queue: \(response)") }
}

private func checkPermissions(_ permissions: [ATT.AttributePermission], _ attribute: GATTDatabase.Attribute) -> ATT.Error? {
private func checkPermissions(_ permissions: BitMaskOptionSet<ATT.AttributePermission>,
_ attribute: GATTDatabase.Attribute) -> ATT.Error? {

guard attribute.permissions != permissions else { return nil }

Expand Down

0 comments on commit 7c8c11c

Please sign in to comment.