auto-sync

This commit is contained in:
rusEfi 2016-01-09 15:01:41 -05:00
parent 1a3c04dab1
commit 51647739fe
11 changed files with 72 additions and 29 deletions

View File

@ -98,13 +98,13 @@ float FastInterpolation::getValue(float x) {
*
* @note For example, "interpolate(engineConfiguration.tpsMin, 0, engineConfiguration.tpsMax, 100, adc);"
*/
float interpolate(float x1, float y1, float x2, float y2, float x) {
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x) {
// todo: double comparison using EPS
if (x1 == x2) {
/**
* we could end up here for example while resetting bins while changing engine type
*/
warning(OBD_PCM_Processor_Fault, "interpolate: Same x1 and x2 in interpolate: %f/%f", x1, x2);
warning(OBD_PCM_Processor_Fault, "interpolate%s: Same x1 and x2 in interpolate: %f/%f", msg, x1, x2);
return NAN;
}
@ -121,6 +121,10 @@ float interpolate(float x1, float y1, float x2, float y2, float x) {
return result;
}
float interpolate(float x1, float y1, float x2, float y2, float x) {
return interpolateMsg("", x1, y1, x2, y2, x);
}
int findIndex2(const float array[], unsigned size, float value) {
efiAssert(!cisnan(value), "NaN in findIndex", 0);
efiAssert(size > 1, "NaN in findIndex", 0);
@ -200,7 +204,7 @@ float interpolate2d(float value, float bin[], float values[], int size) {
if (index == size - 1)
return values[size - 1];
return interpolate(bin[index], values[index], bin[index + 1], values[index + 1], value);
return interpolateMsg("2d", bin[index], values[index], bin[index + 1], values[index + 1], value);
}
/**
@ -242,7 +246,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
float rpmMinValue = map[0][yIndex];
float rpmMaxValue = map[0][yIndex + 1];
return interpolate(keyMin, rpmMinValue, keyMax, rpmMaxValue, y);
return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y);
}
if (yIndex < 0) {
@ -305,7 +309,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
float rpmMinKeyMaxValue = map[xIndex][keyMaxIndex];
float rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex];
float keyMaxValue = interpolate(xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
#if DEBUG_INTERPOLATION
if (needInterpolationLogging) {
@ -314,7 +318,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
}
#endif
float result = interpolate(keyMin, keyMinValue, keyMax, keyMaxValue, y);
float result = interpolateMsg("3d", keyMin, keyMinValue, keyMax, keyMaxValue, y);
return result;
}

View File

@ -15,6 +15,7 @@
int findIndex(const float array[], int size, float value);
int findIndex2(const float array[], unsigned size, float value);
float interpolate(float x1, float y1, float x2, float y2, float x);
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x);
float interpolate2d(float value, float bin[], float values[], int size);
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]);
void setTableValue(float bins[], float values[], int size, float key, float value);

View File

@ -12,7 +12,7 @@
void setTableBin2(float array[], int size, float l, float r, float precision) {
for (int i = 0; i < size; i++) {
float value = interpolate(0, l, size - 1, r, i);
float value = interpolateMsg("setTable", 0, l, size - 1, r, i);
/**
* rounded values look nicer, also we want to avoid precision mismatch with Tuner Studio
*/

View File

@ -230,7 +230,7 @@ public class BinaryProtocol {
}
}
public void burnChanges(ConfigurationImage newVersion, Logger logger) throws InterruptedException, EOFException, SerialPortException {
public void uploadChanges(ConfigurationImage newVersion, Logger logger) throws InterruptedException, EOFException, SerialPortException {
ConfigurationImage current = getController();
// let's have our own copy which no one would be able to change
newVersion = newVersion.clone();

View File

@ -86,7 +86,7 @@ public class ECUEditorToolBar extends JToolBar {
Rom lastSelectedRom = ECUEditorManager.getECUEditor().getLastSelectedRom();
byte[] newVersion = ConfigurationImage.extractContent(lastSelectedRom.saveFile());
System.out.println("new version size: " + newVersion.length);
BinaryProtocolCmd.scheduleBurn(new ConfigurationImage(newVersion));
BinaryProtocolCmd.scheduleUpload(new ConfigurationImage(newVersion));
}
});
downloadImage.addActionListener(new ActionListener() {

View File

@ -128,18 +128,24 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
finePanel.add(decrementFine);
finePanel.add(incrementByFine);
this.add(finePanel);
finePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3),
BorderFactory.createLineBorder(Color.black)));
JPanel coarsePanel = new JPanel();
coarsePanel.add(incrementCoarse);
coarsePanel.add(decrementCoarse);
coarsePanel.add(incrementByCoarse);
this.add(coarsePanel);
coarsePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3),
BorderFactory.createLineBorder(Color.red)));
JPanel setValuePanel = new JPanel();
setValuePanel.add(setValueText);
setValuePanel.add(setValue);
setValuePanel.add(multiply);
this.add(setValuePanel);
setValuePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3),
BorderFactory.createLineBorder(Color.green)));
colorCells.setEnabled(false);
refreshCompare.setEnabled(false);

View File

