only:comms stats
This commit is contained in:
parent
0547a0211e
commit
c3fe89b613
|
@ -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<Byte, RateCounter> rateCounters = new HashMap<>();
|
||||
|
||||
Timer everySecond = new Timer(1000, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
for (Map.Entry<Byte, RateCounter> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue