liuwei 6 dienas atpakaļ
vecāks
revīzija
b44e6c4dc8
4 mainītis faili ar 134 papildinājumiem un 130 dzēšanām
  1. 124 119
      common/bluetooth.js
  2. 4 4
      common/bluetooth/ZXCar.js
  3. 2 4
      js_sdk/wa-permission/permission.js
  4. 4 3
      mixin/index.js

+ 124 - 119
common/bluetooth.js

@@ -434,127 +434,131 @@ function alterConnect(device, deviceId, callback = () => {}, fail = () => {}) {
     }
 	console.log("xxxx2")
 	console.log(deviceId)
-    // 获取蓝牙设备的服务列表
+	  var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
 	setTimeout(()=>{
-    uni.getBLEDeviceServices({
-        deviceId: deviceId,
-        success(res) {
-            console.log(res,'res1111');
-			console.log(bluetoothDeviceConfig(device).writeServiceID)
-			// 获取蓝牙设备的写特征值
-			setTimeout(()=>{
-            uni.getBLEDeviceCharacteristics({
-                deviceId: deviceId,
-                serviceId: bluetoothDeviceConfig(device).writeServiceID,
-                success(res) {
-                    console.log(res,'res22222');
-                    // 获取蓝牙设备的读特征值
-                    uni.getBLEDeviceCharacteristics({
-                        deviceId: deviceId,
-                        serviceId: bluetoothDeviceConfig(device).readServiceID,
-                        success(res) {
-                            console.log(res,'res3333');
-                            // 监听蓝牙设备的读特征值变化
-                            uni.notifyBLECharacteristicValueChange({
-                                state: true,
-                                deviceId: deviceId,
-                                serviceId: bluetoothDeviceConfig(device).readServiceID,
-                                characteristicId: bluetoothDeviceConfig(device).readID,
-                                success(res) {
-                                    console.log(res);
-                                    // 判断设备是否支持  ,并且当前平台是否为安卓
-                                    if (bluetoothDeviceConfig(device).MTU && SystemInfoUtil.platform == SystemInfoUtil.ANDROID) {
-                                        // 设置蓝牙设备的MTU
-                                        uni.setBLEMTU({
-                                            deviceId: deviceId,
-                                            mtu: bluetoothDeviceConfig(device).MTU,
-                                            success: (res) => {
-                                                console.log('setBLEMTU success>>', res);
-                                                // 判断设备是否有alterConnect方法
-                                                if (bluetoothDeviceConfig(device).alterConnect) {
-                                                    var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
-													console.log(data[0],'data111111');
-                                                    // 判断alterConnect方法是否返回数据
-                                                    if (data) {
-                                                        // 写入数据
-														setTimeout(()=>{
-															writeData(device, deviceId, data, callback, fail);
-														},100)
+		writeData(device, deviceId, data, callback, fail);
+	},3000)
+    // 获取蓝牙设备的服务列表
+	// setTimeout(()=>{
+ //    uni.getBLEDeviceServices({
+ //        deviceId: deviceId,
+ //        success(res) {
+ //            console.log(res,'res1111');
+	// 		console.log(bluetoothDeviceConfig(device).writeServiceID)
+	// 		// 获取蓝牙设备的写特征值
+	// 		setTimeout(()=>{
+ //            uni.getBLEDeviceCharacteristics({
+ //                deviceId: deviceId,
+ //                serviceId: bluetoothDeviceConfig(device).writeServiceID,
+ //                success(res) {
+ //                    console.log(res,'res22222');
+ //                    // 获取蓝牙设备的读特征值
+ //                    uni.getBLEDeviceCharacteristics({
+ //                        deviceId: deviceId,
+ //                        serviceId: bluetoothDeviceConfig(device).readServiceID,
+ //                        success(res) {
+ //                            console.log(res,'res3333');
+ //                            // 监听蓝牙设备的读特征值变化
+ //                            uni.notifyBLECharacteristicValueChange({
+ //                                state: true,
+ //                                deviceId: deviceId,
+ //                                serviceId: bluetoothDeviceConfig(device).readServiceID,
+ //                                characteristicId: bluetoothDeviceConfig(device).readID,
+ //                                success(res) {
+ //                                    console.log(res);
+ //                                    // 判断设备是否支持  ,并且当前平台是否为安卓
+ //                                    if (bluetoothDeviceConfig(device).MTU && SystemInfoUtil.platform == SystemInfoUtil.ANDROID) {
+ //                                        // 设置蓝牙设备的MTU
+ //                                        uni.setBLEMTU({
+ //                                            deviceId: deviceId,
+ //                                            mtu: bluetoothDeviceConfig(device).MTU,
+ //                                            success: (res) => {
+ //                                                console.log('setBLEMTU success>>', res);
+ //                                                // 判断设备是否有alterConnect方法
+ //                                                if (bluetoothDeviceConfig(device).alterConnect) {
+ //                                                    var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
+	// 												console.log(data[0],'data111111');
+ //                                                    // 判断alterConnect方法是否返回数据
+ //                                                    if (data) {
+ //                                                        // 写入数据
+	// 													setTimeout(()=>{
+	// 														writeData(device, deviceId, data, callback, fail);
+	// 													},3000)
                                                         
-                                                    } else {
-                                                        // 调用回调函数
-                                                        callback(res);
-                                                    }
-                                                } else {
-                                                    // 调用回调函数
-                                                    callback(res);
-                                                }
-                                            },
-                                            fail: (res) => {
-                                                console.log('setBLEMTU fail>>', res);
-                                                // 判断设备是否有alterConnect方法
-                                                if (bluetoothDeviceConfig(device).alterConnect) {
-                                                    var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
-                                                    // 判断alterConnect方法是否返回数据
-                                                    if (data) {
-                                                        // 写入数据
-                                                        writeData(device, deviceId, data, callback, fail);
-                                                    } else {
-                                                        // 调用回调函数
-                                                        callback(res);
-                                                    }
-                                                } else {
-                                                    // 调用回调函数
-                                                    callback(res);
-                                                }
-                                            }
-                                        });
-                                    } else {
-                                        // 判断设备是否有alterConnect方法
-                                        if (bluetoothDeviceConfig(device).alterConnect) {
-                                            var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
-                                            // 判断alterConnect方法是否返回数据
-                                            if (data) {
-                                                // 写入数据
-                                                writeData(device, deviceId, data, callback, fail);
-                                            } else {
-                                                // 调用回调函数
-                                                callback(res);
-                                            }
-                                        } else {
-                                            // 调用回调函数
-                                            callback(res);
-                                        }
-                                    }
-                                },
-                                fail(res) {
-                                    // 调用失败回调函数
-                                    fail(res);
-                                }
-                            });
-                        },
-                        fail(res) {
-                            // 调用失败回调函数
-                            fail(res);
-                        }
-                    });
-				},
-                fail(res) {
-					console.log('getBLEDeviceServices fail',res);
-                    // 调用失败回调函数
-                    fail(res);
-                }
-            });	
-			},500)
+ //                                                    } else {
+ //                                                        // 调用回调函数
+ //                                                        callback(res);
+ //                                                    }
+ //                                                } else {
+ //                                                    // 调用回调函数
+ //                                                    callback(res);
+ //                                                }
+ //                                            },
+ //                                            fail: (res) => {
+ //                                                console.log('setBLEMTU fail>>', res);
+ //                                                // 判断设备是否有alterConnect方法
+ //                                                if (bluetoothDeviceConfig(device).alterConnect) {
+ //                                                    var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
+ //                                                    // 判断alterConnect方法是否返回数据
+ //                                                    if (data) {
+ //                                                        // 写入数据
+ //                                                        writeData(device, deviceId, data, callback, fail);
+ //                                                    } else {
+ //                                                        // 调用回调函数
+ //                                                        callback(res);
+ //                                                    }
+ //                                                } else {
+ //                                                    // 调用回调函数
+ //                                                    callback(res);
+ //                                                }
+ //                                            }
+ //                                        });
+ //                                    } else {
+ //                                        // 判断设备是否有alterConnect方法
+ //                                        if (bluetoothDeviceConfig(device).alterConnect) {
+ //                                            var data = bluetoothDeviceConfig(device).alterConnect(device, deviceId);
+ //                                            // 判断alterConnect方法是否返回数据
+ //                                            if (data) {
+ //                                                // 写入数据
+ //                                                writeData(device, deviceId, data, callback, fail);
+ //                                            } else {
+ //                                                // 调用回调函数
+ //                                                callback(res);
+ //                                            }
+ //                                        } else {
+ //                                            // 调用回调函数
+ //                                            callback(res);
+ //                                        }
+ //                                    }
+ //                                },
+ //                                fail(res) {
+ //                                    // 调用失败回调函数
+ //                                    fail(res);
+ //                                }
+ //                            });
+ //                        },
+ //                        fail(res) {
+ //                            // 调用失败回调函数
+ //                            fail(res);
+ //                        }
+ //                    });
+	// 			},
+ //                fail(res) {
+	// 				console.log('getBLEDeviceServices fail',res);
+ //                    // 调用失败回调函数
+ //                    fail(res);
+ //                }
+ //            });	
+	// 		},500)
             
-        },
-        fail(res) {
+ //        },
+ //        fail(res) {
 			
-            // 调用失败回调函数
-            fail(res);
-        }
-    });
-	},500)
+ //            // 调用失败回调函数
+ //            fail(res);
+ //        }
+ //    });
+	// },500)
 }
 // 关闭设备连接
 function closeDevice(macid, callback = () => {}, fail = () => {}) {
@@ -650,7 +654,8 @@ function writeData(device, deviceId, data, callback = () => {}, fail = () => {})
 	// console.log(buffer,'buffer111');
     // 调用uni.writeBLECharacteristicValue方法,向蓝牙设备写入数据
 	// setTimeout(() => {
-    uni.writeBLECharacteristicValue({
+		plus.bluetooth.writeBLECharacteristicValue({
+    // uni.writeBLECharacteristicValue({
         deviceId: deviceId,
         serviceId: bluetoothDeviceConfig(device).writeServiceID,
         characteristicId: bluetoothDeviceConfig(device).writeID,
@@ -668,7 +673,7 @@ function writeData(device, deviceId, data, callback = () => {}, fail = () => {})
                 // // 否则,延时500毫秒后再次调用writeData函数
                 setTimeout(() => {
                     writeData(device, deviceId, data, callback, fail);
-                }, 60);
+                }, 150);
             }
         },
         // 失败回调函数

+ 4 - 4
common/bluetooth/ZXCar.js

@@ -443,13 +443,14 @@ function getNearCarCmdInfo(macid,data){
 		
 }
 function checkUnlock(macid,type='get'){
-	console.log('test0000000000000');
+	
 	const res=permision.getBondedDevices()
+	console.log(res,'test0000000000000');
 	let app=getApp()
 	if(res){
 			app.globalData.nearLockCheck=true
 			common.simpleToast('感应解锁已开启,前往设置灵敏度页面')
-			uni.navigateTo({ url: '/pages/bluetoothUnlock/unlockSet' })
+			uni.redirectTo({ url: '/pages/bluetoothUnlock/unlockSet' })
 			console.log('test');
 			//redirectTo 关闭当前页面 防止用户重复操作
 		}else{
@@ -477,14 +478,13 @@ function checkUnlock(macid,type='get'){
 						if (res.confirm) {
 							checkUnlock(macid)
 						}else{
-							uni.switchTab({ url: '/pages/index/index' })
+							// uni.switchTab({ url: '/pages/index/index' })
 						}
 					},
 					fail: function(res) {},
 					complete: function(res) {},
 				})
 			}
