feat(dfu): add firmware file selection and validation
This commit is contained in:
70
lib/model/firmware_file_selection.dart
Normal file
70
lib/model/firmware_file_selection.dart
Normal file
@ -0,0 +1,70 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
class DfuV1FirmwareMetadata {
|
||||
const DfuV1FirmwareMetadata({
|
||||
required this.totalLength,
|
||||
required this.crc32,
|
||||
required this.sessionId,
|
||||
required this.flags,
|
||||
});
|
||||
|
||||
final int totalLength;
|
||||
final int crc32;
|
||||
final int sessionId;
|
||||
final int flags;
|
||||
}
|
||||
|
||||
class DfuV1PreparedFirmware {
|
||||
const DfuV1PreparedFirmware({
|
||||
required this.fileName,
|
||||
required this.fileBytes,
|
||||
required this.metadata,
|
||||
this.filePath,
|
||||
});
|
||||
|
||||
final String fileName;
|
||||
final String? filePath;
|
||||
final Uint8List fileBytes;
|
||||
final DfuV1FirmwareMetadata metadata;
|
||||
}
|
||||
|
||||
enum FirmwareSelectionFailureReason {
|
||||
canceled,
|
||||
malformedSelection,
|
||||
unsupportedExtension,
|
||||
emptyFile,
|
||||
readFailed,
|
||||
}
|
||||
|
||||
class FirmwareSelectionFailure {
|
||||
const FirmwareSelectionFailure({
|
||||
required this.reason,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
final FirmwareSelectionFailureReason reason;
|
||||
final String message;
|
||||
}
|
||||
|
||||
class FirmwareFileSelectionResult {
|
||||
const FirmwareFileSelectionResult._({
|
||||
this.firmware,
|
||||
this.failure,
|
||||
});
|
||||
|
||||
final DfuV1PreparedFirmware? firmware;
|
||||
final FirmwareSelectionFailure? failure;
|
||||
|
||||
bool get isSuccess => firmware != null;
|
||||
|
||||
bool get isCanceled =>
|
||||
failure?.reason == FirmwareSelectionFailureReason.canceled;
|
||||
|
||||
static FirmwareFileSelectionResult success(DfuV1PreparedFirmware firmware) {
|
||||
return FirmwareFileSelectionResult._(firmware: firmware);
|
||||
}
|
||||
|
||||
static FirmwareFileSelectionResult failed(FirmwareSelectionFailure failure) {
|
||||
return FirmwareFileSelectionResult._(failure: failure);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user