refactoring: better dependency control
This commit is contained in:
parent
d3f8600373
commit
ac1973a62d
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import static com.rusefi.IoUtil.*;
|
||||
import static com.rusefi.RealHwTest.startRealHardwareTest;
|
||||
|
@ -10,6 +11,7 @@ public class EnduranceTest {
|
|||
private static final int DEFAULT_COUNT = 2000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
LinkManager linkManager = new LinkManager();
|
||||
long start = System.currentTimeMillis();
|
||||
int count = parseCount(args);
|
||||
try {
|
||||
|
@ -22,7 +24,7 @@ public class EnduranceTest {
|
|||
|
||||
FileLog.MAIN.logLine("Running " + count + " cycles");
|
||||
|
||||
IoUtil.realHardwareConnect(port);
|
||||
IoUtil.realHardwareConnect(linkManager, port);
|
||||
for (int i = 0; i < count; i++) {
|
||||
AutoTest.currentEngineType = 3;
|
||||
sendCommand("set " + Fields.CMD_ENGINE_TYPE + " " + 3, AutoTest.COMPLEX_COMMAND_RETRY, Timeouts.SET_ENGINE_TIMEOUT);
|
||||
|
|
|
@ -151,12 +151,12 @@ public class IoUtil {
|
|||
}
|
||||
}
|
||||
|
||||
static void realHardwareConnect(String port) {
|
||||
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);
|
||||
|
||||
final CountDownLatch connected = LinkManager.connect(port);
|
||||
final CountDownLatch connected = linkManager.connect(port);
|
||||
if (connected.getCount() > 0)
|
||||
throw new IllegalStateException("Not connected in time");
|
||||
}
|
||||
|
|
|
@ -83,7 +83,8 @@ public class RealHwTest {
|
|||
}
|
||||
|
||||
private static void runRealHardwareTest(String port) throws Exception {
|
||||
IoUtil.realHardwareConnect(port);
|
||||
mainTestBody(new LinkManager());
|
||||
LinkManager linkManager = new LinkManager();
|
||||
IoUtil.realHardwareConnect(linkManager, port);
|
||||
mainTestBody(linkManager);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.concurrent.*;
|
|||
*/
|
||||
public class LinkManager {
|
||||
@NotNull
|
||||
public static CountDownLatch connect(String port) {
|
||||
public CountDownLatch connect(String port) {
|
||||
final CountDownLatch connected = new CountDownLatch(1);
|
||||
startAndConnect(port, new ConnectionStateListener() {
|
||||
@Override
|
||||
|
@ -141,14 +141,14 @@ public class LinkManager {
|
|||
}
|
||||
});
|
||||
|
||||
public static LinkConnector connector;
|
||||
private static LinkConnector connector;
|
||||
|
||||
/**
|
||||
* This flag controls if mock controls are needed
|
||||
*/
|
||||
public static boolean isSimulationMode;
|
||||
|
||||
public static void startAndConnect(String port, ConnectionStateListener stateListener) {
|
||||
public void startAndConnect(String port, ConnectionStateListener stateListener) {
|
||||
Objects.requireNonNull(port, "port");
|
||||
start(port);
|
||||
connector.connectAndReadConfiguration(stateListener);
|
||||
|
|
|
@ -26,7 +26,8 @@ public class CmdLine {
|
|||
private static void executeCommand(String command, String port) {
|
||||
System.out.println("Sending " + command);
|
||||
System.out.println("Sending to " + port);
|
||||
IoUtil.realHardwareConnect(port);
|
||||
LinkManager linkManager = new LinkManager();
|
||||
IoUtil.realHardwareConnect(linkManager, port);
|
||||
|
||||
IoUtil.sendCommand(command);
|
||||
System.out.println("Done!");
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ConsoleUI {
|
|||
getConfig().getRoot().setProperty(PORT_KEY, port);
|
||||
getConfig().getRoot().setProperty(SPEED_KEY, BaudRateHolder.INSTANCE.baudRate);
|
||||
|
||||
LinkManager.start(port);
|
||||
uiContext.getLinkManager().start(port);
|
||||
|
||||
engineSnifferPanel = new EngineSnifferPanel(uiContext, getConfig().getRoot().getChild("digital_sniffer"));
|
||||
if (!LinkManager.isLogViewerMode(port))
|
||||
|
@ -138,7 +138,7 @@ public class ConsoleUI {
|
|||
tabbedPane.addTab("Trigger Shape", new AverageAnglePanel().getPanel());
|
||||
}
|
||||
|
||||
tabbedPane.addTab("rusEFI Online", new OnlineTab().getContent());
|
||||
tabbedPane.addTab("rusEFI Online", new OnlineTab(uiContext).getContent());
|
||||
|
||||
uiContext.sensorLogger.init();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.autodetect;
|
|||
|
||||
import com.rusefi.IoUtil;
|
||||
import com.rusefi.io.ConnectionStatusLogic;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.light.LightweightGUI;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -9,7 +10,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
public class ReconnectSandbox {
|
||||
public static void main(String[] args) {
|
||||
|
||||
LightweightGUI.waitForDeviceAndStart();
|
||||
LinkManager linkManager = new LinkManager();
|
||||
|
||||
LightweightGUI.waitForDeviceAndStart(linkManager);
|
||||
|
||||
AtomicBoolean status = new AtomicBoolean();
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public class OnlineTab {
|
|||
|
||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
public OnlineTab() {
|
||||
public OnlineTab(UIContext uiContext) {
|
||||
AuthTokenPanel authTokenPanel = new AuthTokenPanel();
|
||||
|
||||
content.add(Misc.getRusEFI_online_manual());
|
||||
|
@ -25,7 +25,7 @@ public class OnlineTab {
|
|||
upload.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Msq tune = Msq.valueOf(LinkManager.connector.getBinaryProtocol().getControllerConfiguration());
|
||||
Msq tune = Msq.valueOf(uiContext.getLinkManager().getCurrentStreamState().getControllerConfiguration());
|
||||
Online.uploadTune(tune, authTokenPanel, content, null);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -67,7 +67,8 @@ public class MainFrame {
|
|||
}
|
||||
});
|
||||
|
||||
LinkManager.startAndConnect(consoleUI.port, new ConnectionStateListener() {
|
||||
final LinkManager linkManager = consoleUI.uiContext.getLinkManager();
|
||||
linkManager.startAndConnect(consoleUI.port, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ public class MainFrame {
|
|||
tabbedPane.settingsTab.showContent();
|
||||
tabbedPane.logsManager.showContent();
|
||||
tabbedPane.fuelTunePane.showContent();
|
||||
BinaryProtocolServer.start(consoleUI.uiContext.getLinkManager());
|
||||
BinaryProtocolServer.start(linkManager);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.rusefi.io.ConnectionStateListener;
|
|||
import com.rusefi.io.ConnectionStatusLogic;
|
||||
import com.rusefi.io.ConnectionWatchdog;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.sensor_logs.SensorLogger;
|
||||
import com.rusefi.ui.UIContext;
|
||||
import com.rusefi.ui.util.FrameHelper;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
@ -21,13 +20,15 @@ import static com.rusefi.StartupFrame.createLogoLabel;
|
|||
|
||||
public class LightweightGUI {
|
||||
|
||||
private final UIContext uiContext;
|
||||
private FrameHelper frameHelper = new FrameHelper();
|
||||
private JPanel content = new JPanel(new BorderLayout());
|
||||
|
||||
private JPanel connectedPanel = new JPanel();
|
||||
private JLabel connectedLabel = new JLabel();
|
||||
|
||||
public LightweightGUI() {
|
||||
public LightweightGUI(UIContext uiContext) {
|
||||
this.uiContext = uiContext;
|
||||
frameHelper.getFrame().setTitle("rusEFI Lightweight " + rusEFIVersion.CONSOLE_VERSION);
|
||||
|
||||
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
|
@ -66,12 +67,12 @@ public class LightweightGUI {
|
|||
|
||||
UIContext uiContext = new UIContext();
|
||||
|
||||
LightweightGUI gui = new LightweightGUI();
|
||||
LightweightGUI gui = new LightweightGUI(uiContext);
|
||||
|
||||
gui.setConnectedUI(false);
|
||||
|
||||
|
||||
new Thread(() -> waitForDeviceAndStart()).start();
|
||||
new Thread(() -> waitForDeviceAndStart(uiContext.getLinkManager())).start();
|
||||
|
||||
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
|
||||
@Override
|
||||
|
@ -104,11 +105,11 @@ public class LightweightGUI {
|
|||
connectedPanel.setBackground(isConnected ? Color.green : Color.red);
|
||||
}
|
||||
|
||||
public static void waitForDeviceAndStart() {
|
||||
public static void waitForDeviceAndStart(LinkManager linkManager) {
|
||||
String autoDetectedPort = detectPortUntilDetected();
|
||||
System.out.println("First time port detected: " + autoDetectedPort);
|
||||
|
||||
LinkManager.startAndConnect(autoDetectedPort, ConnectionStateListener.VOID);
|
||||
linkManager.startAndConnect(autoDetectedPort, ConnectionStateListener.VOID);
|
||||
|
||||
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
|
||||
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
|
||||
|
|
Loading…
Reference in New Issue