添加全局蓝牙监听
This commit is contained in:
@ -311,6 +311,7 @@
|
|||||||
methods: {
|
methods: {
|
||||||
getDevice: function() {
|
getDevice: function() {
|
||||||
console.log("LinkedList=", ble.data.LinkedList);
|
console.log("LinkedList=", ble.data.LinkedList);
|
||||||
|
console.log("formData=", these.formData);
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
return v.deviceId == these.formData.deviceId;
|
return v.deviceId == these.formData.deviceId;
|
||||||
});
|
});
|
||||||
|
@ -167,13 +167,16 @@
|
|||||||
<script>
|
<script>
|
||||||
import gbk from '@/utils/gbk.js'
|
import gbk from '@/utils/gbk.js'
|
||||||
import BleTool from '@/utils/BleHelper.js'
|
import BleTool from '@/utils/BleHelper.js'
|
||||||
|
import BleReceive from '@/utils/BleReceive';
|
||||||
import {
|
import {
|
||||||
showLoading,
|
showLoading,
|
||||||
hideLoading,
|
hideLoading,
|
||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js'
|
||||||
|
const pagePath = "pages/650/HBY650";
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
|
var recei = null;
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -265,10 +268,11 @@
|
|||||||
|
|
||||||
onUnload() {
|
onUnload() {
|
||||||
console.log("页面卸载,释放资源");
|
console.log("页面卸载,释放资源");
|
||||||
ble.removeReceiveCallback(this);
|
ble.removeReceiveCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
these = this;
|
these = this;
|
||||||
|
recei = BleReceive.getBleReceive();
|
||||||
ble = BleTool.getBleTool();
|
ble = BleTool.getBleTool();
|
||||||
ble.addReceiveCallback(these.bleValueNotify);
|
ble.addReceiveCallback(these.bleValueNotify);
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
@ -309,7 +313,7 @@
|
|||||||
these.formData.deviceName = device.deviceName;
|
these.formData.deviceName = device.deviceName;
|
||||||
these.formData.img = device.devicePic;
|
these.formData.img = device.devicePic;
|
||||||
these.formData.id = device.id;
|
these.formData.id = device.id;
|
||||||
these.formData.deviceId=f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
|
|
||||||
@ -322,7 +326,7 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onBackPress(e) {
|
||||||
ble.removeReceiveCallback();
|
ble.removeReceiveCallback(pagePath);
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
RSSIRemark: function() {
|
RSSIRemark: function() {
|
||||||
@ -372,123 +376,44 @@
|
|||||||
|
|
||||||
return className;
|
return className;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(receive) { //订阅消息
|
bleValueNotify: function(receive, device, path) { //订阅消息
|
||||||
console.log("收到订阅消息", receive);
|
|
||||||
var parseData = () => {
|
let data = recei.ReceiveData(receive, device, pagePath);
|
||||||
let bytes = receive.bytes;
|
|
||||||
if (bytes[0] == 0x55) {
|
if (data) {
|
||||||
try {
|
console.log("收到订阅消息", receive);
|
||||||
let staticLevelByte = bytes[1];
|
let keys = Object.keys(data);
|
||||||
let staticLevelText = '未知';
|
for (var i = 0; i < keys.length; i++) {
|
||||||
let modeCurr = "";
|
let key = keys[i];
|
||||||
switch (staticLevelByte) {
|
these.formData[key] = data[key];
|
||||||
case 0x65:
|
|
||||||
staticLevelText = '高档';
|
|
||||||
modeCurr = "hight";
|
|
||||||
break;
|
|
||||||
case 0x66:
|
|
||||||
staticLevelText = '中档';
|
|
||||||
modeCurr = "center";
|
|
||||||
break;
|
|
||||||
case 0x67:
|
|
||||||
staticLevelText = '低档';
|
|
||||||
modeCurr = "low";
|
|
||||||
break;
|
|
||||||
case 0x68:
|
|
||||||
staticLevelText = '关闭';
|
|
||||||
modeCurr = "close";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析照明档位
|
|
||||||
let lightingLevelByte = bytes[2];
|
|
||||||
let lightingLevelText = lightingLevelByte === 0x6e ? '开启' : '关闭';
|
|
||||||
|
|
||||||
|
|
||||||
// 解析剩余照明时间(第三和第四字节,大端序)
|
|
||||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
|
||||||
let hours = Math.floor(lightingTime / 60);
|
|
||||||
let remainingMinutes = lightingTime % 60;
|
|
||||||
let xuhang = '0分';
|
|
||||||
// 处理不同情况的显示
|
|
||||||
if (hours === 0) {
|
|
||||||
xuhang = `${remainingMinutes}分`;
|
|
||||||
} else if (remainingMinutes === 0) {
|
|
||||||
xuhang = `${hours}小时`;
|
|
||||||
} else {
|
|
||||||
xuhang = `${hours}小时${remainingMinutes}分`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析剩余电量
|
|
||||||
let batteryLevelByte = bytes[5];
|
|
||||||
// 电量百分比范围检查
|
|
||||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
|
||||||
let iswarn = false;
|
|
||||||
let warn = bytes[6];
|
|
||||||
if (warn == 0x00) {
|
|
||||||
warn = '无预警';
|
|
||||||
} else if (warn == 0x01) {
|
|
||||||
warn = '弱预警';
|
|
||||||
} else if (warn == 0x02) {
|
|
||||||
iswarn = true;
|
|
||||||
warn = '中预警';
|
|
||||||
} else if (warn == 0x03) {
|
|
||||||
iswarn = true;
|
|
||||||
warn = '强预警';
|
|
||||||
} else if (warn == 0x04) {
|
|
||||||
iswarn = true;
|
|
||||||
warn = '非常强预警';
|
|
||||||
}
|
|
||||||
|
|
||||||
these.formData.battary = batteryLevel;
|
|
||||||
these.formData.xuhang = xuhang;
|
|
||||||
these.formData.cMode = lightingLevelByte === 0x6e;
|
|
||||||
these.formData.modeCurr = modeCurr;
|
|
||||||
these.formData.warnLevel = warn;
|
|
||||||
these.formData.iswarn = iswarn;
|
|
||||||
these.setBleFormData();
|
|
||||||
if (iswarn) {
|
|
||||||
these.showPop({
|
|
||||||
message: "环境存在漏电电源",
|
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
|
|
||||||
borderColor: "#e034344d",
|
|
||||||
buttonBgColor: "#E03434",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('数据解析错误:', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (receive.str) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
let str = receive.str;
|
if (these.formData.iswarn) {
|
||||||
|
these.showPop({
|
||||||
if (str.indexOf('mac address:') == 0) {
|
message: "环境存在漏电电源",
|
||||||
these.formData.macAddress = str.split(':')[1];
|
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
|
||||||
console.log("收到mac地址:", )
|
borderColor: "#e034344d",
|
||||||
} else {
|
buttonBgColor: "#E03434",
|
||||||
console.log("收到无法解析的字符串:", str)
|
});
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("将数据转文本失败", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
these.setBleFormData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// // 转换为字节数组
|
||||||
// 转换为字节数组
|
// const bytes = receive.bytes;
|
||||||
const bytes = receive.bytes;
|
// parseData(bytes);
|
||||||
parseData(bytes);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
getDevice: function() {
|
getDevice: function() {
|
||||||
|
|
||||||
console.log("LinkedList=",ble.data.LinkedList);
|
console.log("LinkedList=", ble.data.LinkedList);
|
||||||
console.log("formData=",these.formData);
|
console.log("formData=", these.formData);
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
return v.deviceId == these.formData.deviceId;
|
return v.deviceId == these.formData.deviceId;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user