From 56e74f329b4fecdd55fd44bd6553eec3716bec7f Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 4 Dec 2021 14:29:27 -0500 Subject: [PATCH] it's not funny sandbox works :( --- .../com/rusefi/io/can/Elm327Connector.java | 8 +++--- .../binaryprotocol/test/Elm327Sandbox.java | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 java_console/io/src/test/java/com/rusefi/binaryprotocol/test/Elm327Sandbox.java diff --git a/java_console/io/src/main/java/com/rusefi/io/can/Elm327Connector.java b/java_console/io/src/main/java/com/rusefi/io/can/Elm327Connector.java index 3de3883bbc..e70bd85f6f 100644 --- a/java_console/io/src/main/java/com/rusefi/io/can/Elm327Connector.java +++ b/java_console/io/src/main/java/com/rusefi/io/can/Elm327Connector.java @@ -24,8 +24,10 @@ public class Elm327Connector implements Closeable { public final static int ELM327_DEFAULT_BAUDRATE = 38400; private final static int BIG_TIMEOUT = 2 * SECOND; private final static int TIMEOUT = 70; + public static final String HELLO = "ATZ"; + public static final String ELM_EOL = "\r"; - private final Object lock = new Object(); + private final Object lock = new Object(); // these should match the defines in the firmware private final static int CAN_SERIAL_TX_ID = 0x100; @@ -209,7 +211,7 @@ public class Elm327Connector implements Closeable { this.stream = stream; this.stream.setInputListener(listener); - if (sendCommand("ATZ", "ELM327 v[0-9]+\\.[0-9]+", BIG_TIMEOUT) != null) { + if (sendCommand(HELLO, "ELM327 v[0-9]+\\.[0-9]+", BIG_TIMEOUT) != null) { log.info("ELM DETECTED on " + msg + "!"); return true; } @@ -226,7 +228,7 @@ public class Elm327Connector implements Closeable { isCommandMode = true; this.completeLines.clear(); try { - this.stream.write((command + "\r").getBytes()); + this.stream.write((command + ELM_EOL).getBytes()); waitForResponse(timeout); } catch (IOException | InterruptedException ignore) { return null; diff --git a/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/Elm327Sandbox.java b/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/Elm327Sandbox.java new file mode 100644 index 0000000000..72ea26f406 --- /dev/null +++ b/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/Elm327Sandbox.java @@ -0,0 +1,25 @@ +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 java.io.IOException; + +import static com.rusefi.Timeouts.SECOND; +import static com.rusefi.io.can.Elm327Connector.ELM327_DEFAULT_BAUDRATE; +import static com.rusefi.io.can.Elm327Connector.ELM_EOL; + +public class Elm327Sandbox { + public static void main(String[] args) throws InterruptedException, IOException { + BaudRateHolder.INSTANCE.baudRate = ELM327_DEFAULT_BAUDRATE; + String serialPort = "COM5"; + + IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort); + stream.setInputListener(freshData -> System.out.println("onDataArrived")); + + stream.write((Elm327Connector.HELLO + ELM_EOL).getBytes()); + Thread.sleep(6 * SECOND); + } +}