diff --git a/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java b/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java index 81cb003..d0cf79b 100644 --- a/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java +++ b/src/main/java/com/rusefi/can/analysis/ByteRateOfChange.java @@ -148,12 +148,12 @@ public class ByteRateOfChange { BinarySensorLog 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; }); diff --git a/src/main/java/com/rusefi/mlv/LoggingContext.java b/src/main/java/com/rusefi/mlv/LoggingContext.java index 59fee3f..03a7e23 100644 --- a/src/main/java/com/rusefi/mlv/LoggingContext.java +++ b/src/main/java/com/rusefi/mlv/LoggingContext.java @@ -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 values = new HashMap<>(); - AtomicReference time = new AtomicReference<>(); + public Map currentSnapshot = new HashMap<>(); + AtomicReference currentTime = new AtomicReference<>(); public BinarySensorLog getBinaryLogEntryBinarySensorLog(Collection 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 packets, BinarySensorLog log, LoggingStrategy.PacketLogger logger) { + public void writeLogContent(List packets, BinarySensorLog 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(); } } diff --git a/src/main/java/com/rusefi/mlv/LoggingStrategy.java b/src/main/java/com/rusefi/mlv/LoggingStrategy.java index 24a0bd7..18fee5e 100644 --- a/src/main/java/com/rusefi/mlv/LoggingStrategy.java +++ b/src/main/java/com/rusefi/mlv/LoggingStrategy.java @@ -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 { diff --git a/src/main/java/com/rusefi/sensor_logs/BinarySensorLog.java b/src/main/java/com/rusefi/sensor_logs/BinarySensorLog.java index 16c3a87..6c4336d 100644 --- a/src/main/java/com/rusefi/sensor_logs/BinarySensorLog.java +++ b/src/main/java/com/rusefi/sensor_logs/BinarySensorLog.java @@ -20,15 +20,15 @@ public class BinarySensorLog 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 valueProvider, Collection sensors, TimeProvider timeProvider, String fileName) { + public BinarySensorLog(Function valueProvider, Collection 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 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 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 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 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 implements SensorLog, Aut } } - public String getFileName() { - return fileName; + public String getOutputFileName() { + return outputFileName; } private void writeLine(DataOutputStream stream, String name, int length) throws IOException { diff --git a/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java b/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java index 7fb90eb..07d7c93 100644 --- a/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java +++ b/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java @@ -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 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");