refactoring: better names
This commit is contained in:
parent
da6ef4d19d
commit
e50e24344b
|
@ -148,12 +148,12 @@ public class ByteRateOfChange {
|
|||
BinarySensorLog<BinaryLogEntry> log = context.getBinaryLogEntryBinarySensorLog(entries.values(), simpleFileName + LoggingStrategy.MLG);
|
||||
|
||||
|
||||
context.processPackets(packets, log, packetContent -> {
|
||||
context.writeLogContent(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);
|
||||
context.currentSnapshot.put(name, (double) value);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi.mlv;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.sensor_logs.BinaryLogEntry;
|
||||
import com.rusefi.sensor_logs.BinarySensorLog;
|
||||
|
||||
|
@ -12,21 +11,21 @@ import java.util.Map;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class LoggingContext {
|
||||
public Map<String, Double> values = new HashMap<>();
|
||||
AtomicReference<Long> time = new AtomicReference<>();
|
||||
public Map<String, Double> currentSnapshot = new HashMap<>();
|
||||
AtomicReference<Long> currentTime = new AtomicReference<>();
|
||||
|
||||
public BinarySensorLog<BinaryLogEntry> getBinaryLogEntryBinarySensorLog(Collection<BinaryLogEntry> entries, String outputFileName) {
|
||||
return new BinarySensorLog<>(o -> {
|
||||
Double value = this.values.get(o.getName());
|
||||
Double value = this.currentSnapshot.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) {
|
||||
public void writeLogContent(List<CANPacket> packets, BinarySensorLog<BinaryLogEntry> log, LoggingStrategy.PacketLogger logger) {
|
||||
for (CANPacket packetContent : packets) {
|
||||
this.time.set((long) (packetContent.getTimeStamp() * 1000));
|
||||
currentTime.set((long) (packetContent.getTimeStamp() * 1000));
|
||||
boolean needLine = logger.takeValues(packetContent);
|
||||
if (needLine)
|
||||
log.writeSensorLogLine();
|
||||
|
@ -35,6 +34,6 @@ public class LoggingContext {
|
|||
}
|
||||
|
||||
public BinarySensorLog.TimeProvider getTimeProvider() {
|
||||
return () -> this.time.get();
|
||||
return () -> this.currentTime.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,12 +38,12 @@ public class LoggingStrategy {
|
|||
return false;
|
||||
|
||||
for (DbcField field : packetMeta.getFields()) {
|
||||
context.values.put(field.getName(), field.getValue(packetContent));
|
||||
context.currentSnapshot.put(field.getName(), field.getValue(packetContent));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
context.processPackets(packets, log, logger);
|
||||
context.writeLogContent(packets, log, logger);
|
||||
}
|
||||
|
||||
public interface PacketLogger {
|
||||
|
|
|
@ -20,15 +20,15 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
private final TimeProvider timeProvider;
|
||||
private DataOutputStream stream;
|
||||
|
||||
private final String fileName;
|
||||
private final String outputFileName;
|
||||
|
||||
private int counter;
|
||||
private int lineCounter;
|
||||
|
||||
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors, TimeProvider timeProvider, String fileName) {
|
||||
public BinarySensorLog(Function<T, Double> valueProvider, Collection<T> sensors, TimeProvider timeProvider, String outputFileName) {
|
||||
this.valueProvider = Objects.requireNonNull(valueProvider, "valueProvider");
|
||||
this.entries = Objects.requireNonNull(sensors, "entries");
|
||||
this.timeProvider = timeProvider;
|
||||
this.fileName = fileName;
|
||||
this.outputFileName = outputFileName;
|
||||
}
|
||||
|
||||
public interface TimeProvider {
|
||||
|
@ -43,10 +43,10 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
@Override
|
||||
public void writeSensorLogLine() {
|
||||
if (stream == null) {
|
||||
System.out.println("Writing to " + fileName);
|
||||
System.out.println("Writing to " + outputFileName);
|
||||
|
||||
try {
|
||||
stream = new DataOutputStream(new FileOutputStream(fileName));
|
||||
stream = new DataOutputStream(new FileOutputStream(outputFileName));
|
||||
writeHeader();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
@ -57,7 +57,7 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
if (stream != null) {
|
||||
try {
|
||||
stream.write(0);
|
||||
stream.write(counter++);
|
||||
stream.write(lineCounter++);
|
||||
stream.writeShort((int) (timeProvider.currentTimestamp() * 100));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
@ -78,7 +78,7 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
stream.write(byteArray);
|
||||
stream.write(checkSum);
|
||||
|
||||
if (counter % 20 == 0) {
|
||||
if (lineCounter % 20 == 0) {
|
||||
// for not flush on each block of data but still flush
|
||||
stream.flush();
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
System.out.println("Finishing " + fileName);
|
||||
System.out.println("Finishing " + outputFileName);
|
||||
close(stream);
|
||||
stream = null;
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ public class BinarySensorLog<T extends BinaryLogEntry> implements SensorLog, Aut
|
|||
}
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
public String getOutputFileName() {
|
||||
return outputFileName;
|
||||
}
|
||||
|
||||
private void writeLine(DataOutputStream stream, String name, int length) throws IOException {
|
||||
|
|
|
@ -13,15 +13,15 @@ public class ByteRateOfChangeSandbox {
|
|||
public static void main(String[] args) throws IOException {
|
||||
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
|
||||
|
||||
String folder = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\Nissan\\2011_Xterra\\CAN-Nov-2022";
|
||||
String inputFileName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\Nissan\\2011_Xterra\\CAN-Nov-2022";
|
||||
|
||||
String reportDestinationFolder = folder + File.separator + "processed";
|
||||
String reportDestinationFolder = inputFileName + File.separator + "processed";
|
||||
new File(reportDestinationFolder).mkdirs();
|
||||
|
||||
|
||||
List<ByteRateOfChange.TraceReport> reports = new ArrayList<>();
|
||||
|
||||
FolderUtil.handleFolder(folder, (simpleFileName, fullFileName) -> {
|
||||
FolderUtil.handleFolder(inputFileName, (simpleFileName, fullFileName) -> {
|
||||
ByteRateOfChange.TraceReport report = ByteRateOfChange.process(fullFileName, reportDestinationFolder, simpleFileName);
|
||||
reports.add(report);
|
||||
}, "pcan.trc");
|
||||
|
|
Loading…
Reference in New Issue