RileyLinkHeartbeatBluetoothDevice.swift 1.6 KB

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