670完成
This commit is contained in:
@ -335,6 +335,8 @@ class BleHelper {
|
||||
}
|
||||
uni.getBluetoothAdapterState({
|
||||
success: (info) => {
|
||||
this.data.available=info.available;
|
||||
this.data.discovering=info.discovering;
|
||||
resolve(info);
|
||||
},
|
||||
fail: (ex1) => {
|
||||
@ -358,6 +360,7 @@ class BleHelper {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
uni.openBluetoothAdapter({
|
||||
success: (args) => {
|
||||
console.log("蓝牙初始化成功:" + JSON.stringify(args));
|
||||
|
@ -45,21 +45,23 @@ class BleReceive {
|
||||
|
||||
|
||||
ReceiveData(receive,f,path) {
|
||||
if(f && f.macAddress && f.id){
|
||||
if(f && f.macAddress && f.id){
|
||||
let data={};
|
||||
if(f.detailPageUrl=='/pages/6155/deviceDetail'){
|
||||
console.log("该设备是6155");
|
||||
return this.Receive_6155(receive,f,path);
|
||||
data= this.Receive_6155(receive,f,path);
|
||||
}
|
||||
|
||||
if(f.detailPageUrl=='/pages/650/HBY650'){
|
||||
console.log("该设备是650");
|
||||
return this.Receive_650(receive,f,path);
|
||||
data= this.Receive_650(receive,f,path);
|
||||
}
|
||||
if(f.detailPageUrl=='/pages/670/HBY670'){
|
||||
console.log("该设备是670");
|
||||
return this.Receive_670(receive,f,path);
|
||||
data= this.Receive_670(receive,f,path);
|
||||
}
|
||||
|
||||
console.log("收到数据并处理完毕,",data);
|
||||
return data;
|
||||
}
|
||||
console.log("已收到该消息,但无法处理",f);
|
||||
|
||||
@ -242,7 +244,7 @@ class BleReceive {
|
||||
|
||||
}
|
||||
|
||||
let data=parseData();
|
||||
let data=parseData(receive.bytes);
|
||||
console.log("data=",data);
|
||||
return data;
|
||||
|
||||
@ -251,10 +253,11 @@ class BleReceive {
|
||||
Receive_670(receive,f,path){
|
||||
|
||||
var todo = (bytes) =>{
|
||||
|
||||
console.log("todo");
|
||||
let receiveData = {};
|
||||
if (bytes[0] == 0x55) {
|
||||
try {
|
||||
console.log("todo");
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '';
|
||||
@ -272,7 +275,7 @@ class BleReceive {
|
||||
staticLevelText = 'close';
|
||||
break
|
||||
}
|
||||
|
||||
console.log("todo");
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close';
|
||||
@ -284,24 +287,24 @@ class BleReceive {
|
||||
let batteryLevelByte = bytes[5];
|
||||
|
||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
||||
|
||||
console.log("todo");
|
||||
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 = '非常强预警';
|
||||
// }
|
||||
if (warn == 0x00) {
|
||||
warn = 'none';
|
||||
} else if (warn == 0x01) {
|
||||
warn = 'ruo';
|
||||
} else if (warn == 0x02) {
|
||||
warn = 'center';
|
||||
} else if (warn == 0x03) {
|
||||
warn = 'hight';
|
||||
} else if (warn == 0x04) {
|
||||
warn = 'veryhight';
|
||||
}
|
||||
|
||||
let staticWarn = bytes[7] == 0x01;//静止报警
|
||||
let fourGStrenth = bytes[8]; //4g信号强度
|
||||
let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? 'sg' : 'rb';
|
||||
|
||||
let sosTxt = bytes[9] == 0x00 ? 'close' : bytes[9] == 0x01 ? 'sg' : 'rb';
|
||||
console.log("todo");
|
||||
receiveData.modeCurr = staticLevelText;
|
||||
receiveData.lightCurr = lightingLevelText;
|
||||
receiveData.xuhang = lightingTime ;
|
||||
@ -313,6 +316,7 @@ class BleReceive {
|
||||
} catch(error) {
|
||||
console.log('数据解析错误:', error);
|
||||
}
|
||||
console.log("todo");
|
||||
} else {
|
||||
try {
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
@ -325,7 +329,7 @@ class BleReceive {
|
||||
receiveData.macAddress = str.split(':').slice(1).join(":");
|
||||
console.log('收到mac地址:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('imei:') == 0) {
|
||||
receiveData.IMEI = str.split(':')[1];
|
||||
receiveData.imei = str.split(':')[1];
|
||||
console.log('收到IEMI:', +this.receiveData.macAddress);
|
||||
|
||||
} else if (str.indexOf('longitude:') == 0) {
|
||||
@ -376,13 +380,13 @@ class BleReceive {
|
||||
console.log('将数据转文本失败', ex);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("todo",receiveData);
|
||||
this.setBleFormData(receiveData,f);
|
||||
return receiveData;
|
||||
}
|
||||
|
||||
|
||||
let data=todo();
|
||||
let data=todo(receive.bytes);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class MqttClient {
|
||||
this.client.onMessageArrived = (message) => {
|
||||
const topic = message.destinationName;
|
||||
const payload = message.payloadString;
|
||||
console.log(`收到消息, 主题: ${topic}, 内容: ${payload}`);
|
||||
// console.log(`收到消息, 主题: ${topic}, 内容: ${payload}`);
|
||||
const potentialJsons = payload.replace(/}\s*{/g, '}|{').split('|');
|
||||
potentialJsons.forEach(jsonString => {
|
||||
if (jsonString.trim() === '') return;
|
||||
|
@ -28,9 +28,11 @@ const request = (options) => {
|
||||
header: options.header || {},
|
||||
timeout: 30000,
|
||||
success: (res) => {
|
||||
console.log("请求成功",res);
|
||||
resolve(res.data);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("请求失败",err);
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user