only:refactoring: part of functionality extracted into `UpdateCalibrationsJobContext` class

This commit is contained in:
kifir23917 2024-09-21 02:45:39 +03:00 committed by rusefillc
parent 6315c6dc47
commit 55b5581d96
4 changed files with 24 additions and 13 deletions

View File

@ -16,17 +16,11 @@ public enum CalibrationsUpdater {
private static final Logging log = getLogging(CalibrationsUpdater.class);
private volatile ConfigurationImage calibrationsToUpload = null;
public void setCalibrationsToUpload(final ConfigurationImage calibrations) {
calibrationsToUpload = calibrations;
}
public synchronized void updateCalibrations(
final String port,
final ConfigurationImage calibrationsImage,
final UpdateOperationCallbacks callbacks
) {
final ConfigurationImage calibrationsImage = calibrationsToUpload;
if (calibrationsImage != null) {
final int calibrationsImageSize = calibrationsImage.getSize();
try {

View File

@ -1,18 +1,20 @@
package com.rusefi.maintenance.jobs;
import com.opensr5.ConfigurationImage;
import com.rusefi.SerialPortScanner;
import com.rusefi.io.UpdateOperationCallbacks;
import com.rusefi.maintenance.CalibrationsUpdater;
public class UpdateCalibrationsJob extends AsyncJobWithContext<SerialPortJobContext> {
public UpdateCalibrationsJob(final SerialPortScanner.PortResult port) {
super("Update calibrations", new SerialPortJobContext(port));
public class UpdateCalibrationsJob extends AsyncJobWithContext<UpdateCalibrationsJobContext> {
public UpdateCalibrationsJob(final SerialPortScanner.PortResult port, final ConfigurationImage calibrations) {
super("Update calibrations", new UpdateCalibrationsJobContext(port, calibrations));
}
@Override
public void doJob(final UpdateOperationCallbacks callbacks) {
CalibrationsUpdater.INSTANCE.updateCalibrations(
context.getPort().port,
context.getCalibrations(),
callbacks
);
}

View File

@ -0,0 +1,17 @@
package com.rusefi.maintenance.jobs;
import com.opensr5.ConfigurationImage;
import com.rusefi.SerialPortScanner;
public class UpdateCalibrationsJobContext extends SerialPortJobContext {
private final ConfigurationImage calibrations;
UpdateCalibrationsJobContext(final SerialPortScanner.PortResult port, final ConfigurationImage calibrations) {
super(port);
this.calibrations = calibrations;
}
public ConfigurationImage getCalibrations() {
return calibrations;
}
}

View File

@ -5,7 +5,6 @@ import com.opensr5.ConfigurationImage;
import com.opensr5.io.ConfigurationImageFile;
import com.rusefi.SerialPortScanner;
import com.rusefi.core.preferences.storage.PersistentConfiguration;
import com.rusefi.maintenance.CalibrationsUpdater;
import com.rusefi.maintenance.ProgramSelector;
import com.rusefi.maintenance.jobs.UpdateCalibrationsJob;
@ -32,8 +31,7 @@ public class UpdateCalibrations {
final ConfigurationImage calibrationsImage = ConfigurationImageFile.readFromFile(
selectedFile.getAbsolutePath()
);
CalibrationsUpdater.INSTANCE.setCalibrationsToUpload(calibrationsImage);
ProgramSelector.executeJob(new UpdateCalibrationsJob(port));
ProgramSelector.executeJob(new UpdateCalibrationsJob(port, calibrationsImage));
} catch (final IOException e) {
final String errorMsg = String.format(
"Failed to load calibrations from file %s",