RileyLinkHeartbeatBluetoothDevice.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // LoopFollow
  2. // RileyLinkHeartbeatBluetoothDevice.swift
  3. import CoreBluetooth
  4. import Foundation
  5. class RileyLinkHeartbeatBluetoothDevice: BluetoothDevice {
  6. private let CBUUID_Service_RileyLink: String = "0235733B-99C5-4197-B856-69219C2A3845"
  7. private let CBUUID_ReceiveCharacteristic_TimerTick: String = "6E6C7910-B89E-43A5-78AF-50C5E2B86F7E"
  8. private let CBUUID_ReceiveCharacteristic_Data: String = "C842E849-5028-42E2-867C-016ADADA9155"
  9. init(address: String, name: String?, bluetoothDeviceDelegate: BluetoothDeviceDelegate) {
  10. super.init(
  11. address: address,
  12. name: name,
  13. CBUUID_Advertisement: nil,
  14. servicesCBUUIDs: [CBUUID(string: CBUUID_Service_RileyLink)],
  15. CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_TimerTick,
  16. bluetoothDeviceDelegate: bluetoothDeviceDelegate
  17. )
  18. }
  19. override func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
  20. super.centralManager(central, didConnect: peripheral)
  21. }
  22. override func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
  23. super.peripheral(peripheral, didUpdateValueFor: characteristic, error: error)
  24. guard characteristic.uuid == CBUUID(string: CBUUID_ReceiveCharacteristic_TimerTick) else {
  25. return
  26. }
  27. bluetoothDeviceDelegate?.heartBeat()
  28. }
  29. override func expectedHeartbeatInterval() -> TimeInterval? {
  30. return 60
  31. }
  32. }