bleWriteModeRules.ts
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* 佳博 GP-D320FX 等 Nordic UART 数据口:实机必须 writeNoResponse 才能稳定长任务下发。
* 安卓 GATT 常只声明 write,若按 GATT 走带响应写,可能首包或跑十几包后 10007 property not support。
* 白名单 UUID 连接/打印时一律优先 writeNoResponse;首包仍 10007 时才允许试一次带响应写。
* 已用 writeNoResponse 跑通后禁止切回带响应写。
*/
export function normalizeBleUuid (uuid: string): string {
return String(uuid || '').replace(/-/g, '').toLowerCase()
}
/** serviceUuid + characteristicUuid(无横线小写) */
const FORCE_WRITE_NO_RESPONSE: Array<{ service: string; characteristic: string }> = [
/** 佳博 GP-D320FX 等 Silicon Labs / 旧 Nordic UART */
{
service: '49535343fe7d4ae58fa99fafd205e455',
characteristic: '49535343884143f4a8d4ecbe34729bb3',
},
/** 标准 Nordic UART (NUS) */
{
service: '6e400001b5a3f393e0a9e50e24dcca9e',
characteristic: '6e400002b5a3f393e0a9e50e24dcca9e',
},
]
const NORDIC_UART_SERVICE_IDS = new Set(
FORCE_WRITE_NO_RESPONSE.map((p) => p.service),
)
export function blePairRequiresWriteNoResponse (
serviceId: string,
characteristicId: string,
): boolean {
const s = normalizeBleUuid(serviceId)
const c = normalizeBleUuid(characteristicId)
return FORCE_WRITE_NO_RESPONSE.some((p) => p.service === s && p.characteristic === c)
}
/** 是否为本仓库维护的 Nordic UART 风格串口服务(需写前开 notify、分包间留间隔等) */
export function isNordicUartStyleBleService (serviceId: string): boolean {
return NORDIC_UART_SERVICE_IDS.has(normalizeBleUuid(serviceId))
}