feat:联调 ota

This commit is contained in:
anfe 2024-04-25 09:39:31 +08:00
parent 46c4c3df4b
commit bb00af7419
5 changed files with 37 additions and 26 deletions

View File

@ -22,7 +22,7 @@ class OTAUpgradeCommand extends SenderProtocol {
int? fwSize; int? fwSize;
String? fwMD5; String? fwMD5;
int? needAuthor; int? needAuthor;
List<int>? publicKey; List<int>? signKey;
List<int>? privateKey; List<int>? privateKey;
List<int>? token; List<int>? token;
@ -37,7 +37,7 @@ class OTAUpgradeCommand extends SenderProtocol {
this.fwSize, this.fwSize,
this.fwMD5, this.fwMD5,
this.needAuthor, this.needAuthor,
this.publicKey, this.signKey,
this.privateKey, this.privateKey,
this.token}) this.token})
: super(CommandType.startOATUpgrade); : super(CommandType.startOATUpgrade);
@ -101,22 +101,24 @@ class OTAUpgradeCommand extends SenderProtocol {
// token 4 Token 0 token失效或者第一次发送的时候token为0 // token 4 Token 0 token失效或者第一次发送的时候token为0
data.addAll(token!); data.addAll(token!);
print('--->1'+data.toString());
if (needAuthor == 0) { if (needAuthor == 0) {
//AuthCodeLen 1 //AuthCodeLen 1
data.add(0); data.add(0);
} else { } else {
List<int> authCodeData = []; List<int> authCodeData = [];
//authUserID
authCodeData.addAll(utf8.encode(userID!));
//KeyID //KeyID
authCodeData.addAll(utf8.encode(keyID!)); authCodeData.addAll(utf8.encode(keyID!));
//UserID
authCodeData.addAll(utf8.encode(userID!));
//token 4 Token 0 //token 4 Token 0
authCodeData.addAll(token!); authCodeData.addAll(token!);
authCodeData.addAll(publicKey!); authCodeData.addAll(signKey!);
// KeyIDauthUserIDmd5加密之后就是authCode // KeyIDauthUserIDmd5加密之后就是authCode
var authCode = crypto.md5.convert(authCodeData); var authCode = crypto.md5.convert(authCodeData);
@ -140,10 +142,14 @@ class OTAUpgradeCommand extends SenderProtocol {
} }
class OTAUpgradeReply extends Reply { class OTAUpgradeReply extends Reply {
List<int> token = [];
OTAUpgradeReply.parseData(CommandType commandType, List<int> dataDetail) OTAUpgradeReply.parseData(CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) { : super.parseData(commandType, dataDetail) {
data = dataDetail; data = dataDetail;
int status = data[6]; token = data.sublist(2, 6);
status = data[6];
print('--->2'+data.toString());
errorWithStstus(status); errorWithStstus(status);
} }
} }

View File

@ -58,7 +58,7 @@ class ProcessOtaUpgradeReply extends Reply {
CommandType commandType, List<int> dataDetail) CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) { : super.parseData(commandType, dataDetail) {
data = dataDetail; data = dataDetail;
int status = data[2]; status = data[2];
errorWithStstus(status); errorWithStstus(status);
} }
} }
@ -68,7 +68,7 @@ class ConfirmationOTAUpgradeReply extends Reply {
CommandType commandType, List<int> dataDetail) CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) { : super.parseData(commandType, dataDetail) {
data = dataDetail; data = dataDetail;
int status = data[2]; status = data[2];
errorWithStstus(status); errorWithStstus(status);
} }
} }

View File

@ -992,7 +992,7 @@ class IoSenderManage {
required String? fwMD5, required String? fwMD5,
required int? needAuthor, required int? needAuthor,
required List<int>? token, required List<int>? token,
required List<int>? publicKey, required List<int>? signKey,
required List<int>? privateKey, required List<int>? privateKey,
CommandSendCallBack? callBack}) { CommandSendCallBack? callBack}) {
CommandSenderManager().managerSendData( CommandSenderManager().managerSendData(
@ -1008,7 +1008,7 @@ class IoSenderManage {
fwMD5: fwMD5, fwMD5: fwMD5,
token: token, token: token,
needAuthor: needAuthor, needAuthor: needAuthor,
publicKey: publicKey, signKey: signKey,
privateKey: privateKey, privateKey: privateKey,
), ),
callBack: callBack); callBack: callBack);

