This commit is contained in:
rusefillc 2022-11-10 23:38:46 -05:00
parent 31fdf3eff1
commit da3c1688e2
4 changed files with 59 additions and 35 deletions

View File

@ -1,12 +1,15 @@
package com.rusefi.can;
import com.rusefi.can.reader.CANLineReader;
import com.rusefi.sensor_logs.BinaryLogEntry;
import com.rusefi.sensor_logs.BinarySensorLog;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
public class ByteRateOfChange {
@ -113,5 +116,22 @@ public class ByteRateOfChange {
public HashMap<ByteId, ByteStatistics> getStatistics() {
return statistics;
}
public void createMegaLogViewer() {
Map<ByteId, BinaryLogEntry> entries = new HashMap<>();
for (ByteId key : statistics.keySet()) {
entries.put(key, BinaryLogEntry.createFloatLogEntry(key.sid + "_" + key.index, Integer.toBinaryString(key.sid)));
}
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.values(), time::get, "haha" + LoggingStrategy.MLG);
}
}
}

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.util.List;
public class ConvertTrcToMegaLogViewerWithDBC {
public static void doJob(String dbcFileName, String inputFolderName, String outputFolder) throws IOException {
DbcFile dbc = DbcFile.readFromFile(dbcFileName);
@ -18,7 +19,7 @@ public class ConvertTrcToMegaLogViewerWithDBC {
FolderUtil.FileAction fileAction = (simpleFileName, fullFileName) -> {
List<CANPacket> packets = CANLineReader.getReader().readFile(fullFileName);
String outputFileName = outputFolder + File.separator + simpleFileName + ".mlg";
String outputFileName = outputFolder + File.separator + simpleFileName + LoggingStrategy.MLG;
LoggingStrategy.writeLog(dbc, packets, outputFileName);
};

View File

@ -6,8 +6,6 @@ import com.rusefi.can.reader.dbc.DbcPacket;
import com.rusefi.sensor_logs.BinaryLogEntry;
import com.rusefi.sensor_logs.BinarySensorLog;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -15,6 +13,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
public class LoggingStrategy {
public static final String MLG = ".mlg";
public static boolean LOG_ONLY_TRANSLATED_FIELDS;
public static List<BinaryLogEntry> getFieldNameEntries(DbcFile dbc, boolean logOnlyTranslatedFields) {
@ -23,46 +22,16 @@ public class LoggingStrategy {
for (DbcField field : packet.getFields()) {
if (logOnlyTranslatedFields && !field.isNiceName())
continue;
entries.add(new BinaryLogEntry() {
@Override
public String getName() {
return field.getName();
}
@Override
public String getCategory() {
return field.getCategory();
}
@Override
public String getUnit() {
return "x";
}
@Override
public int getByteSize() {
return 4;
}
@Override
public void writeToLog(DataOutputStream dos, double value) throws IOException {
dos.writeFloat((float) value);
}
@Override
public String toString() {
return getName();
}
});
entries.add(BinaryLogEntry.createFloatLogEntry(field.getName(), field.getCategory()));
}
}
return entries;
}
public static void writeLog(DbcFile dbc, List<CANPacket> packets, String outputFileName) {
Map<String, Double> values = new HashMap<>();
List<BinaryLogEntry> entries = dbc.getFieldNameEntries();
Map<String, Double> values = new HashMap<>();
AtomicReference<Long> time = new AtomicReference<>();
BinarySensorLog<BinaryLogEntry> log = new BinarySensorLog<>(o -> {
Double value = values.get(o.getName());

View File

@ -4,6 +4,40 @@ import java.io.DataOutputStream;
import java.io.IOException;
public interface BinaryLogEntry {
static BinaryLogEntry createFloatLogEntry(final String name, final String category) {
return new BinaryLogEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getCategory() {
return category;
}
@Override
public String getUnit() {
return "x";
}
@Override
public int getByteSize() {
return 4;
}
@Override
public void writeToLog(DataOutputStream dos, double value) throws IOException {
dos.writeFloat((float) value);
}
@Override
public String toString() {
return getName();
}
};
}
String getName();
String getCategory();