Compare commits

...

4 Commits

Author SHA1 Message Date
rusefillc 29a83d222a things are turning nasty 2024-02-16 00:46:16 -05:00
rusefillc fa68d54687 yes we have a defect for sure! 2024-02-16 00:28:14 -05:00
rusefillc 749f8a2858 isBigEndian 2024-02-16 00:17:46 -05:00
rusefillc 626b92fd24 better name into counters 2024-02-15 21:21:27 -05:00
7 changed files with 109 additions and 68 deletions

View File

@ -105,8 +105,8 @@ public class ByteRateOfChangeReports {
PerSidDump.handle(reportDestinationFolder, simpleFileName, logFileContent);
// at the moment we overwrite counter detection report after we process each file
CounterScanner.scanForCounters(reportDestinationFolder, logFileContent);
ChecksumScanner.scanForChecksums(reportDestinationFolder, logFileContent);
CounterScanner.scanForCounters(reportDestinationFolder, simpleFileName, logFileContent);
ChecksumScanner.scanForChecksums(reportDestinationFolder, simpleFileName, logFileContent);
CanToMegaLogViewer.createMegaLogViewer(reportDestinationFolder, logFileContent, simpleFileName);

View File

@ -13,7 +13,7 @@ public class ChecksumScanner {
public static final String CHECKSUM_YAML = "checksum.yaml";
public static void scanForChecksums(String reportDestinationFolder, List<CANPacket> packets) throws IOException {
public static void scanForChecksums(String reportDestinationFolder, String simpleFileName, List<CANPacket> packets) throws IOException {
Map<Integer, AtomicBoolean> isChecksumMap = new HashMap<>();
J1850_SAE_crc8_Calculator c = new J1850_SAE_crc8_Calculator();
@ -43,6 +43,7 @@ public class ChecksumScanner {
}
withChecksum.sort(Comparator.naturalOrder());
Yaml yaml = new Yaml();
// simpleFileName + "_" +
String yamlCountersReportFileName = reportDestinationFolder + File.separator + CHECKSUM_YAML;
System.out.println(new Date() + " Writing report to " + yamlCountersReportFileName);
yaml.dump(withChecksum, new FileWriter(yamlCountersReportFileName));

View File

@ -10,9 +10,9 @@ public class CounterScanner {
public static final String COUNTERS_YAML = "counters.yaml";
public static void scanForCounters(String reportDestinationFolder, List<CANPacket> packets) throws IOException {
public static void scanForCounters(String reportDestinationFolder, String simpleFileName, List<CANPacket> packets) throws IOException {
String outputFileName = reportDestinationFolder + File.separator + "counter_report.txt";
String outputFileName = reportDestinationFolder + File.separator + simpleFileName + "_counter_report.txt";
PrintWriter pw = new PrintWriter(new FileOutputStream(outputFileName));
Map<BitStateKey, BitState> bitStates = new TreeMap<>();

View File

@ -9,15 +9,17 @@ public class DbcField {
private final double mult;
private final double offset;
private String category;
private final boolean isBigEndian;
private boolean isNiceName;
public DbcField(String name, int startOffset, int length, double mult, double offset, String category) {
public DbcField(String name, int startOffset, int length, double mult, double offset, String category, boolean isBigEndian) {
this.name = name;
this.startOffset = startOffset;
this.length = length;
this.mult = mult;
this.offset = offset;
this.category = category;
this.isBigEndian = isBigEndian;
}
public static DbcField parseField(DbcPacket parent, String line) {
@ -40,11 +42,15 @@ public class DbcField {
throw new IllegalStateException("While " + line, e);
}
int length = Integer.parseInt(tokens[index + 1]);
int endiannessCode = Integer.parseInt(tokens[index + 2]);
if (endiannessCode != 0 && endiannessCode != 1)
throw new IllegalStateException("Unexpected endiannessCode " + endiannessCode);
boolean isBigEndian = endiannessCode == 0;
double mult = Double.parseDouble(tokens[index + 3]);
double offset = Double.parseDouble(tokens[index + 4]);
return new DbcField(name, startOffset, length, mult, offset, parent.getName());
return new DbcField(name, startOffset, length, mult, offset, parent.getName(), isBigEndian);
}
public String getCategory() {
@ -75,6 +81,10 @@ public class DbcField {
return offset;
}
public boolean isBigEndian() {
return isBigEndian;
}
@Override
public String toString() {
return "DbcField{" +
@ -82,28 +92,31 @@ public class DbcField {
", startOffset=" + startOffset +
", length=" + length +
", mult=" + mult +
", isBigEndian=" + isBigEndian +
'}';
}
public static int getBitIndex(byte[] data, int bitIndex, int bitWidth) {
public static int getBitRange(byte[] data, int bitIndex, int bitWidth, boolean isBigEndian) {
if (bitIndex < 0)
throw new IllegalArgumentException("Huh? " + bitIndex + " " + bitWidth);
int byteIndex = bitIndex >> 3;
int shift = bitIndex - byteIndex * 8;
if (byteIndex >= data.length)
return 0;
int value = data[byteIndex] & 0xff;
if (shift + bitWidth > 8) {
if (byteIndex + 1 >= data.length)
int otherByteIndex = (isBigEndian ? -1 : +1) + byteIndex;
if (otherByteIndex < 0 || otherByteIndex >= data.length)
return 0;
value = value + data[1 + byteIndex] * 256;
value = value + data[otherByteIndex] * 256;
}
int mask = (1 << bitWidth) - 1;
return (value >> shift) & mask;
}
public double getValue(CANPacket packet) {
return getBitIndex(packet.getData(), startOffset, length) * mult + offset;
return getBitRange(packet.getData(), startOffset, length, isBigEndian) * mult + offset;
}
public void rename(String niceName) {

View File

@ -1,54 +0,0 @@
package com.rusefi.can.reader.impl;
import com.rusefi.can.CANPacket;
import com.rusefi.mlv.LoggingStrategy;
import com.rusefi.can.reader.dbc.DbcField;
import com.rusefi.can.reader.dbc.DbcFile;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import static com.rusefi.can.reader.impl.ParseDBCTest.VAG_MOTOR_1;
import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class GetValueFromTrc {
public static final double EPS = 0.01;
@Test
public void test() throws IOException {
DbcFile dbc = new DbcFile(LoggingStrategy.LOG_ONLY_TRANSLATED_FIELDS);
{
BufferedReader reader = new BufferedReader(new StringReader(VAG_MOTOR_1));
dbc.read(reader);
}
assertNotNull(dbc.findPacket(640));
assertNull(dbc.findPacket(1640));
String trcLine = " 3769) 2117.7 Rx 0280 8 01 1D DF 12 1E 00 1A 1E ";
PcanTrcReader1_1 reader = new PcanTrcReader1_1();
CANPacket packet = reader.readLine(trcLine);
assertEquals(8, packet.getData().length);
assertEquals(640, packet.getId());
assertEquals(0x12DF, DbcField.getBitIndex(packet.getData(), 16, 16));
assertEquals(0xDF1D, DbcField.getBitIndex(packet.getData(), 8, 16));
assertEquals(1, DbcField.getBitIndex(packet.getData(), 0, 3));
assertEquals(0x1D, DbcField.getBitIndex(packet.getData(), 8, 8));
assertEquals(13 , DbcField.getBitIndex(packet.getData(), 8, 4));
DbcField bf = dbc.getPacketByIndexSlow(0).find("rpm");
assertEquals(1207.75, bf.getValue(packet), EPS);
System.out.println(packet);
}
}

View File

@ -0,0 +1,77 @@
package com.rusefi.can.reader.impl;
import com.rusefi.can.CANPacket;
import com.rusefi.mlv.LoggingStrategy;
import com.rusefi.can.reader.dbc.DbcField;
import com.rusefi.can.reader.dbc.DbcFile;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import static com.rusefi.can.reader.impl.ParseDBCTest.VAG_MOTOR_1;
import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.*;
public class GetValueFromTrcTest {
public static final double EPS = 0.01;
private static int getBitIndex(byte[] data, int bitIndex, int bitWidth) {
return DbcField.getBitRange(data, bitIndex, bitWidth, false);
}
@Test
public void testBigEndian() {
byte[] rpm = {(byte) 0x70, 0x04, 0x1F};
assertEquals(0x41f, DbcField.getBitRange(rpm, 16, 16, true));
byte[] data = {(byte) 0xAB, 0x56, 0x34};
assertEquals(0x56AB, DbcField.getBitRange(data, 0, 16, false));
assertEquals(0xAB56, DbcField.getBitRange(data, 8, 16, true));
assertEquals(0xAB, DbcField.getBitRange(data, 0, 8, false));
assertEquals(0xAB, DbcField.getBitRange(data, 0, 8, true));
assertEquals(0x56, DbcField.getBitRange(data, 8, 8, false));
assertEquals(0x56, DbcField.getBitRange(data, 8, 8, true));
// yes we have a defect for sure, we only touch two bytes at most while in this case we shall touch three bytes
assertEquals(0x56A, DbcField.getBitRange(data, 4, 16, false));
}
@Test
public void test() throws IOException {
DbcFile dbc = new DbcFile(LoggingStrategy.LOG_ONLY_TRANSLATED_FIELDS);
{
BufferedReader reader = new BufferedReader(new StringReader(VAG_MOTOR_1));
dbc.read(reader);
}
assertNotNull(dbc.findPacket(640));
assertNull(dbc.findPacket(1640));
String trcLine = " 3769) 2117.7 Rx 0280 8 01 1D DF 12 1E 00 1A 1E ";
PcanTrcReader1_1 reader = new PcanTrcReader1_1();
CANPacket packet = reader.readLine(trcLine);
assertEquals(8, packet.getData().length);
assertEquals(640, packet.getId());
assertEquals(0x12DF, getBitIndex(packet.getData(), 16, 16));
assertEquals(0xDF1D, getBitIndex(packet.getData(), 8, 16));
assertEquals(1, getBitIndex(packet.getData(), 0, 3));
assertEquals(0x1D, getBitIndex(packet.getData(), 8, 8));
assertEquals(13, getBitIndex(packet.getData(), 8, 4));
DbcField bf = dbc.getPacketByIndexSlow(0).find("rpm");
assertEquals(1207.75, bf.getValue(packet), EPS);
System.out.println(packet);
}
}

View File

@ -11,7 +11,7 @@ import java.io.StringReader;
import java.util.ArrayList;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
public class ParseDBCTest {
public static final String VAG_MOTOR_1 = "BO_ 640 Motor_1: 8 XXX\n" +
@ -30,7 +30,7 @@ public class ParseDBCTest {
" SG_ Fahrpedalwert_ungenau__Motor_1_ M : 1|1@1+ (1,0) [0|0] \"\" XXX\n" +
" SG_ Leergasinformation : 0|1@1+ (1,0) [0|0] \"\" XXX" +
"";
public static final String RPM_DBC = "VERSION \"\"\n" +
private static final String RPM_DBC = "VERSION \"\"\n" +
"\n" +
"\n" +
"NS_ :\n" +
@ -62,7 +62,7 @@ public class ParseDBCTest {
"\n" +
"BO_ 1394 ZAS_1: 2 XXX\n" +
" SG_ Fehlerspeichereintrag__ZAS_ : 15|1@1+ (1,0) [0|0] \"\" XXX\n" +
" SG_ Frei_ZAS_1_3 : 8|7@1+ (1,0) [0|0] \"\" XXX\n" +
" SG_ Frei_ZAS_1_3 : 8|7@0+ (1,0) [0|0] \"\" XXX\n" +
" SG_ Frei_ZAS_1_2 : 7|1@1+ (1,0) [0|0] \"\" XXX\n" +
" SG_ Klemme_15_SV : 6|1@1+ (1,0) [0|0] \"\" XXX\n" +
" SG_ Frei_ZAS_1_1 : 5|1@1+ (1,0) [0|0] \"\" XXX\n" +
@ -102,6 +102,10 @@ public class ParseDBCTest {
assertEquals(dbc.packets.size(), 3);
DbcPacket zacPacket = dbc.getPacketByIndexSlow(0);
assertFalse(zacPacket.getFields().get(0).isBigEndian());
assertTrue(zacPacket.getFields().get(1).isBigEndian());
DbcPacket motorPacket = dbc.getPacketByIndexSlow(2);
assertNotNull(motorPacket);
assertEquals(motorPacket.getId(), 640);