now with MLG
This commit is contained in:
parent
da3c1688e2
commit
f82bd9de34
|
@ -9,7 +9,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ByteRateOfChange {
|
||||
|
||||
|
@ -40,7 +39,9 @@ public class ByteRateOfChange {
|
|||
|
||||
ps.close();
|
||||
|
||||
return new TraceReport(simpleFileName, statistics);
|
||||
TraceReport traceReport = new TraceReport(simpleFileName, statistics);
|
||||
traceReport.createMegaLogViewer(packets);
|
||||
return traceReport;
|
||||
}
|
||||
|
||||
public static String dualSid(int sid) {
|
||||
|
@ -78,6 +79,10 @@ public class ByteRateOfChange {
|
|||
this.index = index;
|
||||
}
|
||||
|
||||
private String getLogKey() {
|
||||
return sid + "_" + index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -117,21 +122,26 @@ public class ByteRateOfChange {
|
|||
return statistics;
|
||||
}
|
||||
|
||||
public void createMegaLogViewer() {
|
||||
public void createMegaLogViewer(List<CANPacket> packets) {
|
||||
Map<ByteId, BinaryLogEntry> entries = new HashMap<>();
|
||||
|
||||
for (ByteId key : statistics.keySet()) {
|
||||
entries.put(key, BinaryLogEntry.createFloatLogEntry(key.sid + "_" + key.index, Integer.toBinaryString(key.sid)));
|
||||
entries.put(key, BinaryLogEntry.createFloatLogEntry(key.getLogKey(), 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);
|
||||
LoggingContext context = new LoggingContext();
|
||||
BinarySensorLog<BinaryLogEntry> log = context.getBinaryLogEntryBinarySensorLog(entries.values(), simpleFileName + LoggingStrategy.MLG);
|
||||
|
||||
|
||||
context.processPackets(packets, log, packetContent -> {
|
||||
for (int i = 0; i < packetContent.getData().length; i++) {
|
||||
int value = packetContent.getData()[i] & 0xFF;
|
||||
|
||||
String name = new ByteId(packetContent.getId(), i).getLogKey();
|
||||
context.values.put(name, (double) value);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import com.rusefi.sensor_logs.BinaryLogEntry;
|
||||
import com.rusefi.sensor_logs.BinarySensorLog;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
class LoggingContext {
|
||||
Map<String, Double> values = new HashMap<>();
|
||||
AtomicReference<Long> time = new AtomicReference<>();
|
||||
|
||||
BinarySensorLog<BinaryLogEntry> getBinaryLogEntryBinarySensorLog(Collection<BinaryLogEntry> entries, String outputFileName) {
|
||||
return new BinarySensorLog<>(o -> {
|
||||
Double value = this.values.get(o.getName());
|
||||
if (value == null)
|
||||
return 0.0;
|
||||
return value;
|
||||
}, entries, getTimeProvider(), outputFileName);
|
||||
}
|
||||
|
||||
public void processPackets(List<CANPacket> packets, BinarySensorLog<BinaryLogEntry> log, LoggingStrategy.PacketLogger logger) {
|
||||
for (CANPacket packetContent : packets) {
|
||||
this.time.set((long) (packetContent.getTimeStamp() * 1000));
|
||||
boolean needLine = logger.takeValues(packetContent);
|
||||
if (needLine)
|
||||
log.writeSensorLogLine();
|
||||
}
|
||||
log.close();
|
||||
}
|
||||
|
||||
public BinarySensorLog.TimeProvider getTimeProvider() {
|
||||
return () -> this.time.get();
|
||||
}
|
||||
}
|
|
@ -7,10 +7,7 @@ import com.rusefi.sensor_logs.BinaryLogEntry;
|
|||
import com.rusefi.sensor_logs.BinarySensorLog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class LoggingStrategy {
|
||||
public static final String MLG = ".mlg";
|
||||
|
@ -31,26 +28,25 @@ public class LoggingStrategy {
|
|||
public static void writeLog(DbcFile dbc, List<CANPacket> packets, String outputFileName) {
|
||||
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());
|
||||
if (value == null)
|
||||
return 0.0;
|
||||
return value;
|
||||
}, entries, time::get, outputFileName);
|
||||
LoggingContext context = new LoggingContext();
|
||||
BinarySensorLog<BinaryLogEntry> log = context.getBinaryLogEntryBinarySensorLog(entries, outputFileName);
|
||||
|
||||
for (CANPacket packetContent : packets) {
|
||||
PacketLogger logger = packetContent -> {
|
||||
DbcPacket packetMeta = dbc.findPacket(packetContent.getId());
|
||||
if (packetMeta == null)
|
||||
continue;
|
||||
return false;
|
||||
|
||||
time.set((long) (packetContent.getTimeStamp() * 1000));
|
||||
for (DbcField field : packetMeta.getFields()) {
|
||||
values.put(field.getName(), field.getValue(packetContent));
|
||||
context.values.put(field.getName(), field.getValue(packetContent));
|
||||
}
|
||||
log.writeSensorLogLine();
|
||||
}
|
||||
log.close();
|
||||
return true;
|
||||
};
|
||||
|
||||
context.processPackets(packets, log, logger);
|
||||
}
|
||||
|
||||
interface PacketLogger {
|
||||
boolean takeValues(CANPacket packetContent);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
System.out.println("Finishing " + fileName);
|
||||
close(stream);
|
||||
stream = null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue