|
发表于 2020-8-2 09:53:10
|
显示全部楼层
我之前刷的一个用的是下面来解析门锁的,因为不稳定,就换成这个。做了逆序调整然后解析也对照不起来。
let mac = msg.payload.dev.mac;
let eid = msg.payload.evt[0].eid;
let edata = msg.payload.evt[0].edata;
let state, method, action, key_id, arert, bolt_state, battery;
let edata1, edata2, edata3;
let time = new Date().Format("yyyy年MM月dd日hh:mm:ss")
msg = {
payload: {}
}
if (eid === 7 || eid === 11 || eid === 4106 || eid === 4110) {
if (eid === 7) {
edata = edata.substring(0, 2);
state = parseInt(edata, 16);
switch (state) {
case 0:
state = "开门";
break;
case 1:
state = "关门";
break;
case 2:
state = "超时未关门";
break;
case 3:
state = "敲门";
break;
case 4:
state = "撬门";
break;
case 5:
state = "门卡住";
break;
}
msg.payload.state = state;
msg.payload.time = time;
msg.topic = "bt/" + mac + "/state"
return msg;
}
if (eid === 11) {
edata1 = edata.substring(0, 1);
edata2 = edata.substring(1, 2);
edata3 = edata.substring(2, 10);
method = parseInt(edata1, 16);
action = parseInt(edata2, 16);
switch (method) {
case 0:
method = "蓝牙";
break;
case 1:
method = "密码";
break;
case 2:
method = "指纹";
break;
case 3:
method = "应急钥匙";
break;
case 4:
method = "转盘方式";
break;
case 5:
method = "NFC";
break;
case 6:
method = "一次性密码";
break;
case 7:
method = "双重验证";
break;
case 10:
method = "人工";
break;
case 11:
method = "自动";
break;
case 15:
method = "异常";
break;
}
switch (action) {
case 0:
action = "开门";
break;
case 1:
action = "上提把手锁门";
break;
case 2:
action = "反锁";
break;
case 3:
action = "解除反锁";
break;
case 4:
action = "室内开门";
break;
case 5:
action = "门内上锁";
break;
case 6:
action = "开启童锁";
break;
case 7:
action = "关闭童锁";
break;
case 15:
action = "异常";
break;
}
if (
edata3.substring(2, 8) === "00dec0" ||
edata3.substring(2, 8) === "10dec0"
) {
edata4 = edata3.substring(1, 2);
arert = parseInt(edata4, 16);
if (edata3.substring(2, 8) === "00dec0") {
switch (arert) {
case 0:
arert = "密码多次验证失败";
break;
case 1:
arert = "指纹多次验证失败";
break;
case 2:
arert = "密码输入超时";
break;
case 3:
arert = "撬锁";
break;
case 4:
arert = "重置按键按下";
break;
case 5:
arert = "有人撬锁或钥匙未拔"; /////钥匙频繁开锁
break;
case 6:
arert = "钥匙孔异物";
break;
case 7:
arert = "钥匙未取出";
break;
case 8:
arert = "NFC设备多次验证失败";
break;
case 9:
arert = "超时未按要求上锁";
break;
}
} else {
switch (arert) {
case 0:
arert = "电量低于10%";
break;
case 1:
arert = "电量低于5%";
break;
case 2:
arert = "指纹传感器异常";
break;
}
}
msg.payload.arert = arert;
msg.payload.time = time;
} else {
key_id = edata3;
///////00000000管理员密码;0a000(1/2)80:0a为第几个密码(指纹+密码),180为指纹,280为密码;00000280一次性密码
msg.payload.event = method + action;
msg.payload.time = time;
if (key_id !== "ffffffff") {
switch (key_id) {
case "00000000":
key = "我";
break;
case "08000180":
key = "我的右手拇指";
break;
case "03000180":
key = "我的左手拇指";
break;
case "01000280":
key = "我的管理员密码";
break;
case "0400280":
key = "客人";
break;
default:
key = key_id;
break;
}
}
msg.payload.key = key;
}
msg.topic = "bt/" + mac + "/event"
return msg;
}
if (eid === 4106) {
edata = edata.substring(0, 2);
battery = parseInt(edata, 16);
msg.payload.battery = battery;
msg.topic = "bt/" + mac + "/battery"
return msg;
}
if (eid === 4110) {
bolt_state = parseInt(edata, 16);
switch (bolt_state) {
case 0:
bolt_state = "所有锁舌收回";
break;
case 4:
bolt_state = "斜舌弹出";
break;
case 5:
bolt_state = "方舌/斜舌弹出";
break;
case 6:
bolt_state = "呆舌/斜舌弹出";
break;
case 7:
bolt_state = "所有锁舌弹出";
break;
}
msg.payload.bolt = bolt_state;
msg.topic = "bt/" + mac + "/bolt"
return msg;
}
} |
|