完成102添加联机日志,报警日志
This commit is contained in:
@ -780,7 +780,6 @@ class BleHelper {
|
||||
|
||||
if (this.cfg.receivDataCallback.length > 0) {
|
||||
|
||||
let path = this.getCurrentPagePath();
|
||||
// console.log("有人订阅消息")
|
||||
this.cfg.receivDataCallback.forEach((
|
||||
rec) => {
|
||||
@ -789,7 +788,7 @@ class BleHelper {
|
||||
try {
|
||||
// console.log("正在处理订阅消息",rec);
|
||||
rec.callback(recData, f,
|
||||
path, this.cfg
|
||||
rec.key, this.cfg
|
||||
.receivDataCallback
|
||||
);
|
||||
// console.log("处理订阅消息完毕");
|
||||
@ -1601,12 +1600,23 @@ class BleHelper {
|
||||
timeout: 30000,
|
||||
success: (info) => {
|
||||
//释放连接锁
|
||||
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
console.log("新连接成功", this.data.LinkedList);
|
||||
|
||||
// 处理 MTU 设置
|
||||
if (plus.os.name === 'Android') {
|
||||
this.setMtu(deviceId).catch(ex => {
|
||||
console.error("mtu设置失败=", ex);
|
||||
});
|
||||
}
|
||||
|
||||
this.getLinkBlue().then((arr) => {
|
||||
let linkId=new Date().getTime();//本次连接的id
|
||||
let cr = arr.devices.find(c => {
|
||||
if (c.deviceId == deviceId) {
|
||||
c.Linked = true;
|
||||
c.linkId=linkId
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -1614,6 +1624,7 @@ class BleHelper {
|
||||
|
||||
if (fIndex > -1) {
|
||||
this.data.LinkedList[fIndex].Linked = true;
|
||||
this.data.LinkedList[fIndex].linkId=linkId;
|
||||
} else {
|
||||
this.data.LinkedList.push(cr);
|
||||
}
|
||||
@ -1647,12 +1658,7 @@ class BleHelper {
|
||||
});
|
||||
}
|
||||
|
||||
// 处理 MTU 设置
|
||||
if (plus.os.name === 'Android') {
|
||||
this.setMtu(deviceId).catch(ex => {
|
||||
console.error("mtu设置失败=", ex);
|
||||
});
|
||||
}
|
||||
|
||||
resolve(true);
|
||||
|
||||
}).catch((ex) => {
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -218,7 +218,7 @@ export default {
|
||||
value: "1",
|
||||
label: "灯光模式",
|
||||
checked: false,
|
||||
type: ['6170', '670']
|
||||
type: ['6170', '670','102']
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
@ -282,7 +282,7 @@ export default {
|
||||
value: "46",
|
||||
label: "手动报警",
|
||||
checked: false,
|
||||
type: ['210']
|
||||
type: ['210','102']
|
||||
},
|
||||
{
|
||||
value: "47",
|
||||
@ -290,6 +290,18 @@ export default {
|
||||
checked: false,
|
||||
type: ['210']
|
||||
},
|
||||
{
|
||||
value: "48",
|
||||
label: "物体感应",
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
{
|
||||
value: "49",
|
||||
label: "联机模式",
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
]
|
||||
|
||||
let arr = [];
|
||||
|
||||
Reference in New Issue
Block a user