Elm327Connector.processLine(): {STOPPED} #3655

This commit is contained in:
rusefillc 2021-12-05 01:44:34 -05:00
parent f11f304ace
commit a875aa62fb
1 changed files with 27 additions and 10 deletions

View File

@ -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);
}
}