1
0
forked from dyf/APP

修改App图标、名称、蓝牙加入断线重连

This commit is contained in:
liub
2025-09-16 11:37:06 +08:00
parent 52b3bd796c
commit 778594574b
14 changed files with 3589 additions and 3686 deletions

View File

@ -151,12 +151,17 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {
registerPersonInfo
} from '@/api/6170/deviceControl.js';
var ble = null;
var these = null;
var BrighInteval = null;
export default {
components: {
TextToHexV1
TextToHexV1
},
data() {
return {
@ -228,7 +233,26 @@
textLines: ['', '', ''],
mode: ''
},
inteval: 200
inteval: 200,
device: {
id: "",
deviceName: "",
deviceImei: "",
deviceMac: "",
communicationMode: 0,
devicePic: "",
typeName: "",
bluetoothName: null,
deviceStatus: null,
bindingTime: "",
onlineStatus: 0,
battery: "0",
latitude: null,
longitude: null,
alarmStatus: null,
detailPageUrl: "/pages/6155/deviceDetail",
showConfirm: false
}
}
},
@ -283,16 +307,17 @@
// } else {
// link();
// }
ble.addReceiveCallback(these.bleValueNotify);
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', function(data) {
let device = data.data;
these.device = device;
console.log("收到父页面的参数:" + JSON.stringify(device));
let f = ble.data.LinkedList.find((v) => {
if (v.deviceId == device.deviceId) {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
@ -362,7 +387,7 @@
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
return v.macAddress == these.device.deviceMac;
});
return f;
@ -431,8 +456,8 @@
this.formData.battary = batteryLevel;
this.formData.statu = warn;
this.formData.xuhang = lightingTime;
if(batteryLevel<=20){
if (batteryLevel <= 20) {
this.showPop({
message: "设备电量低",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -448,7 +473,7 @@
}
},
proParam: function() {
uni.navigateTo({
@ -492,25 +517,25 @@
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
const arr = ble.convertToRGB565(pixels, 'bgr');
var list = [];
let index = 0; // 用于追踪arr的当前位置
let packetSize=2048;
let cSize=248;
let packetSize = 2048;
let cSize = 248;
// 外层循环7个主要元素i从1到7
for (let i = 1; i < 8; i++) {
let secondLevel = [];
let secondCnt=0;
let secondCnt = 0;
// 中层循环每个主要元素包含9个子数组j从1到9
for (let j = 1; j < 10; j++) {
// 确定当前子数组的长度前8个是254第9个是64
let thirdLevel = [];
// 从arr中提取相应数量的元素
for (let k = 0; k < cSize && index < arr.length; k++) {
if(secondCnt==packetSize){
if (secondCnt == packetSize) {
break;
}
thirdLevel.push(arr[index]);
@ -523,20 +548,20 @@
list.push(secondLevel);
}
console.log("list=",list);
let length=0;
console.log("list=", list);
let length = 0;
for (let i = 0; i < list.length; i++) {
const item = list[i];
let clength=0;
for (let j = 0; j < item.length; j++) {
const element = item[j];
console.log("第"+i+"包,第"+j+"小包,长度:"+element.length)
length+=element.length;
clength+=element.length;
}
const item = list[i];
let clength = 0;
for (let j = 0; j < item.length; j++) {
const element = item[j];
console.log("第" + i + "包,第" + j + "小包,长度:" + element.length)
length += element.length;
clength += element.length;
}
}
// 分包发送
sendImagePackets(list).then(resolve).catch(reject);
@ -558,22 +583,24 @@
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
setTimeout(()=>{
setTimeout(() => {
hideLoading(these);
these.Status.BottomMenu.show = false;
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
});
resolve();
},20000)
}, 20000)
return;
}
var packetData = imageData[currentPacket - 1][childPacket - 1];
var packetData = imageData[currentPacket - 1][childPacket - 1];
// if (packetData.length == 0) {
// hideLoading(these);
// these.Status.BottomMenu.show = false;
@ -586,38 +613,37 @@
// resolve();
// return;
// }
let start=0;
let bufferSize=packetData.length*2;
if(currentPacket==7 ){
if(childPacket>2 && childPacket<9){
bufferSize=496;
}
else if(childPacket==9){
bufferSize=128;
let start = 0;
let bufferSize = packetData.length * 2;
if (currentPacket == 7) {
if (childPacket > 2 && childPacket < 9) {
bufferSize = 496;
} else if (childPacket == 9) {
bufferSize = 128;
}
}
if(childPacket==1){
bufferSize=bufferSize+8
start=8;
if (childPacket == 1) {
bufferSize = bufferSize + 8
start = 8;
}
if(childPacket==9 ){//|| (currentPacket==7 && childPacket==3
bufferSize=bufferSize+1
if (childPacket == 9) { //|| (currentPacket==7 && childPacket==3
bufferSize = bufferSize + 1
}
//FA 09 10 04 FC 09 [00] [01] + 4096字节+FF 数据格式
var buffer = new ArrayBuffer(bufferSize);
var dataView = new DataView(buffer);
if(childPacket==1){
if (childPacket == 1) {
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x09); // 帧头
dataView.setUint8(2, 0x10); // 帧头
dataView.setUint8(3, 0x04); // 帧头
dataView.setUint8(4, 0xFC); // 帧头
dataView.setUint8(5, 0x09); // 帧头
dataView.setUint8(6, 0x00); // 图序号,图片固定0视频的话要写序号
dataView.setUint8(7, currentPacket); //子包序号
}
@ -625,20 +651,21 @@
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
}
console.log("packetData.length=",packetData.length);
console.log("bufferSize=",bufferSize)
if(childPacket==9){// || (currentPacket==7 && childPacket==3
dataView.setUint8(bufferSize-1, 0xFF);
console.log("packetData.length=", packetData.length);
console.log("bufferSize=", bufferSize)
if (childPacket == 9) { // || (currentPacket==7 && childPacket==3
dataView.setUint8(bufferSize - 1, 0xFF);
}
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
30)
.then(() => {
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log(""+currentPacket+"大包,"+childPacket+"小包发送完成,总计"+curr);
totalChildPacket;
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
updateLoading(these, {
text: "正在发送" + curr + "/63"
@ -949,7 +976,7 @@
let packetSize = rgbdata.length; //每包均分的数量
let mode = rgbdata.length % packetSize; //最后一包的数量
let cnt =
1; // parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :0); //总包数量
1; // parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :0); //总包数量
let curr = 1; //当前包序号
let sendNext = () => {
@ -994,7 +1021,7 @@
dataView.setUint8(bufferSize - 1, 0xFF);
let inteval =parseInt(this.inteval ? this.inteval : 50);
let inteval = parseInt(this.inteval ? this.inteval : 50);
console.log("inteval=", inteval)
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 30).then(() => {
@ -1027,12 +1054,12 @@
console.log("11111");
var result = null;
try {
console.log("this.$refs.textToHex=",this.$refs.textToHex);
console.log("this.$refs.textToHex=", this.$refs.textToHex);
result = await this.$refs.textToHex.drawAndGetPixels();
} catch (ex) {
console.log("ex=", ex);
}
if(!result){
if (!result) {
hideLoading(this);
return;
}
@ -1041,7 +1068,7 @@ if(!result){
return level1.flat(Infinity);
});
console.log("result=", result);
// var str1="FA 06 01 00 FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 FF 81 03 ED BB DD B7 CB CF F3 C7 CD 39 BE FF FE FF C0 03 FE FB FD FB F3 F7 8F 87 FF FF FF FF FE FF FE FF FE FF C0 03 FF FB FD FB FD FB FD FB FD FB FB FB FB FF F7 F7 EF F7 9F 8F FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
// var str2="FA 07 01 00 FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EF 77 EF 73 EF 7F 80 01 EF 7F EF 7F EF 03 E7 3B 8E BB EE D7 EE EF ED E7 ED 9B 8B 7D FF FF FF FF FF FF F7 EF F7 F7 EF F7 DF FB FF FF FF FF FE FF 80 01 FE 7F FD BF FB DF F7 E7 9F F9 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
// var str3="FA 08 01 00 FF FF EF DF EC 01 EF FF AB FF AA 03 AA FB AE FB EE 03 EF DF EF DF EE DB ED DF ED DD EF 1F FF FF FF FF EF BF EF 87 81 77 EE F7 EC 03 81 7F EF 7F EF 7F EF 03 81 7F EF 7F EF 7D EF 7D EF 03 FF FF FF FF F9 F1 CF BF DF FF DF FF C1 FF DD 81 DD F7 DD F7 C1 F7 DF 77 FF 77 BF 77 BF 77 FF F7 FF FF FF FF FD FF FD FF FB FF FB FF F0 07 E7 F7 EF F7 D8 07 BF F7 FF F7 F8 07 FF F7 FF F7 FF C7 FF FF FF FF FF FF FF FF FF FF FE FF FE 7F FE 7F FE FF FD BF FD FF FB DF F7 EF EF F7 DF FB BF FD FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
@ -1086,8 +1113,26 @@ if(!result){
if (flag) {
console.log("发送成功");
this.showPop({
message: "发送成功"
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
});
// let formdata = {
// code:"",
// name: these.formData.textLines[2],
// position: these.formData.textLines[1],
// unitName: these.formData.textLines[0],
// deviceId: these.device.id,
// deviceImei: these.device.deviceImei
// };
// registerPersonInfo(formdata).then(res=>{
// console.log("res=",res);
// }).catch(ex=>{
// console.log("ex=",ex);
// });
} else {
this.showPop({
message: "出现异常发送失败",

View File

@ -173,6 +173,11 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {request,baseURL} from '../../utils/request';
import {
registerPersonInfo
} from '@/api/6170/deviceControl.js';
const pagePath = "pages/650/HBY650";
var ble = null;
var these = null;
@ -259,7 +264,26 @@
iswarn: false
},
rgb565Data: [],
videoHexArray: []
videoHexArray: [],
device: {
id: "",
deviceName: "",
deviceImei: "",
deviceMac: "",
communicationMode: 0,
devicePic: "",
typeName: "",
bluetoothName: null,
deviceStatus: null,
bindingTime: "",
onlineStatus: 0,
battery: "0",
latitude: null,
longitude: null,
alarmStatus: null,
detailPageUrl: "/pages/650/HBY650",
showConfirm: false
},
}
},
@ -278,7 +302,7 @@
console.log("收到父页面的参数:" + JSON.stringify(data));
var device = data.data;
these.device=device;
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
@ -374,9 +398,9 @@
return className;
},
bleValueNotify: function(receive, device, path) { //订阅消息
console.log("收到设备的数据", data)
let data = recei.ReceiveData(receive, device, pagePath);
console.log("收到设备的数据",data)
if (data) {
if ("staBlue_picture" in data) {
//重发图片
@ -403,10 +427,10 @@ console.log("收到设备的数据",data)
let keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if(key in these.formData){
these.formData[key] = data[key];
if (key in these.formData) {
these.formData[key] = data[key];
}
}
if (these.formData.iswarn) {
@ -434,7 +458,7 @@ console.log("收到设备的数据",data)
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
return v.macAddress == these.device.deviceMac;
});
return f;
@ -606,11 +630,12 @@ console.log("收到设备的数据",data)
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
});
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f
.deviceId, f
.writeServiceId, f.wirteCharactId);
},500);
}, 500);
}
resolve();
@ -635,7 +660,7 @@ console.log("收到设备的数据",data)
const packetData = these.rgb565Data.slice(startIndex,
endIndex);
// 构建数据包
const bufferSize =505;// 5 + packetData.length * 2; // 头部5字节 + 数据部分
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
@ -771,18 +796,20 @@ console.log("收到设备的数据",data)
this.totalPackets = totalPackets;
// 发送单个数据包
const sendNextVideoPacket = () => {
console.log("准备发送一段数据");
console.log("准备发送一段数据");
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f
.writeServiceId, f.wirteCharactId).then(()=>{
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f
.deviceId, f
.writeServiceId, f.wirteCharactId).then(
() => {
console.log("全部发送完毕")
}).catch((ex)=>{
console.log("出现异常",ex);
});
},500);
}).catch((ex) => {
console.log("出现异常", ex);
});
}, 500);
}
these.Status.BottomMenu.show = false;
hideLoading(these);
@ -793,7 +820,7 @@ console.log("收到设备的数据",data)
});
resolve();
@ -837,10 +864,10 @@ console.log("收到设备的数据",data)
}
let inteval = 50;
console.log("开始发送一段视频"); //
console.log("开始发送一段视频"); //
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 10).then(() => {
updateLoading(these, {
text: "正在发送:" + currentPacket + "/" +
totalPackets
@ -902,13 +929,28 @@ console.log("收到设备的数据",data)
let p1 = these.HoldYouHand("video transmit start", 2200, f.deviceId, f.writeServiceId,
f.wirteCharactId);
let p2 = new Promise((succ, err) => {
const token = uni.getStorageSync('token');
const clientid = uni.getStorageSync('clientID');
if (!token) {
err({
code: 401,
msg: "请先登陆后再试"
});
hideLoading(these);
return;
}
uni.uploadFile({
url: 'http://114.55.111.217/video/upload',
// url: 'http://114.55.111.217/video/upload',
url: baseURL+"app/video/upload",
filePath: videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
timeout: 600000,
fail: (ex) => {
@ -1127,14 +1169,15 @@ console.log("收到设备的数据",data)
// console.log("currentPacket=",currentPacket);
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f.writeServiceId, f
.wirteCharactId);
},500);
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f.deviceId, f
.writeServiceId, f
.wirteCharactId);
}, 500);
}
these.showPop({
@ -1155,6 +1198,16 @@ console.log("收到设备的数据",data)
visibleClose: true
});
these.setBleFormData();
// let formdata = {
// code: these.formData.id,
// name: these.formData.name,
// position: these.formData.job,
// unitName: these.formData.company,
// deviceId: these.device.id,
// deviceImei: these.device.deviceImei
// };
// registerPersonInfo(formdata);
return;
}
@ -1163,7 +1216,7 @@ console.log("收到设备的数据",data)
let arr = gbk.encode(text)
let gbkData = gbk.arr2hex(arr);
// 构建数据包
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
@ -1174,7 +1227,7 @@ console.log("收到设备的数据",data)
dataView.setUint8(1, 0x03); // 帧类型:文字
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
dataView.setUint16(3, (text.length * 2).toString(16)); // 数据长度
// 填充数据
let index = 0;
for (var i = 0; i < gbkData.length; i += 2) {
@ -1182,8 +1235,8 @@ console.log("收到设备的数据",data)
dataView.setUint8(5 + index, value);
index++;
}
// 发送数据包
@ -1219,7 +1272,7 @@ console.log("收到设备的数据",data)
}
if(ReSendNo){
if (ReSendNo) {
sendText(ReSendNo);
return;
}
@ -1261,16 +1314,26 @@ console.log("收到设备的数据",data)
}
console.log("开始握手");
ble.sendData(deviceid, buffer, serviceid, characid, 10).then(
() => {
setTimeout(() => {
console.log("握手成功并完成了等待");
resolve(true);
}, pauseTime);
}).catch(err => {
console.log("握手没有成功", )
reject(err);
});
let send = () => {
ble.sendData(deviceid, buffer, serviceid, characid, 10).then(
() => {
setTimeout(() => {
console.log("握手成功并完成了等待");
resolve(true);
}, pauseTime);
}).catch(err => {
if (err.code == 10007) {
send();
} else {
console.log("握手没有成功", err)
reject(err);
}
});
}
send();
});

