同一特征值分段读取时安卓和苹果的速度区别
发布于 6 年前 作者 na09 2638 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

var _this = this

let deviceId = e.currentTarget.dataset.id

let info = e.currentTarget.dataset.info

let checkBoxValue = e.currentTarget.dataset.value

let offset = Math.floor(info[21]/30)

wx.getBLEDeviceServices({

    deviceId: deviceId,

    success(res) {

        wx.getBLEDeviceCharacteristics({

            deviceId: deviceId,

            serviceId: ‘10FF0200-BA5E-F4EE-5CA1-EB1E5E4B1CE0’,

            success(res1) {

                writeOffset(deviceId, offset, _this)

            }

        })

    }

})

var common = require(’…/…/lib/public.js’)

function readinfo(deviceId, offset,_this) {

    var arr = new Array()

    wx.readBLECharacteristicValue({

        deviceId: deviceId,

        serviceId: ‘10FF0200-BA5E-F4EE-5CA1-EB1E5E4B1CE0’,

        characteristicId: ‘0000FF50-0000-1000-8000-00805F9B34FB’,

        success(res3) {

        

        }

    })

    wx.onBLECharacteristicValueChange((characteristic) => {

        var dv = new Int16Array(characteristic.value)

        for (let j = 0; j < dv.length; j++) {

        arr[j] = (dv[j] / 10).toFixed(1)

        }

        arr = common.resetArray(arr, _this.data.index)

        for (var z = 0; z < arr.length; z++) {

        //arr[z].push(_this.data.index)

        _this.data.upPage[1].push(arr[z])

        }

            if(_this.data.index==0){

              _this.data.time1 = new Date().getTime()

            }else{

              console.log(new Date().getTime() - _this.data.time1)

              _this.data.time1 = new Date().getTime()

            }

        //console.log(arr)

        if (_this.data.index < offset) {

        _this.data.index++

        writeOffset(deviceId, offset, _this)

        }

    })

}

function writeOffset(deviceId, offset, _this) {

    _this.data.isfor = false

    let buffer = new ArrayBuffer(4)

    let dataView = new DataView(buffer)

    dataView.setUint32(0, _this.data.index, true)

    wx.writeBLECharacteristicValue({

        deviceId: deviceId,

        serviceId: ‘10FF0200-BA5E-F4EE-5CA1-EB1E5E4B1CE0’,

        characteristicId: ‘0000FF53-0000-1000-8000-00805F9B34FB’,

        value: buffer,

        success(res2) {

            if (res2.errCode == 0) {

                readinfo(deviceId, offset, _this)

            }

        }

    })

}

蓝牙设备上有很多数据,但是一次只能读120自己,所以就先写入读取位置,然后读取-再写入读取这样吧把所有数据读取出来,这时候安卓比苹果速度慢7倍。这是什么原因呢?

回到顶部