修复7305设备上报问题

This commit is contained in:
微微一笑
2025-11-01 17:21:45 +08:00
parent 3526f28d06
commit 500b461bdd
3 changed files with 162 additions and 61 deletions

View File

@ -301,6 +301,17 @@
these.showBleUnConnect();
return;
}
// 确保设备对象的detailPageUrl正确设置以便ReceiveData能找到对应的handler
if (f.device) {
f.device.detailPageUrl = "/pages/7305/BJQ7305";
} else {
f.device = {
...device,
detailPageUrl: "/pages/7305/BJQ7305"
};
}
let form = f.formData;
if (form) {
let keys = Object.keys(form);
@ -314,9 +325,23 @@
these.formData.img = device.devicePic;
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
// 更新缓存中的设备信息
ble.updateCache();
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
console.log("连接成功");
these.formData.bleStatu = true;
// 确保订阅消息已开启
let linkedDevice = ble.data.LinkedList.find(v => v.deviceId == f.deviceId);
if (linkedDevice && !linkedDevice.notifyState) {
console.log("连接成功但未订阅,主动订阅消息");
ble.subScribe(f.deviceId, true).then(() => {
console.log("订阅消息成功");
}).catch(err => {
console.error("订阅消息失败:", err);
});
}
});
these.setBleFormData();
these.getDetail();
@ -386,6 +411,18 @@
}
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
// 连接恢复后,确保重新订阅消息以接收设备上报的数据
let f = this.getDevice();
if (f && (f.notifyServiceid || f.notifyCharactId)) {
console.log("连接恢复,重新订阅消息");
ble.subScribe(res.deviceId, true).then(() => {
console.log("订阅消息成功,等待设备上报数据");
}).catch(err => {
console.error("订阅消息失败:", err);
});
}
setTimeout(() => {
hideLoading(these, 1000);
});
@ -475,30 +512,49 @@
}
let json = recei.ReceiveData(receive, device, path, recArr);
if (!json) {
// 检查返回的数据是否有效应该是解析后的对象不是原始receive对象
// 如果返回的是原始receive对象有bytes属性说明handler没有匹配或解析失败
if (!json || (json.hasOwnProperty('bytes') && (!json.battary && json.battary !== 0))) {
console.log("收到7305数据但未解析或解析失败:", json);
return;
}
console.log("收到7305解析数据:", json);
console.log("formData更新前 - battary:", these.formData.battary, "xuhang:", these.formData.xuhang, "statu:", these.formData.statu);
// 确保电量和续航时间正确更新(使用 $set 确保 Vue 响应式)
if (json.battary !== undefined && json.battary !== null) {
this.$set(these.formData, 'battary', json.battary);
console.log("更新电量:", json.battary, "->", these.formData.battary);
if (json.battary <= 20) {
this.showPop({
message: "设备电量低",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}
}
if (json.xuhang !== undefined && json.xuhang !== null) {
this.$set(these.formData, 'xuhang', json.xuhang);
console.log("更新续航时间:", json.xuhang, "->", these.formData.xuhang);
}
// 更新充电状态
if (json.statu !== undefined && json.statu !== null) {
this.$set(these.formData, 'statu', json.statu);
console.log("更新充电状态:", json.statu, "->", these.formData.statu);
}
// 更新其他字段
let keys = Object.keys(json);
keys.forEach((key) => {
if (key in these.formData) {
these.formData[key] = json[key];
if (key in these.formData && key !== 'battary' && key !== 'xuhang' && key !== 'statu') {
this.$set(these.formData, key, json[key]);
}
});
if ('statu' in json) {
these.formData.statu = json.statu == '1' ? '充电中' : '未充电';
}
if ('xuhang' in json) {
these.formData.xuhang = json.xuhang;
}
if ('battary' in json && this.formData.battary <= 20) {
this.showPop({
message: "设备电量低",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}
console.log("formData更新后 - battary:", these.formData.battary, "xuhang:", these.formData.xuhang, "statu:", these.formData.statu);
},