progress!!!

This commit is contained in:
rusefi 2020-06-07 15:44:42 -04:00
parent dbbc0644d4
commit 4b81136a1f
8 changed files with 104 additions and 31 deletions

View File

@ -6,10 +6,14 @@ package com.rusefi;
public interface Timeouts {
int SECOND = 1000;
int COMMAND_TIMEOUT_SEC = 10; // seconds
/**
* The longest justified binary communication delay would be related to stm32f407 flash saving time
*/
int BINARY_IO_TIMEOUT = 5 * SECOND;
int READ_IMAGE_TIMEOUT = 60 * SECOND;
int CONNECTION_RESTART_DELAY = 20 * SECOND;
int CONNECTION_RESTART_DELAY = BINARY_IO_TIMEOUT;
int CMD_TIMEOUT = 20 * SECOND;
int SET_ENGINE_TIMEOUT = 60 * SECOND;

View File

@ -9,9 +9,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* todo: eliminate logic duplication with {@link ConnectionWatchdog}
*/
public class ConnectionStatusLogic {
@NotNull
private ConnectionStatusValue value = ConnectionStatusValue.NOT_CONNECTED;

View File

@ -75,7 +75,7 @@ public class ConsoleUI {
tabbedPane.addTab("Log Viewer", new LogViewer(engineSnifferPanel));
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
LinkManager.restart();
}).start();

View File

@ -92,13 +92,11 @@ public class SensorLogger {
private SensorLogger() {
}
private static boolean isRunning;
public static void init() {
if (isRunning)
return;
isRunning = true;
static {
init();
}
private static void init() {
SensorCentral.getInstance().addListener(Sensor.TIME_SECONDS, new SensorCentral.SensorListener() {
@Override
public void onSensorUpdate(double value) {
@ -114,7 +112,6 @@ public class SensorLogger {
writeSensorLogLine();
}
});
}
private static void writeSensorLogLine() {

View File

@ -0,0 +1,24 @@
package com.rusefi.autodetect;
import com.rusefi.IoUtil;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.ui.light.LightweightGUI;
import java.util.concurrent.atomic.AtomicBoolean;
public class ReconnectSandbox {
public static void main(String[] args) {
LightweightGUI.waitForDeviceAndStart();
AtomicBoolean status = new AtomicBoolean();
ConnectionStatusLogic.INSTANCE.addListener(isConnected -> status.set(isConnected));
while (true) {
System.out.println("Hello " + status);
IoUtil.sleepSeconds(1);
}
}
}

View File

@ -158,17 +158,7 @@ public class ConsoleTools {
System.err.println("rusEFI not detected");
return;
}
LinkManager.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
@Override
public void onConnectionEstablished() {
SensorLogger.init();
}
@Override
public void onConnectionFailed() {
}
});
LinkManager.startAndConnect(autoDetectedPort, ConnectionStateListener.VOID);
}
private static void invokeCallback(String callback) {

View File

@ -88,7 +88,6 @@ public class MainFrame {
@Override
public void onUpdate(String firmwareVersion) {
Launcher.firmwareVersion.set(firmwareVersion);
SensorLogger.init();
setTitle();
VersionChecker.getInstance().onFirmwareVersion(firmwareVersion);
}

View File

@ -1,7 +1,11 @@
package com.rusefi.ui.light;
import com.rusefi.StartupFrame;
import com.rusefi.rusEFIVersion;
import com.rusefi.*;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.io.ConnectionStateListener;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.io.ConnectionWatchdog;
import com.rusefi.io.LinkManager;
import com.rusefi.ui.util.FrameHelper;
import javax.swing.*;
@ -10,14 +14,25 @@ import java.awt.*;
import static com.rusefi.StartupFrame.createLogoLabel;
public class LightweightGUI {
public static void start() {
FrameHelper frameHelper = new FrameHelper();
JPanel content = new JPanel(new BorderLayout());
private FrameHelper frameHelper = new FrameHelper();
private JPanel content = new JPanel(new BorderLayout());
private JPanel connectedPanel = new JPanel();
private JLabel connectedLabel = new JLabel();
public LightweightGUI() {
frameHelper.getFrame().setTitle("rusEFI Lightweight " + rusEFIVersion.CONSOLE_VERSION);
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
connectedPanel.add(connectedLabel);
topPanel.add(connectedPanel);
topPanel.add(new InternetStatus().getContent());
content.add(topPanel, BorderLayout.NORTH);
content.add(new JLabel(StartupFrame.LINK_TEXT), BorderLayout.CENTER);
@ -25,8 +40,55 @@ public class LightweightGUI {
if (logo != null) {
content.add(logo, BorderLayout.EAST);
}
frameHelper.showFrame(content, true);
}
public static void start() {
LightweightGUI gui = new LightweightGUI();
gui.setConnectedUI(false);
new Thread(() -> waitForDeviceAndStart()).start();
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
@Override
public void onConnectionStatus(boolean isConnected) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
gui.setConnectedUI(isConnected);
}
});
}
});
}
private void setConnectedUI(boolean isConnected) {
connectedLabel.setText(isConnected ? "Connected" : "NOT CONNECTED");
connectedPanel.setBackground(isConnected ? Color.green : Color.red);
}
public static void waitForDeviceAndStart() {
String autoDetectedPort = detectPortUntilDetected();
System.out.println("First time port detected: " + autoDetectedPort);
LinkManager.startAndConnect(autoDetectedPort, ConnectionStateListener.VOID);
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
LinkManager.restart();
}).start();
}
private static String detectPortUntilDetected() {
while (true) {
String port = PortDetector.autoDetectSerial(null);
System.out.println("Detected " + port);
if (port != null)
return port;
IoUtil.sleepSeconds(1);
}
}
}