diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index e7fbf51fac..5e8ce13286 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -58,7 +58,7 @@ EXTERN_ENGINE ; extern bool hasFirmwareErrorFlag; -static LocalVersionHolder localVersion; +static LocalVersionHolder triggerVersion; extern engine_pins_s enginePins; static MainTriggerCallback mainTriggerCallbackInstance; @@ -334,7 +334,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL int revolutionIndex = engine->rpmCalculator.getRevolutionCounter() % 2; if (eventIndex == 0) { - if (localVersion.isOld()) + if (triggerVersion.isOld()) prepareOutputSignals(PASS_ENGINE_PARAMETER_F); } diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index 503a34189a..711b1a2740 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -69,7 +69,7 @@ static int stopEmulationAtIndex = DO_NOT_STOP; static bool isEmulating = true; static Logging *logger; -static LocalVersionHolder localVersion; +static LocalVersionHolder emulatorConfigVersion; EXTERN_ENGINE; @@ -89,8 +89,8 @@ void setTriggerEmulatorRPM(int rpm, Engine *engine) { } static void updateTriggerShapeIfNeeded(PwmConfig *state) { - if (localVersion.isOld()) { - scheduleMsg(logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(), + if (emulatorConfigVersion.isOld()) { + scheduleMsg(logger, "Stimulator: updating trigger shape: %d/%d %d", emulatorConfigVersion.getVersion(), getGlobalConfigurationVersion(), currentTimeMillis()); applyNonPersistentConfiguration(logger, engine); diff --git a/firmware/util/LocalVersionHolder.cpp b/firmware/util/LocalVersionHolder.cpp index bd95283791..ed1d55324c 100644 --- a/firmware/util/LocalVersionHolder.cpp +++ b/firmware/util/LocalVersionHolder.cpp @@ -11,7 +11,10 @@ int getGlobalConfigurationVersion(void); //ctor LocalVersionHolder::LocalVersionHolder() { - localVersion = 0; + /** + * we want local version to be 'old' on instantiation + */ + localVersion = -1; } int LocalVersionHolder::getVersion() { diff --git a/java_console/models/src/com/rusefi/AverageAngles.java b/java_console/models/src/com/rusefi/AverageAngles.java index 6724c78aa2..5f1407a420 100644 --- a/java_console/models/src/com/rusefi/AverageAngles.java +++ b/java_console/models/src/com/rusefi/AverageAngles.java @@ -3,6 +3,7 @@ package com.rusefi; import org.apache.commons.math3.stat.descriptive.moment.Mean; import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; +import java.io.PrintStream; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -49,9 +50,10 @@ public class AverageAngles { } } - public void printReport() { + public void printReport(PrintStream stream) { List angles = new ArrayList<>(); + stream.println("index,average,stdev"); for (Map.Entry> e : angleData.entrySet()) { int k = e.getKey(); @@ -68,16 +70,15 @@ public class AverageAngles { angles.add(mean); - System.out.println("i " + k + " average=" + mean + " dev=" + sdv); + stream.println(k + "," + mean + "," + sdv); } if (angleData.isEmpty()) return; Double lastValue = angles.get(angles.size() - 1); - System.out.println("Last value = " + lastValue); + stream.println("Last value = " + lastValue); double delta = 720 - lastValue; for (double v : angles) { - System.out.println((delta + v)); + stream.println((delta + v)); } - } } diff --git a/java_console/models/src/com/rusefi/AverageAnglesUtil.java b/java_console/models/src/com/rusefi/AverageAnglesUtil.java index c503f20861..70285a791d 100644 --- a/java_console/models/src/com/rusefi/AverageAnglesUtil.java +++ b/java_console/models/src/com/rusefi/AverageAnglesUtil.java @@ -53,7 +53,7 @@ public class AverageAnglesUtil { System.out.println(line); } - aa.printReport(); + aa.printReport(System.out); } } \ No newline at end of file diff --git a/java_console/models/src/com/rusefi/core/SensorCentral.java b/java_console/models/src/com/rusefi/core/SensorCentral.java index aff75a9cfb..932f6f5488 100644 --- a/java_console/models/src/com/rusefi/core/SensorCentral.java +++ b/java_console/models/src/com/rusefi/core/SensorCentral.java @@ -27,20 +27,10 @@ public class SensorCentral { private SensorCentral() { } - public double getValueOrNan(Sensor sensor) { - Double value = values.get(sensor); - if (value == null) - return Double.NaN; - return value; - } - - /** - * todo: migrate to getValueOrNan implementation? - */ public double getValue(Sensor sensor) { Double value = values.get(sensor); if (value == null) - throw new NullPointerException("No value for sensor: " + sensor); + return Double.NaN; return value; } diff --git a/java_console/models/src/com/rusefi/core/SensorStats.java b/java_console/models/src/com/rusefi/core/SensorStats.java index fd65f13f7f..8c443cd9d4 100644 --- a/java_console/models/src/com/rusefi/core/SensorStats.java +++ b/java_console/models/src/com/rusefi/core/SensorStats.java @@ -59,7 +59,7 @@ public class SensorStats { SensorCentral.getInstance().addListener(input1, new SensorCentral.SensorListener() { @Override public void onSensorUpdate(double value) { - double valueMs = 1.0 * (value - SensorCentral.getInstance().getValueOrNan(input2)) / WaveReport.SYS_TICKS_PER_MS; + double valueMs = 1.0 * (value - SensorCentral.getInstance().getValue(input2)) / WaveReport.SYS_TICKS_PER_MS; SensorCentral.getInstance().setValue(valueMs, destination); } }); diff --git a/java_console/ui/src/com/rusefi/AnalogChartCentral.java b/java_console/ui/src/com/rusefi/AnalogChartCentral.java index 99d873c9fb..5576227181 100644 --- a/java_console/ui/src/com/rusefi/AnalogChartCentral.java +++ b/java_console/ui/src/com/rusefi/AnalogChartCentral.java @@ -9,7 +9,7 @@ import java.util.concurrent.CopyOnWriteArrayList; public class AnalogChartCentral { private static final String KEY = "analog_chart"; - static List listeners = new CopyOnWriteArrayList<>(); + private static List listeners = new CopyOnWriteArrayList<>(); static { LinkManager.engineState.registerStringValueAction(KEY, new EngineState.ValueCallback() { @@ -22,6 +22,10 @@ public class AnalogChartCentral { ); } + public static void addListener(AnalogChartListener listener) { + listeners.add(listener); + } + interface AnalogChartListener { void onAnalogChart(String analogChart); } diff --git a/java_console/ui/src/com/rusefi/AnalogChartPanel.java b/java_console/ui/src/com/rusefi/AnalogChartPanel.java index f108b0765a..d1f90ad8b9 100644 --- a/java_console/ui/src/com/rusefi/AnalogChartPanel.java +++ b/java_console/ui/src/com/rusefi/AnalogChartPanel.java @@ -39,7 +39,7 @@ public class AnalogChartPanel { public AnalogChartPanel() { - AnalogChartCentral.listeners.add(new AnalogChartCentral.AnalogChartListener() { + AnalogChartCentral.addListener(new AnalogChartCentral.AnalogChartListener() { @Override public void onAnalogChart(String message) { unpackValues(values, message); @@ -47,7 +47,6 @@ public class AnalogChartPanel { processValues(); UiUtils.trueRepaint(canvas); } - } }); @@ -67,17 +66,15 @@ public class AnalogChartPanel { JButton imageButton = new JButton(EngineSnifferPanel.SAVE_IMAGE); imageButton.setMnemonic('s'); upperPanel.add(imageButton); - imageButton.addActionListener(new + imageButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int rpm = RpmModel.getInstance().getValue(); + String fileName = FileLog.getDate() + "rpm_" + rpm + "_sensor" + ".png"; - ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - int rpm = RpmModel.getInstance().getValue(); - String fileName = FileLog.getDate() + "rpm_" + rpm + "_analog" + ".png"; - - UiUtils.saveImageWithPrompt(fileName, upperPanel, canvas); - } - } + UiUtils.saveImageWithPrompt(fileName, upperPanel, canvas); + } + } ); final JButton pauseButton = new JButton(PAUSE.getMessage()); diff --git a/java_console/ui/src/com/rusefi/AverageAnglePanel.java b/java_console/ui/src/com/rusefi/AverageAnglePanel.java index 7cd37c3be4..40a6e5a7fb 100644 --- a/java_console/ui/src/com/rusefi/AverageAnglePanel.java +++ b/java_console/ui/src/com/rusefi/AverageAnglePanel.java @@ -1,31 +1,58 @@ package com.rusefi; -import com.rusefi.core.MessagesCentral; +import com.rusefi.core.Sensor; +import com.rusefi.core.SensorCentral; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static com.rusefi.ui.util.LocalizedMessages.RESET; public class AverageAnglePanel { - final JPanel panel = new JPanel(new BorderLayout()); + private final JPanel panel = new JPanel(new BorderLayout()); - AverageAngles aa = new AverageAngles(); + private final AverageAngles aa = new AverageAngles(); + private final JTextArea text = new JTextArea(); public AverageAnglePanel() { - JButton reset = new JButton("reset"); + JButton reset = new JButton(RESET.getMessage()); reset.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { aa.clear(); + showResults(); } }); - MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() { + panel.add(reset, BorderLayout.NORTH); + panel.add(new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) { @Override - public void onMessage(Class clazz, String message) { - + public Dimension getPreferredSize() { + return new Dimension(400, 400); } - }); + }, BorderLayout.CENTER); + AnalogChartCentral.addListener(new AnalogChartCentral.AnalogChartListener() { + @Override + public void onAnalogChart(String message) { + int rpm = (int) SensorCentral.getInstance().getValue(Sensor.RPM); + aa.add(rpm, message); + showResults(); + } + } + ); + } + + private void showResults() { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + aa.printReport(new PrintStream(byteArrayOutputStream)); + text.setText(byteArrayOutputStream.toString()); + } + + public JPanel getPanel() { + return panel; } } \ No newline at end of file diff --git a/java_console/ui/src/com/rusefi/ui/Wizard.java b/java_console/ui/src/com/rusefi/ui/Wizard.java index 1461259fd1..72a1981cf8 100644 --- a/java_console/ui/src/com/rusefi/ui/Wizard.java +++ b/java_console/ui/src/com/rusefi/ui/Wizard.java @@ -1,5 +1,6 @@ package com.rusefi.ui; +import com.rusefi.AverageAnglePanel; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.OutputChannel; @@ -96,6 +97,8 @@ public class Wizard { panel.add(content, BorderLayout.CENTER); + panel.add(new AverageAnglePanel().getPanel(), BorderLayout.SOUTH); + button.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { diff --git a/java_console/ui/src/com/rusefi/ui/util/LocalizedMessages.java b/java_console/ui/src/com/rusefi/ui/util/LocalizedMessages.java index 5d4311cc0c..bb7e388907 100644 --- a/java_console/ui/src/com/rusefi/ui/util/LocalizedMessages.java +++ b/java_console/ui/src/com/rusefi/ui/util/LocalizedMessages.java @@ -4,6 +4,7 @@ public enum LocalizedMessages { CLEAR("clear"), PAUSE("pause"), RESUME("resume"), + RESET("reset"), ; private final String message;