runFirmwareUpdateFullAuto method
Implementation
Future<bool> runFirmwareUpdateFullAuto({
required TransferType txType,
required List<int> payload,
String? destination,
String? expectedVersion,
int maxRetriesPerStep = _maxDfuRetriesPerStep,
}) async {
final useSetupMulti = txType.useSetupMulti;
if (useSetupMulti && (destination == null || destination.isEmpty)) {
return false;
}
final flowSteps = txType.firmwareDfuSteps();
if (flowSteps.isEmpty) {
return false;
}
final retriesPerStep = maxRetriesPerStep.clamp(1, _maxDfuRetriesPerStep);
final totalSteps = flowSteps.length;
final lastVersionStepIndex = flowSteps.lastIndexOf(DfuStep.version);
final expectedVersionString = expectedVersion?.trim();
if (expectedVersionString == null ||
expectedVersionString.isEmpty ||
lastVersionStepIndex < 0) {
return false;
}
_firmwareAutoUpdateNotifier.startInstall();
bool wasSuccessful = false;
try {
for (int stepIndex = 0; stepIndex < flowSteps.length; stepIndex++) {
final step = flowSteps[stepIndex];
final currentStepIndex = stepIndex + 1;
int retries = 0;
while (true) {
if (_firmwareAutoUpdateNotifier.isCancellationRequested) {
return false;
}
_firmwareAutoUpdateNotifier.setDfuStepProgress(
txType: txType,
totalSteps: totalSteps,
currentStep: currentStepIndex,
stepProgress: retries / retriesPerStep,
);
final stepSucceeded = await _runDfuStep(
step: step,
txType: txType,
destination: destination,
payload: payload,
stepAttempt: retries,
useSetupMulti: useSetupMulti,
totalSteps: totalSteps,
currentStepIndex: currentStepIndex,
expectedVersion: expectedVersionString,
enforceExpectedVersion: stepIndex == lastVersionStepIndex,
);
if (stepSucceeded) {
_firmwareAutoUpdateNotifier.setDfuStepProgress(
txType: txType,
totalSteps: totalSteps,
currentStep: currentStepIndex,
stepProgress: 1,
);
break;
}
if (_firmwareAutoUpdateNotifier.isCancellationRequested) {
return false;
}
retries++;
if (retries >= retriesPerStep) {
return false;
}
await Future.delayed(_dfuRetryDelay);
}
}
wasSuccessful = true;
return wasSuccessful;
} finally {
_firmwareAutoUpdateNotifier.finishInstall();
}
}