auto-sync
This commit is contained in:
parent
4466187798
commit
c300701348
|
@ -24,12 +24,12 @@ public enum FileLog {
|
|||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
rlog(msg);
|
||||
MAIN.logLine(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
rlog(msg);
|
||||
MAIN.logLine(msg);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -95,8 +95,8 @@ public enum FileLog {
|
|||
}
|
||||
}
|
||||
|
||||
public static void rlog(String msg) {
|
||||
System.out.println("r " + msg);
|
||||
private static void rlog(String msg) {
|
||||
System.out.println("rlog " + msg);
|
||||
}
|
||||
|
||||
public void log(IllegalStateException exception) {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
|
||||
import com.rusefi.ConfigurationImage;
|
||||
import com.rusefi.ConfigurationImageDiff;
|
||||
import com.rusefi.Logger;
|
||||
import com.rusefi.Timeouts;
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.io.DataListener;
|
||||
import com.rusefi.io.serial.SerialPortReader;
|
||||
|
@ -102,7 +99,7 @@ public class BinaryProtocol {
|
|||
}
|
||||
} catch (SerialPortException | EOFException e) {
|
||||
close();
|
||||
System.out.println("exception: " + e);
|
||||
FileLog.MAIN.logLine("exception: " + e);
|
||||
return;
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
@ -113,9 +110,11 @@ public class BinaryProtocol {
|
|||
|
||||
private void dropPending() {
|
||||
synchronized (cbb) {
|
||||
if (isClosed)
|
||||
return;
|
||||
int pending = cbb.length();
|
||||
if (pending > 0) {
|
||||
logger.error("Unexpected pending data: " + pending);
|
||||
logger.error("Unexpected pending data: " + pending + " byte(s)");
|
||||
cbb.get(new byte[pending]);
|
||||
}
|
||||
try {
|
||||
|
@ -270,10 +269,12 @@ public class BinaryProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
private void close() {
|
||||
public void close() {
|
||||
isClosed = true;
|
||||
try {
|
||||
FileLog.MAIN.logLine("CLOSING PORT...");
|
||||
serialPort.closePort();
|
||||
FileLog.MAIN.logLine("PORT CLOSED");
|
||||
} catch (SerialPortException e) {
|
||||
logger.error("Error closing port: " + e);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ public class BaseMap {
|
|||
}
|
||||
|
||||
public static XYData loadData(String filename, final String key, final String value) {
|
||||
FileLog.rlog("Loading from " + filename);
|
||||
FileLog.rlog("Loading " + key + ">" + value);
|
||||
FileLog.MAIN.logLine("Loading from " + filename);
|
||||
FileLog.MAIN.logLine("Loading " + key + ">" + value);
|
||||
final XYData data = new XYData();
|
||||
|
||||
EngineState.EngineStateListener listener = new EngineState.EngineStateListenerImpl() {
|
||||
|
|
|
@ -60,10 +60,10 @@ public class PortHolder {
|
|||
setupPort(serialPort, BAUD_RATE);
|
||||
// serialPort.addEventListener(new SerialPortReader(serialPort, portHolderListener));
|
||||
} catch (SerialPortException e) {
|
||||
FileLog.rlog("ERROR " + e.getMessage());
|
||||
FileLog.MAIN.logLine("ERROR " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
FileLog.rlog("PortHolder: Sleeping a bit");
|
||||
FileLog.MAIN.logLine("PortHolder: Sleeping a bit");
|
||||
try {
|
||||
// todo: why is this delay here? add a comment
|
||||
Thread.sleep(200);
|
||||
|
@ -103,7 +103,7 @@ public class PortHolder {
|
|||
}
|
||||
sleep();
|
||||
}
|
||||
FileLog.rlog("Stopping text pull");
|
||||
FileLog.MAIN.logLine("Stopping text pull");
|
||||
}
|
||||
};
|
||||
Thread tr = new Thread(textPull);
|
||||
|
|
|
@ -24,11 +24,11 @@ class SerialManager {
|
|||
|
||||
public static void scheduleOpening(LinkManager.LinkStateListener listener) {
|
||||
SerialManager.listener = listener;
|
||||
FileLog.rlog("scheduleOpening");
|
||||
FileLog.MAIN.logLine("scheduleOpening");
|
||||
LinkManager.IO_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FileLog.rlog("scheduleOpening>openPort");
|
||||
FileLog.MAIN.logLine("scheduleOpening>openPort");
|
||||
PortHolder.getInstance().openPort(port, SerialManager.dataListener, SerialManager.listener);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SerialPortReader implements SerialPortEventListener {
|
|||
e.printStackTrace(System.err);
|
||||
}
|
||||
} else {
|
||||
FileLog.rlog("less expected SerialPortReader serialEvent " + spe);
|
||||
FileLog.MAIN.logLine("less expected SerialPortReader serialEvent " + spe);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public class TcpConnector implements LinkConnector {
|
|||
*/
|
||||
@Override
|
||||
public void connect(LinkManager.LinkStateListener listener) {
|
||||
FileLog.rlog("Connecting to " + port);
|
||||
FileLog.MAIN.logLine("Connecting to " + port);
|
||||
BufferedInputStream stream;
|
||||
try {
|
||||
Socket socket = new Socket(LOCALHOST, port);
|
||||
|
@ -101,7 +101,7 @@ public class TcpConnector implements LinkConnector {
|
|||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TCP connector loop");
|
||||
FileLog.rlog("Running TCP connection loop");
|
||||
FileLog.MAIN.logLine("Running TCP connection loop");
|
||||
while (true) {
|
||||
try {
|
||||
String line = reader.readLine();
|
||||
|
@ -134,7 +134,7 @@ public class TcpConnector implements LinkConnector {
|
|||
@Override
|
||||
public void send(String text) throws InterruptedException {
|
||||
String command = LinkManager.encodeCommand(text);
|
||||
FileLog.rlog("Writing " + command);
|
||||
FileLog.MAIN.logLine("Writing " + command);
|
||||
try {
|
||||
writer.write(command + "\r\n");
|
||||
writer.flush();
|
||||
|
|
|
@ -120,7 +120,7 @@ public final class Histograms {
|
|||
confidence_bounds = new double[]{0.5 - H_CONFIDENCE * 0.5, 0.5, 0.5 + H_CONFIDENCE * 0.5};
|
||||
confidence_separators = new String[]{"(", " [", "-", "-", "] ", ")"};
|
||||
|
||||
FileLog.rlog("BOUND_LENGTH=" + BOUND_LENGTH);
|
||||
FileLog.MAIN.logLine("BOUND_LENGTH=" + BOUND_LENGTH);
|
||||
|
||||
bounds = new long[BOUND_LENGTH];
|
||||
bounds[0] = 0;
|
||||
|
|
|
@ -26,11 +26,11 @@ public class ReportReader {
|
|||
|
||||
public static TreeMap<Integer, TreeMap<Integer, ReportLine>> readMap(String filename) {
|
||||
if (!new File(filename).exists()) {
|
||||
FileLog.rlog("Error: not found " + filename);
|
||||
FileLog.MAIN.logLine("Error: not found " + filename);
|
||||
return new TreeMap<>();
|
||||
}
|
||||
List<ReportLine> lines = read(filename);
|
||||
FileLog.rlog("Got " + lines.size() + " lines");
|
||||
FileLog.MAIN.logLine("Got " + lines.size() + " lines");
|
||||
|
||||
lines = filter(Collections.unmodifiableList(lines));
|
||||
|
||||
|
@ -73,8 +73,8 @@ public class ReportReader {
|
|||
minRpm = Math.min(minRpm, cur.getRpm().getValue());
|
||||
maxRpm = Math.max(maxRpm, cur.getRpm().getValue());
|
||||
}
|
||||
FileLog.rlog("MAF range from " + minMaf + " to " + maxMaf);
|
||||
FileLog.rlog("RPM range from " + minRpm + " to " + maxRpm);
|
||||
FileLog.MAIN.logLine("MAF range from " + minMaf + " to " + maxMaf);
|
||||
FileLog.MAIN.logLine("RPM range from " + minRpm + " to " + maxRpm);
|
||||
}
|
||||
|
||||
private static List<ReportLine> filter(List<ReportLine> lines) {
|
||||
|
@ -93,7 +93,7 @@ public class ReportReader {
|
|||
int timeDiff = cur.getTime() - prev.getTime();
|
||||
|
||||
if (Math.abs(rpmDiff) > INVALID_RPM_DIFF) {
|
||||
FileLog.rlog("Invalid diff: " + cur);
|
||||
FileLog.MAIN.logLine("Invalid diff: " + cur);
|
||||
removedCount++;
|
||||
continue;
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ public class ReportReader {
|
|||
// System.out.println("value," + cur.getRpm().getValue() + "," + cur.getMaf().getValue() + "," + cur.getWave());
|
||||
}
|
||||
double percent = 100.0 * removedCount / originalCount;
|
||||
FileLog.rlog(removedCount + " out of " + originalCount + " record(s) removed. " + percent + "%");
|
||||
FileLog.rlog("Max valid diff: " + maxValidDiff);
|
||||
FileLog.MAIN.logLine(removedCount + " out of " + originalCount + " record(s) removed. " + percent + "%");
|
||||
FileLog.MAIN.logLine("Max valid diff: " + maxValidDiff);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ public class EngineState {
|
|||
response = handleStringActionPair(response, pair, listener);
|
||||
}
|
||||
if (originalResponse.length() == response.length()) {
|
||||
FileLog.rlog("EngineState.unknown: " + response);
|
||||
FileLog.MAIN.logLine("EngineState.unknown: " + response);
|
||||
// discarding invalid line
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class AverageData {
|
|||
double minX = data.getMinXValue();
|
||||
double xWidth = data.getMaxXValue() - minX;
|
||||
|
||||
FileLog.rlog("From x" + minX + " w=" + xWidth);
|
||||
FileLog.MAIN.logLine("From x" + minX + " w=" + xWidth);
|
||||
|
||||
XYData result = new XYData();
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class AverageData {
|
|||
double fromX_ = minX + (xWidth * i) / divider;
|
||||
double toX_ = minX + (xWidth * (i + 1)) / divider;
|
||||
|
||||
FileLog.rlog("from " + fromX_ + " to " + toX_);
|
||||
FileLog.MAIN.logLine("from " + fromX_ + " to " + toX_);
|
||||
|
||||
// double fromX = data.findXfromSet(fromX_);
|
||||
// double toX = data.findXfromSet(toX_);
|
||||
|
|
|
@ -129,7 +129,7 @@ public class XYData {
|
|||
public void saveToFile(String filename) {
|
||||
try {
|
||||
String name = date + filename;
|
||||
FileLog.rlog("Writing data to " + name);
|
||||
FileLog.MAIN.logLine("Writing data to " + name);
|
||||
Writer w = new FileWriter(name);
|
||||
for (YAxisData yAxisData : yDatas.values())
|
||||
yAxisData.write(w);
|
||||
|
|
|
@ -30,8 +30,8 @@ public class XYDataReader {
|
|||
Point3D xyz = Point3D.parseLine(line);
|
||||
data.addPoint(xyz);
|
||||
}
|
||||
FileLog.rlog("x range: " + data.getMinXValue() + " to " + data.getMaxXValue());
|
||||
FileLog.rlog("y range: " + data.getMinYValue() + " to " + data.getMaxYValue());
|
||||
FileLog.MAIN.logLine("x range: " + data.getMinXValue() + " to " + data.getMaxXValue());
|
||||
FileLog.MAIN.logLine("y range: " + data.getMinYValue() + " to " + data.getMaxYValue());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class YAxisData {
|
|||
|
||||
float newAvg = holder.get();
|
||||
if (newAvg != value && !Float.isNaN(newAvg)) {
|
||||
FileLog.rlog("new " + value + " avg " + newAvg + " for x=" + x + "/y=" + y);
|
||||
FileLog.MAIN.logLine("new " + value + " avg " + newAvg + " for x=" + x + "/y=" + y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class WaveChartParser {
|
|||
public static WaveChart unpackToMap(String value) {
|
||||
if (value == null)
|
||||
throw new NullPointerException("value");
|
||||
FileLog.rlog(": " + value);
|
||||
FileLog.MAIN.logLine(": " + value);
|
||||
|
||||
String[] array = value.split(DELI);
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public class AnalogChartPanel {
|
|||
List<Double> keys = new ArrayList<>(values.keySet());
|
||||
minX = keys.get(0);
|
||||
maxX = keys.get(keys.size() - 1);
|
||||
FileLog.rlog("Analog chart from " + minX + " to " + maxX);
|
||||
FileLog.MAIN.logLine("Analog chart from " + minX + " to " + maxX);
|
||||
|
||||
TreeSet<Double> sortedValues = new TreeSet<>();
|
||||
sortedValues.addAll(values.values());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
@ -53,8 +54,14 @@ public class Launcher {
|
|||
|
||||
@Override
|
||||
protected void onWindowClosed() {
|
||||
super.onWindowClosed();
|
||||
/**
|
||||
* here we would close the port and log a message about it
|
||||
*/
|
||||
windowClosedHandler();
|
||||
/**
|
||||
* here we would close the log file
|
||||
*/
|
||||
super.onWindowClosed();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -140,6 +147,9 @@ public class Launcher {
|
|||
root.setProperty("version", CONSOLE_VERSION);
|
||||
root.setProperty(TAB_INDEX, tabbedPane.getSelectedIndex());
|
||||
getConfig().save();
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
if (bp != null && !bp.isClosed)
|
||||
bp.close();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ public class LogViewer extends JPanel {
|
|||
engineState.registerStringValueAction("wave_chart", new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String value) {
|
||||
FileLog.rlog("Got wave_chart: " + value);
|
||||
FileLog.MAIN.logLine("Got wave_chart: " + value);
|
||||
|
||||
ChartRepository.getInstance().addChart(value);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class PersistentConfiguration {
|
|||
config = (Map<String, Object>) e.readObject();
|
||||
e.close();
|
||||
} catch (Throwable e) {
|
||||
FileLog.rlog("Error reading from " + CONFIG_FILE_NAME);
|
||||
FileLog.MAIN.logLine("Error reading from " + CONFIG_FILE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class PersistentConfiguration {
|
|||
e.close();
|
||||
System.out.println("Saved to " + CONFIG_FILE_NAME);
|
||||
} catch (FileNotFoundException e1) {
|
||||
FileLog.rlog("Error saving " + CONFIG_FILE_NAME);
|
||||
FileLog.MAIN.logLine("Error saving " + CONFIG_FILE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,11 @@ public class FrameHelper {
|
|||
}
|
||||
|
||||
protected void onWindowOpened() {
|
||||
FileLog.rlog("onWindowOpened");
|
||||
FileLog.MAIN.logLine("onWindowOpened");
|
||||
}
|
||||
|
||||
protected void onWindowClosed() {
|
||||
FileLog.rlog("onWindowClosed");
|
||||
FileLog.MAIN.logLine("onWindowClosed");
|
||||
FileLog.MAIN.close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue