Merge branch 'release_hyx' into release

This commit is contained in:
anfe 2024-05-27 17:43:55 +08:00
commit a085a0d7f7
5 changed files with 144 additions and 53 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/tools/commonDataManage.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';
@ -17,12 +18,12 @@ typedef ConnectStateCallBack = Function(
typedef ScanDevicesCallBack = Function(List<ScanResult>); typedef ScanDevicesCallBack = Function(List<ScanResult>);
class BlueManage { class BlueManage {
factory BlueManage() => shareManager()!; factory BlueManage() => shareManager()!;
BlueManage._init() { BlueManage._init() {
_initBlue(); _initBlue();
} }
final List<ScanResult> scanDevices = <ScanResult>[]; final List<ScanResult> scanDevices = <ScanResult>[];
// id // id
@ -311,10 +312,21 @@ class BlueManage {
{bool isAddEquipment = false}) async { {bool isAddEquipment = false}) async {
connectDeviceName = deviceName; connectDeviceName = deviceName;
final List<ScanResult> devicesList = scanDevices; final List<ScanResult> devicesList = scanDevices;
final bool isExistDevice = isExistScanDevices(connectDeviceName); final bool isExistDevice = isExistScanDevices(connectDeviceName);
final bool isCurrentDevice =
CommonDataManage().currentKeyInfo.lockName == deviceName;
final String? mac = CommonDataManage().currentKeyInfo.mac;
if (isAddEquipment == false && isExistDevice == false) { AppLog.log('开始连接 是否存在缓存:$isExistDevice 是否是当前设备:$isCurrentDevice mac$mac');
if (GetPlatform.isAndroid &&
!isExistDevice &&
isCurrentDevice &&
mac != null) {
//android
await doNotSearchBLE(mac, connectStateCallBack);
await Future<dynamic>.delayed(3.seconds);
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
} else if (isAddEquipment == false && isExistDevice == false) {
//使 //使
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) { startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
_connectDevice(scanDevices, deviceName, connectStateCallBack, _connectDevice(scanDevices, deviceName, connectStateCallBack,
@ -421,7 +433,51 @@ class BlueManage {
} }
} }
//
Future<void> doNotSearchBLE(
String masAdds, ConnectStateCallBack connectStateCallBack) async {
// FlutterBluePlus.setLogLevel(LogLevel.debug);
final BluetoothDevice device = BluetoothDevice.fromId(masAdds);
//
const int maxAttempts = 3;
bool connected = false;
int attempt = 0;
while (attempt < maxAttempts && !connected) {
try {
await device.connect();
connected = true;
} catch (e, s) {
AppLog.log('连接失败 重连了: ${e.toString()} ${s.toString()}');
attempt++; // Increase the attempt count
if (attempt < maxAttempts) {
AppLog.log('重新尝试连接...');
}
}
}
if (!connected) {
connectStateCallBack(BluetoothConnectionState.disconnected);
return;
}
bluetoothConnectDevice = device;
bluetoothConnectionState = BluetoothConnectionState.connected;
final List<BluetoothService> services =
await bluetoothConnectDevice!.discoverServices();
for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic
in service.characteristics) {
if (characteristic.characteristicUuid ==
_characteristicIdSubscription) {
_subScribeToCharacteristic(characteristic);
}
}
}
}
connectStateCallBack(BluetoothConnectionState.connected);
// writeCharacteristicWithResponse(value);
}
Future<void> _subScribeToCharacteristic( Future<void> _subScribeToCharacteristic(
BluetoothCharacteristic characteristic) async { BluetoothCharacteristic characteristic) async {

View File

@ -295,6 +295,32 @@ class LockDetailLogic extends BaseGetXController {
resetOpenDoorState(); resetOpenDoorState();
} }
}); });
// BlueManage()
// .blueStart((BluetoothConnectionState deviceConnectionState) async {
// if (deviceConnectionState == BluetoothConnectionState.connected) {
// BlueManage().writeDirectlyBLE(
// 'DC:8F:92:83:69:ED',
// OpenLockCommand(
// lockID: BlueManage().connectDeviceName,
// userID: await Storage.getUid(),
// openMode: state.openDoorModel,
// openTime: getUTCNetTime(),
// onlineToken: state.lockNetToken,
// token: getTokenList,
// needAuthor: 1,
// signKey: signKeyDataList,
// privateKey: getPrivateKeyList,
// ).packageData());
// } else if (deviceConnectionState ==
// BluetoothConnectionState.disconnected) {
// cancelBlueConnetctToastTimer();
// if (state.ifCurrentScreen.value == true) {
// showBlueConnetctToast();
// }
// resetOpenDoorState();
// }
// });
} }
// //
@ -513,7 +539,6 @@ class LockDetailLogic extends BaseGetXController {
Future<void> onReady() async { Future<void> onReady() async {
super.onReady(); super.onReady();
getServerDatetime(); getServerDatetime();
await PermissionDialog.request(Permission.location); await PermissionDialog.request(Permission.location);
await PermissionDialog.requestBluetooth(); await PermissionDialog.requestBluetooth();
} }

View File

@ -70,7 +70,9 @@ class GroupList {
List<LockListInfoItemEntity>? lockList; List<LockListInfoItemEntity>? lockList;
bool _isChecked = false; bool _isChecked = false;
bool get isChecked => _isChecked ?? false; bool get isChecked => _isChecked ?? false;
set isChecked(bool value) => _isChecked = value; set isChecked(bool value) => _isChecked = value;
GroupList({this.groupName, this.groupId, this.lockList}); GroupList({this.groupName, this.groupId, this.lockList});
@ -131,41 +133,44 @@ class LockListInfoItemEntity {
LockFeature? lockFeature; LockFeature? lockFeature;
LockSetting? lockSetting; LockSetting? lockSetting;
int? hasGateway; int? hasGateway;
String? mac;
LockListInfoItemEntity( LockListInfoItemEntity({
{this.keyId, this.keyId,
this.lockId, this.lockId,
this.lockName, this.lockName,
this.lockAlias, this.lockAlias,
this.electricQuantity, this.electricQuantity,
this.fwVersion, this.fwVersion,
this.hwVersion, this.hwVersion,
this.keyType, this.keyType,
this.passageMode, this.passageMode,
this.userType, this.userType,
this.startDate, this.startDate,
this.endDate, this.endDate,
this.weekDays, this.weekDays,
this.remoteEnable, this.remoteEnable,
this.faceAuthentication, this.faceAuthentication,
this.lastFaceValidateTime, this.lastFaceValidateTime,
this.nextFaceValidateTime, this.nextFaceValidateTime,
this.keyRight, this.keyRight,
this.keyStatus, this.keyStatus,
this.isLockOwner, this.isLockOwner,
this.bluetooth, this.bluetooth,
this.lockFeature, this.lockFeature,
this.lockSetting, this.lockSetting,
this.sendDate, this.sendDate,
this.lockUserNo, this.lockUserNo,
this.electricQuantityDate, this.electricQuantityDate,
this.electricQuantityStandby, this.electricQuantityStandby,
this.senderUserId, this.senderUserId,
this.isOnlyManageSelf, this.isOnlyManageSelf,
this.restoreCount, this.restoreCount,
this.model, this.model,
this.vendor, this.vendor,
this.hasGateway}); this.hasGateway,
this.mac,
});
LockListInfoItemEntity.fromJson(Map<String, dynamic> json) { LockListInfoItemEntity.fromJson(Map<String, dynamic> json) {
keyId = json['keyId']; keyId = json['keyId'];
@ -207,6 +212,7 @@ class LockListInfoItemEntity {
? LockSetting.fromJson(json['lockSetting']) ? LockSetting.fromJson(json['lockSetting'])
: null; : null;
hasGateway = json['hasGateway']; hasGateway = json['hasGateway'];
mac = json['mac'];
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -250,12 +256,13 @@ class LockListInfoItemEntity {
data['lockSetting'] = lockSetting!.toJson(); data['lockSetting'] = lockSetting!.toJson();
} }
data['hasGateway'] = hasGateway; data['hasGateway'] = hasGateway;
data['mac'] = mac;
return data; return data;
} }
// //
bool isLockOwnerBool(){ bool isLockOwnerBool() {
return isLockOwner== 1; return isLockOwner == 1;
} }
} }
@ -304,18 +311,20 @@ class LockFeature {
int? videoIntercom; int? videoIntercom;
int? isSupportCatEye; int? isSupportCatEye;
int? isSupportBackupBattery; int? isSupportBackupBattery;
LockFeature(
{this.password, LockFeature({
this.icCard, this.password,
this.fingerprint, this.icCard,
this.fingerVein, this.fingerprint,
this.palmVein, this.fingerVein,
this.isSupportIris, this.palmVein,
this.d3Face, this.isSupportIris,
this.bluetoothRemoteControl, this.d3Face,
this.videoIntercom, this.bluetoothRemoteControl,
this.isSupportCatEye, this.videoIntercom,
this.isSupportBackupBattery}); this.isSupportCatEye,
this.isSupportBackupBattery,
});
LockFeature.fromJson(Map<String, dynamic> json) { LockFeature.fromJson(Map<String, dynamic> json) {
password = json['password']; password = json['password'];
@ -352,6 +361,7 @@ class LockSetting {
int? attendance; int? attendance;
int? appUnlockOnline; int? appUnlockOnline;
int? remoteUnlock; int? remoteUnlock;
LockSetting({ LockSetting({
this.attendance, this.attendance,
this.appUnlockOnline, this.appUnlockOnline,

View File

@ -127,7 +127,7 @@ dependencies:
url_launcher: ^6.1.10 url_launcher: ^6.1.10
#蓝牙 #蓝牙
# flutter_reactive_ble: ^5.1.1 # flutter_reactive_ble: ^5.1.1
flutter_blue_plus: 1.31.16 flutter_blue_plus: 1.32.7
# #
event_bus: ^2.0.0 event_bus: ^2.0.0
#菊花 #菊花