parent
18683e35eb
commit
4e45ff935c
|
@ -6,7 +6,7 @@ import com.rusefi.config.generated.Fields;
|
|||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.can.Elm327Connector;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import com.rusefi.io.serial.BufferedSerialIoStream;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -57,7 +57,7 @@ public class SerialAutoChecker {
|
|||
|
||||
public void openAndCheckResponse(AtomicReference<AutoDetectResult> result, Function<CallbackContext, Void> callback) {
|
||||
String signature;
|
||||
try (IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort)) {
|
||||
try (IoStream stream = BufferedSerialIoStream.openPort(serialPort)) {
|
||||
signature = checkResponse(stream, callback);
|
||||
}
|
||||
if (signature != null) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
|
|||
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.serial.StreamConnector;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import com.rusefi.io.serial.BufferedSerialIoStream;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -82,7 +82,7 @@ public class LinkManager implements Closeable {
|
|||
public static IoStream open(String port) throws IOException {
|
||||
if (TcpConnector.isTcpPort(port))
|
||||
return TcpIoStream.open(port);
|
||||
return SerialIoStreamJSerialComm.openPort(port);
|
||||
return BufferedSerialIoStream.openPort(port);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -230,7 +230,7 @@ public class LinkManager implements Closeable {
|
|||
@Override
|
||||
public IoStream call() {
|
||||
messageListener.postMessage(getClass(), "Opening port: " + port);
|
||||
IoStream stream = ((Callable<IoStream>) () -> SerialIoStreamJSerialComm.openPort(port)).call();
|
||||
IoStream stream = ((Callable<IoStream>) () -> BufferedSerialIoStream.openPort(port)).call();
|
||||
if (stream == null) {
|
||||
// error already reported
|
||||
return null;
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.rusefi.io.can;
|
|||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import com.rusefi.io.serial.BufferedSerialIoStream;
|
||||
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class Elm327Connector implements Closeable {
|
|||
public void start(String serialPort) {
|
||||
log.info("* Elm327.start()");
|
||||
|
||||
if (initConnection(serialPort, SerialIoStreamJSerialComm.openPort(serialPort))) {
|
||||
if (initConnection(serialPort, BufferedSerialIoStream.openPort(serialPort))) {
|
||||
// reset to defaults
|
||||
sendCommand("ATD", "OK");
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.fazecast.jSerialComm.SerialPort;
|
||||
import com.fazecast.jSerialComm.SerialPortDataListener;
|
||||
import com.fazecast.jSerialComm.SerialPortEvent;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.io.IoStream;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
||||
/**
|
||||
* https://github.com/Fazecast/jSerialComm looks to be alive as of 2020
|
||||
* <p>
|
||||
* Andrey Belomutskiy, (c) 2013-2020
|
||||
* 06/03/2019
|
||||
*/
|
||||
public class BufferedSerialIoStream extends SerialIoStream {
|
||||
private static final Logging log = getLogging(BufferedSerialIoStream.class);
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
|
||||
/**
|
||||
* @see #openPort(String)
|
||||
*/
|
||||
private BufferedSerialIoStream(SerialPort sp, String port) {
|
||||
super(sp, port);
|
||||
this.dataBuffer = IncomingDataBuffer.createDataBuffer("[serial] ", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just open physical serial and not much more
|
||||
* @see PortHolder#connectAndReadConfiguration()
|
||||
*/
|
||||
public static IoStream openPort(String port) {
|
||||
log.info("[SerialIoStreamJSerialComm] openPort " + port);
|
||||
SerialPort serialPort = SerialPort.getCommPort(port);
|
||||
serialPort.setBaudRate(BaudRateHolder.INSTANCE.baudRate);
|
||||
serialPort.openPort(0);
|
||||
// FileLog.LOGGER.info("[SerialIoStreamJSerialComm] opened " + port);
|
||||
return new BufferedSerialIoStream(serialPort, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return port + " " + super.toString();
|
||||
}
|
||||
}
|
|
@ -1,34 +1,23 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.fazecast.jSerialComm.SerialPort;
|
||||
import com.fazecast.jSerialComm.SerialPortDataListener;
|
||||
import com.fazecast.jSerialComm.SerialPortEvent;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.io.IoStream;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
public class SerialIoStream extends AbstractIoStream {
|
||||
protected final SerialPort sp;
|
||||
protected final String port;
|
||||
|
||||
/**
|
||||
* https://github.com/Fazecast/jSerialComm looks to be alive as of 2020
|
||||
* <p>
|
||||
* Andrey Belomutskiy, (c) 2013-2020
|
||||
* 06/03/2019
|
||||
*/
|
||||
public class SerialIoStreamJSerialComm extends AbstractIoStream {
|
||||
private static final Logging log = getLogging(SerialIoStreamJSerialComm.class);
|
||||
private final SerialPort sp;
|
||||
private final String port;
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
|
||||
/**
|
||||
* @see #openPort(String)
|
||||
*/
|
||||
private SerialIoStreamJSerialComm(SerialPort sp, String port) {
|
||||
public SerialIoStream(SerialPort sp, String port) {
|
||||
this.sp = sp;
|
||||
this.port = port;
|
||||
this.dataBuffer = IncomingDataBuffer.createDataBuffer("[serial] ", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +25,19 @@ public class SerialIoStreamJSerialComm extends AbstractIoStream {
|
|||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
log.info(port + ": Closing port...");
|
||||
super.close();
|
||||
sp.closePort();
|
||||
log.info(port + ": Closed port.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes) {
|
||||
sp.writeBytes(bytes, bytes.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputListener(DataListener listener) {
|
||||
// datalistener can be redefined
|
||||
|
@ -71,39 +73,4 @@ public class SerialIoStreamJSerialComm extends AbstractIoStream {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
log.info(port + ": Closing port...");
|
||||
super.close();
|
||||
sp.closePort();
|
||||
log.info(port + ": Closed port.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes) {
|
||||
sp.writeBytes(bytes, bytes.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just open physical serial and not much more
|
||||
* @see PortHolder#connectAndReadConfiguration()
|
||||
*/
|
||||
public static IoStream openPort(String port) {
|
||||
log.info("[SerialIoStreamJSerialComm] openPort " + port);
|
||||
SerialPort serialPort = SerialPort.getCommPort(port);
|
||||
serialPort.setBaudRate(BaudRateHolder.INSTANCE.baudRate);
|
||||
serialPort.openPort(0);
|
||||
// FileLog.LOGGER.info("[SerialIoStreamJSerialComm] opened " + port);
|
||||
return new SerialIoStreamJSerialComm(serialPort, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return port + " " + super.toString();
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package com.rusefi.binaryprotocol.test;
|
|||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.can.Elm327Connector;
|
||||
import com.rusefi.io.serial.BaudRateHolder;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import com.rusefi.io.serial.BufferedSerialIoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class Elm327Sandbox {
|
|||
BaudRateHolder.INSTANCE.baudRate = ELM327_DEFAULT_BAUDRATE;
|
||||
String serialPort = "COM5";
|
||||
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort);
|
||||
IoStream stream = BufferedSerialIoStream.openPort(serialPort);
|
||||
stream.setInputListener(freshData -> System.out.println("onDataArrived"));
|
||||
|
||||
stream.write((Elm327Connector.HELLO + ELM_EOL).getBytes());
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.rusefi.autodetect.PortDetector;
|
|||
import com.rusefi.autodetect.SerialAutoChecker;
|
||||
import com.rusefi.io.DfuHelper;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import com.rusefi.io.serial.BufferedSerialIoStream;
|
||||
import com.rusefi.ui.StatusWindow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -70,7 +70,7 @@ public class DfuFlasher {
|
|||
AtomicBoolean isSignatureValidated = new AtomicBoolean(true);
|
||||
if (!PortDetector.isAutoPort(port)) {
|
||||
wnd.append("Using selected " + port + "\n");
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
|
||||
IoStream stream = BufferedSerialIoStream.openPort(port);
|
||||
AtomicReference<String> signature = new AtomicReference<>();
|
||||
new SerialAutoChecker(PortDetector.DetectorMode.DETECT_TS, port, new CountDownLatch(1)).checkResponse(stream, new Function<SerialAutoChecker.CallbackContext, Void>() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue