|
@@ -2,6 +2,7 @@ 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';
|
|
@@ -15,6 +16,8 @@ let currentCommandIndex = 1;
|
|
|
var totalLength = 0 //总包长度
|
|
|
var joinPack = []//接收到的数据包
|
|
|
var readRepeatTime = 0 //读到完整数据包的时间戳
|
|
|
+var readRepeatTime = 0 //读到完整数据包的时间戳
|
|
|
+
|
|
|
|
|
|
function acceptDevice(device) {
|
|
|
return device.btid ? true : false;
|
|
@@ -76,10 +79,17 @@ function alterConnect(device, deviceId) {
|
|
|
// console.log(data,'datatest');
|
|
|
console.log(crc8IEEE8023(data).toString(16).toUpperCase(),'crc---------');
|
|
|
const crc_data = parseInt(crc8IEEE8023(data).toString(16).toUpperCase(),16)
|
|
|
+ // const crc_data =crc8IEEE8023(data).toString(16).toUpperCase()
|
|
|
data.push(crc_data,0xAA,0xAA)
|
|
|
data.unshift(0x22,0x22,0x01)
|
|
|
+ // // 从索引 0 开始,删除 3 个元素
|
|
|
+ const firstPart = data.splice(0, 20);
|
|
|
|
|
|
- return [data]
|
|
|
+ // // 剩余的元素
|
|
|
+ const secondPart = data;
|
|
|
+ // const threePart = data;
|
|
|
+ // return [data]
|
|
|
+ return [firstPart,secondPart]
|
|
|
// return [[0x22,0x22,0x02,0x01,0x02,0x1B,0xAA,0xAA]]
|
|
|
}
|
|
|
|
|
@@ -118,9 +128,10 @@ function stringToHexArray(str) {
|
|
|
function readData(device, value, data) {
|
|
|
console.log('***********************test');
|
|
|
var test = new Uint8Array(value);
|
|
|
- const bmsData=Array.from(test);
|
|
|
- console.log(bmsData,'bmsData-------------');
|
|
|
- const normalArray =packBmsData(bmsData)
|
|
|
+ // const bmsData=Array.from(test);
|
|
|
+ const normalArray=Array.from(test);
|
|
|
+ // console.log(bmsData,'bmsData-------------');
|
|
|
+ // const normalArray =packBmsData(bmsData)
|
|
|
|
|
|
if(normalArray){
|
|
|
console.log(normalArray[2],'normalArray---------------');
|
|
@@ -130,7 +141,7 @@ function readData(device, value, data) {
|
|
|
loginCmd(device.mac_id,normalArray)
|
|
|
break;
|
|
|
|
|
|
- case 0x61||0x62||0x65||0x7F:
|
|
|
+ case 0x61||0x62||0x65:
|
|
|
//开机指令 关机 寻车 //设置灵敏度回复
|
|
|
trunCarCommand(device.mac_id,normalArray)
|
|
|
break;
|
|
@@ -146,6 +157,7 @@ function readData(device, value, data) {
|
|
|
break;
|
|
|
|
|
|
case 0x7E:
|
|
|
+
|
|
|
//获取车辆接近解锁 是否配对 灵敏度信息
|
|
|
getNearCarCmdInfo(device.mac_id,normalArray)
|
|
|
break;
|
|
@@ -224,19 +236,21 @@ function loginCmd(mac_id,data){
|
|
|
// uni.hideLoading();
|
|
|
//正常模式
|
|
|
console.log('登陆成功');
|
|
|
- if('lockType' in app.globalData.nearLockInfo ){
|
|
|
- if(app.globalData.nearLockInfo.lockType==0){
|
|
|
- console.log('获取接近解锁指令为关闭');
|
|
|
+ // if('lockType' in app.globalData.nearLockInfo ){
|
|
|
+ // if(app.globalData.nearLockInfo.lockType==0){
|
|
|
+ // console.log('获取接近解锁指令为关闭');
|
|
|
|
|
|
- }else{
|
|
|
- uni.hideLoading();
|
|
|
- console.log('获取接近解锁指令为成功');
|
|
|
- }
|
|
|
- }else{
|
|
|
- const getNearUnlockSetCmd=getNearUnlockSet()
|
|
|
- console.log(getNearUnlockSetCmd,'getNearUnlockSetCmd');
|
|
|
- writeData(mac_id,getNearUnlockSetCmd)
|
|
|
- }
|
|
|
+ // }else{
|
|
|
+ // uni.hideLoading();
|
|
|
+ // console.log('获取接近解锁指令为成功');
|
|
|
+ // }
|
|
|
+ // }else{
|
|
|
+ // const getNearUnlockSetCmd=getNearUnlockSet()
|
|
|
+ // console.log(getNearUnlockSetCmd,'getNearUnlockSetCmd');
|
|
|
+ // writeData(mac_id,getNearUnlockSetCmd)
|
|
|
+ // }
|
|
|
+ checkUnlock(mac_id,'login')
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
function checkSendNextCommand(mac_id,data){
|
|
@@ -260,11 +274,19 @@ function trunCarCommand(mac_id,data){
|
|
|
}
|
|
|
function nearCarCmd(mac_id,data){
|
|
|
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('操作成功')
|
|
|
+ common.simpleToast(`请在系统通知中同意与${mac_id}配对`)
|
|
|
+
|
|
|
}else if(data[len]==0x01){
|
|
|
- common.simpleToast('操作失败')
|
|
|
+ common.simpleToast('配对失败,请重新开始配对')
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -332,7 +354,7 @@ function sendCommand(cmd, data = []) {
|
|
|
//信息内容 cmd
|
|
|
//crc校验
|
|
|
const pData=[dataLen,...data]
|
|
|
- const crcData='0x'+crc8IEEE8023(pData).toString(16).toUpperCase()
|
|
|
+ const crcData=parseInt(crc8IEEE8023(pData).toString(16).toUpperCase(), 16)
|
|
|
cmdData.push(cmd,dataLen,...data,crcData,0xAA, 0xAA)
|
|
|
// console.log(cmdData,'cmdDatacmdData');
|
|
|
return cmdData
|
|
@@ -377,25 +399,30 @@ function getNearUnlockSet(device, deviceId,type) {
|
|
|
return [sendCommand(0x4D,[0x4D])];
|
|
|
}
|
|
|
|
|
|
-function getNearCarCmdInfo(mac_id,data){
|
|
|
- const pData={
|
|
|
- lockType:data[4],//接近解锁配置
|
|
|
- level:data[5],//感应等级
|
|
|
- status:data[6]//配对状态
|
|
|
- }
|
|
|
- console.log(pData,data,pData.status,'pData');
|
|
|
- app.globalData.nearLockInfo=pData
|
|
|
+function getNearCarCmdInfo(macid,data){
|
|
|
+
|
|
|
if(pData.lockType==0x02||pData.lockType==0x01){
|
|
|
- console.log('已开启配对');
|
|
|
- common.simpleToast('感应解锁已开启,前往设置灵敏度页面')
|
|
|
- uni.navigateTo({ url: '/pages/bluetoothUnlock/unlockset' })
|
|
|
uni.hideLoading();
|
|
|
- if( pData.status == 0x01){
|
|
|
- common.simpleToast('配对成功')
|
|
|
- return
|
|
|
- }else if(pData.status==0x00){
|
|
|
- common.simpleToast('未配对')
|
|
|
- }
|
|
|
+ const pData={
|
|
|
+ lockType:data[4],//接近解锁配置
|
|
|
+ level:data[5],//感应等级
|
|
|
+ }
|
|
|
+ app.globalData.nearLockInfo=pData
|
|
|
+
|
|
|
+ console.log('已开启配对');
|
|
|
+ // common.simpleToast('已开启配对',2000)
|
|
|
+ // common.simpleToast('感应解锁已开启,前往设置灵敏度页面')
|
|
|
+ // uni.navigateTo({ url: '/pages/bluetoothUnlock/unlockset' })
|
|
|
+
|
|
|
+ // if( pData.status == 0x01){
|
|
|
+ // common.simpleToast('配对成功')
|
|
|
+ // return
|
|
|
+ // }else if(pData.status==0x00){
|
|
|
+ // common.simpleToast('未配对')
|
|
|
+ // }
|
|
|
+ setTimeout(()=>{
|
|
|
+ checkUnlock(macid)
|
|
|
+ },300)
|
|
|
}else if(pData.lockType==0x00){
|
|
|
console.log('未开启配对')
|
|
|
const nearUnlockCmd=nearUnlock()
|
|
@@ -404,6 +431,49 @@ function getNearCarCmdInfo(mac_id,data){
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+function checkUnlock(macid,type='get'){
|
|
|
+ let deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ let device = app.globalData.connectionState[deviceId].device
|
|
|
+ permision.getBondedDevices(deviceId).then(res=>{
|
|
|
+ if(res){
|
|
|
+ app.globalData.nearLockCheck=true
|
|
|
+ common.simpleToast('感应解锁已开启,前往设置灵敏度页面')
|
|
|
+ //redirectTo 关闭当前页面 防止用户重复操作
|
|
|
+ uni.redirectTo({ url: '/pages/bluetoothUnlock/unlockset' })
|
|
|
+ }else{
|
|
|
+ if(type==='login'){
|
|
|
+ //下发接近解锁指令
|
|
|
+ // const nearUnlockCmd=nearUnlock()
|
|
|
+ // console.log(nearUnlockCmd,'nearUnlockCmd');
|
|
|
+ // writeData(mac_id,nearUnlockCmd)
|
|
|
+
|
|
|
+ // 获取接近解锁指令信息
|
|
|
+ const getNearUnlockSetCmd=getNearUnlockSet()
|
|
|
+ console.log(getNearUnlockSetCmd,'getNearUnlockSetCmd');
|
|
|
+ writeData(mac_id,getNearUnlockSetCmd)
|
|
|
+ }else{
|
|
|
+ uni.showModal({
|
|
|
+ title: '蓝牙配对确认',
|
|
|
+ content: '请在系统通知栏前往同意与'+device.name+'设备配对',
|
|
|
+ cancelText: '取消',
|
|
|
+ confirmText: '已同意',
|
|
|
+ success: function(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ checkUnlock(macid)
|
|
|
+ }else{
|
|
|
+ uni.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function(res) {},
|
|
|
+ complete: function(res) {},
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
function switchFactory(device, deviceId) {
|
|
|
//切换正常,工厂模式指令
|