parent
06f9faccf5
commit
a060991f73
|
@ -3,7 +3,6 @@ package com.rusefi.binaryprotocol;
|
|||
import com.opensr5.Logger;
|
||||
import com.rusefi.Timeouts;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.IoStream;
|
||||
import etch.util.CircularByteBuffer;
|
||||
import net.jcip.annotations.ThreadSafe;
|
||||
|
||||
|
@ -32,12 +31,6 @@ public class IncomingDataBuffer {
|
|||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static IncomingDataBuffer createDataBuffer(IoStream stream, Logger logger) {
|
||||
IncomingDataBuffer incomingData = new IncomingDataBuffer(logger);
|
||||
stream.setInputListener(incomingData::addData);
|
||||
return incomingData;
|
||||
}
|
||||
|
||||
public byte[] getPacket(Logger logger, String msg, boolean allowLongResponse) throws InterruptedException, EOFException {
|
||||
return getPacket(logger, msg, allowLongResponse, System.currentTimeMillis());
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.opensr5.Logger;
|
|||
import com.opensr5.io.DataListener;
|
||||
import com.opensr5.io.WriteStream;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.binaryprotocol.IoHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -41,8 +40,6 @@ public interface IoStream extends WriteStream {
|
|||
write(packet);
|
||||
}
|
||||
|
||||
IncomingDataBuffer getDataBuffer();
|
||||
|
||||
/**
|
||||
* @param listener would be invoked from unknown implementation-dependent thread
|
||||
*/
|
||||
|
|
|
@ -187,7 +187,7 @@ public class LinkManager {
|
|||
int portPart = TcpConnector.getTcpPort(port);
|
||||
String hostname = TcpConnector.getHostname(port);
|
||||
socket = new Socket(hostname, portPart);
|
||||
return new TcpIoStream(logger, socket);
|
||||
return new TcpIoStream(logger, LinkManager.this, socket);
|
||||
} catch (Throwable e) {
|
||||
stateListener.onConnectionFailed();
|
||||
return null;
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.fazecast.jSerialComm.SerialPortDataListener;
|
|||
import com.fazecast.jSerialComm.SerialPortEvent;
|
||||
import com.opensr5.Logger;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.io.IoStream;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +14,6 @@ import com.rusefi.io.IoStream;
|
|||
* 06/03/2019
|
||||
*/
|
||||
public class SerialIoStreamJSerialComm implements IoStream {
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
private boolean isClosed;
|
||||
private SerialPort sp;
|
||||
private final String port;
|
||||
|
@ -28,12 +26,6 @@ public class SerialIoStreamJSerialComm implements IoStream {
|
|||
this.sp = sp;
|
||||
this.port = port;
|
||||
this.logger = logger;
|
||||
dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -109,7 +109,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
byte command = (byte) dis.read();
|
||||
System.out.println("Got [" + (char) command + "/" + command + "] command");
|
||||
|
||||
TcpIoStream stream = new TcpIoStream(logger, clientSocket);
|
||||
TcpIoStream stream = new TcpIoStream(logger, linkManager, clientSocket);
|
||||
if (command == COMMAND_HELLO) {
|
||||
stream.sendPacket((TS_OK + Fields.TS_SIGNATURE).getBytes(), logger);
|
||||
} else if (command == COMMAND_PROTOCOL) {
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.rusefi.io.tcp;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.io.ByteReader;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -20,27 +20,22 @@ public class TcpIoStream implements IoStream {
|
|||
private final InputStream input;
|
||||
private final OutputStream output;
|
||||
private final Logger logger;
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
private final LinkManager linkManager;
|
||||
private boolean isClosed;
|
||||
|
||||
public TcpIoStream(Logger logger, Socket socket) throws IOException {
|
||||
this(logger, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||
public TcpIoStream(Logger logger, LinkManager linkManager, Socket socket) throws IOException {
|
||||
this(logger, linkManager, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||
}
|
||||
|
||||
private TcpIoStream(Logger logger, InputStream input, OutputStream output) {
|
||||
private TcpIoStream(Logger logger, LinkManager linkManager, InputStream input, OutputStream output) {
|
||||
this.logger = logger;
|
||||
this.linkManager = linkManager;
|
||||
if (input == null)
|
||||
throw new NullPointerException("input");
|
||||
if (output == null)
|
||||
throw new NullPointerException("output");
|
||||
this.output = output;
|
||||
this.input = input;
|
||||
dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.autodetect;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolCommands;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
|
@ -39,7 +40,7 @@ public class SerialAutoChecker implements Runnable {
|
|||
public void run() {
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort, logger);
|
||||
Logger logger = FileLog.LOGGER;
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
IncomingDataBuffer incomingData = BinaryProtocol.createDataBuffer(stream, logger);
|
||||
try {
|
||||
stream.sendPacket(new byte[]{BinaryProtocolCommands.COMMAND_HELLO}, logger);
|
||||
byte[] response = incomingData.getPacket(logger, "", false);
|
||||
|
|
|
@ -308,7 +308,7 @@ public class ConsoleTools {
|
|||
}
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort, FileLog.LOGGER);
|
||||
Logger logger = FileLog.LOGGER;
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
IncomingDataBuffer incomingData = BinaryProtocol.createDataBuffer(stream, logger);
|
||||
byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello");
|
||||
stream.sendPacket(commandBytes, logger);
|
||||
// skipping response
|
||||
|
|
Loading…
Reference in New Issue