650添加应答,app图标添加

This commit is contained in:
liub
2025-09-15 11:55:44 +08:00
parent 6ee45f6868
commit 9c9c684ab6
27 changed files with 31504 additions and 7864 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);

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>
@ -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,7 +143,7 @@
</template>
<script>
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
import bleTool from '@/utils/BleHelper.js';
import {
@ -153,7 +153,11 @@
} from '@/utils/loading.js'
var ble = null;
var these = null;
var BrighInteval = null;
export default {
components: {
TextToHexV1
},
data() {
return {
Status: {
@ -221,10 +225,10 @@
liangDu: '100',
id: '',
deviceId: '',
textLines: ['我爱你', '中国', '五星红旗'],
textLines: ['', '', ''],
mode: ''
},
inteval: 200
}
},
@ -234,7 +238,52 @@
onLoad: function() {
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback(these.bleValueNotify);
// 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();
// }
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', function(data) {
@ -243,7 +292,7 @@
let device = data.data;
console.log("收到父页面的参数:" + JSON.stringify(device));
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
if (v.deviceId == device.deviceId) {
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
@ -310,8 +359,8 @@
},
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;
});
@ -382,6 +431,15 @@
this.formData.battary = batteryLevel;
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) {
@ -390,7 +448,7 @@
}
},
proParam: function() {
uni.navigateTo({
@ -433,10 +491,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 +549,114 @@
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;
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
resolve();
setTimeout(()=>{
hideLoading(these);
these.Status.BottomMenu.show = false;
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
resolve();
},20000)
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;
// }
if (packetData.length == 250) {
dataView.setUint8(3, 0x01);
dataView.setUint8(4, 0xF4);
} else {
dataView.setUint8(3, 0x00);
dataView.setUint8(4, 0x64);
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==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 +694,8 @@
these.Status.BottomMenu.show = false;
setTimeout(function() {
processAndSendImageData(data.piexls).catch((ex) => {
processAndSendImageData(data.piexls).catch((
ex) => {
console.log("出现异常", ex);
});
}, 0)
@ -617,7 +745,7 @@
{
text: '爆闪',
icon: '/static/images/6155/DeviceDetail/shan.png'
},
},
{
text: '关闭',
icon: '/static/images/6155/DeviceDetail/close.png'
@ -668,20 +796,23 @@
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 = 0x0A;
}
break;
case 1:
dataValue = 0x04;
@ -693,11 +824,11 @@
dataValue = 0x03;
break;
case 4:
dataValue = 0x00;
dataValue = 0x0B;
break;
}
console.log("dataValue=", dataValue)
// 构建数据包
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
@ -817,8 +948,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 +962,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 +976,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 +984,7 @@
dataView.setUint8(2, 0x01);
dataView.setUint8(3, 0x00);
// dataView.setUint16(2, str.length, false);
start = 4;
}
@ -862,8 +994,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 +1024,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 +1069,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,7 +1085,7 @@
hideLoading(these);
if (flag) {
console.log("发送成功");
this.showPop( {
this.showPop({
message: "发送成功"
});
} else {
@ -956,23 +1112,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

@ -1382,7 +1382,7 @@
}).catch((ex) => {
console.log("出现异常", ex);
});
}, 500);
}, 3000);
}
these.Status.BottomMenu.show = false;

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>
@ -230,7 +230,7 @@
request,
baseURL
} from '@/utils/request.js';
var videoChannel=null;
var videoChannel = null;
var mqttClient = null;
export default {
data() {
@ -303,7 +303,7 @@
videoHeight: "",
videoDuration: "",
currentSOS: "",
reSendNumber:null
reSendNumber: null
}
},
computed: {
@ -678,51 +678,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 +1467,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 +1622,7 @@
this.currentPacket = ReSendNo;
this.currentPacket = ReSendNo;
totalPackets = ReSendNo;
currentPacket=ReSendNo;
currentPacket = ReSendNo;
}
// 发送单个数据包
let sendNextPacket = () => {
@ -1635,9 +1630,9 @@
this.isSending = false;
if (!ReSendNo) {
this.bleSendComplete();
}else{
// this.reSendNumber="";
}
} else {
// this.reSendNumber="";
}
resolve();
return;
}
@ -1742,11 +1737,11 @@
reject(err);
});
}
if(ReSendNo){
if (ReSendNo) {
sendNextPacket();
}else{
HoldYouHand();
} else {
HoldYouHand();
}
});
@ -1877,7 +1872,7 @@
console.log('文字发送完成');
if (!ReSendNo) {
this.bleSendComplete();
}else{
} else {
// this.reSendNumber="";
}
@ -2002,10 +1997,9 @@
});
});
}
if(!ReSendNo){
HoldYouHand();
}
else{
if (!ReSendNo) {
HoldYouHand();
} else {
sendNextPacket();
}
@ -2017,14 +2011,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 +2068,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 +2079,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,24 @@ 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',
filePath: this.videoPath,
name: 'file',
header: {
@ -138,28 +151,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 +180,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 +225,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 +262,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 +297,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 +323,8 @@ import Common from '@/utils/Common';
});
};
sendNextPacket();
@ -294,12 +340,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 +359,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 +377,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 +462,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 +506,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: '地图测试'