var $jscomp = $jscomp || {}; $jscomp.scope = {}; $jscomp.checkStringArgs = function(a, b, c) { if (null == a) throw new TypeError("The 'this' value for String.prototype." + c + " must not be null or undefined"); if (b instanceof RegExp) throw new TypeError("First argument to String.prototype." + c + " must not be a regular expression"); return a + "" }; $jscomp.ASSUME_ES5 = !1; $jscomp.ASSUME_NO_NATIVE_MAP = !1; $jscomp.ASSUME_NO_NATIVE_SET = !1; $jscomp.SIMPLE_FROUND_POLYFILL = !1; $jscomp.defineProperty = $jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) { a != Array.prototype && a != Object.prototype && (a[b] = c.value) }; $jscomp.getGlobal = function(a) { return "undefined" != typeof window && window === a ? a : "undefined" != typeof global && null != global ? global : a }; $jscomp.global = $jscomp.getGlobal(this); $jscomp.polyfill = function(a, b, c, e) { if (b) { c = $jscomp.global; a = a.split("."); for (e = 0; e < a.length - 1; e++) { var d = a[e]; d in c || (c[d] = {}); c = c[d] } a = a[a.length - 1]; e = c[a]; b = b(e); b != e && null != b && $jscomp.defineProperty(c, a, { configurable: !0, writable: !0, value: b }) } }; $jscomp.polyfill("String.prototype.startsWith", function(a) { return a ? a : function(a, c) { var b = $jscomp.checkStringArgs(this, a, "startsWith"); a += ""; var d = b.length, f = a.length; c = Math.max(0, Math.min(c | 0, b.length)); for (var h = 0; h < f && c < d;) if (b[c++] != a[h++]) return !1; return h >= f } }, "es6", "es3"); $jscomp.arrayIteratorImpl = function(a) { var b = 0; return function() { return b < a.length ? { done: !1, value: a[b++] } : { done: !0 } } }; $jscomp.arrayIterator = function(a) { return { next: $jscomp.arrayIteratorImpl(a) } }; $jscomp.makeIterator = function(a) { var b = "undefined" != typeof Symbol && Symbol.iterator && a[Symbol.iterator]; return b ? b.call(a) : $jscomp.arrayIterator(a) }; $jscomp.FORCE_POLYFILL_PROMISE = !1; $jscomp.polyfill("Promise", function(a) { function b() { this.batch_ = null } function c(a) { return a instanceof d ? a : new d(function(b, h) { b(a) }) } if (a && !$jscomp.FORCE_POLYFILL_PROMISE) return a; b.prototype.asyncExecute = function(a) { if (null == this.batch_) { this.batch_ = []; var b = this; this.asyncExecuteFunction(function() { b.executeBatch_() }) } this.batch_.push(a) }; var e = $jscomp.global.setTimeout; b.prototype.asyncExecuteFunction = function(a) { e(a, 0) }; b.prototype.executeBatch_ = function() { for (; this.batch_ && this.batch_.length;) { var a = this.batch_; this.batch_ = []; for (var b = 0; b < a.length; ++b) { var c = a[b]; a[b] = null; try { c() } catch (k) { this.asyncThrow_(k) } } } this.batch_ = null }; b.prototype.asyncThrow_ = function(a) { this.asyncExecuteFunction(function() { throw a; }) }; var d = function(a) { this.state_ = 0; this.result_ = void 0; this.onSettledCallbacks_ = []; var b = this.createResolveAndReject_(); try { a(b.resolve, b.reject) } catch (g) { b.reject(g) } }; d.prototype.createResolveAndReject_ = function() { function a(a) { return function(d) { c || (c = !0, a.call(b, d)) } } var b = this, c = !1; return { resolve: a(this.resolveTo_), reject: a(this.reject_) } }; d.prototype.resolveTo_ = function(a) { if (a === this) this.reject_(new TypeError("A Promise cannot resolve to itself")); else if (a instanceof d) this.settleSameAsPromise_(a); else { a: switch (typeof a) { case "object": var b = null != a; break a; case "function": b = !0; break a; default: b = !1 } b ? this.resolveToNonPromiseObj_(a) : this.fulfill_(a) } }; d.prototype.resolveToNonPromiseObj_ = function(a) { var b = void 0; try { b = a.then } catch (g) { this.reject_(g); return } "function" == typeof b ? this.settleSameAsThenable_(b, a) : this.fulfill_(a) }; d.prototype.reject_ = function(a) { this.settle_(2, a) }; d.prototype.fulfill_ = function(a) { this.settle_(1, a) }; d.prototype.settle_ = function(a, b) { if (0 != this.state_) throw Error("Cannot settle(" + a + ", " + b + "): Promise already settled in state" + this.state_); this.state_ = a; this.result_ = b; this.executeOnSettledCallbacks_() }; d.prototype.executeOnSettledCallbacks_ = function() { if (null != this.onSettledCallbacks_) { for (var a = 0; a < this.onSettledCallbacks_.length; ++a) f.asyncExecute(this .onSettledCallbacks_[a]); this.onSettledCallbacks_ = null } }; var f = new b; d.prototype.settleSameAsPromise_ = function(a) { var b = this.createResolveAndReject_(); a.callWhenSettled_(b.resolve, b.reject) }; d.prototype.settleSameAsThenable_ = function(a, b) { var c = this.createResolveAndReject_(); try { a.call(b, c.resolve, c.reject) } catch (k) { c.reject(k) } }; d.prototype.then = function(a, b) { function c(a, b) { return "function" == typeof a ? function(b) { try { e(a(b)) } catch (l) { f(l) } } : b } var e, f, h = new d(function(a, b) { e = a; f = b }); this.callWhenSettled_(c(a, e), c(b, f)); return h }; d.prototype.catch = function(a) { return this.then(void 0, a) }; d.prototype.callWhenSettled_ = function(a, b) { function c() { switch (d.state_) { case 1: a(d.result_); break; case 2: b(d.result_); break; default: throw Error("Unexpected state: " + d.state_); } } var d = this; null == this.onSettledCallbacks_ ? f.asyncExecute(c) : this.onSettledCallbacks_.push(c) }; d.resolve = c; d.reject = function(a) { return new d(function(b, c) { c(a) }) }; d.race = function(a) { return new d(function(b, d) { for (var e = $jscomp.makeIterator(a), f = e.next(); !f.done; f = e.next()) c(f.value) .callWhenSettled_(b, d) }) }; d.all = function(a) { var b = $jscomp.makeIterator(a), e = b.next(); return e.done ? c([]) : new d(function(a, d) { function f(b) { return function(c) { h[b] = c; k--; 0 == k && a(h) } } var h = [], k = 0; do h.push(void 0), k++, c(e.value).callWhenSettled_(f(h.length - 1), d), e = b .next(); while (!e.done) }) }; return d }, "es6", "es3"); var dataUtil = require("./jy-bluetooth-obu-interface.js"), errorCode = require("./jy-bluetooth-obu-ErrorCode.js"), mScanCount = 20, currentScanCount; function setScanParams(a, b) { mScanCount = a; dataUtil.setScanTimeOut(b) } function connectDevice(a, b) { dataUtil.connectBle(a, b) } function disconnectDevice(a) { dataUtil.selfDeviceChannel("C3", function(b, c) { c = {}; c.code = "0" == b ? errorCode.SUCCESS_CODE : b; "function" === typeof a && a(c); dataUtil.closeBle() }) } function transCmd(cmd, cmdtype, callback) { console.log("cmd===", cmd, cmdtype) //写卡 if (cmdtype == '10') { cardCommand(cmd, callback); console.log("callback===", cmd, callback) } if (cmdtype == '20') { esamCommand(cmd, callback); } } function esamCommand(a, b) { var c = []; c[0] = a; dataUtil.esamChannel(c, function(a, c) { var d = {}; "0" == a ? (d.code = errorCode.SUCCESS_CODE, d.data = c[0]) : (d.code = a, d.data = c); "function" === typeof b && b(d) }) } function cardCommand(a, b) { console.log("a====",a,b) var c = []; c[0] = a; dataUtil.cardChannel(c, function(a, c) { var d = {}; "0" == a ? (d.code = errorCode.SUCCESS_CODE, d.data = c[0]) : (d.code = a, d.data = c); "function" === typeof b && b(d) }) } function getCardInfo(a) { var b = ["00A40000021001"]; dataUtil.cardChannel(b, function(c, e) { var d = {}; "0" == c ? (dataUtil.consoleLog("res1\uff1a" + e), b[0] = "00B095002B", dataUtil.cardChannel(b, function(b, c) { "0" == b ? (dataUtil.consoleLog("res2\uff1a" + c), d.code = errorCode.SUCCESS_CODE, b = {}, b.provider = c[0].substring(0, 16), b.cardType = c[0].substring(16, 18), b.cardVersion = c[0].substring(18, 20), b.cardId = c[0].substring(20, 40), b .signedDate = c[0].substring(40, 48), b.expiredDate = c[0].substring(48, 56), b .vehicleNumber = c[0].substring(56, 80), b.userType = c[0].substring(80, 82), b.cardVersion.startsWith("4") ? ( console.log("4x\u5361\uff1a" + b.cardVersion), b.plateColor = c[0] .substring(82, 84), b.vehicleModel = c[0].substring(84, 86)) : (console.log( "\u975e4x\u5361\uff1a" + b.cardVersion), b.plateColor = c[0].substring( 84, 86), b.vehicleModel = "00"), d.cardInfo = b) : d.code = b; "function" === typeof a && a(d) })) : (d.code = c, "function" === typeof a && a(d)) }) } function getObuId(a) { dataUtil.selfDeviceChannel("CD", function(b, c) { var e = {}; "0" == b ? (e.code = errorCode.SUCCESS_CODE, e.obuId = c) : (console.log("res\uff1a" + c), e.code = b); "function" === typeof a && a(e) }) } function getSystemInfo(a) { dataUtil.esamChannel(["00A40000023F00", "00B081001B"], function(b, c) { var e = {}; "0" == b ? (e.code = errorCode.SUCCESS_CODE, b = c[1].substring(0, c[1].length - 4), c = {}, c .provider = b.substring(0, 16), c.type = b.substring(16, 18), c.version = b.substring(18, 20), c .serialNumber = b.substring(20, 36), c.signedDate = b.substring(36, 44), c.expiredDate = b .substring(44, 52), c.temperStatus = b.substring(52, 54), e.systemInfo = c) : e.code = b; "function" === typeof a && a(e) }) } module.exports = { setScanParams: setScanParams, connectDevice: connectDevice, disconnectDevice: disconnectDevice, esamCommand: esamCommand, cardCommand: cardCommand, transCmd: transCmd, getCardInfo: getCardInfo, getObuId: getObuId, getSystemInfo: getSystemInfo };