RileyLinkHeartbeatBluetoothDevice.swift 1.6 KB

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