Compare commits
4 Commits
76329756c9
...
793fe7132b
Author | SHA1 | Date | |
---|---|---|---|
793fe7132b | |||
585bd76a0a | |||
96acaa5d94 | |||
5e5bde6934 |
@ -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;
|
||||||
});
|
});
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
<image src="/static/images/BLEAdd/addBleDevice.png" class="titleIco" mode="aspectFit">
|
<image src="/static/images/BLEAdd/addBleDevice.png" class="titleIco" mode="aspectFit">
|
||||||
</image>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="deviceName">
|
||||||
|
蓝牙名:{{device.name}}
|
||||||
|
</view>
|
||||||
<view class="deviceName">
|
<view class="deviceName">
|
||||||
设备名:{{device.deviceName}}
|
设备名:{{device.deviceName}}
|
||||||
</view>
|
</view>
|
||||||
@ -19,21 +22,24 @@
|
|||||||
连接
|
连接
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<global-loading ref="loading" />
|
<global-loading ref="loading" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import request from '@/utils/request.js';
|
import request from '@/utils/request.js';
|
||||||
import bleTool from '@/utils/BleHelper.js'
|
import bleTool from '@/utils/BleHelper.js';
|
||||||
import {
|
import {
|
||||||
showLoading,
|
showLoading,
|
||||||
hideLoading,
|
hideLoading,
|
||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js';
|
||||||
|
|
||||||
|
const pagePath="pages/common/addBLE/LinkBle";
|
||||||
|
|
||||||
var these = null;
|
var these = null;
|
||||||
var eventChannel = null;
|
var eventChannel = null;
|
||||||
var ble=null;
|
var ble = null;
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -66,57 +72,113 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onBackPress() {
|
||||||
|
console.log("返回时断开蓝牙连接,取消订阅");
|
||||||
|
ble.disconnectDevice(these.device.deviceId);
|
||||||
|
ble.removeReceiveCallback(pagePath);
|
||||||
|
},
|
||||||
|
onUnload() {
|
||||||
|
ble.removeReceiveCallback(pagePath);
|
||||||
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
these = this;
|
these = this;
|
||||||
ble=bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
|
ble.addReceiveCallback((receive,f,path) => {
|
||||||
|
console.log("收到设备消息,", receive);
|
||||||
|
if (these.device.deviceId == receive.deviceId) {
|
||||||
|
console.log("11111");
|
||||||
|
|
||||||
|
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
||||||
|
if (f && f.macAddress) {
|
||||||
|
these.device.macAddress = f.macAddress;
|
||||||
|
console.log("222222");
|
||||||
|
these.initDevice();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},pagePath);
|
||||||
eventChannel = this.getOpenerEventChannel();
|
eventChannel = this.getOpenerEventChannel();
|
||||||
eventChannel.on('LinkItem', function(data) {
|
eventChannel.on('LinkItem', function(data) {
|
||||||
let f=ble.data.LinkedList.find((v)=>{
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
return v.deviceId=data.deviceId;
|
return v.deviceId = data.deviceId;
|
||||||
});
|
});
|
||||||
if(f){
|
if (f) {
|
||||||
these.device = f;
|
these.device = Object.assign({}, these.device, f);
|
||||||
console.log("获取到设备",f);
|
console.log("获取到设备", f);
|
||||||
these.initDevice();
|
|
||||||
}else{
|
} else {
|
||||||
console.log("未获取到设备");
|
console.log("未获取到设备");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
initDevice: function() {
|
initDevice: function() {
|
||||||
|
showLoading(these, {
|
||||||
|
text: '正在获取设备信息'
|
||||||
|
});
|
||||||
request({
|
request({
|
||||||
url: 'app/device/getDeviceInfoByDeviceMac',
|
url: '/app/device/getDeviceInfoByDeviceMac',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
data: {
|
data: {
|
||||||
deviceMac: these.device.macAddress
|
deviceMac: these.device.macAddress
|
||||||
}
|
}
|
||||||
}).then(res=>{
|
}).then(res => {
|
||||||
console.log("获取设备信息",res);
|
console.log("获取设备信息", res);
|
||||||
}).catch((ex)=>{
|
if (res && res.code == 200) {
|
||||||
console.log("获取设备出现异常:",ex);
|
let data = res.data;
|
||||||
|
if (data) {
|
||||||
|
let keys = Object.keys(data);
|
||||||
|
ble.data.LinkedList.find((v) => {
|
||||||
|
if(v.deviceId = these.device.deviceId){
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
let key = keys[i];
|
||||||
|
v[key] = data[key];
|
||||||
|
console.log("key="+key);
|
||||||
|
console.log("value="+data[key]);
|
||||||
|
|
||||||
|
|
||||||
|
these.$set(these.device, key, data[key]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ble.setBleData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("device=",these.device);
|
||||||
|
console.log("LinkedList=",ble.data.LinkedList);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}).catch((ex) => {
|
||||||
|
console.log("获取设备出现异常:", ex);
|
||||||
|
}).finally(() => {
|
||||||
|
hideLoading(these);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
Link() {
|
Link() {
|
||||||
// 调用绑定设备接口
|
// 调用绑定设备接口
|
||||||
|
|
||||||
let f=ble.data.LinkedList.find((v)=>{
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
return v.deviceId=these.device.deviceId;
|
return v.deviceId = these.device.deviceId;
|
||||||
});
|
});
|
||||||
if(!f){
|
if (!f) {
|
||||||
these.Statu.bound = false;
|
these.Statu.bound = false;
|
||||||
these.Statu.boundRemark = "蓝牙连接不成功";
|
these.Statu.boundRemark = "蓝牙连接不成功";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!f.macAddress){
|
if (!f.macAddress) {
|
||||||
these.Statu.bound = false;
|
these.Statu.bound = false;
|
||||||
these.Statu.boundRemark = "获取设备Mac地址异常";
|
these.Statu.boundRemark = "设备上报Mac地址异常";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
these.Statu.bound = null;
|
these.Statu.bound = null;
|
||||||
these.Statu.boundRemark = "";
|
these.Statu.boundRemark = "";
|
||||||
showLoading(these,{
|
showLoading(these, {
|
||||||
|
|
||||||
text: "连接中..."
|
text: "连接中..."
|
||||||
})
|
})
|
||||||
let promise = request({
|
let promise = request({
|
||||||
@ -130,15 +192,17 @@
|
|||||||
});
|
});
|
||||||
promise.then((res) => {
|
promise.then((res) => {
|
||||||
console.log("1111" + JSON.stringify(res));
|
console.log("1111" + JSON.stringify(res));
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
these.Statu.bound = true;
|
these.Statu.bound = true;
|
||||||
these.Statu.boundRemark = "设备绑定成功!";
|
these.Statu.boundRemark = "设备绑定成功!";
|
||||||
|
|
||||||
|
|
||||||
uni.$emit("refreshDeviceList");
|
uni.$emit("refreshDeviceList");
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
url:"/pages/common/index/index"
|
url: "/pages/common/index/index"
|
||||||
});
|
});
|
||||||
},500);
|
}, 500);
|
||||||
} else {
|
} else {
|
||||||
these.Statu.bound = false;
|
these.Statu.bound = false;
|
||||||
these.Statu.boundRemark = res.msg;
|
these.Statu.boundRemark = res.msg;
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
hideLoading,
|
hideLoading,
|
||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js'
|
||||||
|
const pagePath="pages/common/addBLE/addEquip";
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
export default {
|
export default {
|
||||||
@ -136,17 +136,23 @@
|
|||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
|
ble.removeReceiveCallback(pagePath);
|
||||||
},
|
},
|
||||||
onBackPress: (e) => {
|
onBackPress: (e) => {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
ble.removeDeviceFound();
|
ble.removeDeviceFound(pagePath);
|
||||||
ble.removeReceiveCallback();
|
ble.removeReceiveCallback(pagePath);
|
||||||
|
},
|
||||||
|
onUnload(){
|
||||||
|
ble.StopSearch();
|
||||||
|
ble.removeDeviceFound(pagePath);
|
||||||
|
ble.removeReceiveCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
these = this;
|
these = this;
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
ble.addDeviceFound((arr) => {
|
ble.addDeviceFound((arr) => {
|
||||||
console.log("发现新设备"+JSON.stringify(arr));
|
|
||||||
arr = arr.devices;
|
arr = arr.devices;
|
||||||
for (var i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
|
|
||||||
@ -164,29 +170,30 @@
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
},pagePath);
|
||||||
|
|
||||||
ble.addReceiveCallback((receivData) => {
|
|
||||||
console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
|
|
||||||
console.log("LinkedList=",ble.data.LinkedList);
|
|
||||||
let data=uni.getStorageSync(ble.StorageKey);
|
|
||||||
console.log("data=",data);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
console.log("222222");
|
|
||||||
|
|
||||||
|
this.EquipMents=[];
|
||||||
|
this.PairEquip=[];
|
||||||
ble.StartSearch().catch((ex) => {
|
ble.StartSearch().catch((ex) => {
|
||||||
if (ex.code == 10001) {
|
if (ex.code == 10001) {
|
||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ble.addReceiveCallback((receivData) => {
|
||||||
|
console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
|
||||||
|
console.log("LinkedList=",ble.data.LinkedList);
|
||||||
|
let data=uni.getStorageSync(ble.StorageKey);
|
||||||
|
console.log("data=",data);
|
||||||
|
},pagePath);
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -207,30 +214,7 @@
|
|||||||
}
|
}
|
||||||
return src;
|
return src;
|
||||||
},
|
},
|
||||||
alert: function(title, content, callback) {
|
|
||||||
if (!title) {
|
|
||||||
title = '提示'
|
|
||||||
}
|
|
||||||
if (!content) {
|
|
||||||
content = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
uni.showModal({
|
|
||||||
title: title,
|
|
||||||
content: content,
|
|
||||||
success: function(res) {
|
|
||||||
if (res.confirm) {
|
|
||||||
console.log('用户点击确定');
|
|
||||||
} else if (res.cancel) {
|
|
||||||
console.log('用户点击取消');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
showOpenSetting: function() {
|
showOpenSetting: function() {
|
||||||
this.Status.BottomMenu.show = true;
|
this.Status.BottomMenu.show = true;
|
||||||
@ -257,13 +241,15 @@
|
|||||||
|
|
||||||
these.PairEquip.push(item);
|
these.PairEquip.push(item);
|
||||||
}
|
}
|
||||||
|
ble.removeReceiveCallback(pagePath);
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:"/pages/common/addBLE/LinkBle",
|
url:"/pages/common/addBLE/LinkBle",
|
||||||
events:{
|
events:{
|
||||||
|
|
||||||
},
|
},
|
||||||
success(res) {
|
success(res) {
|
||||||
res.eventChannel.emit('LinkItem', item)
|
|
||||||
|
res.eventChannel.emit('LinkItem', item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import receivTool from "@/utils/BleReceive.js"
|
||||||
|
var recei = null;
|
||||||
class BleHelper {
|
class BleHelper {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.StorageKey = "linkedDevices";
|
this.StorageKey = "linkedDevices";
|
||||||
|
recei = receivTool.getBleReceive();
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
@ -37,7 +40,9 @@ class BleHelper {
|
|||||||
onDeviceFound: [], //发现新设备的事件
|
onDeviceFound: [], //发现新设备的事件
|
||||||
receivDataCallback: [] //接收到数据的事件
|
receivDataCallback: [] //接收到数据的事件
|
||||||
}
|
}
|
||||||
|
this.addReceiveCallback((a,b,c)=>{
|
||||||
|
recei.ReceiveData(a,b,c);
|
||||||
|
}, "BleReceiveData");
|
||||||
this.dic = {
|
this.dic = {
|
||||||
errRemarks: [{
|
errRemarks: [{
|
||||||
key: '10000',
|
key: '10000',
|
||||||
@ -128,8 +133,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//设置发现新设备的回调
|
//设置发现新设备的回调
|
||||||
addDeviceFound(callback,currKey) {
|
addDeviceFound(callback, currKey) {
|
||||||
let key =currKey?currKey:this.getCurrentPagePath();
|
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = new Date().getTime();
|
key = new Date().getTime();
|
||||||
}
|
}
|
||||||
@ -151,7 +156,7 @@ class BleHelper {
|
|||||||
|
|
||||||
//移除发现新设备的回调
|
//移除发现新设备的回调
|
||||||
removeDeviceFound(currKey) {
|
removeDeviceFound(currKey) {
|
||||||
let key =currKey?currKey: this.getCurrentPagePath();
|
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
console.log("key=" + key);
|
console.log("key=" + key);
|
||||||
@ -170,12 +175,13 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//添加接收到数据的回调
|
//添加接收到数据的回调
|
||||||
addReceiveCallback(callback,currKey) {
|
addReceiveCallback(callback, currKey) {
|
||||||
let key =currKey?currKey: this.getCurrentPagePath();
|
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = new Date().getTime();
|
key = new Date().getTime();
|
||||||
}
|
}
|
||||||
if (key) {
|
if (key) {
|
||||||
|
console.log("订阅消息回调,key=" + key);
|
||||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
||||||
return v.key == key;
|
return v.key == key;
|
||||||
});
|
});
|
||||||
@ -193,10 +199,10 @@ class BleHelper {
|
|||||||
|
|
||||||
|
|
||||||
//设置接收到数据的回调
|
//设置接收到数据的回调
|
||||||
removeReceiveCallback(ev,currKey) {
|
removeReceiveCallback(currKey) {
|
||||||
let key =currKey?currKey: this.getCurrentPagePath();
|
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||||
if (key) {
|
if (key) {
|
||||||
console.log("key=" + key);
|
console.log("移除消息回调:" + key);
|
||||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
||||||
return v.key == key;
|
return v.key == key;
|
||||||
});
|
});
|
||||||
@ -426,8 +432,10 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
|
|
||||||
uni.onBLECharacteristicValueChange((receive) => {
|
uni.onBLECharacteristicValueChange((receive) => {
|
||||||
|
//订阅消息
|
||||||
|
let f=this.data.LinkedList.find((v) => {
|
||||||
|
return v.deviceId == receive.deviceId;
|
||||||
|
})
|
||||||
let dataView = new DataView(receive.value);
|
let dataView = new DataView(receive.value);
|
||||||
|
|
||||||
// 转换为字节数组
|
// 转换为字节数组
|
||||||
@ -453,21 +461,23 @@ class BleHelper {
|
|||||||
.deviceId) {
|
.deviceId) {
|
||||||
v.macAddress = str.replace(
|
v.macAddress = str.replace(
|
||||||
header, "");
|
header, "");
|
||||||
console.log("收到mac地址:", str)
|
// console.log("收到mac地址:", str)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
uni.setStorageSync(this.StorageKey, this.data
|
uni.setStorageSync(this.StorageKey, this.data
|
||||||
.LinkedList);
|
.LinkedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
|
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
|
||||||
if (arr.length >= 7) {
|
// console.log("收到mac地址:", bytes)
|
||||||
let mac = arr.slice(1, 7).join(":");
|
if (bytes.length >= 7) {
|
||||||
|
let mac = hexs.slice(1, 7).join(":")
|
||||||
|
.toUpperCase();
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == receive
|
if (v.deviceId == receive
|
||||||
.deviceId) {
|
.deviceId) {
|
||||||
v.macAddress = mac;
|
v.macAddress = mac;
|
||||||
console.log("收到mac地址:", str)
|
// console.log("收到mac地址:", str)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
uni.setStorageSync(this.StorageKey, this
|
uni.setStorageSync(this.StorageKey, this
|
||||||
@ -478,19 +488,31 @@ class BleHelper {
|
|||||||
////console.log("将数据转文本失败", ex);
|
////console.log("将数据转文本失败", ex);
|
||||||
}
|
}
|
||||||
let recData = {
|
let recData = {
|
||||||
|
deviceId: receive.deviceId,
|
||||||
|
serviceId: receive.serviceId,
|
||||||
|
characteristicId: receive.characteristicId,
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
str: str,
|
str: str,
|
||||||
hexs: hexs
|
hexs: hexs
|
||||||
};
|
};
|
||||||
console.log("监听到特征值:" + JSON.stringify(recData));
|
console.log("监听到特征值:" + JSON.stringify(recData));
|
||||||
if (this.cfg.receivDataCallback) {
|
if (this.cfg.receivDataCallback) {
|
||||||
|
|
||||||
if (this.cfg.receivDataCallback.length > 0) {
|
if (this.cfg.receivDataCallback.length > 0) {
|
||||||
|
|
||||||
|
let path = this.getCurrentPagePath();
|
||||||
|
|
||||||
this.cfg.receivDataCallback.forEach((rec) => {
|
this.cfg.receivDataCallback.forEach((rec) => {
|
||||||
rec.callback(recData);
|
|
||||||
|
if (rec.callback) {
|
||||||
|
|
||||||
|
}
|
||||||
|
rec.callback(recData, f, path);
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("无任何人订阅receivDataCallback,不处理数据");
|
console.log("无人订阅receivDataCallback,不处理数据");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -986,9 +1008,16 @@ class BleHelper {
|
|||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
////console.log("11111111");
|
////console.log("11111111");
|
||||||
if (res) { //新连接
|
if (res) { //新连接
|
||||||
console.log("开始获取服务", targetServiceId)
|
if (fIndex == -1) {
|
||||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
console.log("开始获取服务", targetServiceId)
|
||||||
|
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||||
notifyCharId); //获取服务
|
notifyCharId); //获取服务
|
||||||
|
} else {
|
||||||
|
if (!f.notifyState) {
|
||||||
|
this.subScribe(deviceId, true);
|
||||||
|
}
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
} else { //已连接过,直接订阅消息
|
} else { //已连接过,直接订阅消息
|
||||||
if (fIndex > -1 && f && !f.notifyState) {
|
if (fIndex > -1 && f && !f.notifyState) {
|
||||||
|
|
||||||
@ -1196,25 +1225,31 @@ class BleHelper {
|
|||||||
|
|
||||||
//将点阵数据转换成RGB565
|
//将点阵数据转换成RGB565
|
||||||
convertToRGB565(pixels, type) {
|
convertToRGB565(pixels, type) {
|
||||||
|
if (!type) {
|
||||||
|
type = 'rgb';
|
||||||
|
}
|
||||||
const result = new Uint16Array(pixels.length / 4);
|
const result = new Uint16Array(pixels.length / 4);
|
||||||
let index = 0;
|
let index = 0;
|
||||||
for (let i = 0; i < pixels.length; i += 4) {
|
for (let i = 0; i < pixels.length; i += 4) {
|
||||||
let r = pixels[i];
|
let r = pixels[i];
|
||||||
let g = pixels[i + 1];
|
let g = pixels[i + 1];
|
||||||
let b = pixels[i + 2];
|
let b = pixels[i + 2];
|
||||||
|
let a = pixels[i + 3];
|
||||||
|
|
||||||
let rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
|
||||||
let bgr565 = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
|
|
||||||
if (type == 'bgr') {
|
if (type == 'bgr') {
|
||||||
result[index++] = bgr565;
|
result[index++] = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
|
||||||
} else {
|
} else {
|
||||||
result[index++] = rgb565;
|
result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setBleData() {
|
||||||
|
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let instance = null;
|
let instance = null;
|
||||||
|
@ -1,21 +1,225 @@
|
|||||||
|
class BleReceive {
|
||||||
class BleReceive {
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.StorageKey = "linkedDevices";
|
this.StorageKey = "linkedDevices";
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentPagePath() {
|
||||||
|
|
||||||
|
const pages = getCurrentPages();
|
||||||
|
|
||||||
|
if (pages.length === 0) {
|
||||||
|
console.log("pages.length=0");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPage = pages[pages.length - 1];
|
||||||
|
console.log("currentPage=", currentPage.route);
|
||||||
|
return currentPage.route;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setBleFormData(data,f) {
|
||||||
|
if(data){
|
||||||
|
let linkedList=uni.getStorageSync(this.StorageKey);
|
||||||
|
linkedList.find((v)=>{
|
||||||
|
if(f.deviceId==v.deviceId){
|
||||||
|
let keys=Object.keys(data);
|
||||||
|
keys.forEach((key)=>{
|
||||||
|
if(!v.formData){
|
||||||
|
v.formData={};
|
||||||
|
}
|
||||||
|
if(!f.formData){
|
||||||
|
f.formData={};
|
||||||
|
}
|
||||||
|
v.formData[key]=data[key];
|
||||||
|
f.formData[key]=data[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
uni.setStorageSync(this.StorageKey,linkedList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReceiveData(receive,f,path) {
|
||||||
|
if(f && f.macAddress && f.id){
|
||||||
|
if(f.detailPageUrl=='/pages/6155/deviceDetail'){
|
||||||
|
console.log("该设备是6155");
|
||||||
|
return this.Receive_6155(receive,f,path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(f.detailPageUrl=='/pages/650/HBY650'){
|
||||||
|
console.log("该设备是650");
|
||||||
|
return this.Receive_650(receive,f,path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log("已收到该消息,但无法处理",f);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Receive_650(receive,f,path) {
|
||||||
|
console.log("通用程序正在处理650的数据");
|
||||||
|
|
||||||
|
var parseData = () => {
|
||||||
|
let bytes = receive.bytes;
|
||||||
|
if (bytes[0] == 0x55) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let staticLevelByte = bytes[1];
|
||||||
|
let staticLevelText = '未知';
|
||||||
|
let modeCurr = "";
|
||||||
|
switch (staticLevelByte) {
|
||||||
|
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 = '非常强预警';
|
||||||
|
}
|
||||||
|
|
||||||
|
let formData={};
|
||||||
|
formData.battary = batteryLevel;
|
||||||
|
formData.xuhang = xuhang;
|
||||||
|
formData.cMode = lightingLevelByte === 0x6e;
|
||||||
|
formData.modeCurr = modeCurr;
|
||||||
|
formData.warnLevel = warn;
|
||||||
|
formData.iswarn = iswarn;
|
||||||
|
this.setBleFormData(formData,f);
|
||||||
|
|
||||||
|
let route=this.getCurrentPagePath();
|
||||||
|
console.log("f=",f);
|
||||||
|
console.log("route="+route);
|
||||||
|
if (iswarn && f.detailPageUrl.indexOf(route)==-1 ) {
|
||||||
|
uni.showModal({
|
||||||
|
content:"环境存在漏电电源",
|
||||||
|
title:"警告",
|
||||||
|
success(res){
|
||||||
|
if(res.confirm){
|
||||||
|
|
||||||
|
if(f){
|
||||||
|
uni.navigateTo({
|
||||||
|
url: f.detailPageUrl,
|
||||||
|
events: {
|
||||||
|
ack: function(data) {}
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
res.eventChannel.emit('detailData', {
|
||||||
|
data: f,
|
||||||
|
deviceType: '',
|
||||||
|
apiType: 'listA'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
console.log("当前全局不处理此消息");
|
||||||
|
}
|
||||||
|
return formData;
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receive.str) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
let str = receive.str;
|
||||||
|
|
||||||
|
if (str.indexOf('mac address:') == 0) {
|
||||||
|
let formData={};
|
||||||
|
formData.macAddress = str.split(':')[1];
|
||||||
|
this.setBleFormData(formData,f);
|
||||||
|
return formData;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let data=parseData();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Receive_6155() {
|
||||||
|
console.log("通用程序正在处理6155的数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let instance = null;
|
let receiveInstance = null;
|
||||||
export default {
|
export default {
|
||||||
getBleReceive: function(found, receive) {
|
getBleReceive: function(found, receive) {
|
||||||
if (!instance) {
|
if (!receiveInstance) {
|
||||||
instance = new BleReceive();
|
receiveInstance = new BleReceive();
|
||||||
|
|
||||||
}
|
}
|
||||||
return instance;
|
return receiveInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,8 +25,7 @@ export const hideLoading = (ev) => {
|
|||||||
|
|
||||||
if(!ev){
|
if(!ev){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("hide.....")
|
|
||||||
ev.$refs.loading.hide();
|
ev.$refs.loading.hide();
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,13 @@ const request = (options) => {
|
|||||||
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 处理GET请求参数
|
// 处理GET请求参数
|
||||||
let url = BASE.BASE_URL + options.url;
|
let url =options.url;
|
||||||
|
if(url.indexOf('http://')===0 || url.indexOf('https://')===0){
|
||||||
|
url=url;
|
||||||
|
}else{
|
||||||
|
url=BASE.BASE_URL + url;
|
||||||
|
}
|
||||||
|
|
||||||
console.log("url"+url)
|
console.log("url"+url)
|
||||||
if (options.method === 'GET' && options.data) {
|
if (options.method === 'GET' && options.data) {
|
||||||
// 使用qs序列化参数
|
// 使用qs序列化参数
|
||||||
|
Reference in New Issue
Block a user