proxy progress
This commit is contained in:
parent
720ade2319
commit
968015f5ec
|
@ -118,7 +118,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
}
|
||||
};
|
||||
|
||||
incomingData = createDataBuffer(stream, logger);
|
||||
incomingData = stream.getDataBuffer();
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
rpmListener = value -> {
|
||||
if (value <= COMPOSITE_OFF_RPM) {
|
||||
|
@ -131,12 +131,6 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
};
|
||||
}
|
||||
|
||||
public static IncomingDataBuffer createDataBuffer(IoStream stream, Logger logger) {
|
||||
IncomingDataBuffer incomingData = new IncomingDataBuffer(logger);
|
||||
stream.setInputListener(incomingData::addData);
|
||||
return incomingData;
|
||||
}
|
||||
|
||||
public static void sleep(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
|
|
|
@ -3,6 +3,7 @@ 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;
|
||||
|
||||
|
@ -31,6 +32,12 @@ 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,6 +4,7 @@ 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;
|
||||
|
@ -40,6 +41,8 @@ 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, LinkManager.this, socket);
|
||||
return new TcpIoStream(logger, socket);
|
||||
} catch (Throwable e) {
|
||||
stateListener.onConnectionFailed();
|
||||
return null;
|
||||
|
|
|
@ -5,6 +5,7 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -14,6 +15,7 @@ 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;
|
||||
|
@ -26,6 +28,12 @@ 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, linkManager, clientSocket);
|
||||
TcpIoStream stream = new TcpIoStream(logger, 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,22 +20,27 @@ public class TcpIoStream implements IoStream {
|
|||
private final InputStream input;
|
||||
private final OutputStream output;
|
||||
private final Logger logger;
|
||||
private final LinkManager linkManager;
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
private boolean isClosed;
|
||||
|
||||
public TcpIoStream(Logger logger, LinkManager linkManager, Socket socket) throws IOException {
|
||||
this(logger, linkManager, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||
public TcpIoStream(Logger logger, Socket socket) throws IOException {
|
||||
this(logger, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||
}
|
||||
|
||||
private TcpIoStream(Logger logger, LinkManager linkManager, InputStream input, OutputStream output) {
|
||||
private TcpIoStream(Logger logger, 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,7 +2,6 @@ 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;
|
||||
|
@ -40,7 +39,7 @@ public class SerialAutoChecker implements Runnable {
|
|||
public void run() {
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort, logger);
|
||||
Logger logger = FileLog.LOGGER;
|
||||
IncomingDataBuffer incomingData = BinaryProtocol.createDataBuffer(stream, logger);
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
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 = BinaryProtocol.createDataBuffer(stream, logger);
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello");
|
||||
stream.sendPacket(commandBytes, logger);
|
||||
// skipping response
|
||||
|
|
Loading…
Reference in New Issue