diff --git a/java_console/ui/src/main/java/com/rusefi/tools/CANConnectorStartup.java b/java_console/ui/src/main/java/com/rusefi/tools/CANConnectorStartup.java index 44d2fc8b18..55a73654dd 100644 --- a/java_console/ui/src/main/java/com/rusefi/tools/CANConnectorStartup.java +++ b/java_console/ui/src/main/java/com/rusefi/tools/CANConnectorStartup.java @@ -1,12 +1,20 @@ package com.rusefi.tools; import com.rusefi.binaryprotocol.BinaryProtocol; +import com.rusefi.config.generated.Integration; import com.rusefi.io.serial.AbstractIoStream; +import com.rusefi.io.serial.RateCounter; import com.rusefi.io.tcp.BinaryProtocolProxy; +import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.io.tcp.TcpConnector; import com.rusefi.ui.StatusConsumer; +import javax.swing.*; +import java.awt.event.ActionEvent; import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; public class CANConnectorStartup { public static void start(AbstractIoStream tsStream, StatusConsumer statusListener) throws IOException { @@ -19,7 +27,26 @@ public class CANConnectorStartup { } else { statusListener.append("Got [" + signature + "] ECU signature via " + tsStream); } - BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, BinaryProtocolProxy.ClientApplicationActivityListener.VOID, statusListener); + Map rateCounters = new HashMap<>(); + Timer everySecond = new Timer(1000, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent event) { + for (Map.Entry e : rateCounters.entrySet()) { + String name = BinaryProtocol.findCommand(e.getKey()); + + statusListener.append(new Date() + ": Command " + name + ": " + e.getValue().getCurrentRate()); + } + } + }); + everySecond.start(); + BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, clientRequest -> { + byte[] packet = clientRequest.getPacket(); + if (packet.length == 0) + throw new IllegalStateException("Zero size packet not expected"); + byte commandId = packet[0]; + RateCounter counter = rateCounters.computeIfAbsent(commandId, command -> new RateCounter()); + counter.add(); + }, statusListener); } }