-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Queue fixes, advertisement data/rssi, connection respects task cancel…
…lation
- Loading branch information
Showing
9 changed files
with
365 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ import Foundation | |
|
||
public enum CentralError: Error { | ||
case unknown | ||
case cancelled | ||
} |
58 changes: 58 additions & 0 deletions
58
Sources/SwiftBluetooth/Peripheral/Peripheral+DiscoveryInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Foundation | ||
import CoreBluetooth | ||
|
||
extension Peripheral { | ||
public struct DiscoveryInfo { | ||
public var RSSI: Int | ||
public var advertisementData: AdvertisementData | ||
|
||
init(RSSI: NSNumber, advertisementData: [String : Any]) { | ||
self.RSSI = Int(truncating: RSSI) | ||
self.advertisementData = .init(data: advertisementData) | ||
} | ||
|
||
public struct AdvertisementData { | ||
private(set) var data: [String : Any] | ||
|
||
subscript(key: String) -> Any? { | ||
data[key] | ||
} | ||
|
||
public var localName: String? { | ||
data[CBAdvertisementDataLocalNameKey] as? String | ||
} | ||
|
||
public var manufacturerData: Data? { | ||
data[CBAdvertisementDataManufacturerDataKey] as? Data | ||
} | ||
|
||
public var serviceData: [CBUUID : Data]? { | ||
data[CBAdvertisementDataServiceDataKey] as? [CBUUID : Data] | ||
} | ||
|
||
public var serviceUUIDs: [CBUUID]? { | ||
data[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID] | ||
} | ||
|
||
public var overflowServiceUUIDs: [CBUUID]? { | ||
data[CBAdvertisementDataOverflowServiceUUIDsKey] as? [CBUUID] | ||
} | ||
|
||
public var txPowerLevel: Int? { | ||
guard let value = data[CBAdvertisementDataTxPowerLevelKey] as? NSNumber else { return nil } | ||
|
||
return Int(truncating: value) | ||
} | ||
|
||
public var isConnectable: Bool? { | ||
guard let value = data[CBAdvertisementDataIsConnectable] as? NSNumber else { return nil } | ||
|
||
return Bool(truncating: value) | ||
} | ||
|
||
public var solicitedServiceUUIDs: [CBUUID]? { | ||
data[CBAdvertisementDataSolicitedServiceUUIDsKey] as? [CBUUID] | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.