From 10700106f7eada56f9dfb97ed335ccf73c277dda Mon Sep 17 00:00:00 2001 From: rusefillc Date: Thu, 25 Jul 2024 21:22:16 -0400 Subject: [PATCH] FirstPacket tool --- .../can/analysis/ByteRateOfChangeReports.java | 1 + .../com/rusefi/can/analysis/FirstPacket.java | 53 +++++++++++++++++++ .../com/rusefi/can/analysis/PacketRatio.java | 4 +- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 reader/src/main/java/com/rusefi/can/analysis/FirstPacket.java diff --git a/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChangeReports.java b/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChangeReports.java index 563ed4f..b7bccbc 100644 --- a/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChangeReports.java +++ b/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChangeReports.java @@ -131,6 +131,7 @@ public static void scanInputFolder(String inputFolderName, String fileNameSuffix CanToMegaLogViewer.createMegaLogViewer(reportDestinationFolder, logFileContent, simpleFileName); PacketRatio.write(dbc, reportDestinationFolder, logFileContent, simpleFileName); + FirstPacket.write(dbc, reportDestinationFolder, logFileContent, simpleFileName); ByteRateOfChange.TraceReport report = ByteRateOfChange.process(reportDestinationFolder, simpleFileName, logFileContent); report.save(simpleFileName + "-ByteRateOfChange.txt"); diff --git a/reader/src/main/java/com/rusefi/can/analysis/FirstPacket.java b/reader/src/main/java/com/rusefi/can/analysis/FirstPacket.java new file mode 100644 index 0000000..5989c99 --- /dev/null +++ b/reader/src/main/java/com/rusefi/can/analysis/FirstPacket.java @@ -0,0 +1,53 @@ +package com.rusefi.can.analysis; + +import com.rusefi.can.CANPacket; +import com.rusefi.can.reader.dbc.DbcFile; +import com.rusefi.can.reader.dbc.DbcPacket; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +public class FirstPacket { + public static void write(DbcFile dbc, String reportDestinationFolder, List logFileContent, String simpleFileName) throws IOException { + if (logFileContent.isEmpty()) + return; + CANPacket firstPacket = logFileContent.get(0); + + Map firstPacketById = new TreeMap<>(); + Map sorterByFirstPacket = new TreeMap<>(); + + for (CANPacket packet : logFileContent) { + if (!firstPacketById.containsKey(packet.getId())) { + firstPacketById.put(packet.getId(), packet); + sorterByFirstPacket.put(packet.getTimeStamp() - firstPacket.getTimeStamp(), packet); + } + } + + + Writer w = new FileWriter(reportDestinationFolder + File.separator + "start_" + simpleFileName + ".txt"); + + for (CANPacket packet : firstPacketById.values()) { + writeLine(dbc, packet, w, firstPacket); + } + + w.write("***************************************************\n"); + + for (CANPacket packet : sorterByFirstPacket.values()) { + writeLine(dbc, packet, w, firstPacket); + } + + w.close(); + } + + private static void writeLine(DbcFile dbc, CANPacket packet, Writer w, CANPacket firstPacket) throws IOException { + int sid = packet.getId(); + DbcPacket dbcPacket = dbc == null ? null : dbc.packets.get(sid); + String key = dbcPacket == null ? Integer.toString(sid) : dbcPacket.getName(); + w.write(key + ": " + (packet.getTimeStamp() - firstPacket.getTimeStamp()) + "\n"); + } +} diff --git a/reader/src/main/java/com/rusefi/can/analysis/PacketRatio.java b/reader/src/main/java/com/rusefi/can/analysis/PacketRatio.java index a9700f4..d158b77 100644 --- a/reader/src/main/java/com/rusefi/can/analysis/PacketRatio.java +++ b/reader/src/main/java/com/rusefi/can/analysis/PacketRatio.java @@ -29,8 +29,8 @@ public static void write(DbcFile dbc, String reportDestinationFolder, List e : countBySID.entrySet()) { double ratio = 100.0 * e.getValue().get() / logFileContent.size(); Integer sid = e.getKey(); - DbcPacket packet = dbc == null ? null : dbc.packets.get(sid); - String key = packet == null ? Integer.toString(sid) : packet.getName(); + DbcPacket dbcPacket = dbc == null ? null : dbc.packets.get(sid); + String key = dbcPacket == null ? Integer.toString(sid) : dbcPacket.getName(); w.write(key + ": " + ratio + "\n"); } w.close();