From bb00af74196c957627509e6fd044b56f291a1e4c Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Thu, 25 Apr 2024 09:39:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=81=94=E8=B0=83=20ota?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/blue/io_protocol/io_otaUpgrade.dart | 20 +++++++---- .../io_protocol/io_processOtaUpgrade.dart | 4 +-- star_lock/lib/blue/sender_manage.dart | 4 +-- .../lockDetail/lockNetToken_entity.dart | 2 +- .../lockEscalation/lockEscalation_logic.dart | 33 +++++++++++-------- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/star_lock/lib/blue/io_protocol/io_otaUpgrade.dart b/star_lock/lib/blue/io_protocol/io_otaUpgrade.dart index 23e500dd..b7396a5e 100644 --- a/star_lock/lib/blue/io_protocol/io_otaUpgrade.dart +++ b/star_lock/lib/blue/io_protocol/io_otaUpgrade.dart @@ -22,7 +22,7 @@ class OTAUpgradeCommand extends SenderProtocol { int? fwSize; String? fwMD5; int? needAuthor; - List? publicKey; + List? signKey; List? privateKey; List? token; @@ -37,7 +37,7 @@ class OTAUpgradeCommand extends SenderProtocol { this.fwSize, this.fwMD5, this.needAuthor, - this.publicKey, + this.signKey, this.privateKey, this.token}) : super(CommandType.startOATUpgrade); @@ -101,22 +101,24 @@ class OTAUpgradeCommand extends SenderProtocol { // token 长度4 首次请求 Token 填 0,如果锁需要鉴权 操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。 当token失效或者第一次发送的时候token为0 data.addAll(token!); + print('--->1'+data.toString()); + if (needAuthor == 0) { //AuthCodeLen 1 data.add(0); } else { List authCodeData = []; - //authUserID - authCodeData.addAll(utf8.encode(userID!)); - //KeyID authCodeData.addAll(utf8.encode(keyID!)); + //UserID + authCodeData.addAll(utf8.encode(userID!)); + //token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。 authCodeData.addAll(token!); - authCodeData.addAll(publicKey!); + authCodeData.addAll(signKey!); // 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode var authCode = crypto.md5.convert(authCodeData); @@ -140,10 +142,14 @@ class OTAUpgradeCommand extends SenderProtocol { } class OTAUpgradeReply extends Reply { + List token = []; + OTAUpgradeReply.parseData(CommandType commandType, List dataDetail) : super.parseData(commandType, dataDetail) { data = dataDetail; - int status = data[6]; + token = data.sublist(2, 6); + status = data[6]; + print('--->2'+data.toString()); errorWithStstus(status); } } diff --git a/star_lock/lib/blue/io_protocol/io_processOtaUpgrade.dart b/star_lock/lib/blue/io_protocol/io_processOtaUpgrade.dart index 38b52bac..ef3a438f 100644 --- a/star_lock/lib/blue/io_protocol/io_processOtaUpgrade.dart +++ b/star_lock/lib/blue/io_protocol/io_processOtaUpgrade.dart @@ -58,7 +58,7 @@ class ProcessOtaUpgradeReply extends Reply { CommandType commandType, List dataDetail) : super.parseData(commandType, dataDetail) { data = dataDetail; - int status = data[2]; + status = data[2]; errorWithStstus(status); } } @@ -68,7 +68,7 @@ class ConfirmationOTAUpgradeReply extends Reply { CommandType commandType, List dataDetail) : super.parseData(commandType, dataDetail) { data = dataDetail; - int status = data[2]; + status = data[2]; errorWithStstus(status); } } diff --git a/star_lock/lib/blue/sender_manage.dart b/star_lock/lib/blue/sender_manage.dart index 9f1ee9f5..e64b3bef 100644 --- a/star_lock/lib/blue/sender_manage.dart +++ b/star_lock/lib/blue/sender_manage.dart @@ -992,7 +992,7 @@ class IoSenderManage { required String? fwMD5, required int? needAuthor, required List? token, - required List? publicKey, + required List? signKey, required List? privateKey, CommandSendCallBack? callBack}) { CommandSenderManager().managerSendData( @@ -1008,7 +1008,7 @@ class IoSenderManage { fwMD5: fwMD5, token: token, needAuthor: needAuthor, - publicKey: publicKey, + signKey: signKey, privateKey: privateKey, ), callBack: callBack); diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockNetToken_entity.dart b/star_lock/lib/main/lockDetail/lockDetail/lockNetToken_entity.dart index b1be8d76..fc74063a 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockNetToken_entity.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockNetToken_entity.dart @@ -27,7 +27,7 @@ class LockNetTokenEntity { } class Data { - int? token; + String? token; Data({this.token}); diff --git a/star_lock/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart b/star_lock/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart index 69eb2bac..f7d327f5 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart @@ -33,6 +33,7 @@ class LockEscalationLogic extends BaseGetXController { int otaIndex = 0; Uint8List? otaBin; int startSecond = 0; + Map? headJson = null; // 锁升级 Future setLockSetGeneralSetting() async { @@ -57,29 +58,28 @@ class LockEscalationLogic extends BaseGetXController { } File file = File(result.files.single.path!); Uint8List data = await file.readAsBytes(); - Map? headJson = await getHeadFile(data); + headJson = await getHeadFile(data); if (headJson is! Map) { return; } - otaBin = await checkFile(data, headJson); + otaBin = await checkFile(data, headJson!); if (otaBin == null) { return; } - startOTAData(); - blueOTAUpgrade(headJson); + String md5Str = md5.convert(otaBin!).toString(); + headJson!['fwMd5'] = md5Str; + blueOTAUpgrade(headJson!, [0,0,0,0]); } //蓝牙操作 ota 升级 - void blueOTAUpgrade(Map data) { + void blueOTAUpgrade(Map data, List token) { BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); - var publicKey = await Storage.getStringList(saveBluePublicKey); - List getPublicKeyList = changeStringListToIntList(publicKey!); + var signKey = await Storage.getStringList(saveBlueSignKey); + List signKeyDataList = changeStringListToIntList(signKey!); String lockID = CommonDataManage.shareManager() ?.currentLockSetInfoData .lockId @@ -99,8 +99,8 @@ class LockEscalationLogic extends BaseGetXController { fwSize: data['fwSize'], fwMD5: data['fwMd5'], needAuthor: 1, - token: getTokenList, - publicKey: getPublicKeyList, + token: token, + signKey: signKeyDataList, privateKey: getPrivateKeyList) .packageData()); } else if (deviceConnectionState == @@ -119,6 +119,7 @@ class LockEscalationLogic extends BaseGetXController { int difference = length % 240; otaCount = length ~/ 240 + (difference > 0 ? 1 : 0); startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000; + startOTAData(); } if (otaCount <= otaIndex) { int now = DateTime.now().millisecondsSinceEpoch ~/ 1000; @@ -216,9 +217,13 @@ class LockEscalationLogic extends BaseGetXController { super.onInit(); _replySubscription = EventBusManager().eventBus!.on().listen((reply) { - if (reply is OTAUpgradeReply && reply.status == 0x00) { - //验证通过,开始发送数据包 - processOtaUpgrade(); + if (reply is OTAUpgradeReply) { + if (reply.status == 0x00) { + //验证通过,开始发送数据包 + processOtaUpgrade(); + } else if (reply.status == 0x06) { + blueOTAUpgrade(headJson!, reply.token); + } } else if (reply is ProcessOtaUpgradeReply && reply.status == 0x00) { otaIndex++; processOtaUpgrade();