1
0
forked from dyf/APP

Merge branch 'liubiao-new-20250827'

# Conflicts:
#	pages.json
This commit is contained in:
2025-09-18 11:48:39 +08:00
34 changed files with 34422 additions and 6977 deletions

View File

@ -35,11 +35,11 @@
handleCrop(e) {
var these = this;
const eventChannel = these.getOpenerEventChannel();
this.Statu = true;
console.log("裁剪完成");
console.log(e.tempFilePath);
//
eventChannel.emit('ImgCutOver_Path',e.tempFilePath);
const ctx = uni.createCanvasContext('splashCanvas', this);
ctx.drawImage(
e.tempFilePath,
@ -56,7 +56,7 @@
height: 80,
success: (res) => {
// 处理像素数据并发送
const eventChannel = these.getOpenerEventChannel();
console.log("res.data.length="+res.data.length);
eventChannel.emit('ImgCutOverPath', {
picPath: e.tempFilePath

View File

@ -31,7 +31,7 @@
<text class="value">{{formData.deviceName}}</text>
</view>
<view class="item">
<text class="lbl">设备状态</text>
<text class="lbl">充电状态</text>
<text class="value">{{formData.statu}}</text>
</view>
</view>
@ -55,7 +55,7 @@
</view>
<view class="rightTxt">
<text class="bigTxt">主灯模式</text>
<text class="smallTxt">强光模式</text>
<text class="smallTxt">{{getMode}}</text>
</view>
</view>
<view class="mode marginLeft fleft" v-on:click.stop="ModeSetting('fu')">
@ -83,8 +83,8 @@
<text class="usrtitle fleft">人员信息登记</text>
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="clear"></view>
<TextToHex class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#000000'"
:color="'#FFFFFF'" :fontSize="16" />
<TextToHexV1 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
:color="'#000000'" :fontSize="14" />
</view>
<view class="item">
@ -143,17 +143,26 @@
</template>
<script>
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
import bleTool from '@/utils/BleHelper.js';
import usrApi from '@/api/670/HBY670.js'
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
import BleReceive from '@/utils/BleReceive';
var ble = null;
var these = null;
var BrighInteval = null;
var recei = null;
export default {
components: {
TextToHexV1
},
data() {
return {
Status: {
@ -221,10 +230,29 @@
liangDu: '100',
id: '',
deviceId: '',
textLines: ['我爱你', '中国', '五星红旗'],
textLines: ['', '', ''],
mode: ''
},
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
}
}
},
@ -233,7 +261,54 @@
},
onLoad: function() {
these = this;
recei = BleReceive.getBleReceive();
ble = bleTool.getBleTool();
// let bleName = 'FB_Site_UART'; //JQZM-EF4651 FB_Site_UART
// let f = ble.data.LinkedList.find((v) => {
// if (v.name == bleName) {
// console.log("找到设备了", v);
// these.formData.deviceId = v.deviceId;
// return true;
// }
// return false;
// });
// let link = () => {
// if (bleName == 'FB_Site_UART') {
// ble.LinkBlue(f.deviceId, '0000AE30-0000-1000-8000-00805F9B34FB',
// '0000AE03-0000-1000-8000-00805F9B34FB', '0000AE02-0000-1000-8000-00805F9B34FB');
// } else {
// ble.LinkBlue(f.deviceId, '0000FFE0-0000-1000-8000-00805F9B34FB',
// '0000FFE1-0000-1000-8000-00805F9B34FB', '0000FFE2-0000-1000-8000-00805F9B34FB');
// }
// }
// if (!f) {
// ble.addDeviceFound((res) => {
// // console.log("发现新设备", res);
// f = res.devices.find((v) => {
// return v.name == bleName;
// });
// if (f) {
// console.log("找到目标设备了", f);
// these.formData.deviceId = f.deviceId;
// link();
// ble.StopSearch();
// }
// });
// ble.StartSearch();
// } else {
// link();
// }
console.log("6155");
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
@ -241,7 +316,8 @@
let device = data.data;
console.log("收到父页面的参数:" + JSON.stringify(device));
these.device = device;
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
@ -253,12 +329,7 @@
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
let form = f.formData;
@ -306,21 +377,54 @@
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
}
},
getMode() {
let txt = "关闭";
if (this.Status.BottomMenu.type == 'fu') {
return txt;
}
switch (this.formData.mode) {
case 0:
txt = "强光模式";
break;
case 1:
txt = "弱光模式";
break;
case 2:
txt = "爆闪模式";
break;
case 3:
txt = "关闭";
break;
default:
txt = "关闭";
break;
}
return txt;
}
},
methods: {
getDevice: function() {
console.log("LinkedList=", ble.data.LinkedList);
console.log("formData=", these.formData);
// 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;
},
bleValueNotify: function(receive) {
console.log("处理接收到的数据:" + receive);
bleValueNotify: function(receive, device, path) {
let str = recei.ReceiveData(receive, device, path);
console.log("处理接收到的数据:" + str);
return;
let data = recei.ReceiveData(receive, device, path);
let bytes = receive.bytes;
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
@ -383,6 +487,15 @@
this.formData.statu = warn;
this.formData.xuhang = lightingTime;
if (batteryLevel <= 20) {
this.showPop({
message: "设备电量低",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}
this.setBleFormData();
} catch (error) {
console.log('数据解析错误:', error);
@ -416,16 +529,40 @@
}
});
},
showBleUnConnect() {
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
okCallback: function() {
console.log("1111");
uni.navigateTo({
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', {
data: these.device
})
},
fail(ex) {
console.log("跳转失败", ex);
}
})
}
});
},
checkImgUpload: function() {
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
@ -433,10 +570,55 @@
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
const rgb565Data = ble.convertToRGB565(pixels);
const arr = ble.convertToRGB565(pixels, 'bgr');
var list = [];
let index = 0; // 用于追踪arr的当前位置
let packetSize = 2048;
let cSize = 248;
// 外层循环7个主要元素i从1到7
for (let i = 1; i < 8; i++) {
let secondLevel = [];
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) {
break;
}
thirdLevel.push(arr[index]);
secondCnt++;
index++;
}
secondLevel.push(thirdLevel);
}
list.push(secondLevel);
}
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;
}
}
// 分包发送
sendImagePackets(rgb565Data).then(resolve).catch(reject);
sendImagePackets(list).then(resolve).catch(reject);
});
}
@ -446,90 +628,116 @@
var sendImagePackets = function(imageData) {
return new Promise((resolve, reject) => {
// 总数据包数
const totalPackets = 52;
const totalPackets = 7;
let currentPacket = 1;
let childPacket = 1;
let totalChildPacket = 9;
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
hideLoading(these);
these.Status.BottomMenu.show = false;
setTimeout(() => {
hideLoading(these);
these.Status.BottomMenu.show = false;
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
resolve();
}, 20000)
resolve();
return;
}
// 计算当前包的数据
let packetSize = 250;
if (currentPacket <= 51) {
packetSize = 250; // 前51个包每个500字节
} else {
packetSize = 50; // 最后一个包100字节
}
var packetData = imageData[currentPacket - 1][childPacket - 1];
// if (packetData.length == 0) {
// hideLoading(these);
// these.Status.BottomMenu.show = false;
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData
.length);
if (startIndex > endIndex) {
return;
}
const packetData = imageData.slice(startIndex,
endIndex); // imageData.subarray(startIndex, endIndex);
console.log("imageData.length=" + imageData.length +
",startIndex=" +
startIndex +
",endIndex=" + endIndex + ",数据包长度" + (endIndex -
startIndex) +
',packetData.length=' + packetData.length);
// 构建数据包
const bufferSize = 5 + packetData.length * 2; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
// these.showPop({
// message: "上传成功",
// iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
// });
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x02); // 帧类型:开机画面
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
'0')); // 包序号
// if(packetData.length==250)
// {
// dataView.setUint8(3, 0x01);
// dataView.setUint8(4, 0xFF);
// resolve();
// return;
// }
let start = 0;
let bufferSize = packetData.length * 2;
if (packetData.length == 250) {
dataView.setUint8(3, 0x01);
dataView.setUint8(4, 0xF4);
} else {
dataView.setUint8(3, 0x00);
dataView.setUint8(4, 0x64);
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 == 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) {
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); //子包序号
}
// 填充数据每个RGB565值占2字节
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
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);
}
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
30)
.then(() => {
console.log("发送一个包完成了");
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
updateLoading(these, {
text: "正在发送" + currentPacket + "/" +
totalPackets
text: "正在发送" + curr + "/63"
})
currentPacket++;
if (childPacket == 9) {
currentPacket++;
childPacket = 1;
} else {
childPacket++;
}
setTimeout(sendNextPacket, 100);
}).catch(err => {
if (err.code == 10007) {
setTimeout(sendNextPacket, 100);
return;
}
console.log("发送数据包失败了", err);
these.Status.BottomMenu.show = false;
@ -567,7 +775,8 @@
these.Status.BottomMenu.show = false;
setTimeout(function() {
processAndSendImageData(data.piexls).catch((ex) => {
processAndSendImageData(data.piexls).catch((
ex) => {
console.log("出现异常", ex);
});
}, 0)
@ -606,10 +815,10 @@
text: '强光',
icon: '/static/images/6155/DeviceDetail/qiang.png'
},
{
text: '工作光',
icon: '/static/images/6155/DeviceDetail/fan.png'
},
// {
// text: '工作光',
// icon: '/static/images/6155/DeviceDetail/fan.png'
// },
{
text: '弱光',
icon: '/static/images/6155/DeviceDetail/ruo.png'
@ -617,7 +826,7 @@
{
text: '爆闪',
icon: '/static/images/6155/DeviceDetail/shan.png'
},
},
{
text: '关闭',
icon: '/static/images/6155/DeviceDetail/close.png'
@ -662,42 +871,40 @@
}
this.closeMenu();
},
setMode(mode, type) {
let dataValue = 0;
this.setBleFormData();
if (type == 'main') {
type = 0x04;
} else if (type == 'fu') {
type = 0x05;
}
this.currentMode = mode;
switch (mode) {
case 0:
dataValue = 0x01;
if (type == 'main') {
dataValue = 0x01;
} else if (type == 'fu') {
dataValue = 0x04;
}
break;
case 1:
dataValue = 0x04;
break;
case 2:
dataValue = 0x02;
break;
case 3:
// case 2:
// dataValue = 0x02;
// break;
case 2:
dataValue = 0x03;
break;
case 4:
dataValue = 0x00;
case 3:
dataValue = 0x0B;
break;
}
// console.log("dataValue=", dataValue)
// 构建数据包
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
@ -713,12 +920,7 @@
// 发送数据
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
@ -727,7 +929,8 @@
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
this.formData.mode = mode;
this.setBleFormData();
}).catch((ex) => {
these.showPop({
message: "发送失败," + ex.msg,
@ -771,38 +974,54 @@
},
HidePop: function() {
console.log("1111");
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
if (this.Status.Pop.okCallback) {
this.Status.Pop.okCallback();
}
this.Status.Pop.showPop = false;
},
showPop: function(option) {
hideLoading(this);
let defaultCfg = {
showHeader: false,
headerTxt: "",
showHeader: false,
showCancel: false,
borderColor: '#BBE600',
buttonBgColor: '#BBE600',
okCallback: null,
cancelCallback: null,
popType: 'custom',
buttonText: '确定',
clickEvt: ''
};
if (!option) {
option = {
a: 1
};
}
let keys = Object.keys(option);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
these.Status.Pop[key] = option[key];
this.Status.Pop[key] = option[key];
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
keys = Object.keys(defaultCfg);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if (key in option) {
continue;
}
this.Status.Pop[key] = defaultCfg[key];
}
these.Status.Pop.showPop = true;
this.Status.Pop.showPop = true;
},
sendUsr() {
let f = this.getDevice();
if (!f) {
these.showPop({
text: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect()
return;
}
showLoading(these, {
@ -817,8 +1036,8 @@
let packetSize = rgbdata.length; //每包均分的数量
let mode = rgbdata.length % packetSize; //最后一包的数量
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :
0); //总包数量
let cnt =
1; // parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :0); //总包数量
let curr = 1; //当前包序号
let sendNext = () => {
@ -831,6 +1050,7 @@
let bufferSize = 261;
console.log("bufferSize=", bufferSize)
let buffer = new ArrayBuffer(bufferSize);
let dataView = new DataView(buffer);
let startIndex = (curr - 1) * packetSize;
@ -844,7 +1064,7 @@
let packetData = rgbdata.slice(startIndex,
endIndex); //取一片数据发送
console.log("packetData.length=", packetData.length);
let start = 0;
if (curr == 1) {
dataView.setUint8(0, 0xFA);
@ -852,7 +1072,7 @@
dataView.setUint8(2, 0x01);
dataView.setUint8(3, 0x00);
// dataView.setUint16(2, str.length, false);
start = 4;
}
@ -862,8 +1082,8 @@
dataView.setUint8(bufferSize - 1, 0xFF);
let inteval = parseInt(this.inteval ? this.inteval : 0);
let inteval = parseInt(this.inteval ? this.inteval : 50);
console.log("inteval=", inteval)
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 30).then(() => {
@ -892,12 +1112,36 @@
}
var result = await this.$refs.textToHex.drawAndGetPixels();
console.log("11111");
var result = null;
try {
console.log("this.$refs.textToHex=", this.$refs.textToHex);
result = await this.$refs.textToHex.drawAndGetPixels();
} catch (ex) {
console.log("ex=", ex);
}
if (!result) {
hideLoading(this);
return;
}
console.log("result=", result);
result = result.map(level1 => {
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"
// let arr1=('0x'+(str1.split(' ').join(",0x"))).split(',');
// let arr2=('0x'+(str2.split(' ').join(",0x"))).split(',');
// let arr3=('0x'+(str3.split(' ').join(",0x"))).split(',');
// result=[arr1,arr2,arr3];
// console.log("result=",result);
let h3dic = [0x06, 0x07, 0x08];
@ -913,9 +1157,9 @@
var rgb = result[i];
try {
console.log("1111");
// console.log("1111");
await sendTxtPackge(rgb, h3dic[i], str);
console.log("222222");
// console.log("222222");
} catch (ex) {
flag = false;
console.log("33333");
@ -929,9 +1173,24 @@
hideLoading(these);
if (flag) {
console.log("发送成功");
this.showPop( {
message: "发送成功"
this.showPop({
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
let json = {
deviceId: these.device.id,
name: these.formData.textLines[1],
position: these.formData.textLines[0],
unitName: these.formData.textLines[2],
code: ""
};
usrApi.sendUsr(json)
} else {
this.showPop({
message: "出现异常发送失败",
@ -956,23 +1215,25 @@
},
sliderChange: function(evt) {
this.formData.liangDu = evt.detail.value;
clearTimeout(BrighInteval)
//给蓝牙设备发送信号更新亮度
setTimeout(() => {
BrighInteval = setTimeout(() => {
this.sendBrightness();
this.setBleFormData();
}, 10);
}, 100);
},
sendBrightness: function() {
const buffer = new ArrayBuffer(6);
const dataView = new DataView(buffer);
let data = '0x' + parseInt(this.formData.liangDu).toString(16);
console.log("亮度:" + this.formData.liangDu + ',16进制:' + data);
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x01); // 帧类型:亮度调节
dataView.setUint8(2, 0x01); // 包序号
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, data); // 数据
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x05); // 帧类型:亮度调节
dataView.setUint8(2, 0x00); // 包序号
dataView.setUint8(3, 0x01); // 包序号
dataView.setUint8(4, data); // 数据长度
dataView.setUint8(5, 0xFF); // 数据长度
let f = this.getDevice();
if (f) {
// 发送数据

View File

@ -173,6 +173,9 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {request,baseURL} from '../../utils/request';
import usrApi from '@/api/670/HBY670.js'
const pagePath = "pages/650/HBY650";
var ble = null;
var these = null;
@ -259,7 +262,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
},
}
},
@ -271,6 +293,7 @@
these = this;
recei = BleReceive.getBleReceive();
ble = BleTool.getBleTool();
console.log("650")
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
@ -278,7 +301,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);
@ -290,12 +313,7 @@
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
let form = f.formData;
@ -374,9 +392,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 +421,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 +452,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;
@ -533,12 +551,7 @@ console.log("收到设备的数据",data)
these.setBleFormData();
});
} else {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
hideLoading(these);
}
}
@ -547,6 +560,34 @@ console.log("收到设备的数据",data)
},
showBleUnConnect(){
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:'去连接',
okCallback:function(){
console.log("1111");
uni.navigateTo({
url:"/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', { data: these.device })
},
fail(ex){
console.log("跳转失败",ex);
}
})
}
});
},
LampToggle: function() {
this.formData.cMode = !this.formData.cMode;
@ -606,11 +647,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 +677,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 +813,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 +837,7 @@ console.log("收到设备的数据",data)
});
resolve();
@ -837,10 +881,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 +946,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) => {
@ -1103,12 +1162,7 @@ console.log("收到设备的数据",data)
let f = this.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
showLoading(this, {
@ -1127,14 +1181,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 +1210,16 @@ console.log("收到设备的数据",data)
visibleClose: true
});
these.setBleFormData();
let json = {
deviceId: these.device.id,
name: these.formData.company,
position: these.formData.name,
unitName: these.formData.job,
code: these.formData.id
};
usrApi.sendUsr(json)
return;
}
@ -1163,7 +1228,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 +1239,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 +1247,8 @@ console.log("收到设备的数据",data)
dataView.setUint8(5 + index, value);
index++;
}
// 发送数据包
@ -1219,7 +1284,7 @@ console.log("收到设备的数据",data)
}
if(ReSendNo){
if (ReSendNo) {
sendText(ReSendNo);
return;
}
@ -1261,16 +1326,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

@ -44,7 +44,7 @@
</view>
<view class="warnnig" v-bind:class="formData.staticWarn?'':'displayNone'">
<view>警告环境存在漏电电源</view>
<view>警告设备静止报警中</view>
<view class="netContent">
<view v-bind:class="getWarnStyle(1)" class="net netone"></view>
<view v-bind:class="getWarnStyle(2)" class="net nettwo"></view>
@ -55,7 +55,7 @@
</view>
<view class="warnnig" v-bind:class="(formData.qzwarn && Status.staticWarn.time)?'':'displayNone'"
@click="CloseWarn(true)">
<view>设备强制闪烁报警中</view>
<view>设备强制报警中</view>
<view class="netContent">
{{Status.staticWarn.time}}s
</view>
@ -90,7 +90,9 @@
:src="formData.SOS=='sg'?'/static/images/670/sgActive.png':'/static/images/670/sg.png'"
mode="aspectFit"></image>
</view>
<view class="txt">声光报警</view>
<view :class="(formData.qzwarn && Status.staticWarn.time)?'':'displayNone'">
报警中{{Status.staticWarn.time}}</view>
<view :class="(formData.qzwarn && Status.staticWarn.time)?'displayNone':''" class="txt">声光报警</view>
</view>
<view class="item" @click="sosSetting('rb')" :class="formData.SOS=='rb'?'active':''">
<view class="imgContent center">
@ -249,7 +251,13 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
const pagePath = "pages/650/HBY650";
import {
request,
baseURL
} from '../../utils/request';
const pagePath = "pages/670/HBY670";
var ble = null;
var these = null;
var recei = null;
@ -290,7 +298,8 @@
visiblePrompt: false,
promptTitle: '设备名称',
modelValue: '',
visibleClose: false
visibleClose: false,
},
BottomMenu: {
show: false,
@ -338,7 +347,7 @@
Lat: "", //纬度
address: "", //地址
modeCurr: "", //档位
SOS: "sg", //sos
SOS: "", //sos
lightCurr: "qiang", //照明模式
company: "", //单位
usrname: "", //姓名
@ -394,6 +403,7 @@
these = this;
recei = BleReceive.getBleReceive();
ble = BleTool.getBleTool();
console.log("670")
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
@ -629,7 +639,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;
@ -682,9 +692,9 @@
if (this.formData.imei) {
this.initMQ();
}
if (these.formData.staticWarn) { //有静止报警
if (this.formData.staticWarn) { //有静止报警
these.showPop({
message: "环境存在漏电电源",
message: "设备静止报警中",
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
@ -695,14 +705,14 @@
}
these.setBleFormData();
this.setBleFormData();
},
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;
@ -799,112 +809,97 @@
setTimeout(task, 0);
},
CloseWarn: function(ispop) {
let closeEvt=()=>{
{
these.Status.Pop.showPop = false;
these.formData.qzwarn = false;
clearInterval(these.Status.staticWarn.inteval);
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();
});
}
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();
});
}
let f = this.getDevice();
let buffer = null;
if (f) {
// 发送数据
buffer = new ArrayBuffer(6);
let dataView = new DataView(buffer);
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(2, 0x01); // 包序号
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, 0x71); // 数据
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
CloseWarn: function(ispop) { //解除强制报警
let closeEvt = () => {
these.Status.Pop.showPop = false;
these.formData.qzwarn = false;
clearInterval(these.Status.staticWarn.inteval);
let requestCloseSOS = () => {
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);
this.formData.SOS = 'close';
these.setBleFormData();
});
}
let f = this.getDevice();
let buffer = null;
if (f) {
// 发送数据
buffer = new ArrayBuffer(6);
let dataView = new DataView(buffer);
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x05); // 帧类型
dataView.setUint8(2, 0x01); // 包序号
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, 0x6A); // 数据
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 => {
closeSOS();
closeWarn();
});
} else {
closeSOS();
closeWarn();
}
requestCloseSOS();
}).finally(() => {
this.formData.SOS = 'close';
these.setBleFormData();
});
} else {
requestCloseSOS();
}
}
if(!ispop){
if (!ispop) {
closeEvt();
return;
}
this.showQzWarn(closeEvt);
},
showQzWarn(callback) {
let message = '持续报警时间' + this.Status.staticWarn.time;
if (this.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
this.Status.Pop.message = message
return;
}
this.showPop({
showHeader: true,
headerTxt: "强制报警",
message: '持续报警时间' + this.Status.staticWarn.time,
message: message,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:"解除报警",
okCallback: closeEvt
buttonText: "解除报警",
okCallback: callback,
clickEvt: 'time'
});
},
sosSetting: function(type) {
if (this.formData.SOS == type) {
@ -915,7 +910,7 @@
text: "请稍候..."
});
let task = () => {
this.formData.SOS = type;
let dic = {
ble: {
rb: 0x68,
@ -937,6 +932,8 @@
let requestSend = () => {
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=", ex);
these.showPop({
@ -954,7 +951,7 @@
}
let SendCmd = () => {
let bleSendCmd = () => {
let f = this.getDevice();
let buffer = null;
if (f) {
@ -972,21 +969,6 @@
() => {
console.log("蓝牙发送成功了");
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);
})
hideLoading(these);
these.setBleFormData();
@ -1000,33 +982,70 @@
}
}
if (type !== 'sg') {
SendCmd();
} else {
let OpenSOS = () => {
these.formData.qzwarn = true; //标记为强制报警了
these.Status.staticWarn.time = 50;
this.formData.SOS = type;
let loopFunc = () => {
if (these.Status.staticWarn.inteval === null) {
return;
}
if (these.Status.staticWarn.time === 0) {
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;
if (these.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
console.log("111111");
this.showQzWarn(this.Status.Pop.okCallback);
}
}
these.Status.staticWarn.inteval = setInterval(() => {
loopFunc();
}, 1000)
bleSendCmd();
}
if (type == 'rb') { //红蓝报警
this.formData.SOS = type;
bleSendCmd();
return;
}
if (type == 'sg') //强制报警
{
this.showPop({
message: '确定开启声光报警模式?',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: function() {
these.formData.qzwarn = true;
these.Status.staticWarn.time = 5;
these.Status.staticWarn.inteval = setInterval(() => {
if (these.Status.staticWarn.time === 0) {
clearInterval(these.Status.staticWarn.inteval);
these.formData.qzwarn = false;
these.CloseWarn(false);
return;
}
these.Status.staticWarn.time = these.Status.staticWarn
.time - 1;
}, 1000)
SendCmd();
}
okCallback: OpenSOS,
buttonText: "开启"
});
return;
}
if (type == 'close') {
if (this.formData.SOS = 'sg') { //解除声光报警
this.CloseWarn(true);
} else {
this.formData.SOS = type;
bleSendCmd();
}
}
}
@ -1101,8 +1120,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发送")
@ -1382,7 +1407,7 @@
}).catch((ex) => {
console.log("出现异常", ex);
});
}, 500);
}, 3000);
}
these.Status.BottomMenu.show = false;
@ -1437,6 +1462,8 @@
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
let inteval = 30;
console.log("开始发送一段视频"); //
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
@ -1487,6 +1514,40 @@
}
var sendVideo = (videoPath) => {
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接,请连接后再试",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
okCallback: function() {
console.log("1111");
uni.navigateTo({
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', {
data: these.device
})
},
fail(ex) {
console.log("跳转失败", ex);
}
})
}
});
return;
}
let uploadVideo = () => {
if (these.videoHexArray.length > 0) {
@ -1495,7 +1556,9 @@
return;
}
console.log("开始处理,正在上传");
console.log("开始处理,正在上传", f);
const token = uni.getStorageSync('token');
const clientid = uni.getStorageSync('clientID');
showLoading(these, {
text: "上传中"
@ -1503,13 +1566,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 +1639,7 @@
});
})
}
let f = these.getDevice();
@ -1695,7 +1770,9 @@
buttonBgColor: '#BBE600',
okCallback: null,
cancelCallback: null,
popType: 'custom'
popType: 'custom',
buttonText: '确定',
clickEvt: ''
};
if (!option) {
@ -1703,7 +1780,7 @@
let keys = Object.keys(option);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
these.Status.Pop[key] = option[key];
this.Status.Pop[key] = option[key];
}
keys = Object.keys(defaultCfg);
for (var i = 0; i < keys.length; i++) {
@ -1711,10 +1788,10 @@
if (key in option) {
continue;
}
these.Status.Pop[key] = defaultCfg[key];
this.Status.Pop[key] = defaultCfg[key];
}
these.Status.Pop.showPop = true;
this.Status.Pop.showPop = true;
},
sendUsr: function(ReSendNo) {
@ -1818,6 +1895,16 @@
});
these.setBleFormData();
hideLoading(these);
let json = {
deviceId: these.device.id,
name: these.formData.company,
position: these.formData.usrname,
unitName: these.formData.job,
code: these.formData.usrid
};
api.sendUsr(json)
return;
}
@ -1909,18 +1996,10 @@
text: "请稍候..."
});
this.setBleFormData();
let arr = [];
if (this.formData.msgTxt.length > 8) {
arr.push(this.formData.msgTxt.substring(0, 8));
arr.push(this.formData.msgTxt.substring(8));
} else {
let index = Math.floor(this.formData.msgTxt.length / 2)
arr.push(this.formData.msgTxt.substring(0, index));
arr.push(this.formData.msgTxt.substring(index));
}
let data = {
"sendMsg": arr.join('|'),
"sendMsg": this.formData.msgTxt,
"deviceIds": [
this.device.id
],

1720
pages/7305/BJQ7305.vue Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -219,7 +219,7 @@
<script>
import gbk from '@/utils/gbk.js';
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
import TextToHexVue from '@/components/TextToHex/TextToHexV1.vue';
export default {
comments: {
TextToHexVue

View File

@ -240,6 +240,8 @@
import gbk from '@/utils/gbk.js';
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
import Common from '../../../utils/Common';
import BleHelper from '../../../utils/BleHelper';
var ble=BleHelper.getBleTool();
export default {
components: {
TextToHexV1
@ -251,7 +253,7 @@
canvasTop: '-1000px',
canvasLeft: '-1000px',
inteval: 100,
inteval: 1000,
isLoading: false,
isBluetoothOpen: false,
isSearching: false,
@ -270,7 +272,7 @@
logList: [],
packetCount: 1,
currentPage: 'deviceList',
targetDeviceName: 'JQZM-EF4651',
targetDeviceName: 'JQZM-EF4651',//FB_Site_UART
currentTab: 'mode',
brightness: 50,
brightnessTimer: null,
@ -287,7 +289,7 @@
totalPackets: 100,
imageWidth: 0,
imageHeight: 0,
textLines: ['下雨了', '天亮了', '连接成功'],
textLines: ['那个', '你看到我的小熊', '了吗'],
textProgress: 0,
currentTextPacket: 0,
totalTextPackets: 4,
@ -308,6 +310,7 @@
}
},
onLoad() {
this.initBluetoothAdapter();
},
methods: {
@ -335,32 +338,41 @@
},
// 蓝牙初始化
initBluetoothAdapter() {
ble.addDeviceFound(this.onDeviceFound);
console.log('开始初始化蓝牙适配器');
uni.openBluetoothAdapter({
success: (res) => {
this.isBluetoothOpen = true;
this.bluetoothStatus = '已开启';
console.log('蓝牙适配器初始化成功');
this.getBluetoothAdapterState();
// 自动开始搜索设备
this.startSearch();
},
fail: (err) => {
this.bluetoothStatus = '初始化失败';
console.log(`蓝牙适配器初始化失败: ${err.errMsg}`);
if (err.errCode === 10001) {
uni.onBluetoothAdapterStateChange((res) => {
if (res.available) {
this.isBluetoothOpen = true;
this.bluetoothStatus = '已开启';
console.log('蓝牙适配器已开启');
this.startSearch();
}
});
}
}
ble.OpenBlue().then((res)=>{
this.isBluetoothOpen = true;
this.bluetoothStatus = '已开启';
ble.StartSearch();
}).catch((err)=>{
this.isBluetoothOpen = true;
this.bluetoothStatus = '已开启';
});
// uni.openBluetoothAdapter({
// success: (res) => {
// this.isBluetoothOpen = true;
// this.bluetoothStatus = '已开启';
// console.log('蓝牙适配器初始化成功');
// this.getBluetoothAdapterState();
// // 自动开始搜索设备
// this.startSearch();
// },
// fail: (err) => {
// this.bluetoothStatus = '初始化失败';
// console.log(`蓝牙适配器初始化失败: ${err.errMsg}`);
// if (err.errCode === 10001) {
// uni.onBluetoothAdapterStateChange((res) => {
// if (res.available) {
// this.isBluetoothOpen = true;
// this.bluetoothStatus = '已开启';
// console.log('蓝牙适配器已开启');
// this.startSearch();
// }
// });
// }
// }
// });
},
// 获取蓝牙适配器状态
@ -418,39 +430,46 @@
this.deviceList = [];
this.searchTips = '搜索中...';
console.log('开始搜索蓝牙设备');
uni.startBluetoothDevicesDiscovery({
services: ["0xFFE0"],
allowDuplicatesKey: false,
success: (res) => {
console.log('开始搜索蓝牙设备成功');
this.onDeviceFound();
},
fail: (err) => {
this.isSearching = false;
this.searchTips = '搜索失败';
console.log(`搜索蓝牙设备失败: ${err.errMsg}`);
}
ble.StartSearch().then(()=>{
console.log('开始搜索蓝牙设备成功');
}).catch((err)=>{
this.isSearching = false;
this.searchTips = '搜索失败';
console.log(`搜索蓝牙设备失败: ${err.errMsg}`);
});
// uni.startBluetoothDevicesDiscovery({
// allowDuplicatesKey: false,
// success: (res) => {
// console.log('开始搜索蓝牙设备成功');
// this.onDeviceFound();
// },
// fail: (err) => {
// this.isSearching = false;
// this.searchTips = '搜索失败';
// console.log(`搜索蓝牙设备失败: ${err.errMsg}`);
// }
// });
},
// 停止搜索蓝牙设备
stopSearch() {
this.isSearching = false;
this.searchTips = this.deviceList.length > 0 ? '搜索完成' : '未发现蓝牙设备';
uni.stopBluetoothDevicesDiscovery({
success: () => {
console.log('停止搜索蓝牙设备');
}
});
ble.StartSearch();
// uni.stopBluetoothDevicesDiscovery({
// success: () => {
// console.log('停止搜索蓝牙设备');
// }
// });
},
// 监听发现新设备
onDeviceFound() {
uni.onBluetoothDeviceFound((res) => {
onDeviceFound(res) {
// uni.onBluetoothDeviceFound((res) => {
// console.log("发现新设备",res);
var device = res.devices[0];
if (!device.name && !device.localName) return;
// if ((device.name || device.localName) === this.targetDeviceName) {
@ -467,24 +486,62 @@
this.deviceList[index].RSSI = device.RSSI;
}
// }
// 如果找到目标设备,自动连接
if ((device.name || device.localName) === this.targetDeviceName) {
console.log(`发现目标设备: ${JSON.stringify(device)}`);
this.connectDevice(device.deviceId, this.targetDeviceName,device);
}
});
// });
},
// 连接蓝牙设备
connectDevice(deviceId, deviceName,device) {
if (this.isConnected && this.connectedDeviceId === deviceId) return;
let gotoDetail=()=>{
ble.StopSearch();
uni.navigateTo({
url:"/pages/6155/deviceDetail",
success(res) {
res.eventChannel.emit('detailData', {
data: {deviceId:deviceId},
deviceType: '',
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息
});
},fail(ex){
console.log("跳转失败",ex);
}
});
}
if (this.isConnected && this.connectedDeviceId === deviceId) {
gotoDetail();
return;
};
this.isLoading = true;
if(device){
console.log("device=",device);
}
let promise=null;
if (deviceName == 'FB_Site_UART') {
promise=ble.LinkBlue(deviceId, '0000AE30-0000-1000-8000-00805F9B34FB',
'0000AE03-0000-1000-8000-00805F9B34FB', '0000AE02-0000-1000-8000-00805F9B34FB');
} else {
promise=ble.LinkBlue(deviceId, '0000FFE0-0000-1000-8000-00805F9B34FB',
'0000FFE1-0000-1000-8000-00805F9B34FB', '0000FFE2-0000-1000-8000-00805F9B34FB');
}
promise.then(res=>{
console.log("连接成功了");
gotoDetail();
this.isConnected=true;
}).catch(err=>{
console.log("连接失败了",err);
this.isConnected=false;
});
return;
console.log(`开始连接设备: ${deviceName}`);
var these = this;
uni.createBLEConnection({
@ -502,16 +559,20 @@
setTimeout(function() {
uni.setBLEMTU({
deviceId: deviceId,
mtu: 1024,
mtu: 512,
success: (info) => {
console.log("设置mtu成功",info)
these.getDeviceServices(deviceId);
},
fail: (ex) => {
console.log("设置mtu失败" + JSON.stringify(ex));
these.getDeviceServices(deviceId);
},finally(){
}
})
these.getDeviceServices(deviceId);
}, 2000)
// 获取服务和特征值
@ -648,7 +709,7 @@
deviceId: deviceId,
success: (res) => {
these.addLog("发现服务" + JSON.stringify(res.services));
console.log("发现服务" + JSON.stringify(res.services));
if (res.services.length == 0) {
setTimeout(function() {
these.getDeviceServices(deviceId);
@ -662,11 +723,11 @@
});
if (targetService) {
these.addLog(`找到目标服务: ${targetService.uuid}`);
console.log(`找到目标服务: ${targetService.uuid}`);
this.serviceId = targetService.uuid;
this.getDeviceCharacteristics(deviceId, targetService.uuid);
} else {
these.addLog("没找到目标服务");
console.log("没找到目标服务");
}
},
fail: (err) => {
@ -684,7 +745,7 @@
serviceId: serviceId,
success: (res) => {
console.log(`获取设备特征值成功,共发现 ${res.characteristics.length} 个特征值`);
these.addLog(`获取设备成功:${JSON.stringify(res.characteristics)}`);
console.log(`获取设备成功:${JSON.stringify(res.characteristics)}`);
// 查找可写特征值
var writeChar = res.characteristics.find(char => {
return char.uuid.indexOf("FFE1") > -1 || char.uuid.indexOf(
@ -818,7 +879,7 @@
"续航时间:"+this.receiveData.time
];
this.logList=[];
this.addLog(arr.join(","));
console.log(arr.join(","));
} catch (error) {
console.log('数据解析错误:',error);
}
@ -833,14 +894,14 @@
let arr=hexs.split(' ');
if(arr.length>=7){
this.receiveData.macAddress=arr.slice(1,7).join(":");
this.addLog("设备mac地址:"+this.receiveData.macAddress);
console.log("设备mac地址:"+this.receiveData.macAddress);
}else{
this.addLog("收到无效的数据");
console.log("收到无效的数据");
}
}
else {
this.addLog("收到无效的数据");
console.log("收到无效的数据");
}
}
@ -929,7 +990,7 @@
setMode(mode, type) {
this.logList = [];
if (!this.isConnected) {
this.addLog("未连接设备")
console.log("未连接设备")
uni.showToast({
title: '未连接设备',
icon: 'none'
@ -1195,10 +1256,33 @@
processAndSendImageData(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
var rgb565Data = this.convertToRGB565(pixels, 160, 80);
// console.log("rgb565Data=,",rgb565Data);
var arr = this.convertToRGB565(pixels, 160, 80);
var list = [];
let index = 0; // 用于追踪arr的当前位置
// 外层循环7个主要元素i从1到7
for (let i = 1; i < 8; i++) {
let secondLevel = [];
// 中层循环每个主要元素包含9个子数组j从1到9
for (let j = 1; j < 10; j++) {
// 确定当前子数组的长度前8个是254第9个是16
let length = (j < 9) ? 248 : 128;
let thirdLevel = [];
// 从arr中提取相应数量的元素
for (let k = 0; k < length && index < arr.length; k++) {
thirdLevel.push(arr[index]);
index++;
}
secondLevel.push(thirdLevel);
}
list.push(secondLevel);
}
// 分包发送
this.sendImagePackets(rgb565Data).then(resolve).catch(reject);
this.sendImagePackets(list).then(resolve).catch(reject);
});
},
@ -1221,8 +1305,11 @@
var b = pixels[i + 2];
//var rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
var bgr565 = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
// var rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
var bgr565 = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
result[index++] = bgr565;
}
@ -1239,68 +1326,61 @@
// 总数据包数
let currentPacket = 1;
let packetSize = 120;
let mode = imageData.length % packetSize;
let totalPackets = parseInt(imageData.length / packetSize) + (mode > 0 ? 1 : 0)
let totalPackets =7;
let childPacket=1;
let totalChildPacket=9;
let inteval = parseInt(this.inteval ? this.inteval : 100);
this.totalPackets = totalPackets;
this.totalPackets = 57;
// 发送单个数据包
var sendNextPacket = () => {
if (currentPacket > totalPackets) {
if (currentPacket> totalPackets) {
this.isSending = false;
resolve();
return;
}
var packetData = imageData[currentPacket-1][childPacket-1];
if(packetData.length==0){
this.isSending = false;
resolve();
return;
}
var start = 0;
var dataLength = 0;
var bufferSize = 0;
if (currentPacket == 1) {
bufferSize = packetSize * 2 + 5;
dataLength = packetSize * 2;
start = 5;
} else if (currentPacket == totalPackets) {
bufferSize = mode > 0 ? (mode * 2) : (packetSize * 2);
dataLength = bufferSize
} else {
bufferSize = packetSize * 2;
dataLength = bufferSize;
}
// 创建数据包
var startIndex = (currentPacket - 1) * packetSize;
var endIndex = Math.min(startIndex + packetSize, imageData.length);
if (startIndex > endIndex) {
return;
}
var packetData = imageData.slice(startIndex,
endIndex); // imageData.subarray(startIndex, endIndex);
// 构建数据包
var buffer = new ArrayBuffer(bufferSize);
var buffer = new ArrayBuffer(500);
var dataView = new DataView(buffer);
if (currentPacket == 1) { //第一包要填充头部
// 填充头部
dataView.setUint8(0, 0x70); // 帧头
dataView.setUint8(1, 0x65); // 帧头
dataView.setUint8(2, 0x0A); // 帧类型
dataView.setUint16(3, dataLength, false); //包长度
}
dataView.setUint8(0, 0xFB); // 帧头
dataView.setUint8(1, 0x09); // 帧头
dataView.setUint8(2, currentPacket); // 包序号
dataView.setUint8(3, childPacket); //子包序号
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
dataView.setUint16(4 + i * 2, packetData[i], false); //本包数据,大端字节序
}
if(packetData.length<248){
for (var i = 4+packetData.length*2; i < 500; i++) {
dataView.setUint8(i, 0xFF);
}
}
//发送数据包
this.sendData(buffer).then(() => {
// 更新进度
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) * totalPackets);
currentPacket++;
this.currentPacket =childPacket+ (currentPacket-1)*totalChildPacket;
this.progress = Math.round((this.currentPacket / this.totalPackets) * 100);
if(childPacket==9){
currentPacket++;
childPacket=1;
}else{
childPacket++;
}
setTimeout(sendNextPacket, inteval);
}).catch(err => {
@ -1332,7 +1412,7 @@
title: "请稍候....",
mask: true
});
this.addLog({
console.log({
date: Common.DateFormat(),
remark: '开始发送文字'
});
@ -1346,7 +1426,7 @@
let mode = rgbdata.length % packetSize; //最后一包的数量
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 : 0); //总包数量
let curr = 1; //当前包序号
this.addLog({
console.log({
date: Common.DateFormat(),
remark: '当前包' + curr
});
@ -1356,7 +1436,7 @@
resolve();
return;
}
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "正在向设备发送" + curr + "/" + cnt
})
@ -1372,13 +1452,13 @@
let buffer = new ArrayBuffer(bufferSize);
let dataView = new DataView(buffer);
let startIndex = (curr - 1) * packetSize;
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "分片大小" + bufferSize
})
let endIndex = Math.min(startIndex + packetSize, rgbdata.length);
if (startIndex > endIndex) {
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "发送完成"
})
@ -1386,7 +1466,7 @@
}
let packetData = rgbdata.slice(startIndex, endIndex); //取一片数据发送
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "获取到分片"
})
@ -1396,8 +1476,6 @@
dataView.setUint8(1, type);
dataView.setUint8(2, 0x01);
dataView.setUint8(3, 0x00);
// dataView.setUint16(2, str.length, false);
start = 4;
}
@ -1406,7 +1484,7 @@
}
dataView.setUint8(bufferSize - 1, 0xFF);
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "数据准备就绪"
})
@ -1414,7 +1492,7 @@
//发送数据包
this.sendData(buffer).then(() => {
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "发送成功,准备发送下一包"
})
@ -1422,7 +1500,7 @@
setTimeout(sendNext, inteval);
}).catch(err => {
console.log("err=", err);
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "出现错误" + JSON.stringify(err)
});
@ -1438,7 +1516,7 @@
sendNext();
} catch (ex) {
console.log("ex=", ex);
this.addLog({
console.log({
date: Common.DateFormat(),
remark: "出现异常1" + JSON.stringify(ex)
})
@ -1450,12 +1528,12 @@
}
// this.addLog({
// console.log({
// date: Common.DateFormat(),
// remark: '正在取模'
// });
var result = await this.$refs.textToHex.drawAndGetPixels();
// this.addLog({
// console.log({
// date: Common.DateFormat(),
// remark: '取模成功'
// });
@ -1464,6 +1542,19 @@
});
// console.log("result=",result);
// var str1="00 00 0E 58 7C 4C 08 44 08 40 7F FE 08 60 08 64 0B 6C 7F 38 78 30 08 72 08 D2 0B 9E 38 0C 00 00 00 00 1F F8 18 08 1F F8 18 18 18 18 1F F8 00 00 7F FE 01 80 19 80 19 F8 3D 80 67 80 61 FE 00 00 00 00 01 80 01 80 3F FC 3F FC 21 84 21 84 21 84 21 84 3F FC 21 84 01 80 01 80 01 80 01 80 00 00 00 00 7F FE 7F FE 60 06 6F F6 61 86 61 86 6F E6 61 86 61 A6 61 A6 6F F6 60 06 7F FE 7F FE 00 00 00 00 01 80 01 80 01 80 01 80 01 80 01 80 03 C0 02 40 06 60 0C 30 0C 10 38 1C 70 0E 40 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
// var str2="00 00 3F FC 3F 00 19 98 7F FE 7F FE 66 06 1F F8 04 00 0F F8 0F F8 1A 30 31 E0 73 F0 4E 1C 00 00 00 00 7F FE 7F FE 60 06 6F F6 61 86 61 86 6F E6 61 86 61 A6 61 A6 6F F6 60 06 7F FE 7F FE 00 00 00 00 01 00 3F F6 03 0C 01 18 7F FE 01 C0 03 80 1F F8 78 08 08 08 0F F8 08 08 0F F8 0F F8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
// var str3="00 00 3F FC 3F FC 01 80 01 80 01 00 7F FE 03 80 03 C0 02 40 06 60 0C 30 18 18 30 0C 60 06 00 00 00 00 7F FE 7F FE 01 00 01 00 01 C0 01 E0 01 38 01 0C 01 00 01 00 01 00 01 00 01 00 01 00 00 00 00 00 33 00 13 00 1B 00 7F FC 7F FC 02 04 02 04 02 84 06 C4 04 64 0C 24 18 0C 30 0C 60 78 00 00 00 00 04 20 0C 20 08 30 18 18 10 18 31 0C 63 06 43 02 06 20 04 30 0C 10 18 18 3F F8 18 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
// let arr1=('0x'+(str1.split(' ').join(",0x"))).split(',');
// let arr2=('0x'+(str2.split(' ').join(",0x"))).split(',');
// let arr3=('0x'+(str3.split(' ').join(",0x"))).split(',');
// result=[arr1,arr2,arr3];
console.log("result=",result);
let h3dic = [0x06, 0x07, 0x08];
let pros = [];
let flag = true;
@ -1475,7 +1566,7 @@
let width = str.length * 16;
var rgb = result[i];
this.addLog({
console.log({
date: Common.DateFormat(),
remark: '开始发送第' + (i + 1)
});
@ -1509,39 +1600,62 @@
// 发送数据通用方法
sendData(buffer) {
this.addLog("设备就绪,正在握手");
console.log("设备就绪,正在握手");
return new Promise((resolve, reject) => {
this.addLog("握手成功,正在发送");
this.addLog("设备id:" + this.connectedDeviceId);
this.addLog("服务id:" + this.serviceId);
this.addLog("特征id:" + this.writeCharacteristicId);
uni.writeBLECharacteristicValue({
deviceId: this.connectedDeviceId,
serviceId: this.serviceId,
characteristicId: this.writeCharacteristicId,
writeType:plus.os.name=='Android'?'writeNoResponse':'write',
value: buffer,
success: () => {
this.addLog({
date: Common.DateFormat(),
remark: "发送数据成功"
})
resolve();
},
fail: (err) => {
this.addLog({
date: Common.DateFormat(),
remark: "发送数据失败" + JSON.stringify(err)
})
reject(err);
},
complete: () => {
this.addLog({
date: Common.DateFormat(),
remark: "向设备写入数据完成"
})
console.log("握手成功,正在发送");
console.log("设备id:" + this.connectedDeviceId);
console.log("服务id:" + this.serviceId);
console.log("特征id:" + this.writeCharacteristicId);
let promise1=new Promise((succ,err)=>{
uni.writeBLECharacteristicValue({
deviceId: this.connectedDeviceId,
serviceId: this.serviceId,
characteristicId: this.writeCharacteristicId,
writeType:plus.os.name=='Android'?'writeNoResponse':'write',
value: buffer,
success: () => {
console.log({
date: Common.DateFormat(),
remark: "发送数据成功"
})
succ();
},
fail: (err) => {
console.log({
date: Common.DateFormat(),
remark: "发送数据失败" + JSON.stringify(err)
})
err(err);
},
complete: () => {
console.log({
date: Common.DateFormat(),
remark: "向设备写入数据完成"
})
}
});
});
let promise2=new Promise((succ,err)=>{
setTimeout(()=>{
err({
code: -1,
errMsg: '超时了'
});
},50)
})
Promise.race([promise1, promise2]).then(resolve).catch((ex) => {
console.log("ex=", ex);
if (ex.code == -1) {
resolve(ex);
} else {
reject(ex);
}
}).finally(() => {
//console.log("完成了")
});
});
},

File diff suppressed because it is too large Load Diff

View File

@ -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>

View File

@ -60,7 +60,7 @@
</view>
<view>重发包序号{{reSendNumber}}</view>
<view class="sending-progress" v-if="isSending">
<view class="progress-bar">
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
</view>
@ -226,11 +226,10 @@
<script>
import gbk from '@/utils/gbk.js';
import MqttClient from '@/utils/mqtt.js';
import {
request,
import request,{
baseURL
} from '@/utils/request.js';
var videoChannel=null;
var videoChannel = null;
var mqttClient = null;
export default {
data() {
@ -303,7 +302,7 @@
videoHeight: "",
videoDuration: "",
currentSOS: "",
reSendNumber:null
reSendNumber: null
}
},
computed: {
@ -678,51 +677,47 @@
);
} else {
try {
let json=JSON.parse(str);
if("staBlue_picture" in json){
let json = JSON.parse(str);
if ("staBlue_picture" in json) {
//重发图片
console.log("收到重新发送图片的命令");
this.reSendNumber=json.staBlue_picture;
setTimeout(()=>{
this.sendImagePackets(this.rgb565Data,json.staBlue_picture);
},0);
return ;
}
else if("staBlue_text" in json){
this.reSendNumber = json.staBlue_picture;
setTimeout(() => {
this.sendImagePackets(this.rgb565Data, json.staBlue_picture);
}, 0);
return;
} else if ("staBlue_text" in json) {
//重发文本
console.log("收到重新发送文本的命令");
this.reSendNumber=json.staBlue_text;
setTimeout(()=>{
this.sendText(null,json.staBlue_text);
},0)
return ;
}
else if("staBlue_vidio" in json){
this.reSendNumber = json.staBlue_text;
setTimeout(() => {
this.sendText(null, json.staBlue_text);
}, 0)
return;
} else if ("staBlue_vidio" in json) {
//重发视频
console.log("收到重新发送视频的命令");
videoChannel.emit("ReSendVideo", {
videoNo:json.staBlue_vidio
videoNo: json.staBlue_vidio
});
return ;
}
else if("staBlue" in json){
if(json.staBlue=="finish"){
return;
} else if ("staBlue" in json) {
if (json.staBlue == "finish") {
console.log("收到设备回复,全部传输完成");
}
return ;
}
else{
return;
} else {
console.log("无法解析该文本");
}
} catch (error) {
console.log("文本解析失败")
}
@ -1471,11 +1466,10 @@
events: {
ImgCutOver: function(data) {
console.log("111111");
console.log("data=", data.length);
console.log("data=", data);
these.rgb565Data = these.convertToRGB565(
data);
console.log("rgb565=", these.rgb565Data
.length);
data.piexls);
console.log("rgb565=", these.rgb565Data);
},
ImgCutOver_Path: function(data) {
these.tempImagePath = data;
@ -1627,7 +1621,7 @@
this.currentPacket = ReSendNo;
this.currentPacket = ReSendNo;
totalPackets = ReSendNo;
currentPacket=ReSendNo;
currentPacket = ReSendNo;
}
// 发送单个数据包
let sendNextPacket = () => {
@ -1635,9 +1629,9 @@
this.isSending = false;
if (!ReSendNo) {
this.bleSendComplete();
}else{
// this.reSendNumber="";
}
} else {
// this.reSendNumber="";
}
resolve();
return;
}
@ -1742,11 +1736,11 @@
reject(err);
});
}
if(ReSendNo){
if (ReSendNo) {
sendNextPacket();
}else{
HoldYouHand();
} else {
HoldYouHand();
}
});
@ -1877,7 +1871,7 @@
console.log('文字发送完成');
if (!ReSendNo) {
this.bleSendComplete();
}else{
} else {
// this.reSendNumber="";
}
@ -2002,10 +1996,9 @@
});
});
}
if(!ReSendNo){
HoldYouHand();
}
else{
if (!ReSendNo) {
HoldYouHand();
} else {
sendNextPacket();
}
@ -2017,14 +2010,14 @@
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
setTimeout(()=>{
setTimeout(() => {
this.sendData(buffer).then(() => {
console.log("完成指令发送成功");
}).catch(err => {
console.log("完成指令发送失败");
});
},500)
}, 500)
},
// 将文字转换为GBK编码使用第三方库或API
convertToGBK(text) {
@ -2074,7 +2067,7 @@
url: "/pages/BlueTooth/ModeSetting/VideoSend_670",
success: (res) => {
let channel = res.eventChannel;
videoChannel=channel;
videoChannel = channel;
channel.emit("receiveDevice", {
connectedDeviceId: this.connectedDeviceId,
serviceId: this.serviceId,
@ -2085,7 +2078,7 @@
});
},
fail(ex) {
console.log("出现异常,",ex);
console.log("出现异常,", ex);
}
})
},

