Compare commits
7 Commits
b20a93dd28
...
0909d9f023
| Author | SHA1 | Date | |
|---|---|---|---|
| 0909d9f023 | |||
| 1d8b3b4a9a | |||
| a5c6faa9da | |||
| 15ba241317 | |||
| fa64e7f1fc | |||
| 45328120c1 | |||
| 0033649677 |
@ -156,7 +156,7 @@
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
import BleReceive from '@/utils/BleReceive';
|
||||
var pagePath = "pages/6155/HBY6155";
|
||||
var pagePath = "/pages/6155/HBY6155";
|
||||
|
||||
var ble = null;
|
||||
var these = null;
|
||||
@ -514,11 +514,11 @@
|
||||
|
||||
return f;
|
||||
},
|
||||
bleValueNotify: function(receive, device, path) {
|
||||
bleValueNotify: function(receive, device, path,recArr) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
let json = recei.ReceiveData(receive, device, path);
|
||||
let json = recei.ReceiveData(receive, device, path,recArr);
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@
|
||||
} from '../../utils/request';
|
||||
|
||||
import usrApi from '@/api/670/HBY670.js'
|
||||
const pagePath = "pages/650/HBY650";
|
||||
const pagePath = "/pages/650/HBY650";
|
||||
|
||||
var ble = null;
|
||||
var these = null;
|
||||
@ -490,9 +490,9 @@
|
||||
|
||||
return className;
|
||||
},
|
||||
bleValueNotify: function(receive, device, path) { //订阅消息
|
||||
bleValueNotify: function(receive, device, path,recArr) { //订阅消息
|
||||
console.log("收到设备的数据", receive)
|
||||
let data = recei.ReceiveData(receive, device, pagePath);
|
||||
let data = recei.ReceiveData(receive, device, pagePath,recArr);
|
||||
|
||||
if (data) {
|
||||
if ("staBlue_picture" in data) {
|
||||
|
||||
@ -289,7 +289,7 @@
|
||||
} from '../../utils/request';
|
||||
import lnglatConvert from '@/utils/wgs84_to_gcj02.js'
|
||||
|
||||
const pagePath = "pages/670/HBY670";
|
||||
const pagePath = "/pages/670/HBY670";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var recei = null;
|
||||
@ -982,9 +982,9 @@
|
||||
this.refreshFormData(receiveData, 'auto');
|
||||
return receiveData;
|
||||
},
|
||||
bleValueNotify: function(receive, device, path) { //订阅消息
|
||||
bleValueNotify: function(receive, device, path,recArr) { //订阅消息
|
||||
|
||||
let data = recei.ReceiveData(receive, device, pagePath);
|
||||
let data = recei.ReceiveData(receive, device, pagePath,recArr);
|
||||
console.log("收到设备的数据", data)
|
||||
if (data) {
|
||||
if ("staBlue_picture" in data) {
|
||||
|
||||
@ -87,21 +87,23 @@
|
||||
<text class="usrtitle fleft">人员信息登记</text>
|
||||
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
|
||||
<view class="clear"></view>
|
||||
<textToDotMatrixFor7305 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
|
||||
:color="'#000000'" :fontSize="11" />
|
||||
</view>
|
||||
<textToDotMatrixFor7305 class="TextToHex" ref="textToHex" :txts="formData.textLines"
|
||||
:bgColor="'#FFFFFF'" :color="'#000000'" :fontSize="11" / </view>
|
||||
|
||||
<view class="item">
|
||||
<text class="lbl">单位:</text>
|
||||
<input class="value" v-model="formData.textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
|
||||
<input class="value" v-model="formData.textLines[0]" placeholder="请输入单位"
|
||||
placeholder-class="usrplace" />
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">部门:</text>
|
||||
<input class="value" v-model="formData.textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
|
||||
<input class="value" v-model="formData.textLines[1]" placeholder="请输入姓名"
|
||||
placeholder-class="usrplace" />
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">姓名:</text>
|
||||
<input class="value" v-model="formData.textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
|
||||
<input class="value" v-model="formData.textLines[2]" placeholder="请输入职位"
|
||||
placeholder-class="usrplace" />
|
||||
</view>
|
||||
|
||||
</view>
|
||||
@ -162,7 +164,7 @@
|
||||
var these = null;
|
||||
var BrighInteval = null;
|
||||
var recei = null;
|
||||
var pagePath = "pages/7305/BJQ7305";
|
||||
var pagePath = "/pages/7305/BJQ7305";
|
||||
export default {
|
||||
components: {
|
||||
textToDotMatrixFor7305
|
||||
@ -465,12 +467,12 @@
|
||||
|
||||
return f;
|
||||
},
|
||||
bleValueNotify: function(receive, device, path) {
|
||||
bleValueNotify: function(receive, device, path, recArr) {
|
||||
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
let json = recei.ReceiveData(receive, device, path);
|
||||
let json = recei.ReceiveData(receive, device, path, recArr);
|
||||
|
||||
if (!json) {
|
||||
return;
|
||||
@ -580,7 +582,9 @@
|
||||
imageData.push(0x00);
|
||||
}
|
||||
|
||||
const fullPacket = new Uint8Array([...header, ...imageData.slice(0, 1024), ...footer]);
|
||||
const fullPacket = new Uint8Array([...header, ...imageData.slice(0, 1024), ...
|
||||
footer
|
||||
]);
|
||||
const fullBuffer = fullPacket.buffer;
|
||||
|
||||
// 2. 将完整数据包切片成20字节的小块进行发送
|
||||
@ -608,14 +612,17 @@
|
||||
const end = Math.min(start + chunkSize, fullBuffer.byteLength);
|
||||
const chunk = fullBuffer.slice(start, end);
|
||||
|
||||
const hexArray = Array.from(new Uint8Array(chunk)).map(b => b.toString(16).padStart(2, '0'));
|
||||
console.log(`发送图片数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray.join(' '));
|
||||
const hexArray = Array.from(new Uint8Array(chunk)).map(b => b.toString(
|
||||
16).padStart(2, '0'));
|
||||
console.log(`发送图片数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray.join(
|
||||
' '));
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送 " + (chunkIndex + 1) + "/" + numChunks
|
||||
});
|
||||
|
||||
ble.sendData(f.deviceId, chunk, f.writeServiceId, f.wirteCharactId, 100)
|
||||
ble.sendData(f.deviceId, chunk, f.writeServiceId, f.wirteCharactId,
|
||||
100)
|
||||
.then(() => {
|
||||
chunkIndex++;
|
||||
setTimeout(sendNextChunk, 20); // 每个小包之间延时20ms
|
||||
@ -1086,10 +1093,13 @@
|
||||
const end = Math.min(start + chunkSize, fullBuffer.byteLength);
|
||||
const chunk = fullBuffer.slice(start, end);
|
||||
|
||||
const hexArray = Array.from(new Uint8Array(chunk)).map(b => b.toString(16).padStart(2, '0'));
|
||||
console.log(`发送数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray.join(' '));
|
||||
const hexArray = Array.from(new Uint8Array(chunk)).map(b => b
|
||||
.toString(16).padStart(2, '0'));
|
||||
console.log(`发送数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray
|
||||
.join(' '));
|
||||
|
||||
ble.sendData(f.deviceId, chunk, f.writeServiceId, f.wirteCharactId, 100).then(() => {
|
||||
ble.sendData(f.deviceId, chunk, f.writeServiceId, f
|
||||
.wirteCharactId, 100).then(() => {
|
||||
chunkIndex++;
|
||||
setTimeout(sendNextChunk, 30); // 每个小包之间延时30ms
|
||||
}).catch(err => {
|
||||
|
||||
@ -771,10 +771,10 @@ class BleHelper {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// console.log("无人订阅消息");
|
||||
console.log("无人订阅消息");
|
||||
}
|
||||
} else {
|
||||
// console.log("无人订阅receivDataCallback,不处理数据");
|
||||
console.log("无人订阅receivDataCallback,不处理数据");
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error("处理订阅消息失败,ex=", ex);
|
||||
|
||||
@ -1,21 +1,12 @@
|
||||
class BleReceive {
|
||||
constructor() {
|
||||
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;
|
||||
this.HandlerMap = {
|
||||
'/pages/6155/deviceDetail': this.Receive_6155.bind(this),
|
||||
'/pages/7305/BJQ7305': this.Receive_6155.bind(this),
|
||||
'/pages/650/HBY650': this.Receive_650.bind(this),
|
||||
'/pages/670/HBY670': this.Receive_670.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -49,22 +40,24 @@ class BleReceive {
|
||||
|
||||
ReceiveData(receive, f, path, recArr) {
|
||||
if (f && f.macAddress && f.device && f.device.id) {
|
||||
let data={};
|
||||
if(f.device.detailPageUrl=='/pages/6155/deviceDetail' || f.device.detailPageUrl=='/pages/7305/BJQ7305'){
|
||||
// console.log("该设备是6155");
|
||||
data= this.Receive_6155(receive,f,path,recArr);
|
||||
let handler = null;
|
||||
let keys = Object.keys(this.HandlerMap);
|
||||
for (let index = 0; index < keys.length; index++) {
|
||||
let key = keys[index].replaceAll('/', '').toLowerCase();
|
||||
let devKey = f.device.detailPageUrl ? f.device.detailPageUrl.replaceAll('/', '').toLowerCase() : '';
|
||||
if (key == devKey) {
|
||||
handler = this.HandlerMap[keys[index]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(f.device.detailPageUrl=='/pages/650/HBY650'){
|
||||
// console.log("该设备是650");
|
||||
data= this.Receive_650(receive,f,path,recArr);
|
||||
}
|
||||
if(f.device.detailPageUrl=='/pages/670/HBY670'){
|
||||
// console.log("该设备是670");
|
||||
data= this.Receive_670(receive,f,path,recArr);
|
||||
}
|
||||
// console.log("收到数据并处理完毕,",data);
|
||||
if (handler) {
|
||||
let data = handler(receive, f, path, recArr);
|
||||
return data;
|
||||
} else {
|
||||
console.log("已收到消息,但无指定处理程序", receive);
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("已收到该消息,但无法处理", receive);
|
||||
}
|
||||
@ -154,10 +147,13 @@ class BleReceive {
|
||||
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 ) {
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replaceAll('/', '').toLowerCase() == f.device.detailPageUrl
|
||||
.replaceAll('/', '').toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
|
||||
if (iswarn) {
|
||||
uni.showModal({
|
||||
content: "环境存在漏电电源",
|
||||
title: "警告",
|
||||
@ -182,8 +178,7 @@ class BleReceive {
|
||||
}
|
||||
}
|
||||
})
|
||||
}else{
|
||||
console.log("当前全局不处理此消息");
|
||||
}
|
||||
}
|
||||
return formData;
|
||||
} catch (error) {
|
||||
@ -201,9 +196,10 @@ class BleReceive {
|
||||
formData.macAddress = str.split(':')[1];
|
||||
this.setBleFormData(formData, f);
|
||||
return formData;
|
||||
}
|
||||
else{
|
||||
let receiveData={a:1};
|
||||
} else {
|
||||
let receiveData = {
|
||||
a: 1
|
||||
};
|
||||
try {
|
||||
let json = JSON.parse(str);
|
||||
|
||||
@ -211,25 +207,21 @@ class BleReceive {
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData = json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
} else if ("staBlue_text" in json) {
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData = json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
} else if ("staBlue_vidio" in json) {
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData = json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
} else if ("staBlue" in json) {
|
||||
if (json.staBlue == "finish") {
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData = json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
receiveData = {};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
@ -284,7 +276,8 @@ class BleReceive {
|
||||
// console.log("todo");
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close';
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight' : lightingLevelByte === 0x6e ?
|
||||
'low' : 'close';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
||||
@ -323,7 +316,8 @@ class BleReceive {
|
||||
this.setBleFormData(receiveData, f);
|
||||
console.log("recArr=", recArr);
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key == f.device.detailPageUrl;
|
||||
return v.key.replaceAll('/', '').toLowerCase() == f.device.detailPageUrl
|
||||
.replaceAll('/', '').toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (this.formData.staticWarn) { //有静止报警
|
||||
@ -367,25 +361,21 @@ class BleReceive {
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData = json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
} else if ("staBlue_text" in json) {
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData = json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
} else if ("staBlue_vidio" in json) {
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData = json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
} else if ("staBlue" in json) {
|
||||
if (json.staBlue == "finish") {
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData = json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
receiveData = {};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
@ -412,6 +402,7 @@ class BleReceive {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Receive_6155(receive, f, path, recArr) {
|
||||
let bytes = receive.bytes;
|
||||
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
|
||||
@ -474,13 +465,23 @@ class BleReceive {
|
||||
formData.statu = warn;
|
||||
formData.xuhang = lightingTime;
|
||||
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
|
||||
return v.key.replaceAll('/', '').toLowerCase() === f.device.detailPageUrl.replaceAll(
|
||||
'/', '').toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (batteryLevel <= 20) {
|
||||
|
||||
uni.showModal({
|
||||
content: "设备电量低",
|
||||
title: "提示"
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.setBleFormData(formData, f);
|
||||
return formData;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user