parent
8f4b16ae52
commit
72cf3e2e36
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -49,11 +49,11 @@ public class PortHolder {
|
|||
MessagesCentral.getInstance().postMessage(logger, getClass(), "Opening port: " + port);
|
||||
|
||||
stream = streamFactory.call();
|
||||
IncomingDataBuffer dataBuffer = IncomingDataBuffer.createDataBuffer(stream, logger);
|
||||
if (stream == null) {
|
||||
// error already reported
|
||||
return false;
|
||||
}
|
||||
IncomingDataBuffer dataBuffer = stream.getDataBuffer();
|
||||
synchronized (portLock) {
|
||||
bp = new BinaryProtocol(linkManager, logger, stream, dataBuffer);
|
||||
portLock.notifyAll();
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -18,6 +19,7 @@ public class SerialIoStreamJSerialComm implements IoStream {
|
|||
private SerialPort sp;
|
||||
private final String port;
|
||||
private final Logger logger;
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
|
||||
/**
|
||||
* @see #openPort(String, Logger)
|
||||
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
||||
|
@ -20,6 +21,7 @@ public class TcpIoStream implements IoStream {
|
|||
private final OutputStream output;
|
||||
private final Logger logger;
|
||||
private boolean isClosed;
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
|
||||
public TcpIoStream(Logger logger, Socket socket) throws IOException {
|
||||
this(logger, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||
|
@ -33,6 +35,12 @@ public class TcpIoStream implements IoStream {
|
|||
throw new NullPointerException("output");
|
||||
this.output = output;
|
||||
this.input = input;
|
||||
dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,7 @@ public class SerialAutoChecker implements Runnable {
|
|||
public void run() {
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort, logger);
|
||||
Logger logger = FileLog.LOGGER;
|
||||
IncomingDataBuffer incomingData = IncomingDataBuffer.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 = IncomingDataBuffer.createDataBuffer(stream, logger);
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello");
|
||||
stream.sendPacket(commandBytes, logger);
|
||||
// skipping response
|
||||
|
|
Loading…
Reference in New Issue