refactoring
This commit is contained in:
parent
42f3d775e2
commit
885fee5342
|
@ -4,6 +4,7 @@ import com.rusefi.core.EngineState;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.core.SensorCentral;
|
import com.rusefi.core.SensorCentral;
|
||||||
import com.rusefi.io.CommandQueue;
|
import com.rusefi.io.CommandQueue;
|
||||||
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.InvocationConfirmationListener;
|
import com.rusefi.io.InvocationConfirmationListener;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.tcp.TcpConnector;
|
import com.rusefi.io.tcp.TcpConnector;
|
||||||
|
@ -168,7 +169,7 @@ public class IoUtil {
|
||||||
static void realHardwareConnect(String port) {
|
static void realHardwareConnect(String port) {
|
||||||
LinkManager.start(port);
|
LinkManager.start(port);
|
||||||
final CountDownLatch connected = new CountDownLatch(1);
|
final CountDownLatch connected = new CountDownLatch(1);
|
||||||
LinkManager.open(new LinkManager.LinkStateListener() {
|
LinkManager.open(new ConnectionStateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed() {
|
public void onConnectionFailed() {
|
||||||
System.out.println("CONNECTION FAILED, did you specify the right port name?");
|
System.out.println("CONNECTION FAILED, did you specify the right port name?");
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.rusefi.io;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrey Belomutskiy
|
||||||
|
* 3/1/2017
|
||||||
|
*/
|
||||||
|
public interface ConnectionStateListener {
|
||||||
|
ConnectionStateListener VOID = new ConnectionStateListener() {
|
||||||
|
@Override
|
||||||
|
public void onConnectionEstablished() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionFailed() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is invoked once we have connection & configuration from controller
|
||||||
|
*/
|
||||||
|
void onConnectionEstablished();
|
||||||
|
|
||||||
|
void onConnectionFailed();
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ package com.rusefi.io;
|
||||||
public interface LinkConnector extends LinkDecoder {
|
public interface LinkConnector extends LinkDecoder {
|
||||||
LinkConnector VOID = new LinkConnector() {
|
LinkConnector VOID = new LinkConnector() {
|
||||||
@Override
|
@Override
|
||||||
public void connect(LinkManager.LinkStateListener listener) {
|
public void connect(ConnectionStateListener listener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +34,7 @@ public interface LinkConnector extends LinkDecoder {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void connect(LinkManager.LinkStateListener listener);
|
void connect(ConnectionStateListener listener);
|
||||||
|
|
||||||
void send(String command, boolean fireEvent) throws InterruptedException;
|
void send(String command, boolean fireEvent) throws InterruptedException;
|
||||||
|
|
||||||
|
|
|
@ -92,14 +92,14 @@ public class LinkManager {
|
||||||
/**
|
/**
|
||||||
* todo: should this be merged into {@link #start(String)} ?
|
* todo: should this be merged into {@link #start(String)} ?
|
||||||
*/
|
*/
|
||||||
public static void open(LinkStateListener listener) {
|
public static void open(ConnectionStateListener listener) {
|
||||||
if (connector == null)
|
if (connector == null)
|
||||||
throw new NullPointerException("connector");
|
throw new NullPointerException("connector");
|
||||||
connector.connect(listener);
|
connector.connect(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void open() {
|
public static void open() {
|
||||||
open(LinkStateListener.VOID);
|
open(ConnectionStateListener.VOID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(String command, boolean fireEvent) throws InterruptedException {
|
public static void send(String command, boolean fireEvent) throws InterruptedException {
|
||||||
|
@ -125,23 +125,4 @@ public class LinkManager {
|
||||||
return connector.unpackConfirmation(message);
|
return connector.unpackConfirmation(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface LinkStateListener {
|
|
||||||
LinkStateListener VOID = new LinkStateListener() {
|
|
||||||
@Override
|
|
||||||
public void onConnectionFailed() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectionEstablished() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void onConnectionFailed();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is invoked once we have connection & configuration from controller
|
|
||||||
*/
|
|
||||||
void onConnectionEstablished();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package com.rusefi.io.serial;
|
||||||
import com.rusefi.FileLog;
|
import com.rusefi.FileLog;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
import com.rusefi.io.CommunicationLoggingHolder;
|
import com.rusefi.io.CommunicationLoggingHolder;
|
||||||
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.DataListener;
|
import com.rusefi.io.DataListener;
|
||||||
import com.rusefi.io.LinkManager;
|
|
||||||
import jssc.SerialPort;
|
import jssc.SerialPort;
|
||||||
import jssc.SerialPortException;
|
import jssc.SerialPortException;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -30,7 +30,7 @@ public class PortHolder {
|
||||||
@Nullable
|
@Nullable
|
||||||
private SerialPort serialPort;
|
private SerialPort serialPort;
|
||||||
|
|
||||||
boolean openPort(String port, DataListener dataListener, LinkManager.LinkStateListener listener) {
|
boolean openPort(String port, DataListener dataListener, ConnectionStateListener listener) {
|
||||||
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(SerialManager.class, "Opening port: " + port);
|
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(SerialManager.class, "Opening port: " + port);
|
||||||
if (port == null)
|
if (port == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi.io.serial;
|
||||||
import com.rusefi.FileLog;
|
import com.rusefi.FileLog;
|
||||||
import com.rusefi.core.MessagesCentral;
|
import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.io.CommandQueue;
|
import com.rusefi.io.CommandQueue;
|
||||||
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.LinkConnector;
|
import com.rusefi.io.LinkConnector;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ public class SerialConnector implements LinkConnector {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(LinkManager.LinkStateListener listener) {
|
public void connect(ConnectionStateListener listener) {
|
||||||
FileLog.MAIN.logLine("SerialConnector: connecting");
|
FileLog.MAIN.logLine("SerialConnector: connecting");
|
||||||
SerialManager.listener = listener;
|
SerialManager.listener = listener;
|
||||||
FileLog.MAIN.logLine("scheduleOpening");
|
FileLog.MAIN.logLine("scheduleOpening");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.io.serial;
|
package com.rusefi.io.serial;
|
||||||
|
|
||||||
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.DataListener;
|
import com.rusefi.io.DataListener;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ class SerialManager {
|
||||||
LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static LinkManager.LinkStateListener listener;
|
public static ConnectionStateListener listener;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static String[] findSerialPorts() {
|
static String[] findSerialPorts() {
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class TcpConnector implements LinkConnector {
|
||||||
* this implementation is blocking
|
* this implementation is blocking
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void connect(LinkManager.LinkStateListener listener) {
|
public void connect(ConnectionStateListener listener) {
|
||||||
FileLog.MAIN.logLine("Connecting to host=" + hostname + "/port=" + port);
|
FileLog.MAIN.logLine("Connecting to host=" + hostname + "/port=" + port);
|
||||||
OutputStream os;
|
OutputStream os;
|
||||||
BufferedInputStream stream;
|
BufferedInputStream stream;
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class Launcher {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LinkManager.open(new LinkManager.LinkStateListener() {
|
LinkManager.open(new ConnectionStateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed() {
|
public void onConnectionFailed() {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue