优化蓝牙协议

This commit is contained in:
魏少阳 2024-01-09 13:51:35 +08:00
parent 89710ffcf0
commit e23d241f8c
8 changed files with 38 additions and 32 deletions

View File

@ -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/notificationMode/notificationMode_page.dart';
import 'package:star_lock/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_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/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/main/lockDetail/passwordKey/passwordKeyDetailChangeDate/passwordKeyDetailChangeDate_page.dart';
import 'package:star_lock/mine/about/webviewShow_page.dart'; import 'package:star_lock/mine/about/webviewShow_page.dart';
import 'package:star_lock/mine/mine/safeVerify/safeVerify_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/lcokSet/wirelessKeyboard/wirelessKeyboardList/wirelessKeyboard_page.dart';
import 'main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart'; import 'main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart';
import 'main/lockDetail/monitoring/monitoringRealTimeScreen/monitoringRealTimeScreen_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/addRemoteControl/addRemoteControlManage/addRemoteControlManage_page.dart';
import 'main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart'; import 'main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart';
import 'main/lockDetail/videoLog/editVideoLog/editVideoLog_page.dart'; import 'main/lockDetail/videoLog/editVideoLog/editVideoLog_page.dart';

View File

@ -114,6 +114,7 @@ class BlueManage {
// //
if(deviceConnectionState != DeviceConnectionState.connected){ if(deviceConnectionState != DeviceConnectionState.connected){
if(isAddEquipment == false){ if(isAddEquipment == false){
// print("666666666");
startScan(); startScan();
} }
@ -121,6 +122,7 @@ class BlueManage {
stateCallBack(deviceConnectionState!); stateCallBack(deviceConnectionState!);
}); });
}else{ }else{
stopScan();
stateCallBack(deviceConnectionState!); stateCallBack(deviceConnectionState!);
} }
}else{ }else{
@ -137,34 +139,32 @@ class BlueManage {
if (knownDeviceIndex >= 0) { if (knownDeviceIndex >= 0) {
// //
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
stopScan();
} else { } else {
// -1 5 // -1 5
var index = 0; var index = 0;
Completer? completer = Completer(); Completer? completer = Completer();
Timer.periodic(const Duration(seconds: 1), (timer) { Timer.periodic(const Duration(seconds: 1), (timer) async {
/// ///
// print("timer index0:$index"); // print("timer index0:$index");
if(index >= 9){ if(index >= 9){
// 5 // 5
completer.complete();
stopScan();
timer.cancel();
connectDeviceMacAddress = ""; connectDeviceMacAddress = "";
connectStateCallBack(DeviceConnectionState.disconnected);
completer.complete();
await stopScan();
timer.cancel();
// deviceConnectionState = DeviceConnectionState.disconnected; // deviceConnectionState = DeviceConnectionState.disconnected;
// print("timer index1:$index"); // print("timer index1:$index");
connectStateCallBack(DeviceConnectionState.disconnected);
}else{ }else{
// //
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
if (knownDeviceIndex >= 0) { if (knownDeviceIndex >= 0) {
// //
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
completer.complete(); completer.complete();
stopScan();
timer.cancel(); timer.cancel();
// print("timer index2:$index"); // print("timer index2:$index");
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
// var uuidStr = (scanDevices[knownDeviceIndex].serviceUuids.isNotEmpty ? scanDevices[knownDeviceIndex].serviceUuids[0] : "").toString(); // var uuidStr = (scanDevices[knownDeviceIndex].serviceUuids.isNotEmpty ? scanDevices[knownDeviceIndex].serviceUuids[0] : "").toString();
// if(uuidStr[31] == "0"){ // if(uuidStr[31] == "0"){
@ -184,16 +184,17 @@ class BlueManage {
// Completer完成 // Completer完成
await completer.future; await completer.future;
} }
print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName"); print("1 connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName");
await stopScan();
if (connectDeviceMacAddress.isEmpty) { if (connectDeviceMacAddress.isEmpty) {
return; return;
} }
// print("33333333333333333333333");
_currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 5)).listen((connectionStateUpdate) async { _currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 5)).listen((connectionStateUpdate) async {
// //
deviceConnectionState = connectionStateUpdate.connectionState; deviceConnectionState = connectionStateUpdate.connectionState;
print('deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}'); print('2 deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}');
if (connectionStateUpdate.connectionState == DeviceConnectionState.connected) { if (connectionStateUpdate.connectionState == DeviceConnectionState.connected) {
// //
try { try {
@ -326,7 +327,9 @@ class BlueManage {
// //
Future<void> stopScan() async { Future<void> stopScan() async {
// print("444444444");
if(_scanSubscription != null){ if(_scanSubscription != null){
// print("555555555555");
_scanSubscription?.cancel(); _scanSubscription?.cancel();
_scanSubscription = null; _scanSubscription = null;
} }
@ -335,10 +338,11 @@ class BlueManage {
// //
Future<void> disconnect(String deviceMAC) async { Future<void> disconnect(String deviceMAC) async {
try { try {
if(_currentConnectionStream != null){ connectDeviceMacAddress = "";
// if(_currentConnectionStream != null){
_currentConnectionStream?.cancel(); _currentConnectionStream?.cancel();
_currentConnectionStream = null; _currentConnectionStream = null;
} // }
print('disconnecting to device: $deviceMAC'); print('disconnecting to device: $deviceMAC');
} on Exception catch (e, _) { } on Exception catch (e, _) {

View File

@ -501,18 +501,18 @@ class LockSetLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
Get.back(); Get.back();
// if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){ if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
// // //
// // //
// if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
// // //
// factoryDataResetAction(); factoryDataResetAction();
// } else { } else {
// // //
// deletUserAction(); deletUserAction();
// } }
// return; return;
// } }
if (state.currentDeviceUUid.value.isNotEmpty) { if (state.currentDeviceUUid.value.isNotEmpty) {
// //

View File

@ -410,6 +410,8 @@ class LockDetailLogic extends BaseGetXController {
Future<void> openDoorAction(int openMode) async { Future<void> openDoorAction(int openMode) async {
showBlueConnetctToastTimer(action:() { showBlueConnetctToastTimer(action:() {
state.openLockBtnState.value = 0; state.openLockBtnState.value = 0;
BlueManage().stopScan();
// state.animationController.reset(); // state.animationController.reset();
// state.animationController.forward(); // state.animationController.forward();
}); });
@ -578,10 +580,6 @@ class LockDetailLogic extends BaseGetXController {
} }
} }
longPressCloseDoor(){
}
// token // token
void getLockNetToken() async { void getLockNetToken() async {
LockNetTokenEntity entity = await ApiRepository.to LockNetTokenEntity entity = await ApiRepository.to

View File

@ -634,6 +634,8 @@ class _LockDetailPageState extends State<LockDetailPage>
// print("LockDetailPage===didPop"); // print("LockDetailPage===didPop");
state.ifCurrentScreen.value = false; state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer(); logic.cancelBlueConnetctToastTimer();
BlueManage().stopScan();
state.openLockBtnState.value = 0;
state.animationController.reset(); state.animationController.reset();
state.animationController.forward(); state.animationController.forward();
state.animationController.dispose(); state.animationController.dispose();
@ -654,6 +656,8 @@ class _LockDetailPageState extends State<LockDetailPage>
// print("LockDetailPage===didPushNext"); // print("LockDetailPage===didPushNext");
state.ifCurrentScreen.value = false; state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer(); logic.cancelBlueConnetctToastTimer();
BlueManage().stopScan();
state.openLockBtnState.value = 0;
state.animationController.reset(); state.animationController.reset();
state.animationController.forward(); state.animationController.forward();
} }

View File

@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_voice_processor/flutter_voice_processor.dart'; import 'package:flutter_voice_processor/flutter_voice_processor.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.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 'package:star_lock/talk/call/callTalk.dart';
import '../../../../talk/call/g711.dart'; import '../../../../talk/call/g711.dart';
@ -13,6 +12,7 @@ import '../../../../talk/udp/udp_manage.dart';
import '../../../../talk/udp/udp_senderManage.dart'; import '../../../../talk/udp/udp_senderManage.dart';
import '../../../../tools/baseGetXController.dart'; import '../../../../tools/baseGetXController.dart';
import '../../../../tools/eventBusEventManage.dart'; import '../../../../tools/eventBusEventManage.dart';
import 'realTimePicture_state.dart';
class RealTimePictureLogic extends BaseGetXController { class RealTimePictureLogic extends BaseGetXController {
final RealTimePictureState state = RealTimePictureState(); final RealTimePictureState state = RealTimePictureState();

View File

@ -4,11 +4,11 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart';
import '../../../../app_settings/app_colors.dart'; import '../../../../app_settings/app_colors.dart';
import '../../../../tools/showTFView.dart'; import '../../../../tools/showTFView.dart';
import '../../../../tools/toast.dart'; import '../../../../tools/toast.dart';
import 'realTimePicture_logic.dart';
class RealTimePicturePage extends StatefulWidget { class RealTimePicturePage extends StatefulWidget {
const RealTimePicturePage({Key? key}) : super(key: key); const RealTimePicturePage({Key? key}) : super(key: key);