123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- const _0x92e0 = ['错误码:', 'FEE7', 'concat', 'sendDataToDevice->', 'data', '发送数据异常', 'code', 'toString', '发送蓝牙指令返回数据异常',
- 'slice', '发送esam指令成功', 'connectTimeout', 'errorMessage', 'length', 'exports', 'resolveTLV', 'makeTLV',
- 'offBLECharacteristicValueChange', '蓝牙数据发送:', 'Services->', 'log', 'deviceId', 'function',
- 'getBLEDeviceServices', 'makeA8SendData', 'stringify', 'value', 'success', 'fail', 'push', '发送蓝牙指令超时', 'then',
- 'bufferArrayToHexString', 'makeA5SendData', 'notifyBLECharacteristicValueChange', '监听数据失败', '读取不到Services',
- 'services', '连接超时'
- ];
- const _0xf5c9 = function(_0x92e01f, _0xf5c941) {
- _0x92e01f = _0x92e01f - 0x0;
- let _0x50d73c = _0x92e0[_0x92e01f];
- return _0x50d73c;
- };
- const dataUtil = require('./DataUtil.js');
- module[_0xf5c9('0xe')] = {
- 'connectAndInit': connectDevice,
- 'disConnect': disconnectDevice,
- 'sendAndReceive': sendAndReceive,
- 'sendA5Command': sendA5Command
- };
- const FUNCTION = _0xf5c9('0x16');
- var tagServiceUUID = '';
- var tagWriteUUID = '';
- var tagReadUUID = '';
- const androidServiceUUID = '0000fee7-0000-1000-8000-00805f9b34fb';
- const androidWriteUUID = '0000fec7-0000-1000-8000-00805f9b34fb';
- const androidReadUUID = '0000fec8-0000-1000-8000-00805f9b34fb';
- const iosServiceUUID = _0xf5c9('0x1');
- const iosWriteUUID = 'FEC7';
- const iosReadUUID = 'FEC8';
- var connectDeviceId;
- var connectCallback;
- var connectTimer;
- var reconnectTimer;
- var transTimer;
- var read = ![];
- var frame = '';
- var frameLen = 0x0;
- var frames = new Array();
- var framesLen = 0x0;
- var dataHandlerCallback;
- var sendBufferArray = new Array();
- var cmds = new Array();
- var sendIndex;
- var resendCount = 0x3;
- var reconnectCount = 0x0;
-
- function toObject(_0x163b31, _0x2cb0af, _0x2f910b) {
- return {
- 'code': _0x163b31,
- 'data': _0x2cb0af,
- 'msg': _0x2f910b
- };
- }
- const codeEnum = {
- 'success': 0x3e8,
- 'fail': 0xfa0,
- 'timeout': 0x7d0,
- 'connectTimeout': 0x7d2
- };
-
- function connectDevice(_0x51d9b3, _0x15c0b5, _0x297201) {
- my[_0xf5c9('0x11')]();
- setTimeout(() => {
- connectDeviceId = _0x51d9b3[_0xf5c9('0x15')];
- connectCallback = _0x15c0b5;
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- connectTimer = setTimeout(() => {
- typeof connectCallback['fail'] == FUNCTION && connectCallback['fail'](toObject(codeEnum[
- _0xf5c9('0xb')], undefined, _0xf5c9('0x26')));
- }, _0x297201);
- my['connectBLEDevice']({
- 'deviceId': connectDeviceId,
- 'success': _0x1e99d7 => {
- getBLEDeviceServices();
- },
- 'fail': _0x3ba55a => {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- typeof connectCallback[_0xf5c9('0x1c')] == FUNCTION && connectCallback[_0xf5c9(
- '0x1c')](toObject(codeEnum[_0xf5c9('0x1c')], undefined, '连接失败:' + JSON[
- _0xf5c9('0x19')](_0x3ba55a)));
- }
- });
- }, 0x96);
- }
-
- function disconnectDevice(_0x129f55) {
- my['disconnectBLEDevice']({
- 'deviceId': connectDeviceId,
- 'success'(_0x4e659d) {
- typeof _0x129f55[_0xf5c9('0x1b')] == FUNCTION && _0x129f55['success'](toObject(codeEnum[_0xf5c9(
- '0x1b')], _0x4e659d, '断开连接成功'));
- },
- 'fail'(_0x22025a) {
- typeof _0x129f55[_0xf5c9('0x1c')] == FUNCTION && _0x129f55['fail'](toObject(codeEnum['fail'],
- _0x22025a, '断开连接失败'));
- }
- });
- }
-
- function getBLEDeviceServices() {
- my[_0xf5c9('0x17')]({
- 'deviceId': connectDeviceId,
- 'success': _0x4c2800 => {
- console[_0xf5c9('0x14')](_0xf5c9('0x13'), _0x4c2800);
- let _0x5ab723 = ![];
- tagServiceUUID = '';
- for (let _0x2af1b7 = 0x0; _0x2af1b7 < _0x4c2800[_0xf5c9('0x25')]['length']; _0x2af1b7++) {
- let _0x3a301e = _0x4c2800['services'][_0x2af1b7]['serviceId'];
- if (_0x3a301e == androidServiceUUID) {
- _0x5ab723 = !![];
- tagServiceUUID = androidServiceUUID;
- break;
- }
- if (_0x3a301e == iosServiceUUID) {
- _0x5ab723 = !![];
- tagServiceUUID = iosServiceUUID;
- break;
- }
- }
- if (_0x5ab723 == !![]) {
- getBLEDeviceCharacteristics();
- } else {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- typeof connectCallback[_0xf5c9('0x1c')] == FUNCTION && connectCallback[_0xf5c9('0x1c')](
- toObject(codeEnum['fail'], undefined, _0xf5c9('0x24')));
- }
- },
- 'fail': _0x40d4c9 => {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- typeof connectCallback['fail'] == FUNCTION && connectCallback[_0xf5c9('0x1c')](toObject(
- codeEnum[_0xf5c9('0x1c')], undefined, '读取Services失败'));
- }
- });
- }
-
- function getBLEDeviceCharacteristics() {
- my['getBLEDeviceCharacteristics']({
- 'deviceId': connectDeviceId,
- 'serviceId': tagServiceUUID,
- 'success': _0x32b130 => {
- let _0x28eee5 = ![];
- let _0x17a958 = ![];
- tagReadUUID = '';
- tagWriteUUID = '';
- console[_0xf5c9('0x14')]('Characteristics->', _0x32b130);
- for (let _0x1ca77b = 0x0; _0x1ca77b < _0x32b130['characteristics']['length']; _0x1ca77b++) {
- let _0x4abe38 = _0x32b130['characteristics'][_0x1ca77b]['characteristicId'];
- if (_0x4abe38 == androidReadUUID) {
- _0x28eee5 = !![];
- tagReadUUID = androidReadUUID;
- } else if (_0x4abe38 == androidWriteUUID) {
- _0x17a958 = !![];
- tagWriteUUID = androidWriteUUID;
- } else if (_0x4abe38 == iosReadUUID) {
- _0x28eee5 = !![];
- tagReadUUID = iosReadUUID;
- } else if (_0x4abe38 == iosWriteUUID) {
- _0x17a958 = !![];
- tagWriteUUID = iosWriteUUID;
- }
- if (_0x28eee5 == !![] && _0x17a958 == !![]) {
- break;
- }
- }
- if (_0x28eee5 == !![] && _0x17a958 == !![]) {
- notifyBLECharacteristicValueChange();
- } else {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- typeof connectCallback[_0xf5c9('0x1c')] == FUNCTION && connectCallback['fail'](toObject(
- codeEnum['fail'], undefined, '读取不到Characteristics'));
- }
- },
- 'fail': _0x1aa5f4 => {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- typeof connectCallback[_0xf5c9('0x1c')] == FUNCTION && connectCallback['fail'](toObject(
- codeEnum['fail'], undefined, '读取Characteristics失败'));
- }
- });
- }
-
- function notifyBLECharacteristicValueChange() {
- my[_0xf5c9('0x22')]({
- 'state': !![],
- 'deviceId': connectDeviceId,
- 'serviceId': tagServiceUUID,
- 'characteristicId': tagReadUUID,
- 'success': () => {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- setTimeout(() => {
- typeof connectCallback[_0xf5c9('0x1b')] == FUNCTION && connectCallback[_0xf5c9(
- '0x1b')](toObject(codeEnum['success'], undefined, '连接成功,握手成功'));
- }, 0x3e8);
- my['onBLECharacteristicValueChange']({
- 'success': _0x30bb4a => {
- if (read) {
- analyticData(_0x30bb4a[_0xf5c9('0x1a')]['toLowerCase']());
- }
- }
- });
- },
- 'fail': _0x5e6282 => {
- if (typeof connectTimer != undefined) {
- clearTimeout(connectTimer);
- }
- typeof connectCallback['fail'] == FUNCTION && connectCallback['fail'](toObject(codeEnum[_0xf5c9(
- '0x1c')], undefined, _0xf5c9('0x23')));
- }
- });
- }
-
- function offBLECharacteristicValueChange() {
- my['offBLECharacteristicValueChange']();
- }
-
- function analyticData(_0x3e5a78) {
- console[_0xf5c9('0x14')]('蓝牙数据接收:' + _0x3e5a78);
- if (frame[_0xf5c9('0xd')] == 0x0) {
- frameLen = parseInt(_0x3e5a78['slice'](0x4, 0x8), 0x10) * 0x2;
- }
- frame += _0x3e5a78;
- if (frame[_0xf5c9('0x9')](0x0, 0x4) != 'fe01') {
- frame = '';
- frameLen = 0x0;
- } else if (frame['length'] > frameLen) {
- frame = '';
- frameLen = 0x0;
- typeof dataHandlerCallback == FUNCTION && dataHandlerCallback(toObject(codeEnum[_0xf5c9('0x1c')], '',
- '数据长度越界'));
- } else if (frame[_0xf5c9('0xd')] == frameLen) {
- let _0x4b2e97 = frame[_0xf5c9('0x9')](0x8, 0xc);
- if (_0x4b2e97 === '2712') {
- let _0x1453f8 = frame['slice'](0x10);
- let _0x206028 = _0x1453f8['slice'](0x8, -0x6);
- frame = '';
- frameLen = 0x0;
- if (frames['length'] == 0x0) {
- let _0x15c5e1 = parseInt(_0x206028['slice'](0x4, 0x6), 0x10);
- framesLen = _0x15c5e1 - 0x80 + 0x1;
- }
- frames[_0xf5c9('0x1d')](_0x206028);
- if (frames['length'] == framesLen) {
- let _0x5e3a98 = !![];
- for (let _0xab8645 = 0x0; _0xab8645 < frames[_0xf5c9('0xd')]; _0xab8645++) {
- let _0x40bd69 = frames[_0xab8645];
- let _0x2c9f45 = 0x0;
- for (let _0x3a8918 = 0x1; _0x3a8918 < parseInt(_0x40bd69[_0xf5c9('0xd')] / 0x2) -
- 0x1; _0x3a8918++) {
- let _0x1e2dcc = parseInt(_0x40bd69['slice'](_0x3a8918 * 0x2, (_0x3a8918 + 0x1) * 0x2), 0x10);
- _0x2c9f45 ^= _0x1e2dcc;
- }
- if (_0x2c9f45 != parseInt(_0x40bd69[_0xf5c9('0x9')](-0x2), 0x10)) {
- _0x5e3a98 = ![];
- break;
- }
- }
- if (_0x5e3a98 == ![]) {
- frames = new Array();
- framesLen = 0x0;
- typeof dataHandlerCallback == FUNCTION && dataHandlerCallback(toObject(codeEnum[_0xf5c9('0x1c')],
- '', 'bcc校验不通过'));
- } else {
- let _0x33b27d = '';
- for (let _0x345bc5 = 0x0; _0x345bc5 < frames[_0xf5c9('0xd')]; _0x345bc5++) {
- let _0x49a282 = frames[_0x345bc5];
- _0x33b27d += _0x49a282[_0xf5c9('0x9')](0x8, -0x2);
- }
- frames = new Array();
- framesLen = 0x0;
- typeof dataHandlerCallback == FUNCTION && dataHandlerCallback(toObject(codeEnum['success'],
- _0x33b27d, '成功'));
- }
- }
- } else {
- frame = '';
- frameLen = 0x0;
- }
- }
- }
-
- function sendAndReceive(_0x232938, _0x172387, _0x2383ba, _0x30b171) {
- if (_0x232938 != 0x0 && _0x232938 != 0x1) {
- typeof _0x2383ba[_0xf5c9('0x1c')] == FUNCTION && _0x2383ba['fail'](toObject(codeEnum['success'], undefined,
- 'type\x20错误'));
- return;
- }
- if (typeof transTimer != undefined) {
- clearTimeout(transTimer);
- }
- transTimer = setTimeout(() => {
- typeof _0x2383ba['fail'] == FUNCTION && _0x2383ba[_0xf5c9('0x1c')](toObject(codeEnum['timeout'],
- undefined, _0x232938 == 0x0 ? '发送ICC指令超时' : '发送esam指令超时'));
- }, _0x30b171);
- cmds = _0x172387[_0xf5c9('0x9')]();
- var _0x3a5000 = promise(_0x172387, _0x232938);
- _0x3a5000 = _0x3a5000[_0xf5c9('0x1f')](_0x3e2371 => {
- if (typeof transTimer != undefined) {
- clearTimeout(transTimer);
- }
- if (_0x3e2371 === undefined) {
- return;
- }
- typeof _0x2383ba['success'] == FUNCTION && _0x2383ba['success'](toObject(codeEnum['success'], _0x3e2371,
- _0x232938 == 0x0 ? '发送ICC指令成功' : _0xf5c9('0xa')));
- }, (_0x423b8f, _0x29d8d8) => {
- if (_0x423b8f != undefined) {
- if (typeof transTimer != undefined) {
- clearTimeout(transTimer);
- }
- typeof _0x2383ba['fail'] == FUNCTION && _0x2383ba['fail'](toObject(codeEnum[_0xf5c9('0x1c')],
- _0x29d8d8, _0x423b8f));
- }
- });
- }
-
- function promise(_0x468151, _0x4d2ff8) {
- return new Promise((_0x34c1f8, _0x2da9e1) => {
- if (_0x4d2ff8 === 0x0) {
- var _0x3b4904 = dataUtil['makeA3SendData']('00', dataUtil['makeTLV'](_0x468151));
- } else {
- var _0x3b4904 = dataUtil[_0xf5c9('0x18')]('00', dataUtil[_0xf5c9('0x10')](_0x468151));
- }
- sendDataToDevice(_0x3b4904, _0x26bfbd => {
- if (_0x26bfbd['code'] === codeEnum[_0xf5c9('0x1b')]) {
- if (_0x26bfbd['data'][_0xf5c9('0x9')](0x2, 0x4) === '00' || _0x26bfbd[_0xf5c9('0x4')][
- 'slice'
- ](0x2, 0x4) === 'cf') {
- let _0xe05ae9 = _0x26bfbd['data']['slice'](0xa);
- let _0x209462 = dataUtil[_0xf5c9('0xf')](_0x26bfbd['data']['slice'](0xa));
- _0x34c1f8(_0x209462);
- } else {
- console['log']('TLV指令集有指令执行失败');
- let _0x295677 = _0x26bfbd['data']['slice'](0xa);
- let _0x41c368 = dataUtil[_0xf5c9('0xf')](_0x26bfbd[_0xf5c9('0x4')][_0xf5c9('0x9')](
- 0xa));
- _0x2da9e1(_0xf5c9('0x0') + _0x41c368[_0x41c368['length'] - 0x1][_0xf5c9('0x9')](-
- 0x4));
- }
- } else {
- console['log'](_0xf5c9('0x5'));
- _0x2da9e1(_0x26bfbd['msg']);
- }
- });
- });
- }
-
- function sendDataToDevice(_0x11c220, _0xdbb603) {
- dataHandlerCallback = _0xdbb603;
- sendBufferArray = new Array()[_0xf5c9('0x2')](_0x11c220);
- sendIndex = 0x0;
- read = !![];
- frame = '';
- frameLen = 0x0;
- frames = new Array();
- framesLen = 0x0;
- runningSendData();
- }
-
- function runningSendData() {
- let _0x1cf6e5 = sendBufferArray[sendIndex];
- let _0x32342d = dataUtil[_0xf5c9('0x20')](_0x1cf6e5);
- console[_0xf5c9('0x14')](_0xf5c9('0x12') + _0x32342d);
- my['writeBLECharacteristicValue']({
- 'deviceId': connectDeviceId,
- 'serviceId': tagServiceUUID,
- 'characteristicId': tagWriteUUID,
- 'value': _0x1cf6e5,
- 'success': function(_0x2fc6f) {
- sendIndex++;
- resendCount = 0x3;
- if (sendIndex < sendBufferArray[_0xf5c9('0xd')]) {
- runningSendData();
- }
- },
- 'fail': function(_0x3d2851) {
- if (_0x3d2851[_0xf5c9('0xc')]['indexOf']('数据格式错误') != -0x1) {
- typeof dataHandlerCallback == FUNCTION && dataHandlerCallback(toObject(codeEnum[_0xf5c9(
- '0x1c')], '', '发送的数据格式错误:' + _0x32342d));
- } else {
- typeof dataHandlerCallback == FUNCTION && dataHandlerCallback(toObject(codeEnum[_0xf5c9(
- '0x1c')], '', '发送数据失败:' + JSON['stringify'](_0x3d2851)));
- }
- }
- });
- }
-
- function sendA5Command(_0x1fc32c, _0x2ce9f8, _0x1cd591) {
- var _0x3eaa69 = setTimeout(() => {
- typeof _0x2ce9f8['fail'] == FUNCTION && _0x2ce9f8[_0xf5c9('0x1c')](toObject(codeEnum['fail'], undefined,
- _0xf5c9('0x1e')));
- }, _0x1cd591);
- var _0x1e98c4 = dataUtil['makeA5SendData'](_0x1fc32c['toUpperCase']());
- sendDataToDevice(_0x1e98c4, _0xabe804 => {
- if (_0x3eaa69 != undefined) {
- clearTimeout(_0x3eaa69);
- }
- console['log'](_0xf5c9('0x3'), JSON['stringify'](_0xabe804));
- if (_0xabe804[_0xf5c9('0x6')] === codeEnum['success']) {
- if (_0xabe804['data'][_0xf5c9('0x9')](0x0, 0x2) == 'b5' && _0xabe804['data']['slice'](0x2, 0x4) ==
- '00') {
- let _0x3a72fc = parseInt(_0xabe804[_0xf5c9('0x4')][_0xf5c9('0x9')](0x4, 0x6), 0x10);
- typeof _0x2ce9f8[_0xf5c9('0x1b')] == FUNCTION && _0x2ce9f8['success'](toObject(codeEnum[
- 'success'], _0xabe804[_0xf5c9('0x4')][_0xf5c9('0x9')](0x6, 0x6 + _0x3a72fc *
- 0x2), '成功'));
- } else {
- typeof _0x2ce9f8['fail'] == FUNCTION && _0x2ce9f8['fail'](toObject(codeEnum[_0xf5c9('0x1c')],
- _0xabe804['data'], _0xf5c9('0x8')));
- }
- } else {
- typeof _0x2ce9f8['fail'] == FUNCTION && _0x2ce9f8[_0xf5c9('0x1c')](toObject(codeEnum[_0xf5c9(
- '0x1c')], undefined, 'A5指令发送数据失败'));
- }
- });
- }
-
- function openOrCloseAerial(_0x53abde, _0x2bfc73, _0x557cdb) {
- if (_0x53abde == undefined || typeof _0x53abde != 'number' || _0x53abde != 0x0 && _0x53abde != 0x1) {
- typeof _0x2bfc73['fail'] == FUNCTION && _0x2bfc73['fail'](toObject(0xfa0, undefined, '无效参数'));
- } else {
- var _0x3aeea4 = setTimeout(() => {
- typeof _0x2bfc73[_0xf5c9('0x1c')] == FUNCTION && _0x2bfc73[_0xf5c9('0x1c')](toObject(0x7d0,
- undefined, '打开/关闭天线指令超时'));
- }, _0x557cdb);
- var _0x1299bc = 0x0;
- if (_0x53abde === 0x0) {
- _0x1299bc = 0x3;
- } else {
- _0x1299bc = 0x1;
- }
- let _0x483ee7 = 'C7' + parseInt(_0x1299bc)[_0xf5c9('0x7')](0x10)['padStart'](0x2, '0');
- var _0xb5d3ff = dataUtil[_0xf5c9('0x21')](_0x483ee7);
- console[_0xf5c9('0x14')](_0xb5d3ff);
- sendDataToDevice(_0xb5d3ff, _0x50a3b1 => {
- if (_0x3aeea4 != undefined) {
- clearTimeout(_0x3aeea4);
- }
- if (_0x50a3b1['code'] === codeEnum['successCode']) {
- if (_0x50a3b1['data']['slice'](0x0, 0x2) == 'b5' && _0x50a3b1[_0xf5c9('0x4')]['slice'](0x2,
- 0x4) == '00') {
- let _0x146e42 = parseInt(_0x50a3b1[_0xf5c9('0x4')]['slice'](0x4, 0x6), 0x10);
- typeof _0x2bfc73[_0xf5c9('0x1b')] == FUNCTION && _0x2bfc73['success'](toObject(codeEnum[
- 'successCode'], _0x50a3b1[_0xf5c9('0x4')][_0xf5c9('0x9')](0x6, 0x6 +
- _0x146e42 * 0x2), '成功'));
- } else {
- typeof _0x2bfc73['fail'] == FUNCTION && _0x2bfc73[_0xf5c9('0x1c')](toObject(0xfa0,
- _0x50a3b1['data'], _0xf5c9('0x8')));
- }
- } else {
- typeof _0x2bfc73['fail'] == FUNCTION && _0x2bfc73['fail'](toObject(0xfa0, undefined,
- '打开/关闭天线失败'));
- }
- });
- }
- }
|