live data progress
This commit is contained in:
parent
f7e3f97928
commit
4611e3acbc
|
@ -29,6 +29,7 @@ public class CodeWalkthrough {
|
|||
public static final Color BROKEN_CODE = Color.orange;
|
||||
public static final Color TRUE_CONDITION = Color.GREEN;
|
||||
public static final Color FALSE_CONDITION = Color.RED;
|
||||
public static final Color CONFIG = Color.BLUE;
|
||||
|
||||
static {
|
||||
log.configureDebugEnabled(false);
|
||||
|
@ -76,7 +77,11 @@ public class CodeWalkthrough {
|
|||
@Override
|
||||
public void visitTerminal(TerminalNode node) {
|
||||
allTerminals.add(node);
|
||||
if ("else".equalsIgnoreCase(node.getSymbol().getText())) {
|
||||
|
||||
String text = node.getSymbol().getText();
|
||||
valueSource.getValue(text);
|
||||
|
||||
if ("else".equalsIgnoreCase(text)) {
|
||||
if (log.debugEnabled())
|
||||
log.debug("CONDITIONAL ELSE terminal, flipping condition");
|
||||
|
||||
|
@ -98,8 +103,14 @@ public class CodeWalkthrough {
|
|||
if (currentState.isEmpty()) {
|
||||
painter.paintBackground(PASSIVE_CODE, new Range(ctx));
|
||||
} else {
|
||||
Boolean state = (Boolean) valueSource.getValue(conditionVariable);
|
||||
BranchingState branchingState = BranchingState.valueOf(state);
|
||||
VariableValueSource.VariableState state = valueSource.getValue(conditionVariable);
|
||||
Boolean value;
|
||||
if (state == null) {
|
||||
value = null;
|
||||
} else {
|
||||
value = state.getValue() != 0;
|
||||
}
|
||||
BranchingState branchingState = BranchingState.valueOf(value);
|
||||
if (log.debugEnabled())
|
||||
log.debug("CURRENT STATE ADD " + state);
|
||||
currentState.add(branchingState);
|
||||
|
@ -154,7 +165,7 @@ public class CodeWalkthrough {
|
|||
allTerminals.get(i + 1).getText().equals("->")
|
||||
) {
|
||||
Token token = allTerminals.get(i + 2).getSymbol();
|
||||
painter.paintForeground(Color.BLUE, new Range(token, token));
|
||||
painter.paintForeground(CONFIG, new Range(token, token));
|
||||
configTokens.add(token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,24 +170,21 @@ public class LiveDataParserPanel {
|
|||
private static LiveDataParserPanel createLiveDataParserPanel(UIContext uiContext, final live_data_e live_data_e, final Field[] values, String fileName) {
|
||||
AtomicReference<byte[]> reference = new AtomicReference<>();
|
||||
|
||||
LiveDataParserPanel livePanel = new LiveDataParserPanel(uiContext, new VariableValueSource() {
|
||||
@Override
|
||||
public Object getValue(String name) {
|
||||
byte[] bytes = reference.get();
|
||||
if (bytes == null)
|
||||
return null;
|
||||
Field f = Field.findFieldOrNull(values, "", name);
|
||||
if (f == null) {
|
||||
log.error("BAD condition, should be variable: " + name);
|
||||
return null;
|
||||
}
|
||||
int number = f.getValue(new ConfigurationImage(bytes)).intValue();
|
||||
if (log.debugEnabled()) {
|
||||
log.debug("getValue(" + name + "): " + number);
|
||||
}
|
||||
// convert Number to Boolean
|
||||
return number != 0;
|
||||
LiveDataParserPanel livePanel = new LiveDataParserPanel(uiContext, name -> {
|
||||
byte[] bytes = reference.get();
|
||||
if (bytes == null)
|
||||
return null;
|
||||
Field f = Field.findFieldOrNull(values, "", name);
|
||||
if (f == null) {
|
||||
//log.error("BAD condition, should be variable: " + name);
|
||||
return null;
|
||||
}
|
||||
double number = f.getValue(new ConfigurationImage(bytes)).doubleValue();
|
||||
if (log.debugEnabled()) {
|
||||
log.debug("getValue(" + name + "): " + number);
|
||||
}
|
||||
// convert Number to Boolean
|
||||
return new VariableValueSource.VariableState(f, number);
|
||||
}, fileName);
|
||||
RefreshActions refreshAction = new RefreshActions() {
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
package com.rusefi.ui.livedata;
|
||||
|
||||
import com.rusefi.config.Field;
|
||||
|
||||
public interface VariableValueSource {
|
||||
VariableValueSource VOID = name -> null;
|
||||
|
||||
Object getValue(String name);
|
||||
VariableState getValue(String name);
|
||||
|
||||
class VariableState {
|
||||
private final Field field;
|
||||
private final double value;
|
||||
|
||||
public VariableState(Field field, double value) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class LiveDataConventionTest {
|
|||
return null;
|
||||
}
|
||||
System.out.println("getValue");
|
||||
return true;
|
||||
return new VariableValueSource.VariableState(null, 0);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.rusefi.livedata;
|
||||
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.config.FieldType;
|
||||
import com.rusefi.ui.UIContext;
|
||||
import com.rusefi.ui.livedata.VariableValueSource;
|
||||
import com.rusefi.ui.util.FrameHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Map;
|
||||
|
@ -13,12 +16,23 @@ import java.util.TreeMap;
|
|||
*/
|
||||
public class LiveDataParserSandbox {
|
||||
public static void main(String[] args) {
|
||||
Map<String, Object> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
values.put("engineTooSlow", Boolean.TRUE);
|
||||
values.put("engineTooFast", Boolean.FALSE);
|
||||
Map<String, Double> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
values.put("engineTooSlow", 1.0);
|
||||
values.put("engineTooFast", 0.0);
|
||||
|
||||
VariableValueSource valueSource = values::get;
|
||||
VariableValueSource valueSource = getVariableValueSource(values);
|
||||
|
||||
new FrameHelper(JDialog.EXIT_ON_CLOSE).showFrame(new LiveDataParserPanel(new UIContext(), valueSource, "ac_control.cpp").getContent());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VariableValueSource getVariableValueSource(Map<String, Double> values) {
|
||||
VariableValueSource valueSource = name -> {
|
||||
Double value = values.get(name);
|
||||
if (value == null)
|
||||
return null;
|
||||
return new VariableValueSource.VariableState(new Field(name, 0, FieldType.BIT), value);
|
||||
};
|
||||
return valueSource;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,18 +2,19 @@ package com.rusefi.ui.livedata;
|
|||
|
||||
import com.rusefi.CodeWalkthrough;
|
||||
import com.rusefi.livedata.LiveDataParserPanel;
|
||||
import com.rusefi.livedata.LiveDataParserSandbox;
|
||||
import com.rusefi.livedata.LiveDataView;
|
||||
import com.rusefi.livedata.ParseResult;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static com.rusefi.CodeWalkthrough.TRUE_CONDITION;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -41,11 +42,11 @@ public class LiveDataParserTest {
|
|||
|
||||
@Test
|
||||
public void testParsing() {
|
||||
Map<String, Object> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
values.put("engineTooSlow", Boolean.TRUE);
|
||||
values.put("engineTooFast", Boolean.FALSE);
|
||||
Map<String, Double> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
values.put("engineTooSlow", 1.0);
|
||||
values.put("engineTooFast", 1.0);
|
||||
|
||||
VariableValueSource valueSource = values::get;
|
||||
VariableValueSource valueSource = LiveDataParserSandbox.getVariableValueSource(values);
|
||||
|
||||
String sourceCode = "bool AcState::getAcState() {\n" +
|
||||
"\tauto rpm = Sensor::getOrZero(SensorType::Rpm);\n" +
|
||||
|
@ -68,13 +69,12 @@ public class LiveDataParserTest {
|
|||
|
||||
SourceCodePainter painter = run(valueSource, sourceCode);
|
||||
|
||||
verify(painter, times(2)).paintForeground(eq(Color.blue), any());
|
||||
verify(painter, times(2)).paintForeground(eq(CodeWalkthrough.CONFIG), any());
|
||||
|
||||
verify(painter).paintBackground(eq(Color.red), any());
|
||||
verify(painter).paintBackground(eq(Color.green), any());
|
||||
verify(painter).paintBackground(eq(TRUE_CONDITION), any());
|
||||
|
||||
verify(painter, times(4)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any());
|
||||
verify(painter, times(4)).paintBackground(eq(CodeWalkthrough.PASSIVE_CODE), any());
|
||||
verify(painter, times(5)).paintBackground(eq(CodeWalkthrough.PASSIVE_CODE), any());
|
||||
}
|
||||
|
||||
private SourceCodePainter run(VariableValueSource valueSource, String sourceCode) {
|
||||
|
|
Loading…
Reference in New Issue