Skip to content

Commit

Permalink
GATT.UUID should be internal
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 24, 2018
1 parent a87337f commit aaf53f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
20 changes: 5 additions & 15 deletions Sources/GATT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
public enum GATT {

/// GATT UUIDs
public enum UUID: UInt16 {
internal enum UUID: UInt16 {

case primaryService = 0x2800
case secondaryService = 0x2801
Expand All @@ -34,19 +34,10 @@ public enum GATT {
/// Initializes from a Bluetooth UUID
public init?(uuid: BluetoothUUID) {

switch uuid {

case let .bit16(value):

guard let gatt = GATT.UUID(rawValue: value)
else { return nil }

self = gatt

default:

return nil
}
guard case let .bit16(value) = uuid
else { return nil }

self.init(rawValue: value)
}

/// Returns a Bluetooth UUID initialized with the `rawValue` of this GATT UUID.
Expand All @@ -55,7 +46,6 @@ public enum GATT {
return .bit16(rawValue)
}
}

}

// MARK: - Characteristic Property
Expand Down
12 changes: 9 additions & 3 deletions Sources/GATTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public final class GATTClient {
let serviceUUID = BluetoothUUID(littleEndian: littleEndianServiceUUID)

let service = Service(uuid: serviceUUID,
type: operation.type,
isPrimary: operation.type == .primaryService,
handle: serviceData.attributeHandle,
end: serviceData.endGroupHandle)

Expand Down Expand Up @@ -747,7 +747,7 @@ public final class GATTClient {
for serviceData in pdu.handles {

let service = Service(uuid: serviceUUID,
type: operation.type,
isPrimary: operation.type == .primaryService,
handle: serviceData.foundAttribute,
end: serviceData.groupEnd)

Expand Down Expand Up @@ -1240,11 +1240,17 @@ public extension GATTClient {

public let uuid: BluetoothUUID

public let type: GATT.UUID
public let isPrimary: Bool

public let handle: UInt16

public let end: UInt16

@available(*, deprecated, renamed: "isPrimary")
public var type: BluetoothUUID {

return isPrimary ? .primaryService : .secondaryService
}
}

/// A discovered characteristic.
Expand Down
12 changes: 9 additions & 3 deletions Tests/BluetoothTests/GATTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Foundation
final class GATTTests: XCTestCase {

static let allTests = [
("testUUID", testUUID),
("testGATT", testGATT),
("testMTUExchange", testMTUExchange),
("testDiscoverPrimaryServicesNoMTUExchange", testDiscoverPrimaryServicesNoMTUExchange),
Expand All @@ -23,6 +24,11 @@ final class GATTTests: XCTestCase {
("testDiscoverServiceByUUID", testDiscoverServiceByUUID)
]

func testUUID() {


}

func testMTUExchange() {

guard let mtu = ATTMaximumTransmissionUnit(rawValue: 512)
Expand Down Expand Up @@ -603,7 +609,7 @@ final class GATTTests: XCTestCase {
XCTAssertEqual(foundService.uuid, services[0].uuid)
XCTAssertEqual(foundService.handle, database.serviceHandles(at: 0).start)
XCTAssertEqual(foundService.end, database.serviceHandles(at: 0).end)
XCTAssertEqual(foundService.type.uuid, database.first!.uuid)
XCTAssertEqual(foundService.isPrimary, database.first!.uuid == .primaryService)

client.discoverAllCharacteristics(of: foundService) {

Expand Down Expand Up @@ -686,7 +692,7 @@ final class GATTTests: XCTestCase {

XCTAssertEqual(foundService.handle, database.serviceHandles(at: 0).start)
XCTAssertEqual(foundService.end, database.serviceHandles(at: 0).end)
XCTAssertEqual(foundService.type.uuid, database.first!.uuid)
XCTAssertEqual(foundService.isPrimary, database.first!.uuid == .primaryService)

client.discoverAllCharacteristics(of: foundService) {

Expand Down Expand Up @@ -845,7 +851,7 @@ final class GATTTests: XCTestCase {

XCTAssertEqual(foundService.handle, database.serviceHandles(at: 0).start)
XCTAssertEqual(foundService.end, database.serviceHandles(at: 0).end)
XCTAssertEqual(foundService.type.uuid, database[0].uuid)
XCTAssertEqual(foundService.isPrimary, database.first!.uuid == .primaryService)

client.discoverAllCharacteristics(of: foundService) {

Expand Down

0 comments on commit aaf53f7

Please sign in to comment.