|
Bogdan Timofte
authored
2 weeks ago
|
1
|
//
|
|
|
2
|
// BluetoothRadio.swift
|
|
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 19/03/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import CoreBluetooth
|
|
|
10
|
|
|
|
11
|
/**
|
|
|
12
|
Bluetooth Radio Modules
|
|
|
13
|
# DX-BT18 (HM-10)
|
|
|
14
|
- Documentation [DX-BT18 User Manual](https:fccid.io/2AKS8DX-BT18/User-Manual/Users-Manual-4216091)
|
|
|
15
|
- Code [HM10 Bluetooth Serial iOS](https://github.com/hoiberg/HM10-BluetoothSerial-iOS)
|
|
|
16
|
# PW0316
|
|
|
17
|
- Documentation [PW0316 BLE4.0 User Manual](http://www.phangwei.com/o/PW0316_User_Manual_V2.9.pdf)
|
|
|
18
|
*/
|
|
|
19
|
enum BluetoothRadio : CaseIterable {
|
|
|
20
|
case BT18
|
|
|
21
|
case PW0316
|
|
|
22
|
case UNKNOWN
|
|
|
23
|
}
|
|
|
24
|
|
|
|
25
|
/**
|
|
|
26
|
Dictionary containing services used in our communication for each radio
|
|
|
27
|
*/
|
|
|
28
|
var BluetoothRadioServicesUUIDS: [BluetoothRadio:[CBUUID]] = [
|
|
|
29
|
.BT18 : [CBUUID(string: "FFE0")],
|
|
|
30
|
.PW0316 : [CBUUID(string: "FFE0"), CBUUID(string: "FFE5")]
|
|
|
31
|
]
|
|
|
32
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
33
|
/**
|
|
|
34
|
Dictionary containing preferred notification characteristics used in our communication.
|
|
|
35
|
|
|
|
36
|
Notes:
|
|
|
37
|
- UM-family radios are documented around an HM-10 style `FFE0` / `FFE1` path
|
|
|
38
|
- DX-BT18 can additionally expose `FFE2` as a write-only characteristic
|
|
|
39
|
- TC66C PW0316 uses `FFE4` for notifications
|
|
|
40
|
*/
|
|
|
41
|
var BluetoothRadioNotifyUUIDs: [BluetoothRadio:[CBUUID]] = [
|
|
|
42
|
.BT18 : [CBUUID(string: "FFE1")],
|
|
|
43
|
.PW0316 : [CBUUID(string: "FFE4")]
|
|
|
44
|
]
|
|
|
45
|
|
|
|
46
|
/**
|
|
|
47
|
Dictionary containing preferred write characteristics used in our communication.
|
|
|
48
|
|
|
|
49
|
Preference order matters:
|
|
|
50
|
- for BT18 radios we prefer `FFE2` when available and fall back to `FFE1`
|
|
|
51
|
- for PW0316 radios we write to `FFE9`
|
|
|
52
|
*/
|
|
|
53
|
var BluetoothRadioWriteUUIDs: [BluetoothRadio:[CBUUID]] = [
|
|
|
54
|
.BT18 : [CBUUID(string: "FFE2"), CBUUID(string: "FFE1")],
|
|
|
55
|
.PW0316 : [CBUUID(string: "FFE9")]
|
|
|
56
|
]
|
|
|
57
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
58
|
/**
|
|
|
59
|
Returns an array containing all service UUIDs used by radios
|
|
|
60
|
*/
|
|
|
61
|
func allBluetoothRadioServices () -> [CBUUID] {
|
|
|
62
|
var retval: [CBUUID] = []
|
|
|
63
|
for radio in BluetoothRadio.allCases {
|
|
|
64
|
for serviceUUID in BluetoothRadioServicesUUIDS[radio] ?? [] {
|
|
|
65
|
if !retval.contains(serviceUUID) {
|
|
|
66
|
retval.append(serviceUUID)
|
|
|
67
|
}
|
|
|
68
|
}
|
|
|
69
|
}
|
|
|
70
|
return retval
|
|
|
71
|
}
|