Whatever we call it, no matter how we do it - we need live data / remote view into rusEFI actual state #3353

progress
This commit is contained in:
rusefillc 2021-10-14 19:55:17 -04:00
parent da3519015f
commit e9d8df122c
4 changed files with 85 additions and 26 deletions

View File

@ -1,10 +1,7 @@
package com.rusefi.ldmp;
import com.rusefi.config.Field;
import com.rusefi.config.generated.EngineState;
import com.rusefi.config.generated.PidState;
import com.rusefi.config.generated.TriggerCentral;
import com.rusefi.config.generated.TriggerState;
import com.rusefi.config.generated.*;
import com.rusefi.enums.live_data_e;
import org.jetbrains.annotations.NotNull;
@ -14,8 +11,7 @@ import java.util.Map;
public enum StateDictionary {
INSTANCE;
public static final int NONE = -1;
private Map<live_data_e, Field[]> map = new HashMap<>();
private final Map<live_data_e, Field[]> map = new HashMap<>();
StateDictionary() {
register(live_data_e.LDS_SPEED_DENSITY, EngineState.VALUES); // 2
@ -28,7 +24,7 @@ public enum StateDictionary {
// LDS_ALTERNATOR_PID
// LDS_CJ125_PID
register(live_data_e.LDS_TRIGGER_STATE, TriggerState.VALUES); // 11
register(live_data_e.LDS_AC_STATE, AcControl.VALUES); // 12
register(live_data_e.LDS_AC_CONTROL, AcControl.VALUES); // 12
}
private void register(live_data_e ldsIndex, Field[] values) {

View File

@ -37,9 +37,12 @@ public class LiveDataParserPanel {
private static final Logging log = getLogging(LiveDataParserPanel.class);
private final JPanel content = new JPanel(new BorderLayout());
private final JTextPane text = new JTextPane();
private final VariableValueSource valueSource;
private String sourceCode;
public LiveDataParserPanel(VariableValueSource valueSource) {
JTextPane text = new JTextPane();
this.valueSource = valueSource;
JScrollPane rightScrollPane = new JScrollPane(text,
VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
@ -47,24 +50,10 @@ public class LiveDataParserPanel {
content.add(rightScrollPane);
try {
String sourceCode = getContent(getClass(), "ac_control.cpp");
sourceCode = getContent(getClass(), "ac_control.cpp");
text.setText(sourceCode);
ParseTree tree = getParseTree(sourceCode);
StyleContext sc = StyleContext.getDefaultStyleContext();
StyledDocument style = text.getStyledDocument();
AttributeSet oldSet = style.getCharacterElement(0).getAttributes();
applyVariables(valueSource, sourceCode, new SourceCodePainter() {
@Override
public void paint(Color color, Range range) {
AttributeSet s = sc.addAttribute(oldSet, StyleConstants.Background, color);
style.setCharacterAttributes(range.getStart(), range.getLength(), s, true);
}
}, tree);
refresh();
} catch (IOException | URISyntaxException e) {
log.warn("Error reading: " + e);
}
@ -84,8 +73,13 @@ public class LiveDataParserPanel {
}
@NotNull
public static ParseTree getParseTree(String sourceCode) throws IOException {
CharStream in = new ANTLRInputStream(new ByteArrayInputStream(sourceCode.getBytes()));
public static ParseTree getParseTree(String sourceCode) {
CharStream in;
try {
in = new ANTLRInputStream(new ByteArrayInputStream(sourceCode.getBytes()));
} catch (IOException e) {
throw new IllegalStateException(e);
}
CPP14Parser parser = new CPP14Parser(new CommonTokenStream(new CPP14Lexer(in)));
return parser.translationUnit();
}
@ -142,4 +136,22 @@ public class LiveDataParserPanel {
public JPanel getContent() {
return content;
}
public void refresh() {
ParseTree tree = getParseTree(sourceCode);
StyleContext sc = StyleContext.getDefaultStyleContext();
StyledDocument styledDocument = text.getStyledDocument();
AttributeSet oldSet = styledDocument.getCharacterElement(0).getAttributes();
styledDocument.setCharacterAttributes(0, sourceCode.length(), sc.getEmptySet(), true);
applyVariables(valueSource, sourceCode, new SourceCodePainter() {
@Override
public void paint(Color color, Range range) {
AttributeSet s = sc.addAttribute(oldSet, StyleConstants.Background, color);
styledDocument.setCharacterAttributes(range.getStart(), range.getLength(), s, true);
}
}, tree);
}
}

View File

@ -4,10 +4,19 @@ import com.opensr5.ConfigurationImage;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.Field;
import com.rusefi.config.generated.AcControl;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.enums.live_data_e;
import com.rusefi.livedata.LiveDataParserPanel;
import com.rusefi.ui.config.ConfigField;
import com.rusefi.ui.livedata.VariableValueSource;
import com.rusefi.ui.livedocs.LiveDocHolder;
import com.rusefi.ui.livedocs.LiveDocsRegistry;
import com.rusefi.ui.livedocs.RefreshActions;
import com.rusefi.ui.livedocs.RefreshActionsMap;
import com.rusefi.ui.util.UiUtils;
import com.rusefi.ui.widgets.IntGaugeLabel;
import org.jetbrains.annotations.NotNull;
@ -21,6 +30,7 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.concurrent.atomic.AtomicReference;
/**
@ -42,7 +52,41 @@ public class FormulasPane {
public FormulasPane(UIContext uiContext) {
this.uiContext = uiContext;
AtomicReference<byte[]> reference = new AtomicReference<>();
JPanel vertical = new JPanel(new VerticalFlowLayout());
LiveDataParserPanel livePanel = new LiveDataParserPanel(new VariableValueSource() {
@Override
public Object getValue(String name) {
byte[] bytes = reference.get();
if (bytes == null)
return null;
Field f = Field.findField(AcControl.VALUES, "", name);
int number = f.getValue(new ConfigurationImage(bytes)).intValue();
System.out.println("getValue");
return number != 0;
}
});
RefreshActionsMap refreshActionsMap = new RefreshActionsMap();
refreshActionsMap.put(live_data_e.LDS_AC_CONTROL, new RefreshActions() {
@Override
public void refresh(BinaryProtocol bp, byte[] response) {
reference.set(response);
livePanel.refresh();
}
});
LiveDocsRegistry.INSTANCE.register(new LiveDocHolder(live_data_e.LDS_AC_CONTROL, refreshActionsMap) {
@Override
public boolean isVisible() {
JPanel panel = livePanel.getContent();
boolean isVisible = !panel.getVisibleRect().isEmpty();
return isVisible && isRecursivelyVisible(panel);
}
});
vertical.add(livePanel.getContent());
vertical.add(formulaProxy);
JScrollPane scroll = new JScrollPane(vertical, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
@ -274,4 +318,9 @@ public class FormulasPane {
public JPanel getContent() {
return content;
}
static boolean isRecursivelyVisible(Container c) {
Container parent = c.getParent();
return c.isVisible() && (parent == null || isRecursivelyVisible(parent));
}
}

View File

@ -55,6 +55,8 @@ public class EnumConfigField extends BaseConfigField {
if (ec)
return;
String value = (String) view.getSelectedItem();
if (value == null)
throw new NullPointerException(field.getName());
int ordinal = ordinals.get(value);
sendValue(field, Integer.toString(ordinal));
}