From d7cfa664256321b7536031026bb5c0cd66b78026 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Tue, 5 Nov 2024 22:29:54 -0500 Subject: [PATCH] AlwaysSameScanner --- .../rusefi/can/analysis/ByteRateOfChange.java | 4 + .../com/rusefi/can/AlwaysSameScanner.java | 78 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 reader/src/test/java/com/rusefi/can/AlwaysSameScanner.java diff --git a/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java b/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java index 6782236..8891685 100644 --- a/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java +++ b/reader/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java @@ -135,6 +135,10 @@ public boolean equals(Object o) { return sid == byteId.sid && byteIndex == byteId.byteIndex; } + public int getSid() { + return sid; + } + public int getByteIndex() { return byteIndex; } diff --git a/reader/src/test/java/com/rusefi/can/AlwaysSameScanner.java b/reader/src/test/java/com/rusefi/can/AlwaysSameScanner.java new file mode 100644 index 0000000..7e706e0 --- /dev/null +++ b/reader/src/test/java/com/rusefi/can/AlwaysSameScanner.java @@ -0,0 +1,78 @@ +package com.rusefi.can; + +import com.rusefi.can.analysis.ByteRateOfChange; +import com.rusefi.can.analysis.CanMetaDataContext; +import com.rusefi.can.reader.CANLineReader; +import com.rusefi.can.reader.dbc.DbcFile; +import com.rusefi.can.reader.dbc.DbcPacket; +import com.rusefi.util.FolderUtil; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +public class AlwaysSameScanner { + + static Map existingValue = new TreeMap<>(); + + public static void run(String inputFolderName, DbcFile dbc) throws IOException { + File inputFolder = new File(inputFolderName); + for (String simpleFileName : inputFolder.list()) { + String fullInputFile = inputFolderName + File.separator + simpleFileName; + if (new File(fullInputFile).isDirectory()) { + System.out.println("Recursion " + fullInputFile); + run(fullInputFile, dbc); + } + } + + + FolderUtil.handleFolder(inputFolderName, (simpleFileName, fullInputFileName) -> { + System.out.println("File " + simpleFileName + " " + fullInputFileName); + + List logFileContent = CANLineReader.getReader().readFile(fullInputFileName); + + for (CANPacket packet : logFileContent) { + + for (int i = 0; i < packet.getData().length; i++) { + ByteRateOfChange.ByteId id = new ByteRateOfChange.ByteId(packet.getId(), i); + + int currentValue = packet.getData()[i]; + Integer existing = existingValue.putIfAbsent(id, currentValue); + if (existing == null) { + // first time we are hitting this byte + continue; + } else if (existing == currentValue) { + // same value, still unit + continue; + } else { + existingValue.put(id, Integer.MAX_VALUE); + } + } + } + }, Launcher.fileNameSuffixValue); + } + + public static void report(DbcFile dbc) { + + for (Map.Entry e : existingValue.entrySet()) { + + Integer value = e.getValue(); + if (value == Integer.MAX_VALUE) { + // not unique byte + continue; + } + + int sid = e.getKey().getSid(); + DbcPacket packet = dbc.findPacket(sid); + String name = packet == null ? Integer.toString(sid) : packet.getName(); + + + System.out.println(name + " index " + e.getKey().getByteIndex() + " is always same " + value); + + + } + + } +}