From 076960c4199f3022828d3eb6bae970e022368e4d Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 11 Feb 2022 22:59:53 -0500 Subject: [PATCH] console connectivity on specific Win11 device #3923 --- .../rusefi/binaryprotocol/BinaryProtocol.java | 4 +++- .../binaryprotocol/IncomingDataBuffer.java | 21 ++++++++++++++----- .../com/rusefi/io/serial/SerialIoStream.java | 7 +++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java index d147645a86..604c752b0b 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -8,6 +8,7 @@ import com.rusefi.ConfigurationImageDiff; import com.rusefi.NamedThreadFactory; import com.rusefi.SignatureHelper; import com.rusefi.Timeouts; +import com.rusefi.binaryprotocol.test.Bug3923; import com.rusefi.config.generated.Fields; import com.rusefi.core.Pair; import com.rusefi.core.SensorCentral; @@ -422,7 +423,8 @@ public class BinaryProtocol { try { linkManager.assertCommunicationThread(); dropPending(); - + if (Bug3923.obscene) + log.info("Sending opcode " + opcode + " payload " + packet.length); sendPacket(fullRequest); return receivePacket(msg); } catch (IOException e) { diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java index f19597ed30..911ef915a6 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java @@ -10,6 +10,7 @@ import net.jcip.annotations.ThreadSafe; import java.io.EOFException; import java.io.IOException; +import java.util.Arrays; import java.util.Objects; import static com.devexperts.logging.Logging.getLogging; @@ -53,8 +54,11 @@ public class IncomingDataBuffer { */ public byte[] getPacket(String msg, long start) throws EOFException { boolean isTimeout = waitForBytes(msg + " header", start, 2); - if (isTimeout) + if (isTimeout) { + if (Bug3923.obscene) + log.info("Timeout waiting for header"); return null; + } int packetSize = swap16(getShort()); // if (log.debugEnabled()) @@ -78,6 +82,8 @@ public class IncomingDataBuffer { log.warn(errorMessage); return null; } + if (Bug3923.obscene && packet.length < 10) + log.info("got packet: " + Arrays.toString(packet)); onPacketArrived(); // if (log.debugEnabled()) @@ -100,7 +106,7 @@ public class IncomingDataBuffer { cbb.notifyAll(); } if (log.debugEnabled() || Bug3923.obscene) - log.debug(freshData.length + " byte(s) arrived, total " + cbb.length()); + log.info(freshData.length + " byte(s) arrived, total " + cbb.length()); } /** @@ -165,8 +171,8 @@ public class IncomingDataBuffer { streamStats.onArrived(2); synchronized (cbb) { int result = cbb.getShort(); - if (log.debugEnabled()) - log.debug("Consumed some, " + cbb.length() + " remaining"); + if (log.debugEnabled() || Bug3923.obscene) + log.info("Consumed short, " + cbb.length() + " remaining"); return result; } } @@ -174,13 +180,18 @@ public class IncomingDataBuffer { public int getInt() throws EOFException { streamStats.onArrived(4); synchronized (cbb) { - return cbb.getInt(); + int result = cbb.getInt(); + if (log.debugEnabled() || Bug3923.obscene) + log.info("Consumed int, " + cbb.length() + " remaining"); + return result; } } public void getData(byte[] packet) { synchronized (cbb) { cbb.get(packet); + if (log.debugEnabled() || Bug3923.obscene) + log.info(packet.length + " consumed, " + cbb.length() + " remaining"); } streamStats.onArrived(packet.length); } diff --git a/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStream.java b/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStream.java index 5e42141124..efaf408de7 100644 --- a/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStream.java +++ b/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStream.java @@ -54,6 +54,8 @@ public class SerialIoStream extends AbstractIoStream { @Override public void write(byte[] bytes) { + if (Bug3923.obscene) + log.info("Writing " + bytes.length + " byte(s)"); sp.writeBytes(bytes, bytes.length); } @@ -78,7 +80,7 @@ public class SerialIoStream extends AbstractIoStream { @Override public void serialEvent(SerialPortEvent event) { if (Bug3923.obscene) - System.out.println("serialEvent " + event); + log.info("serialEvent " + event); if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) return; if (isFirstEvent) { @@ -96,10 +98,7 @@ public class SerialIoStream extends AbstractIoStream { byte[] data = new byte[numRead]; System.arraycopy(newData, 0, data, 0, numRead); listener.onDataArrived(data); - //System.out.println("Read " + numRead + " bytes."); } }); - } - }