View File

@ -1,11 +1,11 @@
<template>
<view class="content">
<canvas canvas-id="flashCanvas"
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
<f-video ref="compARef" :src="videoPath" :direction="-90" :autoplay="true" @shotVideoClick="shotVideoClick"
:videoWidth="videoWidth" :videoHeight="videoHeight"></f-video>
<view>
重发包序号:{{reSendNumber}}
</view>
<view>
<text>发送间隔</text>
@ -13,7 +13,7 @@
</view>
<view>
<button @click="checkVideo">选择视频</button>
<!-- <button @click="CutImg">发送</button> -->
<button @click="uploadVideo">发送</button>
</view>
@ -28,8 +28,8 @@
</view>
</template>
<script>
import Common from '@/utils/Common';
<script>
import Common from '@/utils/Common';
export default {
data() {
@ -51,7 +51,7 @@ import Common from '@/utils/Common';
videoWidth: 320,
videoHeight: 160,
videoDuration: 2,
reSendNumber:null,
hexArray: []
}
@ -64,7 +64,17 @@ import Common from '@/utils/Common';
this.serviceId = data.serviceId;
this.writeCharacteristicId = data.writeCharacteristicId;
this.notifyCharacteristicId = data.notifyCharacteristicId;
})
});
eventChannel.on('ReSendVideo', (data) => {
//重新发送某一包
this.reSendNumber = data.videoNo;
setTimeout(() => {
this.shotVideoClick(this.hexArray, 'rgb565', data.videoNo);
}, 0);
});
},
methods: {
checkVideo: function() {
@ -76,9 +86,12 @@ import Common from '@/utils/Common';
success: (res) => {
this.videoPath = res.tempFilePath;
this.imgs = [];
this.hexArray = [];
this.$refs.compARef.base64 = [];
this.videoWidth = res.width;
this.videoHeight = res.height;
this.videoDuration = res.duration;
@ -95,24 +108,25 @@ import Common from '@/utils/Common';
return;
}
if(!this.videoPath){
if (!this.videoPath) {
uni.showToast({
title: "请选择视频",
icon: 'fail'
})
return;
}
console.log("正在上传视频");
uni.showLoading({
title: "上传中"
});
let p2=new Promise((resolve,reject)=>{
let p2 = new Promise((resolve, reject) => {
let start = new Date();
console.log("Common.baseURL="+Common.baseURL);
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: {
@ -138,28 +152,28 @@ import Common from '@/utils/Common';
uni.hideLoading();
resolve(res);
}
});
});
let p1=this.HoldYouHand();
Promise.all([p2,p1]).then((arr)=>{
if(arr[1]===true){
let res=arr[0];
let p1 = this.HoldYouHand();
Promise.all([p2, p1]).then((arr) => {
if (arr[1] === true) {
let res = arr[0];
res = JSON.parse(res.data);
if (res.data) {
this.hexArray = res.data;
uni.showLoading({
title: "正在发送"
});
setTimeout(() => {
this.shotVideoClick(res.data, 'rgb565');
}, 0)
} else {
console.log("res")
uni.showModal({
@ -167,24 +181,39 @@ import Common from '@/utils/Common';
title: '错误'
})
}
}else{
} else {
uni.showModal({
content:"与设备握手失败了",
title:"错误"
content: "与设备握手失败了",
title: "错误"
})
}
});
},
shotVideoClick: function(array, type) {
bleSendComplete() {
var str = "transmit complete"; //握手的协议字符串
let buffer = new ArrayBuffer(str.length);
let dataView = new DataView(buffer);
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
setTimeout(() => {
this.sendData(buffer).then(() => {
console.log("完成指令发送成功");
}).catch(err => {
console.log("完成指令发送失败");
});
}, 3000)
},
shotVideoClick: function(array, type, ReSendNo) {
//console.log("处理视频完成", array);
//console.log("type=" + type)
//console.log("array=", array);
this.imgs = array;
var sendImagePackets = (imageData) => {
return new Promise((resolve, reject) => {
@ -197,12 +226,25 @@ import Common from '@/utils/Common';
const totalPackets = 1536;
this.totalPackets = totalPackets;
let currentPacket = 1;
if (ReSendNo) {
console.log("11111");
this.progress = ReSendNo - 1;
this.currentPacket = ReSendNo - 1;
console.log("22222");
this.totalPackets = ReSendNo;
console.log("11111=",ReSendNo);
}
// 发送单个数据包
const sendNextPacket = () => {
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
if (currentPacket > totalPackets) {
this.isSending = false;
if (!ReSendNo) {
this.bleSendComplete();
} else {
// this.reSendNumber="";
}
resolve();
return;
@ -221,11 +263,11 @@ import Common from '@/utils/Common';
resolve();
return;
}
////console.log("111111");
console.log("111111");
const packetData = imageData.slice(startIndex, endIndex);
// 构建数据包
////console.log("packetData.length"+packetData.length);
console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
@ -256,11 +298,16 @@ import Common from '@/utils/Common';
let inteval = parseInt(this.inteval ? this.inteval : 0);
this.sendData(buffer).then(() => {
if(ReSendNo){
this.isSending = false;
resolve();
return;
}
// 更新进度
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) *
100);
//console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
currentPacket++;
@ -277,8 +324,8 @@ import Common from '@/utils/Common';
});
};
sendNextPacket();
@ -294,12 +341,13 @@ import Common from '@/utils/Common';
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff-s) / 60;
let m = (diff - s) / 60;
console.log("发送完成,耗时:" + m + "分" + s + "秒");
uni.showToast({
title: "发送完成,耗时:" + m + "分" + s + "秒",
icon: 'success'
})
uni.showModal({
content:"发送完成,耗时:" + m + "分" + s + "秒",
title:"提示"
});
}).catch((ex1) => {
//console.log("出现了异常", ex1)
}).finally(() => {
@ -312,17 +360,17 @@ import Common from '@/utils/Common';
},
HoldYouHand() {
var promise=new Promise((resolve,reject)=>{
try{
let start=new Date();
var promise = new Promise((resolve, reject) => {
try {
let start = new Date();
var str = "video transmit start"; //握手的协议字符串
console.log("开始握手:"+str)
console.log("开始握手:" + str)
// 1. 创建 ArrayBuffer 和 DataView
const buffer = new ArrayBuffer(str.length);
const dataView = new DataView(buffer);
// 2. 将字符串转换为 ASCII 码并写入 DataView
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
@ -330,31 +378,31 @@ import Common from '@/utils/Common';
//console.log("111111");
this.sendData(buffer).then(() => {
// 开始发送第一个包
setTimeout(()=>{
setTimeout(() => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
resolve(true);
console.log("握手成功并完成2200ms等待,耗时" + m + "分" + s + "秒");
resolve(true);
}, 2200);
}).catch(err => {
//console.log("握手没有成功");
reject(err);
});
}catch(ex){
} catch (ex) {
reject(ex);
}
});
return promise;
},
sendData(buffer) {
////console.log("deviceId=" + this.connectedDeviceId);
@ -415,18 +463,8 @@ import Common from '@/utils/Common';
promise.then(resolve).catch(reject);
}
});
},
CutImg: function() {
if (this.imgs.length == 30) {
this.shotVideoClick(this.imgs, 'img');
return;
}
//console.log("开始处理视频")
uni.showLoading({
title: '开始处理'
});
this.$refs.compARef.shotVideoClick(0);
}
}
}
</script>
@ -469,4 +507,19 @@ import Common from '@/utils/Common';
align-items: center;
justify-content: center;
}
.splash-frame {
height: 320rpx;
width: 640rpx;
border: 2rpx solid #409eff;
border-radius: 8rpx;
overflow: hidden;
position: relative;
background-color: #f0f0f0;
}
.splash-frame image {
width: 100%;
height: 100%;
}
</style>

View File

@ -1,8 +1,6 @@
<template>
<view class="content">
<canvas canvas-id="flashCanvas"
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
<view>
<view>
选择的视频:{{videoPath}}</view>
@ -287,6 +285,11 @@ var mqttClient=null;
let inteval = parseInt(this.inteval ? this.inteval : 0);
this.sendData(buffer).then(() => {
if(ReSendNo){
this.isSending = false;
resolve();
return;
}
// 更新进度
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) *
@ -401,7 +404,7 @@ var mqttClient=null;
}).catch(err => {
console.log("完成指令发送失败");
});
},1500)
},3000)
},
sendData(buffer) {

View File

@ -19,10 +19,10 @@
name: '/pages/BlueTooth/ModeSetting/HBY650',
url: 'HBY650'
},
{
name: '/pages/BlueTooth/ModeSetting/HBY650_1',
url: 'HBY650_V1'
},
// {
// name: '/pages/BlueTooth/ModeSetting/HBY650_1',
// url: 'HBY650_V1'
// },
{
name: '/pages/BlueTooth/ModeSetting/HBY6155',
@ -36,7 +36,10 @@
name: "/pages/BlueTooth/ModeSetting/HBY670V1",
url: 'HBY670'
},
{
name: "/pages/BlueTooth/ModeSetting/4877",
url: '4877'
},
{
name: '/pages/MapTest/MapTest',
url: '地图测试'

View File

@ -12,14 +12,14 @@
设备名:{{device.deviceName}}
</view>
<view class="deviceId">
ID:{{device.deviceId}}
设备Mac:{{device.macAddress}}
</view>
<view class="bound" v-bind:class="boundStatu">
{{Statu.boundRemark}}
</view>
</view>
<view class="btnLink" @click="Link()">
连接
绑定
</view>
<global-loading ref="loading" />
@ -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,92 +86,105 @@
onLoad(option) {
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback((receive,f,path) => {
console.log("LinkBle")
ble.addReceiveCallback((receive, f, path) => {
console.log("收到设备消息,", receive);
if (these.device.deviceId == receive.deviceId) {
// console.log("11111");
console.log("11111:",receive);
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
if (f && f.macAddress) {
these.device.macAddress = f.macAddress;
// console.log("222222");
console.log("222222");
these.initDevice();
}
}
}
},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 +222,22 @@
if (res.code == 200) {
these.Statu.bound = true;
these.Statu.boundRemark = "设备绑定成功!";
let data=these.serverDevice;
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];
}
ble.updateCache();
}
});
ble.removeReceiveCallback(pagePath);
uni.$emit("refreshDeviceList");
@ -222,6 +253,7 @@
}).catch((ex) => {
these.Statu.bound = false;
these.Statu.boundRemark = '出现了未知的异常,操作失败';
console.log("ex=",ex);
}).finally(() => {
hideLoading(this);
});

