fix:修复开锁的问题,以及操作记录重复上传的问题。
This commit is contained in:
parent
bc31d7d651
commit
b067e8a22e
@ -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;
|
||||
|
||||
@ -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<void> writeNull() async {
|
||||
List<BluetoothService> 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<int> valueList = [1];
|
||||
AppLog.log('APP写入 writeNull ');
|
||||
await characteristic.write(valueList);
|
||||
} on Exception catch (e, s) {
|
||||
AppLog.log('APP写入失败 writeNull : $e $s');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 读取
|
||||
// Future<List<int>> _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("断开连接成功");
|
||||
|
||||
@ -35,7 +35,8 @@ abstract class SenderProtocol extends IOData {
|
||||
|
||||
void printLog(List<int> 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:拼装数据Ï
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
// 把得到的数据按8位分割成数组 然后塞进一个新的数组里面
|
||||
@ -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<int> 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<void> senderReferEventRecordTime() async {
|
||||
showBlueConnetctToastTimer(
|
||||
isShowBlueConnetctToast: false,
|
||||
outTimer: 10,
|
||||
action: () {
|
||||
BlueManage().disconnect();
|
||||
});
|
||||
|
||||
@ -403,8 +403,9 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
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<LockDetailPage>
|
||||
|
||||
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<LockDetailPage>
|
||||
|
||||
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<LockDetailPage>
|
||||
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<LockDetailPage>
|
||||
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<LockDetailPage>
|
||||
onTap: bottomBtnisEable
|
||||
? onClick
|
||||
: () {
|
||||
logic.showToast("请在锁旁边完成第一次开锁".tr);
|
||||
},
|
||||
logic.showToast("请在锁旁边完成第一次开锁".tr);
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
@ -1406,7 +1412,7 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
state.openLockBtnState.value = 0;
|
||||
logic.closeLuckStatus();
|
||||
BlueManage().disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user