* ADD: Port closing & and reconnection attempt at restart event * FIX: Syntax error * Explicitly initialization of lastTriedPort * Explicitly initialization of isStarted * Revert "Explicitly initialization of isStarted" This reverts commit 4acdd44d6cb7c46caa22f1dece4aef61798756fd. * DEL: Dead code Co-authored-by: alxrMironov <330OMcorporative>
This commit is contained in:
parent
2914f53d0f
commit
fa63c99ed3
|
@ -46,6 +46,8 @@ public class LinkManager implements Closeable {
|
||||||
public static final String LOG_VIEWER = "log viewer";
|
public static final String LOG_VIEWER = "log viewer";
|
||||||
private final CommandQueue commandQueue;
|
private final CommandQueue commandQueue;
|
||||||
|
|
||||||
|
private String lastTriedPort = null;
|
||||||
|
|
||||||
private LinkConnector connector = LinkConnector.VOID;
|
private LinkConnector connector = LinkConnector.VOID;
|
||||||
private boolean isStarted;
|
private boolean isStarted;
|
||||||
private boolean compositeLogicEnabled = true;
|
private boolean compositeLogicEnabled = true;
|
||||||
|
@ -209,6 +211,7 @@ public class LinkManager implements Closeable {
|
||||||
public void start(String port, ConnectionFailedListener stateListener) {
|
public void start(String port, ConnectionFailedListener stateListener) {
|
||||||
Objects.requireNonNull(port, "port");
|
Objects.requireNonNull(port, "port");
|
||||||
log.info("LinkManager: Starting " + port);
|
log.info("LinkManager: Starting " + port);
|
||||||
|
lastTriedPort = port; // Save port before connection attempt
|
||||||
if (isLogViewerMode(port)) {
|
if (isLogViewerMode(port)) {
|
||||||
setConnector(LinkConnector.VOID);
|
setConnector(LinkConnector.VOID);
|
||||||
} else if (PCAN.equals(port)) {
|
} else if (PCAN.equals(port)) {
|
||||||
|
@ -272,13 +275,20 @@ public class LinkManager implements Closeable {
|
||||||
|
|
||||||
public void restart() {
|
public void restart() {
|
||||||
ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.NOT_CONNECTED);
|
ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.NOT_CONNECTED);
|
||||||
connector.restart();
|
close(); // Explicitly kill the connection (call connectors destructor??????)
|
||||||
|
|
||||||
|
String[] ports = getCommPorts();
|
||||||
|
boolean isPortAvaliableAgain = Arrays.stream(ports).anyMatch(lastTriedPort::equals);
|
||||||
|
if(isPortAvaliableAgain) {
|
||||||
|
connect(lastTriedPort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (connector != null)
|
if (connector != null)
|
||||||
connector.stop();
|
connector.stop();
|
||||||
|
isStarted = false; // Connector is dead and cant be in started state (Otherwise the Exception will raised)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String unpackConfirmation(String message) {
|
public static String unpackConfirmation(String message) {
|
||||||
|
|
Loading…
Reference in New Issue