fix: 蓝牙协议接口编码实现。
This commit is contained in:
@@ -902,9 +902,18 @@ const getBLEDeviceServices = async (deviceId) => {
|
||||
let notifyCharacteristicId = '' // 可监听特征值
|
||||
let mainServiceId = '' // 主服务ID
|
||||
|
||||
// 自动获取第一个服务的特征值(用于展示)
|
||||
// 查找协议规定的服务ID (0x00FF)
|
||||
// 注意:不同设备可能返回不同格式的UUID,需要兼容匹配
|
||||
if (res.services.length > 0) {
|
||||
mainServiceId = res.services[0].uuid
|
||||
// 优先查找包含 "00FF" 或 "0xFF" 的服务UUID
|
||||
const targetService = res.services.find(s => {
|
||||
const uuid = s.uuid.toUpperCase()
|
||||
return uuid.includes('00FF') || uuid.includes('0XFF') || uuid === '0X00FF'
|
||||
})
|
||||
|
||||
// 如果找到目标服务,使用它;否则使用第一个服务
|
||||
mainServiceId = targetService ? targetService.uuid : res.services[0].uuid
|
||||
console.log('使用的主服务UUID:', mainServiceId, targetService ? '(匹配协议0x00FF)' : '(默认第一个服务)')
|
||||
const chars = await getBLEDeviceCharacteristicsSync(deviceId, mainServiceId)
|
||||
characteristics.value = chars
|
||||
|
||||
|
||||
Reference in New Issue
Block a user