Skip to content

Commit

Permalink
Merge pull request #62 from PureSwift/feature/add-aerobic-heart-rate-…
Browse files Browse the repository at this point in the history
…upper-limit

Added GATT Aerobic Heart Rate Upper Limit Characteristic
  • Loading branch information
colemancda authored Jun 13, 2018
2 parents 8cf99b4 + 11bc22e commit a39c083
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
56 changes: 56 additions & 0 deletions Sources/GATTCharacteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,62 @@ extension GATTAerobicHeartRateLowerLimit: CustomStringConvertible {
}
}

/**
Aerobic Heart Rate Upper Limit
Upper limit of the heart rate where the user enhances his endurance while exercising
- SeeAlso: [Aerobic Heart Rate Upper Limit](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.aerobic_heart_rate_upper_limit.xml)
*/
public struct GATTAerobicHeartRateUpperLimit: GATTProfileCharacteristic {

public typealias BeatsPerMinute = GATTBeatsPerMinute.Byte

internal static let length = MemoryLayout<UInt8>.size

public static var uuid: BluetoothUUID { return .aerobicHeartRateUpperLimit }

public var beats: BeatsPerMinute

public init(beats: BeatsPerMinute) {

self.beats = beats
}

public init?(data: Data) {

guard data.count == type(of: self).length
else { return nil }

let beats = BeatsPerMinute(rawValue: data[0])

self.init(beats: beats)
}

public var data: Data {

return Data([beats.rawValue])
}

}

extension GATTAerobicHeartRateUpperLimit: Equatable {

public static func == (lhs: GATTAerobicHeartRateUpperLimit,
rhs: GATTAerobicHeartRateUpperLimit) -> Bool {

return lhs.beats == rhs.beats
}
}

extension GATTAerobicHeartRateUpperLimit: CustomStringConvertible {

public var description: String {

return beats.description
}
}

// MARK: - Supporting Types

public enum GATTBeatsPerMinute {
Expand Down
24 changes: 23 additions & 1 deletion Tests/BluetoothTests/GATTCharacteristicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ final class GATTCharacteristicTests: XCTestCase {
("testUnreadAlertStatus", testUnreadAlertStatus),
("testAlertNotificationControlPoint", testAlertNotificationControlPoint),
("testBloodPressureMeasurement", testBloodPressureMeasurement),
("testAerobicHeartRateLowerLimit", testAerobicHeartRateLowerLimit)
("testAerobicHeartRateLowerLimit", testAerobicHeartRateLowerLimit),
("testAerobicHeartRateUpperLimit", testAerobicHeartRateUpperLimit)
]

func testDateTime() {
Expand Down Expand Up @@ -260,4 +261,25 @@ final class GATTCharacteristicTests: XCTestCase {
XCTAssertEqual(GATTAerobicHeartRateLowerLimit.uuid, .aerobicHeartRateLowerLimit)
XCTAssertEqual(BeatsPerMinute.unitType, .beatsPerMinute)
}

func testAerobicHeartRateUpperLimit() {

typealias BeatsPerMinute = GATTAerobicHeartRateUpperLimit.BeatsPerMinute

XCTAssertNil(GATTAerobicHeartRateUpperLimit(data: Data([0x3d, 0x72])))

let data = Data([0x22])

let rateLowerLimit: BeatsPerMinute = 34

guard let characteristic = GATTAerobicHeartRateUpperLimit(data: data)
else { XCTFail("Could not decode from bytes"); return }

XCTAssertEqual(characteristic.data, data)
XCTAssertEqual(characteristic.beats, rateLowerLimit)
XCTAssertEqual(characteristic.description, "34")
XCTAssertEqual(rateLowerLimit.description, "34")
XCTAssertEqual(GATTAerobicHeartRateUpperLimit.uuid, .aerobicHeartRateUpperLimit)
XCTAssertEqual(BeatsPerMinute.unitType, .beatsPerMinute)
}
}

0 comments on commit a39c083

Please sign in to comment.