优化蓝牙协议

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/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';

View File

@ -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, _) {

View File

@ -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) {
//

View File

@ -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

View File

@ -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();
}

View File

@ -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();

View File

@ -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);