-			
 	}
 }
 

+ 2 - 4
js_sdk/wa-permission/permission.js

@@ -470,11 +470,9 @@ function getBondedDevices() {
 	//   address: plus.android.invoke(device, 'getAddress'),
 	//   type: getDeviceType(plus.android.invoke(device, 'getBluetoothClass'))
 	// }));
-	const car_info = uni.getStorageSync('car_info') ||{}
-	const car_sn=car_info.car_sn
 	const app = getApp();
-	
-	let deviceId = uni.getStorageSync('car_info').car_sn
+	const car_sn=  uni.getStorageSync('car_info').car_sn
+	const deviceId =app.globalData.connectionState[car_sn].deviceId
 	if(!deviceId) return false
 	//配对配对蓝牙设备是否在蓝牙列表里面
 	deviceArray.map(device => {

+ 4 - 3
mixin/index.js

@@ -1,7 +1,7 @@
 // mixins/countdownMixin.js
 var bluetooth = require('@/common/bluetooth.js');
 import {getFunctionTag,setFunctionTag,getUserCurrentLocation} from '@/common/storage.js';
-var app = getApp();
+
 var config = require('@/common/config.js');
 var common = require('@/common/common.js');
 var http = require('@/common/http.js');
@@ -61,7 +61,7 @@ export default {
 		},
 		tapBlueToothCmd(cmd,type){
 			const car_info= uni.getStorageSync('car_info');
-			const isCarLocation = cmd=='more'?true:type
+			const isCarLocation = (cmd=='more')?true:type
 			if(this.cmdType=='batteryInfo'){
 				uni.navigateTo({
 					url:`/pages/batteryDetail/batteryDetail`
@@ -143,8 +143,9 @@ export default {
 		bluetoothCmd(isCarLocation){
 			const me=this
 			const car_info= uni.getStorageSync('car_info');
+			const app = getApp();
 			//蓝牙是否已经连接 未连接提示去连接 已连接下发对应指令
-			const isBluetoothConnect = app.globalData.connectionStateChangeFunc[car_info.car_sn]
+			const isBluetoothConnect = app.globalData.nearLockCheck
 			if(isBluetoothConnect){
 				const isTurnOn=this.contrilList.find(item => item.isTurnOn).isTurnOn==1
 				console.log(isTurnOn,this.cmdType,this.contrilList);