un-breaking console
This commit is contained in:
parent
7f92b3b40d
commit
02d4515b53
|
@ -4,6 +4,8 @@ import com.opensr5.Logger;
|
|||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* At any given moment of time JVM manages one communication stream
|
||||
*
|
||||
|
@ -24,6 +26,7 @@ public enum BinaryProtocolHolder {
|
|||
}
|
||||
|
||||
public static BinaryProtocol getCurrentStreamState() {
|
||||
Objects.requireNonNull(LinkManager.connector, "connector");
|
||||
return LinkManager.connector.getBinaryProtocol();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
|
|||
public interface LinkConnector extends LinkDecoder {
|
||||
LinkConnector VOID = new LinkConnector() {
|
||||
@Override
|
||||
public void connect(ConnectionStateListener listener) {
|
||||
public void connectAndReadConfiguration(ConnectionStateListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ public interface LinkConnector extends LinkDecoder {
|
|||
}
|
||||
};
|
||||
|
||||
void connect(ConnectionStateListener listener);
|
||||
void connectAndReadConfiguration(ConnectionStateListener listener);
|
||||
|
||||
void send(String command, boolean fireEvent) throws InterruptedException;
|
||||
|
||||
|
|
|
@ -135,6 +135,11 @@ public class LinkManager {
|
|||
|
||||
public static void startAndConnect(String port, ConnectionStateListener stateListener) {
|
||||
FileLog.MAIN.logLine("LinkManager: Starting " + port);
|
||||
start(port);
|
||||
connect(stateListener);
|
||||
}
|
||||
|
||||
public static void start(String port) {
|
||||
if (isLogViewerMode(port)) {
|
||||
connector = LinkConnector.VOID;
|
||||
} else if (TcpConnector.isTcpPort(port)) {
|
||||
|
@ -143,7 +148,6 @@ public class LinkManager {
|
|||
} else {
|
||||
connector = new SerialConnector(port);
|
||||
}
|
||||
connect(stateListener);
|
||||
}
|
||||
|
||||
public static boolean isLogViewerMode(String port) {
|
||||
|
@ -157,11 +161,7 @@ public class LinkManager {
|
|||
public static void connect(ConnectionStateListener listener) {
|
||||
if (connector == null)
|
||||
throw new NullPointerException("connector");
|
||||
connector.connect(listener);
|
||||
}
|
||||
|
||||
public static void connect() {
|
||||
connect(ConnectionStateListener.VOID);
|
||||
connector.connectAndReadConfiguration(listener);
|
||||
}
|
||||
|
||||
public static void send(String command, boolean fireEvent) throws InterruptedException {
|
||||
|
|
|
@ -20,7 +20,7 @@ public class SerialConnector implements LinkConnector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connect(ConnectionStateListener listener) {
|
||||
public void connectAndReadConfiguration(ConnectionStateListener listener) {
|
||||
FileLog.MAIN.logLine("SerialConnector: connecting");
|
||||
portHolder.listener = listener;
|
||||
FileLog.MAIN.logLine("scheduleOpening");
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TcpConnector implements LinkConnector {
|
|||
* this implementation is blocking
|
||||
*/
|
||||
@Override
|
||||
public void connect(ConnectionStateListener listener) {
|
||||
public void connectAndReadConfiguration(ConnectionStateListener listener) {
|
||||
FileLog.MAIN.logLine("Connecting to host=" + hostname + "/port=" + port);
|
||||
OutputStream os;
|
||||
BufferedInputStream stream;
|
||||
|
|
|
@ -40,6 +40,16 @@ public class ConsoleTools {
|
|||
}
|
||||
|
||||
private static void saveBinaryConfig(String[] args) {
|
||||
if (args.length < 2) {
|
||||
System.out.println("Please specify output file name for binary configuration");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
String autoDetectedPort = autoDetectPort();
|
||||
if (autoDetectedPort == null)
|
||||
return;
|
||||
LinkManager.startAndConnect(autoDetectedPort, ConnectionStateListener.VOID);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ public class Launcher {
|
|||
getConfig().getRoot().setProperty(PORT_KEY, port);
|
||||
getConfig().getRoot().setProperty(SPEED_KEY, BaudRateHolder.INSTANCE.baudRate);
|
||||
|
||||
LinkManager.start(port);
|
||||
|
||||
engineSnifferPanel = new EngineSnifferPanel(getConfig().getRoot().getChild("digital_sniffer"));
|
||||
if (!LinkManager.isLogViewerMode(port))
|
||||
engineSnifferPanel.setOutpinListener(LinkManager.engineState);
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MainFrame {
|
|||
}
|
||||
});
|
||||
|
||||
LinkManager.connect(new ConnectionStateListener() {
|
||||
LinkManager.startAndConnect(Launcher.port, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue