mirror of https://github.com/rusefi/rusefi-1.git
.logicdata files are a bit broken #1482
This commit is contained in:
parent
9fb76630c4
commit
9990a48c7f
|
@ -28,6 +28,7 @@ import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -81,9 +82,15 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
private boolean isCompositeLoggerEnabled;
|
private boolean isCompositeLoggerEnabled;
|
||||||
private long lastLowRpmTime = System.currentTimeMillis();
|
private long lastLowRpmTime = System.currentTimeMillis();
|
||||||
|
|
||||||
private List<StreamFile> compositeLogs = Arrays.asList(new VcdStreamFile(getFileName("rusEFI_trigger_log_")),
|
private List<StreamFile> compositeLogs = new ArrayList<>();
|
||||||
new TSHighSpeedLog(getFileName("rusEFI_trigger_log_")),
|
|
||||||
new LogicdataStreamFile(getFileName("rusEFI_trigger_log_", ".logicdata")));
|
private void createCompositesIfNeeded() {
|
||||||
|
if (!compositeLogs.isEmpty())
|
||||||
|
return;
|
||||||
|
compositeLogs.addAll(Arrays.asList(new VcdStreamFile(getFileName("rusEFI_trigger_log_")),
|
||||||
|
new TSHighSpeedLog(getFileName("rusEFI_trigger_log_")),
|
||||||
|
new LogicdataStreamFile(getFileName("rusEFI_trigger_log_", ".logicdata"))));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isClosed;
|
public boolean isClosed;
|
||||||
/**
|
/**
|
||||||
|
@ -101,11 +108,14 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final Thread hook = new Thread(() -> closeComposites());
|
||||||
|
|
||||||
protected BinaryProtocol(final Logger logger, IoStream stream) {
|
protected BinaryProtocol(final Logger logger, IoStream stream) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
|
||||||
incomingData = createDataBuffer(stream, logger);
|
incomingData = createDataBuffer(stream, logger);
|
||||||
|
Runtime.getRuntime().addShutdownHook(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IncomingDataBuffer createDataBuffer(IoStream stream, Logger logger) {
|
public static IncomingDataBuffer createDataBuffer(IoStream stream, Logger logger) {
|
||||||
|
@ -222,11 +232,17 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
packet[1] = Fields.TS_COMPOSITE_DISABLE;
|
packet[1] = Fields.TS_COMPOSITE_DISABLE;
|
||||||
executeCommand(packet, "disable composite");
|
executeCommand(packet, "disable composite");
|
||||||
isCompositeLoggerEnabled = false;
|
isCompositeLoggerEnabled = false;
|
||||||
for (StreamFile composite : compositeLogs)
|
closeComposites();
|
||||||
composite.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void closeComposites() {
|
||||||
|
for (StreamFile composite : compositeLogs) {
|
||||||
|
composite.close();
|
||||||
|
}
|
||||||
|
compositeLogs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public Logger getLogger() {
|
public Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
@ -397,6 +413,8 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
isClosed = true;
|
isClosed = true;
|
||||||
SensorCentral.getInstance().removeListener(Sensor.RPM, rpmListener);
|
SensorCentral.getInstance().removeListener(Sensor.RPM, rpmListener);
|
||||||
stream.close();
|
stream.close();
|
||||||
|
closeComposites();
|
||||||
|
Runtime.getRuntime().removeShutdownHook(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeData(byte[] content, Integer offset, int size, Logger logger) throws SerialPortException, EOFException, InterruptedException {
|
public void writeData(byte[] content, Integer offset, int size, Logger logger) throws SerialPortException, EOFException, InterruptedException {
|
||||||
|
@ -521,6 +539,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
byte[] response = executeCommand(packet, "composite log", true);
|
byte[] response = executeCommand(packet, "composite log", true);
|
||||||
if (checkResponseCode(response, RESPONSE_OK)) {
|
if (checkResponseCode(response, RESPONSE_OK)) {
|
||||||
List<CompositeEvent> events = CompositeParser.parse(response);
|
List<CompositeEvent> events = CompositeParser.parse(response);
|
||||||
|
createCompositesIfNeeded();
|
||||||
for (StreamFile composite : compositeLogs)
|
for (StreamFile composite : compositeLogs)
|
||||||
composite.append(events);
|
composite.append(events);
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,6 +344,8 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeFooter() throws IOException {
|
protected void writeFooter() throws IOException {
|
||||||
|
if (stream == null)
|
||||||
|
return;
|
||||||
write(BLOCK);
|
write(BLOCK);
|
||||||
for (int i = 0; i < numChannels; i++) {
|
for (int i = 0; i < numChannels; i++) {
|
||||||
writeId(i, 1);
|
writeId(i, 1);
|
||||||
|
|
|
@ -32,14 +32,15 @@ public abstract class StreamFile {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignoring this one
|
// ignoring this one
|
||||||
}
|
}
|
||||||
|
writer = null;
|
||||||
}
|
}
|
||||||
writer = null;
|
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
try {
|
try {
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignoring this one
|
// ignoring this one
|
||||||
}
|
}
|
||||||
|
stream = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class TSHighSpeedLog extends StreamFile {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeFooter() throws IOException {
|
protected void writeFooter() throws IOException {
|
||||||
writer.write("MARK 028\n");
|
if (writer != null)
|
||||||
|
writer.write("MARK 028\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue