@@ -0,0 +1,265 @@ | |||
var DATA_LENGTH = 190, | |||
FRAME_LENGTH = 40, | |||
Protocol_Type = "genvict", | |||
SEQ = 3, | |||
SN = 1; | |||
function protocolType() { | |||
return Protocol_Type | |||
} | |||
function setProtocolType(a) { | |||
Protocol_Type = a | |||
} | |||
function setPackageLen(a) { | |||
DATA_LENGTH = 2 * (a - 5); | |||
console.log("packageLen:" + DATA_LENGTH / 2) | |||
} | |||
function makeAuthResponse() { | |||
var a = [], | |||
b = new Uint8Array("FE0100124E2100010A06080012024F4B1200".match(/[\da-f]{2}/gi).map(function(a) { | |||
return parseInt(a, 16) | |||
})); | |||
a.push(b.buffer); | |||
return a | |||
} | |||
function makeInitResponse() { | |||
var a = [], | |||
b = "FE0100164E2300020A06080012024F4B100018002000".substring(0, FRAME_LENGTH); | |||
b = new Uint8Array(b.match(/[\da-f]{2}/gi).map(function(a) { | |||
return parseInt(a, 16) | |||
})); | |||
a.push(b.buffer); | |||
b = new Uint8Array("2000".match(/[\da-f]{2}/gi).map(function(a) { | |||
return parseInt(a, 16) | |||
})); | |||
a.push(b.buffer); | |||
return a | |||
} | |||
function makeFrame(a) { | |||
var b = "" + a, | |||
c = parseInt(b.length / DATA_LENGTH), | |||
d = b.length % DATA_LENGTH; | |||
a = []; | |||
for (var e = 0; e < c; e++) a.push(b.substring(e * DATA_LENGTH, e * DATA_LENGTH + DATA_LENGTH)); | |||
0 < d && a.push(b.substring(b.length - d)); | |||
b = []; | |||
SN++; | |||
15 < SN && (SN = 1); | |||
for (c = 0; c < a.length; c++) { | |||
d = ""; | |||
d = 0 == c ? numberToHexString(128 + a.length - 1, 1, !0) : numberToHexString(a.length - c - 1, 1, !0); | |||
d = GVPackData(a[c], d); | |||
d = wechatPackData(d); | |||
e = parseInt(d.length / FRAME_LENGTH); | |||
for (var g = d.length % FRAME_LENGTH, f = 0; f < e; f++) { | |||
var h = d.substring(f * FRAME_LENGTH, | |||
f * FRAME_LENGTH + FRAME_LENGTH); | |||
h = new Uint8Array(h.match(/[\da-f]{2}/gi).map(function(a) { | |||
return parseInt(a, 16) | |||
})); | |||
b.push(h.buffer) | |||
} | |||
0 < g && (d = d.substring(d.length - g), d = new Uint8Array(d.match(/[\da-f]{2}/gi).map(function(a) { | |||
return parseInt(a, 16) | |||
})), b.push(d.buffer)) | |||
} | |||
return b | |||
} | |||
function makeCosSendData(a, b) { | |||
b = 0 == parseInt(a.substring(1, 2), 10) ? "80" + tlvPackData(b) : b[0]; | |||
a = "A1" + a + numberToHexString(b.length / 2, 2, !1) + b; | |||
return makeFrame(a) | |||
} | |||
function initDeviceSendData() { | |||
return makeFrame("A2") | |||
} | |||
function makePiccChannelSendData(a, b) { | |||
b = 0 == parseInt(a.substring(1, 2), 10) ? "80" + tlvPackData(b) : b[0]; | |||
a = "A3" + a + numberToHexString(b.length / 2, 2, !1) + b; | |||
return makeFrame(a) | |||
} | |||
function makeDeviceChannelSendData(a) { | |||
a = "" + a; | |||
a = "A5" + numberToHexString(a.length / 2, 1, !1) + a; | |||
return makeFrame(a) | |||
} | |||
function makeAuthenChannelSendData(a, b) { | |||
a += b; | |||
a = "A6" + numberToHexString(a.length / 2, 2, !1) + a; | |||
return makeFrame(a) | |||
} | |||
function makePiccResetSendData() { | |||
return makeFrame("A900") | |||
} | |||
function makeEsamResetSendData() { | |||
return makeFrame("AA") | |||
} | |||
function makeEsamChannelSendData(a, b) { | |||
if ("pre" == Protocol_Type) { | |||
var c = "AC"; | |||
b = 0 == parseInt(a.substring(1, 2), 10) ? "80" + tlvPackData(b) : b[0] | |||
} else b = "80" + tlvPackData(b), c = "A1", a = "20"; | |||
a = c + a + numberToHexString(b.length / 2, 2, !1) + b; | |||
return makeFrame(a) | |||
} | |||
function makeDeviceAuthenSendData(a, b) { | |||
a = "C1" + a + b; | |||
a = "AD" + numberToHexString(a.length / 2, 2, !1) + a; | |||
return makeFrame(a) | |||
} | |||
function makeSelfDeviceChannelSendData(a) { | |||
a = "" + a; | |||
a = "AE" + numberToHexString(a.length / 2, 1, !1) + a; | |||
return makeFrame(a) | |||
} | |||
function makeUpdateChannelSendData(a, b) { | |||
a = null == b || 0 >= b.length ? "" + a : a + b; | |||
a = "A0" + numberToHexString(a.length / 2, 1, !1) + a; | |||
return makeFrame(a) | |||
} | |||
function tlvPackData(a) { | |||
for (var b = "", c = 0; c < a.length; c++) { | |||
var d = 256 <= a[c].length / 2 ? "82" + numberToHexString(a[c].length / 2, 2, !1) + a[c] : 128 < a[c].length / | |||
2 ? "81" + numberToHexString(a[c].length / 2, 1, !1) + a[c] : numberToHexString(a[c].length / 2, 1, !1) + a[ | |||
c]; | |||
b = b + numberToHexString(c + 1, 1, !1) + d | |||
} | |||
a = b.length / 2; | |||
return 256 <= a ? "82" + numberToHexString(a, 2, !1) + b : 128 < a ? "81" + numberToHexString(a, 1, !1) + b : | |||
numberToHexString(a, 1, !1) + b | |||
} | |||
function wechatPackData(a) { | |||
if (1 > a.length / 256) a = "0A0012" + numberToHexString(a.length / 2, 1, !0) + a + "1800"; | |||
else { | |||
var b = numberToHexString((a.length % 256 + 256) / 2, 1, !0), | |||
c = numberToHexString(parseInt(a.length / 256), 1, !1); | |||
a = "0A0012" + b + c + a + "1800" | |||
} | |||
b = numberToHexString(a.length / 2 + 8, 2, !0); | |||
c = numberToHexString(SEQ, 2, !0); | |||
SEQ++; | |||
15 < SEQ && (SEQ = 1); | |||
return "FE01" + b + "7531" + c + a | |||
} | |||
function GVPackData(a, b) { | |||
var c = numberToHexString(SN, 1, !0); | |||
a = "" + a; | |||
var d = numberToHexString(a.length / 2, 1, !0); | |||
b = "33" + c + b + d + a; | |||
c = 0; | |||
for (a = 1; a < b.length / 2; a++) d = parseInt(b.substring(2 * a, 2 * a + 2), 16), c ^= d; | |||
return b += numberToHexString(c, 1, !0) | |||
} | |||
function numberToHexString(a, b, c) { | |||
a = a.toString(16); | |||
for (var d = a.length; d < 2 * b; d++) a = "0" + a; | |||
a.length > 2 * b && (a = a.substring(a.length - 2 * b)); | |||
if (!c) { | |||
b = ""; | |||
for (c = a.length - 2; 0 <= c; c -= 2) b += a.substring(c, c + 2); | |||
a = b | |||
} | |||
return a | |||
} | |||
function fromCharCode(a) { | |||
for (var b = "", c = 0; c < a.length / 2; c++) { | |||
var d = a.substring(2 * c, 2 * c + 2); | |||
b += String.fromCharCode(parseInt(d, 16)) | |||
} | |||
return b | |||
} | |||
function byteArrayToHexStr(a) { | |||
for (var b = "", c = 0; c < a.length; c++) { | |||
var d = (a[c] & 255).toString(16); | |||
d = 1 === d.length ? "0" + d : d; | |||
b += d | |||
} | |||
return b | |||
} | |||
function hexToString(a) { | |||
for (var b = "", c = 0; c < a.length; c += 2) b += String.fromCharCode(parseInt(a.substr(c, 2), 16)); | |||
return b | |||
} | |||
function stringtoHex(a) { | |||
if ("" === a) return ""; | |||
for (var b = [], c = 0; c < a.length; c++) b.push(a.charCodeAt(c).toString(16)); | |||
return b.join("") | |||
} | |||
function hexToBytes(a) { | |||
for (var b = [], c = 0; c < a.length; c += 2) b.push(parseInt(a.substr(c, 2), 16)); | |||
return b | |||
} | |||
function getTime() { | |||
var a = new Date, | |||
b = a.getFullYear(), | |||
c = a.getMonth() + 1, | |||
d = a.getDate(); | |||
a.getTime(); | |||
var e = a.getHours(), | |||
g = a.getMinutes(), | |||
f = a.getSeconds(); | |||
a = a.getMilliseconds(); | |||
1 <= c && 9 >= c && (c = "0" + c); | |||
0 <= d && 9 >= d && (d = "0" + d); | |||
0 <= e && 9 >= e && (e = "0" + e); | |||
0 <= g && 9 >= g && (g = "0" + g); | |||
0 <= f && 9 >= f && (f = "0" + f); | |||
return b + "-" + c + "-" + d + " " + e + ":" + g + ":" + f + ":" + a | |||
} | |||
function consoleLog(a) { | |||
a = getTime() + "\uff1a" + a + "\n"; | |||
console.log(a) | |||
} | |||
module.exports = { | |||
makeAuthResponse: makeAuthResponse, | |||
makeInitResponse: makeInitResponse, | |||
makeFrame: makeFrame, | |||
makeCosSendData: makeCosSendData, | |||
initDeviceSendData: initDeviceSendData, | |||
makePiccChannelSendData: makePiccChannelSendData, | |||
makeDeviceChannelSendData: makeDeviceChannelSendData, | |||
makeAuthenChannelSendData: makeAuthenChannelSendData, | |||
makePiccResetSendData: makePiccResetSendData, | |||
makeEsamResetSendData: makeEsamResetSendData, | |||
makeEsamChannelSendData: makeEsamChannelSendData, | |||
makeDeviceAuthenSendData: makeDeviceAuthenSendData, | |||
makeSelfDeviceChannelSendData: makeSelfDeviceChannelSendData, | |||
makeUpdateChannelSendData: makeUpdateChannelSendData, | |||
numberToHexString: numberToHexString, | |||
protocolType: protocolType, | |||
setProtocolType: setProtocolType, | |||
setPackageLen: setPackageLen, | |||
fromCharCode: fromCharCode, | |||
stringtoHex: stringtoHex, | |||
hexToBytes: hexToBytes, | |||
hexToString: hexToString, | |||
byteArrayToHexStr: byteArrayToHexStr, | |||
consoleLog: consoleLog | |||
}; |
@@ -0,0 +1,3 @@ | |||
var SUCCESS_CODE="0",FAILED_CODE="-1",ERR_OPENBLE_CODE="10001",ERR_SCANBLE_CODE="10002",ERR_STOPSCANBLE_CODE="10003",ERR_CONNECTBLE_CODE="10004",ERR_DEPLOPBLE_CODE="10005",DISSCONNECTBLE_CODE="10006",ERR_WX_INIT_CODE="10007",ERR_WX_AUTH_CODE="10008",ERR_DISSCONNECTBLE_CODE="10009",ERR_SCANBLE_TIMEOUT="10010",ERR_CONNECT_TIMEOUT="10011",ERR_RECVDATA_TIMEOUT="10012",ERR_PARAMS_CODE="20001",ERR_CMD_EXECUTE_CODE="30001",ERR_UPDATE_CODE="40001"; | |||
module.exports={SUCCESS_CODE:SUCCESS_CODE,FAILED_CODE:FAILED_CODE,ERR_OPENBLE_CODE:ERR_OPENBLE_CODE,ERR_SCANBLE_CODE:ERR_SCANBLE_CODE,ERR_STOPSCANBLE_CODE:ERR_STOPSCANBLE_CODE,ERR_CONNECTBLE_CODE:ERR_CONNECTBLE_CODE,ERR_DEPLOPBLE_CODE:ERR_DEPLOPBLE_CODE,DISSCONNECTBLE_CODE:DISSCONNECTBLE_CODE,ERR_WX_INIT_CODE:ERR_WX_INIT_CODE,ERR_WX_AUTH_CODE:ERR_WX_AUTH_CODE,ERR_DISSCONNECTBLE_CODE:ERR_DISSCONNECTBLE_CODE,ERR_SCANBLE_TIMEOUT:ERR_SCANBLE_TIMEOUT,ERR_CONNECT_TIMEOUT:ERR_CONNECT_TIMEOUT,ERR_RECVDATA_TIMEOUT:ERR_RECVDATA_TIMEOUT, | |||
ERR_PARAMS_CODE:ERR_PARAMS_CODE,ERR_CMD_EXECUTE_CODE:ERR_CMD_EXECUTE_CODE,ERR_UPDATE_CODE:ERR_UPDATE_CODE}; |
@@ -0,0 +1,619 @@ | |||
var dataUtil = require("./jy-bluetooth-obu-DataUtil.js"), | |||
errorCode = require("./jy-bluetooth-obu-ErrorCode.js"), | |||
XXXDeviceId = "", | |||
XXXServiceId = "", | |||
XXXWriteId = "", | |||
XXXReadId = "", | |||
XXXSendBuffer = [], | |||
XXXSendIndex = 0, | |||
XXXResendCount = 3, | |||
sendCallback, stephex = "", | |||
frameLength = 0, | |||
deployCall, frameArray = [], | |||
frameCount = 0, | |||
connectCall, isInitResponse = !1, | |||
SERVICE_UUID_FEE7 = "0000FEE7-0000-1000-8000-00805F9B34FB", | |||
WRITE_UUID_FEC7 = "0000FEC7-0000-1000-8000-00805F9B34FB", | |||
READ_UUID_FEC8 = "0000FEC8-0000-1000-8000-00805F9B34FB", | |||
SHORT_SERVICE_UUID_FEE7 = | |||
"FEE7", | |||
SHORT_WRITE_UUID_FEC7 = "FEC7", | |||
SHORT_READ_UUID_FEC8 = "FEC8", | |||
SERVICE_UUID = SERVICE_UUID_FEE7, | |||
WRITE_UUID = WRITE_UUID_FEC7, | |||
READ_UUID = READ_UUID_FEC8, | |||
SHORT_SERVICE_UUID = SHORT_SERVICE_UUID_FEE7, | |||
SHORT_WRITE_UUID = SHORT_WRITE_UUID_FEC7, | |||
SHORT_READ_UUID = SHORT_READ_UUID_FEC8, | |||
foundDevices = [], | |||
COS_SUCCESS_CODE = "9000", | |||
isScanFinish, connectDevice, reConnectNum = 1, | |||
scanTimeoutId = null, | |||
mScanTimeOut = 5E3, | |||
isBLEConnectionStateChange = !1, | |||
connectTimeoutId = null, | |||
isBleConnected = !1, | |||
isSending = !1, | |||
sendDataTimeoutId; | |||
function isConnected() { | |||
return isBleConnected | |||
} | |||
function initData() { | |||
stephex = ""; | |||
XXXSendBuffer = []; | |||
XXXSendIndex = 0; | |||
frameArray = [] | |||
} | |||
function sendData(a, b) { | |||
stephex = ""; | |||
XXXSendBuffer = a; | |||
XXXSendIndex = 0; | |||
sendCallback = b; | |||
frameArray = []; | |||
startSendData(b) | |||
} | |||
function startSendData(a) { | |||
var b = XXXSendBuffer[XXXSendIndex], | |||
c = Array.prototype.map.call(new Uint8Array(b), function(b) { | |||
return ("00" + b.toString(16)).slice(-2) | |||
}).join(""); | |||
dataUtil.consoleLog("\u53d1\u9001\u6570\u636e\uff1a" + c); | |||
wx.writeBLECharacteristicValue({ | |||
deviceId: XXXDeviceId, | |||
serviceId: XXXServiceId, | |||
characteristicId: XXXWriteId, | |||
value: b, | |||
success: function(b) { | |||
XXXResendCount = 3; | |||
XXXSendIndex++; | |||
XXXSendIndex < XXXSendBuffer.length ? startSendData() : isInitResponse && ("function" == | |||
typeof sendCallback && sendCallback(errorCode.SUCCESS_CODE), | |||
isInitResponse = !1) | |||
}, | |||
fail: function() { | |||
dataUtil.consoleLog("\u53d1\u9001\u5931\u8d25\u4e86\uff1a"); | |||
"function" == typeof a && a(errorCode.FAILED_CODE) | |||
} | |||
}) | |||
} | |||
function openReceiveData(a) { | |||
wx.notifyBLECharacteristicValueChange({ | |||
deviceId: XXXDeviceId, | |||
serviceId: XXXServiceId, | |||
characteristicId: XXXReadId, | |||
state: !0, | |||
success: function(b) { | |||
"function" === typeof a && a(errorCode.SUCCESS_CODE) | |||
}, | |||
fail: function() { | |||
"function" === typeof a && a(errorCode.FAILED_CODE) | |||
} | |||
}); | |||
wx.onBLECharacteristicValueChange(function(b) { | |||
b = Array.prototype.map.call(new Uint8Array(b.value), function(b) { | |||
return ("00" + b.toString(16)).slice(-2) | |||
}).join(""); | |||
dataUtil.consoleLog("\u63a5\u6536\u6570\u636e\uff1a" + b); | |||
0 == | |||
stephex.length && (frameLength = 2 * parseInt(b.substring(4, 8), 16)); | |||
stephex += b; | |||
if (stephex.length == frameLength) | |||
if (b = stephex.substring(8, 12), "2711" == b) authResponse(); | |||
else if ("2713" == b) initResponse(); | |||
else if ("2712" == b) { | |||
b = stephex.substring(16); | |||
if (256 <= b.length - 16) { | |||
var a = 256 * parseInt(b.substring(8, 10), 16) + (2 * parseInt(b.substring(6, 8), 16) - 256); | |||
b = b.substring(10, 10 + a) | |||
} else b = b.substring(8, 8 + 2 * parseInt(b.substring(6, 8), 16)); | |||
genvictDataResponse(b) | |||
} | |||
}) | |||
} | |||
function initResponse() { | |||
var a = dataUtil.makeInitResponse(); | |||
isInitResponse = !0; | |||
var b = {}; | |||
sendData(a, function(a, d) { | |||
clearTimeout(connectTimeoutId); | |||
0 == a ? initDevice(function(a, c) { | |||
dataUtil.consoleLog("res:" + c); | |||
a == errorCode.SUCCESS_CODE ? (2 < c.length && 10 < parseInt(c.substring(0, 2), 16) ? ( | |||
dataUtil.consoleLog("\u540e\u88c5OBU"), dataUtil.setProtocolType("genvict"), | |||
dataUtil.setPackageLen(100)) : (dataUtil.consoleLog("\u524d\u88c5OBU"), dataUtil | |||
.setProtocolType("pre"), a = c.substring(2, 4), dataUtil.setPackageLen(parseInt( | |||
a, | |||
16))), b.code = errorCode.SUCCESS_CODE, b.msg = "\u8fde\u63a5\u6210\u529f") : (b | |||
.code = errorCode.ERR_INIT_DEVICE_CODE, b.msg = "\u8fde\u63a5\u5931\u8d25"); | |||
"function" == typeof connectCall && connectCall(b) | |||
}) : (b.code = errorCode.ERR_WX_INIT_CODE, "function" == typeof connectCall && connectCall(b)) | |||
}) | |||
} | |||
function authResponse() { | |||
var a = dataUtil.makeAuthResponse(); | |||
sendData(a, function(b, a) { | |||
0 != b && (b = {}, b.code = errorCode.ERR_WX_AUTH_CODE, "function" == typeof connectCall && connectCall( | |||
b)) | |||
}) | |||
} | |||
function genvictDataResponse(a) { | |||
stephex = ""; | |||
frameLength = 0; | |||
0 == frameArray.length && (frameCount = parseInt(a.substring(4, 6), 16) - 128 + 1); | |||
frameArray.push(a); | |||
if (frameCount == frameArray.length) { | |||
a = ""; | |||
for (var b = 0; b < frameArray.length; b++) { | |||
var c = "" + frameArray[b]; | |||
a += c.substring(8, c.length - 2) | |||
} | |||
frameArray = []; | |||
frameCount = 0; | |||
150 != parseInt(a.substring(0, 2), 16) && "function" == typeof sendCallback && sendCallback(errorCode | |||
.SUCCESS_CODE, a) | |||
} | |||
} | |||
function deployBle(a) { | |||
initData(); | |||
XXXReadId = XXXWriteId = ""; | |||
var b = {}; | |||
wx.getBLEDeviceServices({ | |||
deviceId: XXXDeviceId, | |||
success: function(c) { | |||
dataUtil.consoleLog("getBLEDeviceServices-success"); | |||
for (var d = 0; d < c.services.length; d++) { | |||
var e = c.services[d].uuid; | |||
dataUtil.consoleLog("serviceuuid\uff1a" + e); | |||
if (e === SERVICE_UUID || e === SHORT_SERVICE_UUID) { | |||
XXXServiceId = e; | |||
wx.getBLEDeviceCharacteristics({ | |||
deviceId: XXXDeviceId, | |||
serviceId: XXXServiceId, | |||
success: function(c) { | |||
for (var d = 0; d < c.characteristics.length; d++) { | |||
var e = c.characteristics[d].uuid; | |||
dataUtil.consoleLog("chauuid" + e); | |||
if (e === READ_UUID || e === SHORT_READ_UUID) XXXReadId = e; | |||
else if (e === WRITE_UUID || e === SHORT_WRITE_UUID) | |||
XXXWriteId = e | |||
} | |||
dataUtil.consoleLog("XXXReadId\uff1a" + XXXReadId); | |||
dataUtil.consoleLog("XXXWriteId" + XXXWriteId); | |||
0 === XXXWriteId.length || 0 === XXXReadId.length ? (b.code = | |||
errorCode.ERR_CONNECTBLE_CODE, "function" === typeof a && a( | |||
b)) : openReceiveData(function(c) { | |||
dataUtil.consoleLog("openReceiveData"); | |||
"0" === c ? "normal" == dataUtil.protocolType() || | |||
"hlj_ff15" == dataUtil.protocolType() ? (b.code = | |||
errorCode.SUCCESS_CODE, | |||
"function" === typeof a && a(b)) : (dataUtil | |||
.consoleLog("start wx auth init"), connectCall = | |||
a) : (b.code = errorCode.ERR_CONNECTBLE_CODE, | |||
"function" === typeof a && a(b)) | |||
}) | |||
}, | |||
fail: function() { | |||
b.code = errorCode.ERR_DEPLOPBLE_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}); | |||
return | |||
} | |||
} | |||
b.code = errorCode.ERR_DEPLOPBLE_CODE; | |||
"function" === typeof a && a(b) | |||
}, | |||
fail: function() { | |||
b.code = errorCode.ERR_DEPLOPBLE_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}) | |||
} | |||
function scanBle(a) { | |||
foundDevices = []; | |||
isScanFinish = !1; | |||
var b = {}; | |||
clearTimeout(scanTimeoutId); | |||
scanTimeoutId = setTimeout(function() { | |||
isScanFinish || (stopScanBle(function(b) {}), b.code = errorCode.ERR_SCANBLE_TIMEOUT, b.err_msg = | |||
"\u626b\u63cf\u8d85\u65f6", "function" === typeof a && a(b)) | |||
}, mScanTimeOut); | |||
wx.startBluetoothDevicesDiscovery({ | |||
success: function(c) { | |||
wx.onBluetoothDeviceFound(function(c) { | |||
for (var d = 0; d < c.devices.length && !isInvalidBle(c.devices[d]) && !isSameBle(c | |||
.devices[d]); d++) dataUtil.consoleLog("name:" + c.devices[d].name + | |||
" address:" + c.devices[d].deviceId), foundDevices.push(c.devices[d]), b | |||
.code = errorCode.SUCCESS_CODE, b.devices = foundDevices, isScanFinish = !0, a( | |||
b) | |||
}) | |||
}, | |||
fail: function() { | |||
b.code = errorCode.ERR_SCANBLE_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}) | |||
} | |||
function setScanTimeOut(a) { | |||
mScanTimeOut = a | |||
} | |||
function isInvalidBle(a) { | |||
return null == a || null == a.deviceId || 0 >= a.deviceId.length || null == a.name || 0 >= a.name.length ? !0 : !1 | |||
} | |||
function isSameBle(a) { | |||
var b = !1; | |||
foundDevices.forEach(function(c) { | |||
a.name === c.name && a.deviceId === c.deviceId && (b = !0) | |||
}); | |||
return b | |||
} | |||
function openBle(a) { | |||
var b = {}; | |||
wx.openBluetoothAdapter({ | |||
success: function(c) { | |||
dataUtil.consoleLog("openBle success"); | |||
b.code = errorCode.SUCCESS_CODE; | |||
"function" === typeof a && a(b) | |||
}, | |||
fail: function() { | |||
dataUtil.consoleLog("openBle fail"); | |||
b.code = errorCode.ERR_OPENBLE_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}) | |||
} | |||
function stopScanBle(a) { | |||
var b = {}; | |||
isScanFinish = !0; | |||
wx.stopBluetoothDevicesDiscovery({ | |||
success: function(c) { | |||
dataUtil.consoleLog("\u505c\u6b62\u641c\u7d22\u84dd\u7259\u8bbe\u5907"); | |||
b.code = errorCode.SUCCESS_CODE; | |||
"function" === typeof a && a(b) | |||
}, | |||
fail: function() { | |||
dataUtil.consoleLog("\u505c\u6b62\u641c\u7d22\u84dd\u7259\u8bbe\u5907\u5931\u8d25"); | |||
b.code = errorCode.ERR_STOPSCANBLE_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}) | |||
} | |||
function connectBle(a, b) { | |||
var c = {}; | |||
clearTimeout(connectTimeoutId); | |||
connectTimeoutId = setTimeout(function() { | |||
disconnectBle(function() {}); | |||
c.code = errorCode.ERR_CONNECT_TIMEOUT; | |||
c.err_msg = "\u8fde\u63a5\u8d85\u65f6"; | |||
"function" === typeof b && b(c) | |||
}, 1E4); | |||
startOnBleConnectionStateChange(); | |||
connectDevice = a; | |||
XXXDeviceId = a.deviceId; | |||
dataUtil.consoleLog("\u5f00\u59cb\u8fde\u63a5"); | |||
reConnectNum = 1; | |||
createBleConnection(function(a) { | |||
a.code == errorCode.SUCCESS_CODE ? (isBleConnected = !0, "function" === typeof b && b(a)) : 0 < | |||
reConnectNum ? | |||
(reConnectNum--, disconnectBle(function(b) {}), dataUtil.consoleLog("\u5f00\u59cb\u91cd\u8fde"), | |||
createBleConnection(b)) : (clearTimeout(connectTimeoutId), c.code = errorCode | |||
.ERR_CONNECTBLE_CODE, "function" === typeof b && b(c)) | |||
}) | |||
} | |||
function startOnBleConnectionStateChange() { | |||
if (!isBLEConnectionStateChange) wx.onBLEConnectionStateChange(function(a) { | |||
isBLEConnectionStateChange = !0; | |||
a.connected ? dataUtil.consoleLog("onBLEConnectionStateChange-connected") : (dataUtil.consoleLog( | |||
"onBLEConnectionStateChange-disconnect"), isBleConnected = !1, wx.closeBLEConnection({ | |||
deviceId: XXXDeviceId | |||
})) | |||
}) | |||
} | |||
function createBleConnection(a) { | |||
var b = {}; | |||
wx.createBLEConnection({ | |||
deviceId: XXXDeviceId, | |||
success: function(b) { | |||
deployBle(a) | |||
}, | |||
fail: function(c) { | |||
b.code = errorCode.ERR_CONNECTBLE_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}) | |||
} | |||
function closeBle(a) { | |||
var b = {}; | |||
wx.closeBluetoothAdapter({ | |||
success: function(c) { | |||
dataUtil.consoleLog("\u5173\u95ed\u84dd\u7259\u9002\u914d\u5668\u6210\u529f"); | |||
b.code = errorCode.SUCCESS_CODE; | |||
"function" === typeof a && a(b) | |||
}, | |||
fail: function() { | |||
dataUtil.consoleLog("\u5173\u95ed\u84dd\u7259\u9002\u914d\u5668\u5931\u8d25"); | |||
b.code = errorCode.FAILED_CODE; | |||
"function" === typeof a && a(b) | |||
} | |||
}) | |||
} | |||
function disconnectBle(a) { | |||
wx.closeBLEConnection({ | |||
XXXDeviceId: XXXDeviceId, | |||
success: function(b) { | |||
console.log("closeBLEConnection:" + b) | |||
} | |||
}) | |||
} | |||
function cosChannel(a, b, c) { | |||
sendDataTimeout(c); | |||
sendData(dataUtil.makeCosSendData(a, b), function(b, a) { | |||
clearTimeout(sendDataTimeoutId); | |||
if ("0" === b) | |||
if (dataUtil.consoleLog("initDevice-res\uff1a" + a), b = a.substring(2, 4), "00" == b) { | |||
b = a.substring(10, a.length); | |||
b = tlvUnpackData(b); | |||
for (var d = 0; d < b.length; d++) { | |||
var e = b[d].substring(b[d].length - 4, b[d].length); | |||
dataUtil.consoleLog("cosCode:" + e); | |||
if (e != COS_SUCCESS_CODE) { | |||
"function" === typeof c && c(e, a); | |||
return | |||
} | |||
} | |||
"function" === typeof c && c(errorCode.SUCCESS_CODE, b) | |||
} else "function" === | |||
typeof c && c(b, a); | |||
else "function" === typeof c && c(errorCode.ERR_CMD_EXECUTE_CODE, a) | |||
}) | |||
} | |||
function initDevice(a) { | |||
sendDataTimeout(a); | |||
sendData(dataUtil.initDeviceSendData(), function(b, c) { | |||
clearTimeout(sendDataTimeoutId); | |||
if ("0" === b) { | |||
dataUtil.consoleLog("initDevice-res\uff1a" + c); | |||
var d = c.substring(2, 4); | |||
"00" == d ? (c = c.substring(6, c.length), "function" === typeof a && a(b, c)) : "function" === | |||
typeof a && a(d, c) | |||
} else "function" === typeof a && a(errorCode.ERR_CMD_EXECUTE_CODE, c) | |||
}) | |||
} | |||
function cardChannel(a, b) { | |||
console.log("a,b", a, b) | |||
sendDataTimeout(b); | |||
sendData(dataUtil.makePiccChannelSendData("00", a), function(a, d) { | |||
clearTimeout(sendDataTimeoutId); | |||
if ("0" === a) | |||
if (dataUtil.consoleLog("cardChannel-res\uff1a" + d), a = d.substring(2, 4), "00" == a) { | |||
var c = d.substring(10, d.length); | |||
c = tlvUnpackData(c); | |||
for (a = 0; a < c.length; a++) { | |||
var f = c[a].substring(c[a].length - 4, c[a].length); | |||
dataUtil.consoleLog("cosCode:" + f); | |||
if (f != COS_SUCCESS_CODE) { | |||
"function" === typeof b && b(f, d); | |||
return | |||
} | |||
} | |||
"function" === typeof b && b(errorCode.SUCCESS_CODE, c) | |||
} else "function" === | |||
typeof b && b(a, c); | |||
else "function" === typeof b && b(errorCode.ERR_CMD_EXECUTE_CODE, d) | |||
}) | |||
} | |||
function deviceChannel(a, b) { | |||
sendDataTimeout(b); | |||
sendData(dataUtil.makeDeviceChannelSendData(a), function(a, d) { | |||
clearTimeout(sendDataTimeoutId); | |||
"0" === a ? (dataUtil.consoleLog("deviceChannel-res\uff1a" + d), a = d.substring(2, 4), "00" == a ? (d = | |||
d.substring(6, d.length - 6), "function" === typeof b && b(errorCode.SUCCESS_CODE, d)) : | |||
"function" === typeof b && b(a, d)) : "function" === typeof b && b(errorCode | |||
.ERR_CMD_EXECUTE_CODE, d) | |||
}) | |||
} | |||
function authenChannel(a, b, c) { | |||
sendDataTimeout(c); | |||
sendData(dataUtil.makeAuthenChannelSendData(a, b), function(a, b) { | |||
clearTimeout(sendDataTimeoutId); | |||
"0" === a ? (dataUtil.consoleLog("authenChannel-res\uff1a" + b), "function" === typeof c && c(a, b)) : | |||
"function" === typeof c && c(errorCode.ERR_CMD_EXECUTE_CODE, b) | |||
}) | |||
} | |||
function cardReset(a) { | |||
sendDataTimeout(a); | |||
sendData(dataUtil.makePiccResetSendData(), function(b, c) { | |||
clearTimeout(sendDataTimeoutId); | |||
"0" === b ? (dataUtil.consoleLog("cardReset-res\uff1a" + c), b = c.substring(2, 4), "00" == b ? (c = c | |||
.substring(6, c.length - 6), "function" === typeof a && a(errorCode.SUCCESS_CODE, c)) : | |||
"function" === typeof a && a(b, c)) : "function" === typeof a && a(errorCode | |||
.ERR_CMD_EXECUTE_CODE, c) | |||
}) | |||
} | |||
function esamReset(a) { | |||
sendDataTimeout(a); | |||
sendData(dataUtil.makeEsamResetSendData(), function(b, c) { | |||
clearTimeout(sendDataTimeoutId); | |||
"0" === b ? (dataUtil.consoleLog("esamReset-res\uff1a" + c), b = c.substring(2, 4), "00" == b ? (c = c | |||
.substring(6, c.length - 6), "function" === typeof a && a(errorCode.SUCCESS_CODE, c)) : | |||
"function" === typeof a && a(b, c)) : "function" === typeof a && a(errorCode | |||
.ERR_CMD_EXECUTE_CODE, c) | |||
}) | |||
} | |||
function esamChannel(a, b) { | |||
sendDataTimeout(b); | |||
sendData(dataUtil.makeEsamChannelSendData("00", a), function(a, d) { | |||
clearTimeout(sendDataTimeoutId); | |||
if ("0" === a) | |||
if (dataUtil.consoleLog("esamChannel-res\uff1a" + d), a = d.substring(2, 4), "00" == a) { | |||
a = d.substring(10, d.length); | |||
a = tlvUnpackData(a); | |||
for (var c = 0; c < a.length; c++) { | |||
var f = a[c].substring(a[c].length - 4, a[c].length); | |||
dataUtil.consoleLog("cosCode:" + f); | |||
if (f != COS_SUCCESS_CODE) { | |||
"function" === typeof b && b(f, d); | |||
return | |||
} | |||
} | |||
"function" === typeof b && b(errorCode.SUCCESS_CODE, a) | |||
} else "function" === | |||
typeof b && b(a, d); | |||
else "function" === typeof b && b(errorCode.ERR_CMD_EXECUTE_CODE, d) | |||
}) | |||
} | |||
function deviceAuthenChannel(a, b, c) { | |||
sendDataTimeout(c); | |||
sendData(dataUtil.makeDeviceAuthenSendData(a, b), function(a, b) { | |||
clearTimeout(sendDataTimeoutId); | |||
"0" === a ? (dataUtil.consoleLog("deviceAuthenChannel-res\uff1a" + b), a = b.substring(2, 4), "00" == | |||
a ? (b = b.substring(8, b.length), "function" === typeof c && c(errorCode.SUCCESS_CODE, b)) : | |||
"function" === typeof c && c(a, b)) : "function" === typeof c && c(errorCode | |||
.ERR_CMD_EXECUTE_CODE, b) | |||
}) | |||
} | |||
function selfDeviceChannel(a, b) { | |||
sendDataTimeout(b); | |||
sendData(dataUtil.makeSelfDeviceChannelSendData(a), function(a, d) { | |||
clearTimeout(sendDataTimeoutId); | |||
"0" === a ? (a = d.substring(2, 4), "00" == a ? (d = d.substring(8, d.length), dataUtil.consoleLog( | |||
"selfChannel-data\uff1a" + d), "function" === typeof b && b(errorCode.SUCCESS_CODE, d)) : | |||
"function" === typeof b && b(a, d)) : "function" === typeof b && b(errorCode | |||
.ERR_CMD_EXECUTE_CODE, d) | |||
}) | |||
} | |||
function updateChannel(a, b, c) { | |||
sendDataTimeout(c); | |||
sendData(dataUtil.makeUpdateChannelSendData(a, b), function(a, b) { | |||
clearTimeout(sendDataTimeoutId); | |||
if ("0" === a) { | |||
var d = b.substring(2, 4); | |||
"00" == d ? (b = b.substring(8, b.length), "function" === typeof c && c(a, b)) : "function" === | |||
typeof c && c(d, b) | |||
} else "function" === typeof c && c(errorCode.ERR_CMD_EXECUTE_CODE, b) | |||
}) | |||
} | |||
function sendDataTimeout(a) { | |||
sendDataTimeoutId = setTimeout(function() { | |||
dataUtil.consoleLog("\u6570\u636e\u54cd\u5e94\u8d85\u65f6\uff0c\u8fd4\u56de\u9519\u8bef"); | |||
"function" === typeof a && a(errorCode.ERR_RECVDATA_TIMEOUT, "\u6570\u636e\u54cd\u5e94\u8d85\u65f6") | |||
}, 5E3) | |||
} | |||
function tlvUnpackData(a) { | |||
var b = parseInt(a.substring(2, 4), 16), | |||
c = []; | |||
128 >= b ? (b = 2 * parseInt(a.substring(2, 4), 16), a = a.substring(4, a.length)) : 129 == b ? (b = 2 * parseInt(a | |||
.substring(4, 6), 16), a = a.substring(6, a.length)) : (b = 2 * parseInt(a.substring(4, 8), 16), a = a | |||
.substring(8, a.length)); | |||
for (var d = 0, e = 0, f; 0 < b;) f = 2 * parseInt(a.substring(2 + e, 4 + e), 16), c[d] = a.substring(4 + e, f + 4 + | |||
e), e = e + 4 + f, d++, b = b - 4 - f; | |||
return c | |||
} | |||
function encryptRandom(a) { | |||
a = a.match(/.{1,2}/g).map(function(a) { | |||
return parseInt(a, 16) | |||
}); | |||
for (var b = "67656E7669637430".match(/.{1,2}/g).map(function(a) { | |||
return parseInt(a, 16) | |||
}), c = new Uint8Array(a.length), d = 0; d < a.length; d++) c[d] = a[d] ^ b[d]; | |||
return byteArrayToHexStr(c) | |||
} | |||
function stringtoHex(a) { | |||
return dataUtil.stringtoHex(a) | |||
} | |||
function hexToBytes(a) { | |||
return dataUtil.hexToBytes(a) | |||
} | |||
function hexToString(a) { | |||
return dataUtil.hexToString(a) | |||
} | |||
function byteArrayToHexStr(a) { | |||
return dataUtil.byteArrayToHexStr(a) | |||
} | |||
function fromCharCode(a) { | |||
return dataUtil.fromCharCode(a) | |||
} | |||
function numberToHexString(a, b, c) { | |||
return dataUtil.numberToHexString(a, b, c) | |||
} | |||
function calcPercent(a, b) { | |||
a = (a / b).toFixed(2); | |||
a = 100 * parseFloat(a); | |||
return parseInt(a) | |||
} | |||
function consoleLog(a) { | |||
dataUtil.consoleLog(a) | |||
} | |||
module.exports = { | |||
deployBle: deployBle, | |||
openBle: openBle, | |||
closeBle: closeBle, | |||
setScanTimeOut: setScanTimeOut, | |||
scanBle: scanBle, | |||
stopScanBle: stopScanBle, | |||
connectBle: connectBle, | |||
disconnectBle: disconnectBle, | |||
isConnected: isConnected, | |||
cosChannel: cosChannel, | |||
initDevice: initDevice, | |||
cardChannel: cardChannel, | |||
deviceChannel: deviceChannel, | |||
authenChannel: authenChannel, | |||
cardReset: cardReset, | |||
esamReset: esamReset, | |||
esamChannel: esamChannel, | |||
deviceAuthenChannel: deviceAuthenChannel, | |||
selfDeviceChannel: selfDeviceChannel, | |||
updateChannel: updateChannel, | |||
encryptRandom: encryptRandom, | |||
stringtoHex: stringtoHex, | |||
fromCharCode: fromCharCode, | |||
numberToHexString: numberToHexString, | |||
hexToBytes: hexToBytes, | |||
hexToString: hexToString, | |||
byteArrayToHexStr: byteArrayToHexStr, | |||
calcPercent: calcPercent, | |||
consoleLog: consoleLog | |||
}; |
@@ -0,0 +1,384 @@ | |||
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 | |||
}; |
@@ -26,7 +26,7 @@ let zzApi = require("../etc/WJAPI/wjBleAPI.js"); | |||
let jtApi = require("../etc/JTAPI/BleUtil.js"); | |||
const jlQZApi = require("../etc/JLQZAPI/JLObuSDK.js"); | |||
let kcApi = require("../etc/kcBle/kcBleAPI.js"); | |||
// let jyApiEtc = require("../etc/JYAPI-ETC/jy-bluetooth-obu-wechatmp.js"); //前装-金溢 | |||
let jyApiEtc = require("../etc/JYAPI-ETC/jy-bluetooth-obu-wechatmp.js"); //前装-金溢 | |||
import { | |||
login | |||
} from "../../utils/network/api"; | |||
@@ -78,13 +78,12 @@ function disconnectDevice() { | |||
datas.setData("bluLinkStatus", false); | |||
datas.setData("connectPrefixName", ""); | |||
}); | |||
} | |||
// else if (datas.getData("deviceName").includes("JY")) { | |||
// jyApiEtc.disconnectDevice(function(res) { | |||
// datas.setData("bluLinkStatus", false); | |||
// datas.setData("connectPrefixName", ""); | |||
// }); | |||
// } | |||
}else if (datas.getData("deviceName").includes("JY")) { | |||
jyApiEtc.disconnectDevice(function(res) { | |||
datas.setData("bluLinkStatus", false); | |||
datas.setData("connectPrefixName", ""); | |||
}); | |||
} | |||
break; | |||
case "JY": | |||
@@ -218,21 +217,20 @@ function transCmd(cmdArr, type, func, callBack = null) { | |||
} | |||
} | |||
}); | |||
} | |||
// else if (datas.getData("deviceName").includes("JY")) { | |||
// jyApiEtc.transCmd(cmdArr, type, function(res) { | |||
// console.log('WJ执行内容====11111', res) | |||
// if (res.code == 0) { | |||
// func(res.data); | |||
// } else { | |||
// if (callBack != null) { | |||
// callBack(res.msg); | |||
// } else { | |||
// alertF(res.msg); | |||
// } | |||
// } | |||
// }); | |||
// } | |||
}else if (datas.getData("deviceName").includes("JY")) { | |||
jyApiEtc.transCmd(cmdArr, type, function(res) { | |||
console.log('JY执行内容====11111', res) | |||
if (res.code == 0) { | |||
func(res.data); | |||
} else { | |||
if (callBack != null) { | |||
callBack(res.msg); | |||
} else { | |||
alertF(res.msg); | |||
} | |||
} | |||
}); | |||
} | |||
break; | |||
case "JY": |
@@ -222,26 +222,26 @@ | |||
const getCardId = () => { | |||
//执行0015文件 | |||
tools.showLoadingAlert("执行指令"); | |||
if (datas.getData("deviceName").includes("JY")) { | |||
jyApiEtc.getCardInfo(function(res) { | |||
if (res.code == '0') { | |||
var cardInfo = res.cardInfo; | |||
console.log("res.cardInfo", res.cardInfo) | |||
card.cardNo = cardInfo.cardId; | |||
card.startTime = cardInfo.signedDate; | |||
card.endTime = cardInfo.expiredDate; | |||
// message = "卡片方标识:" + cardInfo.provider + " 卡片类型:" + cardInfo.cardType + " 卡片版本号:" + | |||
// cardInfo.cardVersion + " 卡号:" + cardInfo.cardId + " 启用时间:" + | |||
// cardInfo.signedDate + " 到期时间:" + cardInfo.expiredDate + " 车牌号:" + cardInfo | |||
// .vehicleNumber + | |||
// " 用户类型:" + cardInfo.userType + " 车牌颜色:" + cardInfo.plateColor + " 车型:" + cardInfo | |||
// .vehicleModel; | |||
getObuId(); | |||
} else { | |||
tools.alertF("获取卡片信息失败" + res.code); | |||
} | |||
}) | |||
} else { | |||
// if (datas.getData("deviceName").includes("JY")) { | |||
// jyApiEtc.getCardInfo(function(res) { | |||
// if (res.code == '0') { | |||
// var cardInfo = res.cardInfo; | |||
// console.log("res.cardInfo", res.cardInfo) | |||
// card.cardNo = cardInfo.cardId; | |||
// card.startTime = cardInfo.signedDate; | |||
// card.endTime = cardInfo.expiredDate; | |||
// // message = "卡片方标识:" + cardInfo.provider + " 卡片类型:" + cardInfo.cardType + " 卡片版本号:" + | |||
// // cardInfo.cardVersion + " 卡号:" + cardInfo.cardId + " 启用时间:" + | |||
// // cardInfo.signedDate + " 到期时间:" + cardInfo.expiredDate + " 车牌号:" + cardInfo | |||
// // .vehicleNumber + | |||
// // " 用户类型:" + cardInfo.userType + " 车牌颜色:" + cardInfo.plateColor + " 车型:" + cardInfo | |||
// // .vehicleModel; | |||
// getObuId(); | |||
// } else { | |||
// tools.alertF("获取卡片信息失败" + res.code); | |||
// } | |||
// }) | |||
// } else { | |||
let cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, "00B095002B"]; | |||
console.log(cmdArr); | |||
console.log(bluetoothUtil); | |||
@@ -352,7 +352,7 @@ | |||
alertF("CMD_READBINARY指令长度不符" + res[2]); | |||
}) | |||
} | |||
// } | |||
}; | |||
/** | |||
@@ -360,18 +360,18 @@ | |||
*/ | |||
const getObuId = () => { | |||
tools.showLoadingAlert("执行指令"); | |||
if (datas.getData("deviceName").includes("JY")) { | |||
// jyApiEtc.getSystemInfo(function(res) { | |||
// console.log("获取OBU===", res) | |||
// if (res.code == 0) { | |||
// obu.num = res.systemInfo.serialNumber | |||
// obu.startTime = res.systemInfo.signedDate | |||
// obu.endTime = res.systemInfo.expiredDate | |||
// } else { | |||
// tools.alertF("获取OBU信息失败"); | |||
// } | |||
// }); | |||
} else { | |||
// if (datas.getData("deviceName").includes("JY")) { | |||
// jyApiEtc.getSystemInfo(function(res) { | |||
// console.log("获取OBU===", res) | |||
// if (res.code == 0) { | |||
// obu.num = res.systemInfo.serialNumber | |||
// obu.startTime = res.systemInfo.signedDate | |||
// obu.endTime = res.systemInfo.expiredDate | |||
// } else { | |||
// tools.alertF("获取OBU信息失败"); | |||
// } | |||
// }); | |||
// } else { | |||
let cmdArr = [cmd.HOME_DIRECTORY, cmd.OBU_SYSTEM_FILE]; | |||
bluetoothUtil.transCmd(cmdArr, '20', function(res) { | |||
var obuStr = res[1]; | |||
@@ -454,7 +454,7 @@ | |||
} | |||
alertF("OBU_SYSTEM_FILE指令长度不符" + res[1]); | |||
}) | |||
} | |||
// } | |||
}; | |||