|
@@ -0,0 +1,700 @@
|
|
|
+const common = require('../common.js');
|
|
|
+
|
|
|
+const FMBMS = require('./FMBMS.js');
|
|
|
+var bluetooth = require('@/common/bluetooth.js');
|
|
|
+import permision from "@/js_sdk/wa-permission/permission.js"
|
|
|
+
|
|
|
+const readServiceID = '0000FEE7-0000-1000-8000-00805F9B34FB';
|
|
|
+const readID = '000036F6-0000-1000-8000-00805F9B34FB';
|
|
|
+const writeServiceID = '0000FEE7-0000-1000-8000-00805F9B34FB';
|
|
|
+const writeID = '000036F5-0000-1000-8000-00805F9B34FB';
|
|
|
+const MTU = 115;
|
|
|
+let subIndex = -1
|
|
|
+let commands = [];
|
|
|
+let currentCommandIndex = 1;
|
|
|
+var totalLength = 0
|
|
|
+var joinPack = []
|
|
|
+var readRepeatTime = 0
|
|
|
+var readRepeatTime = 0
|
|
|
+
|
|
|
+
|
|
|
+function acceptDevice(device) {
|
|
|
+ return device.btid ? true : false;
|
|
|
+}
|
|
|
+
|
|
|
+function isSingleBt() {
|
|
|
+ console.log('是单蓝牙');
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+function haveBms() {
|
|
|
+ console.log('是单蓝牙并且带bms');
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+function isDevice(device, data) {
|
|
|
+
|
|
|
+ const advertisData = new Uint8Array(data.advertisData);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const mac = device.btid
|
|
|
+ .split('')
|
|
|
+ .map((p, i) => parseInt(p + device.btid[i + 1], 16))
|
|
|
+ .filter((p, i) => i % 2 == 0);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const result = data.name.startsWith("ZX");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (result) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function alterConnect(device, deviceId) {
|
|
|
+ const app = getApp();
|
|
|
+ readRepeatTime=0
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ console.log("校检---》")
|
|
|
+ let data=[ 0x1F, 0x0F]
|
|
|
+
|
|
|
+ const device_sn=stringToHexArray(device.mac_id)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ data.push(...device_sn)
|
|
|
+ data.push(0x08, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x67, 0xAC, 0x53, 0xE7, 0x08, 0x00)
|
|
|
+
|
|
|
+
|
|
|
+ console.log(crc8IEEE8023(data).toString(16).toUpperCase(),'crc---------');
|
|
|
+ const crc_data = parseInt(crc8IEEE8023(data).toString(16).toUpperCase(),16)
|
|
|
+
|
|
|
+ data.push(crc_data,0xAA,0xAA)
|
|
|
+ data.unshift(0x22,0x22,0x01)
|
|
|
+
|
|
|
+ const firstPart = data.splice(0, 20);
|
|
|
+
|
|
|
+
|
|
|
+ const secondPart = data;
|
|
|
+
|
|
|
+
|
|
|
+ return [firstPart,secondPart]
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function crc8IEEE8023(data) {
|
|
|
+ const poly = 0x07;
|
|
|
+ let crc = 0x00;
|
|
|
+
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ crc ^= data[i];
|
|
|
+ for (let j = 0; j < 8; j++) {
|
|
|
+ if (crc & 0x80) {
|
|
|
+ crc = ((crc << 1) ^ poly) & 0xFF;
|
|
|
+ } else {
|
|
|
+ crc = (crc << 1) & 0xFF;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return crc;
|
|
|
+}
|
|
|
+
|
|
|
+function stringToHexArray(str) {
|
|
|
+ const result = [];
|
|
|
+ for (let i = 0; i < str.length; i++) {
|
|
|
+ const charCode = str.charCodeAt(i);
|
|
|
+ const hexValue=`0x${charCode.toString(16).toUpperCase()}`
|
|
|
+ const hexDataValue=parseInt(hexValue,16)
|
|
|
+ result.push(hexDataValue);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function readData(device, value, data) {
|
|
|
+ console.log('***********************test');
|
|
|
+ var test = new Uint8Array(value);
|
|
|
+
|
|
|
+ const normalArray=Array.from(test);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(normalArray){
|
|
|
+ console.log(normalArray[2],'normalArray---------------');
|
|
|
+ switch(normalArray[2]){
|
|
|
+ case 0x60:
|
|
|
+
|
|
|
+ loginCmd(device.mac_id,normalArray)
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x61||0x62||0x65:
|
|
|
+
|
|
|
+ trunCarCommand(device.mac_id,normalArray)
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x66:
|
|
|
+
|
|
|
+ checkSendNextCommand(device.mac_id,normalArray)
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x7C:
|
|
|
+
|
|
|
+ nearCarCmd(device.mac_id,normalArray)
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x7E:
|
|
|
+
|
|
|
+
|
|
|
+ getNearCarCmdInfo(device.mac_id,normalArray)
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return data;
|
|
|
+}
|
|
|
+
|
|
|
+function loginCmd(mac_id,data){
|
|
|
+ const len=data.length-4
|
|
|
+ if(data[len-1]==0x00 && data[len]==0x01){
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ confirmText: '开始升级',
|
|
|
+ content: '登陆成功,当前处于升级模式是否开始升级',
|
|
|
+ success: function(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ currentCommandIndex=0
|
|
|
+ otaUpgrade().then(()=>{
|
|
|
+
|
|
|
+ sendNextCommand(device.mac_id)
|
|
|
+ })
|
|
|
+ } else {}
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else if(data[4]==0x00 && data[4]==0x00){
|
|
|
+
|
|
|
+
|
|
|
+ console.log('登陆成功');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ checkUnlock(mac_id,'login')
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+function checkSendNextCommand(mac_id,data){
|
|
|
+ const len=data.length-4
|
|
|
+ if(data[len]==0x00){
|
|
|
+ sendNextCommand(device.mac_id)
|
|
|
+ }else if(data[len]==0x01){
|
|
|
+ uni.hideLoading();
|
|
|
+
|
|
|
+ common.simpleToast('升级文件回复失败')
|
|
|
+ }
|
|
|
+}
|
|
|
+function trunCarCommand(mac_id,data){
|
|
|
+ uni.hideLoading();
|
|
|
+ const len=data.length-4
|
|
|
+ if(data[len]==0x00){
|
|
|
+ common.simpleToast('操作成功')
|
|
|
+ }else if(data[len]==0x01){
|
|
|
+ common.simpleToast('操作失败')
|
|
|
+ }
|
|
|
+}
|
|
|
+function nearCarCmd(mac_id,data){
|
|
|
+ const app = getApp();
|
|
|
+ uni.hideLoading();
|
|
|
+
|
|
|
+ const len=data.length-4
|
|
|
+ const pData={
|
|
|
+ lockType:data[4],
|
|
|
+ }
|
|
|
+ console.log(pData,data,pData.status,'pData');
|
|
|
+ app.globalData.nearLockInfo=pData
|
|
|
+
|
|
|
+ if(data[len]==0x00){
|
|
|
+ common.simpleToast('操作成功')
|
|
|
+
|
|
|
+
|
|
|
+ }else if(data[len]==0x01){
|
|
|
+ common.simpleToast('操作失败')
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function packBmsData(value) {
|
|
|
+ if (value.length!=0) {
|
|
|
+ console.log(endTime - readRepeatTime);
|
|
|
+ if (endTime - readRepeatTime > 8000) {
|
|
|
+ readRepeatTime = endTime
|
|
|
+ joinPack = []
|
|
|
+ }
|
|
|
+
|
|
|
+ if((value[0] == 0x22) && (value[1]== 0x22)){
|
|
|
+ var endTime = new Date().getTime()
|
|
|
+ totalLength = value[3]
|
|
|
+ joinPack=value
|
|
|
+
|
|
|
+ }else if(joinPack.length!=0 && (joinPack[0] == 0x22) && (joinPack[1]== 0x22)){
|
|
|
+ const len=joinPack.length-1
|
|
|
+ const diffJoinLength =joinPack.length-4
|
|
|
+ readRepeatTime = endTime
|
|
|
+
|
|
|
+ if(totalLength > diffJoinLength){
|
|
|
+ joinPack.push(...value)
|
|
|
+ return joinPack
|
|
|
+ }else if(totalLength <= diffJoinLength){
|
|
|
+ joinPack = []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ readRepeatTime = endTime
|
|
|
+ joinPack = []
|
|
|
+ return joinPack
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function mergeUint8Array(arr1, arr2) {
|
|
|
+ let len1 = arr1 ? arr1.length : 0;
|
|
|
+ let len2 = arr2.length;
|
|
|
+ let arr = new Uint8Array(len1 + len2);
|
|
|
+
|
|
|
+ for (let i = 0; i < len1; i++) {
|
|
|
+ arr[i] = arr1[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < len2; i++) {
|
|
|
+ arr[len1 + i] = arr2[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function sendCommand(cmd, data = []) {
|
|
|
+ readRepeatTime=0
|
|
|
+ let cmdData = [0x22, 0x22]
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const dataLen=parseInt(data.length.toString(16).toUpperCase(), 16)
|
|
|
+
|
|
|
+
|
|
|
+ const pData=[dataLen,...data]
|
|
|
+ const crcData=parseInt(crc8IEEE8023(pData).toString(16).toUpperCase(), 16)
|
|
|
+ cmdData.push(cmd,dataLen,...data,crcData,0xAA, 0xAA)
|
|
|
+
|
|
|
+ return cmdData
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function turnOnCar(device, deviceId) {
|
|
|
+ return [sendCommand(0x02,[0x02])];
|
|
|
+}
|
|
|
+
|
|
|
+function turnOffCar(device, deviceId) {
|
|
|
+ return [sendCommand(0x03,[0x03])];
|
|
|
+}
|
|
|
+function findCarCmd(device, deviceId) {
|
|
|
+ return [sendCommand(0x06,[0x06])];
|
|
|
+}
|
|
|
+function openCarSeat(device, deviceId) {
|
|
|
+ return [sendCommand(0x07,[0x07])];
|
|
|
+}
|
|
|
+function openCarTrunk(device, deviceId) {
|
|
|
+ return [sendCommand(0x08,[0x08])];
|
|
|
+}
|
|
|
+function getCarPressure(device, deviceId) {
|
|
|
+ return [sendCommand(0x4A,[0x4A])];
|
|
|
+}
|
|
|
+function nearUnlock(device, deviceId) {
|
|
|
+ return [sendCommand(0x4B,[0x02])];
|
|
|
+}
|
|
|
+function nearCloseUnlock(device, deviceId) {
|
|
|
+ return [sendCommand(0x4B,[0x00])];
|
|
|
+}
|
|
|
+function getSensitivity(device, deviceId) {
|
|
|
+ return [sendCommand(0x4F,[0x4F])];
|
|
|
+}
|
|
|
+function setSensitivity(device, deviceId,type) {
|
|
|
+ return [sendCommand(0x4E,['0x4'+type])];
|
|
|
+}
|
|
|
+function setNearUnlock(device, deviceId,type) {
|
|
|
+ return [sendCommand(0x4D,[0x4D])];
|
|
|
+}
|
|
|
+function getNearUnlockSet(device, deviceId,type) {
|
|
|
+ return [sendCommand(0x4D,[0x4D])];
|
|
|
+}
|
|
|
+
|
|
|
+function getNearCarCmdInfo(macid,data){
|
|
|
+ console.log('getNearCarCmdInfo',macid,data);
|
|
|
+
|
|
|
+
|
|
|
+ if(data[5]==0x02||data[5]==0x01){
|
|
|
+ uni.hideLoading();
|
|
|
+ const pData={
|
|
|
+ lockType:data[4],
|
|
|
+ level:data[5],
|
|
|
+ }
|
|
|
+ const app = getApp();
|
|
|
+ app.globalData.nearLockInfo=pData
|
|
|
+
|
|
|
+ console.log('已开启配对');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setTimeout(()=>{
|
|
|
+ checkUnlock(macid)
|
|
|
+ },300)
|
|
|
+ }else if(data[5]==0x00){
|
|
|
+ console.log('未开启配对')
|
|
|
+ const nearUnlockCmd=nearUnlock()
|
|
|
+ console.log(nearUnlockCmd,'nearUnlockCmd');
|
|
|
+ writeData(mac_id,nearUnlockCmd)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+function checkUnlock(macid,type='get'){
|
|
|
+
|
|
|
+ const res=permision.getBondedDevices()
|
|
|
+ console.log(res,'test0000000000000');
|
|
|
+ let app=getApp()
|
|
|
+ if(res){
|
|
|
+ app.globalData.nearLockCheck=true
|
|
|
+ common.simpleToast('感应解锁已开启,前往设置灵敏度页面')
|
|
|
+ uni.redirectTo({ url: '/pages/bluetoothUnlock/unlockSet' })
|
|
|
+ console.log('test');
|
|
|
+
|
|
|
+ }else{
|
|
|
+ if(type==='login'){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const getNearUnlockSetCmd=getNearUnlockSet()
|
|
|
+ console.log(getNearUnlockSetCmd,'getNearUnlockSetCmd');
|
|
|
+ setTimeout(() => {
|
|
|
+ writeData(macid,getNearUnlockSetCmd)
|
|
|
+ }, 200);
|
|
|
+ }else{
|
|
|
+ uni.showModal({
|
|
|
+ title: '蓝牙配对确认',
|
|
|
+ content: '请在系统通知栏前往同意与'+macid+'设备配对',
|
|
|
+ cancelText: '取消',
|
|
|
+ confirmText: '已同意',
|
|
|
+ success: function(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ checkUnlock(macid)
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function(res) {},
|
|
|
+ complete: function(res) {},
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function switchFactory(device, deviceId) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return [[0x22,0x22,0x54,0x01,0x01,0x12,0xAA,0xAA]]
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function otaUpgrade(device){
|
|
|
+
|
|
|
+ const data = readBinBinarayToCommand()
|
|
|
+ data.then(result=>{commands=result})
|
|
|
+
|
|
|
+
|
|
|
+ return data
|
|
|
+}
|
|
|
+async function readBinBinarayToCommand() {
|
|
|
+ let res =await uni.request({
|
|
|
+ url: 'https://opt.bms16.com/ota.BIN',
|
|
|
+ method: 'GET',
|
|
|
+ responseType: 'arraybuffer',
|
|
|
+ });
|
|
|
+ const arrayBuffer=res[1].data
|
|
|
+ const uint8Array = new Uint8Array(arrayBuffer);
|
|
|
+ const test = splitArrayIntoChunks(uint8Array, 80);
|
|
|
+ const data =makeArr(test)
|
|
|
+ return data
|
|
|
+}
|
|
|
+
|
|
|
+function sendNextCommand(mac_id) {
|
|
|
+ const app = getApp();
|
|
|
+ readRepeatTime=0
|
|
|
+
|
|
|
+
|
|
|
+ if (currentCommandIndex >= commands.length) {
|
|
|
+ uni.hideLoading();
|
|
|
+ common.simpleToast('所有指令发送完成', 2000)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == mac_id);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ console.log('deviceId == undefined');
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ const command = [commands[currentCommandIndex]];
|
|
|
+ if(command.length==0){
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var buffer;
|
|
|
+ buffer = common.toArrayBuffer(command.shift());
|
|
|
+
|
|
|
+ uni.writeBLECharacteristicValue({
|
|
|
+ deviceId: deviceId,
|
|
|
+ serviceId: writeServiceID,
|
|
|
+ characteristicId: writeID,
|
|
|
+ value: buffer,
|
|
|
+ success() {
|
|
|
+
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.error('指令发送失败', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ currentCommandIndex++;
|
|
|
+}
|
|
|
+
|
|
|
+function splitArrayIntoChunks(array, chunkSize) {
|
|
|
+ const newArr=array.slice(16383)
|
|
|
+ const numChunks = Math.ceil(newArr.length / chunkSize);
|
|
|
+
|
|
|
+ return Array.from({ length: numChunks }, (_, i) => {
|
|
|
+ return newArr.slice(i * chunkSize, (i + 1) * chunkSize);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function makeArr(array) {
|
|
|
+ const result = [];
|
|
|
+ let endPackage;
|
|
|
+ for (let i = 0; i < array.length; i ++) {
|
|
|
+ endPackage = 0x00
|
|
|
+ if((i + 1) >= array.length){
|
|
|
+
|
|
|
+ endPackage = 0x01
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ let startArray = []
|
|
|
+ const packageLen=parseInt((array[i].length+8).toString(16).toUpperCase(), 16)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const totalPackageSize=[0x00,0x00,0x01,0xAB,0xFC]
|
|
|
+ startArray.push(packageLen,...totalPackageSize)
|
|
|
+
|
|
|
+ const ids=splitNumber(i)
|
|
|
+ startArray.push(...ids)
|
|
|
+
|
|
|
+ startArray.push(endPackage)
|
|
|
+
|
|
|
+ const formattedChunk = array[i].map(byte => `0x${byte.toString(16).toUpperCase()}`);
|
|
|
+ startArray.push(...formattedChunk)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const crcStr='0x'+crc8IEEE8023(startArray).toString(16).toUpperCase()
|
|
|
+ const testCrc=parseInt(crcStr,16)
|
|
|
+
|
|
|
+ startArray.push(crcStr)
|
|
|
+ startArray.push(0xAA,0xAA)
|
|
|
+ startArray.unshift(0x22,0x22,0x30)
|
|
|
+ result.push(startArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function splitNumber(num) {
|
|
|
+ let highByte = (num >> 8) & 0xFF;
|
|
|
+
|
|
|
+ let lowByte = num & 0xFF;
|
|
|
+
|
|
|
+
|
|
|
+ let highHex = highByte.toString(16).toUpperCase().padStart(2, '0');
|
|
|
+ let lowHex = lowByte.toString(16).toUpperCase().padStart(2, '0');
|
|
|
+
|
|
|
+
|
|
|
+ return ['0x' + highHex, '0x' + lowHex];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function writeData(mac_id, data, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceIds = app.globalData.connectionState[mac_id].deviceId
|
|
|
+ console.log(deviceIds,'deviceIds');
|
|
|
+ if (deviceIds == undefined) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var buffer;
|
|
|
+ buffer = common.toArrayBuffer(data.shift());
|
|
|
+
|
|
|
+ uni.writeBLECharacteristicValue({
|
|
|
+ deviceId: deviceIds,
|
|
|
+ serviceId: writeServiceID,
|
|
|
+ characteristicId: writeID,
|
|
|
+ value: buffer,
|
|
|
+
|
|
|
+ success(res) {
|
|
|
+
|
|
|
+ if (data.length == 0) {
|
|
|
+ callback(res);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ writeData(device, data, callback, fail);
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fail(res) {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ readServiceID: readServiceID,
|
|
|
+ readID: readID,
|
|
|
+ writeServiceID: writeServiceID,
|
|
|
+ writeID: writeID,
|
|
|
+ MTU: MTU,
|
|
|
+ acceptDevice: acceptDevice,
|
|
|
+ isDevice: isDevice,
|
|
|
+ alterConnect: alterConnect,
|
|
|
+ readData: readData,
|
|
|
+ turnOffCar: turnOffCar,
|
|
|
+ isSingleBt: isSingleBt,
|
|
|
+ haveBms: haveBms,
|
|
|
+ switchFactory: switchFactory,
|
|
|
+ otaUpgrade,
|
|
|
+ findCarCmd,
|
|
|
+ turnOffCar,
|
|
|
+ turnOnCar,
|
|
|
+ getCarPressure,
|
|
|
+ nearUnlock,
|
|
|
+ nearCloseUnlock,
|
|
|
+ getSensitivity,
|
|
|
+ setSensitivity,
|
|
|
+ getNearUnlockSet,
|
|
|
+ setNearUnlock,
|
|
|
+
|
|
|
+
|
|
|
+};
|