Browse Source

添加启动蓝牙下发功能

master
zw_git 3 years ago
parent
commit
7086fbe736
6 changed files with 179 additions and 79 deletions
  1. +88
    -2
      pages/asyntest/asyntest.js
  2. +3
    -2
      pages/asyntest/asyntest.wxml
  3. +67
    -67
      project.config.json
  4. +1
    -1
      utils/btls/bleHandler.js
  5. +1
    -1
      utils/btls/tools.js
  6. +19
    -6
      utils/util.js

+ 88
- 2
pages/asyntest/asyntest.js View File

@ -35,7 +35,26 @@ Page({
this.openLock(userTelephone, userPassword, pwd, openLockType) this.openLock(userTelephone, userPassword, pwd, openLockType)
}, },
btntest3(event){
var that = this
let managerTelephone = "19270949446"
let managerPassword = "123456"
let userTelephone = "38580151200"
let userPassword = "385801"
let userStartTime = "20210813010101"
let userEndTime = "20680813010101"
let fpDataLength = 2048
let fpStartTime = "20210813010101"
let fpEndTime = "20680813010101"
let times = 255
let recycleTime = 65535
this.startFingerprint(managerTelephone, managerPassword, userTelephone, userPassword, userStartTime, userEndTime,
fpDataLength, fpStartTime, fpEndTime, times, recycleTime)
},
//获取输入框的数据 //获取输入框的数据
getmsg(event){ getmsg(event){
this.setData({ this.setData({
@ -44,7 +63,7 @@ Page({
}, },
btntest3(event){
btntest4(event){
var that = this; var that = this;
this.closeblue() this.closeblue()
}, },
@ -129,6 +148,73 @@ Page({
console.log(b) console.log(b)
app.globalData.ble.send(cmd, b, length) app.globalData.ble.send(cmd, b, length)
}, },
startFingerprint(managerTelephone, managerPassword, userTelephone, userPassword, userStartTime, userEndTime,
fpDataLength, fpStartTime, fpEndTime, times, recycleTime) {
wx.showLoading({
title: "正在发送...",
});
setTimeout(() => {
wx.hideLoading()
}, 1000);
let cmd = 0x87
let mt = util.stringToUint8Array(managerTelephone)
let mp = util.stringToUint8Array(managerPassword)
let ut = util.stringToUint8Array(userTelephone)
let up = util.stringToUint8Array(userPassword)
let ust = util.time40ToBytes(userStartTime)
let uet = util.time40ToBytes(userEndTime)
let fpPacketCount = (fpDataLength+511)/512
let crc = 0xAAFF46D3;
let fst = util.time40ToBytes(fpStartTime)
let fet = util.time40ToBytes(fpEndTime)
let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 4 + 4 + 5 + 5 + 1 + 2
let b = new Uint8Array(length)
b[0] = cmd
b.set(mt, 1)
b.set(mp, 12)
b.set(ut, 18)
b.set(up, 29)
b.set(ust, 35)
b.set(uet, 40)
b[45] = (fpDataLength>>24)&0xff;
b[46] = (fpDataLength>>16)&0xff;
b[47] = (fpDataLength>>8)&0xff;
b[48] = fpDataLength&0xff;
b[49] = (fpPacketCount>>24)&0xff;
b[50] = (fpPacketCount>>16)&0xff;
b[51] = (fpPacketCount>>8)&0xff;
b[52] = fpPacketCount&0xff;
b[53] = (crc>>24)&0xff;
b[54] = (crc>>16)&0xff;
b[55] = (crc>>8)&0xff;
b[56] = crc&0xff;
b.set(fst, 57)
b.set(fet, 62)
b[67] = times;
b[68] = (recycleTime>>8)&0xff;
b[69] = recycleTime&0xff;
console.log(b)
app.globalData.ble.send(cmd, b, length)
},
}) })


+ 3
- 2
pages/asyntest/asyntest.wxml View File

@ -12,7 +12,8 @@
<view class="section"> <view class="section">
<input placeholder='请输入要发送的信息' bindinput='getmsg'/> <input placeholder='请输入要发送的信息' bindinput='getmsg'/>
</view> </view>
<button type="primary" class="button" bindtap="btntest2">微信发送消息</button>
<button type="primary" class="button" bindtap="btntest3">断开蓝牙设备</button>
<button type="primary" class="button" bindtap="btntest2">开锁</button>
<button type="primary" class="button" bindtap="btntest3">启动下发指纹</button>
<button type="primary" class="button" bindtap="btntest4">断开蓝牙设备</button>
</view> </view>

+ 67
- 67
project.config.json View File

@ -1,74 +1,74 @@
{ {
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
"enhance": true,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
"description": "项目配置文件",
"packOptions": {
"ignore": []
}, },
"enableEngineNative": false,
"useIsolateContext": true,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
},
"compileType": "miniprogram",
"libVersion": "2.19.4",
"appid": "wx7775ba175d855273",
"projectname": "%E8%93%9D%E7%89%99%E6%B5%8B%E8%AF%95",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
"setting": {
"urlCheck": true,
"es6": true,
"enhance": true,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"enableEngineNative": false,
"useIsolateContext": true,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
}, },
"conversation": {
"list": []
"compileType": "miniprogram",
"libVersion": "2.19.4",
"appid": "wx7775ba175d855273",
"projectname": "%E8%93%9D%E7%89%99%E6%B5%8B%E8%AF%95",
"debugOptions": {
"hidedInDevtools": []
}, },
"game": {
"list": []
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
}, },
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
} }
}
} }

