1
0
forked from dyf/APP

完成102添加联机日志,报警日志

This commit is contained in:
liub
2026-01-28 16:31:34 +08:00
parent 1b48751944
commit d6ca84170f
16 changed files with 2651 additions and 805 deletions

View File

@ -1,8 +1,11 @@
import Common from '@/utils/Common.js'
class BleReceive {
constructor() {
this.StorageKey = "linkedDevices";
this.HandlerMap = {
'/pages/6155/deviceDetail': this.Receive_6155.bind(this),
'/pages/6155/BJQ6155': this.Receive_6155_XH.bind(this),
'/pages/7305/BJQ7305': this.Receive_6155.bind(this),
'/pages/650/HBY650': this.Receive_650.bind(this),
'/pages/670/HBY670': this.Receive_670.bind(this),
@ -423,6 +426,94 @@ class BleReceive {
return data;
}
Receive_6155_XH(receive, f, path, recArr) {
let bytes = receive.bytes;
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
try {
let light = null;
let mode = null;
if (bytes[2] === 0x01 && bytes[3] === 0x00) {
light = 0;
mode = 'main';
} else if (bytes[2] === 0x02 && bytes[3] === 0x00) {
light = 1;
mode = 'main';
} else if (bytes[2] === 0x00 && bytes[3] === 0x01) {
light = 2;
mode = 'main';
} else if (bytes[2] === 0x03 && bytes[3] === 0x00) {
light = 0;
mode = 'fu';
} else if (bytes[2] === 0x04 && bytes[3] === 0x00) {
light = 1;
mode = 'fu';
}
if (bytes[2] === 0x05 && bytes[3] === 0x00) {
light = 3;
}
// 解析剩余电量
let batteryLevelByte = bytes[4];
// 电量百分比范围检查
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
//充电状态
let warn = bytes[5];
if (warn == 0x00) {
warn = '未充电';
} else if (warn == 0x01) {
warn = '充电中';
}
// 解析剩余照明时间(第三和第四字节,小端序)
let lightingTime = "";
let HH = Math.max(0, Math.min(100, bytes[6]));
let mm = Math.max(0, Math.min(100, bytes[7]));
lightingTime = HH + "小时" + mm + "分钟";
let formData = {};
formData.mode = mode;
formData.light = light;
formData.battary = batteryLevel;
formData.statu = warn;
formData.xuhang = lightingTime;
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() === f.device.detailPageUrl.replace(/\//g,
'').toLowerCase();
});
if (!recCnt) {
if (batteryLevel <= 20) {
// 会弹出两个框,暂且注释掉这段代码
uni.showModal({
content: "设备'" + f.device.deviceName + "'电量低",
title: "提示"
});
}
}
this.setBleFormData(formData, f);
return formData;
} catch (error) {
console.log('7305数据解析错误:', error);
return null;
}
}
return null;
}
Receive_6155(receive, f, path, recArr) {
let bytes = receive.bytes;
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
@ -588,8 +679,9 @@ class BleReceive {
let receiveData = {};
try {
// console.log("str=",receive.str);
console.log("订阅消息者:", path);
console.log("设备收到消息:", f);
console.log("消息内容:", receive);
receiveData = JSON.parse(receive.str);
let recCnt = recArr.find(v => {
@ -613,6 +705,134 @@ class BleReceive {
}
}
if (f.device && path === "pages/common/index") { //仅在首页订阅此操作
console.error("1111111111");
let linkKey = "102_" + f.device.id + "_linked";
let warnKey = "102_" + f.device.id + "_warning";
let time = new Date(); //Common.DateFormat(new Date(),'yyyy-MM-dd HH:mmss');
if (receiveData.sta_tomac) { //某个设备上线了
if (receiveData.sta_tomac.indexOf(':') == -1) {
receiveData.sta_tomac = receiveData.sta_tomac.replace(/(.{2})/g, '$1:').slice(0, -
1); //mac地址自动补:
}
uni.getStorageInfo({
success: function(res) {
let arr = [];
let linked = {
linkId: f.linkId,
read: false,
linkEqs: [{
linkTime: time,
linkMac: f.macAddress
}, {
linkTime: time,
linkMac: receiveData.sta_tomac
}]
};
if (res.keys.includes(linkKey)) {
arr = uni.getStorageSync(linkKey);
}
if (arr.length == 0) {
arr.unshift(linked);
} else {
let dev = arr.find(v => {
if (v.linkId == f.linkId) {
let vl = v.linkEqs.find(cvl => {
if(cvl.linkMac === receiveData.sta_tomac){
v.read=false;
cvl.linkTime=time;
return true;
}
return false;
});
if (!vl) {
v.linkEqs.push({
linkTime: time,
linkMac: receiveData.sta_tomac
});
}
return vl;
}
return false;
});
if (!dev) {
arr.unshift(linked);
}
}
console.error("某个设备上线了", arr)
uni.setStorage({
key: linkKey,
data: arr
});
}
});
}
let warnArrs = [];
let guid = Common.guid();
if (receiveData.sta_sosadd) { //某个设备闯入报警
console.error("某个设备闯入报警");
if (receiveData.sta_sosadd.indexOf(':') == -1) {
receiveData.sta_sosadd = receiveData.sta_sosadd.replace(/(.{2})/g, '$1:').slice(0, -
1); //mac地址自动补:
}
warnArrs.push({
linkId: f.linkId,
read: false,
key: guid,
warnType: "闯入报警",
warnMac: receiveData.sta_sosadd,
warnTime: time,
warnName: ""
});
}
if (receiveData.sta_LedType === 'led_alarm' || receiveData.ins_LedType === 'led_alarm') { //强制报警
console.error("强制报警了", f);
warnArrs.push({
linkId: f.linkId,
read: false,
key: guid,
warnType: "强制报警",
warnMac: f.macAddress,
warnTime: time,
warnName: ""
});
}
if (warnArrs.length > 0) {
uni.getStorageInfo({
success: function(res) {
let arr = [];
if (res.keys.includes(warnKey)) {
arr = uni.getStorageSync(warnKey);
arr = warnArrs.concat(arr);
} else {
arr = warnArrs
}
uni.setStorage({
key: warnKey,
data: arr
});
}
});
}
}
} catch (error) {
receiveData = {};
console.log("文本解析失败", error)