feat:联调 ota
This commit is contained in:
parent
46c4c3df4b
commit
bb00af7419
@ -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!);
|
||||||
|
|
||||||
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class LockNetTokenEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Data {
|
class Data {
|
||||||
int? token;
|
String? token;
|
||||||
|
|
||||||
Data({this.token});
|
Data({this.token});
|
||||||
|
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user