@ -110,7 +110,7 @@
category="Fuel"
storageaddress="1a18" sizex="16"
storagetype="float" endian="big">
<scaling units="Target Boost (psia) Compensation (%)" expression="x" to_byte="x" format="0.00"
<scaling units="Compensation (%)" expression="x" to_byte="x" format="0.00"
fineincrement=".01" coarseincrement="0.1"/>
<table type="X Axis" storageaddress="19d8" storagetype="float" endian="big">
<scaling units="uni" expression="x" to_byte="x" format="0.00" fineincrement=".1" coarseincrement="1"/>
@ -119,7 +119,7 @@
<table type="2D" name="Intake air temperature-based extra idle air" storageaddress="1b98"
sizex="16" storagetype="float" endian="big">
<scaling units="Target Boost (psia) Compensation (%)" expression="x" to_byte="x" format="0.00"
<scaling units="Compensation (%)" expression="x" to_byte="x" format="0.00"
fineincrement=".01" coarseincrement="0.1"/>
<table type="X Axis" storageaddress="1b58" storagetype="float" endian="big">
<scaling units="uni" expression="x" to_byte="x" format="0.00" fineincrement=".1" coarseincrement="1"/>

View File

@ -4,20 +4,36 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.io.ConfigurationImageFile;
import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.PortHolder;
import com.rusefi.ui.RecentCommands;
import com.rusefi.ui.SettingsTab;
import com.rusefi.ui.StatusWindow;
import jssc.SerialPort;
import jssc.SerialPortException;
import javax.swing.*;
import java.awt.*;
import java.io.EOFException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* (c) Andrey Belomutskiy 2013-2015
* 3/7/2015
*/
public class UploadChanges {
private static final StatusWindow wnd = new StatusWindow();
static {
wnd.getFrame().setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
wnd.getFrame().setTitle("rusEfi bin upload");
wnd.getFrameHelper().initFrame(wnd.getContent(), false);
JPanel bottomPanel = new JPanel(new FlowLayout());
bottomPanel.add(RecentCommands.createButton(new AtomicBoolean(), SettingsTab.WRITECONFIG));
wnd.getContent().add(bottomPanel, BorderLayout.SOUTH);
}
public static final Logger logger = createUiLogger();
public static void main(String[] args) throws SerialPortException, InvocationTargetException, InterruptedException {
@ -57,15 +73,17 @@ public class UploadChanges {
final BinaryProtocol bp = new BinaryProtocol(logger, serialPort);
bp.setController(ci1);
scheduleBurn(ci2, bp);
scheduleUpload(ci2, bp);
}
public static void scheduleBurn(final ConfigurationImage newVersion, final BinaryProtocol bp) {
public static void scheduleUpload(final ConfigurationImage newVersion, final BinaryProtocol bp) {
JFrame frame = wnd.getFrame();
frame.setVisible(true);
LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
try {
BinaryProtocol.instance.burnChanges(newVersion, logger);
BinaryProtocol.instance.uploadChanges(newVersion, logger);
} catch (InterruptedException | EOFException | SerialPortException e) {
logger.error("Error: " + e);
throw new IllegalStateException(e);
@ -80,9 +98,6 @@ public class UploadChanges {
}
private static Logger createUiLogger() {
final StatusWindow wnd = new StatusWindow();
wnd.showFrame("rusEfi bin upload");
return new Logger() {
@Override
public void trace(final String msg) {

View File

@ -1,7 +1,6 @@
package com.rusefi.binaryprotocol;
import com.romraider.editor.ecu.ECUEditor;
import com.romraider.util.SettingsManager;
import com.rusefi.*;
import com.rusefi.io.serial.PortHolder;
import jssc.SerialPort;
@ -60,7 +59,7 @@ public class BinaryProtocolCmd {
return true;
}
public static void scheduleBurn(ConfigurationImage newVersion) {
UploadChanges.scheduleBurn(newVersion, bp);
public static void scheduleUpload(ConfigurationImage newVersion) {
UploadChanges.scheduleUpload(newVersion, bp);
}
}

View File

@ -3,6 +3,7 @@ package com.rusefi.ui;
import com.rusefi.ui.util.FrameHelper;
import com.rusefi.ui.util.URLLabel;
import com.rusefi.ui.util.UiUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
@ -22,20 +23,33 @@ public class StatusWindow {
return new Dimension(400, 400);
}
};
@NotNull
protected final FrameHelper frameHelper = new FrameHelper();
public StatusWindow() {
log.setLineWrap(true);
}
// todo: make this method more abstract. table editor use-case does not need stm32 driver
public void showFrame(String title) {
// todo: move this somewhere else. table editor use-case does not need stm32 driver
content.add(new URLLabel("stm32 driver", CONSOLE_DRIVER_URI), BorderLayout.NORTH);
content.add(messagesScroll, BorderLayout.CENTER);
}
FrameHelper f = new FrameHelper();
f.getFrame().setTitle(title);
f.showFrame(content, false);
UiUtils.centerWindow(f.getFrame());
@NotNull
public FrameHelper getFrameHelper() {
return frameHelper;
}
public JPanel getContent() {
return content;
}
public JFrame getFrame() {
return frameHelper.getFrame();
}
public void showFrame(String title) {
frameHelper.getFrame().setTitle(title);
frameHelper.showFrame(content, false);
UiUtils.centerWindow(frameHelper.getFrame());
log.setText(""); // let's remove stuff from previous invocation
}

View File

@ -23,6 +23,11 @@ public class FrameHelper {
}
public void showFrame(JComponent component, final boolean maximizeOnStart) {
initFrame(component, maximizeOnStart);
frame.setVisible(true);
}
public void initFrame(JComponent component, final boolean maximizeOnStart) {
frame.setSize(800, 500);
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@ -45,7 +50,6 @@ public class FrameHelper {
defaultFontSize = frame.getFont().getSize();
}
});
frame.setVisible(true);
}
protected void onWindowOpened() {