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