parent
4448550dc9
commit
dc5be4f053
|
@ -4,6 +4,7 @@ import com.opensr5.Logger;
|
||||||
import com.opensr5.io.DataListener;
|
import com.opensr5.io.DataListener;
|
||||||
import com.opensr5.io.WriteStream;
|
import com.opensr5.io.WriteStream;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
|
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.binaryprotocol.IoHelper;
|
import com.rusefi.binaryprotocol.IoHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -40,6 +41,8 @@ public interface IoStream extends WriteStream {
|
||||||
write(packet);
|
write(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IncomingDataBuffer getDataBuffer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param listener would be invoked from unknown implementation-dependent thread
|
* @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);
|
MessagesCentral.getInstance().postMessage(logger, getClass(), "Opening port: " + port);
|
||||||
|
|
||||||
stream = streamFactory.call();
|
stream = streamFactory.call();
|
||||||
IncomingDataBuffer dataBuffer = IncomingDataBuffer.createDataBuffer(stream, logger);
|
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
// error already reported
|
// error already reported
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
IncomingDataBuffer dataBuffer = stream.getDataBuffer();
|
||||||
synchronized (portLock) {
|
synchronized (portLock) {
|
||||||
bp = new BinaryProtocol(linkManager, logger, stream, dataBuffer);
|
bp = new BinaryProtocol(linkManager, logger, stream, dataBuffer);
|
||||||
portLock.notifyAll();
|
portLock.notifyAll();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.fazecast.jSerialComm.SerialPortDataListener;
|
||||||
import com.fazecast.jSerialComm.SerialPortEvent;
|
import com.fazecast.jSerialComm.SerialPortEvent;
|
||||||
import com.opensr5.Logger;
|
import com.opensr5.Logger;
|
||||||
import com.opensr5.io.DataListener;
|
import com.opensr5.io.DataListener;
|
||||||
|
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.io.IoStream;
|
import com.rusefi.io.IoStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +19,7 @@ public class SerialIoStreamJSerialComm implements IoStream {
|
||||||
private SerialPort sp;
|
private SerialPort sp;
|
||||||
private final String port;
|
private final String port;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
private final IncomingDataBuffer dataBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #openPort(String, Logger)
|
* @see #openPort(String, Logger)
|
||||||
|
@ -26,6 +28,12 @@ public class SerialIoStreamJSerialComm implements IoStream {
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IncomingDataBuffer getDataBuffer() {
|
||||||
|
return dataBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.io.tcp;
|
||||||
|
|
||||||
import com.opensr5.Logger;
|
import com.opensr5.Logger;
|
||||||
import com.opensr5.io.DataListener;
|
import com.opensr5.io.DataListener;
|
||||||
|
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.io.ByteReader;
|
import com.rusefi.io.ByteReader;
|
||||||
import com.rusefi.io.IoStream;
|
import com.rusefi.io.IoStream;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ public class TcpIoStream implements IoStream {
|
||||||
private final OutputStream output;
|
private final OutputStream output;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
|
private final IncomingDataBuffer dataBuffer;
|
||||||
|
|
||||||
public TcpIoStream(Logger logger, Socket socket) throws IOException {
|
public TcpIoStream(Logger logger, Socket socket) throws IOException {
|
||||||
this(logger, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
this(logger, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||||
|
@ -33,6 +35,12 @@ public class TcpIoStream implements IoStream {
|
||||||
throw new NullPointerException("output");
|
throw new NullPointerException("output");
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
|
dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IncomingDataBuffer getDataBuffer() {
|
||||||
|
return dataBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class SerialAutoChecker implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort, logger);
|
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort, logger);
|
||||||
Logger logger = FileLog.LOGGER;
|
Logger logger = FileLog.LOGGER;
|
||||||
IncomingDataBuffer incomingData = IncomingDataBuffer.createDataBuffer(stream, logger);
|
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||||
try {
|
try {
|
||||||
stream.sendPacket(new byte[]{BinaryProtocolCommands.COMMAND_HELLO}, logger);
|
stream.sendPacket(new byte[]{BinaryProtocolCommands.COMMAND_HELLO}, logger);
|
||||||
byte[] response = incomingData.getPacket(logger, "", false);
|
byte[] response = incomingData.getPacket(logger, "", false);
|
||||||
|
|
|
@ -308,7 +308,7 @@ public class ConsoleTools {
|
||||||
}
|
}
|
||||||
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort, FileLog.LOGGER);
|
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort, FileLog.LOGGER);
|
||||||
Logger logger = FileLog.LOGGER;
|
Logger logger = FileLog.LOGGER;
|
||||||
IncomingDataBuffer incomingData = IncomingDataBuffer.createDataBuffer(stream, logger);
|
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||||
byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello");
|
byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello");
|
||||||
stream.sendPacket(commandBytes, logger);
|
stream.sendPacket(commandBytes, logger);
|
||||||
// skipping response
|
// skipping response
|
||||||
|
|
Loading…
Reference in New Issue