优化蓝牙协议,修复udp开锁流程
This commit is contained in:
parent
396c750e47
commit
5434c89b00
@ -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
|
||||
|
||||
@ -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++;
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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"))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user