can-log-tools/reader/src/main/java/com/rusefi/mlv/LoggingStrategy.java

54 lines
1.8 KiB
Java

package com.rusefi.mlv;
import com.rusefi.can.CANPacket;
import com.rusefi.can.reader.dbc.DbcField;
import com.rusefi.can.reader.dbc.DbcFile;
import com.rusefi.can.reader.dbc.DbcPacket;
import com.rusefi.sensor_logs.BinaryLogEntry;
import com.rusefi.sensor_logs.BinarySensorLog;
import java.util.ArrayList;
import java.util.List;
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) {
List<BinaryLogEntry> entries = new ArrayList<>();
for (DbcPacket packet : dbc.packets.values()) {
for (DbcField field : packet.getFields()) {
if (logOnlyTranslatedFields && !field.isNiceName())
continue;
entries.add(BinaryLogEntry.createFloatLogEntry(field.getName(), field.getCategory()));
}
}
return entries;
}
public static void writeLog(DbcFile dbc, List<CANPacket> packets, String outputFileName) {
List<BinaryLogEntry> entries = dbc.getFieldNameEntries();
LoggingContext context = new LoggingContext();
BinarySensorLog<BinaryLogEntry> log = context.getBinaryLogEntryBinarySensorLog(entries, outputFileName);
PacketLogger logger = packetContent -> {
DbcPacket packetMeta = dbc.findPacket(packetContent.getId());
if (packetMeta == null)
return false;
for (DbcField field : packetMeta.getFields()) {
context.currentSnapshot.put(field.getName(), field.getValue(packetContent));
}
return true;
};
context.writeLogContent(packets, log, logger);
}
public interface PacketLogger {
boolean takeValues(CANPacket packetContent);
}
}