From 39a243cdabb15966767d0d86789a52343a51812b Mon Sep 17 00:00:00 2001 From: rusefillc Date: Tue, 6 Oct 2020 22:43:39 -0400 Subject: [PATCH] latest activity timestamp --- .../io/src/main/java/com/rusefi/io/IoStream.java | 5 +++++ .../java/com/rusefi/io/serial/AbstractIoStream.java | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/java_console/io/src/main/java/com/rusefi/io/IoStream.java b/java_console/io/src/main/java/com/rusefi/io/IoStream.java index d452c4b3d4..02d87479d5 100644 --- a/java_console/io/src/main/java/com/rusefi/io/IoStream.java +++ b/java_console/io/src/main/java/com/rusefi/io/IoStream.java @@ -52,8 +52,13 @@ public interface IoStream extends WriteStream, Closeable, StreamStatistics { write(packet.getPacket()); writeInt(packet.getCrc()); flush(); + onActivity(); } + long latestActivityTime(); + + void onActivity(); + default void sendPacket(byte[] plainPacket) throws IOException { if (plainPacket.length == 0) throw new IllegalArgumentException("Empty packets are not valid."); diff --git a/java_console/io/src/main/java/com/rusefi/io/serial/AbstractIoStream.java b/java_console/io/src/main/java/com/rusefi/io/serial/AbstractIoStream.java index c5d7f5221f..5175dac748 100644 --- a/java_console/io/src/main/java/com/rusefi/io/serial/AbstractIoStream.java +++ b/java_console/io/src/main/java/com/rusefi/io/serial/AbstractIoStream.java @@ -10,6 +10,7 @@ public abstract class AbstractIoStream implements IoStream { protected StreamStats streamStats = new StreamStats(); private final AtomicInteger bytesOut = new AtomicInteger(); + private long latestActivity; @Override public StreamStats getStreamStats() { @@ -30,6 +31,15 @@ public abstract class AbstractIoStream implements IoStream { public void flush() throws IOException { } + @Override + public void onActivity() { + latestActivity = System.currentTimeMillis(); + } + + public long latestActivityTime() { + return latestActivity; + } + @Override public boolean isClosed() { return isClosed; @@ -57,6 +67,7 @@ public abstract class AbstractIoStream implements IoStream { maxPacketGap = (int) Math.max(maxPacketGap, now - previousPacketArrivalTime); } previousPacketArrivalTime = now; + AbstractIoStream.this.onActivity(); } public void onArrived(int length) {