reducing complexity
This commit is contained in:
parent
0c0eefbb4f
commit
a0a163b8e5
|
@ -2,6 +2,7 @@ package com.rusefi.binaryprotocol;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
/**
|
||||
* At any given moment of time JVM manages one communication stream
|
||||
|
@ -26,6 +27,6 @@ public enum BinaryProtocolHolder {
|
|||
}
|
||||
|
||||
public BinaryProtocol getCurrentStreamState() {
|
||||
return currentStream;
|
||||
return LinkManager.connector.getBinaryProtocol();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.rusefi.io;
|
||||
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
|
||||
/**
|
||||
* @author Andrey Belomutskiy
|
||||
* 3/3/14
|
||||
|
@ -18,6 +20,11 @@ public interface LinkConnector extends LinkDecoder {
|
|||
public void restart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryProtocol getBinaryProtocol() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unpack(String packet) {
|
||||
return LinkDecoder.TEXT_PROTOCOL_DECODER.unpack(packet);
|
||||
|
@ -30,4 +37,5 @@ public interface LinkConnector extends LinkDecoder {
|
|||
|
||||
void restart();
|
||||
|
||||
BinaryProtocol getBinaryProtocol();
|
||||
}
|
||||
|
|
|
@ -126,6 +126,7 @@ public class LinkManager {
|
|||
ConnectionWatchdog.onDataArrived();
|
||||
}
|
||||
});
|
||||
|
||||
public static LinkConnector connector;
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,14 +25,12 @@ public class PortHolder {
|
|||
public ConnectionStateListener listener;
|
||||
private final Object portLock = new Object();
|
||||
|
||||
@Nullable
|
||||
private BinaryProtocol bp;
|
||||
|
||||
protected PortHolder() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IoStream serialPort;
|
||||
|
||||
public String port;
|
||||
|
||||
boolean connectAndReadConfiguration() {
|
||||
|
@ -43,12 +41,10 @@ public class PortHolder {
|
|||
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
|
||||
synchronized (portLock) {
|
||||
this.serialPort = stream;
|
||||
bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, stream);
|
||||
portLock.notifyAll();
|
||||
}
|
||||
|
||||
bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, stream);
|
||||
|
||||
boolean result = bp.connectAndReadConfiguration(dataListener);
|
||||
if (listener != null) {
|
||||
if (result) {
|
||||
|
@ -62,10 +58,10 @@ public class PortHolder {
|
|||
|
||||
public void close() {
|
||||
synchronized (portLock) {
|
||||
if (serialPort != null) {
|
||||
if (bp != null) {
|
||||
try {
|
||||
serialPort.close();
|
||||
serialPort = null;
|
||||
bp.close();
|
||||
bp = null;
|
||||
} finally {
|
||||
portLock.notifyAll();
|
||||
}
|
||||
|
@ -73,6 +69,11 @@ public class PortHolder {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BinaryProtocol getBp() {
|
||||
return bp;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method blocks till a connection is available
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
|
@ -32,6 +33,11 @@ public class SerialConnector implements LinkConnector {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryProtocol getBinaryProtocol() {
|
||||
return portHolder.getBp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restart() {
|
||||
LinkManager.execute(new Runnable() {
|
||||
|
|
|
@ -37,6 +37,10 @@ public class TcpConnector implements LinkConnector {
|
|||
}
|
||||
}
|
||||
|
||||
public BinaryProtocol getBinaryProtocol() {
|
||||
return bp;
|
||||
}
|
||||
|
||||
public static boolean isTcpPort(String port) {
|
||||
try {
|
||||
getTcpPort(port);
|
||||
|
|
Loading…
Reference in New Issue