folder processing mode
This commit is contained in:
parent
5c809e7a22
commit
435861b7b7
|
@ -0,0 +1,31 @@
|
||||||
|
package com.rusefi.can;
|
||||||
|
|
||||||
|
import com.rusefi.can.reader.dbc.DbcFile;
|
||||||
|
import com.rusefi.can.reader.impl.PcanTrcReader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class HandleFolder {
|
||||||
|
public static void doJob(String dbcFileName, String inputFolderName, String outputFolder) throws IOException {
|
||||||
|
System.out.println("Dbc file " + dbcFileName);
|
||||||
|
System.out.println("inputFolderName " + inputFolderName);
|
||||||
|
System.out.println("outputFolder " + outputFolder);
|
||||||
|
DbcFile dbc = DbcFile.readFromFile(dbcFileName);
|
||||||
|
|
||||||
|
File inputFolder = new File(inputFolderName);
|
||||||
|
for (String inputFile : Objects.requireNonNull(inputFolder.list((dir, name) -> name.endsWith(".trc")))) {
|
||||||
|
System.out.println("Handling " + inputFile);
|
||||||
|
|
||||||
|
String fullInputFile = inputFolderName + File.separator + inputFile;
|
||||||
|
|
||||||
|
List<CANPacket> packets = new PcanTrcReader().readFile(fullInputFile);
|
||||||
|
|
||||||
|
String outputFileName = outputFolder + File.separator + inputFile;
|
||||||
|
|
||||||
|
LoggingStrategy.writeLog(dbc, packets, outputFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,8 +59,9 @@ public class LoggingStrategy {
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeLog(DbcFile dbc, List<BinaryLogEntry> entries, List<CANPacket> packets) {
|
public static void writeLog(DbcFile dbc, List<CANPacket> packets, String outputFileName) {
|
||||||
Map<String, Double> values = new HashMap<>();
|
Map<String, Double> values = new HashMap<>();
|
||||||
|
List<BinaryLogEntry> entries = dbc.getFieldNameEntries();
|
||||||
|
|
||||||
AtomicReference<Long> time = new AtomicReference<>();
|
AtomicReference<Long> time = new AtomicReference<>();
|
||||||
BinarySensorLog<BinaryLogEntry> log = new BinarySensorLog<>(o -> {
|
BinarySensorLog<BinaryLogEntry> log = new BinarySensorLog<>(o -> {
|
||||||
|
@ -68,8 +69,7 @@ public class LoggingStrategy {
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
return value;
|
return value;
|
||||||
}, entries, time::get);
|
}, entries, time::get, outputFileName);
|
||||||
|
|
||||||
|
|
||||||
for (CANPacket packetContent : packets) {
|
for (CANPacket packetContent : packets) {
|
||||||
DbcPacket packetMeta = dbc.findPacket(packetContent.getId());
|
DbcPacket packetMeta = dbc.findPacket(packetContent.getId());
|
||||||
|
|
|
@ -2,28 +2,32 @@ package com.rusefi.can;
|
||||||
|
|
||||||
import com.rusefi.can.reader.dbc.DbcFile;
|
import com.rusefi.can.reader.dbc.DbcFile;
|
||||||
import com.rusefi.can.reader.impl.PcanTrcReader;
|
import com.rusefi.can.reader.impl.PcanTrcReader;
|
||||||
import com.rusefi.sensor_logs.BinaryLogEntry;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrcToMlq {
|
public class TrcToMlq {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
if (args.length != 2) {
|
LoggingStrategy.LOG_ONLY_TRANSLATED_FIELDS = true;
|
||||||
|
|
||||||
|
if (args.length == 3) {
|
||||||
|
String dbcFileName = args[0];
|
||||||
|
String inputFolder = args[1];
|
||||||
|
String outputFolder = args[1];
|
||||||
|
HandleFolder.doJob(dbcFileName, inputFolder, outputFolder);
|
||||||
|
} else if (args.length != 2) {
|
||||||
System.err.println("Two arguments expected - DBC file name and TRC file name");
|
System.err.println("Two arguments expected - DBC file name and TRC file name");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
|
} else {
|
||||||
|
String dbcFileName = args[0];
|
||||||
|
String inputFileName = args[1];
|
||||||
|
|
||||||
|
DbcFile dbc = DbcFile.readFromFile(dbcFileName);
|
||||||
|
|
||||||
|
List<CANPacket> packets = new PcanTrcReader().readFile(inputFileName);
|
||||||
|
|
||||||
|
String outputFileName = System.getProperty("mlq_file_name", "gauges.mlg");
|
||||||
|
LoggingStrategy.writeLog(dbc, packets, outputFileName);
|
||||||
}
|
}
|
||||||
String dbcFileName = args[0];
|
|
||||||
String trcFileName = args[1];
|
|
||||||
|
|
||||||
DbcFile dbc = DbcFile.readFromFile(dbcFileName);
|
|
||||||
|
|
||||||
LoggingStrategy.LOG_ONLY_TRANSLATED_FIELDS = true;
|
|
||||||
List<BinaryLogEntry> entries = LoggingStrategy.getFieldNameEntries(dbc);
|
|
||||||
|
|
||||||
List<CANPacket> packets = new PcanTrcReader().readFile(trcFileName);
|
|
||||||
System.out.println("Got " + packets.size() + " CAN packets");
|
|
||||||
|
|
||||||
LoggingStrategy.writeLog(dbc, entries, packets);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public interface CANLineReader {
|
||||||
if (packet != null)
|
if (packet != null)
|
||||||
result.add(packet);
|
result.add(packet);
|
||||||
});
|
});
|
||||||
|
System.out.println("Got " + result.size() + " CAN packets from " + fileName);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.rusefi.can.reader.dbc;
|
package com.rusefi.can.reader.dbc;
|
||||||
|
|
||||||
|
import com.rusefi.can.LoggingStrategy;
|
||||||
|
import com.rusefi.sensor_logs.BinaryLogEntry;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -13,6 +16,8 @@ public class DbcFile {
|
||||||
|
|
||||||
private static final boolean debugEnabled = false;
|
private static final boolean debugEnabled = false;
|
||||||
|
|
||||||
|
private List<BinaryLogEntry> list;
|
||||||
|
|
||||||
public static DbcFile readFromFile(String fileName) throws IOException {
|
public static DbcFile readFromFile(String fileName) throws IOException {
|
||||||
DbcFile dbc = new DbcFile();
|
DbcFile dbc = new DbcFile();
|
||||||
{
|
{
|
||||||
|
@ -113,4 +118,12 @@ public class DbcFile {
|
||||||
public DbcPacket findPacket(int canId) {
|
public DbcPacket findPacket(int canId) {
|
||||||
return packets.get(canId);
|
return packets.get(canId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<BinaryLogEntry> getFieldNameEntries() {
|
||||||
|
if (list == null) {
|
||||||
|
list = LoggingStrategy.getFieldNameEntries(this);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,18 +20,15 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
||||||
private final TimeProvider timeProvider;
|
private final TimeProvider timeProvider;
|
||||||
private DataOutputStream stream;
|
private DataOutputStream stream;
|
||||||
|
|
||||||
private final String fileName = System.getProperty("mlq_file_name", "gauges.mlg");
|
private final String fileName;
|
||||||
|
|
||||||
private int counter;
|
private int counter;
|
||||||
|
|
||||||
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors) {
|
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors, TimeProvider timeProvider, String fileName) {
|
||||||
this(valueProvider, sensors, System::currentTimeMillis);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors, TimeProvider timeProvider) {
|
|
||||||
this.valueProvider = Objects.requireNonNull(valueProvider, "valueProvider");
|
this.valueProvider = Objects.requireNonNull(valueProvider, "valueProvider");
|
||||||
this.entries = Objects.requireNonNull(sensors, "entries");
|
this.entries = Objects.requireNonNull(sensors, "entries");
|
||||||
this.timeProvider = timeProvider;
|
this.timeProvider = timeProvider;
|
||||||
|
this.fileName = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TimeProvider {
|
public interface TimeProvider {
|
||||||
|
|
|
@ -24,13 +24,10 @@ public class TrcToMlqSandbox {
|
||||||
dbc.read(reader);
|
dbc.read(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BinaryLogEntry> entries = LoggingStrategy.getFieldNameEntries(dbc);
|
|
||||||
|
|
||||||
List<CANPacket> packets = new PcanTrcReader().readFile(trcFileName);
|
List<CANPacket> packets = new PcanTrcReader().readFile(trcFileName);
|
||||||
System.out.println(packets.size() + " packets");
|
System.out.println(packets.size() + " packets");
|
||||||
|
|
||||||
|
LoggingStrategy.writeLog(dbc, packets, "gauges.mlg");
|
||||||
LoggingStrategy.writeLog(dbc, entries, packets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue