Blame view

泰额版/Food Labeling Management App UniApp/src/utils/print/bleWriteModeRules.ts 1.62 KB
59e51671   “wangming”   1
1
  /**
5a192b24   杨鑫   最新同步
2
3
4
5
   * 佳博 GP-D320FX 等 Nordic UART 数据口:实机必须 writeNoResponse 才能稳定长任务下发。
   * 安卓 GATT 常只声明 write,若按 GATT 走带响应写,可能首包或跑十几包后 10007 property not support。
   * 白名单 UUID 连接/打印时一律优先 writeNoResponse;首包仍 10007 时才允许试一次带响应写。
   * 已用 writeNoResponse 跑通后禁止切回带响应写。
59e51671   “wangming”   1
6
7
8
9
10
11
12
13
   */
  
  export function normalizeBleUuid (uuid: string): string {
    return String(uuid || '').replace(/-/g, '').toLowerCase()
  }
  
  /** serviceUuid + characteristicUuid(无横线小写) */
  const FORCE_WRITE_NO_RESPONSE: Array<{ service: string; characteristic: string }> = [
5a192b24   杨鑫   最新同步
14
    /** 佳博 GP-D320FX 等 Silicon Labs / 旧 Nordic UART */
59e51671   “wangming”   1
15
16
17
18
    {
      service: '49535343fe7d4ae58fa99fafd205e455',
      characteristic: '49535343884143f4a8d4ecbe34729bb3',
    },
5a192b24   杨鑫   最新同步
19
20
21
22
23
    /** 标准 Nordic UART (NUS) */
    {
      service: '6e400001b5a3f393e0a9e50e24dcca9e',
      characteristic: '6e400002b5a3f393e0a9e50e24dcca9e',
    },
59e51671   “wangming”   1
24
25
  ]
  
5a192b24   杨鑫   最新同步
26
27
28
29
  const NORDIC_UART_SERVICE_IDS = new Set(
    FORCE_WRITE_NO_RESPONSE.map((p) => p.service),
  )
  
59e51671   “wangming”   1
30
31
  export function blePairRequiresWriteNoResponse (
    serviceId: string,
5a192b24   杨鑫   最新同步
32
    characteristicId: string,
59e51671   “wangming”   1
33
34
35
36
37
38
39
40
  ): 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 {
5a192b24   杨鑫   最新同步
41
    return NORDIC_UART_SERVICE_IDS.has(normalizeBleUuid(serviceId))
59e51671   “wangming”   1
42
  }