Whatever we call it, how ever we implement it - we need live data / remote view into rusEFI actual state #3353
this stuff is definitely dead code
This commit is contained in:
parent
d7d2834d51
commit
1886a42fe9
|
@ -1,15 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class AccelEnrichmentMeta {
|
|
||||||
public static final Request[] CONTENT = new Request[]{
|
|
||||||
new ConfigRequest("wwaeTau"),
|
|
||||||
new ConfigRequest("wwaeBeta"),
|
|
||||||
new TextRequest("Current_Wall_Fuel_Film"),
|
|
||||||
new FieldRequest("wall_fuel", "wallFuel"),
|
|
||||||
new TextRequest("Fuel"),
|
|
||||||
new FieldRequest("wall_fuel", "wallFuelCorrection"),
|
|
||||||
new TextRequest("ms"),
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class ElectronicThrottleMeta {
|
|
||||||
public static final Request[] CONTENT = new Request[]{
|
|
||||||
new IfRequest("Engine", "1",
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("Electronic_Throttle"),
|
|
||||||
new SensorRequest("TPS"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Pedal"),
|
|
||||||
new SensorRequest("PPS"),
|
|
||||||
new ConfigRequest("throttlePedalPositionAdcChannel"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Feed_forward"),
|
|
||||||
new FieldRequest("Engine", "etbFeedForward"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("input"),
|
|
||||||
new FieldRequest("ETB_pid", "input"),
|
|
||||||
new TextRequest("Output"),
|
|
||||||
new FieldRequest("ETB_pid", "output"),
|
|
||||||
new TextRequest("iTerm"),
|
|
||||||
new FieldRequest("ETB_pid", "iTerm"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new FieldRequest("ETB_pid", "errorAmplificationCoef"),
|
|
||||||
new FieldRequest("ETB_pid", "previousError"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Settings"),
|
|
||||||
new ConfigRequest("ETB_PFACTOR"),
|
|
||||||
new ConfigRequest("ETB_IFACTOR"),
|
|
||||||
new ConfigRequest("ETB_DFACTOR"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new ConfigRequest("ETB_OFFSET"),
|
|
||||||
new ConfigRequest("ETB_PERIODMS"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new ConfigRequest("ETB_MINVALUE"),
|
|
||||||
new ConfigRequest("ETB_MAXVALUE"),
|
|
||||||
},
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("No_Pedal_Sensor"),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class FuelMathMeta {
|
|
||||||
public static final Request[] CONTENT = new Request[]{
|
|
||||||
new FieldRequest("Engine", "sparkDwell"),
|
|
||||||
new FieldRequest("Engine", "dwellAngle"),
|
|
||||||
new FieldRequest("Engine", "cltTimingCorrection"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new IfRequest("Engine", "isCrankingState",
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("Duration_coef"),
|
|
||||||
new FieldRequest("Engine", "cranking_durationCoefficient"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Coolant_coef"),
|
|
||||||
new FieldRequest("Engine", "cranking_coolantTemperatureCoefficient"),
|
|
||||||
new SensorRequest("CLT"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("TPS_coef"),
|
|
||||||
new FieldRequest("Engine", "cranking_tpsCoefficient"),
|
|
||||||
new FieldRequest("Engine", "cranking_tpsCoefficient"),
|
|
||||||
new SensorRequest("TPS"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Cranking_fuel"),
|
|
||||||
new FieldRequest("Engine", "cranking_fuel"),
|
|
||||||
},
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("Base_fuel"),
|
|
||||||
new FieldRequest("Engine", "running_baseFuel"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Intake_coef"),
|
|
||||||
new FieldRequest("Engine", "running_intakeTemperatureCoefficient"),
|
|
||||||
new SensorRequest("IAT"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Coolant_coef"),
|
|
||||||
new FieldRequest("Engine", "running_coolantTemperatureCoefficient"),
|
|
||||||
new SensorRequest("CLT"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Post_cranking_coef"),
|
|
||||||
new FieldRequest("Engine", "running_postCrankingFuelCorrection"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Running_fuel"),
|
|
||||||
new FieldRequest("Engine", "running_fuel"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Injector_lag"),
|
|
||||||
new FieldRequest("Engine", "running_injectorLag"),
|
|
||||||
new SensorRequest("VBATT"),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class IdleThreadMeta {
|
|
||||||
public static final Request[] CONTENT = new Request[]{
|
|
||||||
new TextRequest("Idle_State"),
|
|
||||||
new FieldRequest("Engine", "idleState"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new TextRequest("Base_Position"),
|
|
||||||
new FieldRequest("Engine", "baseIdlePosition"),
|
|
||||||
new TextRequest("Position_with_Adjustments"),
|
|
||||||
new FieldRequest("Engine", "currentIdlePosition"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new SensorRequest("TPS"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new TextRequest("Throttle_Up_State"),
|
|
||||||
new FieldRequest("Engine", "throttlePedalUpState"),
|
|
||||||
new ConfigRequest("throttlePedalUpPin"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new IfRequest("Engine", "isAutomaticIdle",
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("Output"),
|
|
||||||
new FieldRequest("idle_pid", "output"),
|
|
||||||
new TextRequest("iTerm"),
|
|
||||||
new FieldRequest("idle_pid", "iTerm"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("Settings"),
|
|
||||||
new ConfigRequest("IDLERPMPID_PFACTOR"),
|
|
||||||
new ConfigRequest("IDLERPMPID_IFACTOR"),
|
|
||||||
new ConfigRequest("IDLERPMPID_DFACTOR"),
|
|
||||||
new ConfigRequest("IDLERPMPID_OFFSET"),
|
|
||||||
new TextRequest("eol"),
|
|
||||||
new TextRequest("ETB_Idle"),
|
|
||||||
new FieldRequest("Engine", "etbIdleAddition"),
|
|
||||||
},
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("Manual_idle_control"),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class SpeedDensityMeta {
|
|
||||||
public static final Request[] CONTENT = new Request[]{
|
|
||||||
new IfRequest("Engine", "isTChargeAirModel",
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("interpolate_Air_Flow"),
|
|
||||||
new FieldRequest("Engine", "airFlow"),
|
|
||||||
new TextRequest("Between"),
|
|
||||||
new ConfigRequest("tChargeAirCoefMin"),
|
|
||||||
new ConfigRequest("tChargeAirFlowMax"),
|
|
||||||
new ConfigRequest("tChargeAirCoefMax"),
|
|
||||||
},
|
|
||||||
new Request[]{
|
|
||||||
new TextRequest("interpolate_3D"),
|
|
||||||
new SensorRequest("RPM"),
|
|
||||||
new TextRequest("and"),
|
|
||||||
new SensorRequest("TPS"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new TextRequest("Between"),
|
|
||||||
new ConfigRequest("tChargeMinRpmMinTps"),
|
|
||||||
new ConfigRequest("tChargeMinRpmMaxTps"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new ConfigRequest("tChargeMaxRpmMinTps"),
|
|
||||||
new ConfigRequest("tChargeMaxRpmMaxTps"),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class ThermistorsMeta {
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class TpsMeta {
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.rusefi.ldmp.generated;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
|
|
||||||
public class TriggerDecoderMeta {
|
|
||||||
public static final Request[] CONTENT = new Request[]{
|
|
||||||
new TextRequest("Current_Gap"),
|
|
||||||
new FieldRequest("Trigger_State", "currentGap"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new ConfigRequest("TRIGGERINPUTPINS1"),
|
|
||||||
new TextRequest("Trigger 1: Fall"),
|
|
||||||
new FieldRequest("Trigger_Central", "HWEVENTCOUNTERS1"),
|
|
||||||
new TextRequest(", Rise"),
|
|
||||||
new FieldRequest("Trigger_Central", "HWEVENTCOUNTERS2"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new ConfigRequest("TRIGGERINPUTPINS2"),
|
|
||||||
new TextRequest("Trigger 2: Fall"),
|
|
||||||
new FieldRequest("Trigger_Central", "HWEVENTCOUNTERS3"),
|
|
||||||
new TextRequest(", Rise"),
|
|
||||||
new FieldRequest("Trigger_Central", "HWEVENTCOUNTERS4"),
|
|
||||||
new TextRequest("EOL"),
|
|
||||||
new TextRequest("VVT_1"),
|
|
||||||
new ConfigRequest("CAMINPUTS1"),
|
|
||||||
new FieldRequest("Trigger_Central", "vvtEventRiseCounter"),
|
|
||||||
new FieldRequest("Trigger_Central", "vvtEventFallCounter"),
|
|
||||||
new FieldRequest("Trigger_Central", "vvtCamCounter"),
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.core.SensorCentral;
|
import com.rusefi.core.SensorCentral;
|
||||||
import com.rusefi.ui.config.ConfigField;
|
import com.rusefi.ui.config.ConfigField;
|
||||||
import com.rusefi.ui.livedocs.LiveDocPanel;
|
|
||||||
import com.rusefi.ui.util.UiUtils;
|
import com.rusefi.ui.util.UiUtils;
|
||||||
import com.rusefi.ui.widgets.IntGaugeLabel;
|
import com.rusefi.ui.widgets.IntGaugeLabel;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -40,14 +39,10 @@ public class FormulasPane {
|
||||||
private final UIContext uiContext;
|
private final UIContext uiContext;
|
||||||
private boolean isPaused;
|
private boolean isPaused;
|
||||||
|
|
||||||
private JPanel liveDocs;
|
|
||||||
|
|
||||||
public FormulasPane(UIContext uiContext) {
|
public FormulasPane(UIContext uiContext) {
|
||||||
this.uiContext = uiContext;
|
this.uiContext = uiContext;
|
||||||
|
|
||||||
JPanel vertical = new JPanel(new VerticalFlowLayout());
|
JPanel vertical = new JPanel(new VerticalFlowLayout());
|
||||||
liveDocs = LiveDocPanel.createLiveDocumentationPanel(uiContext);
|
|
||||||
vertical.add(liveDocs);
|
|
||||||
vertical.add(formulaProxy);
|
vertical.add(formulaProxy);
|
||||||
|
|
||||||
JScrollPane scroll = new JScrollPane(vertical, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
JScrollPane scroll = new JScrollPane(vertical, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.rusefi.ui;
|
package com.rusefi.ui;
|
||||||
|
|
||||||
import com.rusefi.ui.livedocs.LiveDocPanel;
|
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -10,7 +9,6 @@ import java.awt.*;
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
* Andrey Belomutskiy, (c) 2013-2020
|
||||||
*/
|
*/
|
||||||
public class SensorsLiveDataPane {
|
public class SensorsLiveDataPane {
|
||||||
private JPanel liveDocs;
|
|
||||||
/**
|
/**
|
||||||
* this is the panel we expose to the outside world
|
* this is the panel we expose to the outside world
|
||||||
*/
|
*/
|
||||||
|
@ -19,8 +17,6 @@ public class SensorsLiveDataPane {
|
||||||
public SensorsLiveDataPane(UIContext uiContext) {
|
public SensorsLiveDataPane(UIContext uiContext) {
|
||||||
JPanel vertical = new JPanel(new VerticalFlowLayout());
|
JPanel vertical = new JPanel(new VerticalFlowLayout());
|
||||||
|
|
||||||
liveDocs = LiveDocPanel.createSensorsLiveDataPanel(uiContext);
|
|
||||||
vertical.add(liveDocs);
|
|
||||||
|
|
||||||
JScrollPane scroll = new JScrollPane(vertical, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
JScrollPane scroll = new JScrollPane(vertical, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
content.add(scroll, BorderLayout.CENTER);
|
content.add(scroll, BorderLayout.CENTER);
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs;
|
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Multi-line horizontal flow panel.
|
|
||||||
* <p>
|
|
||||||
* <p>
|
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
|
||||||
*/
|
|
||||||
public class ActionPanel {
|
|
||||||
private final RefreshActionsMap refreshActions = new RefreshActionsMap();
|
|
||||||
private final JPanel panel = new JPanel(new MigLayout());
|
|
||||||
private JPanel currentLinePanel;
|
|
||||||
|
|
||||||
public ActionPanel(String title) {
|
|
||||||
panel.setBorder(BorderFactory.createTitledBorder(title));
|
|
||||||
}
|
|
||||||
|
|
||||||
public JPanel getPanel() {
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void newLine() {
|
|
||||||
initIfNeeded();
|
|
||||||
currentLinePanel = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addControl(JComponent component) {
|
|
||||||
initIfNeeded();
|
|
||||||
currentLinePanel.add(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initIfNeeded() {
|
|
||||||
if (currentLinePanel == null) {
|
|
||||||
currentLinePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
|
|
||||||
panel.add(currentLinePanel, "wrap");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefreshActionsMap getRefreshActions() {
|
|
||||||
return refreshActions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void actionsListAdd(LiveDataContext context, RefreshActions refreshAction) {
|
|
||||||
refreshActions.put(context, refreshAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void actionsListAddAll(RefreshActionsMap actions) {
|
|
||||||
refreshActions.addAll(actions);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs;
|
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
|
||||||
*/
|
|
||||||
public class IfConditionPanel {
|
|
||||||
private final RefreshActionsMap actionsList;
|
|
||||||
private final JPanel panel = new JPanel(new MigLayout());
|
|
||||||
|
|
||||||
public IfConditionPanel(JPanel result, RefreshActionsMap actionsList) {
|
|
||||||
// todo: do we really need this proxy panel or can we just use parameter value?
|
|
||||||
panel.add(result);
|
|
||||||
this.actionsList = actionsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefreshActionsMap getActionsList() {
|
|
||||||
return actionsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JPanel getPanel() {
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
|
||||||
*/
|
|
||||||
public class LessJumpyJLabel extends JLabel {
|
|
||||||
private int maxPreferredWidth = 0;
|
|
||||||
|
|
||||||
public LessJumpyJLabel(String text) {
|
|
||||||
super(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dimension getPreferredSize() {
|
|
||||||
Dimension preferredSize = super.getPreferredSize();
|
|
||||||
// let's occupy maximum width we ever wanted to reduce layout jumpiness
|
|
||||||
maxPreferredWidth = Math.max(maxPreferredWidth, preferredSize.width);
|
|
||||||
return new Dimension(maxPreferredWidth, preferredSize.height);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,242 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs;
|
|
||||||
|
|
||||||
import com.opensr5.ConfigurationImage;
|
|
||||||
import com.rusefi.autoupdate.AutoupdateUtil;
|
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
|
||||||
import com.rusefi.config.Field;
|
|
||||||
import com.rusefi.config.generated.Fields;
|
|
||||||
import com.rusefi.core.Sensor;
|
|
||||||
import com.rusefi.core.SensorCentral;
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
import com.rusefi.ldmp.generated.*;
|
|
||||||
import com.opensr5.ini.DialogModel;
|
|
||||||
import com.opensr5.ini.IniFileModel;
|
|
||||||
import com.rusefi.ui.UIContext;
|
|
||||||
import com.rusefi.ui.livedocs.controls.Toolbox;
|
|
||||||
import com.rusefi.ui.widgets.DetachedSensor;
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.putgemin.VerticalFlowLayout;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
import static com.rusefi.config.Field.niceToString;
|
|
||||||
|
|
||||||
public class LiveDocPanel {
|
|
||||||
|
|
||||||
private static final String CONSTRAINTS = "wrap, grow";
|
|
||||||
private static final String LAYOUT = "gap 0, insets 0";
|
|
||||||
// todo: replace magic hard-coded value with some relative number, maybe 1/3 of frame height or something?
|
|
||||||
private static final int MAGIC_DETACHED_GAUGE_SIZE = 200;
|
|
||||||
private static final int LIVE_DATA_PRECISION = 2;
|
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JPanel createPanel(UIContext uiContext, String title, Request[] content) {
|
|
||||||
return createPanel(uiContext, title, content, "", StateDictionary.NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
static JPanel createPanel(UIContext uiContext, String title, Request[] content, String settingsInstancePrefix, final int defaultContextId) {
|
|
||||||
LiveDataContext defaultContext = new LiveDataContext(defaultContextId);
|
|
||||||
|
|
||||||
ActionPanel ap = createComponents(uiContext, title, content, settingsInstancePrefix, defaultContext);
|
|
||||||
JPanel panel = ap.getPanel();
|
|
||||||
|
|
||||||
LiveDocHolder holder = new LiveDocHolder(defaultContext, ap.getRefreshActions()) {
|
|
||||||
@Override
|
|
||||||
public boolean isVisible() {
|
|
||||||
boolean isVisible = !panel.getVisibleRect().isEmpty();
|
|
||||||
return isVisible && isRecursivelyVisible(panel);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
LiveDocsRegistry.INSTANCE.register(holder);
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isRecursivelyVisible(Container c) {
|
|
||||||
Container parent = c.getParent();
|
|
||||||
return c.isVisible() && (parent == null || isRecursivelyVisible(parent));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ActionPanel createComponents(UIContext uiContext, String title, Request[] content, String settingsInstancePrefix, LiveDataContext defaultContext) {
|
|
||||||
ActionPanel result = new ActionPanel(title);
|
|
||||||
|
|
||||||
for (Request r : content) {
|
|
||||||
if (r instanceof TextRequest) {
|
|
||||||
TextRequest request = (TextRequest) r;
|
|
||||||
if (request.isEol()) {
|
|
||||||
result.newLine();
|
|
||||||
} else {
|
|
||||||
result.addControl(new JLabel(request.getValue().replaceAll("_", " ")));
|
|
||||||
}
|
|
||||||
} else if (r instanceof FieldRequest) {
|
|
||||||
FieldRequest request = (FieldRequest) r;
|
|
||||||
LiveDataContext context = getFieldContext(defaultContext, request.getStateContext());
|
|
||||||
Field field = getField(defaultContext, request);
|
|
||||||
JLabel label = new LessJumpyJLabel("*");
|
|
||||||
label.setIcon(AutoupdateUtil.loadIcon("livedocs/variable.png"));
|
|
||||||
label.setToolTipText("Variable " + field.getName());
|
|
||||||
result.addControl(label);
|
|
||||||
result.actionsListAdd(context, new RefreshActions() {
|
|
||||||
@Override
|
|
||||||
public void refresh(BinaryProtocol bp, byte[] response) {
|
|
||||||
Number fieldValue = field.getValue(new ConfigurationImage(response));
|
|
||||||
String value = Field.niceToString(fieldValue, LIVE_DATA_PRECISION);
|
|
||||||
label.setText(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (r instanceof ConfigRequest) {
|
|
||||||
ConfigRequest request = (ConfigRequest) r;
|
|
||||||
Field field = Field.findField(Fields.VALUES, settingsInstancePrefix, request.getField());
|
|
||||||
|
|
||||||
JLabel label = new LessJumpyJLabel("*");
|
|
||||||
label.setIcon(AutoupdateUtil.loadIcon("livedocs/setting.png"));
|
|
||||||
label.setToolTipText(getTooltipText(field.getName()));
|
|
||||||
result.addControl(label);
|
|
||||||
// todo: use different notification flow altogether since configuration has nothing to do with live data structures
|
|
||||||
result.actionsListAdd(new LiveDataContext(Fields.LDS_ENGINE_STATE_INDEX), new RefreshActions() {
|
|
||||||
@Override
|
|
||||||
public void refresh(BinaryProtocol bp, byte[] response) {
|
|
||||||
double multiplier = 1; // todo: PROPER MULTIPLIER!!!
|
|
||||||
String value = field.getAnyValue(bp.getControllerConfiguration(), multiplier).toString();
|
|
||||||
label.setText(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (r instanceof SensorRequest) {
|
|
||||||
SensorRequest request = (SensorRequest) r;
|
|
||||||
Sensor sensor = Sensor.find(request.getValue());
|
|
||||||
JLabel label = new LessJumpyJLabel("*");
|
|
||||||
label.setIcon(AutoupdateUtil.loadIcon("livedocs/gauge.png"));
|
|
||||||
label.setToolTipText("Sensor " + request.getValue());
|
|
||||||
label.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
if (e.getClickCount() == 2 && !SwingUtilities.isRightMouseButton(e)) {
|
|
||||||
final DetachedSensor ds = new DetachedSensor(uiContext, sensor, MAGIC_DETACHED_GAUGE_SIZE);
|
|
||||||
ds.show(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
result.addControl(label);
|
|
||||||
SensorCentral.getInstance().addListener(sensor, value -> label.setText(niceToString(value, LIVE_DATA_PRECISION)));
|
|
||||||
} else if (r instanceof IfRequest) {
|
|
||||||
IfRequest request = (IfRequest) r;
|
|
||||||
|
|
||||||
IfConditionPanel panel = createIfRequestPanel(uiContext, request, defaultContext);
|
|
||||||
|
|
||||||
result.actionsListAddAll(panel.getActionsList());
|
|
||||||
|
|
||||||
result.addControl(panel.getPanel());
|
|
||||||
} else {
|
|
||||||
throw new UnsupportedOperationException(r.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static LiveDataContext getFieldContext(LiveDataContext defaultContext, String stateContext) {
|
|
||||||
if (stateContext.isEmpty()) {
|
|
||||||
return defaultContext;
|
|
||||||
} else {
|
|
||||||
String indexFieldName = StateDictionary.getContextIndexFieldName(stateContext);
|
|
||||||
return StateDictionary.getStateContext(indexFieldName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Field getField(LiveDataContext defaultContext, FieldReference request) {
|
|
||||||
Field[] context;
|
|
||||||
if (request.getStateContext().isEmpty()) {
|
|
||||||
context = StateDictionary.INSTANCE.getFields("create", defaultContext);
|
|
||||||
} else {
|
|
||||||
context = StateDictionary.INSTANCE.getValue(request.getStateContext());
|
|
||||||
}
|
|
||||||
return Field.findField(context, "", request.getField());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTooltipText(String configurationFieldName) {
|
|
||||||
DialogModel.Field dialogField = IniFileModel.getInstance().getField(configurationFieldName);
|
|
||||||
if (dialogField == null) {
|
|
||||||
return "Configuration " + configurationFieldName;
|
|
||||||
}
|
|
||||||
return "Configuration " + dialogField.getUiName() + " (" + configurationFieldName + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IfConditionPanel createIfRequestPanel(UIContext uiContext, IfRequest request, LiveDataContext defaultContext) {
|
|
||||||
Field conditionField = getField(defaultContext, request);
|
|
||||||
|
|
||||||
JPanel result = new JPanel(new VerticalFlowLayout());
|
|
||||||
|
|
||||||
JLabel conditionLabel = new LessJumpyJLabel(request.getField());
|
|
||||||
result.add(conditionLabel);
|
|
||||||
|
|
||||||
|
|
||||||
ActionPanel trueAP = createComponents(uiContext, "", request.trueBlock.toArray(new Request[0]), "", defaultContext);
|
|
||||||
ActionPanel falseAP = createComponents(uiContext, "", request.falseBlock.toArray(new Request[0]), "", defaultContext);
|
|
||||||
|
|
||||||
result.add(trueAP.getPanel());
|
|
||||||
result.add(falseAP.getPanel());
|
|
||||||
|
|
||||||
RefreshActionsMap combined = trueAP.getRefreshActions();
|
|
||||||
combined.addAll(falseAP.getRefreshActions());
|
|
||||||
|
|
||||||
LiveDataContext context = getFieldContext(defaultContext, request.getStateContext());
|
|
||||||
|
|
||||||
combined.put(context, new RefreshActions() {
|
|
||||||
@Override
|
|
||||||
public void refresh(BinaryProtocol bp, byte[] response) {
|
|
||||||
int value = (int) conditionField.getValue(new ConfigurationImage(response)).intValue();
|
|
||||||
conditionLabel.setText(request.getField() + " is " + (value == 1 ? "TRUE" : "FALSE"));
|
|
||||||
JPanel active;
|
|
||||||
JPanel passive;
|
|
||||||
if (value == 1) {
|
|
||||||
active = trueAP.getPanel();
|
|
||||||
passive = falseAP.getPanel();
|
|
||||||
} else {
|
|
||||||
active = falseAP.getPanel();
|
|
||||||
passive = trueAP.getPanel();
|
|
||||||
}
|
|
||||||
active.setBorder(BorderFactory.createLineBorder(Color.green));
|
|
||||||
passive.setBorder(BorderFactory.createLineBorder(Color.red));
|
|
||||||
Toolbox.setEnabledRecursive(active, true);
|
|
||||||
Toolbox.setEnabledRecursive(passive, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return new IfConditionPanel(result, combined);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JPanel createLiveDocumentationPanel(UIContext uiContext) {
|
|
||||||
JPanel liveDocs = new JPanel(new MigLayout(LAYOUT));
|
|
||||||
|
|
||||||
liveDocs.add(createPanel(uiContext,"Fuel", FuelMathMeta.CONTENT), CONSTRAINTS);
|
|
||||||
|
|
||||||
liveDocs.add(createPanel(uiContext, "tCharge", SpeedDensityMeta.CONTENT), CONSTRAINTS);
|
|
||||||
|
|
||||||
liveDocs.add(createPanel(uiContext, "Idle", IdleThreadMeta.CONTENT), CONSTRAINTS);
|
|
||||||
|
|
||||||
// todo: restore this functionality
|
|
||||||
// liveDocs.add(createPanel("ETB", ElectronicThrottleMeta.CONTENT), CONSTRAINTS);
|
|
||||||
|
|
||||||
return liveDocs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JPanel createSensorsLiveDataPanel(UIContext uiContext) {
|
|
||||||
JPanel liveDocs = new JPanel(new MigLayout(LAYOUT));
|
|
||||||
|
|
||||||
/*
|
|
||||||
One day we shall have this back
|
|
||||||
liveDocs.add(createPanel("Throttle Position Sensor", TpsMeta.TPS_SECTION), CONSTRAINTS);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
liveDocs.add(createPanel(uiContext, "Trigger", TriggerDecoderMeta.CONTENT), CONSTRAINTS);
|
|
||||||
|
|
||||||
return liveDocs;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.generated.ThermistorsMeta;
|
|
||||||
import com.rusefi.ui.livedocs.controls.Toolbox;
|
|
||||||
import com.rusefi.ui.util.FrameHelper;
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
import static com.rusefi.ui.livedocs.controls.Toolbox.setTransparentLineBorder;
|
|
||||||
|
|
||||||
public class LiveDocsSandbox {
|
|
||||||
public static JLabel comment = new JLabel("Prototype Comments appear here");
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
comment.setForeground(Color.blue);
|
|
||||||
|
|
||||||
JPanel panels = new JPanel(new MigLayout("fillx, gap 0, insets 0"));
|
|
||||||
// panels.add(LiveDocPanel.createPanel("Coolant Sensor", ThermistorsMeta.CONTENT, "CLT", LDS_CLT_STATE_INDEX), "wrap");
|
|
||||||
// panels.add(LiveDocPanel.createPanel("Intake Air Sensor", ThermistorsMeta.CONTENT, "IAT", LDS_IAT_STATE_INDEX), "wrap");
|
|
||||||
|
|
||||||
panels.add(getTChargePanel(), "wrap, grow");
|
|
||||||
|
|
||||||
panels.add(comment);
|
|
||||||
|
|
||||||
new FrameHelper().showFrame(panels);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Component getTChargePanel() {
|
|
||||||
JPanel panel = new JPanel(new MigLayout("gap 0, insets 0"));
|
|
||||||
panel.setBorder(BorderFactory.createTitledBorder("Air Charge Temperature"));
|
|
||||||
panel.setBorder(BorderFactory.createLineBorder(Color.CYAN));
|
|
||||||
|
|
||||||
JPanel topPanel = new JPanel(new MigLayout());
|
|
||||||
setTransparentLineBorder(topPanel);
|
|
||||||
topPanel.add(new JLabel("top"));
|
|
||||||
|
|
||||||
JPanel bottomPanel = new JPanel(new MigLayout());
|
|
||||||
setTransparentLineBorder(bottomPanel);
|
|
||||||
bottomPanel.add(new JLabel("bottom"));
|
|
||||||
|
|
||||||
addBranch(panel, true, topPanel, bottomPanel);
|
|
||||||
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addBranch(JPanel panel, boolean b, JPanel topPanel, JPanel bottomPanel) {
|
|
||||||
//IfBranch branch;
|
|
||||||
JPanel topWrapped = wrapWithOffset(topPanel);
|
|
||||||
JPanel bottomWrapped = wrapWithOffset(bottomPanel);
|
|
||||||
|
|
||||||
topPanel.setBorder(BorderFactory.createLineBorder(Color.green));
|
|
||||||
bottomPanel.setBorder(BorderFactory.createLineBorder(Color.red));
|
|
||||||
Toolbox.setEnabledRecursive(bottomPanel, false);
|
|
||||||
|
|
||||||
|
|
||||||
panel.add(new JLabel("If xa"), "wrap");
|
|
||||||
panel.add(topWrapped, "wrap");
|
|
||||||
panel.add(new JLabel("else"), "wrap");
|
|
||||||
panel.add(bottomWrapped, "wrap");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JPanel wrapWithOffset(JPanel panel) {
|
|
||||||
JPanel topWrapped = new JPanel(new FlowLayout());
|
|
||||||
topWrapped.add(new JLabel(" "));
|
|
||||||
topWrapped.add(panel);
|
|
||||||
return topWrapped;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs.controls;
|
|
||||||
|
|
||||||
public class ConfigReference {
|
|
||||||
final int value;
|
|
||||||
|
|
||||||
public ConfigReference(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs.controls;
|
|
||||||
|
|
||||||
import com.rusefi.ui.livedocs.LiveDocsSandbox;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
public class ConfigView {
|
|
||||||
private final JLabel content;
|
|
||||||
|
|
||||||
public ConfigView(ConfigReference e) {
|
|
||||||
content = new JLabel(Integer.toString(e.value));
|
|
||||||
markLiveElement(content);
|
|
||||||
content.setToolTipText("Configuration XXX");
|
|
||||||
|
|
||||||
content.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
LiveDocsSandbox.comment.setText("Mouse action shows tooltip");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void markLiveElement(JComponent content) {
|
|
||||||
content.setBackground(Color.lightGray);
|
|
||||||
content.setOpaque(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JLabel getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs.controls;
|
|
||||||
|
|
||||||
import com.rusefi.ui.livedocs.LiveDocsSandbox;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
import static com.rusefi.ui.livedocs.controls.ConfigView.markLiveElement;
|
|
||||||
|
|
||||||
public class LogicReference {
|
|
||||||
private final JLabel content = new JLabel();
|
|
||||||
|
|
||||||
public LogicReference(double value, JComponent reference) {
|
|
||||||
content.setText(Double.toString(value));
|
|
||||||
markLiveElement(content);
|
|
||||||
content.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
reference.setBorder(BorderFactory.createLineBorder(Color.red));
|
|
||||||
LiveDocsSandbox.comment.setText("Mouse action highlights referenced element");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) {
|
|
||||||
Toolbox.setTransparentLineBorder(reference);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public JLabel getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs.controls;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swing UI utilities
|
|
||||||
*/
|
|
||||||
public class Toolbox {
|
|
||||||
public static void setTransparentLineBorder(JComponent reference) {
|
|
||||||
reference.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setEnabledRecursive(Container panel, boolean value) {
|
|
||||||
panel.setEnabled(value);
|
|
||||||
Component[] com = panel.getComponents();
|
|
||||||
for (int a = 0; a < com.length; a++) {
|
|
||||||
Component element = com[a];
|
|
||||||
if (element instanceof Container) {
|
|
||||||
setEnabledRecursive((Container) element, value);
|
|
||||||
} else {
|
|
||||||
element.setEnabled(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs.test;
|
|
||||||
|
|
||||||
import com.rusefi.ui.livedocs.LiveDocPanel;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
public class LiveDocPanelTest {
|
|
||||||
@Test
|
|
||||||
public void testFindField() throws NoSuchFieldException {
|
|
||||||
// Field reflectField = Fields.class.getField("LDS_CLT_STATE_INDEX");
|
|
||||||
// assertNotNull(reflectField);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidDocumentationMetaInfo() {
|
|
||||||
assertNotNull(LiveDocPanel.createLiveDocumentationPanel(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidSensorsMetaInfo() {
|
|
||||||
assertNotNull(LiveDocPanel.createSensorsLiveDataPanel(null));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reference to a parameter from configuration
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ConfigRequest extends Request {
|
|
||||||
//@NotNull
|
|
||||||
private final String field;
|
|
||||||
|
|
||||||
public ConfigRequest(String field) {
|
|
||||||
Objects.requireNonNull(field);
|
|
||||||
this.field = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getField() {
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ConfigRequest{" +
|
|
||||||
"field='" + field + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
ConfigRequest that = (ConfigRequest) o;
|
|
||||||
return field.equals(that.field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGeneratedJavaCode() {
|
|
||||||
return withSimpleParameter(quoteString(field));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
public interface FieldReference {
|
|
||||||
String getStateContext();
|
|
||||||
|
|
||||||
String getField();
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static com.rusefi.ConfigDefinition.EOL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
|
||||||
*/
|
|
||||||
public class FieldRequest extends Request implements FieldReference {
|
|
||||||
private final String stateContext;
|
|
||||||
private final String field;
|
|
||||||
|
|
||||||
public FieldRequest(String stateContext, String field) {
|
|
||||||
this.stateContext = stateContext;
|
|
||||||
this.field = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStateContext() {
|
|
||||||
return stateContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getField() {
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "FieldRequest{" +
|
|
||||||
"stateContext='" + stateContext + '\'' +
|
|
||||||
", field='" + field + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
FieldRequest request = (FieldRequest) o;
|
|
||||||
return stateContext.equals(request.stateContext) &&
|
|
||||||
field.equals(request.field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(stateContext, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGeneratedJavaCode() {
|
|
||||||
return GLOBAL_PREFIX + "new " + getClass().getSimpleName() + "("
|
|
||||||
+ quoteString(stateContext)
|
|
||||||
+ ", "
|
|
||||||
+ quoteString(field)
|
|
||||||
+ ")," + EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.rusefi.ConfigDefinition.EOL;
|
|
||||||
|
|
||||||
public class IfRequest extends Request implements FieldReference {
|
|
||||||
private final String stateContext;
|
|
||||||
private final String variable;
|
|
||||||
public List<Request> trueBlock = new ArrayList<>();
|
|
||||||
public List<Request> falseBlock = new ArrayList<>();
|
|
||||||
|
|
||||||
public IfRequest(String stateContext, String variable) {
|
|
||||||
this.stateContext = stateContext;
|
|
||||||
this.variable = variable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IfRequest(String stateContext, String variable, Request[] trueBlock, Request[] falseBlock) {
|
|
||||||
this(stateContext, variable);
|
|
||||||
this.trueBlock.addAll(Arrays.asList(trueBlock));
|
|
||||||
this.falseBlock.addAll(Arrays.asList(falseBlock));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStateContext() {
|
|
||||||
return stateContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "IfRequest{" +
|
|
||||||
"variable='" + variable + '\'' +
|
|
||||||
", trueBlock=" + trueBlock +
|
|
||||||
", falseBlock=" + falseBlock +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getField() {
|
|
||||||
return variable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGeneratedJavaCode() {
|
|
||||||
String result = Request.GLOBAL_PREFIX;
|
|
||||||
|
|
||||||
Request.GLOBAL_PREFIX = Request.GLOBAL_PREFIX + "\t";
|
|
||||||
|
|
||||||
result += "new IfRequest("
|
|
||||||
+ quoteString(stateContext)
|
|
||||||
+ ", "
|
|
||||||
+ quoteString(variable)
|
|
||||||
+ "," + EOL +
|
|
||||||
Request.GLOBAL_PREFIX + "new Request[]{" + EOL +
|
|
||||||
Request.getGeneratedJavaCode(trueBlock) +
|
|
||||||
"}," + EOL +
|
|
||||||
Request.GLOBAL_PREFIX + "new Request[]{" + EOL +
|
|
||||||
Request.getGeneratedJavaCode(falseBlock) +
|
|
||||||
"})," + EOL;
|
|
||||||
|
|
||||||
Request.GLOBAL_PREFIX = Request.GLOBAL_PREFIX.substring(1);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,207 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import com.rusefi.util.SystemOut;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static com.rusefi.ConfigDefinition.EOL;
|
|
||||||
|
|
||||||
public class LiveDocsMetaParser {
|
|
||||||
private static final String DISPLAY_TAG = "DISPLAY_TAG";
|
|
||||||
private static final String DISPLAY_CONFIG = "DISPLAY_CONFIG";
|
|
||||||
private static final String DISPLAY_PREFIX = "DISPLAY_PREFIX";
|
|
||||||
private static final String DISPLAY_FIELD = "DISPLAY_FIELD";
|
|
||||||
private static final String DISPLAY_STATE = "DISPLAY_STATE";
|
|
||||||
private static final String DISPLAY_TEXT = "DISPLAY_TEXT";
|
|
||||||
private static final String DISPLAY_SENSOR = "DISPLAY_SENSOR";
|
|
||||||
private static final String DISPLAY_IF = "DISPLAY_IF";
|
|
||||||
private static final String DISPLAY_ELSE = "DISPLAY_ELSE";
|
|
||||||
private static final String DISPLAY_ENDIF = "DISPLAY_ENDIF";
|
|
||||||
private static final char QUOTE_SYMBOL = '"';
|
|
||||||
public static final String TODO_MAKE_THIS_DESTINATION_PARAMETER = "/ui/src/main/java/com/rusefi/ldmp/generated/";
|
|
||||||
private static StringBuilder prefix = new StringBuilder();
|
|
||||||
|
|
||||||
private static String readLineByLine(String filePath) throws IOException {
|
|
||||||
StringBuilder contentBuilder = new StringBuilder();
|
|
||||||
Stream<String> stream = Files.lines(Paths.get(filePath), StandardCharsets.UTF_8);
|
|
||||||
stream.forEach(s -> contentBuilder.append(s).append("\n"));
|
|
||||||
return contentBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
if (args.length != 2)
|
|
||||||
throw new IllegalArgumentException("Two arguments expected but " + Arrays.toString(args));
|
|
||||||
String destinationPath = args[0];
|
|
||||||
String fileName = args[1];
|
|
||||||
handleMetaData(destinationPath, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleMetaData(String destinationPath, String inputFileName) throws IOException {
|
|
||||||
MetaInfo metaInfo = getMetaFromFile(inputFileName);
|
|
||||||
SystemOut.println(metaInfo);
|
|
||||||
|
|
||||||
String className = getClassName(inputFileName);
|
|
||||||
String javaCode = generateJavaCode(metaInfo, className);
|
|
||||||
String fullDestination = destinationPath + TODO_MAKE_THIS_DESTINATION_PARAMETER;
|
|
||||||
new File(fullDestination).mkdirs();
|
|
||||||
FileWriter fw = new FileWriter(fullDestination + className + ".java");
|
|
||||||
fw.write(javaCode);
|
|
||||||
fw.close();
|
|
||||||
SystemOut.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MetaInfo getMetaFromFile(String fileName) throws IOException {
|
|
||||||
SystemOut.println(fileName);
|
|
||||||
if (!new File(fileName).exists())
|
|
||||||
throw new IllegalStateException("Not found " + fileName);
|
|
||||||
String content = readLineByLine(fileName);
|
|
||||||
return parse(content, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MetaInfo parse(String string, String context) {
|
|
||||||
Stack<List<Request>> stack = new Stack<>();
|
|
||||||
|
|
||||||
|
|
||||||
MetaInfo meta = new MetaInfo();
|
|
||||||
|
|
||||||
List<Request> result = meta.start("CONTENT");
|
|
||||||
string = string.replaceAll("[()>.]", " ");
|
|
||||||
SystemOut.println(string);
|
|
||||||
Scanner s = new Scanner(string);
|
|
||||||
while (s.hasNext()) {
|
|
||||||
String token = s.next();
|
|
||||||
//SystemOut.println(token);
|
|
||||||
if (DISPLAY_CONFIG.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String config = s.next();
|
|
||||||
SystemOut.println("REQ CONF " + config);
|
|
||||||
result.add(new ConfigRequest(config));
|
|
||||||
}
|
|
||||||
} else if (DISPLAY_STATE.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String state = s.next();
|
|
||||||
meta.stateStack.push(state); }
|
|
||||||
} else if (DISPLAY_TEXT.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String config = s.next();
|
|
||||||
if (config.startsWith(String.valueOf(QUOTE_SYMBOL))) {
|
|
||||||
config = config.substring(1);
|
|
||||||
while (!config.endsWith(String.valueOf(QUOTE_SYMBOL))) {
|
|
||||||
String next = s.next();
|
|
||||||
config += ' ' + next;
|
|
||||||
}
|
|
||||||
config = config.substring(0, config.length() - 1);
|
|
||||||
}
|
|
||||||
SystemOut.println("Display test " + config);
|
|
||||||
result.add(new TextRequest(config));
|
|
||||||
}
|
|
||||||
} else if (DISPLAY_TAG.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String tag = s.next();
|
|
||||||
SystemOut.println("REQ TAG " + tag);
|
|
||||||
result = meta.start(tag);
|
|
||||||
}
|
|
||||||
} else if (DISPLAY_PREFIX.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String current = s.next();
|
|
||||||
prefix.append(current + "_");
|
|
||||||
}
|
|
||||||
} else if (DISPLAY_FIELD.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String fieldName = prefix + s.next();
|
|
||||||
SystemOut.println("REQ FIELD " + fieldName);
|
|
||||||
result.add(new FieldRequest(meta.getStateContext(), fieldName));
|
|
||||||
prefix.setLength(0);
|
|
||||||
}
|
|
||||||
} else if (DISPLAY_IF.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
stack.push(result);
|
|
||||||
|
|
||||||
String conditionVariable = s.next();
|
|
||||||
|
|
||||||
SystemOut.println("if Condition " + conditionVariable);
|
|
||||||
IfRequest ifRequest = new IfRequest(meta.getStateContext(), conditionVariable);
|
|
||||||
result.add(ifRequest);
|
|
||||||
|
|
||||||
result = ifRequest.trueBlock;
|
|
||||||
}
|
|
||||||
} else if (DISPLAY_ELSE.equalsIgnoreCase(token)) {
|
|
||||||
if (stack.isEmpty())
|
|
||||||
throw new IllegalStateException("No IF statement on stack while we have DISPLAY_ELSE while " + context);
|
|
||||||
List<Request> onStack = stack.peek();
|
|
||||||
if (onStack.isEmpty())
|
|
||||||
throw new IllegalStateException("Empty on stack");
|
|
||||||
Request request = onStack.get(onStack.size() - 1);
|
|
||||||
if (!(request instanceof IfRequest))
|
|
||||||
throw new IllegalStateException("Something not right " + request);
|
|
||||||
IfRequest ifRequest = (IfRequest) request;
|
|
||||||
|
|
||||||
result = ifRequest.falseBlock;
|
|
||||||
} else if (DISPLAY_ENDIF.equalsIgnoreCase(token)) {
|
|
||||||
if (stack.isEmpty())
|
|
||||||
throw new IllegalStateException("No IF statement on stack");
|
|
||||||
result = stack.pop();
|
|
||||||
|
|
||||||
} else if (DISPLAY_SENSOR.equalsIgnoreCase(token)) {
|
|
||||||
if (s.hasNext()) {
|
|
||||||
String config = s.next();
|
|
||||||
SystemOut.println("REQ SENSOR " + config);
|
|
||||||
result.add(new SensorRequest(config));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stack.isEmpty())
|
|
||||||
throw new IllegalStateException("Unfinished");
|
|
||||||
return meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String generateJavaCode(MetaInfo r, String className) {
|
|
||||||
StringBuilder java = new StringBuilder("package com.rusefi.ldmp.generated;" + EOL + EOL +
|
|
||||||
"import com.rusefi.ldmp.*;" + EOL + EOL +
|
|
||||||
"public class " + className + " {" + EOL
|
|
||||||
);
|
|
||||||
|
|
||||||
for (Map.Entry<String, List<Request>> e : r.map.entrySet()) {
|
|
||||||
List<Request> list = e.getValue();
|
|
||||||
if (list.isEmpty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
java.append("\tpublic static final Request[] " +
|
|
||||||
e.getKey() +
|
|
||||||
" = new Request[]{" + EOL);
|
|
||||||
java.append(Request.getGeneratedJavaCode(list));
|
|
||||||
java.append("\t};" + EOL);
|
|
||||||
}
|
|
||||||
|
|
||||||
java.append("}");
|
|
||||||
return java.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String toProperCase(String s) {
|
|
||||||
return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getClassName(String cppSourceName) {
|
|
||||||
int lastDotIndex = cppSourceName.lastIndexOf('.');
|
|
||||||
if (lastDotIndex != -1)
|
|
||||||
cppSourceName = cppSourceName.substring(0, lastDotIndex);
|
|
||||||
int lastSlashIndex = cppSourceName.lastIndexOf('/');
|
|
||||||
if (lastDotIndex != -1)
|
|
||||||
cppSourceName = cppSourceName.substring(lastSlashIndex + 1);
|
|
||||||
|
|
||||||
String[] parts = cppSourceName.split("_");
|
|
||||||
String camelCaseString = "";
|
|
||||||
for (String part : parts) {
|
|
||||||
camelCaseString = camelCaseString + toProperCase(part);
|
|
||||||
}
|
|
||||||
return camelCaseString + "Meta";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MetaInfo {
|
|
||||||
public Map<String, List<Request>> map = new TreeMap<>();
|
|
||||||
public Stack<String> stateStack = new Stack<>();
|
|
||||||
|
|
||||||
public List<Request> start(String content) {
|
|
||||||
map.putIfAbsent(content, new ArrayList<>());
|
|
||||||
return map.get(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Request> first() {
|
|
||||||
return map.values().iterator().next();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStateContext() {
|
|
||||||
if (stateStack.isEmpty()) {
|
|
||||||
// state context not defined, java code would have to explicitly provide that information
|
|
||||||
// this is used if code does not know context, for instance thermistor code does not know if CLT or IAT usage
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return stateStack.peek();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.rusefi.ConfigDefinition.EOL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
|
||||||
*/
|
|
||||||
public abstract class Request {
|
|
||||||
static String GLOBAL_PREFIX = "\t\t\t";
|
|
||||||
|
|
||||||
static String getGeneratedJavaCode(List<Request> r) {
|
|
||||||
StringBuilder java = new StringBuilder();
|
|
||||||
for (Request request : r)
|
|
||||||
java.append(request.getGeneratedJavaCode());
|
|
||||||
return java.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String getGeneratedJavaCode();
|
|
||||||
|
|
||||||
protected String withSimpleParameter(String parameter) {
|
|
||||||
return GLOBAL_PREFIX + "new " + getClass().getSimpleName() + "(" + parameter + ")," + EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String quoteString(String variable) {
|
|
||||||
return "\"" + variable + "\"";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class SensorRequest extends Request {
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
public SensorRequest(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SensorRequest{" +
|
|
||||||
"value='" + value + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
SensorRequest that = (SensorRequest) o;
|
|
||||||
return value.equals(that.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGeneratedJavaCode() {
|
|
||||||
return withSimpleParameter(quoteString(value));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package com.rusefi.ldmp;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Static text label
|
|
||||||
*/
|
|
||||||
public class TextRequest extends Request {
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
public TextRequest(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEol() {
|
|
||||||
return "EOL".equalsIgnoreCase(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TextRequest{" +
|
|
||||||
"value='" + value + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
TextRequest that = (TextRequest) o;
|
|
||||||
return value.equals(that.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGeneratedJavaCode() {
|
|
||||||
return withSimpleParameter(quoteString(value));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,6 @@ public class UsagesReader {
|
||||||
List<String> usages = (List) data.get("Usages");
|
List<String> usages = (List) data.get("Usages");
|
||||||
SystemOut.println("Usages: " + usages);
|
SystemOut.println("Usages: " + usages);
|
||||||
for (String fileName : usages) {
|
for (String fileName : usages) {
|
||||||
LiveDocsMetaParser.handleMetaData(destination, fileName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,122 +0,0 @@
|
||||||
package com.rusefi.ldmp.test;
|
|
||||||
|
|
||||||
import com.rusefi.ldmp.*;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class LiveDocsMetaParserTest {
|
|
||||||
public static MetaInfo parse(String s) {
|
|
||||||
return LiveDocsMetaParser.parse(s, "unit_test");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getClassName() {
|
|
||||||
assertEquals("TpsMeta", LiveDocsMetaParser.getClassName("controllers/sensors/tps.cpp"));
|
|
||||||
assertEquals("SpeedDensityMeta", LiveDocsMetaParser.getClassName("speed_density.cpp"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseConfigElements() {
|
|
||||||
MetaInfo r = parse("\t\t// TCHARGE_MODE_RPM_TPS\n" +
|
|
||||||
"\t\tfloat minRpmKcurrentTPS = interpolateMsg(\"minRpm\", tpMin, DISPLAY_CONFIG(tChargeMinRpmMinTps), tpMax,\n" +
|
|
||||||
"\t\t\t\t/***display*/CONFIG(tChargeMinRpmMaxTps), tps);\n" +
|
|
||||||
"\t\tfloat maxRpmKcurrentTPS = interpolateMsg(\"maxRpm\", tpMin, DISPLAY_CONFIG(tChargeMaxRpmMinTps), tpMax,\n" +
|
|
||||||
"\t\t\t\tDISPLAY_CONFIG(tChargeMaxRpmMaxTps), tps);\n" +
|
|
||||||
"\n" +
|
|
||||||
"\t\tengine->engineState.Tcharge_coff = interpolateMsg(\"Kcurr\", rpmMin, minRpmKcurrentTPS, rpmMax, maxRpmKcurrentTPS, rpm);\n");
|
|
||||||
assertEquals(3, r.first().size());
|
|
||||||
assertEquals(new ConfigRequest("tChargeMinRpmMinTps"), r.first().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseField() {
|
|
||||||
MetaInfo r = parse(
|
|
||||||
"DISPLAY_STATE(tps)\n" +
|
|
||||||
"\tDISPLAY_TEXT(Analog_MCU_reads);\n" +
|
|
||||||
"\tengine->engineState.DISPLAY_FIELD(currentTpsAdc) = adc;\n" +
|
|
||||||
"\tDISPLAY_TEXT(ADC_which_equals);\n");
|
|
||||||
assertEquals(3, r.first().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseTextWithSpecialCharacters() {
|
|
||||||
MetaInfo r = parse(
|
|
||||||
"DISPLAY_TEXT(\"Analog: !MCU_reads\");"
|
|
||||||
);
|
|
||||||
assertEquals(1, r.first().size());
|
|
||||||
TextRequest request = (TextRequest) r.first().get(0);
|
|
||||||
assertEquals("Analog: !MCU_reads", request.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseTextWithSpecialCharactersAndSpaces() {
|
|
||||||
MetaInfo r = parse(
|
|
||||||
"DISPLAY_TEXT(\"Analog: !MCU_reads\");"
|
|
||||||
);
|
|
||||||
assertEquals(1, r.first().size());
|
|
||||||
TextRequest request = (TextRequest) r.first().get(0);
|
|
||||||
assertEquals("Analog: !MCU_reads", request.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseDisplayConfig() {
|
|
||||||
MetaInfo r = parse("\t\t// DISPLAY_TEXT(interpolate(\")\n" +
|
|
||||||
"+\t\tDISPLAY_SENSOR(RPM) DISPLAY_TEXT(TCHARGE_MODE_RPM_TPS)\n" +
|
|
||||||
"\t\tfloat minRpmKcurrentTPS = interpolateMsg(\"minRpm\", tpMin, DISPLAY_CONFIG(tChargeMinRpmMinTps), tpMax,\n");
|
|
||||||
assertEquals(4, r.first().size());
|
|
||||||
// implementation has eaten the bracket :(
|
|
||||||
assertEquals(new TextRequest("interpolate"), r.first().get(0));
|
|
||||||
assertEquals(new SensorRequest("RPM"), r.first().get(1));
|
|
||||||
|
|
||||||
String javaCode = LiveDocsMetaParser.generateJavaCode(r, "xx");
|
|
||||||
assertEquals("package com.rusefi.ldmp.generated;\n" +
|
|
||||||
"\n" +
|
|
||||||
"import com.rusefi.ldmp.*;\n" +
|
|
||||||
"\n" +
|
|
||||||
"public class xx {\n" +
|
|
||||||
"\tpublic static final Request[] CONTENT = new Request[]{\n" +
|
|
||||||
"\t\t\tnew TextRequest(\"interpolate\"),\n" +
|
|
||||||
"\t\t\tnew SensorRequest(\"RPM\"),\n" +
|
|
||||||
"\t\t\tnew TextRequest(\"TCHARGE_MODE_RPM_TPS\"),\n" +
|
|
||||||
"\t\t\tnew ConfigRequest(\"tChargeMinRpmMinTps\"),\n" +
|
|
||||||
"\t};\n" +
|
|
||||||
"}", javaCode);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testField() {
|
|
||||||
MetaInfo r = parse(
|
|
||||||
"DISPLAY_STATE(tps)\n" +
|
|
||||||
"tm->DISPLAY_FIELD(voltageMCU) = getVoltage(\"term\", config->adcChannel);\n" +
|
|
||||||
|
|
||||||
"DISPLAY_tag(tag) DISPLAY_FIELD(voltageMCU2)");
|
|
||||||
assertEquals(1, r.first().size());
|
|
||||||
assertEquals(new FieldRequest("tps", "voltageMCU"), r.first().get(0));
|
|
||||||
|
|
||||||
assertEquals(2, r.map.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseIf() {
|
|
||||||
MetaInfo r = parse("\tDisPLAY_IF(cond)\t// DISPLAY_TEXT(\"interpolate(\")\n" +
|
|
||||||
"+\t\tDISPLAY_SENSOR(RPM)" +
|
|
||||||
"/* DISPLAY_ElsE */ DISPLAY_TEXT(\"TCHARGE_MODE_RPM_TPS\")\n" +
|
|
||||||
"\t\tfloat minRpmKcurrentTPS = interpolateMsg(\"minRpm\", tpMin, DISPLAY_CONFIG(tChargeMinRpmMinTps), tpMax,\n" +
|
|
||||||
"/* DISPLAY_ENDIF */");
|
|
||||||
|
|
||||||
assertEquals(1, r.first().size());
|
|
||||||
IfRequest ifRequest = (IfRequest) r.first().get(0);
|
|
||||||
List<Request> trueBlock = ifRequest.trueBlock;
|
|
||||||
assertEquals(2, trueBlock.size());
|
|
||||||
assertEquals(new SensorRequest("RPM"), trueBlock.get(1));
|
|
||||||
|
|
||||||
List<Request> falseBlock = ifRequest.falseBlock;
|
|
||||||
assertEquals(2, falseBlock.size());
|
|
||||||
assertEquals(new ConfigRequest("tChargeMinRpmMinTps"), falseBlock.get(1));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue