sweet usability

This commit is contained in:
rusefi 2020-05-30 13:01:59 -04:00
parent bd9a601ce6
commit 1aac0f88e7
6 changed files with 141 additions and 47 deletions

View File

@ -67,12 +67,32 @@ public class BinaryProtocol implements BinaryProtocolCommands {
private final Object imageLock = new Object(); private final Object imageLock = new Object();
private ConfigurationImage controller; private ConfigurationImage controller;
private static final int COMPOSITE_OFF_RPM = 300;
/**
* Composite logging turns off after 10 seconds of RPM above 300
*/
private boolean needCompositeLogger = true;
private boolean isCompositeLoggerEnabled;
private long lastLowRpmTime = System.currentTimeMillis();
private VcdStreamFile composite = new VcdStreamFile();
public boolean isClosed; public boolean isClosed;
/** /**
* Snapshot of current gauges status * Snapshot of current gauges status
* @see BinaryProtocolCommands#COMMAND_OUTPUTS * @see BinaryProtocolCommands#COMMAND_OUTPUTS
*/ */
public byte[] currentOutputs; public byte[] currentOutputs;
private SensorCentral.SensorListener rpmListener = value -> {
if (value <= COMPOSITE_OFF_RPM) {
needCompositeLogger = true;
lastLowRpmTime = System.currentTimeMillis();
} else if (System.currentTimeMillis() - lastLowRpmTime > 10 * Timeouts.SECOND) {
FileLog.MAIN.logLine("Time to turn off composite logging");
needCompositeLogger = false;
}
};
protected BinaryProtocol(final Logger logger, IoStream stream) { protected BinaryProtocol(final Logger logger, IoStream stream) {
this.logger = logger; this.logger = logger;
@ -134,6 +154,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
return false; return false;
startTextPullThread(listener); startTextPullThread(listener);
SensorCentral.getInstance().addListener(Sensor.RPM, rpmListener);
return true; return true;
} }
@ -152,7 +173,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
public void run() { public void run() {
if (requestOutputChannels()) if (requestOutputChannels())
ConnectionWatchdog.onDataArrived(); ConnectionWatchdog.onDataArrived();
// getComposite(); compositeLogic();
String text = requestPendingMessages(); String text = requestPendingMessages();
if (text != null) if (text != null)
listener.onDataArrived((text + "\r\n").getBytes()); listener.onDataArrived((text + "\r\n").getBytes());
@ -170,6 +191,19 @@ public class BinaryProtocol implements BinaryProtocolCommands {
tr.start(); tr.start();
} }
private void compositeLogic() {
if (needCompositeLogger) {
getComposite();
} else if (isCompositeLoggerEnabled) {
byte packet[] = new byte[2];
packet[0] = Fields.TS_SET_LOGGER_SWITCH;
packet[1] = Fields.TS_COMPOSITE_DISABLE;
executeCommand(packet, "disable composite");
isCompositeLoggerEnabled = false;
composite.close();
}
}
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
} }
@ -338,6 +372,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
if (isClosed) if (isClosed)
return; return;
isClosed = true; isClosed = true;
SensorCentral.getInstance().removeListener(Sensor.RPM, rpmListener);
stream.close(); stream.close();
} }
@ -443,7 +478,6 @@ public class BinaryProtocol implements BinaryProtocolCommands {
byte[] response = executeCommand(new byte[]{Fields.TS_GET_TEXT}, "text", true); byte[] response = executeCommand(new byte[]{Fields.TS_GET_TEXT}, "text", true);
if (response != null && response.length == 1) if (response != null && response.length == 1)
Thread.sleep(100); Thread.sleep(100);
// System.out.println(result);
return new String(response, 1, response.length - 1); return new String(response, 1, response.length - 1);
} catch (InterruptedException e) { } catch (InterruptedException e) {
FileLog.MAIN.log(e); FileLog.MAIN.log(e);
@ -457,15 +491,14 @@ public class BinaryProtocol implements BinaryProtocolCommands {
byte packet[] = new byte[1]; byte packet[] = new byte[1];
packet[0] = Fields.TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY; packet[0] = Fields.TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY;
// get command would enable composite logging in controller but we need to turn it off from our end
// todo: actually if console gets disconnected composite logging might end up enabled in controller?
isCompositeLoggerEnabled = true;
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);
try { composite.append(events);
CompositeParser.writeVCD(events, new FileWriter("rusEFI.vcd"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
} }
} }

View File

@ -22,6 +22,7 @@ public enum FileLog {
public static final String LOG_INFO_TEXT = "Writing logs to '" + DIR + "'"; public static final String LOG_INFO_TEXT = "Writing logs to '" + DIR + "'";
public static final String OS_VERSION = "os.version"; public static final String OS_VERSION = "os.version";
public static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss_SSS"; public static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss_SSS";
private static final String WIKI_URL = "https://github.com/rusefi/rusefi/wiki/rusEFI-logs-folder";
public static String currentLogName; public static String currentLogName;
public static final String END_OF_TIMESTAND_TAG = "<EOT>: "; public static final String END_OF_TIMESTAND_TAG = "<EOT>: ";
public static final Logger LOGGER = new Logger() { public static final Logger LOGGER = new Logger() {
@ -62,8 +63,7 @@ public enum FileLog {
private static void writeReadmeFile() { private static void writeReadmeFile() {
LazyFile file = new LazyFile(DIR + "README.html"); LazyFile file = new LazyFile(DIR + "README.html");
file.write("<center>" + file.write("<center>" + "<a href='" + WIKI_URL + "'>More info online<br/><img src=https://raw.githubusercontent.com/wiki/rusefi/rusefi/logo.gif></a>");
"<a href='https://github.com/rusefi/rusefi/wiki/rusEFI-logs-folder'>More info online<br/><img src=https://raw.githubusercontent.com/wiki/rusefi/rusefi/logo.gif></a>");
try { try {
file.close(); file.close();
} catch (IOException e) { } catch (IOException e) {

View File

@ -0,0 +1,11 @@
package com.rusefi.binaryprotocol;
import com.rusefi.composite.CompositeEvent;
import java.util.List;
public interface StreamFile {
void append(List<CompositeEvent> events);
void close();
}

View File

@ -0,0 +1,83 @@
package com.rusefi.binaryprotocol;
import com.rusefi.FileLog;
import com.rusefi.composite.CompositeEvent;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.List;
/**
* https://en.wikipedia.org/wiki/Value_change_dump
*
* @see FileLog#WIKI_URL
*/
public class VcdStreamFile implements StreamFile {
private static final String TAG_PRIMARY = "t";
private static final String TAG_SECONDARY = "s";
private static final String TAG_TRG = "r";
private static final String TAG_SYNC = "y";
private FileWriter writer;
public static void writeHeader(Writer writer, Date date) throws IOException {
writer.write("$date\n");
writer.write("\t" + date + "\n");
writer.write("$end\n" +
"$version\n" +
" 1.0\n" +
"$end\n" +
"$timescale\n" +
" 1ps\n" +
"$end\n" +
"$scope module test $end\n" +
"$var wire 1 " + TAG_PRIMARY + " PRI_TRG $end\n" +
"$var wire 1 " + TAG_SECONDARY + " SEC_TRG $end\n" +
"$var wire 1 " + TAG_TRG + " TRG $end\n" +
"$var wire 1 " + TAG_SYNC + " SYNC $end\n" +
"$upscope $end\n" +
"$enddefinitions $end\n" +
"$dumpvars\n");
}
public static void appendEvents(List<CompositeEvent> events, Writer writer) throws IOException {
for (CompositeEvent event : events) {
writer.write("#" + event.getTimestamp() + "\n");
writer.write(event.isPrimaryTriggerAsInt() + TAG_PRIMARY + "\n");
writer.write(event.isSecondaryTriggerAsInt() + TAG_SECONDARY + "\n");
writer.write(event.isTrgAsInt() + TAG_TRG + "\n");
writer.write(event.isSyncAsInt() + TAG_SYNC + "\n");
}
writer.flush();
}
@Override
public void append(List<CompositeEvent> events) {
try {
if (writer == null) {
String fileName = FileLog.DIR + "rusEFI_trigger_log_" + FileLog.getDate() + ".vcd";
writer = new FileWriter(fileName);
writeHeader(writer, new Date());
}
appendEvents(events, writer);
} catch (IOException e) {
// ignoring this one
}
}
@Override
public void close() {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// ignoring this one
}
}
writer = null;
}
}

View File

@ -1,11 +1,11 @@
package com.rusefi.composite; package com.rusefi.composite;
import com.opensr5.ini.field.EnumIniField; import com.opensr5.ini.field.EnumIniField;
import com.rusefi.binaryprotocol.VcdStreamFile;
import com.rusefi.config.generated.Fields; import com.rusefi.config.generated.Fields;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -15,11 +15,6 @@ import java.util.List;
public class CompositeParser { public class CompositeParser {
public static final String TAG_PRIMARY = "t";
public static final String TAG_SECONDARY = "s";
public static final String TAG_TRG = "r";
public static final String TAG_SYNC = "y";
public static List<CompositeEvent> parse(byte[] response) { public static List<CompositeEvent> parse(byte[] response) {
ByteBuffer byteBuffer = ByteBuffer.wrap(response); ByteBuffer byteBuffer = ByteBuffer.wrap(response);
byteBuffer.order(ByteOrder.BIG_ENDIAN); byteBuffer.order(ByteOrder.BIG_ENDIAN);
@ -46,40 +41,12 @@ public class CompositeParser {
return events; return events;
} }
/**
* https://en.wikipedia.org/wiki/Value_change_dump
*/
public static void writeVCD(List<CompositeEvent> events, Writer writer, Date date) throws IOException { public static void writeVCD(List<CompositeEvent> events, Writer writer, Date date) throws IOException {
writer.write("$date\n"); VcdStreamFile.writeHeader(writer, date);
writer.write("\t" + date + "\n"); VcdStreamFile.appendEvents(events, writer);
writer.write("$end\n" +
"$version\n" +
" 1.0\n" +
"$end\n" +
"$timescale\n" +
" 1ps\n" +
"$end\n" +
"$scope module test $end\n" +
"$var wire 1 " + TAG_PRIMARY + " PRI_TRG $end\n" +
"$var wire 1 " + TAG_SECONDARY + " SEC_TRG $end\n" +
"$var wire 1 " + TAG_TRG + " TRG $end\n" +
"$var wire 1 " + TAG_SYNC + " SYNC $end\n" +
"$upscope $end\n" +
"$enddefinitions $end\n" +
"$dumpvars\n");
for (CompositeEvent event : events) {
writer.write("#" + event.getTimestamp() + "\n");
writer.write(event.isPrimaryTriggerAsInt() + TAG_PRIMARY + "\n");
writer.write(event.isSecondaryTriggerAsInt() + TAG_SECONDARY + "\n");
writer.write(event.isTrgAsInt() + TAG_TRG + "\n");
writer.write(event.isSyncAsInt() + TAG_SYNC + "\n");
}
writer.flush();
} }
public static void writeVCD(List<CompositeEvent> events, FileWriter fileWriter) throws IOException { public static void writeVCD(List<CompositeEvent> events, FileWriter fileWriter) throws IOException {
writeVCD(events, fileWriter, new Date()); writeVCD(events, fileWriter, new Date());
} }
} }

View File

@ -139,7 +139,7 @@ public class SensorLogger {
private static void startSensorLogFile() { private static void startSensorLogFile() {
FileLog.createFolderIfNeeded(); FileLog.createFolderIfNeeded();
String fileName = FileLog.DIR + "rusEFI_" + FileLog.getDate() + ".msl"; String fileName = FileLog.DIR + "rusEFI_gauges_" + FileLog.getDate() + ".msl";
fileStartTime = System.currentTimeMillis(); fileStartTime = System.currentTimeMillis();
try { try {