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