diff --git a/java_console/io/src/com/rusefi/ConfigurationImageDiff.java b/java_console/io/src/com/rusefi/ConfigurationImageDiff.java index ed9cdb718e..4d505faf5b 100644 --- a/java_console/io/src/com/rusefi/ConfigurationImageDiff.java +++ b/java_console/io/src/com/rusefi/ConfigurationImageDiff.java @@ -3,10 +3,16 @@ package com.rusefi; import com.rusefi.core.Pair; /** + * This class has the logic of finding all ranges of changes between who {@link ConfigurationImage} + * It's used to send just the diff to the ECU. + * * (c) Andrey Belomutskiy * 3/6/2015 */ public class ConfigurationImageDiff { + private ConfigurationImageDiff() { + } + /** * @return NULL if images are the same from OFFSET and to the end */ diff --git a/java_console/romraider/src/com/romraider/maps/Table.java b/java_console/romraider/src/com/romraider/maps/Table.java index 753352b68d..17aabdd930 100644 --- a/java_console/romraider/src/com/romraider/maps/Table.java +++ b/java_console/romraider/src/com/romraider/maps/Table.java @@ -420,6 +420,10 @@ public abstract class Table extends JPanel implements Serializable { this.setInputMap(WHEN_FOCUSED, im); } + public void reset() { + centerPanel.removeAll(); + } + public DataCell[] getData() { return data; } diff --git a/java_console/ui/src/com/rusefi/UploadChanges.java b/java_console/ui/src/com/rusefi/UploadChanges.java index cd6bf89616..0607ab49d7 100644 --- a/java_console/ui/src/com/rusefi/UploadChanges.java +++ b/java_console/ui/src/com/rusefi/UploadChanges.java @@ -73,10 +73,10 @@ public class UploadChanges { final BinaryProtocol bp = new BinaryProtocol(logger, serialPort); bp.setController(ci1); - scheduleUpload(ci2, bp); + scheduleUpload(ci2); } - public static void scheduleUpload(final ConfigurationImage newVersion, final BinaryProtocol bp) { + public static void scheduleUpload(final ConfigurationImage newVersion) { JFrame frame = wnd.getFrame(); frame.setVisible(true); LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() { diff --git a/java_console/ui/src/com/rusefi/binaryprotocol/BinaryProtocolCmd.java b/java_console/ui/src/com/rusefi/binaryprotocol/BinaryProtocolCmd.java index 3ef3e428b9..43b1e75c5a 100644 --- a/java_console/ui/src/com/rusefi/binaryprotocol/BinaryProtocolCmd.java +++ b/java_console/ui/src/com/rusefi/binaryprotocol/BinaryProtocolCmd.java @@ -60,6 +60,6 @@ public class BinaryProtocolCmd { } public static void scheduleUpload(ConfigurationImage newVersion) { - UploadChanges.scheduleUpload(newVersion, bp); + UploadChanges.scheduleUpload(newVersion); } } diff --git a/java_console/ui/src/com/rusefi/ui/FuelTunePane.java b/java_console/ui/src/com/rusefi/ui/FuelTunePane.java index 6d583cbb20..7fbaad1d13 100644 --- a/java_console/ui/src/com/rusefi/ui/FuelTunePane.java +++ b/java_console/ui/src/com/rusefi/ui/FuelTunePane.java @@ -2,11 +2,16 @@ package com.rusefi.ui; import com.romraider.Settings; import com.romraider.maps.Scale; +import com.romraider.maps.Table; import com.romraider.maps.Table3D; +import com.romraider.xml.RomAttributeParser; import com.rusefi.BinarySearch; +import com.rusefi.ConfigurationImage; import com.rusefi.FileLog; +import com.rusefi.UploadChanges; import com.rusefi.autotune.FuelAutoTune; import com.rusefi.binaryprotocol.BinaryProtocol; +import com.rusefi.config.Field; import com.rusefi.config.Fields; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; @@ -16,6 +21,10 @@ 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.nio.ByteOrder; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -34,6 +43,8 @@ public class FuelTunePane { private final float veRpmBins[] = new float[Fields.FUEL_RPM_COUNT]; private final Table3D veTable = new Table3D(); private final Table3D changeMap = new Table3D(); + private final JButton upload = new JButton("Upload"); + private byte[] newVeMap; public FuelTunePane() { final JLabel incomingBufferSize = new JLabel(); @@ -45,10 +56,23 @@ public class FuelTunePane { doJob(); } }); + upload.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + byte[] newVeMap = FuelTunePane.this.newVeMap; + BinaryProtocol bp = BinaryProtocol.instance; + if (newVeMap == null || bp == null) + return; + ConfigurationImage ci = bp.getController().clone(); + System.arraycopy(newVeMap, 0, ci.getContent(), Fields.VETABLE.getOffset(), newVeMap.length); + UploadChanges.scheduleUpload(ci); + } + }); JPanel topPanel = new JPanel(new FlowLayout()); topPanel.add(incomingBufferSize); topPanel.add(runLogic); + topPanel.add(upload); Timer timer = new Timer(300, new ActionListener() { @Override @@ -62,9 +86,9 @@ public class FuelTunePane { }); timer.start(); + upload.setEnabled(false); content.add(topPanel, BorderLayout.NORTH); - JPanel rightPanel = new JPanel(new GridLayout(2, 1)); rightPanel.add(changeMap); rightPanel.add(new JLabel("bottom")); @@ -78,6 +102,14 @@ public class FuelTunePane { initTable(changeMap); } + private static void loadData(Table table, byte[] content, int offset) { + table.reset(); + table.setStorageAddress(offset); + table.setStorageType(Settings.STORAGE_TYPE_FLOAT); + table.populateTable(content, 0); + table.drawTable(); + } + private void initTable(Table3D table) { // todo: which one is which? table.setSizeX(Fields.FUEL_LOAD_COUNT); @@ -108,19 +140,25 @@ public class FuelTunePane { // todo: move this away from AWT thread FuelAutoTune.Result a = FuelAutoTune.process(false, data, 0.1, 14.7, veTable); + newVeMap = toByteArray(a.getKgbcRES()); - changeMap.setStorageAddress(0); - changeMap.setStorageType(Settings.STORAGE_TYPE_FLOAT); - changeMap.populateTable(new byte[4 * 16 * 16], 0); + loadData(changeMap, newVeMap, 0); + upload.setEnabled(true); + } - for (int i = 0; i < 16; i++) { - for (int rpmIndex = 0; rpmIndex < 16; rpmIndex++) { - changeMap.get3dData()[i][rpmIndex].setBinValue(a.getKgbcRES()[i][rpmIndex]); + private byte[] toByteArray(float[][] output) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (int loadIndex = 0; loadIndex < Fields.FUEL_LOAD_COUNT; loadIndex++) { + for (int rpmIndex = 0; rpmIndex < Fields.FUEL_RPM_COUNT; rpmIndex++) { + byte[] b4 = RomAttributeParser.floatToByte(output[loadIndex][rpmIndex], Settings.ENDIAN_BIG); + baos.write(b4); + } } + return baos.toByteArray(); + } catch (IOException e) { + throw new IllegalStateException(e); } - - changeMap.drawTable(); - } public void showContent() { @@ -143,18 +181,20 @@ public class FuelTunePane { } }); - loadArray(veLoadBins, Fields.VETABLE.getOffset() + Fields.FUEL_RPM_COUNT * Fields.FUEL_LOAD_COUNT * 4); - loadArray(veRpmBins, Fields.VETABLE.getOffset() + Fields.FUEL_RPM_COUNT * Fields.FUEL_LOAD_COUNT * 4 + Fields.FUEL_LOAD_COUNT * 4); + int veLoadOffset = Fields.VETABLE.getOffset() + Fields.FUEL_RPM_COUNT * Fields.FUEL_LOAD_COUNT * 4; + loadArray(veLoadBins, veLoadOffset); + int veRpmOffset = Fields.VETABLE.getOffset() + Fields.FUEL_RPM_COUNT * Fields.FUEL_LOAD_COUNT * 4 + Fields.FUEL_LOAD_COUNT * 4; + loadArray(veRpmBins, veRpmOffset); BinaryProtocol bp = BinaryProtocol.instance; byte[] content = bp.getController().getContent(); - veTable.setStorageAddress(Fields.VETABLE.getOffset()); - veTable.setStorageType(Settings.STORAGE_TYPE_FLOAT); - veTable.populateTable(content, 0); - veTable.drawTable(); + loadData(veTable.getXAxis(), content, veRpmOffset); + loadData(veTable.getYAxis(), content, veLoadOffset); + loadData(veTable, content, Fields.VETABLE.getOffset()); -// UiUtils.trueLayout(content.getParent()); + loadData(changeMap.getXAxis(), content, veRpmOffset); + loadData(changeMap.getYAxis(), content, veLoadOffset); } private void loadMap(float[][] map, int offset) {