mirror of https://github.com/rusefi/rusefi-1.git
auto-sync
This commit is contained in:
parent
f6223df68f
commit
be8c0795d6
|
@ -14,7 +14,7 @@ public enum FileLog {
|
||||||
MAIN,
|
MAIN,
|
||||||
SIMULATOR_CONSOLE;
|
SIMULATOR_CONSOLE;
|
||||||
|
|
||||||
private static final String DIR = "out/";
|
public static final String DIR = "out/";
|
||||||
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() {
|
||||||
|
|
|
@ -23,10 +23,14 @@ public class FuelAutoTune {
|
||||||
|
|
||||||
public static class stDataOnline {
|
public static class stDataOnline {
|
||||||
public final double AFR;
|
public final double AFR;
|
||||||
|
private final int rpm;
|
||||||
|
private final double engineLoad;
|
||||||
int rpmIndex;
|
int rpmIndex;
|
||||||
int engineLoadIndex;
|
int engineLoadIndex;
|
||||||
|
|
||||||
public stDataOnline(double AFR, int rpmIndex, int engineLoadIndex) {
|
public stDataOnline(double AFR, int rpmIndex, int engineLoadIndex, int rpm, double engineLoad) {
|
||||||
|
this.rpm = rpm;
|
||||||
|
this.engineLoad = engineLoad;
|
||||||
if (rpmIndex < 0 || rpmIndex >= Fields.FUEL_RPM_COUNT)
|
if (rpmIndex < 0 || rpmIndex >= Fields.FUEL_RPM_COUNT)
|
||||||
throw new IllegalStateException("rpmIndex " + rpmIndex);
|
throw new IllegalStateException("rpmIndex " + rpmIndex);
|
||||||
if (engineLoadIndex < 0 || engineLoadIndex >= Fields.FUEL_LOAD_COUNT)
|
if (engineLoadIndex < 0 || engineLoadIndex >= Fields.FUEL_LOAD_COUNT)
|
||||||
|
@ -41,7 +45,7 @@ public class FuelAutoTune {
|
||||||
if (rpmIndex < 0 || rpmIndex >= Fields.FUEL_RPM_COUNT)
|
if (rpmIndex < 0 || rpmIndex >= Fields.FUEL_RPM_COUNT)
|
||||||
return null;
|
return null;
|
||||||
int engineLoadIndex = (int) (engineLoad / 120.0 * SIZE);
|
int engineLoadIndex = (int) (engineLoad / 120.0 * SIZE);
|
||||||
return new stDataOnline(AFR, rpmIndex, engineLoadIndex);
|
return new stDataOnline(AFR, rpmIndex, engineLoadIndex, rpm, engineLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRpmIndex() {
|
int getRpmIndex() {
|
||||||
|
@ -59,6 +63,14 @@ public class FuelAutoTune {
|
||||||
public int RPM_RT_32() {
|
public int RPM_RT_32() {
|
||||||
return getRpmIndex();
|
return getRpmIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRpm() {
|
||||||
|
return rpm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getEngineLoad() {
|
||||||
|
return engineLoad;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Result {
|
public static class Result {
|
||||||
|
|
|
@ -32,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||||
* @see EngineSnifferPanel
|
* @see EngineSnifferPanel
|
||||||
*/
|
*/
|
||||||
public class Launcher {
|
public class Launcher {
|
||||||
public static final int CONSOLE_VERSION = 20160206;
|
public static final int CONSOLE_VERSION = 20160208;
|
||||||
public static final boolean SHOW_STIMULATOR = false;
|
public static final boolean SHOW_STIMULATOR = false;
|
||||||
private static final String TAB_INDEX = "main_tab";
|
private static final String TAB_INDEX = "main_tab";
|
||||||
protected static final String PORT_KEY = "port";
|
protected static final String PORT_KEY = "port";
|
||||||
|
@ -114,7 +114,7 @@ public class Launcher {
|
||||||
tabbedPane.add("Bench Test", new BenchTestPane().getContent());
|
tabbedPane.add("Bench Test", new BenchTestPane().getContent());
|
||||||
if (!LinkManager.isLogViewer() && false) // todo: fix it & better name?
|
if (!LinkManager.isLogViewer() && false) // todo: fix it & better name?
|
||||||
tabbedPane.add("Logs Manager", logsManager.getContent());
|
tabbedPane.add("Logs Manager", logsManager.getContent());
|
||||||
if (false)
|
if (true)
|
||||||
tabbedPane.add("Fuel Tune", fuelTunePane.getContent());
|
tabbedPane.add("Fuel Tune", fuelTunePane.getContent());
|
||||||
|
|
||||||
if (!LinkManager.isLogViewerMode(port)) {
|
if (!LinkManager.isLogViewerMode(port)) {
|
||||||
|
|
|
@ -21,12 +21,11 @@ import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,6 +46,7 @@ public class FuelTunePane {
|
||||||
private final JCheckBox collect = new JCheckBox("enable");
|
private final JCheckBox collect = new JCheckBox("enable");
|
||||||
private final JButton clean = new JButton("clear");
|
private final JButton clean = new JButton("clear");
|
||||||
private byte[] newVeMap;
|
private byte[] newVeMap;
|
||||||
|
private DataOutputStream dos;
|
||||||
|
|
||||||
public FuelTunePane() {
|
public FuelTunePane() {
|
||||||
final JLabel incomingBufferSize = new JLabel();
|
final JLabel incomingBufferSize = new JLabel();
|
||||||
|
@ -142,6 +142,7 @@ public class FuelTunePane {
|
||||||
private void doJob() {
|
private void doJob() {
|
||||||
float veTable[][] = new float[Fields.FUEL_LOAD_COUNT][Fields.FUEL_RPM_COUNT];
|
float veTable[][] = new float[Fields.FUEL_LOAD_COUNT][Fields.FUEL_RPM_COUNT];
|
||||||
loadMap(veTable, Fields.VETABLE.getOffset());
|
loadMap(veTable, Fields.VETABLE.getOffset());
|
||||||
|
logMap("source", veTable);
|
||||||
|
|
||||||
List<FuelAutoTune.stDataOnline> data = new ArrayList<>();
|
List<FuelAutoTune.stDataOnline> data = new ArrayList<>();
|
||||||
synchronized (incomingDataPoints) {
|
synchronized (incomingDataPoints) {
|
||||||
|
@ -149,16 +150,74 @@ public class FuelTunePane {
|
||||||
data.add(point.asDataOnline());
|
data.add(point.asDataOnline());
|
||||||
incomingDataPoints.clear();
|
incomingDataPoints.clear();
|
||||||
}
|
}
|
||||||
|
writeDataPoints(data);
|
||||||
|
|
||||||
// todo: move this away from AWT thread
|
// todo: move this away from AWT thread
|
||||||
FuelAutoTune.Result a = FuelAutoTune.process(false, data, 0.1, 14.7, veTable);
|
FuelAutoTune.Result a = FuelAutoTune.process(false, data, 0.1, 14.7, veTable);
|
||||||
|
|
||||||
newVeMap = toByteArray(a.getKgbcRES());
|
float[][] result = a.getKgbcRES();
|
||||||
|
logMap("result", result);
|
||||||
|
newVeMap = toByteArray(result);
|
||||||
|
|
||||||
loadData(changeMap, newVeMap, 0);
|
loadData(changeMap, newVeMap, 0);
|
||||||
upload.setEnabled(true);
|
upload.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeDataPoints(List<FuelAutoTune.stDataOnline> data) {
|
||||||
|
DataOutputStream dos = getTuneLogStream();
|
||||||
|
if (dos == null)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
dos.writeBytes("Running with " + data.size() + " points\r\n");
|
||||||
|
dos.writeBytes("AFR\tRPM\tload\r\n");
|
||||||
|
for (FuelAutoTune.stDataOnline point : data)
|
||||||
|
dos.writeBytes(point.AFR +"\t" + point.getRpm() + "\t" + point.getEngineLoad() + "\r\n");
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
FileLog.MAIN.logLine("Error writing auto-tune log");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logMap(String msg, float[][] table) {
|
||||||
|
DataOutputStream dos = getTuneLogStream();
|
||||||
|
if (dos == null)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
dos.writeBytes(new Date() + ": " + msg + "\r\n");
|
||||||
|
|
||||||
|
for (int rpmIndex = 0; rpmIndex < Fields.FUEL_RPM_COUNT; rpmIndex++) {
|
||||||
|
dos.writeChar('\t');
|
||||||
|
dos.writeBytes(Float.toString(veRpmBins[rpmIndex]));
|
||||||
|
}
|
||||||
|
dos.writeBytes("\r\n");
|
||||||
|
|
||||||
|
for (int loadIndex = 0; loadIndex < Fields.FUEL_LOAD_COUNT; loadIndex++) {
|
||||||
|
dos.writeBytes(Float.toString(veLoadBins[loadIndex]));
|
||||||
|
for (int rpmIndex = 0; rpmIndex < Fields.FUEL_RPM_COUNT; rpmIndex++) {
|
||||||
|
dos.writeChar('\t');
|
||||||
|
float v = table[loadIndex][rpmIndex];
|
||||||
|
dos.writeBytes(Float.toString(v));
|
||||||
|
}
|
||||||
|
dos.writeBytes("\r\n");
|
||||||
|
}
|
||||||
|
dos.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
FileLog.MAIN.logLine("Error writing auto-tune log");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataOutputStream getTuneLogStream() {
|
||||||
|
if (dos == null) {
|
||||||
|
String fileName = FileLog.DIR + "tune_" + FileLog.getDate() + ".txt";
|
||||||
|
try {
|
||||||
|
dos = new DataOutputStream(new FileOutputStream(fileName));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
FileLog.MAIN.logLine("Error creating " + fileName + ":" + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dos;
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] toByteArray(float[][] output) {
|
private byte[] toByteArray(float[][] output) {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
@ -250,7 +309,7 @@ public class FuelTunePane {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuelAutoTune.stDataOnline asDataOnline() {
|
public FuelAutoTune.stDataOnline asDataOnline() {
|
||||||
return new FuelAutoTune.stDataOnline(afr, rpmIndex, engineLoadIndex);
|
return new FuelAutoTune.stDataOnline(afr, rpmIndex, engineLoadIndex, rpm, engineLoad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue