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.

wjBleAPI.js 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. "use strict";
  2. var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
  3. return typeof e
  4. } : function(e) {
  5. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" :
  6. typeof e
  7. },
  8. _wjUtils = require("./wjUtils.js"),
  9. _wjUtils2 = _interopRequireDefault(_wjUtils),
  10. _wjService = require("./wjService.js"),
  11. _wjService2 = _interopRequireDefault(_wjService),
  12. _wjDataInteract = require("./wjDataInteract.js"),
  13. _wjDataInteract2 = _interopRequireDefault(_wjDataInteract),
  14. _wjDataAnalysis = require("./wjDataAnalysis.js"),
  15. _wjDataAnalysis2 = _interopRequireDefault(_wjDataAnalysis),
  16. _wjDataEncode = require("./wjDataEncode.js"),
  17. _wjDataEncode2 = _interopRequireDefault(_wjDataEncode);
  18. function _interopRequireDefault(e) {
  19. return e && e.__esModule ? e : {
  20. default: e
  21. }
  22. }
  23. var TAG_FUNCTION = "function";
  24. function connectDevice2(t, a) {
  25. var i = {};
  26. _wjService2.default.reallyscanConnect(function(e) {
  27. i.code = e.serviceCode, i.msg = e.serviceInfo, i.data = [], _wjUtils2.default.showLog("连接結果:" + i.msg),
  28. (void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(i)
  29. }, function(e) {
  30. (i = {
  31. data: []
  32. }).code = e.serviceCode, i.msg = e.serviceInfo, _wjUtils2.default.showLog("连接状态:" + i.msg), (void 0 ===
  33. a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
  34. })
  35. }
  36. function connectDevice(e, t, a) {
  37. var i = {};
  38. _wjService2.default.reallyConnect(e, function(e) {
  39. i.data = [], i.code = e.serviceCode, i.msg = e.serviceInfo, _wjUtils2.default.showLog("连接结果:", i.msg), (
  40. void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(i)
  41. }, function(e) {
  42. (i = {
  43. data: []
  44. }).code = e.serviceCode, i.msg = e.serviceInfo, _wjUtils2.default.showLog("连接状态:", i.msg), (void 0 ===
  45. a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
  46. })
  47. }
  48. function disconnectDevice(t) {
  49. var a = {
  50. data: []
  51. };
  52. _wjService2.default.reallyDisConnect(function(e) {
  53. a.code = e.serviceCode, a.msg = e.serviceInfo, (void 0 === t ? "undefined" : _typeof(t)) ==
  54. TAG_FUNCTION && t(a)
  55. })
  56. }
  57. function transCmd(t, i, n) {
  58. _wjUtils2.default.showLog("start transCmd");
  59. var d = {};
  60. if (null != t && "" != t && 0 < t.length && "10" == i || "20" == i || "30" == i || "00" == i) {
  61. var o = {},
  62. s = "82";
  63. d.data = new Array;
  64. var r = t.length,
  65. f = 0;
  66. ! function a() {
  67. if (t[f].length % 2 == 0) {
  68. var e = "01" + _wjUtils2.default.byte2hexStr(parseInt(t[f].length / 2)) + t[f];
  69. _wjUtils2.default.showLog("reqapdu:" + e), 0 == (o = _wjDataEncode2.default.encode(e, i, s))
  70. .serviceCode ? _wjDataInteract2.default._StartSendData(o.serviceData.dataEncode, function(e) {
  71. if (d.code = e.serviceCode, 0 == e.serviceCode)
  72. if (_wjUtils2.default.showLog("APDU透传指令成功"), 4 < e.serviceData.dataBuff.length) {
  73. var t = e.serviceData.dataBuff.substring(4);
  74. _wjUtils2.default.showLog("revtpdu:" + t), d.data[f] = t, ++f < r ? (_wjUtils2
  75. .default.showLog("sendIndex:" + f), a()) : (d.msg = "transcmd success", (
  76. void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d))
  77. } else d.code = 1204, d.data = [], d.msg = "transcmd success but data error", _wjUtils2
  78. .default.showError("transcmd success but data error"), (void 0 === n ? "undefined" :
  79. _typeof(n)) == TAG_FUNCTION && n(d);
  80. else d.msg = e.serviceInfo, (void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(
  81. d)
  82. }) : (d.code = 1203, d.msg = "encode fail!", _wjUtils2.default.showError("encode fail!"), (
  83. void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d))
  84. } else d.code = 1202, d.msg = "The " + f + "th cmd maybe error", _wjUtils2.default.showError("The " + f +
  85. "th cmd maybe error"), (void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d)
  86. }()
  87. } else d.code = 1201, d.msg = "paramaters maybe error!", _wjUtils2.default.showError("paramaters maybe error"), (
  88. void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d)
  89. }
  90. function transCmd2(e, t, a, i) {
  91. var n = {};
  92. if ("10" == t || "20" == t || "30" == t || "00" == t && e.length % 2 == 0) {
  93. var d, o = "01" + _wjUtils2.default.byte2hexStr(parseInt(e.length / 2)) + e;
  94. d = _wjDataEncode2.default.encode(o, t, a), _wjDataInteract2.default._StartSendData(d.serviceData.dataEncode,
  95. function(e) {
  96. if (0 == e.serviceCode) {
  97. _wjUtils2.default.showLog("APDU透传指令成功");
  98. var t = (n = e).serviceData.dataBuff;
  99. 4 < t.length ? e.serviceData = t.substr(4) : e.serviceData = "", (void 0 === i ? "undefined" :
  100. _typeof(i)) == TAG_FUNCTION && i(n)
  101. } else n = e, (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(n)
  102. })
  103. } else n.serviceCode = -1, n.serviceInfo = "command参数错误!", (void 0 === i ? "undefined" : _typeof(i)) ==
  104. TAG_FUNCTION && i(n)
  105. }
  106. function getDeviceInfo(e, t) {
  107. var a, i = {},
  108. n = "",
  109. d = _wjUtils2.default.getCMD_TYPE();
  110. 0 == d ? n = "810100" + e : 1 == d && (n = "A501" + e), a = _wjDataEncode2.default.encode(n), _wjDataInteract2
  111. .default._StartSendData(a.serviceData.dataEncode, function(e) {
  112. i = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取设备信息成功"), _wjDataAnalysis2.default
  113. .analysisDeviceInfo(e.serviceData.dataBuff)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
  114. TAG_FUNCTION && t(i)
  115. })
  116. }
  117. function initIC(t) {
  118. var e, a = {},
  119. i = "",
  120. n = _wjUtils2.default.getCMD_TYPE();
  121. 0 == n ? i = "80" : 1 == n && (i = "A2"), e = _wjDataEncode2.default.encode(i), _wjDataInteract2.default
  122. ._StartSendData(e.serviceData.dataEncode, function(e) {
  123. a = 0 == e.serviceCode ? _wjDataAnalysis2.default.analysisinitIC(e.serviceData.dataBuff) : e, (
  124. void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(a)
  125. })
  126. }
  127. function initESAM(t) {
  128. var e, a = {},
  129. i = "",
  130. n = _wjUtils2.default.getCMD_TYPE();
  131. 0 == n ? i = "8001" : 1 == n && (i = "A2"), e = _wjDataEncode2.default.encode(i), _wjDataInteract2.default
  132. ._StartSendData(e.serviceData.dataEncode, function(e) {
  133. 0 == e.serviceCode ? (a.serviceCode = e.serviceCode, a.serviceInfo = "initESAM success") : a = e, (
  134. void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(a)
  135. })
  136. }
  137. function selectDir(a, e, i) {
  138. var n = {};
  139. if (4 == a.length && "10" == e || "20" == e) {
  140. var t = "00A4000002" + a,
  141. d = e,
  142. o = "";
  143. 1 == _wjUtils2.default.getTRANSFER_TYPE() && (t = _wjUtils2.default.TPDU2APDU(t));
  144. var s = _wjUtils2.default.getCMD_TYPE();
  145. 0 == s ? o = "82" : 1 == s && (o = "A3"), this.transCmd(t, d, o, function(e) {
  146. if (0 == e.serviceCode) {
  147. var t = _wjDataAnalysis2.default._analysisIs9000(e.serviceData);
  148. n = e, 0 == t.serviceCode && (_wjUtils2.default.showLog("进 " + a + " 目录成功"), n.serviceInfo =
  149. "进" + a + "目录成功"), (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(n)
  150. } else n = e, (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(n)
  151. })
  152. } else n.serviceCode = -1, n.serviceInfo = "参数长度有误", (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(
  153. n)
  154. }
  155. function getCardInfo(e, t) {
  156. var a = {},
  157. i = "00B095002B",
  158. n = "",
  159. d = "";
  160. 1 == _wjUtils2.default.getTRANSFER_TYPE() && (i = _wjUtils2.default.TPDU2APDU(i));
  161. var o = _wjUtils2.default.getCMD_TYPE();
  162. 0 == o ? (n = "10", d = "82") : 1 == o && (n = "00", d = "A3"), this.transCmd(i, n, d, function(e) {
  163. a = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取卡片信息成功"), _wjDataAnalysis2.default
  164. .analysisCardInfo(e.serviceData)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
  165. TAG_FUNCTION && t(a)
  166. })
  167. }
  168. function getRand(e, t) {
  169. var a = {},
  170. i = "0084000004",
  171. n = e,
  172. d = "";
  173. 1 == _wjUtils2.default.getTRANSFER_TYPE() && (i = _wjUtils2.default.TPDU2APDU(i));
  174. var o = _wjUtils2.default.getCMD_TYPE();
  175. 0 == o ? d = "82" : 1 == o && (d = "A3"), this.transCmd(i, n, d, function(e) {
  176. a = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取IC随机数成功"), _wjDataAnalysis2.default
  177. .analysisGetRand(e.serviceData)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
  178. TAG_FUNCTION && t(a)
  179. })
  180. }
  181. function getObuSysInfo(t) {
  182. var a = {},
  183. e = "00B0810063",
  184. i = "",
  185. n = "";
  186. 1 == _wjUtils2.default.getTRANSFER_TYPE() && (e = _wjUtils2.default.TPDU2APDU(e));
  187. var d = _wjUtils2.default.getCMD_TYPE();
  188. 0 == d ? (i = "20", n = "82") : 1 == d && (i = "00", n = "A0"), this.transCmd(e, i, n, function(e) {
  189. a = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取系统信息成功"), _wjDataAnalysis2.default
  190. .analysisgetObuSysInfo(e.serviceData)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
  191. TAG_FUNCTION && t(a)
  192. })
  193. }
  194. function writeObuIssue(e, a) {
  195. var i = {};
  196. if (null != e && 20 == e.length) {
  197. var t = e,
  198. n = "",
  199. d = "";
  200. 1 == _wjUtils2.default.getTRANSFER_TYPE() && (t = _wjUtils2.default.TPDU2APDU(t));
  201. var o = _wjUtils2.default.getCMD_TYPE();
  202. 0 == o ? (n = "20", d = "82") : 1 == o && (n = "00", d = "A0"), this.transCmd(t, n, d, function(e) {
  203. if (0 == e.serviceCode) {
  204. var t = _wjDataAnalysis2.default._analysisIs9000(e.serviceData);
  205. i = e, 0 == t.serviceCode && (_wjUtils2.default.showLog("OBU激活成功"), i.serviceInfo = "OBU激活成功"),
  206. (void 0 === a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
  207. } else i = e, (void 0 === a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
  208. })
  209. } else i.serviceCode = -1, i.serviceInfo = "激活参数错误", (void 0 === a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(
  210. i)
  211. }
  212. module.exports = {
  213. connectDevice: connectDevice,
  214. connectDevice2: connectDevice2,
  215. disconnectDevice: disconnectDevice,
  216. transCmd: transCmd,
  217. getDeviceInfo: getDeviceInfo
  218. };