650完成,670完成部分
This commit is contained in:
@ -55,7 +55,10 @@ class BleReceive {
|
||||
console.log("该设备是650");
|
||||
return this.Receive_650(receive,f,path);
|
||||
}
|
||||
|
||||
if(f.detailPageUrl=='/pages/670/HBY670'){
|
||||
console.log("该设备是670");
|
||||
return this.Receive_670(receive,f,path);
|
||||
}
|
||||
|
||||
}
|
||||
console.log("已收到该消息,但无法处理",f);
|
||||
@ -63,7 +66,7 @@ class BleReceive {
|
||||
}
|
||||
|
||||
Receive_650(receive,f,path) {
|
||||
console.log("通用程序正在处理650的数据");
|
||||
console.log("通用程序正在处理650的数据",receive);
|
||||
|
||||
var parseData = () => {
|
||||
let bytes = receive.bytes;
|
||||
@ -74,6 +77,7 @@ class BleReceive {
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
let modeCurr = "";
|
||||
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
@ -190,6 +194,46 @@ class BleReceive {
|
||||
this.setBleFormData(formData,f);
|
||||
return formData;
|
||||
}
|
||||
else{
|
||||
let receiveData={a:1};
|
||||
try {
|
||||
let json=JSON.parse(str);
|
||||
|
||||
if("staBlue_picture" in json){
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData=json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
receiveData={};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData={};
|
||||
console.log("文本解析失败")
|
||||
}
|
||||
return receiveData;
|
||||
}
|
||||
return null;
|
||||
} catch (ex) {
|
||||
return null;
|
||||
@ -199,11 +243,149 @@ class BleReceive {
|
||||
}
|
||||
|
||||
let data=parseData();
|
||||
|
||||
console.log("data=",data);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
Receive_670(receive,f,path){
|
||||
|
||||
var todo = (bytes) =>{
|
||||
|
||||
let receiveData = {};
|
||||
if (bytes[0] == 0x55) {
|
||||
try {
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
break
|
||||
case 0x66:
|
||||
staticLevelText = '中档';
|
||||
break
|
||||
case 0x67:
|
||||
staticLevelText = '低档';
|
||||
break
|
||||
case 0x68:
|
||||
staticLevelText = '关闭';
|
||||
break
|
||||
}
|
||||
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? '强光': lightingLevelByte === 0x6e ? '弱光': '关闭';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
||||
|
||||
// 解析剩余电量 // 电量百分比范围检查
|
||||
let batteryLevelByte = bytes[5];
|
||||
|
||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
||||
|
||||
let warn = bytes[6];
|
||||
if (warn == 0x00) {
|
||||
warn = '无预警';
|
||||
} else if (warn == 0x01) {
|
||||
warn = '弱预警';
|
||||
} else if (warn == 0x02) {
|
||||
warn = '中预警';
|
||||
} else if (warn == 0x03) {
|
||||
warn = '强预警';
|
||||
} else if (warn == 0x04) {
|
||||
warn = '非常强预警';
|
||||
}
|
||||
|
||||
let staticWarn = bytes[7] == 0x01 ? '静止报警': '无静止报警';
|
||||
let fourGStrenth = bytes[8]; //4g信号强度
|
||||
let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? '爆闪模式' : '红蓝模式';
|
||||
|
||||
receiveData.staticLevel = staticLevelText;
|
||||
receiveData.lightingLevel = lightingLevelText;
|
||||
receiveData.lightingTime = lightingTime ;
|
||||
receiveData.batteryLevel = batteryLevel;
|
||||
receiveData.warnLevel = warn;
|
||||
receiveData.staticWarn = staticWarn;
|
||||
receiveData.fourGStrenth = fourGStrenth;
|
||||
receiveData.SOS=sosTxt;
|
||||
} catch(error) {
|
||||
console.log('数据解析错误:', error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
if (str.indexOf('mac address:') == 0) {
|
||||
receiveData.macAddress = str.split(':').slice(1).join(":");
|
||||
console.log('收到mac地址:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('imei:') == 0) {
|
||||
receiveData.IMEI = str.split(':')[1];
|
||||
console.log('收到IEMI:', +this.receiveData.macAddress);
|
||||
|
||||
} else if (str.indexOf('longitude:') == 0) {
|
||||
receiveData.Lon = str.split(':')[1];
|
||||
console.log('收到经度:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('latitude:') == 0) {
|
||||
receiveData.Lat = str.split(':')[1];
|
||||
console.log('收到纬度:', +this.receiveData.macAddress);
|
||||
} else {
|
||||
try {
|
||||
let json=JSON.parse(str);
|
||||
if("staBlue_picture" in json){
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData=json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
receiveData={};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData={};
|
||||
console.log("文本解析失败")
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
receiveData={};
|
||||
console.log('将数据转文本失败', ex);
|
||||
}
|
||||
}
|
||||
|
||||
this.setBleFormData(receiveData,f);
|
||||
return receiveData;
|
||||
}
|
||||
|
||||
|
||||
let data=todo();
|
||||
|
||||
return data;
|
||||
}
|
||||
Receive_6155() {
|
||||
console.log("通用程序正在处理6155的数据");
|
||||
}
|
||||
|
Reference in New Issue
Block a user