logging skip rate

This commit is contained in:
rusefillc 2022-08-09 12:03:29 -04:00 committed by rusefillc
parent fb7000b49e
commit fe298bf2b4
1 changed files with 14 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import static com.rusefi.config.generated.Fields.CAN_ECU_SERIAL_TX_ID;
import static peak.can.basic.TPCANMessageType.PCAN_MESSAGE_STANDARD; import static peak.can.basic.TPCANMessageType.PCAN_MESSAGE_STANDARD;
public class PCanIoStream extends AbstractIoStream { public class PCanIoStream extends AbstractIoStream {
private static final int INFO_SKIP_RATE = 3-00;
static Logging log = getLogging(PCanIoStream.class); static Logging log = getLogging(PCanIoStream.class);
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1; public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
@ -51,6 +52,7 @@ public class PCanIoStream extends AbstractIoStream {
public void receiveData() { public void receiveData() {
} }
}; };
private int logSkipRate;
@Nullable @Nullable
public static PCanIoStream createStream() { public static PCanIoStream createStream() {
@ -115,14 +117,17 @@ public class PCanIoStream extends AbstractIoStream {
TPCANStatus status = can.Read(CHANNEL, rx, null); TPCANStatus status = can.Read(CHANNEL, rx, null);
if (status == TPCANStatus.PCAN_ERROR_OK) { if (status == TPCANStatus.PCAN_ERROR_OK) {
totalCounter.add(); totalCounter.add();
if (log.debugEnabled())
log.debug("Got [" + rx + "] id=" + String.format("%X", rx.getID()) + " len=" + rx.getLength() + ": " + IoStream.printByteArray(rx.getData()));
if (rx.getID() != CAN_ECU_SERIAL_TX_ID) { if (rx.getID() != CAN_ECU_SERIAL_TX_ID) {
// if (log.debugEnabled()) // if (log.debugEnabled())
log.info("Skipping non " + String.format("%X", CAN_ECU_SERIAL_TX_ID) + " packet: " + String.format("%X", rx.getID())); logSkipRate ++;
log.info("Total rate " + totalCounter.getCurrentRate() + ", isotp rate " + isoTpCounter.getCurrentRate()); if (logSkipRate % INFO_SKIP_RATE == 0) {
debugPacket(rx);
log.info("Skipping non " + String.format("%X", CAN_ECU_SERIAL_TX_ID) + " packet: " + String.format("%X", rx.getID()));
log.info("Total rate " + totalCounter.getCurrentRate() + ", isotp rate " + isoTpCounter.getCurrentRate());
}
return; return;
} }
debugPacket(rx);
isoTpCounter.add(); isoTpCounter.add();
byte[] decode = canDecoder.decodePacket(rx.getData()); byte[] decode = canDecoder.decodePacket(rx.getData());
listener.onDataArrived(decode); listener.onDataArrived(decode);
@ -133,6 +138,11 @@ public class PCanIoStream extends AbstractIoStream {
} }
} }
private void debugPacket(TPCANMsg rx) {
if (log.debugEnabled())
log.debug("Got [" + rx + "] id=" + String.format("%X", rx.getID()) + " len=" + rx.getLength() + ": " + IoStream.printByteArray(rx.getData()));
}
@Override @Override
public IncomingDataBuffer getDataBuffer() { public IncomingDataBuffer getDataBuffer() {
return dataBuffer; return dataBuffer;