优化蓝牙协议
This commit is contained in:
parent
89710ffcf0
commit
e23d241f8c
@ -15,7 +15,6 @@ import 'package:star_lock/main/lockDetail/lcokSet/msgNotification/msgNotificatio
|
||||
import 'package:star_lock/main/lockDetail/lcokSet/notificationMode/notificationMode_page.dart';
|
||||
import 'package:star_lock/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_page.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_main_page.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart';
|
||||
import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyDetailChangeDate/passwordKeyDetailChangeDate_page.dart';
|
||||
import 'package:star_lock/mine/about/webviewShow_page.dart';
|
||||
import 'package:star_lock/mine/mine/safeVerify/safeVerify_page.dart';
|
||||
@ -101,6 +100,7 @@ import 'main/lockDetail/lcokSet/wirelessKeyboard/seletWirelessKeyboard/seletWire
|
||||
import 'main/lockDetail/lcokSet/wirelessKeyboard/wirelessKeyboardList/wirelessKeyboard_page.dart';
|
||||
import 'main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart';
|
||||
import 'main/lockDetail/monitoring/monitoringRealTimeScreen/monitoringRealTimeScreen_page.dart';
|
||||
import 'main/lockDetail/realTimePicture/realTimePicture_page.dart';
|
||||
import 'main/lockDetail/remoteControl/addRemoteControl/addRemoteControlManage/addRemoteControlManage_page.dart';
|
||||
import 'main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart';
|
||||
import 'main/lockDetail/videoLog/editVideoLog/editVideoLog_page.dart';
|
||||
|
||||
@ -114,6 +114,7 @@ class BlueManage {
|
||||
// 蓝牙已开启,可以进行蓝牙操作
|
||||
if(deviceConnectionState != DeviceConnectionState.connected){
|
||||
if(isAddEquipment == false){
|
||||
// print("666666666");
|
||||
startScan();
|
||||
}
|
||||
|
||||
@ -121,6 +122,7 @@ class BlueManage {
|
||||
stateCallBack(deviceConnectionState!);
|
||||
});
|
||||
}else{
|
||||
stopScan();
|
||||
stateCallBack(deviceConnectionState!);
|
||||
}
|
||||
}else{
|
||||
@ -137,34 +139,32 @@ class BlueManage {
|
||||
if (knownDeviceIndex >= 0) {
|
||||
// 存在的时候赋值
|
||||
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
|
||||
stopScan();
|
||||
} else {
|
||||
// 不存在的时候返回-1 然后循环5秒
|
||||
var index = 0;
|
||||
Completer? completer = Completer();
|
||||
Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
///定时任务
|
||||
// print("timer index0:$index");
|
||||
if(index >= 9){
|
||||
// 当超过5秒的时候取消定时任务 弹窗显示连接失败
|
||||
completer.complete();
|
||||
stopScan();
|
||||
timer.cancel();
|
||||
connectDeviceMacAddress = "";
|
||||
connectStateCallBack(DeviceConnectionState.disconnected);
|
||||
completer.complete();
|
||||
await stopScan();
|
||||
timer.cancel();
|
||||
// deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
// print("timer index1:$index");
|
||||
connectStateCallBack(DeviceConnectionState.disconnected);
|
||||
}else{
|
||||
// 每秒判断数组列表里面是否有这个设备
|
||||
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
|
||||
|
||||
if (knownDeviceIndex >= 0) {
|
||||
// 存在的时候销毁定时器,赋值
|
||||
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
|
||||
completer.complete();
|
||||
stopScan();
|
||||
timer.cancel();
|
||||
// print("timer index2:$index");
|
||||
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
|
||||
|
||||
// var uuidStr = (scanDevices[knownDeviceIndex].serviceUuids.isNotEmpty ? scanDevices[knownDeviceIndex].serviceUuids[0] : "").toString();
|
||||
// if(uuidStr[31] == "0"){
|
||||
@ -184,16 +184,17 @@ class BlueManage {
|
||||
// 等待Completer完成
|
||||
await completer.future;
|
||||
}
|
||||
print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName");
|
||||
|
||||
print("1 connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName");
|
||||
await stopScan();
|
||||
if (connectDeviceMacAddress.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
// print("33333333333333333333333");
|
||||
_currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 5)).listen((connectionStateUpdate) async {
|
||||
// 获取状态
|
||||
deviceConnectionState = connectionStateUpdate.connectionState;
|
||||
print('deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}');
|
||||
print('2 deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}');
|
||||
if (connectionStateUpdate.connectionState == DeviceConnectionState.connected) {
|
||||
// 如果状态是连接的开始发现服务
|
||||
try {
|
||||
@ -326,7 +327,9 @@ class BlueManage {
|
||||
|
||||
// 停止扫描蓝牙设备
|
||||
Future<void> stopScan() async {
|
||||
// print("444444444");
|
||||
if(_scanSubscription != null){
|
||||
// print("555555555555");
|
||||
_scanSubscription?.cancel();
|
||||
_scanSubscription = null;
|
||||
}
|
||||
@ -335,10 +338,11 @@ class BlueManage {
|
||||
// 断开连接
|
||||
Future<void> disconnect(String deviceMAC) async {
|
||||
try {
|
||||
if(_currentConnectionStream != null){
|
||||
connectDeviceMacAddress = "";
|
||||
// if(_currentConnectionStream != null){
|
||||
_currentConnectionStream?.cancel();
|
||||
_currentConnectionStream = null;
|
||||
}
|
||||
// }
|
||||
|
||||
print('disconnecting to device: $deviceMAC');
|
||||
} on Exception catch (e, _) {
|
||||
|
||||
@ -501,18 +501,18 @@ class LockSetLogic extends BaseGetXController {
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
Get.back();
|
||||
|
||||
// if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
|
||||
// // 如果是已连接状态 直接调用协议
|
||||
// // 已配对 表示这把锁未被初始化,还处于被添加状态
|
||||
// if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
|
||||
// // 如果是锁拥有者直接删除锁,调用初始化协议
|
||||
// factoryDataResetAction();
|
||||
// } else {
|
||||
// // 不是锁拥有者,调用删除钥匙协议
|
||||
// deletUserAction();
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
|
||||
// 如果是已连接状态 直接调用协议
|
||||
// 已配对 表示这把锁未被初始化,还处于被添加状态
|
||||
if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
|
||||
// 如果是锁拥有者直接删除锁,调用初始化协议
|
||||
factoryDataResetAction();
|
||||
} else {
|
||||
// 不是锁拥有者,调用删除钥匙协议
|
||||
deletUserAction();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.currentDeviceUUid.value.isNotEmpty) {
|
||||
// 已经扫描到了当前设备 停止扫描,直接删除锁
|
||||
|
||||
@ -410,6 +410,8 @@ class LockDetailLogic extends BaseGetXController {
|
||||
Future<void> openDoorAction(int openMode) async {
|
||||
showBlueConnetctToastTimer(action:() {
|
||||
state.openLockBtnState.value = 0;
|
||||
BlueManage().stopScan();
|
||||
|
||||
// state.animationController.reset();
|
||||
// state.animationController.forward();
|
||||
});
|
||||
@ -578,10 +580,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
}
|
||||
|
||||
longPressCloseDoor(){
|
||||
|
||||
}
|
||||
|
||||
// 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口
|
||||
void getLockNetToken() async {
|
||||
LockNetTokenEntity entity = await ApiRepository.to
|
||||
|
||||
@ -634,6 +634,8 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
// print("LockDetailPage===didPop");
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
BlueManage().stopScan();
|
||||
state.openLockBtnState.value = 0;
|
||||
state.animationController.reset();
|
||||
state.animationController.forward();
|
||||
state.animationController.dispose();
|
||||
@ -654,6 +656,8 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
// print("LockDetailPage===didPushNext");
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
BlueManage().stopScan();
|
||||
state.openLockBtnState.value = 0;
|
||||
state.animationController.reset();
|
||||
state.animationController.forward();
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_state.dart';
|
||||
import 'package:star_lock/talk/call/callTalk.dart';
|
||||
|
||||
import '../../../../talk/call/g711.dart';
|
||||
@ -13,6 +12,7 @@ import '../../../../talk/udp/udp_manage.dart';
|
||||
import '../../../../talk/udp/udp_senderManage.dart';
|
||||
import '../../../../tools/baseGetXController.dart';
|
||||
import '../../../../tools/eventBusEventManage.dart';
|
||||
import 'realTimePicture_state.dart';
|
||||
|
||||
class RealTimePictureLogic extends BaseGetXController {
|
||||
final RealTimePictureState state = RealTimePictureState();
|
||||
@ -4,11 +4,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart';
|
||||
|
||||
import '../../../../app_settings/app_colors.dart';
|
||||
import '../../../../tools/showTFView.dart';
|
||||
import '../../../../tools/toast.dart';
|
||||
import 'realTimePicture_logic.dart';
|
||||
|
||||
class RealTimePicturePage extends StatefulWidget {
|
||||
const RealTimePicturePage({Key? key}) : super(key: key);
|
||||
Loading…
x
Reference in New Issue
Block a user