Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. _wjService = require("./wjService.js"),
  9. _wjService2 = _interopRequireDefault(_wjService),
  10. _wjUtils = require("./wjUtils.js"),
  11. _wjUtils2 = _interopRequireDefault(_wjUtils),
  12. _wjDataDecode = require("./wjDataDecode.js"),
  13. _wjDataDecode2 = _interopRequireDefault(_wjDataDecode);
  14. function _interopRequireDefault(e) {
  15. return e && e.__esModule ? e : {
  16. default: e
  17. }
  18. }
  19. var TAG_FUNCTION = "function",
  20. sendCallback = void 0,
  21. TimerID = null;
  22. function _StartSendData(o, e) {
  23. var s = {},
  24. u = 0,
  25. c = 0;
  26. null != TimerID && (clearTimeout(TimerID), TimerID = null), _wjDataDecode2.default.init(), TimerID = setTimeout(
  27. pro_timeout, 1e4), _wjUtils2.default.showLog(TimerID, "开启时钟"), sendCallback = e, _wjService2.default
  28. ._SetDataListenerCallBack(!0, datacallback),
  29. function t() {
  30. var e = "";
  31. 40 * c >= o[u].length && (u++, c = 0);
  32. u < o.length && (e = o[u].length >= 40 * (c + 1) ? o[u].substring(40 * c, 40 * (c + 1)) : o[u].substring(
  33. 40 * c, o[u].length));
  34. if ("" == e) _wjUtils2.default.showLog("数据发送完毕!");
  35. else {
  36. for (var a = _wjUtils2.default.hexStr2byteArray(e), l = new ArrayBuffer(a.byteLength), r = new DataView(
  37. l), i = 0; i < a.byteLength; i++) r.setUint8(i, a[i]);
  38. _wjUtils2.default.showLog("发送数据:", e), _wjService2.default._writeBLECharacteristicValue(l, function(e) {
  39. 0 == e.serviceCode ? (c++, t()) : (_wjUtils2.default.showError(TimerID, "数据发送失败,取消时钟"),
  40. null != TimerID && (clearTimeout(TimerID), TimerID = null), _wjService2.default
  41. ._SetDataListenerCallBack(!1), s.serviceCode = -2, s.serviceInfo = "数据发送失败", (
  42. void 0 === sendCallback ? "undefined" : _typeof(sendCallback)) ==
  43. TAG_FUNCTION && sendCallback(s))
  44. })
  45. }
  46. }()
  47. }
  48. function datacallback(e) {
  49. _wjService2.default._SetDataListenerCallBack(!0, datacallback), _ReceiveData(e)
  50. }
  51. function pro_timeout() {
  52. var e = {};
  53. _wjUtils2.default.showError(TimerID, "数据接收超时,取消时钟"), null != TimerID && (clearTimeout(TimerID), TimerID = null),
  54. _wjService2.default._SetDataListenerCallBack(!1), e.serviceCode = -3, e.serviceInfo = "数据接收超时", (void 0 ===
  55. sendCallback ? "undefined" : _typeof(sendCallback)) == TAG_FUNCTION && sendCallback(e)
  56. }
  57. function _ReceiveData(e) {
  58. var t, a, l = {},
  59. r = _wjUtils2.default.getProtocolType();
  60. 0 == r ? t = _wjDataDecode2.default.decode_GB(e) : 1 == r && (t = _wjDataDecode2.default.decode_WX(e)), 0 == t
  61. .serviceCode && (null != (a = PackageDecode(t.serviceData.strData)) ? (_wjUtils2.default.showLog(TimerID,
  62. "接收数据成功,取消时钟"), null != TimerID && (clearTimeout(TimerID), TimerID = null), _wjService2.default
  63. ._SetDataListenerCallBack(!1), l.serviceCode = 0, l.serviceInfo = "数据接收成功", l.serviceData = {}, l
  64. .serviceData.dataBuff = a) : (_wjUtils2.default.showError(TimerID, "数据解析失败,取消时钟"), null != TimerID && (
  65. clearTimeout(TimerID), TimerID = null), _wjService2.default._SetDataListenerCallBack(!1), l
  66. .serviceCode = -1, l.serviceInfo = "数据解析失败"), (void 0 === sendCallback ? "undefined" : _typeof(
  67. sendCallback)) == TAG_FUNCTION && sendCallback(l))
  68. }
  69. function PackageDecode(e) {
  70. if (null == e || null == e) return _wjUtils2.default.showError("revStrData == null"), null;
  71. var t, a = _wjUtils2.default.getDATA_TYPE(),
  72. l = _wjUtils2.default.hexStr2byteArray(e),
  73. r = 0,
  74. i = l[1],
  75. o = l[0];
  76. if (_wjUtils2.default.showLog("WJPackageDecode:", e), 0 != i) return _wjUtils2.default.showError("WJ结果码非00"), null;
  77. switch (o) {
  78. case 146:
  79. case 176:
  80. case 179:
  81. case 180:
  82. if (0 == a) {
  83. var s = 7;
  84. 129 == l[5] && (129 == l[6] ? (r = 255 & l[7], s += 1) : 130 == l[6] ? (r = l[7] << 8, r += 255 & l[8],
  85. s += 2) : r = 255 & l[6]), t = l.slice(s, r + s), c = _wjUtils2.default.byteArray2hexStr(t)
  86. } else 1 == a && (t = l.slice(5), c = _wjUtils2.default.APDU2TPDU(_wjUtils2.default.byteArray2hexStr(t)));
  87. return _wjUtils2.default.showLog("WJ有效数据长度:", c.length / 2, c), _wjUtils2.default.showLog("操作类型ok", o), c;
  88. case 145:
  89. case 148:
  90. case 144:
  91. var u = (255 & l[3]) << 8;
  92. u += l[2], t = l.slice(4, u + 4);
  93. var c = _wjUtils2.default.byteArray2hexStr(t);
  94. return _wjUtils2.default.showLog("WJ有效数据长度:", u, _wjUtils2.default.byteArray2hexStr(t)), _wjUtils2.default
  95. .showLog("操作类型ok", o), c;
  96. case 181:
  97. u = l[2];
  98. return t = l.slice(3, u + 3), _wjUtils2.default.showLog("WJ有效数据长度:", u, _wjUtils2.default.byteArray2hexStr(
  99. t)), _wjUtils2.default.showLog("操作类型ok", o), _wjUtils2.default.byteArray2hexStr(t);
  100. default:
  101. return _wjUtils2.default.showError("WJ通道类型有误"), null
  102. }
  103. }
  104. module.exports = {
  105. _StartSendData: _StartSendData,
  106. _ReceiveData: _ReceiveData
  107. };