Skip to content

Commit

Permalink
FirstPacket tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Jul 26, 2024
1 parent 6a63b31 commit 1070010
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
53 changes: 53 additions & 0 deletions reader/src/main/java/com/rusefi/can/analysis/FirstPacket.java
Original file line number Diff line number Diff line change
@@ -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<CANPacket> logFileContent, String simpleFileName) throws IOException {
if (logFileContent.isEmpty())
return;
CANPacket firstPacket = logFileContent.get(0);

Map<Integer, CANPacket> firstPacketById = new TreeMap<>();
Map<Double, CANPacket> 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");
}
}
4 changes: 2 additions & 2 deletions reader/src/main/java/com/rusefi/can/analysis/PacketRatio.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static void write(DbcFile dbc, String reportDestinationFolder, List<CANPa
for (Map.Entry<Integer, AtomicInteger> 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();
Expand Down

0 comments on commit 1070010

Please sign in to comment.