优化蓝牙通信,蓝牙发送数据无反应

This commit is contained in:
魏少阳 2024-01-04 18:27:50 +08:00
parent db5ab63e55
commit 2076278df5
35 changed files with 182 additions and 129 deletions

View File

@ -16,13 +16,13 @@ class BlueManage {
final List<DiscoveredDevice> scanDevices = [];
// id
Uuid serviceIdConnect = Uuid.parse("fff0");
final Uuid _serviceIdConnect = Uuid.parse("fff0");
// id
Uuid serviceIdWrite = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB');
final Uuid _serviceIdWrite = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB');
// id
Uuid characteristicIdSubscription = Uuid.parse("fff1");
final Uuid _characteristicIdSubscription = Uuid.parse("fff1");
// id
Uuid characteristicIdWrite = Uuid.parse("fff2");
final Uuid _characteristicIdWrite = Uuid.parse("fff2");
//
StreamSubscription<EventSendModel>? _sendStreamSubscription;
@ -36,8 +36,7 @@ class BlueManage {
// mac地址
String connectDeviceMacAddress = "";
//
DeviceConnectionState? deviceConnectionState =
DeviceConnectionState.disconnected;
DeviceConnectionState? deviceConnectionState = DeviceConnectionState.disconnected;
static BlueManage? _manager;
BlueManage._init();
@ -92,7 +91,7 @@ class BlueManage {
}
///
Future<void> judgeReconnect(String deviceName, ConnectStateCallBack stateCallBack) async {
Future<void> bludSendData(String deviceName, ConnectStateCallBack stateCallBack) async {
if(deviceConnectionState != DeviceConnectionState.connected){
_connect(deviceName, (state){
stateCallBack(deviceConnectionState!);
@ -117,7 +116,7 @@ class BlueManage {
Timer.periodic(const Duration(milliseconds: 1000), (timer) {
///
// print("timer index0:$index");
if(index >= 5){
if(index >= 4){
// 5
completer.complete();
timer.cancel();
@ -127,8 +126,7 @@ class BlueManage {
connectStateCallBack(DeviceConnectionState.disconnected);
}else{
//
final knownDeviceIndex =
scanDevices.indexWhere((d) => d.name == deviceName);
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
if (knownDeviceIndex >= 0) {
//
completer.complete();
@ -138,7 +136,7 @@ class BlueManage {
} else {
// -1 5
index++;
print("index:$index 没有找到设备");
print("index:$index");
}
}
});
@ -158,7 +156,7 @@ class BlueManage {
if (connectionStateUpdate.connectionState == DeviceConnectionState.connected) {
//
try {
_subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: serviceIdConnect, deviceId: connectDeviceMacAddress));
_subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: _characteristicIdSubscription, serviceId: _serviceIdConnect, deviceId: connectDeviceMacAddress));
print('Discovering services finished');
deviceConnectionState = connectionStateUpdate.connectionState;
@ -225,7 +223,7 @@ class BlueManage {
//
Future<void> writeCharacteristicWithResponse(List<int> value) async {
QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceIdWrite, deviceId: connectDeviceMacAddress);
QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: _characteristicIdWrite, serviceId: _serviceIdWrite, deviceId: connectDeviceMacAddress);
int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250);
print("mtuLength:$mtuLength");
try {

View File

@ -50,7 +50,7 @@ class MyApp extends StatefulWidget {
}
// RouteObserver navigation observer.
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
// final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
final _aliyunPush = AliyunPush();
@ -68,7 +68,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
GetMaterialApp _initMaterialApp() => GetMaterialApp(
title: 'Star Lock',
navigatorObservers: [routeObserver, AppRouteObserver().routeObserver],
navigatorObservers: [AppRouteObserver().routeObserver],
translations: TranslationMessage(),
supportedLocales: appDept.deptSupportedLocales,
localizationsDelegates: const [
@ -233,3 +233,4 @@ Future<bool> getMicrophonePermission() async {
}
return false;
}

View File

@ -163,7 +163,7 @@ class AuthorizedAdminLogic extends BaseGetXController {
//
Future<void> transferPermissionsAction() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -192,7 +192,7 @@ class AuthorizedAdminLogic extends BaseGetXController {
//
Future<void> addUserConnectBlue(String receiveId) async {
//
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connecteState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connecteState) async {
if (connecteState == DeviceConnectionState.connected) {
//
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -214,7 +214,7 @@ class AddICCardLogic extends BaseGetXController{
//
Future<void> senderAddICCard() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
@ -241,7 +241,7 @@ class AddICCardLogic extends BaseGetXController{
token: getTokenList,
);
} else if (deviceConnectionState == DeviceConnectionState.disconnected){
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
showBlueConnetctToast();
Get.close(2);
}
});
@ -249,7 +249,7 @@ class AddICCardLogic extends BaseGetXController{
//
Future<void> senderAddStressICCard() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -88,7 +88,7 @@ class CardDetailLogic extends BaseGetXController{
//
Future<void> senderAddICCard() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -205,7 +205,7 @@ class CardListLogic extends BaseGetXController {
//
Future<void> senderCheckingCardStatus() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -233,7 +233,7 @@ class CardListLogic extends BaseGetXController {
// ()
Future<void> senderCheckingUserInfoCount() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -260,7 +260,7 @@ class CardListLogic extends BaseGetXController {
//
Future<void> senderAddICCard() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -252,7 +252,7 @@ class AddFingerprintLogic extends BaseGetXController {
//
Future<void> senderAddFingerprint() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
// print("66666666:$deviceConnectionState");
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
@ -280,7 +280,7 @@ class AddFingerprintLogic extends BaseGetXController {
token: getTokenList,
);
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
showBlueConnetctToast();
Get.close(2);
}
});
@ -288,7 +288,7 @@ class AddFingerprintLogic extends BaseGetXController {
//
Future<void> senderAddStressFingerprint() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -89,7 +89,7 @@ class FingerprintDetailLogic extends BaseGetXController{
//
Future<void> senderAddFingerprint() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -238,7 +238,7 @@ class FingerprintListLogic extends BaseGetXController{
}
//
Future<void> senderQueryingFingerprintStatus() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName,(DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName,(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -266,7 +266,7 @@ class FingerprintListLogic extends BaseGetXController{
// ()
Future<void> senderCheckingUserInfoCount() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -293,7 +293,7 @@ class FingerprintListLogic extends BaseGetXController{
//
Future<void> senderAddFingerprint() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected){
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -128,7 +128,7 @@ class AutomaticBlockingLogic extends BaseGetXController{
// -
Future<void> _readSupportFunctionsWithParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -155,7 +155,7 @@ class AutomaticBlockingLogic extends BaseGetXController{
// ()
Future<void> sendAutoLock() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -13,7 +13,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
// -
Future<void> _readAdminPassword() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -7,7 +7,7 @@ class BasicInformationLogic extends BaseGetXController{
// -
// Future<void> _readAdminPassword() async {
// BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -112,7 +112,7 @@ class BurglarAlarmLogic extends BaseGetXController{
// -
Future<void> _readSupportFunctionsNoParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -139,7 +139,7 @@ class BurglarAlarmLogic extends BaseGetXController{
// ()
Future<void> sendBurglarAlarm() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -144,7 +144,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
// wifi
Future<void> senderConfiguringWifiAction() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected){
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -257,7 +257,9 @@ class LockSetLogic extends BaseGetXController {
//
Future<void> deletUserAction() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
showBlueConnetctToastTimer();
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
cancelBlueConnetctToastTimer();
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
@ -291,7 +293,9 @@ class LockSetLogic extends BaseGetXController {
//
Future<void> factoryDataResetAction() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
showBlueConnetctToastTimer();
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
cancelBlueConnetctToastTimer();
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
@ -320,7 +324,7 @@ class LockSetLogic extends BaseGetXController {
// -
// Future<void> _readSupportFunctionsNoParameters(int type) async {
// BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -347,7 +351,9 @@ class LockSetLogic extends BaseGetXController {
// ()
Future<void> sendBurglarAlarm(int type) async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
showBlueConnetctToastTimer();
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
cancelBlueConnetctToastTimer();
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
@ -614,7 +620,6 @@ class LockSetLogic extends BaseGetXController {
void onReady() {
// TODO: implement onReady
super.onReady();
print("onReady()");
getLockSettingInfoData();
@ -626,12 +631,12 @@ class LockSetLogic extends BaseGetXController {
void onInit() {
// TODO: implement onInit
super.onInit();
print("onInit()");
}
@override
void onClose() {
// TODO: implement onClose
_replySubscription.cancel();
_passCurrentLockInformationEvent!.cancel();
_scanListDiscoveredDeviceSubscription.cancel();

View File

@ -5,6 +5,7 @@ import 'package:get/get.dart';
import '../../../../appRouters.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../main.dart';
import '../../../../tools/appRouteObserver.dart';
import '../../../../tools/commonItem.dart';
@ -15,6 +16,7 @@ import '../../../../tools/toast.dart';
import '../../../../translations/trans_lib.dart';
import 'lockSet_logic.dart';
// final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
class LockSetPage extends StatefulWidget {
const LockSetPage({Key? key}) : super(key: key);
@ -782,7 +784,6 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
// },
// );
// }
@override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
@ -800,27 +801,33 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
super.dispose();
}
///
///
@override
void didPush() {
super.didPush();
print("lockSet===didPush");
}
///
///
@override
void didPop() {
super.didPop();
print("lockSet===didPop");
logic.cancelBlueConnetctToastTimer();
}
///
///
@override
void didPopNext() {
super.didPopNext();
print("lockSet===didPopNext");
}
///
///
@override
void didPushNext() {
super.didPushNext();
print("lockSet===didPushNext");
logic.cancelBlueConnetctToastTimer();
}
}

View File

@ -120,7 +120,7 @@ class LockSoundSetLogic extends BaseGetXController {
// -
Future<void> _readSupportFunctionsWithParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -147,7 +147,7 @@ class LockSoundSetLogic extends BaseGetXController {
// ()
Future<void> sendLockSound() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -131,7 +131,7 @@ class LockTimeLogic extends BaseGetXController{
//
// Future<void> _getLockStatus() async {
// //
// BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// if (state == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -147,7 +147,7 @@ class LockTimeLogic extends BaseGetXController{
//
Future<void> sendTiming() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -111,7 +111,7 @@ class MotorPowerLogic extends BaseGetXController {
// -
Future<void> _readSupportFunctionsNoParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -137,7 +137,7 @@ class MotorPowerLogic extends BaseGetXController {
// ()
Future<void> sendOpenDoorDirection() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -139,7 +139,7 @@ class NormallyOpenModeLogic extends BaseGetXController{
// -
Future<void> _readSupportFunctionsWithParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -166,7 +166,7 @@ class NormallyOpenModeLogic extends BaseGetXController{
// ()
Future<void> sendAutoLock() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -113,7 +113,7 @@ class OpenDoorDirectionLogic extends BaseGetXController {
// -
Future<void> _readSupportFunctionsNoParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -140,7 +140,7 @@ class OpenDoorDirectionLogic extends BaseGetXController {
// ()
Future<void> sendOpenDoorDirection() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
dismissEasyLoading();
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -112,7 +112,7 @@ class RemoteUnlockingLogic extends BaseGetXController{
// -
Future<void> _readSupportFunctionsNoParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -139,7 +139,7 @@ class RemoteUnlockingLogic extends BaseGetXController{
// ()
Future<void> sendBurglarAlarm() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -114,7 +114,7 @@ class ResetButtonLogic extends BaseGetXController{
// -
Future<void> _readSupportFunctionsNoParameters() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -141,7 +141,7 @@ class ResetButtonLogic extends BaseGetXController{
// ()
Future<void> sendBurglarAlarm() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);

View File

@ -78,7 +78,7 @@ class LockDetailLogic extends BaseGetXController {
state.electricQuantity.value = power;
getLockRecordLastUploadDataTime();
state.lockState.value = 2;
state.openLockBtnState.value = 0;
state.animationController.reset();
state.animationController.forward();
// state.animationController.isCompleted;
@ -345,8 +345,13 @@ class LockDetailLogic extends BaseGetXController {
//
Future<void> openDoorAction() async {
BlueManage().judgeReconnect(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
showBlueConnetctToastTimer();
BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
cancelBlueConnetctToastTimer();
if (deviceConnectionState == DeviceConnectionState.connected){
state.connectState.value = 1;
state.openLockBtnState.value = 0;
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -369,11 +374,12 @@ class LockDetailLogic extends BaseGetXController {
privateKey: getPrivateKeyList,
);
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
if(state.lockState.value != 2){
// 2 toast
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
}
state.lockState.value = 4;
// if(state.lockState.value != 2){
// // 2 toast
showBlueConnetctToast();
// }
state.connectState.value = 0;
state.openLockBtnState.value = 0;
state.animationController.reset();
state.animationController.forward();
}
@ -382,7 +388,7 @@ class LockDetailLogic extends BaseGetXController {
//
// Future<void> editLockUserAction() async {
// BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// if (state == DeviceConnectionState.connected){
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
@ -442,7 +448,7 @@ class LockDetailLogic extends BaseGetXController {
// ()
Future<void> senderReferEventRecordTime(int time) async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName,
BlueManage().bludSendData(BlueManage().connectDeviceName,
(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
@ -472,7 +478,7 @@ class LockDetailLogic extends BaseGetXController {
// ()
Future<void> addUserConnectBlue() async {
//
BlueManage().judgeReconnect(BlueManage().connectDeviceName,
BlueManage().bludSendData(BlueManage().connectDeviceName,
(DeviceConnectionState deviceConnectionState) async {
if (deviceConnectionState == DeviceConnectionState.connected) {
//
@ -508,15 +514,15 @@ class LockDetailLogic extends BaseGetXController {
});
}
//
startConnect() {
if(state.lockState.value == 4){
// 4
state.lockState.value = 3;
}else{
//
startOpenLock() {
// if(state.lockState.value == 4){
// // 4
// state.lockState.value = 3;
// }else{
//
state.lockState.value = 1;
}
state.openLockBtnState.value = 1;
// }
state.animationController.forward();
if (state.lockUserNo == 0) {
@ -533,6 +539,10 @@ class LockDetailLogic extends BaseGetXController {
}
}
longPressCloseDoor(){
}
// token
void getLockNetToken() async {
LockNetTokenEntity entity = await ApiRepository.to
@ -581,11 +591,11 @@ class LockDetailLogic extends BaseGetXController {
// connectBlueAndAnimationController(){
// state.lockState.value = 1;
// state.animationController.forward();
// BlueManage().judgeReconnect(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
// BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
// if (deviceConnectionState == DeviceConnectionState.connected){
// state.lockState.value = 2;
// }else if (deviceConnectionState == DeviceConnectionState.disconnected){
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
// showBlueConnetctToast();
//
// state.lockState.value = 4;
// state.animationController.reset();
@ -597,7 +607,7 @@ class LockDetailLogic extends BaseGetXController {
///
StreamSubscription?
_lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent;
void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
void _initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
// eventBus
_lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent = eventBus
.on<LockSetChangeSetRefreshLockDetailWithType>()
@ -621,8 +631,7 @@ class LockDetailLogic extends BaseGetXController {
print("onReady()");
_initReplySubscription();
initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction();
_initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction();
}
@override

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
@ -8,8 +7,8 @@ import '../../../appRouters.dart';
import '../../../app_settings/app_colors.dart';
import '../../../blue/blue_manage.dart';
import '../../../blue/io_tool/io_tool.dart';
import '../../../tools/appRouteObserver.dart';
import '../../../tools/storage.dart';
import '../../../tools/toast.dart';
import '../../../translations/trans_lib.dart';
import '../../lockMian/entity/lockListInfo_entity.dart';
import 'lockDetail_logic.dart';
@ -44,25 +43,19 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
state.isOpenLockNeedOnline.value = state.keyInfos.value.lockSetting!.appUnlockOnline!;
state.electricQuantity.value = state.keyInfos.value.electricQuantity!;
BlueManage().connectDeviceName =
state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
// BlueManage().connectDeviceMacAddress =
// state.keyInfos.value.bluetooth!.bluetoothDeviceId!;
BlueManage().connectDeviceName = state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
List<int> publicKeyData =
state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
List<int> publicKeyData = state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
var saveStrList = changeIntListToStringList(publicKeyData);
Storage.setStringList(saveBluePublicKey, saveStrList);
//
List<int> privateKeyData =
state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
List<int> privateKeyData = state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
var savePrivateKeyList = changeIntListToStringList(privateKeyData);
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
// signKey
List<int> signKeyData =
state.keyInfos.value.bluetooth!.signKey!.cast<int>();
List<int> signKeyData = state.keyInfos.value.bluetooth!.signKey!.cast<int>();
var saveSignKeyList = changeIntListToStringList(signKeyData);
Storage.setStringList(saveBlueSignKey, saveSignKeyList);
@ -124,14 +117,14 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
children: [
Center(
child: GestureDetector(
child: Obx(() => Stack(
child: Obx(() => Stack(
children: [
Image.asset(
(state.lockState.value == 4 || state.lockState.value == 3) ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png',
state.connectState.value == 0 ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png',
width: 330.w,
height: 330.w,
),
(state.lockState.value == 1 || state.lockState.value == 3)
state.openLockBtnState.value == 1
? buildRotationTransition()
: Positioned(
child: Image.asset(
@ -141,9 +134,14 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
)),
],
)),
onTap: () {
logic.startConnect();
},
onTap: () {
Get.log("点击开锁");
logic.startOpenLock();
},
onLongPressStart: (details) {
Get.log("长按开锁");
// logic.startConnect();
},
)),
],
),
@ -503,33 +501,41 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
void dispose() {
// TODO: implement dispose
///
// AppRouteObserver().routeObserver.unsubscribe(this);
AppRouteObserver().routeObserver.unsubscribe(this);
state.animationController.dispose();
super.dispose();
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
}
///
///
@override
void didPush() {
print("LockDetailPage didPush");
super.didPush();
print("LockDetailPage===didPush");
}
/// Called when the current route has been popped off.
///
@override
void didPop() {
print("LockDetailPage didPop");
super.didPop();
print("LockDetailPage===didPop");
logic.cancelBlueConnetctToastTimer();
}
/// Called when the current route has been popped off.
///
@override
void didPopNext() {
print("LockDetailPage didPopNext");
super.didPopNext();
print("LockDetailPage===didPopNext");
}
/// Called when the current route has been popped off.
///
@override
void didPushNext() {
print("LockDetailPage didPushNext");
super.didPushNext();
print("LockDetailPage===didPushNext");
logic.cancelBlueConnetctToastTimer();
}
}

View File

@ -24,7 +24,11 @@ class LockDetailState {
var isOpenLockNeedOnline = 0.obs; // APP开锁时是否需联网
var electricQuantity = 0.obs; //
var currentDeviceUUid = "".obs;// uuid
//
late AnimationController animationController;
var lockState = 0.obs;// 0 1() 2 3 4 5
// var lockState = 0.obs;// 0 1() 2 3 4 5
var openLockBtnState = 0.obs;// 0() 1()
var connectState = 0.obs;// 0 1
}

View File

@ -132,7 +132,7 @@ class LockOperatingRecordLogic extends BaseGetXController{
// ()
// Future<void> senderReferEventRecordNumber() async {
// BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// if (state == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -159,7 +159,7 @@ class LockOperatingRecordLogic extends BaseGetXController{
// ()
Future<void> senderReferEventRecordTime(int time) async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -149,11 +149,9 @@ class LockMonitoringLogic extends BaseGetXController {
Future<void> startProcessing() async {
frameListener(List<int> frame) async {
// Get.log('Get data.length:${frame.length} Received data:$frame');
for (int i = 0; i < frame.length; i++) {
frame[i] = linearToULaw(frame[i]);
}
// Get.log('change Get data.length:${frame.length} change Received data:$frame');
await Future.delayed(const Duration(milliseconds: 50));
sendRecordData({
"bytes": frame,

View File

@ -223,7 +223,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
//
Future<void> senderCustomPasswords() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -67,7 +67,7 @@ class _LockAddressPageState extends State<LockAddressPage> with RouteAware{
void didChangeDependencies() {
super.didChangeDependencies();
// routeObserver RouteAware
routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
// routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
}
@override

View File

@ -28,7 +28,7 @@ class NearbyLockLogic extends BaseGetXController {
//
void connect(String deviceName){
showEasyLoading();
BlueManage().judgeReconnect(deviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(deviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
IoSenderManage.getPublicKey(lockId: deviceName);
}else if (state == DeviceConnectionState.disconnected) {
@ -322,7 +322,7 @@ class NearbyLockLogic extends BaseGetXController {
Future<void> _getStarLockStatus() async {
// print("connectDeviceMacAddress:${BlueManage().connectDeviceMacAddress} connectDeviceName:${BlueManage().connectDeviceName}");
//
BlueManage().judgeReconnect(BlueManage().connectDeviceName,
BlueManage().bludSendData(BlueManage().connectDeviceName,
(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
dismissEasyLoading();

View File

@ -106,7 +106,7 @@ class SaveLockLogic extends BaseGetXController {
// print("111111");
//
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// print("222222");
if (state == DeviceConnectionState.connected){
// print("333333");

View File

@ -1,6 +1,6 @@
abstract class Api {
// static String baseAddress = "https://pre.lock.star-lock.cn:8093"; //
static String baseAddress = "http://192.168.56.101:8099"; //
static String baseAddress = "https://pre.lock.star-lock.cn:8093"; //
// static String baseAddress = "http://192.168.56.101:8099"; //
// static String baseAddress = "http://192.168.1.15:8022"; //
final String baseUrl = "$baseAddress/api";

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:async/async.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart';
@ -44,9 +45,9 @@ class BaseGetXController extends GetxController{
Get.log('onClose -----> $runtimeType');
}
operationFailedCallBack(e){
showOperationFailed();
}
// operationFailedCallBack(e){
// showOperationFailed();
// }
Future delay({Duration? duration,Function? something}) => Future.delayed(duration ?? 500. milliseconds,something as FutureOr Function()?);
@ -54,8 +55,31 @@ class BaseGetXController extends GetxController{
void dismissEasyLoading() => EasyLoading.dismiss();
Timer? _timer;
// CancelableOperation? _operation;
void showBlueConnetctToastTimer() {
if(_timer != null && _timer!.isActive){
_timer!.cancel();
}
_timer = Timer.periodic(15.seconds, (timer) {
showBlueConnetctToast();
});
// _operation = CancelableOperation.fromFuture(
// Future.delayed(const Duration(seconds: 15), () {
// print('Operation completed');
// showBlueConnetctToast();
// }),
// );
}
void cancelBlueConnetctToastTimer() {
Get.log('cancelBlueConnetctToastTimer');
if(_timer != null && _timer!.isActive) _timer!.cancel();
// _operation?.cancel();
}
void showBlueConnetctToast() {
showToast("未扫描到要连接的设备,请确保在设备附近,设备未被连接,设备已打开");
showToast("连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
}
void showToast(String status,{Function? something}) {

View File

@ -38,6 +38,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
async: ^2.8.2
# 常用工具类
flustars: ^2.0.1
# 提示