123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861 |
- var a = require('./GenvictDataUtil.js');
- const common_vendor = require("../../../common/vendor.js");
- var uni = common_vendor.index
- var b = [];
- var c = '';
- var d = '';
- var e = '';
- var f = '';
- var g = [];
- var h = 0;
- var i = 3;
- var j;
- var k = false;
- var l = [];
- var m = [];
- var n = 0;
- var o = 0;
- var p = 0;
- var q = "";
- var r = 0;
- var s;
- var t = new Array();
- var u = 0;
- var v;
- var w = false;
- const ARTC_SERVICE_UUID = '0000FEE7-0000-1000-8000-00805F9B34FB';
- const ARTC_WRTIE_UUID = '0000FEC7-0000-1000-8000-00805F9B34FB';
- const ARTC_READ_UUID = '0000FEC8-0000-1000-8000-00805F9B34FB';
- const SUCCESS_CODE = 0;
- const FAILED_CODE = 1;
- const PLOY_SERVICE_FAILE = '2';
- const PLOY_NO_AIM_SERVICE = '3';
- const PLOY_CHARACTERISTIC_FAILE = '4';
- const PLOY_NO_CHARACTERISTIC = '5';
- const PLOY_NOTIY_FAILE = '6';
- const COS_SUCCESS_CODE = '9000';
-
- function openBle(x) {
- uni.openBluetoothAdapter({
- success(res) {
- typeof x === 'function' && x(SUCCESS_CODE)
- },
- fail() {
- typeof x === 'function' && x(FAILED_CODE)
- }
- })
- };
-
- function closeBle(x) {
- uni.closeBluetoothAdapter({
- success(res) {
- typeof x === 'function' && x(SUCCESS_CODE)
- },
- fail() {
- typeof x === 'function' && x(FAILED_CODE)
- }
- })
- };
-
- function scanBle(x) {
- b = [];
- uni.startBluetoothDevicesDiscovery({
- success(res) {
- uni.onBluetoothDeviceFound((res) => {
- for (let i = 0; i < res.devices.length; i++) {
- let isHave = false;
- for (let j = 0; j < b.length; j++) {
- if (res.devices[i].deviceId === b[j].deviceId) {
- isHave = true;
- break
- }
- };
- if (!isHave) {
- console.log(res.devices[i].name);
- if (res.devices[i].name.indexOf("GV__GD_FK") == 0 || res.devices[i].name
- .indexOf("GV_HCB_Q1") == 0 || res.devices[i].name.indexOf("GV__BT_WX") ==
- 0 || res.devices[i].name.indexOf("GENVICT") == 0 || res.devices[i].name
- .indexOf("GXETC_GV") == 0 || res.devices[i].name.indexOf("zj") == 0 || res
- .devices[i].name.indexOf("JY") == 0 || res.devices[i].name.indexOf(
- "SD_BT_WX") == 0 || res.devices[i].name.indexOf("GS") == 0 || res
- .devices[i].name.indexOf("GV") == 0 || res.devices[i].name.indexOf("ETC") ==
- 0 || res.devices[i].name.indexOf("HN") == 0) {
- b.push(res.devices[i]);
- x(res.devices[i])
- }
- }
- }
- })
- },
- fail() {
- typeof x === 'function' && x(FAILED_CODE)
- }
- })
- };
-
- function connectDevice(x, y, z) {
- uni.stopBluetoothDevicesDiscovery({
- success(res) {
- console.log('停止搜索')
- }
- });
- openBle(function(A) {
- uni.onBLEConnectionStateChange(function(B) {
- if (!B.connected) {
- var C = new Object();
- C.code = FAILED_CODE;
- C.data = '';
- C.msg = '蓝牙连接已断开';
- typeof z === 'function' && z(C)
- }
- })
- });
- c = x.deviceId;
- uni.createBLEConnection({
- deviceId: c,
- success(res) {
- deployBle(y)
- },
- fail() {
- var A = new Object();
- A.code = FAILED_CODE;
- A.msg = '连接失败';
- A.data = '';
- typeof y === 'function' && y(A)
- }
- })
- };
-
- function deployBle(x) {
- var y = this;
- e = '';
- f = '';
- uni.getBLEDeviceServices({
- deviceId: c,
- success(res) {
- for (let i = 0; i < res.services.length; i++) {
- let serviceuuid = res.services[i].uuid;
- if (serviceuuid === ARTC_SERVICE_UUID) {
- d = serviceuuid;
- uni.getBLEDeviceCharacteristics({
- deviceId: c,
- serviceId: d,
- success(res) {
- for (let i = 0; i < res.characteristics.length; i++) {
- let chauuid = res.characteristics[i].uuid;
- if (chauuid === ARTC_READ_UUID) {
- f = chauuid
- } else if (chauuid === ARTC_WRTIE_UUID) {
- e = chauuid
- }
- };
- if (e.length === 0 || f.length === 0) {
- typeof x === 'function' && x(PLOY_NO_CHARACTERISTIC)
- } else {
- openReceiveData((code) => {
- if (code === SUCCESS_CODE) {
- if (a.protocolType() == "normal") {
- typeof x === 'function' && x(SUCCESS_CODE)
- } else {
- v = x
- }
- } else {
- var A = new Object();
- A.code = FAILED_CODE;
- A.msg = '连接失败';
- A.data = '';
- typeof x === 'function' && x(A)
- }
- })
- }
- },
- fail() {
- var A = new Object();
- A.code = FAILED_CODE;
- A.msg = '连接失败';
- A.data = '';
- typeof x === 'function' && x(A)
- }
- });
- return
- }
- };
- var z = new Object();
- z.code = FAILED_CODE;
- z.msg = '连接失败';
- z.data = '';
- typeof x === 'function' && x(z)
- },
- fail() {
- var z = new Object();
- z.code = FAILED_CODE;
- z.msg = '连接失败';
- z.data = '';
- typeof x === 'function' && x(z)
- }
- })
- };
-
- function disconnectDevice(x) {
- uni.closeBLEConnection({
- deviceId: c,
- success(res) {
- var y = new Object();
- y.code = SUCCESS_CODE;
- y.msg = '蓝牙已断开';
- y.data = '';
- x(y)
- },
- fail() {
- var y = new Object();
- y.code = FAILED_CODE;
- y.msg = '蓝牙连接断开失败';
- y.data = '';
- x(y)
- }
- })
- };
-
- function openReceiveData(x) {
- uni.notifyBLECharacteristicValueChange({
- deviceId: c,
- serviceId: d,
- characteristicId: f,
- state: true,
- success(res) {
- typeof x === 'function' && x(SUCCESS_CODE)
- },
- fail() {
- typeof x === 'function' && x(FAILED_CODE)
- }
- });
- uni.onBLECharacteristicValueChange((characteristic) => {
- let hex = Array.prototype.map.call(new Uint8Array(characteristic.value), x => ('00' + x.toString(16))
- .slice(-2)).join('');
- console.log('接收数据:' + hex);
- if (a.protocolType() == "normal") {
- normalDataResponse(hex)
- } else {
- let ST = hex.substring(0, 2).toUpperCase();
- if (q.length == 0) {
- if (ST == "FE") {
- r = parseInt(hex.substring(4, 8), 16) * 2
- } else {
- return
- }
- };
- q = q + hex;
- if (q.length == r) {
- let cmdId = q.substring(8, 12);
- if (cmdId == "2711") {
- authResponse()
- } else if (cmdId == "2713") {
- initResponse()
- } else if (cmdId == "2712") {
- let frame = q.substring(16);
- wechatDataResponse(frame)
- }
- } else if (q.length > r) {
- q = "";
- r = 0
- }
- }
- })
- };
-
- function initResponse() {
- let bufferArray = a.makeInitResponse();
- let hasErr = false;
- w = true;
- sendData(bufferArray, function(x, y) {
- if (x != 0) {
- hasErr = true
- }
- })
- };
-
- function authResponse() {
- let bufferArray = a.makeAuthResponse();
- sendData(bufferArray, function(x, y) {
- if (x != 0) {
- typeof s == 'function' && s(FAILED_CODE)
- }
- })
- };
-
- function wechatDataResponse(x) {
- q = "";
- r = 0;
- x = x.substring(8, 8 + parseInt(x.substring(6, 8), 16) * 2);
- if (t.length == 0) {
- if (a.protocolType() == "xinguobiao") {
- let ctl = parseInt(x.substring(2, 6), 16);
- u = ctl - 0x8000
- } else if (a.protocolType() == "genvict") {
- let ctl = parseInt(x.substring(4, 6), 16);
- u = ctl - 0x80 + 1
- }
- };
- t.push(x);
- if (u == t.length) {
- let completeValue = "";
- for (let i = 0; i < t.length; i++) {
- let temp = "" + t[i];
- completeValue += temp.substring(8, temp.length - 2)
- };
- t = new Array();
- u = 0;
- if (parseInt(completeValue.substring(0, 2), 16) != 0x96) {
- typeof j == 'function' && j(SUCCESS_CODE, completeValue)
- }
- }
- };
-
- function normalDataResponse(x) {
- q = "";
- r = 0;
- if (t.length == 0) {
- let ctl = parseInt(x.substring(6, 8));
- u = ctl + 1
- };
- t.push(x);
- if (u == t.length) {
- let completeValue = "";
- for (let i = 0; i < t.length; i++) {
- let temp = "" + t[i];
- completeValue += temp.substring(10, temp.length - 2)
- };
- t = new Array();
- u = 0;
- if (parseInt(completeValue.substring(0, 2), 16) != 0x96) {
- typeof j == 'function' && j(SUCCESS_CODE, completeValue)
- }
- }
- };
-
- function sendData(x, y) {
- var z = this;
- q = '';
- g = x;
- h = 0;
- j = y;
- m = [];
- l = [];
- t = new Array();
- startSendData()
- };
-
- function startSendData() {
- var y = this;
- let buffer = g[h];
- let hex = Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
- console.log('发送数据:' + hex);
- uni.writeBLECharacteristicValue({
- deviceId: c,
- serviceId: d,
- characteristicId: e,
- value: buffer,
- success(res) {
- i = 3;
- h++;
- if (h < g.length) {
- startSendData()
- } else {
- if (w) {
- var z = new Object();
- z.code = SUCCESS_CODE;
- z.msg = '连接成功';
- z.data = '';
- typeof v == 'function' && v(z);
- w = false
- }
- }
- },
- fail() {
- console.log('发送失败了:')
- }
- })
- };
-
- function initDevice(x) {
- var y = this;
- console.log('接收数据:xxxx');
- y.sendData(a.initDeviceSendData(), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- if (a.protocolType() == "normal") {
- console.log('接收数据:' + res);
- reapdu = res
- };
- typeof x === 'function' && x(code, reapdu)
- } else {
- typeof x === 'function' && x(FAILED_CODE, res)
- }
- })
- };
-
- function deviceChannel(x, y) {
- var z = this;
- z.sendData(a.makeDeviceChannelSendData(x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof y === 'function' && y(code, res)
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function authenChannel(x, y, z) {
- var A = this;
- A.sendData(a.makeAuthenChannelSendData(x, y), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof z === 'function' && z(code, res)
- } else {
- typeof z === 'function' && z(FAILED_CODE, res)
- }
- })
- };
-
- function selfDeviceChannel(x, y) {
- var z = this;
- z.sendData(a.makeSelfDeviceChannelSendData(x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof y === 'function' && y(code, res)
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function deviceAuthenChannel(x, y, z) {
- var A = this;
- A.sendData(a.makeDeviceAuthenSendData(x, y), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof z === 'function' && z(code, res)
- } else {
- typeof z === 'function' && z(FAILED_CODE, res)
- }
- })
- };
-
- function cosChannel(x, y, z) {
- var A = this;
- A.sendData(a.makecosSendData(x, y), (code, res) => {
- let stateCode = res.substring(2, 4);
- if (code === SUCCESS_CODE && stateCode === '00') {
- let reapdu = res.substring(10, res.length);
- if (a.protocolType() == "genvict") {
- var B = tlvUnpackData(reapdu);
- for (let i = 0; i < B.length; i++) {
- let cosCode = B[i].substring(B[i].length - 4, B[i].length)
- };
- typeof z === 'function' && z(code, B)
- } else {
- typeof z === 'function' && z(code, res)
- }
- } else {
- typeof z === 'function' && z(FAILED_CODE, res)
- }
- })
- };
-
- function tlvUnpackData(x) {
- let tlvMode = parseInt(x.substring(2, 4), 16);
- let cosStr;
- let tlvLen;
- var y = new Array();
- if (tlvMode <= 0x80) {
- tlvLen = parseInt(x.substring(2, 4), 16) * 2;
- cosStr = x.substring(4, x.length)
- } else if (tlvMode == 0x81) {
- tlvLen = parseInt(x.substring(4, 6), 16) * 2;
- cosStr = x.substring(6, x.length)
- } else {
- tlvLen = parseInt(x.substring(4, 8), 16) * 2;
- cosStr = x.substring(8, x.length)
- };
- let i = 0;
- let index = 0;
- let dataLen = 0;
- while (tlvLen > 0) {
- dataLen = parseInt(cosStr.substring(2 + index, 4 + index), 16) * 2;
- y[i] = cosStr.substring(4 + index, dataLen + 4 + index);
- index = index + 4 + dataLen;
- i++;
- tlvLen = tlvLen - 4 - dataLen
- };
- return y
- };
-
- function gvEsamChannel(x, y, z) {
- var A = this;
- A.sendData(a.makeGVEsamSendData(x, y), (code, res) => {
- let stateCode = res.substring(2, 4);
- if (code === SUCCESS_CODE && stateCode === '00') {
- let reapdu = res.substring(10, res.length);
- if (a.protocolType() == "genvict") {
- var B = tlvUnpackData(reapdu);
- for (let i = 0; i < B.length; i++) {
- let cosCode = B[i].substring(B[i].length - 4, B[i].length)
- };
- typeof z === 'function' && z(code, B)
- } else {
- typeof z === 'function' && z(code, res)
- }
- } else {
- typeof z === 'function' && z(FAILED_CODE, res)
- }
- })
- };
-
- function transGVEsamCommand(x, y) {
- var z = this;
- z.sendData(a.makeGVtransEsamSendData('20', x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof y === 'function' && y(code, res)
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function transCommand(x, y, z) {
- var A = this;
- A.sendData(a.maketransSendData(x, y), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof z === 'function' && z(code, res)
- } else {
- typeof z === 'function' && z(FAILED_CODE, res)
- }
- })
- };
-
- function obuChannel(x, y) {
- var z = this;
- z.sendData(a.makeObuChannel(x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof y === 'function' && y(code, res)
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function authenC0(x, y) {
- let send = "C0" + x;
- var z = this;
- z.sendData(a.makeAuthenSendData(send), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof y === 'function' && y(code, res)
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function authenC1(x, y, z, A, B, C, D) {
- let send = "C1" + x + y + z + A + B + C;
- var E = this;
- E.sendData(a.makeAuthenSendData(send), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof D === 'function' && D(code, res)
- } else {
- typeof D === 'function' && D(FAILED_CODE, res)
- }
- })
- };
-
- function readCard(x) {
- var y = '0';
- let reapdu = '12'
- };
-
- function resetCard(x) {
- var y = this;
- y.sendData(a.makeResetCard(), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(18, res.length - 4);
- typeof x === 'function' && x(code, res)
- } else {
- typeof x === 'function' && x(FAILED_CODE, res)
- }
- })
- };
-
- function getICCInfo(x) {
- var y = this;
- var z = new Array();
- z[0] = "00A40000021001";
- z[1] = "00B095002B";
- z[2] = "805C000204";
- var A = "00";
- if (a.protocolType() == "xinguobiao") {
- A = "10"
- };
- y.cosChannel(A, z, function(B, C) {
- if (B == 0 && C[1].length >= 90) {
- var D = new Object();
- D.file0015 = C[1];
- D.provider = C[1].substring(0, 16);
- D.cardType = C[1].substring(16, 18);
- D.cardVersion = C[1].substring(18, 20);
- D.cardId = C[1].substring(20, 40);
- D.signedDate = C[1].substring(40, 48);
- D.expiredDate = C[1].substring(48, 56);
- D.vehicleNumber = C[1].substring(56, 80);
- D.userType = C[1].substring(80, 82);
- if (D.cardVersion == 0x40) {
- D.plateColor = C[1].substring(86, 88);
- D.vehicleModel = C[1].substring(88, 90)
- } else {
- D.plateColor = C[1].substring(88, 90);
- D.vehicleModel = '00'
- };
- D.balance = parseInt(C[2].substring(0, 8), 16);
- typeof x === 'function' && x(B, D)
- } else {
- typeof x === 'function' && x(FAILED_CODE, C)
- }
- })
- };
-
- function pinCode(x, y, z, A, B, C) {
- var D = this;
- var E = new Array();
- E[0] = "00A40000021001";
- E[1] = "00200000" + a.numberToHexString(x.length / 2, 1, true) + x;
- E[2] = "805000" + y + "0B" + z + a.numberToHexString(A, 4, true) + B + "10";
- console.log("回复数据:" + E);
- var F = "00";
- if (a.protocolType() == "xinguobiao") {
- F = "10"
- };
- D.cosChannel(F, E, function(G, H) {
- if (G == 0) {
- var I = new Object();
- I.balance = H[2].substring(0, 8);
- I.counter = H[2].substring(8, 12);
- I.random = H[2].substring(16, 24);
- I.mac1 = H[2].substring(24, 32);
- typeof C === 'function' && C(G, I)
- } else {
- typeof C === 'function' && C(FAILED_CODE, H)
- }
- })
- };
-
- function loadCreditWrite(x, y, z) {
- var A = this;
- var B = new Array();
- B[0] = "805200000B" + x + y;
- var C = "00";
- if (a.protocolType() == "xinguobiao") {
- C = "10"
- };
- A.cosChannel(C, B, function(D, E) {
- if (D == 0 && E.length == 1) {
- typeof z === 'function' && z(D, E)
- } else {
- typeof z === 'function' && z(FAILED_CODE, E)
- }
- })
- };
-
- function transA1reqData(x, y) {
- var z = this;
- z.sendData(a.makeTransA1reqData(x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(10, res.length - 4);
- let credit_length = 0;
- if (reapdu.length > 14) {
- credit_length = parseInt(res.substring(12, 14), 16) * 2
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- };
- let sign_length = 0;
- if (reapdu.length > 4 + credit_length) {
- sign_length = parseInt(res.substring(16 + credit_length, 16 + credit_length + 2), 16) * 2
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- };
- if (res.length > 16 + credit_length + sign_length) {
- var A = new Object();
- A.original = res.substring(14, 14 + credit_length);
- A.sign = res.substring(18 + credit_length, 18 + credit_length + sign_length);
- typeof y === 'function' && y(code, A)
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- }
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function loadCreditT0reqData(x, y) {
- var z = this;
- z.sendData(a.makeLoadCreditT0reqData(x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(10, res.length - 4);
- let credit_length = 0;
- if (reapdu.length > 14) {
- credit_length = parseInt(res.substring(12, 14), 16) * 2
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- };
- let sign_length = 0;
- if (reapdu.length > 4 + credit_length) {
- sign_length = parseInt(res.substring(16 + credit_length, 16 + credit_length + 2), 16) * 2
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- };
- if (res.length > 16 + credit_length + sign_length) {
- var A = new Object();
- A.original = res.substring(14, 14 + credit_length);
- A.sign = res.substring(18 + credit_length, 18 + credit_length + sign_length);
- typeof y === 'function' && y(code, A)
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- }
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function esamMiWen(x, y) {
- var z = this;
- z.sendData(a.makeEsamMiWen(x), (code, res) => {
- if (code === SUCCESS_CODE) {
- let stateCode = res.substring(res.length - 4);
- let reapdu = res.substring(10, res.length - 4);
- let credit_length = 0;
- if (res.length > 14) {
- credit_length = parseInt(res.substring(12, 14), 16) * 2
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- };
- if (res.length > 12 + credit_length) {
- var A = new Object();
- A.original = res.substring(14, 14 + credit_length);
- typeof y === 'function' && y(code, A)
- } else {
- typeof y === 'function' && y(code, "返回不正常包。")
- }
- } else {
- typeof y === 'function' && y(FAILED_CODE, res)
- }
- })
- };
-
- function initiateOBU(x) {
- var y = this;
- console.log("initiateOBU");
- var z = new Array();
- z[0] = "00A40000023F00";
- z[1] = "00B0810063";
- y.gvEsamChannel('20', z, function(A, B) {
- if (A === SUCCESS_CODE) {
- console.log("回复数据:" + B);
- let initiateState = B[1].substring(52, 52 + 2);
- console.log("initiateState:" + initiateState);
- if (initiateState === '02') {
- var C = new Array();
- C[0] = "0059000001";
- y.gvEsamChannel('20', C, function(D, E) {
- typeof x === 'function' && x(D, E)
- });
- console.log("状态1")
- } else if (initiateState === '01') {
- typeof x === 'function' && x(FAILED_CODE, "OBU已激活。");
- console.log("状态2")
- } else if (initiateState === '00') {
- typeof x === 'function' && x(FAILED_CODE, "OBU已失效。");
- console.log("状态3")
- }
- }
- })
- };
-
- function transCmd(x, y, z) {
- var A = y;
- if (y == '10') {
- A = '00'
- };
- sendData(a.makeGVEsamSendData(A, x), (code, res) => {
- let stateCode = res.substring(2, 4);
- console.log("res.substring(2, 4):" + res);
- console.log("res.substring(2, 4):" + res.substring(2, 4));
- if (code === SUCCESS_CODE && stateCode === '00') {
- let reapdu = res.substring(10, res.length);
- console.log("reapdu:" + reapdu);
- if (a.protocolType() == "genvict") {
- var B = tlvUnpackData(reapdu);
- var C = new Object();
- C.code = SUCCESS_CODE;
- C.msg = '操作成功';
- C.data = B;
- typeof z === 'function' && z(C)
- }
- } else {
- var B = new Object();
- B.code = FAILED_CODE;
- B.msg = '操作失败';
- B.data = res;
- typeof z === 'function' && z(B)
- }
- })
- };
- module.exports = {
- sendData: sendData,
- openBle: openBle,
- closeBle: closeBle,
- scanBle: scanBle,
- connectDevice: connectDevice,
- deployBle: deployBle,
- disconnectDevice: disconnectDevice,
- initDevice: initDevice,
- deviceChannel: deviceChannel,
- selfDeviceChannel: selfDeviceChannel,
- cosChannel: cosChannel,
- authenC0: authenC0,
- authenC1: authenC1,
- openReceiveData: openReceiveData,
- deviceAuthenChannel: deviceAuthenChannel,
- gvEsamChannel: gvEsamChannel,
- transGVEsamCommand: transGVEsamCommand,
- transCommand: transCommand,
- resetCard: resetCard,
- getICCInfo: getICCInfo,
- pinCode: pinCode,
- loadCreditWrite: loadCreditWrite,
- authenChannel: authenChannel,
- transA1reqData: transA1reqData,
- loadCreditT0reqData: loadCreditT0reqData,
- esamMiWen: esamMiWen,
- obuChannel: obuChannel,
- initiateOBU: initiateOBU,
- transCmd: transCmd
- };
|