diff --git a/api/670/HBY670.js b/api/670/HBY670.js index 2f2ee24..4cc35d3 100644 --- a/api/670/HBY670.js +++ b/api/670/HBY670.js @@ -1,6 +1,6 @@ -import request from '@/utils/request' +import {request,baseURL} from '@/utils/request' -function getdata(url,method,data){ +function getdata(data,url,method){ return new Promise((resolve,reject)=>{ if(!url){ reject('url为空'); @@ -21,21 +21,70 @@ function getdata(url,method,data){ }); } -//档位设置 - function gearSetting(data){ - let url=""; - return getdata(url,"POST",data); -} + //人员信息设置 function sendUsr(data){ let url="/app/xinghan/device/registerPersonInfo"; - return getdata(url,"POST",data); + return getdata(data,url,"POST"); +} + +//报警信息 +function warnMsg(data){ + let url="/app/xinghan/device/sendAlarmMessage" + return getdata(data,url,"POST"); +} + +//开机图片 +function sendPic(data){ + return new Promise((resolve, reject) => { + + const token = uni.getStorageSync('token'); + const clientid = uni.getStorageSync('clientID'); + let config = { + header: {} + }; + if (token) { + config.header['Authorization'] = 'Bearer ' + token; + config.header['clientid'] = clientid; + } + + uni.uploadFile({ + + url: baseURL + '/app/xinghan/device/uploadLogo', + filePath: data.picPath, + name: 'file', + formData: { + deviceId: data.deviceId, + deviceImei: data.deviceImei + }, + header: config.header, + timeout: 600000, + fail: (ex) => { + console.log("上传视频失败" ,ex); + reject(ex); + }, + success: (res) => { + console.log("上传完成", res); + if(res.statusCode==200){ + resolve(JSON.parse(res.data)); + }else{ + reject(res); + } + + }, + complete: () => { + + } + + }); + }); } export default{ - gearSetting:gearSetting, - sendUsr:sendUsr + sendUsr:sendUsr, + warnMsg:warnMsg, + sendPic:sendPic } diff --git a/pages/6155/ImgCrop.vue b/pages/6155/ImgCrop.vue index 6c2fafe..e06f20f 100644 --- a/pages/6155/ImgCrop.vue +++ b/pages/6155/ImgCrop.vue @@ -60,8 +60,8 @@ console.log("res.data.length="+res.data.length); - eventChannel.emit('ImgCutOver',res.data); - eventChannel.emit('ImgCutOver_Path',e.tempFilePath); + eventChannel.emit('ImgCutOver',{piexls:res.data,picPath:e.tempFilePath}); + uni.navigateBack(); }, fail: (err) => { diff --git a/pages/6155/deviceDetail.vue b/pages/6155/deviceDetail.vue index 7b809f6..8e3e041 100644 --- a/pages/6155/deviceDetail.vue +++ b/pages/6155/deviceDetail.vue @@ -567,7 +567,7 @@ these.Status.BottomMenu.show = false; setTimeout(function() { - processAndSendImageData(data).catch((ex) => { + processAndSendImageData(data.piexls).catch((ex) => { console.log("出现异常", ex); }); }, 0) diff --git a/pages/650/HBY650.vue b/pages/650/HBY650.vue index 12222c2..98aed9c 100644 --- a/pages/650/HBY650.vue +++ b/pages/650/HBY650.vue @@ -736,7 +736,7 @@ console.log("收到设备的数据",data) }); these.Status.BottomMenu.show = false; - these.rgb565Data = ble.convertToRGB565(data); + these.rgb565Data = ble.convertToRGB565(data.piexls); setTimeout(function() { sendImagePackets().catch(() => { diff --git a/pages/670/HBY670.vue b/pages/670/HBY670.vue index 2f1551a..ea422b6 100644 --- a/pages/670/HBY670.vue +++ b/pages/670/HBY670.vue @@ -104,29 +104,7 @@ - + 人员信息登记 @@ -161,6 +139,35 @@ + + + + 发送信息 + 发送 + + + + + + + + + + + + + + 开机画面 + + + + + + + + + + 产品信息 @@ -297,7 +304,7 @@ job: "", //职位 id: "", //id msgTxt: "", //消息1 - qzwarn: false, //是否报警 + qzwarn: false, //是否强制报警 warnLevel: "", //报警级别 staticWarn:false,//静止报警 fourGStrenth:0,//4G信号强度 @@ -323,7 +330,8 @@ showConfirm: false }, rgb565Data: [], - videoHexArray: [] + videoHexArray: [], + picPath:"" } }, @@ -421,22 +429,26 @@ let json = JSON.parse(payload); let keys = Object.keys(json); - console.log("keys=", keys); + // console.log("keys=", keys); if (keys.indexOf('sta_DetectGrade') > -1) { //上报的报文 console.log("收到设备上报的数据", payload); - // this.parseDataMQ(json); - } else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面 - console.log("收到开机画面答复", payload); - // this.SendImgMQ(json); - } else if (keys.indexOf('sta_TexTrans') > -1) { //发送文本信息 - console.log("收到文本回复", payload); - // this.SendTxtMQ(json); - } else if (keys.indexOf('sta_BreakNews') > -1) { //紧急通知 - console.log("收到紧急消息回复", payload); - // this.sendUrgentMQ(json); - } else { - console.log("收到不能处理的数据", payload); - } + this.parseDataMQ(json); + } + // else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面 + // console.log("收到开机画面答复", payload); + // // this.SendImgMQ(json); + // } + // else if (keys.indexOf('sta_TexTrans') > -1) { //发送文本信息 + // console.log("收到文本回复", payload); + // // this.SendTxtMQ(json); + // } + // else if (keys.indexOf('sta_BreakNews') > -1) { //紧急通知 + // console.log("收到紧急消息回复", payload); + // // this.sendUrgentMQ(json); + // } + // else { + // console.log("收到不能处理的数据", payload); + // } } catch (error) { @@ -476,7 +488,54 @@ } }); }, - + parseDataMQ(json){ + let staticLevelText = ""; + let dic = { + "3": "hight", + "2": "center", + "1": "low", + "0": "close", + + }; + staticLevelText = dic[json.sta_DetectGrade]; + + let lightingLevelText = json.sta_LightGrade === + 1 ? 'hight' : + json.sta_LightGrade === + 2 ? + 'low' : + 'close'; + let warn = ""; + dic = { + "0": "none", + "1": "ruo", + "2": "center", + "3": "hight", + "4": "veryhight", + }; + warn = dic[json.sta_DetectResult]; + + + let sosText = json.sta_SOSGrade === 2 ? 'rb' : + json.sta_SOSGrade === 1 ? "sg" : "close" + + let staticWarn = json.sta_ShakeBit === 1 ; + + receiveData.modeCurr = staticLevelText; + receiveData.lightCurr = lightingLevelText; + receiveData.xuhang = json.sta_PowerTime + "分钟"; + receiveData.battary = json.sta_PowerPercent + "%"; + receiveData.SOS = sosText; + receiveData.warnLevel = warn; + receiveData.staticWarn = staticWarn; + receiveData.fourGStrenth = json.sta_4gSinal; + receiveData.imei = json.sta_imei; + receiveData.Lon = json.sta_longitude; + receiveData.Lat = json.sta_latitude; + + this.refreshFormData(receiveData); + return receiveData; + }, bleValueNotify: function(receive, device, path) { //订阅消息 let data = recei.ReceiveData(receive, device, pagePath); @@ -503,41 +562,44 @@ } return; } - - 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(this.formData.imei){ - this.initMQ(); - } - if (these.formData.staticWarn) {//有静止报警 - these.showPop({ - message: "自动报警", - iconUrl: "/static/images/6155/DeviceDetail/warnning.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", - buttonText:"解除报警", - clickEvt:"staticWarn" - }); - this.Status.staticWarn.time=180; - this.Status.staticWarn.inteval=setInterval(()=>{ - if(this.Status.staticWarn.time===0){ - clearInterval(this.Status.staticWarn.inteval); - this.formData.staticWarn=false; - return; - } - this.Status.staticWarn.time=this.Status.staticWarn.time-1; - },1000) - - } - - these.setBleFormData(); + this.refreshFormData(data); + } }, + refreshFormData(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(this.formData.imei){ + this.initMQ(); + } + if (these.formData.staticWarn) {//有静止报警 + these.showPop({ + message: "自动报警", + iconUrl: "/static/images/6155/DeviceDetail/warnning.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + buttonText:"解除报警", + clickEvt:"staticWarn" + }); + this.Status.staticWarn.time=180; + this.Status.staticWarn.inteval=setInterval(()=>{ + if(this.Status.staticWarn.time===0){ + clearInterval(this.Status.staticWarn.inteval); + this.formData.staticWarn=false; + return; + } + this.Status.staticWarn.time=this.Status.staticWarn.time-1; + },1000) + + } + + these.setBleFormData(); + }, getDevice: function() { // console.log("LinkedList=", ble.data.LinkedList); @@ -796,7 +858,7 @@ proParam: function() { uni.navigateTo({ - url: '/pages/common/productDes/index?id=' + this.formData.id, + url: '/pages/common/productDes/index?id=' + this.device.id, success(ev) { } @@ -804,7 +866,7 @@ }, handRemark: function() { uni.navigateTo({ - url: '/pages/common/operatingInstruct/index?id=' + this.formData.id, + url: '/pages/common/operatingInstruct/index?id=' + this.device.id, success(ev) { } @@ -812,7 +874,7 @@ }, handVideo: function() { uni.navigateTo({ - url: '/pages/common/operationVideo/index?id=' + this.formData.id, + url: '/pages/common/operationVideo/index?id=' + this.device.id, success(ev) { } @@ -821,6 +883,41 @@ checkImgUpload: function(type, index) { console.log("123213213213"); let f = these.getDevice(); + + var sendImgByRequest=()=>{ + return new Promise((resolve,reject)=>{ + api.sendPic({ + picPath:these.picPath, + deviceId:these.device.id, + deviceImei:these.device.deviceImei + }).then((res)=>{ + if (res.code == 200) { + these.showPop({ + showPop: true, + message: "上传成功", + iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png", + }); + resolve(); + return; + } else { + + these.showPop({ + message: res.errMsg?res.errMsg:"未知的原因上传失败了", + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + }); + reject(res); + } + }).catch((ex)=>{ + console.log("图片上传失败了",ex); + reject(ex) + }).finally(()=>{ + hideLoading(these); + }); + }); + + } // 分包发送图片数据 var sendImagePackets = function(ReSendNo) { @@ -918,7 +1015,7 @@ updateLoading(these, { text: "正在发送:" + currentPacket + "/" + totalPackets - }) + }); currentPacket++; setTimeout(sendNextPacket, 0); @@ -927,19 +1024,21 @@ if (err.code == '10007') { setTimeout(sendNextPacket, 0); return; + }else{ + updateLoading(these, { + text: "蓝牙发送失败,正在使用4G发送" + }); + sendImgByRequest().then(resolve).catch(reject); } - these.Status.BottomMenu.show = false; - - - - these.showPop({ - message: err.msg, - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", - }); - hideLoading(these); - reject(err); + // these.Status.BottomMenu.show = false; + // these.showPop({ + // message: err.msg, + // iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + // borderColor: "#e034344d", + // buttonBgColor: "#E03434", + // }); + // hideLoading(these); + // reject(err); }); } @@ -952,15 +1051,11 @@ f.wirteCharactId).then(() => { sendNextPacket(); }).catch((err) => { - console.log("握手没有成功"); - these.showPop({ - message: err.msg, - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", + updateLoading(these, { + text: "蓝牙发送失败,正在使用4G发送" }); - hideLoading(these); - reject(err); + sendImgByRequest().then(resolve).catch(reject); + }); } }); @@ -978,8 +1073,10 @@ }); these.Status.BottomMenu.show = false; - these.rgb565Data = ble.convertToRGB565(data); + these.picPath=data.picPath; + these.rgb565Data = ble.convertToRGB565(data.piexls); setTimeout(function() { + sendImagePackets().catch(() => { }); @@ -1080,7 +1177,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(() => { @@ -1272,8 +1369,8 @@ this.Status.BottomMenu.menuItems = []; this.Status.BottomMenu.title = "上传开机画面"; this.Status.BottomMenu.type = "checkImg"; - this.Status.BottomMenu.show = true; - this.formData.cMode = "img"; + this.Status.BottomMenu.show = true; + this.Status.BottomMenu.showBtn=false; }, showMenu(flag) { @@ -1335,8 +1432,8 @@ let requestSend=()=>{ let json = { - deviceId: '1942386314582163705', - deviceImei: '862419074249128', + deviceId: this.device.id, + deviceImei: this.device.deviceImei?this.device.deviceImei:this.formData.imei, name: this.formData.company, position: this.formData.name, unitName: this.formData.job, @@ -1514,6 +1611,67 @@ + }, + sendUrgent(type) { + if(!this.formData.msgTxt){ + + return; + } + showLoading(this, { + 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('|'), + "deviceIds": [ + this.device.id + ], + "deviceImeiList": [ + this.device.deviceImei?this.device.deviceImei:this.formData.imei + ] + } + console.log("data=",data); + api.warnMsg(data).then((res)=>{ + if (res.code == 200) { + these.showPop({ + showPop: true, //是否显示弹窗 + popType: 'custom', + bgColor: '#383934bd', + borderColor: '#BBE600', + textColor: '#ffffffde', + buttonBgColor: '#BBE600', + buttonTextColor: '#232323DE', + iconUrl: '/static/images/6155/DeviceDetail/sendSucc.png', + message: '发送成功', + buttonText: '确定', + clickEvt: 'SendUsr', + visiblePrompt: false, + promptTitle: '', + modelValue: '', + visibleClose: true + }); + } else { + these.showPop({ + message: res.msg, + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + }); + } + }).finally(()=>{ + hideLoading(this); + }); + }, HoldYouHand(str, pauseTime, deviceid, serviceid, characid) { @@ -2189,4 +2347,14 @@ display: flex; height: 100%; } + .picVideo .btnImg{ + width: 100%; + height:100rpx; + border-radius: 16rpx; + background: rgba(42, 42, 42, 1); + } + .picVideo .btnImg .img{ + width: 40rpx; + height:40rpx; + } \ No newline at end of file diff --git a/utils/BleHelper.js b/utils/BleHelper.js index 5d43654..56c9523 100644 --- a/utils/BleHelper.js +++ b/utils/BleHelper.js @@ -335,6 +335,8 @@ class BleHelper { } uni.getBluetoothAdapterState({ success: (info) => { + this.data.available=info.available; + this.data.discovering=info.discovering; resolve(info); }, fail: (ex1) => { @@ -358,6 +360,7 @@ class BleHelper { resolve(false); return; } + uni.openBluetoothAdapter({ success: (args) => { console.log("蓝牙初始化成功:" + JSON.stringify(args)); diff --git a/utils/BleReceive.js b/utils/BleReceive.js index 13a0b99..bfa3de3 100644 --- a/utils/BleReceive.js +++ b/utils/BleReceive.js @@ -45,21 +45,23 @@ class BleReceive { ReceiveData(receive,f,path) { - if(f && f.macAddress && f.id){ + if(f && f.macAddress && f.id){ + let data={}; if(f.detailPageUrl=='/pages/6155/deviceDetail'){ console.log("该设备是6155"); - return this.Receive_6155(receive,f,path); + data= this.Receive_6155(receive,f,path); } if(f.detailPageUrl=='/pages/650/HBY650'){ console.log("该设备是650"); - return this.Receive_650(receive,f,path); + data= this.Receive_650(receive,f,path); } if(f.detailPageUrl=='/pages/670/HBY670'){ console.log("该设备是670"); - return this.Receive_670(receive,f,path); + data= this.Receive_670(receive,f,path); } - + console.log("收到数据并处理完毕,",data); + return data; } console.log("已收到该消息,但无法处理",f); @@ -242,7 +244,7 @@ class BleReceive { } - let data=parseData(); + let data=parseData(receive.bytes); console.log("data=",data); return data; @@ -251,10 +253,11 @@ class BleReceive { Receive_670(receive,f,path){ var todo = (bytes) =>{ - + console.log("todo"); let receiveData = {}; if (bytes[0] == 0x55) { try { + console.log("todo"); // 跳过帧头(第一个字节),从第二个字节开始解析 let staticLevelByte = bytes[1]; let staticLevelText = ''; @@ -272,7 +275,7 @@ class BleReceive { staticLevelText = 'close'; break } - + console.log("todo"); // 解析照明档位 let lightingLevelByte = bytes[2]; let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close'; @@ -284,24 +287,24 @@ class BleReceive { let batteryLevelByte = bytes[5]; let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte)); - + console.log("todo"); 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 = '非常强预警'; - // } + if (warn == 0x00) { + warn = 'none'; + } else if (warn == 0x01) { + warn = 'ruo'; + } else if (warn == 0x02) { + warn = 'center'; + } else if (warn == 0x03) { + warn = 'hight'; + } else if (warn == 0x04) { + warn = 'veryhight'; + } let staticWarn = bytes[7] == 0x01;//静止报警 let fourGStrenth = bytes[8]; //4g信号强度 - let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? 'sg' : 'rb'; - + let sosTxt = bytes[9] == 0x00 ? 'close' : bytes[9] == 0x01 ? 'sg' : 'rb'; + console.log("todo"); receiveData.modeCurr = staticLevelText; receiveData.lightCurr = lightingLevelText; receiveData.xuhang = lightingTime ; @@ -313,6 +316,7 @@ class BleReceive { } catch(error) { console.log('数据解析错误:', error); } + console.log("todo"); } else { try { let uint8Array = new Uint8Array(receive.value); @@ -325,7 +329,7 @@ class BleReceive { receiveData.macAddress = str.split(':').slice(1).join(":"); console.log('收到mac地址:', +this.receiveData.macAddress); } else if (str.indexOf('imei:') == 0) { - receiveData.IMEI = str.split(':')[1]; + receiveData.imei = str.split(':')[1]; console.log('收到IEMI:', +this.receiveData.macAddress); } else if (str.indexOf('longitude:') == 0) { @@ -376,13 +380,13 @@ class BleReceive { console.log('将数据转文本失败', ex); } } - + console.log("todo",receiveData); this.setBleFormData(receiveData,f); return receiveData; } - let data=todo(); + let data=todo(receive.bytes); return data; } diff --git a/utils/mqtt.js b/utils/mqtt.js index e682683..3c79aa6 100644 --- a/utils/mqtt.js +++ b/utils/mqtt.js @@ -167,7 +167,7 @@ class MqttClient { this.client.onMessageArrived = (message) => { const topic = message.destinationName; const payload = message.payloadString; - console.log(`收到消息, 主题: ${topic}, 内容: ${payload}`); + // console.log(`收到消息, 主题: ${topic}, 内容: ${payload}`); const potentialJsons = payload.replace(/}\s*{/g, '}|{').split('|'); potentialJsons.forEach(jsonString => { if (jsonString.trim() === '') return; diff --git a/utils/request.js b/utils/request.js index c02467a..55fba95 100644 --- a/utils/request.js +++ b/utils/request.js @@ -28,9 +28,11 @@ const request = (options) => { header: options.header || {}, timeout: 30000, success: (res) => { + console.log("请求成功",res); resolve(res.data); }, fail: (err) => { + console.log("请求失败",err); reject(err); } };