From 8fdc628377c412dd07e921d2d3a172fb718146e6 Mon Sep 17 00:00:00 2001 From: zw_git <459788263@qq.com> Date: Wed, 15 Sep 2021 19:18:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=AF=E5=8A=A8=E8=93=9D?= =?UTF-8?q?=E7=89=99=E4=B8=8B=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/asyntest/asyntest.js | 51 +++++++++++++++++++++++++++++++++++++++++----- utils/util.js | 17 ++++++++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/pages/asyntest/asyntest.js b/pages/asyntest/asyntest.js index 4f04ac4..f0733ff 100644 --- a/pages/asyntest/asyntest.js +++ b/pages/asyntest/asyntest.js @@ -38,6 +38,14 @@ Page({ btntest3(event){ var that = this + let deviceNum = "yxwl01680000000362" + this.startFingerprint(deviceNum) +}, + + +/* + btntest3(event){ + var that = this let managerTelephone = "19270949446" let managerPassword = "123456" let userTelephone = "38580151200" @@ -53,7 +61,7 @@ Page({ this.startFingerprint(managerTelephone, managerPassword, userTelephone, userPassword, userStartTime, userEndTime, fpDataLength, fpStartTime, fpEndTime, times, recycleTime) }, - +*/ //获取输入框的数据 getmsg(event){ @@ -148,8 +156,41 @@ Page({ console.log(b) app.globalData.ble.send(cmd, b, length) }, + + startFingerprint(deviceNum) { + + wx.showLoading({ + title: "正在发送...", + }); + setTimeout(() => { + wx.hideLoading() + }, 1000); + + let cmd = 0x29 + let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 'F') + let data = 0x00360008 + + let length = 1 + 20 + 4 + 1 + 1 + + let b = new Uint8Array(length) + + b[0] = cmd + b.set(dn, 1) + + b[21] = (data>>24)&0xff; + b[22] = (data>>16)&0xff; + b[23] = (data>>8)&0xff; + b[24] = data&0xff; + b[25] = 0x03 + b[26] = 0x01 + + console.log(b) + app.globalData.ble.send(cmd, b, length) + }, + - startFingerprint(managerTelephone, managerPassword, userTelephone, userPassword, userStartTime, userEndTime, + + startFingerprint_1(managerTelephone, managerPassword, userTelephone, userPassword, userStartTime, userEndTime, fpDataLength, fpStartTime, fpEndTime, times, recycleTime) { wx.showLoading({ @@ -212,9 +253,9 @@ Page({ console.log(b) app.globalData.ble.send(cmd, b, length) - }, - - + }, + + }) diff --git a/utils/util.js b/utils/util.js index b5f1bf6..e3ba0c0 100644 --- a/utils/util.js +++ b/utils/util.js @@ -31,6 +31,22 @@ function stringToUint8Array(str){ let tmpUint8Array = new Uint8Array(arr); return tmpUint8Array } + +function stringToUint8ArrayWithPadding(str, length, padding){ + let arr = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + + for (let i = str.length; i < length; i++) { + arr.push(padding); + } + + let tmpUint8Array = new Uint8Array(arr); + return tmpUint8Array +} + + // 微信官方给的ArrayBuffer转十六进制示例 @@ -155,6 +171,7 @@ module.exports = { formatTime: formatTime, uint8ArrayToString: uint8ArrayToString, stringToUint8Array: stringToUint8Array, + stringToUint8ArrayWithPadding: stringToUint8ArrayWithPadding, ab2hex: ab2hex, hexCharCodeToStr, hexCharCodeToStr: buf2string,