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.

jy-bluetooth-obu-wechatmp.js 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. var $jscomp = $jscomp || {};
  2. $jscomp.scope = {};
  3. $jscomp.checkStringArgs = function(a, b, c) {
  4. if (null == a) throw new TypeError("The 'this' value for String.prototype." + c +
  5. " must not be null or undefined");
  6. if (b instanceof RegExp) throw new TypeError("First argument to String.prototype." + c +
  7. " must not be a regular expression");
  8. return a + ""
  9. };
  10. $jscomp.ASSUME_ES5 = !1;
  11. $jscomp.ASSUME_NO_NATIVE_MAP = !1;
  12. $jscomp.ASSUME_NO_NATIVE_SET = !1;
  13. $jscomp.SIMPLE_FROUND_POLYFILL = !1;
  14. $jscomp.defineProperty = $jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties ? Object.defineProperty :
  15. function(a, b, c) {
  16. a != Array.prototype && a != Object.prototype && (a[b] = c.value)
  17. };
  18. $jscomp.getGlobal = function(a) {
  19. return "undefined" != typeof window && window === a ? a : "undefined" != typeof global && null != global ?
  20. global : a
  21. };
  22. $jscomp.global = $jscomp.getGlobal(this);
  23. $jscomp.polyfill = function(a, b, c, e) {
  24. if (b) {
  25. c = $jscomp.global;
  26. a = a.split(".");
  27. for (e = 0; e < a.length - 1; e++) {
  28. var d = a[e];
  29. d in c || (c[d] = {});
  30. c = c[d]
  31. }
  32. a = a[a.length - 1];
  33. e = c[a];
  34. b = b(e);
  35. b != e && null != b && $jscomp.defineProperty(c, a, {
  36. configurable: !0,
  37. writable: !0,
  38. value: b
  39. })
  40. }
  41. };
  42. $jscomp.polyfill("String.prototype.startsWith", function(a) {
  43. return a ? a : function(a, c) {
  44. var b = $jscomp.checkStringArgs(this, a, "startsWith");
  45. a += "";
  46. var d = b.length,
  47. f = a.length;
  48. c = Math.max(0, Math.min(c | 0, b.length));
  49. for (var h = 0; h < f && c < d;)
  50. if (b[c++] != a[h++]) return !1;
  51. return h >= f
  52. }
  53. }, "es6", "es3");
  54. $jscomp.arrayIteratorImpl = function(a) {
  55. var b = 0;
  56. return function() {
  57. return b < a.length ? {
  58. done: !1,
  59. value: a[b++]
  60. } : {
  61. done: !0
  62. }
  63. }
  64. };
  65. $jscomp.arrayIterator = function(a) {
  66. return {
  67. next: $jscomp.arrayIteratorImpl(a)
  68. }
  69. };
  70. $jscomp.makeIterator = function(a) {
  71. var b = "undefined" != typeof Symbol && Symbol.iterator && a[Symbol.iterator];
  72. return b ? b.call(a) : $jscomp.arrayIterator(a)
  73. };
  74. $jscomp.FORCE_POLYFILL_PROMISE = !1;
  75. $jscomp.polyfill("Promise", function(a) {
  76. function b() {
  77. this.batch_ = null
  78. }
  79. function c(a) {
  80. return a instanceof d ? a : new d(function(b, h) {
  81. b(a)
  82. })
  83. }
  84. if (a && !$jscomp.FORCE_POLYFILL_PROMISE) return a;
  85. b.prototype.asyncExecute = function(a) {
  86. if (null == this.batch_) {
  87. this.batch_ = [];
  88. var b = this;
  89. this.asyncExecuteFunction(function() {
  90. b.executeBatch_()
  91. })
  92. }
  93. this.batch_.push(a)
  94. };
  95. var e = $jscomp.global.setTimeout;
  96. b.prototype.asyncExecuteFunction = function(a) {
  97. e(a, 0)
  98. };
  99. b.prototype.executeBatch_ = function() {
  100. for (; this.batch_ && this.batch_.length;) {
  101. var a =
  102. this.batch_;
  103. this.batch_ = [];
  104. for (var b = 0; b < a.length; ++b) {
  105. var c = a[b];
  106. a[b] = null;
  107. try {
  108. c()
  109. } catch (k) {
  110. this.asyncThrow_(k)
  111. }
  112. }
  113. }
  114. this.batch_ = null
  115. };
  116. b.prototype.asyncThrow_ = function(a) {
  117. this.asyncExecuteFunction(function() {
  118. throw a;
  119. })
  120. };
  121. var d = function(a) {
  122. this.state_ = 0;
  123. this.result_ = void 0;
  124. this.onSettledCallbacks_ = [];
  125. var b = this.createResolveAndReject_();
  126. try {
  127. a(b.resolve, b.reject)
  128. } catch (g) {
  129. b.reject(g)
  130. }
  131. };
  132. d.prototype.createResolveAndReject_ = function() {
  133. function a(a) {
  134. return function(d) {
  135. c || (c = !0, a.call(b, d))
  136. }
  137. }
  138. var b = this,
  139. c = !1;
  140. return {
  141. resolve: a(this.resolveTo_),
  142. reject: a(this.reject_)
  143. }
  144. };
  145. d.prototype.resolveTo_ = function(a) {
  146. if (a === this) this.reject_(new TypeError("A Promise cannot resolve to itself"));
  147. else if (a instanceof d) this.settleSameAsPromise_(a);
  148. else {
  149. a: switch (typeof a) {
  150. case "object":
  151. var b = null != a;
  152. break a;
  153. case "function":
  154. b = !0;
  155. break a;
  156. default:
  157. b = !1
  158. }
  159. b ? this.resolveToNonPromiseObj_(a) : this.fulfill_(a)
  160. }
  161. };
  162. d.prototype.resolveToNonPromiseObj_ = function(a) {
  163. var b = void 0;
  164. try {
  165. b = a.then
  166. } catch (g) {
  167. this.reject_(g);
  168. return
  169. }
  170. "function" == typeof b ?
  171. this.settleSameAsThenable_(b, a) : this.fulfill_(a)
  172. };
  173. d.prototype.reject_ = function(a) {
  174. this.settle_(2, a)
  175. };
  176. d.prototype.fulfill_ = function(a) {
  177. this.settle_(1, a)
  178. };
  179. d.prototype.settle_ = function(a, b) {
  180. if (0 != this.state_) throw Error("Cannot settle(" + a + ", " + b +
  181. "): Promise already settled in state" + this.state_);
  182. this.state_ = a;
  183. this.result_ = b;
  184. this.executeOnSettledCallbacks_()
  185. };
  186. d.prototype.executeOnSettledCallbacks_ = function() {
  187. if (null != this.onSettledCallbacks_) {
  188. for (var a = 0; a < this.onSettledCallbacks_.length; ++a) f.asyncExecute(this
  189. .onSettledCallbacks_[a]);
  190. this.onSettledCallbacks_ = null
  191. }
  192. };
  193. var f = new b;
  194. d.prototype.settleSameAsPromise_ = function(a) {
  195. var b = this.createResolveAndReject_();
  196. a.callWhenSettled_(b.resolve, b.reject)
  197. };
  198. d.prototype.settleSameAsThenable_ = function(a, b) {
  199. var c = this.createResolveAndReject_();
  200. try {
  201. a.call(b, c.resolve, c.reject)
  202. } catch (k) {
  203. c.reject(k)
  204. }
  205. };
  206. d.prototype.then = function(a, b) {
  207. function c(a, b) {
  208. return "function" == typeof a ? function(b) {
  209. try {
  210. e(a(b))
  211. } catch (l) {
  212. f(l)
  213. }
  214. } : b
  215. }
  216. var e, f, h = new d(function(a, b) {
  217. e = a;
  218. f = b
  219. });
  220. this.callWhenSettled_(c(a, e), c(b, f));
  221. return h
  222. };
  223. d.prototype.catch = function(a) {
  224. return this.then(void 0, a)
  225. };
  226. d.prototype.callWhenSettled_ = function(a, b) {
  227. function c() {
  228. switch (d.state_) {
  229. case 1:
  230. a(d.result_);
  231. break;
  232. case 2:
  233. b(d.result_);
  234. break;
  235. default:
  236. throw Error("Unexpected state: " + d.state_);
  237. }
  238. }
  239. var d = this;
  240. null == this.onSettledCallbacks_ ? f.asyncExecute(c) : this.onSettledCallbacks_.push(c)
  241. };
  242. d.resolve = c;
  243. d.reject = function(a) {
  244. return new d(function(b, c) {
  245. c(a)
  246. })
  247. };
  248. d.race = function(a) {
  249. return new d(function(b, d) {
  250. for (var e = $jscomp.makeIterator(a), f = e.next(); !f.done; f = e.next()) c(f.value)
  251. .callWhenSettled_(b,
  252. d)
  253. })
  254. };
  255. d.all = function(a) {
  256. var b = $jscomp.makeIterator(a),
  257. e = b.next();
  258. return e.done ? c([]) : new d(function(a, d) {
  259. function f(b) {
  260. return function(c) {
  261. h[b] = c;
  262. k--;
  263. 0 == k && a(h)
  264. }
  265. }
  266. var h = [],
  267. k = 0;
  268. do h.push(void 0), k++, c(e.value).callWhenSettled_(f(h.length - 1), d), e = b
  269. .next(); while (!e.done)
  270. })
  271. };
  272. return d
  273. }, "es6", "es3");
  274. var dataUtil = require("./jy-bluetooth-obu-interface.js"),
  275. errorCode = require("./jy-bluetooth-obu-ErrorCode.js"),
  276. mScanCount = 20,
  277. currentScanCount;
  278. function setScanParams(a, b) {
  279. mScanCount = a;
  280. dataUtil.setScanTimeOut(b)
  281. }
  282. function connectDevice(a, b) {
  283. dataUtil.connectBle(a, b)
  284. }
  285. function disconnectDevice(a) {
  286. dataUtil.selfDeviceChannel("C3", function(b, c) {
  287. c = {};
  288. c.code = "0" == b ? errorCode.SUCCESS_CODE : b;
  289. "function" === typeof a && a(c);
  290. dataUtil.closeBle()
  291. })
  292. }
  293. function transCmd(cmd, cmdtype, callback) {
  294. console.log("cmd===", cmd, cmdtype)
  295. //写卡
  296. if (cmdtype == '10') {
  297. cardCommand(cmd, callback);
  298. console.log("callback===", cmd, callback)
  299. }
  300. if (cmdtype == '20') {
  301. esamCommand(cmd, callback);
  302. }
  303. }
  304. function esamCommand(a, b) {
  305. var c = [];
  306. c[0] = a;
  307. dataUtil.esamChannel(c, function(a, c) {
  308. var d = {};
  309. "0" == a ? (d.code = errorCode.SUCCESS_CODE, d.data = c[0]) : (d.code = a, d.data = c);
  310. "function" === typeof b && b(d)
  311. })
  312. }
  313. function cardCommand(a, b) {
  314. console.log("a====",a,b)
  315. var c = [];
  316. c[0] = a;
  317. dataUtil.cardChannel(c, function(a, c) {
  318. var d = {};
  319. "0" == a ? (d.code = errorCode.SUCCESS_CODE, d.data = c[0]) : (d.code = a, d.data = c);
  320. "function" === typeof b && b(d)
  321. })
  322. }
  323. function getCardInfo(a) {
  324. var b = ["00A40000021001"];
  325. dataUtil.cardChannel(b, function(c, e) {
  326. var d = {};
  327. "0" == c ? (dataUtil.consoleLog("res1\uff1a" + e), b[0] = "00B095002B", dataUtil.cardChannel(b,
  328. function(b, c) {
  329. "0" == b ? (dataUtil.consoleLog("res2\uff1a" + c), d.code = errorCode.SUCCESS_CODE,
  330. b = {}, b.provider = c[0].substring(0, 16), b.cardType = c[0].substring(16, 18),
  331. b.cardVersion = c[0].substring(18, 20), b.cardId = c[0].substring(20, 40), b
  332. .signedDate = c[0].substring(40, 48), b.expiredDate = c[0].substring(48, 56), b
  333. .vehicleNumber = c[0].substring(56,
  334. 80), b.userType = c[0].substring(80, 82), b.cardVersion.startsWith("4") ? (
  335. console.log("4x\u5361\uff1a" + b.cardVersion), b.plateColor = c[0]
  336. .substring(82, 84), b.vehicleModel = c[0].substring(84, 86)) : (console.log(
  337. "\u975e4x\u5361\uff1a" + b.cardVersion), b.plateColor = c[0].substring(
  338. 84, 86), b.vehicleModel = "00"), d.cardInfo = b) : d.code = b;
  339. "function" === typeof a && a(d)
  340. })) : (d.code = c, "function" === typeof a && a(d))
  341. })
  342. }
  343. function getObuId(a) {
  344. dataUtil.selfDeviceChannel("CD", function(b, c) {
  345. var e = {};
  346. "0" == b ? (e.code = errorCode.SUCCESS_CODE, e.obuId = c) : (console.log("res\uff1a" + c), e.code = b);
  347. "function" === typeof a && a(e)
  348. })
  349. }
  350. function getSystemInfo(a) {
  351. dataUtil.esamChannel(["00A40000023F00", "00B081001B"], function(b, c) {
  352. var e = {};
  353. "0" == b ? (e.code = errorCode.SUCCESS_CODE, b = c[1].substring(0, c[1].length - 4), c = {}, c
  354. .provider = b.substring(0, 16), c.type = b.substring(16, 18), c.version = b.substring(18, 20), c
  355. .serialNumber = b.substring(20, 36), c.signedDate = b.substring(36, 44), c.expiredDate = b
  356. .substring(44, 52), c.temperStatus = b.substring(52, 54), e.systemInfo = c) : e.code = b;
  357. "function" === typeof a && a(e)
  358. })
  359. }
  360. module.exports = {
  361. setScanParams: setScanParams,
  362. connectDevice: connectDevice,
  363. disconnectDevice: disconnectDevice,
  364. esamCommand: esamCommand,
  365. cardCommand: cardCommand,
  366. transCmd: transCmd,
  367. getCardInfo: getCardInfo,
  368. getObuId: getObuId,
  369. getSystemInfo: getSystemInfo
  370. };