auto-sync

This commit is contained in:
rusEfi 2016-02-08 13:02:01 -05:00
parent f6223df68f
commit be8c0795d6
4 changed files with 81 additions and 10 deletions

View File

@ -14,7 +14,7 @@ public enum FileLog {
MAIN,
SIMULATOR_CONSOLE;
private static final String DIR = "out/";
public static final String DIR = "out/";
public static String currentLogName;
public static final String END_OF_TIMESTAND_TAG = "<EOT>: ";
public static final Logger LOGGER = new Logger() {

View File

@ -23,10 +23,14 @@ public class FuelAutoTune {
public static class stDataOnline {
public final double AFR;
private final int rpm;
private final double engineLoad;
int rpmIndex;
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)
throw new IllegalStateException("rpmIndex " + rpmIndex);
if (engineLoadIndex < 0 || engineLoadIndex >= Fields.FUEL_LOAD_COUNT)
@ -41,7 +45,7 @@ public class FuelAutoTune {
if (rpmIndex < 0 || rpmIndex >= Fields.FUEL_RPM_COUNT)
return null;
int engineLoadIndex = (int) (engineLoad / 120.0 * SIZE);
return new stDataOnline(AFR, rpmIndex, engineLoadIndex);
return new stDataOnline(AFR, rpmIndex, engineLoadIndex, rpm, engineLoad);
}
int getRpmIndex() {
@ -59,6 +63,14 @@ public class FuelAutoTune {
public int RPM_RT_32() {
return getRpmIndex();
}
public int getRpm() {
return rpm;
}
public double getEngineLoad() {
return engineLoad;
}
}
public static class Result {

View File

@ -32,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20160206;
public static final int CONSOLE_VERSION = 20160208;
public static final boolean SHOW_STIMULATOR = false;
private static final String TAB_INDEX = "main_tab";
protected static final String PORT_KEY = "port";
@ -114,7 +114,7 @@ public class Launcher {
tabbedPane.add("Bench Test", new BenchTestPane().getContent());
if (!LinkManager.isLogViewer() && false) // todo: fix it & better name?
tabbedPane.add("Logs Manager", logsManager.getContent());
if (false)
if (true)
tabbedPane.add("Fuel Tune", fuelTunePane.getContent());
if (!LinkManager.isLogViewerMode(port)) {

View File

@ -21,12 +21,11 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.*;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
@ -47,6 +46,7 @@ public class FuelTunePane {
private final JCheckBox collect = new JCheckBox("enable");
private final JButton clean = new JButton("clear");
private byte[] newVeMap;
private DataOutputStream dos;
public FuelTunePane() {
final JLabel incomingBufferSize = new JLabel();
@ -142,6 +142,7 @@ public class FuelTunePane {
private void doJob() {
float veTable[][] = new float[Fields.FUEL_LOAD_COUNT][Fields.FUEL_RPM_COUNT];
loadMap(veTable, Fields.VETABLE.getOffset());
logMap("source", veTable);
List<FuelAutoTune.stDataOnline> data = new ArrayList<>();
synchronized (incomingDataPoints) {
@ -149,16 +150,74 @@ public class FuelTunePane {
data.add(point.asDataOnline());
incomingDataPoints.clear();
}
writeDataPoints(data);
// todo: move this away from AWT thread
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);
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) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -250,7 +309,7 @@ public class FuelTunePane {
}
public FuelAutoTune.stDataOnline asDataOnline() {
return new FuelAutoTune.stDataOnline(afr, rpmIndex, engineLoadIndex);
return new FuelAutoTune.stDataOnline(afr, rpmIndex, engineLoadIndex, rpm, engineLoad);
}
}
}