650添加应答,app图标添加
This commit is contained in:
@ -449,7 +449,7 @@
|
||||
console.log("设置mtu失败" + JSON.stringify(ex));
|
||||
},
|
||||
complete() {
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
@ -698,101 +698,224 @@
|
||||
uni.onBLECharacteristicValueChange((
|
||||
receive) => {
|
||||
|
||||
var bytesToHexString =function(bytes) {
|
||||
var bytesToHexString =
|
||||
function(bytes) {
|
||||
return bytes.map(
|
||||
byte =>byte.toString(16).padStart(2, '0')
|
||||
byte =>
|
||||
byte
|
||||
.toString(
|
||||
16)
|
||||
.padStart(
|
||||
2, '0')
|
||||
).join(' ')
|
||||
}
|
||||
|
||||
|
||||
var parseData = (bytes) => {
|
||||
if (bytes.length <7) {
|
||||
console.log('数据包长度不足,至少需要6个字节');
|
||||
var parseData = (
|
||||
bytes) => {
|
||||
if (bytes.length <
|
||||
7) {
|
||||
console.log(
|
||||
'数据包长度不足,至少需要6个字节'
|
||||
);
|
||||
return;
|
||||
}
|
||||
let date = new Date();
|
||||
this.receiveData.date =date.getHours() +":" + date.getMinutes() +":" + date.getSeconds();
|
||||
if(bytes[0]==0x55){
|
||||
let date =
|
||||
new Date();
|
||||
this.receiveData
|
||||
.date = date
|
||||
.getHours() +
|
||||
":" + date
|
||||
.getMinutes() +
|
||||
":" + date
|
||||
.getSeconds();
|
||||
if (bytes[0] ==
|
||||
0x55) {
|
||||
try {
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
switch ( staticLevelByte ) {
|
||||
let staticLevelByte =
|
||||
bytes[
|
||||
1];
|
||||
let staticLevelText =
|
||||
'未知';
|
||||
switch (
|
||||
staticLevelByte
|
||||
) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
staticLevelText
|
||||
=
|
||||
'高档';
|
||||
break;
|
||||
case 0x66:
|
||||
staticLevelText = '中档';
|
||||
staticLevelText
|
||||
=
|
||||
'中档';
|
||||
break;
|
||||
case 0x67:
|
||||
staticLevelText = '低档';
|
||||
staticLevelText
|
||||
=
|
||||
'低档';
|
||||
break;
|
||||
case 0x68:
|
||||
staticLevelText = '关闭';
|
||||
staticLevelText
|
||||
=
|
||||
'关闭';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6e ? '开启':'关闭';
|
||||
|
||||
let lightingLevelByte =
|
||||
bytes[
|
||||
2];
|
||||
let lightingLevelText =
|
||||
lightingLevelByte ===
|
||||
0x6e ?
|
||||
'开启' :
|
||||
'关闭';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime =(bytes[3] <<8) | bytes[4];
|
||||
|
||||
let lightingTime =
|
||||
(bytes[
|
||||
3] <<
|
||||
8
|
||||
) |
|
||||
bytes[
|
||||
4];
|
||||
|
||||
// 解析剩余电量
|
||||
let batteryLevelByte = bytes[5];
|
||||
let batteryLevelByte =
|
||||
bytes[
|
||||
5];
|
||||
// 电量百分比范围检查
|
||||
let batteryLevel = Math.max(0,Math.min(100, batteryLevelByte));
|
||||
|
||||
let warn=bytes[6];
|
||||
if(warn==0x00){
|
||||
warn='无预警';
|
||||
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 =
|
||||
'非常强预警';
|
||||
}
|
||||
else if(warn==0x01){
|
||||
warn='弱预警';
|
||||
}
|
||||
else if(warn==0x02){
|
||||
warn='中预警';
|
||||
}
|
||||
else if(warn==0x03){
|
||||
warn='强预警';
|
||||
}
|
||||
else if(warn==0x04){
|
||||
warn='非常强预警';
|
||||
}
|
||||
console.log(warn)
|
||||
console.log('解析结果:', {
|
||||
staticLevel: staticLevelText,
|
||||
lightingLevel: lightingLevelText,
|
||||
lightingTime: `${lightingTime} 分钟`,
|
||||
batteryLevel: `${batteryLevel}%`
|
||||
});
|
||||
|
||||
this.receiveData.staticLevel =staticLevelText;
|
||||
this.receiveData.lightingLevel =lightingLevelText;
|
||||
this.receiveData.lightingTime =lightingTime +'分钟';
|
||||
this.receiveData.batteryLevel =batteryLevel +'%';
|
||||
this.receiveData.warnLevel=warn;
|
||||
} catch (error) {
|
||||
console.log('数据解析错误:',error);
|
||||
console
|
||||
.log(
|
||||
warn
|
||||
)
|
||||
console
|
||||
.log(
|
||||
'解析结果:', {
|
||||
staticLevel: staticLevelText,
|
||||
lightingLevel: lightingLevelText,
|
||||
lightingTime: `${lightingTime} 分钟`,
|
||||
batteryLevel: `${batteryLevel}%`
|
||||
});
|
||||
|
||||
this.receiveData
|
||||
.staticLevel =
|
||||
staticLevelText;
|
||||
this.receiveData
|
||||
.lightingLevel =
|
||||
lightingLevelText;
|
||||
this.receiveData
|
||||
.lightingTime =
|
||||
lightingTime +
|
||||
'分钟';
|
||||
this.receiveData
|
||||
.batteryLevel =
|
||||
batteryLevel +
|
||||
'%';
|
||||
this.receiveData
|
||||
.warnLevel =
|
||||
warn;
|
||||
} catch (
|
||||
error) {
|
||||
console
|
||||
.log(
|
||||
'数据解析错误:',
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
else{
|
||||
try{
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
} else {
|
||||
try {
|
||||
let uint8Array =
|
||||
new Uint8Array(
|
||||
receive
|
||||
.value
|
||||
);
|
||||
let str =
|
||||
'';
|
||||
for (let i =
|
||||
0; i <
|
||||
uint8Array
|
||||
.length; i++
|
||||
) {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
str +=
|
||||
String
|
||||
.fromCharCode(
|
||||
uint8Array[
|
||||
i
|
||||
]
|
||||
);
|
||||
}
|
||||
if(str.indexOf('mac address:')==0){
|
||||
this.receiveData.macAddress=str.split(':')[1];
|
||||
console.log("收到mac地址:",)
|
||||
}else{
|
||||
console.log("收到无法解析的字符串:",str)
|
||||
}
|
||||
}catch(ex){
|
||||
console.log("将数据转文本失败",ex);
|
||||
if (str
|
||||
.indexOf(
|
||||
'mac address:'
|
||||
) ==
|
||||
0) {
|
||||
this.receiveData
|
||||
.macAddress =
|
||||
str
|
||||
.split(
|
||||
':'
|
||||
)[
|
||||
1
|
||||
];
|
||||
console
|
||||
.log(
|
||||
"收到mac地址:",
|
||||
)
|
||||
} else {
|
||||
console
|
||||
.log(
|
||||
"收到无法解析的字符串:",
|
||||
str
|
||||
)
|
||||
}
|
||||
} catch (ex) {
|
||||
console
|
||||
.log(
|
||||
"将数据转文本失败",
|
||||
ex
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1885,15 +2008,18 @@
|
||||
.txt {
|
||||
border: 1px solid #000000;
|
||||
}
|
||||
.w50{
|
||||
|
||||
.w50 {
|
||||
width: 50%;
|
||||
color: #656363;
|
||||
font-size: 26prx;
|
||||
}
|
||||
.fleft{
|
||||
|
||||
.fleft {
|
||||
float: left;
|
||||
}
|
||||
.clear{
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user