still trying to simplify things
This commit is contained in:
parent
aef391b2bd
commit
7f92b3b40d
|
@ -5,6 +5,7 @@ import com.rusefi.core.EngineState;
|
|||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.InvocationConfirmationListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
|
@ -131,11 +132,11 @@ public class IoUtil {
|
|||
// Thread.sleep(3000);
|
||||
//
|
||||
// FileLog.rlog("Got a TCP port! Connecting...");
|
||||
LinkManager.start("" + TcpConnector.DEFAULT_PORT);
|
||||
|
||||
/**
|
||||
* TCP connector is blocking
|
||||
*/
|
||||
LinkManager.open();
|
||||
LinkManager.startAndConnect("" + TcpConnector.DEFAULT_PORT, ConnectionStateListener.VOID);
|
||||
LinkManager.engineState.registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
waitForFirstResponse();
|
||||
}
|
||||
|
|
|
@ -18,9 +18,8 @@ import java.util.concurrent.*;
|
|||
public class LinkManager {
|
||||
@NotNull
|
||||
public static CountDownLatch connect(String port) {
|
||||
start(port);
|
||||
final CountDownLatch connected = new CountDownLatch(1);
|
||||
open(new ConnectionStateListener() {
|
||||
startAndConnect(port, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
System.out.println("CONNECTION FAILED, did you specify the right port name?");
|
||||
|
@ -134,7 +133,7 @@ public class LinkManager {
|
|||
*/
|
||||
public static boolean isSimulationMode;
|
||||
|
||||
public static void start(String port) {
|
||||
public static void startAndConnect(String port, ConnectionStateListener stateListener) {
|
||||
FileLog.MAIN.logLine("LinkManager: Starting " + port);
|
||||
if (isLogViewerMode(port)) {
|
||||
connector = LinkConnector.VOID;
|
||||
|
@ -144,6 +143,7 @@ public class LinkManager {
|
|||
} else {
|
||||
connector = new SerialConnector(port);
|
||||
}
|
||||
connect(stateListener);
|
||||
}
|
||||
|
||||
public static boolean isLogViewerMode(String port) {
|
||||
|
@ -154,17 +154,14 @@ public class LinkManager {
|
|||
return connector == LinkConnector.VOID;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo: should this be merged into {@link #start(String)} ?
|
||||
*/
|
||||
public static void open(ConnectionStateListener listener) {
|
||||
public static void connect(ConnectionStateListener listener) {
|
||||
if (connector == null)
|
||||
throw new NullPointerException("connector");
|
||||
connector.connect(listener);
|
||||
}
|
||||
|
||||
public static void open() {
|
||||
open(ConnectionStateListener.VOID);
|
||||
public static void connect() {
|
||||
connect(ConnectionStateListener.VOID);
|
||||
}
|
||||
|
||||
public static void send(String command, boolean fireEvent) throws InterruptedException {
|
||||
|
|
|
@ -3,11 +3,9 @@ package com.rusefi.io.serial;
|
|||
import com.fazecast.jSerialComm.SerialPort;
|
||||
import com.fazecast.jSerialComm.SerialPortDataListener;
|
||||
import com.fazecast.jSerialComm.SerialPortEvent;
|
||||
import com.opensr5.Logger;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.io.IoStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* https://github.com/Fazecast/jSerialComm looks to be alive as of 2019
|
||||
|
@ -74,16 +72,15 @@ public class SerialIoStreamJSerialComm implements IoStream {
|
|||
sp.writeBytes(bytes, bytes.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just open physical serial and not much more
|
||||
* @see PortHolder#connectAndReadConfiguration()
|
||||
*/
|
||||
public static IoStream openPort(String port) {
|
||||
return openPort(port, BaudRateHolder.INSTANCE.baudRate, FileLog.LOGGER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IoStream openPort(String port, int baudRate, Logger logger) {
|
||||
logger.info("[SerialIoStreamJSerialComm] " + port);
|
||||
SerialPort sp = SerialPort.getCommPort(port);
|
||||
sp.setBaudRate(baudRate);
|
||||
sp.openPort();
|
||||
return new SerialIoStreamJSerialComm(sp, port);
|
||||
FileLog.LOGGER.info("[SerialIoStreamJSerialComm] " + port);
|
||||
SerialPort serialPort = SerialPort.getCommPort(port);
|
||||
serialPort.setBaudRate(BaudRateHolder.INSTANCE.baudRate);
|
||||
serialPort.openPort();
|
||||
return new SerialIoStreamJSerialComm(serialPort, port);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.rusefi.io.IoStream;
|
|||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import com.rusefi.maintenance.ExecHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
@ -24,6 +25,7 @@ public class ConsoleTools {
|
|||
TOOLS.put("headless", ConsoleTools::runHeadless);
|
||||
TOOLS.put("compile", ConsoleTools::invokeCompileExpressionTool);
|
||||
TOOLS.put("ptrace_enums", ConsoleTools::runPerfTraceTool);
|
||||
TOOLS.put("save_binary_configuration", ConsoleTools::saveBinaryConfig);
|
||||
TOOLS.put("functional_test", ConsoleTools::runFunctionalTest);
|
||||
TOOLS.put("compile_fsio_file", ConsoleTools::runCompileTool);
|
||||
TOOLS.put("firing_order", ConsoleTools::runFiringOrderTool);
|
||||
|
@ -37,8 +39,12 @@ public class ConsoleTools {
|
|||
}
|
||||
}
|
||||
|
||||
private static void saveBinaryConfig(String[] args) {
|
||||
}
|
||||
|
||||
|
||||
private static void sendCommand(String command) throws IOException {
|
||||
String autoDetectedPort = Launcher.autoDetectPort();
|
||||
String autoDetectedPort = autoDetectPort();
|
||||
if (autoDetectedPort == null)
|
||||
return;
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort);
|
||||
|
@ -86,8 +92,7 @@ public class ConsoleTools {
|
|||
System.err.println("rusEFI not detected");
|
||||
return;
|
||||
}
|
||||
LinkManager.start(autoDetectedPort);
|
||||
LinkManager.connector.connect(new ConnectionStateListener() {
|
||||
LinkManager.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
SensorLogger.init();
|
||||
|
@ -143,6 +148,16 @@ public class ConsoleTools {
|
|||
}
|
||||
return false; }
|
||||
|
||||
@Nullable
|
||||
private static String autoDetectPort() {
|
||||
String autoDetectedPort = PortDetector.autoDetectPort(null);
|
||||
if (autoDetectedPort == null) {
|
||||
System.err.println("rusEFI not detected");
|
||||
return null;
|
||||
}
|
||||
return autoDetectedPort;
|
||||
}
|
||||
|
||||
interface ConsoleTool {
|
||||
void runTool(String args[]) throws Exception;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class Launcher {
|
|||
|
||||
private static Frame staticFrame;
|
||||
|
||||
MainFrame mainFrame = new MainFrame(tabbedPane);
|
||||
private MainFrame mainFrame = new MainFrame(tabbedPane);
|
||||
|
||||
/**
|
||||
* We can listen to tab activation event if we so desire
|
||||
|
@ -203,16 +203,6 @@ public class Launcher {
|
|||
SwingUtilities.invokeAndWait(() -> awtCode(args));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static String autoDetectPort() {
|
||||
String autoDetectedPort = PortDetector.autoDetectPort(null);
|
||||
if (autoDetectedPort == null) {
|
||||
System.err.println("rusEFI not detected");
|
||||
return null;
|
||||
}
|
||||
return autoDetectedPort;
|
||||
}
|
||||
|
||||
private static void awtCode(String[] args) {
|
||||
if (JustOneInstance.isAlreadyRunning()) {
|
||||
int result = JOptionPane.showConfirmDialog(null, "Looks like another instance is already running. Do you really want to start another instance?",
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MainFrame {
|
|||
}
|
||||
});
|
||||
|
||||
LinkManager.open(new ConnectionStateListener() {
|
||||
LinkManager.connect(new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue