progress
This commit is contained in:
parent
f367a16570
commit
3c15fc279d
|
@ -54,4 +54,13 @@ public class DbcFile {
|
|||
if (currentState != null)
|
||||
this.packets.add(currentState);
|
||||
}
|
||||
|
||||
// todo: performance optimization SOON
|
||||
public DbcPacket findPacket(int i) {
|
||||
for (DbcPacket packet : packets) {
|
||||
if (packet.getId() == i)
|
||||
return packet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.function.Function;
|
|||
public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog {
|
||||
private final Function<T, Double> valueProvider;
|
||||
private final Collection<T> entries;
|
||||
private final TimeProvider timeProvider;
|
||||
private DataOutputStream stream;
|
||||
|
||||
private String fileName;
|
||||
|
@ -19,8 +20,17 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog {
|
|||
private int counter;
|
||||
|
||||
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors) {
|
||||
this.valueProvider = valueProvider;
|
||||
this(valueProvider, sensors, System::currentTimeMillis);
|
||||
}
|
||||
|
||||
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors, TimeProvider timeProvider) {
|
||||
this.valueProvider = Objects.requireNonNull(valueProvider, "valueProvider");
|
||||
this.entries = Objects.requireNonNull(sensors, "entries");
|
||||
this.timeProvider = timeProvider;
|
||||
}
|
||||
|
||||
public interface TimeProvider {
|
||||
long currentTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,13 +56,15 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog {
|
|||
try {
|
||||
stream.write(0);
|
||||
stream.write(counter++);
|
||||
stream.writeShort((int) (System.currentTimeMillis() * 100));
|
||||
stream.writeShort((int) (timeProvider.currentTimestamp() * 100));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(baos);
|
||||
|
||||
for (T sensor : entries) {
|
||||
double value = valueProvider.apply(sensor);
|
||||
Double value = valueProvider.apply(sensor);
|
||||
if (value == null)
|
||||
throw new NullPointerException("No value for " + sensor);
|
||||
sensor.writeToLog(dos, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@ import java.io.IOException;
|
|||
import java.io.StringReader;
|
||||
|
||||
import static com.rusefi.can.reader.impl.ParseDBC.VAG_MOTOR_1;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class GetValueFromTrc {
|
||||
|
||||
|
@ -23,6 +25,8 @@ public class GetValueFromTrc {
|
|||
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 ";
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public class ParseDBC {
|
|||
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" +
|
||||
" SG_ Fahrpedalwert_oder_Drosselklapp : 40|8@1+ (0.4,0) [0|101.6] \"%\" XXX\n" +
|
||||
" SG_ PPS_TPS : 40|8@1+ (0.4,0) [0|101.6] \"%\" XXX\n" +
|
||||
" SG_ inneres_Motor_Moment_ohne_exter : 32|8@1+ (0.39,0) [0|99] \"MDI\" XXX\n" +
|
||||
" SG_ RPM : 16|16@1+ (0.25,0) [0|16256] \"U/min\" XXX\n" +
|
||||
" SG_ inneres_Motor_Moment : 8|8@1+ (0.39,0) [0|99] \"MDI\" XXX\n" +
|
||||
|
|
|
@ -12,12 +12,18 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static com.rusefi.can.reader.impl.ParseDBC.VAG_MOTOR_1;
|
||||
|
||||
public class TrcToMlqSandbox {
|
||||
|
||||
// private static final String fileName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\VAG\\2006-Passat-B6\\passat-b6-stock-ecu-ecu-ptcan-not-running-pedal-up-and-down.trc";
|
||||
private static final String fileName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\VAG\\2006-Passat-B6\\passat-b6-stock-ecu-ecu-ptcan-parked-revving.trc";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
DbcFile dbc = new DbcFile();
|
||||
{
|
||||
|
@ -48,24 +54,42 @@ public class TrcToMlqSandbox {
|
|||
public void writeToLog(DataOutputStream dos, double value) throws IOException {
|
||||
dos.writeFloat((float) value);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
PcanTrcReader reader = new PcanTrcReader();
|
||||
List<CANPacket> packets = reader.readFile("C:\\stuff\\rusefi_documentation\\OEM-Docs\\VAG\\2006-Passat-B6\\passat-b6-stock-ecu-ecu-ptcan-not-running-pedal-up-and-down.trc");
|
||||
List<CANPacket> packets = reader.readFile(fileName);
|
||||
System.out.println(packets.size() + " packets");
|
||||
|
||||
|
||||
BinarySensorLog log = new BinarySensorLog(new Function<BinaryLogEntry, Double>() {
|
||||
@Override
|
||||
public Double apply(BinaryLogEntry o) {
|
||||
System.out.println("apply");
|
||||
return null;
|
||||
Map<String, Double> values = new HashMap<>();
|
||||
|
||||
AtomicReference<Long> time = new AtomicReference<>();
|
||||
BinarySensorLog<BinaryLogEntry> log = new BinarySensorLog<>(o -> {
|
||||
Double value = values.get(o.getName());
|
||||
if (value == null)
|
||||
return 0.0;
|
||||
return value;
|
||||
}, entries, time::get);
|
||||
|
||||
|
||||
for (CANPacket packetContent : packets) {
|
||||
DbcPacket packetMeta = dbc.findPacket(packetContent.getId());
|
||||
if (packetMeta == null)
|
||||
continue;
|
||||
|
||||
time.set((long) (packetContent.getTimeStamp() * 1000));
|
||||
for (DbcField field : packetMeta.getFields()) {
|
||||
values.put(field.getName(), field.getValue(packetContent));
|
||||
}
|
||||
}, entries);
|
||||
|
||||
|
||||
log.writeSensorLogLine();
|
||||
}
|
||||
log.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue