-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rusefillc
committed
Oct 23, 2023
1 parent
38e229a
commit 5856871
Showing
5 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.rusefi.can.analysis; | ||
|
||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class CanContext { | ||
final Set<Integer> withChecksum = new HashSet<>(); | ||
final Map<Integer, Map<Integer, Integer>> countersMap; | ||
|
||
Set<ByteRateOfChange.ByteId> counterBytes = new HashSet<>(); | ||
|
||
private CanContext(List<Integer> withChecksum, Map<Integer, Map<Integer, Integer>> countersMap) { | ||
this.countersMap = countersMap; | ||
this.withChecksum.addAll(withChecksum); | ||
|
||
for (Map.Entry<Integer, Map<Integer, Integer>> e : countersMap.entrySet()) { | ||
int sid = e.getKey(); | ||
Map<Integer, Integer> v = e.getValue(); | ||
|
||
for (Map.Entry<Integer, Integer> e2 : v.entrySet()) { | ||
int bitIndex = e2.getKey(); | ||
int size = e2.getValue(); | ||
|
||
if (size > 4) { | ||
int byteIndex = bitIndex / 8; | ||
counterBytes.add(new ByteRateOfChange.ByteId(sid, byteIndex)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static CanContext read(String inputFolderName) throws FileNotFoundException { | ||
Yaml checksum = new Yaml(); | ||
List<Integer> withChecksum = checksum.load(new FileReader(inputFolderName + File.separator + ChecksumScanner.CHECKSUM_YAML)); | ||
|
||
Yaml countersYaml = new Yaml(); | ||
Map<Integer, Map<Integer, Integer>> countersMap = countersYaml.load(new FileReader(inputFolderName + File.separator + CounterScanner.COUNTERS_YAML)); | ||
|
||
return new CanContext(withChecksum, countersMap); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/rusefi/can/analysis/ChecksumScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.rusefi.can.analysis; | ||
|
||
import com.rusefi.can.CANPacket; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.*; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class ChecksumScanner { | ||
|
||
public static final String CHECKSUM_YAML = "checksum.yaml"; | ||
|
||
public static void scanForChecksums(String reportDestinationFolder, List<CANPacket> packets) throws IOException { | ||
Map<Integer, AtomicBoolean> isChecksumMap = new HashMap<>(); | ||
|
||
J1850_SAE_crc8_Calculator c = new J1850_SAE_crc8_Calculator(); | ||
|
||
for (CANPacket packet : packets) { | ||
AtomicBoolean isChecksum = isChecksumMap.computeIfAbsent(packet.getId(), integer -> new AtomicBoolean(true)); | ||
if (!isChecksum.get()) | ||
continue; | ||
byte[] data = packet.getData(); | ||
if (data.length != 8) { | ||
isChecksum.set(false); | ||
continue; | ||
} | ||
byte checksum = c.crc8(data, 7); | ||
isChecksum.set(data[7] == checksum); | ||
} | ||
|
||
|
||
List<Integer> withChecksum = new ArrayList<>(); | ||
|
||
for (Map.Entry<Integer, AtomicBoolean> e : isChecksumMap.entrySet()) { | ||
if (e.getValue().get()) { | ||
Integer sid = e.getKey(); | ||
System.out.println("Ends with checksum " + sid); | ||
withChecksum.add(sid); | ||
} | ||
} | ||
Yaml yaml = new Yaml(); | ||
String yamlCountersReportFileName = reportDestinationFolder + File.separator + CHECKSUM_YAML; | ||
System.out.println("Writing report to " + yamlCountersReportFileName); | ||
yaml.dump(withChecksum, new FileWriter(yamlCountersReportFileName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters