|
|
@@ -542,6 +542,7 @@ export const useBleStore = defineStore('ble', {
|
|
|
if (this.bleState === BLE_STATE.CONNECTING) throw _err(BLE_ERROR.BUSY)
|
|
|
this._setState(BLE_STATE.CONNECTING)
|
|
|
this.device = { deviceId, name: '' }
|
|
|
+ console.log("连接蓝牙时的设备id",this.device)
|
|
|
|
|
|
try {
|
|
|
await _invoke(uni.createBLEConnection, {
|
|
|
@@ -575,7 +576,7 @@ export const useBleStore = defineStore('ble', {
|
|
|
/** 扫描 + 连接一步到位(支持 deviceId 直连优先,跳过扫描) */
|
|
|
async scanAndConnect(opt = {}) {
|
|
|
const { deviceId: directId, deviceName, advertisData: passedAdvertisData, ...restOpt } = opt
|
|
|
-
|
|
|
+ console.log("连接opt",opt,directId,passedAdvertisData,restOpt)
|
|
|
// 策略:如果已有 deviceId,先尝试直连(不扫描),失败后回退扫描
|
|
|
if (directId) {
|
|
|
try {
|
|
|
@@ -584,6 +585,7 @@ export const useBleStore = defineStore('ble', {
|
|
|
this.device.name = deviceName || this.device.name || ''
|
|
|
// 存储 advertisData 作为跨平台设备标识
|
|
|
if (passedAdvertisData) {
|
|
|
+ console.log("连接passedAdvertisData",passedAdvertisData)
|
|
|
this.device.advertisData = passedAdvertisData
|
|
|
}
|
|
|
logger.info('directConnect success, scan skipped')
|
|
|
@@ -600,8 +602,10 @@ export const useBleStore = defineStore('ble', {
|
|
|
const device = await this.startScan(scanOpt)
|
|
|
await this.connectDevice(device.deviceId)
|
|
|
this.device.name = device.name || device.localName || ''
|
|
|
- // 存储 advertisData:优先用扫描结果中的,其次用传入的
|
|
|
- this.device.advertisData = device.advertisData || passedAdvertisData || ''
|
|
|
+ console.log("连接device._advertisDataHex",device._advertisDataHex)
|
|
|
+ // 存储 advertisData(hex 字符串):优先用传入的(后台 deviceCode),其次用扫描结果的 hex
|
|
|
+ // 注意:device.advertisData 是原始 ArrayBuffer,不能直接存储,需使用 _advertisDataHex
|
|
|
+ this.device.advertisData = passedAdvertisData || device.advertisData || ''
|
|
|
return this.device
|
|
|
},
|
|
|
|