123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- "use strict";
- var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
- return typeof e
- } : function(e) {
- return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" :
- typeof e
- },
- _wjUtils = require("./wjUtils.js"),
- _wjUtils2 = _interopRequireDefault(_wjUtils),
- _wjService = require("./wjService.js"),
- _wjService2 = _interopRequireDefault(_wjService),
- _wjDataInteract = require("./wjDataInteract.js"),
- _wjDataInteract2 = _interopRequireDefault(_wjDataInteract),
- _wjDataAnalysis = require("./wjDataAnalysis.js"),
- _wjDataAnalysis2 = _interopRequireDefault(_wjDataAnalysis),
- _wjDataEncode = require("./wjDataEncode.js"),
- _wjDataEncode2 = _interopRequireDefault(_wjDataEncode);
-
- function _interopRequireDefault(e) {
- return e && e.__esModule ? e : {
- default: e
- }
- }
- var TAG_FUNCTION = "function";
-
- function connectDevice2(t, a) {
- var i = {};
- _wjService2.default.reallyscanConnect(function(e) {
- i.code = e.serviceCode, i.msg = e.serviceInfo, i.data = [], _wjUtils2.default.showLog("连接結果:" + i.msg),
- (void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(i)
- }, function(e) {
- (i = {
- data: []
- }).code = e.serviceCode, i.msg = e.serviceInfo, _wjUtils2.default.showLog("连接状态:" + i.msg), (void 0 ===
- a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
- })
- }
-
- function connectDevice(e, t, a) {
- var i = {};
- _wjService2.default.reallyConnect(e, function(e) {
- i.data = [], i.code = e.serviceCode, i.msg = e.serviceInfo, _wjUtils2.default.showLog("连接结果:", i.msg), (
- void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(i)
- }, function(e) {
- (i = {
- data: []
- }).code = e.serviceCode, i.msg = e.serviceInfo, _wjUtils2.default.showLog("连接状态:", i.msg), (void 0 ===
- a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
- })
- }
-
- function disconnectDevice(t) {
- var a = {
- data: []
- };
- _wjService2.default.reallyDisConnect(function(e) {
- a.code = e.serviceCode, a.msg = e.serviceInfo, (void 0 === t ? "undefined" : _typeof(t)) ==
- TAG_FUNCTION && t(a)
- })
- }
-
- function transCmd(t, i, n) {
- _wjUtils2.default.showLog("start transCmd");
- var d = {};
- if (null != t && "" != t && 0 < t.length && "10" == i || "20" == i || "30" == i || "00" == i) {
- var o = {},
- s = "82";
- d.data = new Array;
- var r = t.length,
- f = 0;
- ! function a() {
- if (t[f].length % 2 == 0) {
- var e = "01" + _wjUtils2.default.byte2hexStr(parseInt(t[f].length / 2)) + t[f];
- _wjUtils2.default.showLog("reqapdu:" + e), 0 == (o = _wjDataEncode2.default.encode(e, i, s))
- .serviceCode ? _wjDataInteract2.default._StartSendData(o.serviceData.dataEncode, function(e) {
- if (d.code = e.serviceCode, 0 == e.serviceCode)
- if (_wjUtils2.default.showLog("APDU透传指令成功"), 4 < e.serviceData.dataBuff.length) {
- var t = e.serviceData.dataBuff.substring(4);
- _wjUtils2.default.showLog("revtpdu:" + t), d.data[f] = t, ++f < r ? (_wjUtils2
- .default.showLog("sendIndex:" + f), a()) : (d.msg = "transcmd success", (
- void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d))
- } else d.code = 1204, d.data = [], d.msg = "transcmd success but data error", _wjUtils2
- .default.showError("transcmd success but data error"), (void 0 === n ? "undefined" :
- _typeof(n)) == TAG_FUNCTION && n(d);
- else d.msg = e.serviceInfo, (void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(
- d)
- }) : (d.code = 1203, d.msg = "encode fail!", _wjUtils2.default.showError("encode fail!"), (
- void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d))
- } else d.code = 1202, d.msg = "The " + f + "th cmd maybe error", _wjUtils2.default.showError("The " + f +
- "th cmd maybe error"), (void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d)
- }()
- } else d.code = 1201, d.msg = "paramaters maybe error!", _wjUtils2.default.showError("paramaters maybe error"), (
- void 0 === n ? "undefined" : _typeof(n)) == TAG_FUNCTION && n(d)
- }
-
- function transCmd2(e, t, a, i) {
- var n = {};
- if ("10" == t || "20" == t || "30" == t || "00" == t && e.length % 2 == 0) {
- var d, o = "01" + _wjUtils2.default.byte2hexStr(parseInt(e.length / 2)) + e;
- d = _wjDataEncode2.default.encode(o, t, a), _wjDataInteract2.default._StartSendData(d.serviceData.dataEncode,
- function(e) {
- if (0 == e.serviceCode) {
- _wjUtils2.default.showLog("APDU透传指令成功");
- var t = (n = e).serviceData.dataBuff;
- 4 < t.length ? e.serviceData = t.substr(4) : e.serviceData = "", (void 0 === i ? "undefined" :
- _typeof(i)) == TAG_FUNCTION && i(n)
- } else n = e, (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(n)
- })
- } else n.serviceCode = -1, n.serviceInfo = "command参数错误!", (void 0 === i ? "undefined" : _typeof(i)) ==
- TAG_FUNCTION && i(n)
- }
-
- function getDeviceInfo(e, t) {
- var a, i = {},
- n = "",
- d = _wjUtils2.default.getCMD_TYPE();
- 0 == d ? n = "810100" + e : 1 == d && (n = "A501" + e), a = _wjDataEncode2.default.encode(n), _wjDataInteract2
- .default._StartSendData(a.serviceData.dataEncode, function(e) {
- i = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取设备信息成功"), _wjDataAnalysis2.default
- .analysisDeviceInfo(e.serviceData.dataBuff)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
- TAG_FUNCTION && t(i)
- })
- }
-
- function initIC(t) {
- var e, a = {},
- i = "",
- n = _wjUtils2.default.getCMD_TYPE();
- 0 == n ? i = "80" : 1 == n && (i = "A2"), e = _wjDataEncode2.default.encode(i), _wjDataInteract2.default
- ._StartSendData(e.serviceData.dataEncode, function(e) {
- a = 0 == e.serviceCode ? _wjDataAnalysis2.default.analysisinitIC(e.serviceData.dataBuff) : e, (
- void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(a)
- })
- }
-
- function initESAM(t) {
- var e, a = {},
- i = "",
- n = _wjUtils2.default.getCMD_TYPE();
- 0 == n ? i = "8001" : 1 == n && (i = "A2"), e = _wjDataEncode2.default.encode(i), _wjDataInteract2.default
- ._StartSendData(e.serviceData.dataEncode, function(e) {
- 0 == e.serviceCode ? (a.serviceCode = e.serviceCode, a.serviceInfo = "initESAM success") : a = e, (
- void 0 === t ? "undefined" : _typeof(t)) == TAG_FUNCTION && t(a)
- })
- }
-
- function selectDir(a, e, i) {
- var n = {};
- if (4 == a.length && "10" == e || "20" == e) {
- var t = "00A4000002" + a,
- d = e,
- o = "";
- 1 == _wjUtils2.default.getTRANSFER_TYPE() && (t = _wjUtils2.default.TPDU2APDU(t));
- var s = _wjUtils2.default.getCMD_TYPE();
- 0 == s ? o = "82" : 1 == s && (o = "A3"), this.transCmd(t, d, o, function(e) {
- if (0 == e.serviceCode) {
- var t = _wjDataAnalysis2.default._analysisIs9000(e.serviceData);
- n = e, 0 == t.serviceCode && (_wjUtils2.default.showLog("进 " + a + " 目录成功"), n.serviceInfo =
- "进" + a + "目录成功"), (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(n)
- } else n = e, (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(n)
- })
- } else n.serviceCode = -1, n.serviceInfo = "参数长度有误", (void 0 === i ? "undefined" : _typeof(i)) == TAG_FUNCTION && i(
- n)
- }
-
- function getCardInfo(e, t) {
- var a = {},
- i = "00B095002B",
- n = "",
- d = "";
- 1 == _wjUtils2.default.getTRANSFER_TYPE() && (i = _wjUtils2.default.TPDU2APDU(i));
- var o = _wjUtils2.default.getCMD_TYPE();
- 0 == o ? (n = "10", d = "82") : 1 == o && (n = "00", d = "A3"), this.transCmd(i, n, d, function(e) {
- a = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取卡片信息成功"), _wjDataAnalysis2.default
- .analysisCardInfo(e.serviceData)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
- TAG_FUNCTION && t(a)
- })
- }
-
- function getRand(e, t) {
- var a = {},
- i = "0084000004",
- n = e,
- d = "";
- 1 == _wjUtils2.default.getTRANSFER_TYPE() && (i = _wjUtils2.default.TPDU2APDU(i));
- var o = _wjUtils2.default.getCMD_TYPE();
- 0 == o ? d = "82" : 1 == o && (d = "A3"), this.transCmd(i, n, d, function(e) {
- a = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取IC随机数成功"), _wjDataAnalysis2.default
- .analysisGetRand(e.serviceData)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
- TAG_FUNCTION && t(a)
- })
- }
-
- function getObuSysInfo(t) {
- var a = {},
- e = "00B0810063",
- i = "",
- n = "";
- 1 == _wjUtils2.default.getTRANSFER_TYPE() && (e = _wjUtils2.default.TPDU2APDU(e));
- var d = _wjUtils2.default.getCMD_TYPE();
- 0 == d ? (i = "20", n = "82") : 1 == d && (i = "00", n = "A0"), this.transCmd(e, i, n, function(e) {
- a = 0 == e.serviceCode ? (_wjUtils2.default.showLog("获取系统信息成功"), _wjDataAnalysis2.default
- .analysisgetObuSysInfo(e.serviceData)) : e, (void 0 === t ? "undefined" : _typeof(t)) ==
- TAG_FUNCTION && t(a)
- })
- }
-
- function writeObuIssue(e, a) {
- var i = {};
- if (null != e && 20 == e.length) {
- var t = e,
- n = "",
- d = "";
- 1 == _wjUtils2.default.getTRANSFER_TYPE() && (t = _wjUtils2.default.TPDU2APDU(t));
- var o = _wjUtils2.default.getCMD_TYPE();
- 0 == o ? (n = "20", d = "82") : 1 == o && (n = "00", d = "A0"), this.transCmd(t, n, d, function(e) {
- if (0 == e.serviceCode) {
- var t = _wjDataAnalysis2.default._analysisIs9000(e.serviceData);
- i = e, 0 == t.serviceCode && (_wjUtils2.default.showLog("OBU激活成功"), i.serviceInfo = "OBU激活成功"),
- (void 0 === a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
- } else i = e, (void 0 === a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(i)
- })
- } else i.serviceCode = -1, i.serviceInfo = "激活参数错误", (void 0 === a ? "undefined" : _typeof(a)) == TAG_FUNCTION && a(
- i)
- }
- module.exports = {
- connectDevice: connectDevice,
- connectDevice2: connectDevice2,
- disconnectDevice: disconnectDevice,
- transCmd: transCmd,
- getDeviceInfo: getDeviceInfo
- };
|