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.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;
|
||||
|
@ -168,7 +169,7 @@ public class IoUtil {
|
|||
static void realHardwareConnect(String port) {
|
||||
LinkManager.start(port);
|
||||
final CountDownLatch connected = new CountDownLatch(1);
|
||||
LinkManager.open(new LinkManager.LinkStateListener() {
|
||||
LinkManager.open(new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
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 {
|
||||
LinkConnector VOID = new LinkConnector() {
|
||||
@Override
|
||||
public void connect(LinkManager.LinkStateListener listener) {
|
||||
public void connect(ConnectionStateListener listener) {
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
|
|
|
@ -92,14 +92,14 @@ public class LinkManager {
|
|||
/**
|
||||
* todo: should this be merged into {@link #start(String)} ?
|
||||
*/
|
||||
public static void open(LinkStateListener listener) {
|
||||
public static void open(ConnectionStateListener listener) {
|
||||
if (connector == null)
|
||||
throw new NullPointerException("connector");
|
||||
connector.connect(listener);
|
||||
}
|
||||
|
||||
public static void open() {
|
||||
open(LinkStateListener.VOID);
|
||||
open(ConnectionStateListener.VOID);
|
||||
}
|
||||
|
||||
public static void send(String command, boolean fireEvent) throws InterruptedException {
|
||||
|
@ -125,23 +125,4 @@ public class LinkManager {
|
|||
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.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.io.CommunicationLoggingHolder;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.DataListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -30,7 +30,7 @@ public class PortHolder {
|
|||
@Nullable
|
||||
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);
|
||||
if (port == null)
|
||||
return false;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi.io.serial;
|
|||
import com.rusefi.FileLog;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
|
@ -16,7 +17,7 @@ public class SerialConnector implements LinkConnector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connect(LinkManager.LinkStateListener listener) {
|
||||
public void connect(ConnectionStateListener listener) {
|
||||
FileLog.MAIN.logLine("SerialConnector: connecting");
|
||||
SerialManager.listener = listener;
|
||||
FileLog.MAIN.logLine("scheduleOpening");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.DataListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
|
@ -18,7 +19,7 @@ class SerialManager {
|
|||
LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
||||
}
|
||||
};
|
||||
public static LinkManager.LinkStateListener listener;
|
||||
public static ConnectionStateListener listener;
|
||||
|
||||
/*
|
||||
static String[] findSerialPorts() {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class TcpConnector implements LinkConnector {
|
|||
* this implementation is blocking
|
||||
*/
|
||||
@Override
|
||||
public void connect(LinkManager.LinkStateListener listener) {
|
||||
public void connect(ConnectionStateListener listener) {
|
||||
FileLog.MAIN.logLine("Connecting to host=" + hostname + "/port=" + port);
|
||||
OutputStream os;
|
||||
BufferedInputStream stream;
|
||||
|
|
|
@ -233,7 +233,7 @@ public class Launcher {
|
|||
}
|
||||
});
|
||||
|
||||
LinkManager.open(new LinkManager.LinkStateListener() {
|
||||
LinkManager.open(new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue