From a875aa62fb08415c7b4920a557a512f04ead3086 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 5 Dec 2021 01:44:34 -0500 Subject: [PATCH] Elm327Connector.processLine(): {STOPPED} #3655 --- .../binaryprotocol/test/Elm327Sandbox.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) 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 index a56114e18a..8fa3f6d85e 100644 --- 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 @@ -10,12 +10,13 @@ import com.rusefi.io.serial.SerialIoStream; import java.io.IOException; +import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode; import static com.rusefi.io.can.Elm327Connector.ELM327_DEFAULT_BAUDRATE; public class Elm327Sandbox { public static void main(String[] args) throws InterruptedException, IOException { BaudRateHolder.INSTANCE.baudRate = ELM327_DEFAULT_BAUDRATE; - String serialPort = "COM5"; + String serialPort = "COM7"; Elm327Connector connector = new Elm327Connector(SerialIoStream.openPort(serialPort)); connector.start("sandbox"); @@ -25,22 +26,44 @@ public class Elm327Sandbox { System.out.println("Hello new connection " + dataBuffer.getPendingCount()); runFcommand("First time", tsStream); - whyDoWeNeedToSleepBetweenCommands(); + Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); runFcommand("Second time", tsStream); - whyDoWeNeedToSleepBetweenCommands(); + Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); { String signature = BinaryProtocol.getSignature(tsStream); System.out.println("Got " + signature + " signature via CAN/ELM327"); } - whyDoWeNeedToSleepBetweenCommands(); + Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); { String signature = BinaryProtocol.getSignature(tsStream); System.out.println("Let's do it again! Got " + signature + " signature via CAN/ELM327"); } + + Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); + + { + tsStream.sendPacket(new byte[]{Fields.TS_HELLO_COMMAND}); + byte[] response = dataBuffer.getPacket("[hello command]"); + if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK)) + return; + String signature = new String(response, 1, response.length - 1); + System.out.println(Fields.TS_HELLO_COMMAND + " returned " + signature); + } + + Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); + + { + tsStream.sendPacket(BinaryProtocol.createCrcCommand(1000)); + byte[] fResponse = new byte[3]; + dataBuffer.waitForBytes("CRC", System.currentTimeMillis(), fResponse.length); + dataBuffer.getData(fResponse); + System.out.println(" Got CRC response " + IoStream.printHexBinary(fResponse)); + } + } private static void runFcommand(String prefix, IoStream tsStream) throws IOException { @@ -52,10 +75,4 @@ public class Elm327Sandbox { System.out.println(prefix + " Got F response " + IoStream.printHexBinary(fResponse)); } - /** - * TODO: HUH? what's that about?! - */ - private static void whyDoWeNeedToSleepBetweenCommands() throws InterruptedException { - Thread.sleep(200); - } }