'Category' logic

This commit is contained in:
rusefillc 2022-08-17 01:01:48 -04:00
parent 5bdbc8d170
commit 23841f9397
8 changed files with 28 additions and 14 deletions

View File

@ -25,6 +25,11 @@ public class LoggingStrategy {
return field.getName();
}
@Override
public String getCategory() {
return field.getCategory();
}
@Override
public String getUnit() {
return "x";

View File

@ -7,12 +7,18 @@ public class DbcField {
private final int startOffset;
private final int length;
private final double mult;
private String category;
public DbcField(String name, int startOffset, int length, double mult) {
public DbcField(String name, int startOffset, int length, double mult, String category) {
this.name = name;
this.startOffset = startOffset;
this.length = length;
this.mult = mult;
this.category = category;
}
public String getCategory() {
return category;
}
public String getName() {

View File

@ -21,18 +21,18 @@ public class DbcFile {
}
public void read(BufferedReader reader) throws IOException {
DbcPacket currentState = null;
DbcPacket currentPacket = null;
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("BO_")) {
if (currentState != null)
this.packets.add(currentState);
if (currentPacket != null)
this.packets.add(currentPacket);
line = line.replaceAll(":", "");
String[] tokens = line.split(" ");
int decId = Integer.parseInt(tokens[1]);
String name = tokens[2];
currentState = new DbcPacket(decId, name);
String packetName = tokens[2];
currentPacket = new DbcPacket(decId, packetName);
} else if (line.startsWith("SG_")) {
line = line.replaceAll("[|+@(,)\\[\\]]", " ");
@ -56,17 +56,17 @@ public class DbcFile {
double mult = Double.parseDouble(tokens[index + 3]);
DbcField field = new DbcField(name, startOffset, length, mult);
DbcField field = new DbcField(name, startOffset, length, mult, currentPacket.getName());
if (debugEnabled)
System.out.println("Found " + field);
currentState.add(field);
currentPacket.add(field);
} else {
// skipping useless line
}
}
if (currentState != null)
this.packets.add(currentState);
if (currentPacket != null)
this.packets.add(currentPacket);
System.out.println(getClass().getSimpleName() + ": Total " + packets.size() + " packets");
}

View File

@ -6,6 +6,8 @@ import java.io.IOException;
public interface BinaryLogEntry {
String getName();
String getCategory();
String getUnit();
int getByteSize();

View File

@ -136,7 +136,7 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
stream.writeFloat(0);
// 0036h precision digits
stream.write(2);
writeLine(stream, "Category", MLQ_FIELD_HEADER_NAME_OR_CATEGORY);
writeLine(stream, sensor.getCategory(), MLQ_FIELD_HEADER_NAME_OR_CATEGORY);
}
if (stream.size() != infoDataStart)
throw new IllegalStateException("We are doing something wrong :( stream.size=" + stream.size() + "/" + infoDataStart);

View File

@ -9,7 +9,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import static com.rusefi.can.reader.impl.ParseDBC.VAG_MOTOR_1;
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;

View File

@ -11,7 +11,7 @@ import java.io.StringReader;
import static junit.framework.TestCase.assertEquals;
public class ParseDBC {
public class ParseDBCTest {
public static final String VAG_MOTOR_1 = "BO_ 640 Motor_1: 8 XXX\n" +
" SG_ Fahrerwunschmoment : 56|8@1+ (0.39,0) [0|99] \"MDI\" XXX\n" +
" SG_ mechanisches_Motor_Verlustmomen : 48|8@1+ (0.39,0) [0|99] \"MDI\" XXX\n" +
@ -105,5 +105,6 @@ public class ParseDBC {
DbcField rpm = motorPacket.find("RPM");
assertEquals(0.25, rpm.getMult());
assertEquals("Motor_1", rpm.getCategory());
}
}

View File

@ -10,7 +10,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import static com.rusefi.can.reader.impl.ParseDBC.VAG_MOTOR_1;
import static com.rusefi.can.reader.impl.ParseDBCTest.VAG_MOTOR_1;
public class TrcToMlqSandbox {