From 09a8d7b3449678e01406aeb589e6c83d0bc881ec Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 24 Mar 2025 15:14:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=91?= =?UTF-8?q?=E5=90=8E=E8=AF=BB=E5=8F=96=E9=94=81=E8=AE=BE=E7=BD=AE=E5=B9=B6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuringWifi_logic.dart | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart index 1ed6f736..52241914 100755 --- a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart +++ b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart @@ -12,6 +12,7 @@ import 'package:star_lock/appRouters.dart'; import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/blue/io_gateway/io_gateway_configuringWifi.dart'; import 'package:star_lock/blue/io_gateway/io_gateway_getStatus.dart'; +import 'package:star_lock/blue/io_protocol/io_updataLockSet.dart'; import 'package:star_lock/login/login/entity/LoginEntity.dart'; import 'package:star_lock/main/lockDetail/lockDetail/device_network_info.dart'; import 'package:star_lock/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart'; @@ -20,6 +21,7 @@ import 'package:star_lock/mine/gateway/addGateway/selectGateway/getGatewayInfo_m import 'package:star_lock/talk/starChart/entity/star_chart_register_node_entity.dart'; import 'package:star_lock/talk/starChart/star_chart_manage.dart'; import 'package:star_lock/tools/baseGetXController.dart'; +import 'package:star_lock/tools/commonDataManage.dart'; import '../../../../../blue/blue_manage.dart'; import '../../../../../blue/io_protocol/io_configuringWifi.dart'; @@ -59,7 +61,8 @@ class ConfiguringWifiLogic extends BaseGetXController { peerId: peerId, ); if (entity.errorCode!.codeIsSuccessful) { - showToast('配网成功'.tr, something: () { + showToast('配网成功'.tr, something: () async { + await _getUploadLockSet(); eventBus .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); // 设置锁的peerID @@ -101,6 +104,10 @@ class ConfiguringWifiLogic extends BaseGetXController { if (reply is GatewayGetStatusReply) { _replyStatusInfo(reply); } + // 上传数据获取锁设置 + if (reply is UpdataLockSetReply) { + _replyUpdataLockSetReply(reply); + } AppLog.log('蓝牙回调处理完毕${EasyLoading.isShow}'); }); } @@ -389,6 +396,88 @@ class ConfiguringWifiLogic extends BaseGetXController { void _replyStatusInfo(reply) {} + // 上传数据获取设置 + Future _getUploadLockSet() async { + // showBlueConnetctToastTimer(action: (){ + // }); + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + _uploadLockSet(getTokenList); + } else if (connectionState == BluetoothConnectionState.disconnected) { + // cancelBlueConnetctToastTimer(); + // if(state.ifCurrentScreen.value == true){ + // showBlueConnetctToast(); + // } + } + }); + } + + // 公共的上传锁设置 + Future _uploadLockSet(List token) async { + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); + + final List? signKey = await Storage.getStringList(saveBlueSignKey); + final List signKeyDataList = changeStringListToIntList(signKey!); + + IoSenderManage.updataLockSetCommand( + lockID: BlueManage().connectDeviceName, + userID: await Storage.getUid(), + token: token, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList); + } + + // 上传数据获取锁设置解析 + Future _replyUpdataLockSetReply(Reply reply) async { + final int status = reply.data[2]; + switch (status) { + case 0x00: + //成功 + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + _lockDataUpload( + uploadType: 1, + recordType: 0, + records: reply.data.sublist(7, reply.data.length)); + break; + case 0x06: + //无权限 + final List token = reply.data.sublist(3, 7); + final List saveStrList = changeIntListToStringList(token); + Storage.setStringList(saveBlueToken, saveStrList); + + _uploadLockSet(token); + break; + default: + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + break; + } + } + + // 锁数据上传服务器 + Future _lockDataUpload( + {required int uploadType, + required int recordType, + required List records}) async { + final LoginEntity entity = await ApiRepository.to.lockDataUpload( + lockId: CommonDataManage().currentKeyInfo.lockId!, + uploadType: uploadType, + recordType: recordType, + records: records, + isUnShowLoading: true); + if (entity.errorCode!.codeIsSuccessful) { + update(); + } + } + @override void dispose() { // TODO: implement dispose