refactoring: better dependency control
This commit is contained in:
parent
625b02f964
commit
0e6c445a08
|
@ -137,7 +137,7 @@ public class IoUtil {
|
|||
* TCP connector is blocking
|
||||
*/
|
||||
linkManager.startAndConnect("" + TcpConnector.DEFAULT_PORT, ConnectionStateListener.VOID);
|
||||
linkManager.engineState.registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
linkManager.getEngineState().registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
waitForFirstResponse();
|
||||
}
|
||||
|
||||
|
@ -152,9 +152,9 @@ public class IoUtil {
|
|||
}
|
||||
|
||||
static void realHardwareConnect(LinkManager linkManager, String port) {
|
||||
LinkManager.engineState.registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
LinkManager.engineState.registerStringValueAction(Fields.PROTOCOL_OUTPIN, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
LinkManager.engineState.registerStringValueAction(AverageAnglesUtil.KEY, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
linkManager.getEngineState().registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
linkManager.getEngineState().registerStringValueAction(Fields.PROTOCOL_OUTPIN, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
linkManager.getEngineState().registerStringValueAction(AverageAnglesUtil.KEY, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
|
||||
final CountDownLatch connected = linkManager.connect(port);
|
||||
if (connected.getCount() > 0)
|
||||
|
|
|
@ -114,7 +114,7 @@ public class TestingUtils {
|
|||
|
||||
static String getNextWaveChart(CommandQueue commandQueue) {
|
||||
IoUtil.sendCommand(Fields.CMD_RESET_ENGINE_SNIFFER, commandQueue);
|
||||
String result = getEngineChart();
|
||||
String result = getEngineChart(commandQueue);
|
||||
FileLog.MAIN.logLine("current chart: " + result);
|
||||
return result;
|
||||
}
|
||||
|
@ -123,14 +123,15 @@ public class TestingUtils {
|
|||
* This method is blocking and waits for the next wave chart to arrive
|
||||
*
|
||||
* @return next wave chart in the I/O pipeline
|
||||
* @param commandQueue
|
||||
*/
|
||||
private static String getEngineChart() {
|
||||
private static String getEngineChart(CommandQueue commandQueue) {
|
||||
final CountDownLatch engineChartLatch = new CountDownLatch(1);
|
||||
|
||||
final AtomicReference<String> result = new AtomicReference<>();
|
||||
|
||||
FileLog.MAIN.logLine("waiting for next chart");
|
||||
LinkManager.engineState.replaceStringValueAction(EngineReport.ENGINE_CHART, new EngineState.ValueCallback<String>() {
|
||||
commandQueue.getLinkManager().getEngineState().replaceStringValueAction(EngineReport.ENGINE_CHART, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String value) {
|
||||
engineChartLatch.countDown();
|
||||
|
|
|
@ -121,6 +121,10 @@ public class CommandQueue {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public LinkManager getLinkManager() {
|
||||
return linkManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method handles command confirmations packed as
|
||||
* TODO: add example, todo: refactor method and add unit test
|
||||
|
|
|
@ -140,6 +140,10 @@ public class LinkManager {
|
|||
// throw new IllegalStateException("Communication on wrong thread");
|
||||
}
|
||||
|
||||
public EngineState getEngineState() {
|
||||
return engineState;
|
||||
}
|
||||
|
||||
public static EngineState engineState = new EngineState(new EngineState.EngineStateListenerImpl() {
|
||||
@Override
|
||||
public void beforeLine(String fullLine) {
|
||||
|
|
|
@ -112,7 +112,7 @@ public class TcpConnector implements LinkConnector {
|
|||
final ResponseBuffer rb = new ResponseBuffer(new ResponseBuffer.ResponseListener() {
|
||||
@Override
|
||||
public void onResponse(String line) {
|
||||
LinkManager.engineState.processNewData(line + "\r\n", LinkManager.ENCODER);
|
||||
linkManager.getEngineState().processNewData(line + "\r\n", LinkManager.ENCODER);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi;
|
|||
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.ui.UIContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -15,7 +16,7 @@ public class AverageAnglePanel {
|
|||
private final AverageAngles aa = new AverageAngles();
|
||||
private final JTextArea text = new JTextArea();
|
||||
|
||||
public AverageAnglePanel() {
|
||||
public AverageAnglePanel(UIContext uiContext) {
|
||||
JButton reset = new JButton(RESET.getMessage());
|
||||
reset.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
|
@ -33,7 +34,7 @@ public class AverageAnglePanel {
|
|||
}
|
||||
}, BorderLayout.CENTER);
|
||||
|
||||
SensorSnifferCentral.addListener(new SensorSnifferCentral.AnalogChartListener() {
|
||||
uiContext.sensorSnifferCentral.addListener(new SensorSnifferCentral.AnalogChartListener() {
|
||||
@Override
|
||||
public void onAnalogChart(String message) {
|
||||
int rpm = (int) SensorCentral.getInstance().getValue(Sensor.RPM);
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ConsoleUI {
|
|||
|
||||
engineSnifferPanel = new EngineSnifferPanel(uiContext, getConfig().getRoot().getChild("digital_sniffer"));
|
||||
if (!LinkManager.isLogViewerMode(port))
|
||||
engineSnifferPanel.setOutpinListener(LinkManager.engineState);
|
||||
engineSnifferPanel.setOutpinListener(uiContext.getLinkManager().getEngineState());
|
||||
|
||||
if (LinkManager.isLogViewerMode(port))
|
||||
tabbedPane.addTab("Log Viewer", new LogViewer(uiContext, engineSnifferPanel));
|
||||
|
@ -136,7 +136,7 @@ public class ConsoleUI {
|
|||
|
||||
if (!linkManager.isLogViewer()) {
|
||||
if (tabbedPane.paneSettings.showTriggerShapePane)
|
||||
tabbedPane.addTab("Trigger Shape", new AverageAnglePanel().getPanel());
|
||||
tabbedPane.addTab("Trigger Shape", new AverageAnglePanel(uiContext).getPanel());
|
||||
}
|
||||
|
||||
tabbedPane.addTab("rusEFI Online", new OnlineTab(uiContext).getContent());
|
||||
|
|
|
@ -7,11 +7,10 @@ import java.util.List;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class SensorSnifferCentral {
|
||||
private List<AnalogChartListener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
private static List<AnalogChartListener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
static {
|
||||
LinkManager.engineState.registerStringValueAction(AverageAnglesUtil.KEY, new EngineState.ValueCallback<String>() {
|
||||
public SensorSnifferCentral(LinkManager linkManager) {
|
||||
linkManager.getEngineState().registerStringValueAction(AverageAnglesUtil.KEY, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String message) {
|
||||
for (AnalogChartListener listener : listeners)
|
||||
|
@ -21,7 +20,7 @@ public class SensorSnifferCentral {
|
|||
);
|
||||
}
|
||||
|
||||
public static void addListener(AnalogChartListener listener) {
|
||||
public void addListener(AnalogChartListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class SensorSnifferPane {
|
|||
private boolean paused = false;
|
||||
|
||||
public SensorSnifferPane(UIContext uiContext, Node config) {
|
||||
SensorSnifferCentral.addListener(new SensorSnifferCentral.AnalogChartListener() {
|
||||
uiContext.sensorSnifferCentral.addListener(new SensorSnifferCentral.AnalogChartListener() {
|
||||
@Override
|
||||
public void onAnalogChart(final String message) {
|
||||
// this callback is invoked from the connectivity thread, need to handle in AWT for thread-safety
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.ui;
|
||||
|
||||
import com.rusefi.SensorSnifferCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.sensor_logs.SensorLogger;
|
||||
|
@ -10,6 +11,8 @@ public class UIContext {
|
|||
public SensorLogger sensorLogger = new SensorLogger(this);
|
||||
public GaugesPanel.DetachedRepository DetachedRepositoryINSTANCE = new GaugesPanel.DetachedRepository(this);
|
||||
|
||||
public SensorSnifferCentral sensorSnifferCentral = new SensorSnifferCentral(linkManager);
|
||||
|
||||
public LinkManager getLinkManager() {
|
||||
return linkManager;
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class Wizard {
|
|||
|
||||
panel.add(content, BorderLayout.CENTER);
|
||||
|
||||
panel.add(new AverageAnglePanel().getPanel(), BorderLayout.SOUTH);
|
||||
panel.add(new AverageAnglePanel(null).getPanel(), BorderLayout.SOUTH);
|
||||
|
||||
button.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
|
|
|
@ -84,7 +84,7 @@ public class MainFrame {
|
|||
}
|
||||
});
|
||||
|
||||
LinkManager.engineState.registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, new EngineState.ValueCallback<String>() {
|
||||
consoleUI.uiContext.getLinkManager().getEngineState().registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String firmwareVersion) {
|
||||
Launcher.firmwareVersion.set(firmwareVersion);
|
||||
|
|
|
@ -160,7 +160,7 @@ public class EngineSnifferPanel {
|
|||
|
||||
resetImagePanel();
|
||||
|
||||
LinkManager.engineState.registerStringValueAction(EngineReport.ENGINE_CHART, new EngineState.ValueCallback<String>() {
|
||||
uiContext.getLinkManager().getEngineState().registerStringValueAction(EngineReport.ENGINE_CHART, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String value) {
|
||||
if (isPaused)
|
||||
|
|
Loading…
Reference in New Issue