From f4a0da5cf15059479f85ca1d9d473937e67a8d58 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 6 Dec 2021 21:42:04 -0500 Subject: [PATCH] refactoring --- .../binaryprotocol/test/Elm327Sandbox.java | 16 ++-------------- .../binaryprotocol/test/SandboxCommon.java | 8 ++++++++ 2 files changed, 10 insertions(+), 14 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 a4b20fba08..3f3954f254 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 @@ -1,6 +1,5 @@ package com.rusefi.binaryprotocol.test; -import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.binaryprotocol.IncomingDataBuffer; import com.rusefi.config.generated.Fields; import com.rusefi.io.IoStream; @@ -34,22 +33,11 @@ public class Elm327Sandbox { runFcommand("Second time", tsStream); Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); */ - { - String signature = BinaryProtocol.getSignature(tsStream); - System.out.println("Got " + signature + " signature via CAN/ELM327"); - if (signature == null || !signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) - throw new IllegalStateException("Unexpected S " + signature); - } + SandboxCommon.verifySignature(tsStream, "", "ELM"); Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); - { - String signature = BinaryProtocol.getSignature(tsStream); - System.out.println("Let's do it again! Got " + signature + " signature via CAN/ELM327"); - if (signature == null || !signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) - throw new IllegalStateException("Unexpected S " + signature); - } - + SandboxCommon.verifySignature(tsStream, "Let's do it again! ", "ELM"); Elm327Connector.whyDoWeNeedToSleepBetweenCommands(); { diff --git a/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/SandboxCommon.java b/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/SandboxCommon.java index 81c2a63db5..a37a7f7b7e 100644 --- a/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/SandboxCommon.java +++ b/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/SandboxCommon.java @@ -9,6 +9,7 @@ import com.rusefi.io.IoStream; import com.rusefi.io.LinkManager; import com.rusefi.io.serial.StreamConnector; +import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -60,4 +61,11 @@ public class SandboxCommon { System.out.println("ERROR Extra data after CRC"); }); } + + static void verifySignature(IoStream tsStream, String prefix, String suffix) throws IOException { + String signature = BinaryProtocol.getSignature(tsStream); + System.out.println(prefix + "Got " + signature + " signature via " + suffix); + if (signature == null || !signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) + throw new IllegalStateException("Unexpected S " + signature); + } }