From 294d85486712b486d43ba1b88414850d999cd88d Mon Sep 17 00:00:00 2001 From: liub Date: Thu, 20 Nov 2025 16:40:14 +0800 Subject: [PATCH] =?UTF-8?q?670=E5=8A=A0=E5=85=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E6=94=B6=E5=88=B0=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- pages/6155/deviceDetail.vue | 427 ++++++++++++++++++++++++++++--- pages/650/HBY650.vue | 2 +- pages/670/HBY670.vue | 40 ++- pages/common/addBLE/addEquip.vue | 2 +- utils/BleHelper.js | 4 +- utils/BleReceive.js | 4 +- utils/request.js | 2 +- 8 files changed, 433 insertions(+), 50 deletions(-) diff --git a/manifest.json b/manifest.json index 9a059e7..a9d9a5c 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name" : "星汉物联", "appid" : "__UNI__A21EF43", "description" : "设备管控", - "versionName" : "1.0.6", + "versionName" : "1.0.7", "versionCode" : "100", "transformPx" : false, /* 5+App特有相关 */ diff --git a/pages/6155/deviceDetail.vue b/pages/6155/deviceDetail.vue index 25d0e73..6c8b781 100644 --- a/pages/6155/deviceDetail.vue +++ b/pages/6155/deviceDetail.vue @@ -3,7 +3,7 @@ - + @@ -23,15 +23,15 @@ - + 设备名称 {{device.deviceName}} - Mac地址 - {{device.deviceMac}} - + Mac地址 + {{device.deviceMac}} + 设备状态 {{formData.statu}} @@ -86,6 +86,15 @@ 上传 + + + + + + 开机视频 + 上传 + + @@ -162,6 +171,10 @@ updateLoading } from '@/utils/loading.js' import BleReceive from '@/utils/BleReceive'; + import { + baseURL + } from '@/utils/request.js'; + var pagePath = "/pages/6155/HBY6155"; var ble = null; @@ -246,7 +259,7 @@ mode: '', bleStatu: '' }, - inteval: 200, + inteval: 80, device: { id: "", deviceName: "", @@ -360,7 +373,7 @@ } these.formData.blename = f.name ? f.name : "Unname"; these.formData.deviceName = device.deviceName; - + these.formData.id = device.id; these.formData.deviceId = f.deviceId; these.formData.bleStatu = false; @@ -619,7 +632,7 @@ // 创建RGB565格式的像素数据 // console.log("pixels=",pixels); const arr = ble.convertToRGB565(pixels, 'bgr'); - + var list = []; let index = 0; // 用于追踪arr的当前位置 let packetSize = 3200; @@ -631,12 +644,12 @@ // 中层循环:每个主要元素包含9个子数组(j从1到9) for (let j = 1; j < 9; j++) { // 确定当前子数组的长度:前8个是254,第9个是64 - + let thirdLevel = []; - + // 从arr中提取相应数量的元素 for (let k = 0; k < cSize && index < arr.length; k++) { - + if (secondCnt == packetSize) { break; } @@ -644,14 +657,14 @@ 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]; @@ -661,8 +674,8 @@ console.log("第" + i + "包,第" + j + "小包,长度:" + element.length) length += element.length; clength += element.length; - - + + } } // 分包发送 @@ -680,37 +693,39 @@ let currentPacket = 1; let childPacket = 1; let totalChildPacket = 8; - - + + // 发送单个数据包 const sendNextPacket = () => { if (currentPacket > totalPackets) { - updateLoading(these,{text:'发送完成,等待设备30秒'}); + updateLoading(these, { + text: '发送完成,等待设备30秒' + }); setTimeout(() => { hideLoading(these); these.Status.BottomMenu.show = false; - + these.showPop({ message: "上传成功", iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png", borderColor: '#BBE600', buttonBgColor: '#BBE600' }); - + resolve(); }, 0) - + return; } - + var packetData = imageData[currentPacket - 1][childPacket - 1]; console.log("childPacket=", childPacket); console.log("packetData=", packetData); let start = 0; let bufferSize = packetData.length * 2; - - - + + + if (childPacket == 1) { bufferSize = bufferSize + 8 start = 8; @@ -718,8 +733,8 @@ if (childPacket == 8) { //|| (currentPacket==7 && childPacket==3 bufferSize = bufferSize + 1 } - - + + //FA 09 0C 84 FB 09 00 [01~08] + 3200字节 +FF 数据格式 var buffer = new ArrayBuffer(bufferSize); var dataView = new DataView(buffer); @@ -733,7 +748,7 @@ dataView.setUint8(6, 0x00); // 帧头 dataView.setUint8(7, currentPacket); //包序号 } - + for (let i = 0; i < packetData.length; i++) { dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序 } @@ -742,19 +757,19 @@ if (childPacket == 8) { // || (currentPacket==7 && childPacket==3 dataView.setUint8(bufferSize - 1, 0xFF); } - + //发送数据包 ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30) .then(() => { - + let curr = childPacket + (currentPacket - 1) * totalChildPacket; console.log("第" + currentPacket + "大包,第" + childPacket + "小包发送完成,总计:" + curr); updateLoading(these, { text: "正在发送" + curr + "/64" - + }) if (childPacket == 8) { currentPacket++; @@ -762,16 +777,16 @@ } else { childPacket++; } - + setTimeout(sendNextPacket, 100); }).catch(err => { if (err.code == 10007) { setTimeout(sendNextPacket, 100); return; } - + console.log("发送数据包失败了", err); - + these.Status.BottomMenu.show = false; these.showPop({ message: "发送数据包失败了" + err.msg, @@ -779,14 +794,14 @@ borderColor: "#e034344d", buttonBgColor: "#E03434", }); - + hideLoading(these); reject(err); }); } // 开始发送数据 sendNextPacket(); - + }); } @@ -828,6 +843,344 @@ } }); }, + + UploadOpenVideo: function() { //开机动画 + let f = these.getDevice(); + + if (!f) { + these.showBleUnConnect(); + return; + } + + let timeDelayCloseLoading = () => { + setTimeout(() => { + hideLoading(these); + }, 1500); + } + //视频上传 + let uplploadVideo = (videoPath) => { + + return new Promise((resolve, reject) => { + let start = new Date(); + + let token = uni.getStorageSync('token'); + let clientid = uni.getStorageSync('clientID'); + uni.uploadFile({ + + url: baseURL + "/app/video/upload", + filePath: videoPath, + name: 'file', + header: { + "Method": "POST", + "Content-Type": "multipart/form-data", + "Authorization": 'Bearer ' + token, + "clientid": clientid + }, + formData: { + code: 2 + }, + timeout: 600000, + fail: (ex) => { + + updateLoading(these, { + text: '视频文件上传失败了,请检查网络连接' + }); + + reject(ex); + }, + success: (res) => { + // console.error(res); + let end = new Date(); + var diff = (end.getTime() - start.getTime()) / 1000; + let s = diff % 60; + let m = parseInt((diff - s) / 60); + console.log("res.statusCode==", res.statusCode); + res.data = JSON.parse(res.data); + + if (res.statusCode === 200) { + if (res.data.code == 200) { + console.log("上传完成,耗时:" + m + "分" + s + "秒"); + updateLoading(these,{text:"上传完成,耗时:" + m + "分" + s + "秒,正在切片。"}) + resolve(res.data); + + return; + } + + } + console.error("上传完成,耗时:" + m + "分" + s + "秒"); + reject(res); + + } + + }); + + }); + + + + } + + //视频切片 + let videoCutPacket = (array) => { + return new Promise((resolve, reject) => { + try { + let imgSize = 25600; + let packetSize = 3200; + let tdSize = 500; + + let results = []; + for (let i = 0; i < 30; i++) { //先切出30张,每张25600字节 + let packet = array.slice(0, imgSize); + array.splice(0, imgSize) + + let secondLevel = []; + for (let j = 0; j < 8; j++) { //每张切8大包,每包3200字节 + let childPacket = packet.slice(0, packetSize); + + packet.splice(0, packetSize); + + let thirdLevel = []; + for (let k = 0; k < 7; k++) { //每1个大包切出7个小包,前6包500字节,第7包200字节,共计56小包 + + let arr = childPacket.slice(0, tdSize); + + childPacket.splice(0, tdSize) + thirdLevel.push(arr); + } + secondLevel.push(thirdLevel); + } + results.push(secondLevel); + } + updateLoading(these,{text:'切片完成,正在发送'}); + resolve(results); + } catch (error) { + updateLoading(these, { + text: '视频切片发生异常' + }); + reject(error); + } + }); + + + + + } + + //发送视频到设备 + let shotVideoClick = (array, type, ReSendNo) => { + var sendImagePackets = () => { + return new Promise((resolve, reject) => { + + + + this.currentPacket = 0; + + // 总数据包数 + var totalPackets = 1680; + this.totalPackets = totalPackets; + let currentPacket = 1; + + let imgIndex = 0; + let imgPackIndex = 0; + let childPacketIndex = 0; + if (ReSendNo) { + + this.currentPacket = ReSendNo - 1; + currentPacket = ReSendNo; + totalPackets = ReSendNo; + this.totalPackets = ReSendNo; + } + // 发送单个数据包 + const sendNextPacket = () => { + // console.log("111111") + if (currentPacket > totalPackets) { + resolve(); + + return; + } + // console.log("111111") + // 计算当前包的数据 + let packetSize = 500; + + if ((currentPacket - 1) % 56 === 0) { + + packetSize = 508; + + } + + if (childPacketIndex === 6) { + packetSize = 200; + } + + if ((currentPacket - 1) % 56 === 55) { + packetSize = 201; + } + + console.log("imgIndex=" + imgIndex + ",imgPackIndex=" + + imgPackIndex + + ",childPacketIndex=" + childPacketIndex) + + let packetData = array[imgIndex][imgPackIndex][childPacketIndex]; + + let buffer = new ArrayBuffer(packetSize); + let dataView = new DataView(buffer); + + let sortNo = currentPacket.toString(16).padStart(4, '0'); + // console.log("11111"); + let start = 0; + if ((currentPacket - 1) % 56 === 0) { + // 填充头部 + dataView.setUint8(0, 0xFA); // 帧头 + dataView.setUint8(1, 0x09); // 帧类型:开机画面 + dataView.setUint8(2, 0x0C); + dataView.setUint8(3, 0x84); + + + dataView.setUint8(4, 0xFD); + dataView.setUint8(5, 0x09); + dataView.setUint8(6, imgIndex); + dataView.setUint8(7, imgPackIndex + 1); + start = 8; + } + console.log("222222"); + for (let i = 0; i < packetData.length; i++) { + dataView.setUint8(start + i, '0x' + packetData[i]); + } + // console.log("333333333"); + if ((currentPacket - 1) % 56 === 55) { + dataView.setUint8(200, 0xFF); + } + // console.log("444444"); + let inteval = parseInt(this.inteval ? this.inteval : 80); + + ble.sendData(f.deviceId, buffer, f.writeServiceId, f + .wirteCharactId, ).then(() => { + if (ReSendNo) { + + resolve(); + return; + } + // 更新进度 + this.currentPacket = currentPacket; + + updateLoading(these,{ + text:'正在发送:'+currentPacket+"/"+totalPackets + }); + + + childPacketIndex++; + if (childPacketIndex == 7) { + imgPackIndex++; + if (imgPackIndex == 8) { + imgIndex++; + imgPackIndex = 0; + } + childPacketIndex = 0; + } + // 发送下一个包(添加延迟避免蓝牙缓冲区溢出) + currentPacket++; + + + + setTimeout(sendNextPacket, inteval); + }).catch(err => { + if (err.code == 10007) { + console.error(err.errMsg + ",发送失败了,正在补偿:" + + currentPacket); + setTimeout(sendNextPacket, 100); + return; + } + + console.error(err.errMsg + ",发送失败了" + currentPacket); + updateLoading(these,{text:"发送失败,"+err.errMsg}); + reject(err); + }); + }; + + + // console.log("111111") + + sendNextPacket(); + + }); + } + + return sendImagePackets(); + + + + } + + uni.chooseVideo({ + sourceType: ['album'], + success: function(res) { + console.log("res=",res); + let path = res.tempFilePath; + let width = res.width; + let height = res.height; + let duration = res.duration; + let err = []; + if (duration < 2) { + err.push("视频时长至少2秒"); + } + + if (width != 160 || height != 80) { + err.push("视频宽高必须是160*80"); + } + if (err.length > 0) { + err = err.join(";"); + these.showPop({ + message: err, + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + }); + return; + } + showLoading(these, { + text: '正在上传' + }); + setTimeout(() => { + uplploadVideo(path).then(result => { + + videoCutPacket(result.data).then(array => { + + let start = new Date(); + console.log("开始发送"); + shotVideoClick(array).then(() => { + console.log("发送完成"); + let end = new Date(); + var diff = (end.getTime() - start.getTime()) / 1000; + let s =parseInt(diff % 60); + let m =parseInt((diff - s) / 60); + console.log("发送完成,耗时:" + m + "分" + s + "秒"); + updateLoading(these,{ + text: "发送完成,耗时:" + m + "分" + s + "秒", + }); + + }).catch((ex1) => { + console.log("出现了异常", ex1) + }).finally(() => { + timeDelayCloseLoading(); + }); + + + + + }).catch(err => { + timeDelayCloseLoading(); + }); + + }).catch(ex => { + timeDelayCloseLoading(); + }); + }, 0); + + } + }); + + + }, UploadOpenImg: function() { //上传开机画面 this.Status.BottomMenu.menuItems = []; diff --git a/pages/650/HBY650.vue b/pages/650/HBY650.vue index 62eea59..c5be0eb 100644 --- a/pages/650/HBY650.vue +++ b/pages/650/HBY650.vue @@ -1007,7 +1007,7 @@ dataView.setUint8(6 + i, '0x' + packetData[i]); } - let inteval = 50; + let inteval = 30; console.log("开始发送一段视频"); // ble.sendData(f.deviceId, buffer, f.writeServiceId, f .wirteCharactId, 10).then(() => { diff --git a/pages/670/HBY670.vue b/pages/670/HBY670.vue index 6374408..6d78fae 100644 --- a/pages/670/HBY670.vue +++ b/pages/670/HBY670.vue @@ -309,6 +309,8 @@ data() { return { Status: { + msgOkIntval:null,//紧急通知等待的时间 + msgOkTime:null,// pageHide: false, apiType: "listA", navbar: { @@ -465,6 +467,8 @@ onUnload() { console.log("页面卸载,释放资源"); let statusTopic = `A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`; + clearInterval(these.Status.staticWarn.inteval); + clearInterval(this.Status.msgOkIntval); ble.removeAllCallback(pagePath); if (mqttClient) { mqttClient.unsubscribe(statusTopic); @@ -863,10 +867,22 @@ // console.log("收到文本回复", payload); // // this.SendTxtMQ(json); // } - // else if (keys.indexOf('sta_BreakNews') > -1) { //紧急通知 - // console.log("收到紧急消息回复", payload); - // // this.sendUrgentMQ(json); - // } + if (keys.indexOf('sta_BreakNews') > -1) { //紧急通知 + if(json.sta_BreakNews==='I get it')// && this.Status.msgOkTime && this.Status.msgOkIntval){ + { + these.showPop({ + showPop: true, + message: "用户已确认收到紧急通知", + iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png" + }); + + // this.Status.msgOkTime=null + // clearInterval(this.Status.msgOkIntval); + + } + + + } // else { // console.log("收到不能处理的数据", payload); // } @@ -2498,7 +2514,7 @@ buttonBgColor: '#BBE600', buttonTextColor: '#232323DE', iconUrl: '/static/images/6155/DeviceDetail/sendSucc.png', - message: '发送成功', + message: '发送成功,待用户确认', buttonText: '确定', clickEvt: 'SendUsr', visiblePrompt: false, @@ -2506,6 +2522,20 @@ modelValue: '', visibleClose: true }); + + // clearInterval(this.Status.msgOkIntval); + + // this.Status.msgOkTime=0; + // this.Status.msgOkIntval=setInterval(()=>{ + // this.Status.msgOkTime++; + // if(this.Status.msgOkTime>180){ + // this.Status.msgOkTime=null + // clearInterval(this.Status.msgOkIntval); + // this.Status.msgOkIntval=null; + // } + // }); + + } else { these.showPop({ message: res.msg, diff --git a/pages/common/addBLE/addEquip.vue b/pages/common/addBLE/addEquip.vue index ec60d6f..a9cac65 100644 --- a/pages/common/addBLE/addEquip.vue +++ b/pages/common/addBLE/addEquip.vue @@ -604,7 +604,7 @@ console.log("res=", res); linkCallback(res); }).catch(ex => { - console.log("ex=", ex) + console.error("ex=", ex) uni.showModal({ content: "连接失败:" + ex.msg }); diff --git a/utils/BleHelper.js b/utils/BleHelper.js index 646ac35..e7f4296 100644 --- a/utils/BleHelper.js +++ b/utils/BleHelper.js @@ -798,7 +798,7 @@ class BleHelper { if (isUpdate) { this.updateCache(); } - console.log("str1=", str); + // console.log("str1=", str); } catch (ex) { console.error("将数据转文本失败", ex); } @@ -1480,7 +1480,7 @@ class BleHelper { deviceId: deviceId, timeout: 30000, success: (info) => { - // console.log("新连接成功", this.data.LinkedList); + console.log("新连接成功", this.data.LinkedList); this.getLinkBlue().then((arr) => { let cr = arr.devices.find(c => { if (c.deviceId == deviceId) { diff --git a/utils/BleReceive.js b/utils/BleReceive.js index 179cf98..b5f85e7 100644 --- a/utils/BleReceive.js +++ b/utils/BleReceive.js @@ -59,10 +59,10 @@ class BleReceive { if (handler) { let data = handler(receive, f, path, recArr); - console.log("handler返回的数据:", data); + console.log("设备"+f.device.deviceName+"收到消息,handler返回的数据:", data); return data; } else { - console.log("已收到消息,但无指定处理程序, deviceUrl:", f.device.detailPageUrl, "可用handlers:", keys); + console.error("已收到消息,但无指定处理程序, deviceUrl:", f.device.detailPageUrl, "可用handlers:", keys); } } else { diff --git a/utils/request.js b/utils/request.js index 6faf71e..a25cc90 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,5 +1,5 @@ import config from '../config/index.js'; -export const env = 'development'; //production development //开发of线上 改这里就行 +export const env = 'production'; //production development //开发of线上 改这里就行 const BASE = config[env]; const request = (options) => { console.log("options" + JSON.stringify(options), BASE.BASE_URL)