function getSn(payload, start, end) {
var sn = "";
for (i = start; i <= end; i++) {
if(payload[i]<16){
sn += "0"+payload[i].toString(16);
}else{
sn += payload[i].toString(16);
}
}
return sn.toUpperCase();
}
function getCmdId(payload, start, end) {
var sn = "";
for (i = start; i <= end; i++) {
sn += payload[i].toString();
}
return sn.toUpperCase();
}
var result = {};
console.log(payload);
if (!payload instanceof Array) {
console.log("payload is not array, return");
return result;
}
if(payload[0]!=161){
return result;
}
if (payload.length < 12) {
console.log("payload array length lower than 12");
return result;
}
while(true){
if(payload[5]==17){
break;
}
var len=payload[4]*256+payload[3];
if(payload.length<=len){
break;
}
payload=payload.slice(len)
}
var cmdId = getCmdId(payload, 0, 5);
console.log("authCmdId="+cmdId);
if (cmdId == "16116216326017") {
result.auth = true;
result.sn = "SCBB" + getSn(payload, 16, 21);
result.category = "SCBB";
} else if (cmdId == "16116216331018") {
result.auth = true;
result.sn = "SCBB" + getSn(payload, 6, 11);
result.category = "SCBB";
}
return result;
console