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

View File

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

View File

@ -502,7 +502,7 @@ class LockSetLogic extends BaseGetXController {
Get.back();
if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
//
//
//
if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
//
@ -514,9 +514,8 @@ class LockSetLogic extends BaseGetXController {
return;
}
//
if (state.currentDeviceUUid.value.isNotEmpty) {
//
//
BlueManage().stopScan();
deletLockLogic();
} else {
@ -524,9 +523,8 @@ class LockSetLogic extends BaseGetXController {
var index = 0;
showEasyLoading();
state.deletWaitScanCompleter = Completer();
state.deletWaitScanTimer = Timer.periodic(const Duration(milliseconds: 1000), (timer) {
///
// print("timer index0:$index");
state.deletWaitScanTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
//
if(index >= 5){
// 10,
if(state.deletWaitScanTimer != null){
@ -550,11 +548,12 @@ class LockSetLogic extends BaseGetXController {
}
BlueManage().stopScan();
dismissEasyLoading();
deletLockLogic();
} else {
// -1 5
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(
command: 150,
commandTypeIsCalling: 1,
@ -110,7 +110,7 @@ class LockMonitoringLogic extends BaseGetXController {
lockIP: UDPManage().host,
userMobile: await state.userMobile,
userMobileIP: await state.userMobileIP,
endData: []);
endData: list);
Get.back();
}

View File

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

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.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
void onReady() {
// TODO: implement onReady
@ -128,6 +159,11 @@ class LockMainLogic extends BaseGetXController {
print("onInit()");
// getLockInfo();
//
// connectListener();
//
// getConnectType();
getStarLockInfo();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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