diff --git a/star_lock/lib/app_settings/app_settings.dart b/star_lock/lib/app_settings/app_settings.dart index 53f711b5..7998bf68 100644 --- a/star_lock/lib/app_settings/app_settings.dart +++ b/star_lock/lib/app_settings/app_settings.dart @@ -14,6 +14,7 @@ class AppLog { _onlyError = onlyError ?? false; } static log(String msg,{bool? error}){ + msg = '${DateTime.now().toIso8601String()} : $msg'; DebugConsole.info(msg); if(!kDebugMode)return; error = error ?? false; diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index 639ff321..9f99375b 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -623,7 +623,7 @@ class BlueManage { } } } on Exception catch (e, s) { - AppLog.log('APP写入失败: $e'); + AppLog.log('APP写入失败: $e $s'); rethrow; } } @@ -654,6 +654,30 @@ class BlueManage { // } } + // 写入 + Future writeNull() async { + List services = + await bluetoothConnectDevice!.discoverServices(); + for (BluetoothService service in services) { + if (service.uuid == _serviceIdConnect) { + for (BluetoothCharacteristic characteristic + in service.characteristics) { + + if (characteristic.characteristicUuid == _characteristicIdWrite) { + try { + List valueList = [1]; + AppLog.log('APP写入 writeNull '); + await characteristic.write(valueList); + } on Exception catch (e, s) { + AppLog.log('APP写入失败 writeNull : $e $s'); + rethrow; + } + } + } + } + } + } + // 读取 // Future> _readCharacteristic(QualifiedCharacteristic characteristic) async { // try { @@ -696,6 +720,8 @@ class BlueManage { // if(bluetoothConnectDevice != null && bluetoothConnectDevice!.connectionState == BluetoothConnectionState.connected){ connectDeviceMacAddress = ""; if (bluetoothConnectionState == BluetoothConnectionState.connected) { + // await writeNull(); + // await Future.delayed(const Duration(milliseconds: 1000)); //加快蓝牙断连 await bluetoothConnectDevice!.disconnect(timeout: 2); AppLog.log("断开连接成功"); diff --git a/star_lock/lib/blue/io_sender.dart b/star_lock/lib/blue/io_sender.dart index 3d98678d..098f50a5 100644 --- a/star_lock/lib/blue/io_sender.dart +++ b/star_lock/lib/blue/io_sender.dart @@ -35,7 +35,8 @@ abstract class SenderProtocol extends IOData { void printLog(List data) { AppLog.log( - "App -> 锁,指令类型:${commandType!.typeName} \n参数是:\n${toString()} \n加密之前数据是:\n$data 长度是:${data.length}"); + "App -> 锁,指令类型:${commandType!.typeName} ${commandType!.typeValue == 0x3030 + ? '子命令:${data[3]}' : ''} \n参数是:\n${toString()} \n加密之前数据是:\n$data 长度是:${data.length}"); } //TODO:拼装数据Ï diff --git a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart index f8d8d882..ab06c222 100644 --- a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart +++ b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_entity.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_state.dart'; @@ -58,7 +59,7 @@ class DoorLockLogLogic extends BaseGetXController { // AppLog.log("indexList:$indexList"); var indexMap = {}; indexMap["type"] = indexList[0].toString(); - + int operateDate = 0; if (indexList[0] == 2) { var passwordData = indexList.sublist(7, 17); var password = utf8String(passwordData); @@ -75,6 +76,11 @@ class DoorLockLogLogic extends BaseGetXController { (0xFF & indexList[6])); indexMap["date"] = "${time * 1000}"; uploadList.add(indexMap); + + if (i == getList.length - 1) { + //设置最后的时间戳 + state.operateDate = operateDate; + } } lockRecordUploadData(uploadList); diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index 56206c13..0ecca01f 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -188,7 +188,7 @@ class LockDetailLogic extends BaseGetXController { case 0x00: //成功 int dataLength = (reply.data[5] << 8) + reply.data[6]; - AppLog.log("dataLength:$dataLength"); + // AppLog.log("dataLength:$dataLength"); if (dataLength > 0) { reply.data.removeRange(0, 7); // 把得到的数据按17个字节分割成数组 然后塞进一个新的数组里面 @@ -203,7 +203,7 @@ class LockDetailLogic extends BaseGetXController { // AppLog.log("indexList:$indexList"); var indexMap = {}; indexMap["type"] = indexList[0].toString(); - + int operateDate = 0; if (indexList[0] == 2) { var passwordData = reply.data.sublist(7, 17); var password = utf8String(passwordData); @@ -219,8 +219,14 @@ class LockDetailLogic extends BaseGetXController { (0xff & indexList[4]) << 16 | (0xff & indexList[5]) << 8 | (0xFF & indexList[6])); - indexMap["date"] = "${time * 1000}"; + operateDate = time * 1000; + indexMap["date"] = "$operateDate"; uploadList.add(indexMap); + + if (i == getList.length - 1) { + //设置最后的时间戳 + state.operateDate = operateDate; + } } lockRecordUploadData(uploadList); @@ -259,7 +265,8 @@ class LockDetailLogic extends BaseGetXController { var token = await Storage.getStringList(saveBlueToken); List getTokenList = changeStringListToIntList(token!); - BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, + BlueManage() + .bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { IoSenderManage.senderOpenLock( @@ -289,6 +296,7 @@ class LockDetailLogic extends BaseGetXController { Future senderReferEventRecordTime() async { showBlueConnetctToastTimer( isShowBlueConnetctToast: false, + outTimer: 10, action: () { BlueManage().disconnect(); }); diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart index 8986f946..451f629f 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -403,8 +403,9 @@ class _LockDetailPageState extends State children: [ Visibility( visible: - ((state.keyInfos.value.keyType == XSConstantMacro.keyTypeTime || state.keyInfos.value.keyType == XSConstantMacro.keyTypeLoop) - && // 限时、循环 + ((state.keyInfos.value.keyType == XSConstantMacro.keyTypeTime || + state.keyInfos.value.keyType == + XSConstantMacro.keyTypeLoop) && // 限时、循环 (DateTool().compareTimeGetDaysFromNow( state.keyInfos.value.endDate!) <= 15 && @@ -1023,8 +1024,9 @@ class _LockDetailPageState extends State if (state.keyInfos.value.lockFeature!.isSupportIris == 1) { showWidgetArr.add( - bottomItem('images/main/icon_iris.png', '虹膜'.tr, - state.bottomBtnisEable.value, () { + bottomItem( + 'images/main/icon_iris.png', '虹膜'.tr, state.bottomBtnisEable.value, + () { Get.toNamed(Routers.irisListPage, arguments: { "lockId": state.keyInfos.value.lockId, }); @@ -1034,8 +1036,9 @@ class _LockDetailPageState extends State if (state.keyInfos.value.lockFeature!.palmVein == 1) { showWidgetArr.add( - bottomItem('images/main/icon_palm.png', '手掌'.tr, - state.bottomBtnisEable.value, () { + bottomItem( + 'images/main/icon_palm.png', '手掌'.tr, state.bottomBtnisEable.value, + () { Get.toNamed(Routers.palmListPage, arguments: { "lockId": state.keyInfos.value.lockId, }); @@ -1121,7 +1124,8 @@ class _LockDetailPageState extends State return showWidgetArr; } - Widget bottomItem(String iconUrl, String name, bool bottomBtnisEable, Function() onClick) { + Widget bottomItem( + String iconUrl, String name, bool bottomBtnisEable, Function() onClick) { Widget child = F.sw( defaultCall: () => Container( color: Colors.white, @@ -1147,7 +1151,9 @@ class _LockDetailPageState extends State child: Text(name, style: TextStyle( fontSize: 20.sp, - color: bottomBtnisEable ? AppColors.blackColor : AppColors.lockDetailBottomBtnUneable), + color: bottomBtnisEable + ? AppColors.blackColor + : AppColors.lockDetailBottomBtnUneable), textAlign: TextAlign.center)) ], ), @@ -1189,8 +1195,8 @@ class _LockDetailPageState extends State onTap: bottomBtnisEable ? onClick : () { - logic.showToast("请在锁旁边完成第一次开锁".tr); - }, + logic.showToast("请在锁旁边完成第一次开锁".tr); + }, child: child, ); } @@ -1406,7 +1412,7 @@ class _LockDetailPageState extends State void didPushNext() { super.didPushNext(); state.ifCurrentScreen.value = false; - logic.cancelBlueConnetctToastTimer(); - state.openLockBtnState.value = 0; + logic.closeLuckStatus(); + BlueManage().disconnect(); } } diff --git a/star_lock/lib/tools/baseGetXController.dart b/star_lock/lib/tools/baseGetXController.dart index af626b74..4c04428c 100644 --- a/star_lock/lib/tools/baseGetXController.dart +++ b/star_lock/lib/tools/baseGetXController.dart @@ -66,12 +66,14 @@ class BaseGetXController extends GetxController { // CancelableOperation? _operation; void showBlueConnetctToastTimer( - {bool isShowBlueConnetctToast = true, Function? action}) { + {bool isShowBlueConnetctToast = true, + int outTimer = 15, + Function? action}) { if (_timer != null && _timer!.isActive) { _timer!.cancel(); _timer = null; } - _timer = Timer.periodic(15.seconds, (timer) { + _timer = Timer.periodic(outTimer.seconds, (timer) { if (action != null) { action(); }