View File

@ -97,6 +97,7 @@
const pagePath="pages/common/addBLE/addEquip";
var ble = null;
var these = null;
var eventChannel=null;
export default {
data() {
return {
@ -128,7 +129,11 @@
},
PairEquip: [], //已配对设备
EquipMents: [] //搜索出来的设备
EquipMents: [], //搜索出来的设备
device:null,
item:{
deviceId:''
}
}
},
computed: {
@ -145,7 +150,8 @@
},
onUnload(){
ble.StopSearch();
ble.removeDeviceFound(pagePath);
ble.removeReceiveCallback(pagePath);
},
onLoad() {
these = this;
@ -170,13 +176,23 @@
}
}
},pagePath);
// ble.addReceiveCallback((receivData) => {
}, pagePath);
// console.log("addEquip")
// ble.addReceiveCallback((receivData,f,path,arr) => {
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
// if (this.item.deviceId == receivData.deviceId) {
// console.log("11111:",receivData);
// // let data=uni.getStorageSync(ble.StorageKey);
// console.log("LinkedList=",ble.data.LinkedList);
// },pagePath);
// }
// });
eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', function(rec) {
console.log("接收到父页面的参数:",rec);
these.device=rec.data;
});
},
onShow: function() {
@ -223,7 +239,7 @@
ble.showBlueSetting(false);
},
Link: function(item, index) {
this.item.deviceId=item.deviceId;
showLoading(this,{
text: "正在连接"
});
@ -241,6 +257,18 @@
these.PairEquip.push(item);
}
console.log("连接成功");
if(these.device){//从设备详情过来的,回设备详情去
ble.data.LinkedList.find(v=>{
if(v.deviceId==item.deviceId){
v.device=these.device;
return true;
}
return false;
});
ble.updateCache();
uni.navigateBack();
return;
}
uni.navigateTo({
url:"/pages/common/addBLE/LinkBle",
events:{

View File

@ -144,6 +144,8 @@
deviceUnbind, //删除设备
deviceReName
} from '@/api/common/index.js'
import BleHelper from '@/utils/BleHelper.js';
var ble=null;
export default {
onPullDownRefresh() {
// 执行下拉刷新时的操作,比如重新获取数据
@ -388,7 +390,9 @@
}, 500);
this.deleteShow = false
// 关闭所有滑动项
this.$refs.swipeAction.closeAll();
this.$refs.swipeAction.closeAll();
ble && ble.DropDevice(data.id);
} else {
uni.showToast({
title: res.msg,
@ -555,6 +559,7 @@
console.log('列表收到消息了么');
this.onIntall()
});
ble=BleHelper.getBleTool();
},
beforeDestroy() {
// 组件销毁前移除监听器