From 516e9c3da9f1d750f0a829f68df5aa5110ba6ac9 Mon Sep 17 00:00:00 2001 From: "3321822538@qq.com" <3321822538@qq.com> Date: Wed, 19 Feb 2025 17:42:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=87=E8=8A=B1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/blufi/xBlufi-wx-impl.js | 136 +++++++++++-- page_user/lanya.vue | 112 ++++------- page_user/upload.vue | 219 +++++++++++++++++++-- pages/index/index.vue | 295 +++++++++++++++++------------ pages/myorder/returned/index.vue | 2 - 5 files changed, 542 insertions(+), 222 deletions(-) diff --git a/components/blufi/xBlufi-wx-impl.js b/components/blufi/xBlufi-wx-impl.js index 2c19b72..700cc0d 100644 --- a/components/blufi/xBlufi-wx-impl.js +++ b/components/blufi/xBlufi-wx-impl.js @@ -912,8 +912,104 @@ function write_cmd_program_fg(web, deviceId, serviceId, characteristicId, data) // var requestTask = } +// 模拟一个异步操作,比如网络请求 +function fetchData() { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('Data fetched!'); + }, 20); // 模拟网络延迟 2 秒 + }); +} +// 模拟一个异步操作,比如网络请求 +function fetchData2() { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('Data fetched!'); + }, 2000); // 模拟网络延迟 2 秒 + }); +} +async function main(res, my_sum, deviceId, serviceId, characteristicId) { + var address = 0; + var len = 0; + var buf = 0; + var dv = 0; + let result; + dv = new DataView(res.data); + var bufferLength = dv.byteLength; + var sum = 0; + for (var i = 0; i < bufferLength; i++) { + sum += dv.getUint8(i) + } + const data1 = await fetchData2(); + result = dv + console.log(result); + console.log("content-length", bufferLength); + console.log("sum", sum); + len = bufferLength + if (sum != my_sum && my_sum != 100) { + console.log("不相等my_sum", my_sum); + return; + } + var p_data = 0; + var p_ii = 0; + while (address <= len) { + var offst = 176; + if (address + 176 > len) { + offst = len - address; + } + var value = util.write_ota_program(CMD_IAP_PROM, offst, address, result); + var typedArray = new Uint8Array(value); + // console.log("12121") + const data = await fetchData(); - + var qq = await send_ota_data_num(deviceId, serviceId, characteristicId, typedArray.buffer, (address / + len)) + if (qq == false) { + console.log("返回", sum); + return + } + address = address + 176; + // //console.log("送数据", qq) + } + const data = await fetchData(); + // return new Promise + var value2 = util.write_ota_sum(CMD_IAP_SUM, bufferLength, sum); + var typedArray2 = new Uint8Array(value2); + // console.log("送结束数据", value2) + send_ota_data_num(deviceId, serviceId, characteristicId, typedArray2.buffer, 100); +} +function write_cmd_program_sum(web, sum, deviceId, serviceId, characteristicId, data) { + var address = 0; + var len = 0; + var buf = 0; + var dv = 0; + let result; + console.log("更新122") + const mtu = 230; + var value1 = util.write_ota_erase(CMD_IAP_ERASE, 4, 0, 0); + var typedArray1 = new Uint8Array(value1); + console.log("翻盖柜", typedArray1) + console.log("翻盖柜", deviceId) + console.log("翻盖柜", serviceId) + console.log("翻盖柜", characteristicId) + send_ota_data(deviceId, serviceId, characteristicId, typedArray1.buffer); + // return; + setTimeout(function () { + uni.request({ + url: web, //仅为示例,并非真实接口地址。 + //url: 'https://www.zenghi.com/gj/BLE钉钉.bin', //仅为示例,并非真实接口地址。 + // url: 'https://www.zenghi.com/gj/电子秤.bin', //仅为示例,并非真实接口地址。 + responseType: 'arraybuffer', + success: (res) => { + main(res, sum, deviceId, serviceId, characteristicId) + }, + fail: function (res) { + console.log("获取失败"); + } + }) + } + , 3000); +} function writeCutomsData(deviceId, serviceId, characteristicId, data) { // var obj = {}, @@ -939,26 +1035,32 @@ function writeCutomsData(deviceId, serviceId, characteristicId, data) { console.log("characteristicId", characteristicId) // const buffer = new ArrayBuffer(8); console.log("data", data) - if (data.indexOf("update") != -1 && data.indexOf("all_update") == -1) { - console.log("送数update据成功") - write_cmd_program(deviceId, serviceId, characteristicId, data) - } - else if (data.indexOf("upzydsm") != -1 ) { - console.log("送数upzydsm据成功") - write_cmd_program_zy(deviceId, serviceId, characteristicId, data) - } - else if (data.indexOf("upykdate") != -1 ) { - console.log("送数upykdate据成功") - write_cmd_program_yk(deviceId, serviceId, characteristicId, data) - } - else if (data.indexOf("fgdate") != -1 ) { - write_cmd_program_fg('https://fg.zenghi.com/gj/翻盖柜.bin',deviceId, serviceId, characteristicId, data) - } + // if (data.indexOf("update") != -1 && data.indexOf("all_update") == -1) { + // console.log("送数update据成功") + // write_cmd_program(deviceId, serviceId, characteristicId, data) + // } + // else if (data.indexOf("upzydsm") != -1 ) { + // console.log("送数upzydsm据成功") + // write_cmd_program_zy(deviceId, serviceId, characteristicId, data) + // } + // else if (data.indexOf("upykdate") != -1 ) { + // console.log("送数upykdate据成功") + // write_cmd_program_yk(deviceId, serviceId, characteristicId, data) + // } + // else if (data.indexOf("fgdate") != -1 ) { + // write_cmd_program_fg('https://fg.zenghi.com/gj/翻盖柜.bin',deviceId, serviceId, characteristicId, data) + // } // else if (data.indexOf("ble_go7p") != -1 ) { // console.log("送数update据成功") // write_cmd_program7p(deviceId, serviceId, characteristicId, data) // } + if(data.sum != undefined){ + if(data.http != undefined){ + console.log('升级'); + write_cmd_program_sum(data.http, data.sum, deviceId, serviceId, characteristicId, data) + } + } else { var buffer = string2buffer(data) uni.writeBLECharacteristicValue({ @@ -1146,7 +1248,7 @@ function init() { // && devices.devices[0].name != 'SMART_R2XS' // && devices.devices[0].name != 'SMART_R2XS' // ) - if (devices.devices[0].name.indexOf("WATER") != -1){ + if (devices.devices[0].name.indexOf("WATER") != -1 || devices.devices[0].name.indexOf("SMSJ:") != -1){ // if ( devices.devices[0].name.indexOf("gjkg") != -1 ){ // console.log("跳过",devices.devices[0].name) // isnotexist = false; diff --git a/page_user/lanya.vue b/page_user/lanya.vue index 26877cb..8f5e91d 100644 --- a/page_user/lanya.vue +++ b/page_user/lanya.vue @@ -12,17 +12,17 @@ 如未找到想添加的设备,点击重新搜索 - + 丁丁浇花器 - MAC:{{item.name}} + MAC:{{item}} - + 添加 @@ -64,9 +64,11 @@ devicesList:[], deviceId:'', name:'', - mac:'2952BB7A4EE0', + mac:'', flags:true, - userid:'' + userid:'', + arr:'', + jiaohuaqi:[] } }, // 分享到好友(会话) @@ -86,8 +88,11 @@ } }, onLoad() { + + }, + onShow() { this.getinfo() - this.btnss() + this.btnss() }, methods:{ // 获取用户信息 @@ -108,7 +113,8 @@ let mac = e.slice(-12) let data = { mac:mac, - userId:this.userid + userId:this.userid, + pre:e.slice(0,5) } this.$u.post(`/app/bandDevice`,data).then((res) => { if (res.code == 200) { @@ -129,11 +135,12 @@ } }) }, - - btnss(){ + + btnss(){ uni.showLoading({ title: '搜索中...' }) + this.jiaohuaqi = [] this.flag = false let that = this xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent) @@ -146,53 +153,48 @@ }) if (that.devicesList.length > 0) { that.flags = true + this.$u.get(`/app/device/isBand/${this.arr}`).then(res =>{ + if(res.code == 200){ + res.data.forEach(item =>{ + if(item.isBand == false){ + that.devicesList.forEach(val =>{ + if(val.name.slice(-12) == item.mac){ + that.jiaohuaqi.push(val.name) + console.log(that.jiaohuaqi); + } + }) + } + }) + } + }) }else{ - that.flags = false + // that.flags = false } uni.hideLoading() that.flag = true - }, 5000) - }, + }, 3000) + }, // 获取附近蓝牙设备列表 funListenDeviceMsgEvent: function(options) { switch (options.type) { case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: - // that.setData({ - // connected: options.result - // }) if (!options.result) { - // uni.showModal({ - // title: '很抱歉提醒你!', - // content: '小程序与设备异常断开', - // showCancel: false, - // //是否显示取消按钮 - // success: function(res) { - - // } - // }) + } break case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: if (options.result) { - let devicesarr = options.data - this.devicesList = devicesarr - // console.log(devicesarr,'111'); - // devicesarr.forEach(device => { - // const mac = device.name.substring(4); - // if (device.name.slice(5, 17) == this.mac) { - // this.deviceId = device.deviceId - // this.name = device.name - // console.log(device.name,this.mac,'222'); - // this.devicesList.push(device); - // let uniqueDevicesList = Array.from(new Set(this.devicesList)); - // this.devicesList = uniqueDevicesList; - // } - // }) + let devicesarr = [] + this.devicesList = options.data + options.data.forEach(item =>{ + devicesarr.push(item.name.slice(-12)) + }) + this.arr = devicesarr.join(',') } break case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED: - console.log("连接回调:" + JSON.stringify(options)); + console.log("连接回调:" + JSON.stringify(options)) if (options.result) { { xBlufi.notifyInitBleEsp32({ @@ -206,17 +208,7 @@ } break case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA: - // this.ver_data = this.parseCustomData(options.data) - this.ver_data = options.data - console.log("1收到设备发来的自定义数据结果:", this.ver_data) - break; - case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP: - if (options.result) { - let uniqueDevicesList = Array.from(new Set(this.devicesList)) - let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === "WATER") - // 将过滤后的数组重新赋值给 this.devicesList - this.devicesList = filteredDevices - } + break; case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START: if (!options.result) { @@ -233,26 +225,6 @@ break } }, - // 从蓝牙拿到数据进行解析 - parseCustomData(data) { - // 将字符串按照 "@" 分割成数组 - const dataArray = data.split('@') - const voltage = parseFloat(dataArray[0].substring(1)) // 去除前缀 "V",并将字符串转换为浮点数 - const switchState = dataArray[1].substring(1) // 去除前缀 "S" - const current = parseFloat(dataArray[2].substring(1)) // 去除前缀 "A",并将字符串转换为浮点数 - const power = parseFloat(dataArray[4].substring(1)) // 去除前缀 "P",并将字符串转换为浮点数 - const remainingPower = parseFloat(dataArray[5].substring(1)) // 去除前缀 "M",并将字符串转换为浮点数 - const setMode = dataArray[6].substring(1) // 去除前缀 "T" - // 返回解析后的数据对象 - return { - voltage, - switchState, - current, - power, - remainingPower, - setMode - } - }, } } diff --git a/page_user/upload.vue b/page_user/upload.vue index c4e6169..136b13a 100644 --- a/page_user/upload.vue +++ b/page_user/upload.vue @@ -23,10 +23,10 @@ - + 固件更新 - {{gjtxt}} - + + @@ -54,11 +54,30 @@ + + + + + + + + + + + {{ progress }}% + + 固件升级中请保持蓝牙连接 + + + 切记在蓝牙范围内,以防升级失败 + +