完成008A功能开发
This commit is contained in:
@ -73,15 +73,15 @@ class BleHelper {
|
||||
},
|
||||
{
|
||||
key: '10001',
|
||||
remark: '当前蓝牙适配器不可用'
|
||||
remark: '当前蓝牙适配器不可用,请打开手机蓝牙'
|
||||
},
|
||||
{
|
||||
key: '10002',
|
||||
remark: '没有找到指定设备'
|
||||
remark: '没有找到指定设备,设备不在信号范围或被他人连接'
|
||||
},
|
||||
{
|
||||
key: '10003',
|
||||
remark: '蓝牙设备连接失败'
|
||||
remark: '蓝牙设备连接失败,请重试'
|
||||
},
|
||||
{
|
||||
key: '10004',
|
||||
@ -101,7 +101,7 @@ class BleHelper {
|
||||
},
|
||||
{
|
||||
key: '10008',
|
||||
remark: '其余所有系统上报的异常'
|
||||
remark: '系统错误,请重试'
|
||||
},
|
||||
{
|
||||
key: '10009',
|
||||
@ -122,7 +122,7 @@ class BleHelper {
|
||||
{
|
||||
key: '10013',
|
||||
remark: '连接 deviceId 为空或者是格式不正确'
|
||||
},
|
||||
},
|
||||
{
|
||||
key: '10016',
|
||||
remark: '定位服务已关闭'
|
||||
@ -1667,7 +1667,7 @@ class BleHelper {
|
||||
console.log("当前已连接,释放连接锁");
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
resolve(false);
|
||||
LinkedCallback();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1689,7 +1689,7 @@ class BleHelper {
|
||||
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
console.error("新连接成功释放连接锁", deviceId);
|
||||
LinkedCallback();
|
||||
|
||||
// 处理 MTU 设置
|
||||
if (plus.os.name === 'Android') {
|
||||
this.setMtu(deviceId).catch(ex => {
|
||||
@ -1703,6 +1703,7 @@ class BleHelper {
|
||||
if (c.deviceId == deviceId) {
|
||||
c.Linked = true;
|
||||
c.linkId = linkId
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -1710,8 +1711,9 @@ class BleHelper {
|
||||
|
||||
if (fIndex > -1) {
|
||||
this.data.LinkedList[fIndex].Linked = true;
|
||||
this.data.LinkedList[fIndex].linkId =
|
||||
linkId;
|
||||
this.data.LinkedList[fIndex].linkId =linkId;
|
||||
this.data.LinkedList[fIndex].name =cr.name;
|
||||
this.data.LinkedList[fIndex].advertisData =cr.advertisData;
|
||||
} else {
|
||||
this.data.LinkedList.push(cr);
|
||||
}
|
||||
@ -1725,12 +1727,7 @@ class BleHelper {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
// console.log("LinkedList=", this.data
|
||||
// .LinkedList);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
resolve(true);
|
||||
|
||||
}).catch((ex) => {
|
||||
@ -1738,6 +1735,12 @@ class BleHelper {
|
||||
});
|
||||
},
|
||||
fail: (ex) => {
|
||||
if(ex.code===10010){
|
||||
console.log("设备已连接,无需重复连接");
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
ex = this.getError(ex);
|
||||
console.error("蓝牙" + deviceId + "连接失败" + JSON.stringify(
|
||||
ex));
|
||||
@ -1772,7 +1775,7 @@ class BleHelper {
|
||||
console.log("2222222");
|
||||
return linkDevice(deviceId);
|
||||
}).then((res) => {
|
||||
|
||||
LinkedCallback();
|
||||
if (res) { //新连接(含 createBLEConnection 刚成功)
|
||||
// console.log("11111111");
|
||||
if (fIndex == -1) {
|
||||
@ -1780,11 +1783,19 @@ class BleHelper {
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId); //获取服务
|
||||
} else {
|
||||
// 设备已在 LinkedList(例如缓存/重连):不能仅用缓存的 write/notify UUID 直接订阅。
|
||||
// 重连后须先 getBLEDeviceServices,否则部分机型 notifyBLECharacteristicValueChange 报 no service(10004),notify 收不到任何数据。
|
||||
console.log("已缓存设备重新连接,重新发现服务并订阅", deviceId);
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId);
|
||||
if (f.wirteCharactId && f.notifyCharactId) {
|
||||
if (!f.notifyState) {
|
||||
// console.log("开始订阅特征");
|
||||
this.subScribe(deviceId, true);
|
||||
} else {
|
||||
console.log("不订阅消息");
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
} else {
|
||||
console.log("开始获取服务", targetServiceId)
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId);
|
||||
}
|
||||
}
|
||||
} else { //已连接过,直接订阅消息
|
||||
// console.log("11111111");
|
||||
|
||||
Reference in New Issue
Block a user