mirror of https://github.com/rusefi/rusefi-1.git
refactoring: better dependency control
This commit is contained in:
parent
1e497b626e
commit
5371b3b1fb
|
@ -57,11 +57,6 @@ public class LinkManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BinaryProtocol getCurrentStreamStateStatic() {
|
|
||||||
Objects.requireNonNull(connector, "connector");
|
|
||||||
return connector.getBinaryProtocol();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BinaryProtocol getCurrentStreamState() {
|
public BinaryProtocol getCurrentStreamState() {
|
||||||
Objects.requireNonNull(connector, "connector");
|
Objects.requireNonNull(connector, "connector");
|
||||||
return connector.getBinaryProtocol();
|
return connector.getBinaryProtocol();
|
||||||
|
|
|
@ -3,6 +3,6 @@ package com.rusefi;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class rusEFIVersion {
|
public class rusEFIVersion {
|
||||||
public static final int CONSOLE_VERSION = 20200623;
|
public static final int CONSOLE_VERSION = 20200625;
|
||||||
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
|
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.core.SensorCentral;
|
import com.rusefi.core.SensorCentral;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
import com.rusefi.ui.config.ConfigField;
|
import com.rusefi.ui.config.ConfigField;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
@ -20,10 +21,15 @@ import java.io.Writer;
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
* Andrey Belomutskiy, (c) 2013-2020
|
||||||
*/
|
*/
|
||||||
public class PlainTextSensorLog implements SensorLog {
|
public class PlainTextSensorLog implements SensorLog {
|
||||||
|
private final UIContext uiContext;
|
||||||
private Writer logFile;
|
private Writer logFile;
|
||||||
|
|
||||||
private long fileStartTime;
|
private long fileStartTime;
|
||||||
|
|
||||||
|
public PlainTextSensorLog(UIContext uiContext) {
|
||||||
|
this.uiContext = uiContext;
|
||||||
|
}
|
||||||
|
|
||||||
private void startIfNeeded() {
|
private void startIfNeeded() {
|
||||||
if (logFile == null) {
|
if (logFile == null) {
|
||||||
/*
|
/*
|
||||||
|
@ -45,7 +51,7 @@ public class PlainTextSensorLog implements SensorLog {
|
||||||
logFile.write("Captured " + FileLog.getDate() + "\r\n");
|
logFile.write("Captured " + FileLog.getDate() + "\r\n");
|
||||||
|
|
||||||
int debugMode = -1;
|
int debugMode = -1;
|
||||||
BinaryProtocol bp = LinkManager.getCurrentStreamStateStatic();
|
BinaryProtocol bp = uiContext.getLinkManager().getCurrentStreamState();
|
||||||
if (bp != null) {
|
if (bp != null) {
|
||||||
ConfigurationImage ci = bp.getControllerConfiguration();
|
ConfigurationImage ci = bp.getControllerConfiguration();
|
||||||
if (ci != null) {
|
if (ci != null) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.core.SensorCentral;
|
import com.rusefi.core.SensorCentral;
|
||||||
import com.rusefi.io.ConnectionStatusLogic;
|
import com.rusefi.io.ConnectionStatusLogic;
|
||||||
import com.rusefi.io.ConnectionStatusValue;
|
import com.rusefi.io.ConnectionStatusValue;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -81,10 +82,16 @@ public class SensorLogger {
|
||||||
Sensor.engineMakeCodeNameCrc16,
|
Sensor.engineMakeCodeNameCrc16,
|
||||||
Sensor.tuneCrc16,
|
Sensor.tuneCrc16,
|
||||||
};
|
};
|
||||||
|
private final UIContext uiContext;
|
||||||
|
|
||||||
private static List<SensorLog> sensorLogs = Arrays.asList(new PlainTextSensorLog(), new BinarySensorLogRestarter());
|
private List<SensorLog> sensorLogs;
|
||||||
|
|
||||||
private static boolean isInitialized;
|
private boolean isInitialized;
|
||||||
|
|
||||||
|
public SensorLogger(UIContext uiContext) {
|
||||||
|
this.uiContext = uiContext;
|
||||||
|
sensorLogs = Arrays.asList(new PlainTextSensorLog(uiContext), new BinarySensorLogRestarter());
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void init() {
|
public synchronized void init() {
|
||||||
if (isInitialized) {
|
if (isInitialized) {
|
||||||
|
@ -102,7 +109,7 @@ public class SensorLogger {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getSecondsSinceFileStart() {
|
public double getSecondsSinceFileStart() {
|
||||||
return sensorLogs.get(0).getSecondsSinceFileStart();
|
return sensorLogs.get(0).getSecondsSinceFileStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.rusefi.sensor_logs.SensorLogger;
|
||||||
public class UIContext {
|
public class UIContext {
|
||||||
private final LinkManager linkManager = new LinkManager();
|
private final LinkManager linkManager = new LinkManager();
|
||||||
|
|
||||||
public SensorLogger sensorLogger = new SensorLogger();
|
public SensorLogger sensorLogger = new SensorLogger(this);
|
||||||
|
|
||||||
public LinkManager getLinkManager() {
|
public LinkManager getLinkManager() {
|
||||||
return linkManager;
|
return linkManager;
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class EtbCommandsPanel {
|
||||||
content.add(new EnumConfigField(uiContext, Fields.DEBUGMODE, "Debug Mode").getContent());
|
content.add(new EnumConfigField(uiContext, Fields.DEBUGMODE, "Debug Mode").getContent());
|
||||||
|
|
||||||
content.add(createMagicSpotsPanel());
|
content.add(createMagicSpotsPanel());
|
||||||
content.add(UiUtils.wrap(new EtbMonteCarloSequence().getButton()));
|
content.add(UiUtils.wrap(new EtbMonteCarloSequence(uiContext).getButton()));
|
||||||
content.add(UiUtils.wrap(new EtbReturnToNeutral().getContent()));
|
content.add(UiUtils.wrap(new EtbReturnToNeutral().getContent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ import com.rusefi.etb.EtbTarget;
|
||||||
import com.rusefi.etb.StandardTestSequence;
|
import com.rusefi.etb.StandardTestSequence;
|
||||||
import com.rusefi.etb.TestSequenceStep;
|
import com.rusefi.etb.TestSequenceStep;
|
||||||
import com.rusefi.io.CommandQueue;
|
import com.rusefi.io.CommandQueue;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static com.romraider.util.ThreadUtil.sleep;
|
import static com.romraider.util.ThreadUtil.sleep;
|
||||||
import static com.rusefi.sensor_logs.SensorLogger.getSecondsSinceFileStart;
|
|
||||||
import static com.rusefi.Timeouts.SECOND;
|
import static com.rusefi.Timeouts.SECOND;
|
||||||
import static com.rusefi.config.generated.Fields.CMD_ETB_DUTY;
|
import static com.rusefi.config.generated.Fields.CMD_ETB_DUTY;
|
||||||
import static com.rusefi.etb.TestSequenceStep.count;
|
import static com.rusefi.etb.TestSequenceStep.count;
|
||||||
|
@ -28,11 +28,13 @@ public class EtbMonteCarloSequence {
|
||||||
private static final double DEFAULT_POSITION = 7;
|
private static final double DEFAULT_POSITION = 7;
|
||||||
private static final int CLT_THRESHOLD = 75;
|
private static final int CLT_THRESHOLD = 75;
|
||||||
private final JButton button = new JButton("ETB I feel lucky!");
|
private final JButton button = new JButton("ETB I feel lucky!");
|
||||||
|
private final UIContext uiContext;
|
||||||
private int counter;
|
private int counter;
|
||||||
|
|
||||||
private double bestResultSoFar = 750;
|
private double bestResultSoFar = 750;
|
||||||
|
|
||||||
public EtbMonteCarloSequence() {
|
public EtbMonteCarloSequence(UIContext uiContext) {
|
||||||
|
this.uiContext = uiContext;
|
||||||
button.addActionListener(e -> {
|
button.addActionListener(e -> {
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ public class EtbMonteCarloSequence {
|
||||||
CommandQueue.getInstance().write("set etb_d " + dFactor);
|
CommandQueue.getInstance().write("set etb_d " + dFactor);
|
||||||
|
|
||||||
MessagesCentral.getInstance().postMessage(EtbMonteCarloSequence.class,
|
MessagesCentral.getInstance().postMessage(EtbMonteCarloSequence.class,
|
||||||
getSecondsSinceFileStart() + " running " + stats);
|
uiContext.sensorLogger.getSecondsSinceFileStart() + " running " + stats);
|
||||||
|
|
||||||
TestSequenceStep firstStep = new EtbTarget(10 * SECOND, DEFAULT_POSITION, null, TestSequenceStep.Condition.YES);
|
TestSequenceStep firstStep = new EtbTarget(10 * SECOND, DEFAULT_POSITION, null, TestSequenceStep.Condition.YES);
|
||||||
TestSequenceStep.Condition condition = new TestSequenceStep.Condition() {
|
TestSequenceStep.Condition condition = new TestSequenceStep.Condition() {
|
||||||
|
@ -108,10 +110,10 @@ public class EtbMonteCarloSequence {
|
||||||
if (cycleResult < bestResultSoFar) {
|
if (cycleResult < bestResultSoFar) {
|
||||||
bestResultSoFar = cycleResult;
|
bestResultSoFar = cycleResult;
|
||||||
MessagesCentral.getInstance().postMessage(EtbMonteCarloSequence.class,
|
MessagesCentral.getInstance().postMessage(EtbMonteCarloSequence.class,
|
||||||
getSecondsSinceFileStart() + ":" + stats + ":new_record:" + bestResultSoFar);
|
uiContext.sensorLogger.getSecondsSinceFileStart() + ":" + stats + ":new_record:" + bestResultSoFar);
|
||||||
}
|
}
|
||||||
MessagesCentral.getInstance().postMessage(EtbMonteCarloSequence.class,
|
MessagesCentral.getInstance().postMessage(EtbMonteCarloSequence.class,
|
||||||
getSecondsSinceFileStart() + ":" + stats + ":result:" + cycleResult);
|
uiContext.sensorLogger.getSecondsSinceFileStart() + ":" + stats + ":result:" + cycleResult);
|
||||||
if (counter == TOTAL_CYCLES_COUNT) {
|
if (counter == TOTAL_CYCLES_COUNT) {
|
||||||
stopETB();
|
stopETB();
|
||||||
MessagesCentral.getInstance().postMessage(EtbTestSequence.class, "ETB MC sequence done!");
|
MessagesCentral.getInstance().postMessage(EtbTestSequence.class, "ETB MC sequence done!");
|
||||||
|
|
Loading…
Reference in New Issue