View File

@ -249,6 +249,14 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {
request,
baseURL
} from '../../utils/request';
import {
registerPersonInfo
} from '@/api/6170/deviceControl.js';
const pagePath = "pages/650/HBY650";
var ble = null;
var these = null;
@ -629,7 +637,7 @@
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = json.sta_PowerTime + "分钟";
receiveData.battary = json.sta_PowerPercent ;
receiveData.battary = json.sta_PowerPercent;
receiveData.warnLevel = warn;
receiveData.staticWarn = staticWarn;
@ -699,10 +707,10 @@
},
getDevice: function() {
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
console.log("LinkedList=", ble.data.LinkedList);
console.log("this.device=", this.device);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
return v.macAddress == these.device.deviceMac;
});
return f;
@ -800,60 +808,60 @@
setTimeout(task, 0);
},
CloseWarn: function(ispop) {
let closeEvt=()=>{
let closeEvt = () => {
{
these.Status.Pop.showPop = false;
these.formData.qzwarn = false;
clearInterval(these.Status.staticWarn.inteval);
let closeSOS=()=>{
let closeSOS = () => {
let json = {
ins_SOSGrade: [0]
};
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
these.setBleFormData();
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=", ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
these.setBleFormData();
});
}
let closeWarn=()=>{
let closeWarn = () => {
let json = {
ins_ShakeBit: [0]
};
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
these.setBleFormData();
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=", ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
these.setBleFormData();
});
}
let f = this.getDevice();
let buffer = null;
if (f) {
@ -866,31 +874,32 @@
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, 0x71); // 数据
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
() => {
console.log("关闭强制报警成功")
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x05); // 帧类型
dataView.setUint8(2, 0x01); // 包序号
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, 0x68);
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(()=>{
console.log("成功");
});
}).catch(ex => {
() => {
console.log("关闭强制报警成功")
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x05); // 帧类型
dataView.setUint8(2, 0x01); // 包序号
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, 0x68);
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10)
.then(() => {
console.log("成功");
});
}).catch(ex => {
closeSOS();
closeWarn();
// closeWarn();
});
} else {
closeSOS();
closeWarn();
// closeWarn();
}
}
}
if(!ispop){
if (!ispop) {
closeEvt();
return;
}
@ -901,8 +910,8 @@
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:"解除报警",
okCallback: closeEvt
buttonText: "解除报警",
okCallback: closeEvt
});
},
@ -972,21 +981,21 @@
() => {
console.log("蓝牙发送成功了");
dic = {
close: 0x71
}
if (type in dic) {
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(5, 0x71); // 数据
// dic = {
// close: 0x71
// }
// if (type in dic) {
// dataView.setUint8(1, 0x06); // 帧类型
// dataView.setUint8(5, 0x71); // 数据
} else {
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(5, 0x70); // 数据
}
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
10).then(() => {
console.log("蓝牙发送报警成功", type);
})
// } else {
// dataView.setUint8(1, 0x06); // 帧类型
// dataView.setUint8(5, 0x70); // 数据
// }
// ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
// 10).then(() => {
// console.log("蓝牙发送报警成功", type);
// })
hideLoading(these);
these.setBleFormData();
@ -1012,16 +1021,28 @@
okCallback: function() {
these.formData.qzwarn = true;
these.Status.staticWarn.time = 5;
these.Status.staticWarn.inteval = setInterval(() => {
these.Status.staticWarn.time = 180;
let loopFunc = () => {
if (these.Status.staticWarn.inteval === null) {
return;
}
if (these.Status.staticWarn.time === 0) {
console.log("111111");
clearInterval(these.Status.staticWarn.inteval);
these.Status.staticWarn.inteval = null;
these.formData.qzwarn = false;
these.formData.SOS = 'close';
these.CloseWarn(false);
return;
}
these.Status.staticWarn.time = these.Status.staticWarn
.time - 1;
}
these.Status.staticWarn.inteval = setInterval(() => {
loopFunc();
}, 1000)
SendCmd();
@ -1101,8 +1122,14 @@
these.setBleFormData();
}).catch((ex) => {
//使用4G发送
console.log("蓝牙发送失败,转4g发送", ex);
requestSend();
if (ex.code == 10007) {
console.log("蓝牙发送失败,正在重试");
task();
} else {
console.log("蓝牙发送失败,转4g发送", ex);
requestSend();
}
});
} else {
console.log("找不到蓝牙设备使用4G发送")
@ -1437,6 +1464,8 @@
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
let inteval = 30;
console.log("开始发送一段视频"); //
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
@ -1487,6 +1516,17 @@
}
var sendVideo = (videoPath) => {
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接,请连接后再试",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
let uploadVideo = () => {
if (these.videoHexArray.length > 0) {
@ -1495,7 +1535,9 @@
return;
}
console.log("开始处理,正在上传");
console.log("开始处理,正在上传", f);
const token = uni.getStorageSync('token');
const clientid = uni.getStorageSync('clientID');
showLoading(these, {
text: "上传中"
@ -1503,13 +1545,25 @@
let p1 = these.HoldYouHand("video transmit start", 2200, f.deviceId, f.writeServiceId,
f.wirteCharactId);
let p2 = new Promise((succ, err) => {
if (!token) {
err({
code: 401,
msg: "请先登陆后再试"
});
hideLoading(these);
return;
}
console.log("baseURL=", baseURL);
uni.uploadFile({
url: 'http://114.55.111.217/video/upload',
// url: 'http://114.55.111.217/video/upload',
url: baseURL + "/app/video/upload",
filePath: videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
timeout: 600000,
fail: (ex) => {
@ -1564,7 +1618,7 @@
});
})
}
let f = these.getDevice();
@ -1818,6 +1872,17 @@
});
these.setBleFormData();
hideLoading(these);
// let formdata = {
// code: these.formData.usrid,
// name: these.formData.usrname,
// position: these.formData.job,
// unitName: these.formData.company,
// deviceId: these.device.id,
// deviceImei: these.device.deviceImei
// };
// registerPersonInfo(formdata);
return;
}

View File

@ -125,7 +125,8 @@
let start = new Date();
console.log("Common.baseURL=" + Common.baseURL);
uni.uploadFile({
url: Common.baseURL + 'video/upload',
// url: Common.baseURL + 'video/upload',
url:'http://192.168.110.56:8000/app/video/upload',
filePath: this.videoPath,
name: 'file',
header: {

View File

@ -34,12 +34,13 @@
hideLoading,
updateLoading
} from '@/utils/loading.js';
const pagePath="pages/common/addBLE/LinkBle";
const pagePath = "pages/common/addBLE/LinkBle";
var these = null;
var eventChannel = null;
var ble = null;
var timeInteval = null;
export default {
data() {
return {
@ -57,7 +58,8 @@
],
"linkStatu": false,
"macAddress": ""
}
},
serverDevice:null
}
},
computed: {
@ -84,11 +86,11 @@
onLoad(option) {
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback((receive,f,path) => {
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;
@ -97,79 +99,91 @@
}
}
}
},pagePath);
}, pagePath);
eventChannel = this.getOpenerEventChannel();
eventChannel.on('LinkItem', function(data) {
console.log("data=",data);
console.log("data=", data);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == data.deviceId;
});
if (f) {
let keys=Object.keys(f);
keys.forEach((v,index)=>{
these.device[v]=f[v];
let keys = Object.keys(f);
keys.forEach((v, index) => {
these.device[v] = f[v];
})
console.log("LinkedList=",ble.data.LinkedList)
console.log("f=", f);
console.log("LinkedList=", ble.data.LinkedList)
console.log("f=", f);
console.log("获取到设备", these.device);
if (f.macAddress) {
these.device.macAddress = f.macAddress;
these.initDevice();
}
these.device.macAddress = f.macAddress;
these.initDevice();
}
} else {
console.log("未获取到设备");
}
})
let inteval = setInterval(this.initDevice, 5000);
},
methods: {
initDevice: function() {
showLoading(these, {
text: '正在获取设备信息'
});
console.log("these.device=",these.device);
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
data: {
deviceMac: these.device.macAddress
}
}).then(res => {
console.log("获取设备信息", res);
if (res && res.code == 200) {
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);
clearTimeout(timeInteval);
timeInteval = setTimeout(() => {
showLoading(these, {
text: '正在获取设备信息'
});
console.log("these.device=", these.device);
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
data: {
deviceMac: these.device.macAddress
}
}
}).then(res => {
console.log("获取设备信息", res);
if (res && res.code == 200) {
let data = res.data;
this.serverDevice=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];
// if(!v.device){
// v.device={};
// }
// v.device[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);
});
}, 500);
}).catch((ex) => {
console.log("获取设备出现异常:", ex);
}).finally(() => {
hideLoading(these);
});
},
Link() {
// 调用绑定设备接口
@ -207,6 +221,21 @@
if (res.code == 200) {
these.Statu.bound = true;
these.Statu.boundRemark = "设备绑定成功!";
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.device.deviceId) {
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if(!v.device){
v.device={};
}
v.device[key] = data[key];
}
ble.setBleData();
}
});
ble.removeReceiveCallback(pagePath);
uni.$emit("refreshDeviceList");