package com.rusefi.mlv; import com.rusefi.can.CANPacket; 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; public class LoggingContext { public Map currentSnapshot = new HashMap<>(); AtomicReference currentTime = new AtomicReference<>(); public BinarySensorLog getBinaryLogEntryBinarySensorLog(Collection entries, String outputFileName) { return new BinarySensorLog<>(o -> { Double value = this.currentSnapshot.get(o.getName()); if (value == null) return 0.0; return value; }, entries, getTimeProvider(), outputFileName); } public void writeLogContent(List packets, BinarySensorLog log, LoggingStrategy.PacketLogger logger) { for (CANPacket packetContent : packets) { currentTime.set((long) (packetContent.getTimeStamp() * 1000)); boolean needLine = logger.takeValues(packetContent); if (needLine) log.writeSensorLogLine(); } log.close(); } public BinarySensorLog.TimeProvider getTimeProvider() { return () -> this.currentTime.get(); } }