Merge branch 'master_hyx'

This commit is contained in:
anfe 2024-04-25 09:39:50 +08:00
commit 5795e7cb0d
5 changed files with 37 additions and 26 deletions

View File

@ -22,7 +22,7 @@ class OTAUpgradeCommand extends SenderProtocol {
int? fwSize;
String? fwMD5;
int? needAuthor;
List<int>? publicKey;
List<int>? signKey;
List<int>? privateKey;
List<int>? 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<int> 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!);
// KeyIDauthUserIDmd5加密之后就是authCode
var authCode = crypto.md5.convert(authCodeData);
@ -140,10 +142,14 @@ class OTAUpgradeCommand extends SenderProtocol {
}
class OTAUpgradeReply extends Reply {
List<int> token = [];
OTAUpgradeReply.parseData(CommandType commandType, List<int> 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);
}
}

View File

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

View File

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

View File

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

View File

@ -29,6 +29,7 @@ class LockEscalationLogic extends BaseGetXController {
int otaIndex = 0;
Uint8List? otaBin;
int startSecond = 0;
Map? headJson = null;
//
Future<void> setLockSetGeneralSetting() async {
@ -53,29 +54,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<int> token) {
BlueManage().bludSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
var token = await Storage.getStringList(saveBlueToken);
List<int> getTokenList = changeStringListToIntList(token!);
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
var signKey = await Storage.getStringList(saveBlueSignKey);
List<int> signKeyDataList = changeStringListToIntList(signKey!);
String lockID = CommonDataManage.shareManager()
?.currentLockSetInfoData
.lockId
@ -95,8 +95,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 ==
@ -115,6 +115,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;
@ -212,9 +213,13 @@ class LockEscalationLogic extends BaseGetXController {
super.onInit();
_replySubscription =
EventBusManager().eventBus!.on<Reply>().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();