82 lines
1.9 KiB
Dart
82 lines
1.9 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import '../io_tool/io_tool.dart';
|
|
import '../sm4Encipher/sm4.dart';
|
|
import '../io_reply.dart';
|
|
import '../io_sender.dart';
|
|
import '../io_type.dart';
|
|
import 'package:crypto/crypto.dart' as crypto;
|
|
|
|
//oat升级
|
|
class ProcessOtaUpgradeCommand extends SenderProtocol {
|
|
int? index;
|
|
int? size;
|
|
List<int>? data;
|
|
|
|
ProcessOtaUpgradeCommand({
|
|
this.index,
|
|
this.size,
|
|
this.data,
|
|
}) : super(CommandType.processOTAUpgrade);
|
|
|
|
|
|
@override
|
|
String toString() {
|
|
return 'ProcessOtaUpgradeCommand{index: $index, size: $size, data: $data}';
|
|
}
|
|
|
|
@override
|
|
List<int> messageDetail() {
|
|
List<int> data = [];
|
|
|
|
// 指令类型
|
|
int type = commandType!.typeValue;
|
|
double typeDouble = type / 256;
|
|
int type1 = typeDouble.toInt();
|
|
int type2 = type % 256;
|
|
data.add(type1);
|
|
data.add(type2);
|
|
|
|
//index 2
|
|
ByteData indexBytes = ByteData(2); // 创建一个长度为4的字节数据
|
|
indexBytes.setInt16(0, index!);
|
|
List<int> indexList = indexBytes.buffer.asUint8List();
|
|
data.addAll(indexList);
|
|
|
|
//size 2
|
|
ByteData bytes = ByteData(2); // 创建一个长度为4的字节数据
|
|
bytes.setInt16(0, size!);
|
|
List<int> byteList = bytes.buffer.asUint8List();
|
|
data.addAll(byteList);
|
|
|
|
data.addAll(this.data!);
|
|
|
|
printLog(data);
|
|
//不加密
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class ProcessOtaUpgradeReply extends Reply {
|
|
ProcessOtaUpgradeReply.parseData(
|
|
CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
status = data[2];
|
|
errorWithStstus(status);
|
|
}
|
|
}
|
|
|
|
class ConfirmationOTAUpgradeReply extends Reply {
|
|
ConfirmationOTAUpgradeReply.parseData(
|
|
CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
status = data[2];
|
|
errorWithStstus(status);
|
|
}
|
|
}
|