You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
5.4 KiB

1 year ago
  1. var util = require('./util');
  2. import {
  3. BLE
  4. } from "./btls/ble";
  5. const app = getApp();
  6. const emitter = app.globalData.emitter
  7. function ab2hex(buffer) {
  8. var hexArr = Array.prototype.map.call(
  9. new Uint8Array(buffer),
  10. function (bit) {
  11. return ('00' + bit.toString(16)).slice(-2)
  12. }
  13. )
  14. return hexArr.join(',');
  15. }
  16. function startFp1_63(managerTelephone, managerPassword, userTelephone, userPassword, password, startTime, endTime,
  17. num,timestamp,callback) {
  18. wx.showLoading({
  19. title: "正在发送...",
  20. mask:true
  21. });
  22. setTimeout(() => {
  23. wx.hideLoading()
  24. }, 1000);
  25. let cmd = 0x63
  26. let mt = util.stringToUint8Array(managerTelephone)
  27. let mp = util.stringToUint8Array(managerPassword)
  28. let ut = util.stringToUint8Array(userTelephone)
  29. let up = util.stringToUint8Array(userPassword)
  30. let pd = util.hexStringToBytesWithPadding(password, 10, 0xff)
  31. let ust = util.time40ToBytes(startTime)
  32. let uet = util.time40ToBytes(endTime)
  33. let fst = util.time40ToBytes(startTime)
  34. let fet = util.time40ToBytes(endTime)
  35. let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 2 + 10 + 5 + 5 + 1 + 2 + 1
  36. let b = new Uint8Array(length)
  37. b[0] = cmd
  38. b.set(mt, 1)
  39. b.set(mp, 12)
  40. b.set(ut, 18)
  41. b.set(up, 29)
  42. b.set(ust, 35)
  43. b.set(uet, 40)
  44. //权限
  45. b[45] = 0xff;
  46. b[46] = 0xff;
  47. b[47] = 0xff;
  48. b[48] = 0xff;
  49. //密码长度 uint16
  50. b[49] = 0
  51. b[50] = 0x0a
  52. //密码数据
  53. b.set(pd, 51)
  54. b.set(fst, 61)
  55. b.set(fet, 66)
  56. b[71] = 0xff;
  57. b[72] = 0xff;
  58. b[73] = 0xff;
  59. b[74] = num; //添加指纹
  60. app.globalData.ble.send(cmd, b,timestamp,function(data){
  61. callback(data)
  62. })
  63. }
  64. function startFp_26(managerTelephone, managerPassword,timestamp,callback) {
  65. wx.showLoading({
  66. title: "正在发送...",
  67. mask:true
  68. });
  69. setTimeout(() => {
  70. wx.hideLoading()
  71. }, 1000);
  72. let cmd = 0x26
  73. let mt = util.stringToUint8Array(managerTelephone)
  74. let mp = util.stringToUint8Array(managerPassword)
  75. let length = 1 + 11 + 6
  76. let b = new Uint8Array(length)
  77. b[0] = cmd
  78. b.set(mt, 1)
  79. b.set(mp, 12)
  80. app.globalData.ble.send(cmd, b,timestamp,function(data){
  81. callback(data)
  82. })
  83. }
  84. function startFp_23(deviceNum, managerTelephone, managerPassword, newPassword, key,timestamp,callback) {
  85. wx.showLoading({
  86. title: "正在发送...",
  87. mask:true
  88. });
  89. setTimeout(() => {
  90. wx.hideLoading()
  91. }, 1000);
  92. let cmd = 0x23
  93. let dn = util.stringToBytesWithPadding(deviceNum, 20, 255)
  94. let mt = util.stringToUint8Array(managerTelephone)
  95. let mp = util.stringToUint8Array(managerPassword)
  96. let ut = util.stringToUint8Array(newPassword)
  97. let up = util.stringToUint8Array(key)
  98. let length = 1 + 20 + 11 + 6 + 6 + 10
  99. let b = new Uint8Array(length)
  100. b[0] = cmd
  101. b.set(dn, 1)
  102. b.set(mt, 21)
  103. b.set(mp, 32)
  104. b.set(ut, 38)
  105. b.set(up, 44)
  106. app.globalData.ble.send(cmd, b,timestamp,function(data){
  107. callback(data)
  108. })
  109. }
  110. function openLock(userTelephone,userPassword,pwd,openLockType,timestamp,callback) {
  111. wx.showLoading({
  112. title: "正在发送...",
  113. mask:true
  114. });
  115. setTimeout(()=>{
  116. wx.hideLoading()
  117. },3000)
  118. let cmd = 0x41
  119. let ut = util.stringToUint8Array(userTelephone)
  120. let up = util.stringToUint8Array(userPassword)
  121. let p = util.hexStringToBytesWithPadding(pwd, 10, 0xff)
  122. let length = 1 + 11 + 6 + 10 + 1
  123. let b = new Uint8Array(length)
  124. b[0] = cmd
  125. b.set(ut, 1)
  126. b.set(up, 12)
  127. b.set(p, 18)
  128. b[28] = openLockType
  129. app.globalData.ble.send(cmd, b, length,timestamp,function(data){
  130. callback(data)
  131. })
  132. }
  133. function startFp_29(deviceNum, status,timestamp,callback) {
  134. wx.showLoading({
  135. title: "正在发送...",
  136. mask:true
  137. });
  138. let cmd = 0x29
  139. let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  140. let length = 1 + 20 + 5 + 1 + 1
  141. let b = new Uint8Array(length)
  142. b[0] = cmd
  143. b.set(dn, 1)
  144. //send data=0x0036000008
  145. b[21] = 0x00;
  146. b[22] = 0x36;
  147. b[23] = 0;
  148. b[24] = 0;
  149. b[25] = 0x08
  150. b[26] = status //status: 0x03, 0x02, 0x01
  151. b[27] = 0x01
  152. app.globalData.ble.send(cmd, b,timestamp,function(data){
  153. callback(data)
  154. })
  155. }
  156. function startFp_63(managerTelephone, managerPassword, userTelephone, userPassword, startTime, endTime, num,fingerprintId,timestamp,callback) {
  157. wx.showLoading({
  158. title: "正在发送...",
  159. mask:true
  160. });
  161. let cmd = 0x63
  162. let mt = util.stringToUint8Array(managerTelephone)
  163. let mp = util.stringToUint8Array(managerPassword)
  164. let ut = util.stringToUint8Array(userTelephone)
  165. let up = util.stringToUint8Array(userPassword)
  166. let ust = util.time40ToBytes(startTime)
  167. let uet = util.time40ToBytes(endTime)
  168. let fst = util.time40ToBytes(startTime)
  169. let fet = util.time40ToBytes(endTime)
  170. let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 2 + 10 + 5 + 5 + 1 + 2 + 1
  171. let b = new Uint8Array(length)
  172. b[0] = cmd
  173. b.set(mt, 1)
  174. b.set(mp, 12)
  175. b.set(ut, 18)
  176. b.set(up, 29)
  177. b.set(ust, 35)
  178. b.set(uet, 40)
  179. //权限
  180. b[45] = 0x46;
  181. b[46] = 0x46;
  182. b[47] = 0x46;
  183. b[48] = 0x46;
  184. //密码长度 uint16
  185. b[49] = 0
  186. b[50] = 0x0a
  187. //密码数据
  188. console.log(fingerprintId, '指纹ID')
  189. b[51] = fingerprintId
  190. b[52] = 0xff
  191. b[53] = 0xff
  192. b[54] = 0xff
  193. b[55] = 0xff
  194. b[56] = 0xff
  195. b[57] = 0xff
  196. b[58] = 0xff
  197. b[59] = 0xff
  198. b[60] = 0xff
  199. b.set(fst, 61)
  200. b.set(fet, 66)
  201. b[71] = 0xff;
  202. b[72] = 0xff;
  203. b[73] = 0xff;
  204. b[74] = num; //添加指纹
  205. app.globalData.ble.send(cmd, b,timestamp,function(data){
  206. callback(data)
  207. })
  208. }
  209. module.exports = {
  210. startFp1_63,startFp_26,startFp_23,openLock,startFp_29,startFp_63
  211. }