View File

@ -27,7 +27,7 @@ class LockNetTokenEntity {
} }
class Data { class Data {
int? token; String? token;
Data({this.token}); Data({this.token});

View File

@ -33,6 +33,7 @@ class LockEscalationLogic extends BaseGetXController {
int otaIndex = 0; int otaIndex = 0;
Uint8List? otaBin; Uint8List? otaBin;
int startSecond = 0; int startSecond = 0;
Map? headJson = null;
// //
Future<void> setLockSetGeneralSetting() async { Future<void> setLockSetGeneralSetting() async {
@ -57,29 +58,28 @@ class LockEscalationLogic extends BaseGetXController {
} }
File file = File(result.files.single.path!); File file = File(result.files.single.path!);
Uint8List data = await file.readAsBytes(); Uint8List data = await file.readAsBytes();
Map? headJson = await getHeadFile(data); headJson = await getHeadFile(data);
if (headJson is! Map) { if (headJson is! Map) {
return; return;
} }
otaBin = await checkFile(data, headJson); otaBin = await checkFile(data, headJson!);
if (otaBin == null) { if (otaBin == null) {
return; return;
} }
startOTAData(); String md5Str = md5.convert(otaBin!).toString();
blueOTAUpgrade(headJson); headJson!['fwMd5'] = md5Str;
blueOTAUpgrade(headJson!, [0,0,0,0]);
} }
// ota // ota
void blueOTAUpgrade(Map data) { void blueOTAUpgrade(Map data, List<int> token) {
BlueManage().bludSendData(BlueManage().connectDeviceName, BlueManage().bludSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
var token = await Storage.getStringList(saveBlueToken); var signKey = await Storage.getStringList(saveBlueSignKey);
List<int> getTokenList = changeStringListToIntList(token!); List<int> signKeyDataList = changeStringListToIntList(signKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
String lockID = CommonDataManage.shareManager() String lockID = CommonDataManage.shareManager()
?.currentLockSetInfoData ?.currentLockSetInfoData
.lockId .lockId
@ -99,8 +99,8 @@ class LockEscalationLogic extends BaseGetXController {
fwSize: data['fwSize'], fwSize: data['fwSize'],
fwMD5: data['fwMd5'], fwMD5: data['fwMd5'],
needAuthor: 1, needAuthor: 1,
token: getTokenList, token: token,
publicKey: getPublicKeyList, signKey: signKeyDataList,
privateKey: getPrivateKeyList) privateKey: getPrivateKeyList)
.packageData()); .packageData());
} else if (deviceConnectionState == } else if (deviceConnectionState ==
@ -119,6 +119,7 @@ class LockEscalationLogic extends BaseGetXController {
int difference = length % 240; int difference = length % 240;
otaCount = length ~/ 240 + (difference > 0 ? 1 : 0); otaCount = length ~/ 240 + (difference > 0 ? 1 : 0);
startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000; startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000;
startOTAData();
} }
if (otaCount <= otaIndex) { if (otaCount <= otaIndex) {
int now = DateTime.now().millisecondsSinceEpoch ~/ 1000; int now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
@ -216,9 +217,13 @@ class LockEscalationLogic extends BaseGetXController {
super.onInit(); super.onInit();
_replySubscription = _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) { EventBusManager().eventBus!.on<Reply>().listen((reply) {
if (reply is OTAUpgradeReply && reply.status == 0x00) { if (reply is OTAUpgradeReply) {
// if (reply.status == 0x00) {
processOtaUpgrade(); //
processOtaUpgrade();
} else if (reply.status == 0x06) {
blueOTAUpgrade(headJson!, reply.token);
}
} else if (reply is ProcessOtaUpgradeReply && reply.status == 0x00) { } else if (reply is ProcessOtaUpgradeReply && reply.status == 0x00) {
otaIndex++; otaIndex++;
processOtaUpgrade(); processOtaUpgrade();