+ 1
- 1
utils/btls/bleHandler.js View File

@ -296,7 +296,7 @@ class BLEHandler {
let result = new Uint8Array(dataLength) let result = new Uint8Array(dataLength)
for (let i = 0; i < dataLength; i++) { for (let i = 0; i < dataLength; i++) {
result[i] = arrbf[i + data_offset]; result[i] = arrbf[i + data_offset];
result[i] = (result[i] ^ (key ^ ((byte) i)));
result[i] = (result[i] ^ (key ^ i));
result[i] += (dataLength - i) ^ key; result[i] += (dataLength - i) ^ key;
} }


+ 1
- 1
utils/btls/tools.js View File

@ -384,7 +384,7 @@ function _sentOrder(cmd, payload){
let timestamp = new Date().getTime(); let timestamp = new Date().getTime();
let ts = timestamp.toString(16) let ts = timestamp.toString(16)
let t = util.hexStringToBytes(ts)
let t = util.timeStringToBytes(ts, 12)
b.set(t, 4) b.set(t, 4)
b[3] = b[9]; b[3] = b[9];
b[10] = (payloadLength>>8)&0xff; b[10] = (payloadLength>>8)&0xff;


+ 19
- 6
utils/util.js View File

@ -108,16 +108,16 @@ function hexStringToBytesWithPadding(str, byteLen, padding) {
} }
function hexStringToBytes(str) {
let s = str;
if(s.length < 12)
function timeStringToBytes(timeStr, timeLen) {
let s = timeStr;
if(s.length < timeLen)
{ {
let tmp = 12-s.length
let tmp = timeLen-s.length
for(let i = 0; i< tmp; i++) for(let i = 0; i< tmp; i++)
s = "0" + s; s = "0" + s;
} }
else else
s = str.substr(s.length-12, s.length);
s = timeStr.substr(s.length-timeLen, s.length);
let start = 0 let start = 0
let length = s.length let length = s.length
@ -139,6 +139,18 @@ function hexStringToBytes(str) {
return [0]; return [0];
} }
function time40ToBytes(dt) {
var cs = dt.substring(0,4) + "/" + dt.substring(4,6) + "/" + dt.substring(6,8) + " " + dt.substring(8,10) + ":" + dt.substring(10,12)
+ ":" + dt.substring(12,14) + ":100";
var milliTs = new Date(cs).getTime();
var secondTs = milliTs/1000
let ts = secondTs.toString(16)
let t = timeStringToBytes(ts, 10)
return t;
}
module.exports = { module.exports = {
formatTime: formatTime, formatTime: formatTime,
uint8ArrayToString: uint8ArrayToString, uint8ArrayToString: uint8ArrayToString,
@ -149,5 +161,6 @@ module.exports = {
decodeHexNibble, decodeHexNibble,
decodeHexNibble: decodeHexByte, decodeHexNibble: decodeHexByte,
hexStringToBytesWithPadding: hexStringToBytesWithPadding, hexStringToBytesWithPadding: hexStringToBytesWithPadding,
hexStringToBytes: hexStringToBytes
timeStringToBytes: timeStringToBytes,
time40ToBytes: time40ToBytes
} }

Loading…
Cancel
Save