优化蓝牙协议,修复udp开锁流程

This commit is contained in:
魏少阳 2024-01-08 11:32:35 +08:00
parent 396c750e47
commit 5434c89b00
15 changed files with 87 additions and 23 deletions

View File

@ -35,6 +35,9 @@ PODS:
- Flutter - Flutter
- camera_avfoundation (0.0.1): - camera_avfoundation (0.0.1):
- Flutter - Flutter
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
- device_info_plus (0.0.1): - device_info_plus (0.0.1):
- Flutter - Flutter
- EMASRest (11.1.1.2) - EMASRest (11.1.1.2)
@ -83,6 +86,7 @@ PODS:
- permission_handler_apple (9.1.1): - permission_handler_apple (9.1.1):
- Flutter - Flutter
- Protobuf (3.25.1) - Protobuf (3.25.1)
- ReachabilitySwift (5.0.0)
- reactive_ble_mobile (0.0.1): - reactive_ble_mobile (0.0.1):
- Flutter - Flutter
- Protobuf (~> 3.5) - Protobuf (~> 3.5)
@ -112,6 +116,7 @@ DEPENDENCIES:
- audioplayers_darwin (from `.symlinks/plugins/audioplayers_darwin/ios`) - audioplayers_darwin (from `.symlinks/plugins/audioplayers_darwin/ios`)
- auto_orientation (from `.symlinks/plugins/auto_orientation/ios`) - auto_orientation (from `.symlinks/plugins/auto_orientation/ios`)
- camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`) - camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`) - Flutter (from `Flutter`)
- flutter_native_contact_picker (from `.symlinks/plugins/flutter_native_contact_picker/ios`) - flutter_native_contact_picker (from `.symlinks/plugins/flutter_native_contact_picker/ios`)
@ -152,6 +157,7 @@ SPEC REPOS:
- GoogleMaps - GoogleMaps
- ios-voice-processor - ios-voice-processor
- Protobuf - Protobuf
- ReachabilitySwift
- SwiftProtobuf - SwiftProtobuf
- Toast - Toast
@ -172,6 +178,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/auto_orientation/ios" :path: ".symlinks/plugins/auto_orientation/ios"
camera_avfoundation: camera_avfoundation:
:path: ".symlinks/plugins/camera_avfoundation/ios" :path: ".symlinks/plugins/camera_avfoundation/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
device_info_plus: device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios" :path: ".symlinks/plugins/device_info_plus/ios"
Flutter: Flutter:
@ -234,6 +242,7 @@ SPEC CHECKSUMS:
audioplayers_darwin: 877d9a4d06331c5c374595e46e16453ac7eafa40 audioplayers_darwin: 877d9a4d06331c5c374595e46e16453ac7eafa40
auto_orientation: 102ed811a5938d52c86520ddd7ecd3a126b5d39d auto_orientation: 102ed811a5938d52c86520ddd7ecd3a126b5d39d
camera_avfoundation: 3125e8cd1a4387f6f31c6c63abb8a55892a9eeeb camera_avfoundation: 3125e8cd1a4387f6f31c6c63abb8a55892a9eeeb
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
EMASRest: 8df6f87836767a9415ad5cc4af739bc9d215b475 EMASRest: 8df6f87836767a9415ad5cc4af739bc9d215b475
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
@ -256,6 +265,7 @@ SPEC CHECKSUMS:
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
Protobuf: d94761c33f1239c0a43a0817ca1a5f7f7c900241 Protobuf: d94761c33f1239c0a43a0817ca1a5f7f7c900241
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:get/get.dart';
import 'io_tool/io_model.dart'; import 'io_tool/io_model.dart';
import 'io_tool/io_tool.dart'; import 'io_tool/io_tool.dart';
@ -120,7 +121,7 @@ class BlueManage {
// -1 5 // -1 5
var index = 0; var index = 0;
Completer? completer = Completer(); Completer? completer = Completer();
Timer.periodic(const Duration(milliseconds: 1000), (timer) { Timer.periodic(const Duration(seconds: 1), (timer) {
/// ///
// print("timer index0:$index"); // print("timer index0:$index");
if(index >= 9){ if(index >= 9){
@ -135,6 +136,7 @@ class BlueManage {
}else{ }else{
// //
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
if (knownDeviceIndex >= 0) { if (knownDeviceIndex >= 0) {
// //
completer.complete(); completer.complete();
@ -142,6 +144,15 @@ class BlueManage {
timer.cancel(); timer.cancel();
// print("timer index2:$index"); // print("timer index2:$index");
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
// var uuidStr = (scanDevices[knownDeviceIndex].serviceUuids.isNotEmpty ? scanDevices[knownDeviceIndex].serviceUuids[0] : "").toString();
// if(uuidStr[31] == "0"){
// //
// EasyLoading.showToast("当前设备已被清除配对,请删除后重新添加", duration: 2000.milliseconds);
// Future.delayed(2100.milliseconds);
// connectStateCallBack(DeviceConnectionState.disconnected);
// return;
// }
} else { } else {
// -1 5 // -1 5
index++; index++;

View File

@ -502,7 +502,7 @@ class LockSetLogic extends BaseGetXController {
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) {
// //
@ -514,9 +514,8 @@ class LockSetLogic extends BaseGetXController {
return; return;
} }
//
if (state.currentDeviceUUid.value.isNotEmpty) { if (state.currentDeviceUUid.value.isNotEmpty) {
// //
BlueManage().stopScan(); BlueManage().stopScan();
deletLockLogic(); deletLockLogic();
} else { } else {
@ -524,9 +523,8 @@ class LockSetLogic extends BaseGetXController {
var index = 0; var index = 0;
showEasyLoading(); showEasyLoading();
state.deletWaitScanCompleter = Completer(); state.deletWaitScanCompleter = Completer();
state.deletWaitScanTimer = Timer.periodic(const Duration(milliseconds: 1000), (timer) { state.deletWaitScanTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
/// //
// print("timer index0:$index");
if(index >= 5){ if(index >= 5){
// 10, // 10,
if(state.deletWaitScanTimer != null){ if(state.deletWaitScanTimer != null){
@ -550,11 +548,12 @@ class LockSetLogic extends BaseGetXController {
} }
BlueManage().stopScan(); BlueManage().stopScan();
dismissEasyLoading(); dismissEasyLoading();
deletLockLogic(); deletLockLogic();
} else { } else {
// -1 5 // -1 5
index++; index++;
print("index:$index"); // print("index:$index");
} }
} }
}); });

View File

@ -101,7 +101,7 @@ class LockMonitoringLogic extends BaseGetXController {
} }
/// ///
udpOpenDoorAction() async { udpOpenDoorAction(List<int> list) async {
UDPSenderManage.sendMainProtocol( UDPSenderManage.sendMainProtocol(
command: 150, command: 150,
commandTypeIsCalling: 1, commandTypeIsCalling: 1,
@ -110,7 +110,7 @@ class LockMonitoringLogic extends BaseGetXController {
lockIP: UDPManage().host, lockIP: UDPManage().host,
userMobile: await state.userMobile, userMobile: await state.userMobile,
userMobileIP: await state.userMobileIP, userMobileIP: await state.userMobileIP,
endData: []); endData: list);
Get.back(); Get.back();
} }

View File

@ -274,8 +274,9 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
return; return;
} }
List<int> numbers = state.passwordTF.text.split('').map((char) => int.parse(char)).toList();
// //
logic.udpOpenDoorAction(); logic.udpOpenDoorAction(numbers);
}, },
cancelClick: () { cancelClick: () {
Get.back(); Get.back();

View File

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:star_lock/talk/udp/udp_senderManage.dart'; import 'package:star_lock/talk/udp/udp_senderManage.dart';
@ -109,6 +110,36 @@ class LockMainLogic extends BaseGetXController {
}); });
} }
///
void getConnectType() async {
var connectResult = await (Connectivity().checkConnectivity());
if (connectResult == ConnectivityResult.mobile) {
// _netType = "4G";
print("4G 4G 4G 4G 4G");
} else if (connectResult == ConnectivityResult.wifi) {
// _netType = "wifi";
print("wifi wifi wifi wifi wifi");
} else {
// _netType = "未连接";
print("未连接 未连接 未连接 未连接 未连接");
}
}
///
Future<bool> isConnected() async {
var connectResult = await (Connectivity().checkConnectivity());
return connectResult != ConnectivityResult.none;
}
///
connectListener() async {
Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
print("设置网络切换监听:$result");
});
}
@override @override
void onReady() { void onReady() {
// TODO: implement onReady // TODO: implement onReady
@ -128,6 +159,11 @@ class LockMainLogic extends BaseGetXController {
print("onInit()"); print("onInit()");
// getLockInfo(); // getLockInfo();
//
// connectListener();
//
// getConnectType();
getStarLockInfo(); getStarLockInfo();
} }

View File

@ -38,7 +38,7 @@ class _AbountPageState extends State<AbountPage> {
), ),
SizedBox(height: 20.h), SizedBox(height: 20.h),
Text( Text(
"星锁 1.0.0.03(preRelease-20231216)", "星锁 1.0.0.03(preRelease-20240108)",
style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor), style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
), ),
SizedBox( SizedBox(

View File

@ -8,6 +8,7 @@ import 'package:star_lock/tools/storage.dart';
import '../../../../network/api_repository.dart'; import '../../../../network/api_repository.dart';
import '../../../../tools/baseGetXController.dart'; import '../../../../tools/baseGetXController.dart';
import '../../../blue/blue_manage.dart'; import '../../../blue/blue_manage.dart';
import '../../../talk/udp/udp_help.dart';
import '../../../tools/eventBusEventManage.dart'; import '../../../tools/eventBusEventManage.dart';
import '../../../tools/toast.dart'; import '../../../tools/toast.dart';
@ -52,6 +53,7 @@ class MineSetLogic extends BaseGetXController {
Future<void> userLogoutRequest() async { Future<void> userLogoutRequest() async {
LoginEntity entity = await ApiRepository.to.userLogout(); LoginEntity entity = await ApiRepository.to.userLogout();
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
UdpHelp().closeUDP();
logOut(); logOut();
// BlueManage().stopScan(); // BlueManage().stopScan();
BlueManage().disconnect(BlueManage().connectDeviceMacAddress); BlueManage().disconnect(BlueManage().connectDeviceMacAddress);

View File

@ -153,7 +153,7 @@ class CallTalk {
// //
void stopPcmSound() { void stopPcmSound() {
FlutterPcmSound.setup(sampleRate: 8000, channelCount: 1); // FlutterPcmSound.setup(sampleRate: 8000, channelCount: 1);
FlutterPcmSound.pause(); FlutterPcmSound.pause();
FlutterPcmSound.clear(); FlutterPcmSound.clear();
FlutterPcmSound.stop(); FlutterPcmSound.stop();

View File

@ -9,7 +9,7 @@ import 'udp_manage.dart';
import 'udp_senderManage.dart'; import 'udp_senderManage.dart';
class UdpHelp { class UdpHelp {
Timer? timer; Timer? udpHeartTimer;
openUDP() async { openUDP() async {
// ip跟端口 // ip跟端口
@ -42,7 +42,7 @@ class UdpHelp {
} }
var mobile = await Storage.getMobile(); var mobile = await Storage.getMobile();
timer = Timer.periodic(1.seconds, (timer) async { udpHeartTimer = Timer.periodic(1.seconds, (timer) async {
UDPSenderManage.sendHeart( UDPSenderManage.sendHeart(
userName: mobile, userName: mobile,
ipList: serversList, ipList: serversList,
@ -52,15 +52,12 @@ class UdpHelp {
} }
} }
// Future<void> getWifiLockServiceIpAndPort() async { void closeUDP() {
// var entity = await ApiRepository.to.getWifiLockServiceIpAndPort(); udpHeartTimer!.cancel();
// if(entity.errorCode! == 0){ }
//
// }
// }
dispose() { dispose() {
timer!.cancel(); udpHeartTimer!.cancel();
} }
} }

View File

@ -58,7 +58,7 @@ class BaseGetXController extends GetxController{
_timer!.cancel(); _timer!.cancel();
_timer = null; _timer = null;
} }
_timer = Timer.periodic(10.seconds, (timer) { _timer = Timer.periodic(15.seconds, (timer) {
if(action != null) { if(action != null) {
action(); action();
} }

View File

@ -8,6 +8,7 @@ import Foundation
import aj_captcha_flutter import aj_captcha_flutter
import audio_session import audio_session
import audioplayers_darwin import audioplayers_darwin
import connectivity_plus
import device_info_plus import device_info_plus
import file_selector_macos import file_selector_macos
import flutter_pcm_sound import flutter_pcm_sound
@ -23,6 +24,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AjCaptchaFlutterPlugin.register(with: registry.registrar(forPlugin: "AjCaptchaFlutterPlugin")) AjCaptchaFlutterPlugin.register(with: registry.registrar(forPlugin: "AjCaptchaFlutterPlugin"))
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterPcmSoundPlugin.register(with: registry.registrar(forPlugin: "FlutterPcmSoundPlugin")) FlutterPcmSoundPlugin.register(with: registry.registrar(forPlugin: "FlutterPcmSoundPlugin"))

View File

@ -132,6 +132,8 @@ dependencies:
# flutter_audio_capture: <1.1.5 # flutter_audio_capture: <1.1.5
flutter_voice_processor: ^1.1.0 flutter_voice_processor: ^1.1.0
#监听网络连接状态
connectivity_plus: ^5.0.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter

View File

@ -8,6 +8,7 @@
#include <aj_captcha_flutter/aj_captcha_flutter_plugin_c_api.h> #include <aj_captcha_flutter/aj_captcha_flutter_plugin_c_api.h>
#include <audioplayers_windows/audioplayers_windows_plugin.h> #include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h> #include <file_selector_windows/file_selector_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h> #include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
@ -17,6 +18,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("AjCaptchaFlutterPluginCApi")); registry->GetRegistrarForPlugin("AjCaptchaFlutterPluginCApi"));
AudioplayersWindowsPluginRegisterWithRegistrar( AudioplayersWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin")); registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
FileSelectorWindowsRegisterWithRegistrar( FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows")); registry->GetRegistrarForPlugin("FileSelectorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar( PermissionHandlerWindowsPluginRegisterWithRegistrar(

View File

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
aj_captcha_flutter aj_captcha_flutter
audioplayers_windows audioplayers_windows
connectivity_plus
file_selector_windows file_selector_windows
permission_handler_windows permission_handler_windows
url_launcher_windows url_launcher_windows