From 1ca407f3912ee557f7d10e7ff668b0727fce7657 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 31 Oct 2021 12:09:45 -0400 Subject: [PATCH] Whatever we call it, no matter how we do it - we need live data / remote view into rusEFI actual state #3353 better handling of bad conditions --- .../rusefi/livedata/LiveDataParserPanel.java | 21 +++++++++++++++---- .../java/com/rusefi/livedata/ParseResult.java | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java b/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java index 6fd8a78eed..c6e112a0a7 100644 --- a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java +++ b/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java @@ -40,8 +40,13 @@ import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; * this panel shows a live view of rusEFI firmware C/C++ code */ public class LiveDataParserPanel { + private static final String CONFIG_MAGIC_PREFIX = "CONFIG"; private static final Logging log = getLogging(LiveDataParserPanel.class); + { +// log.configureDebugEnabled(true); + } + private final JPanel content = new JPanel(new BorderLayout()); private ParseResult parseResult = ParseResult.VOID; private final UIContext uiContext; @@ -181,7 +186,7 @@ public class LiveDataParserPanel { for (int i = 0; i < allTerminals.size() - 3; i++) { - if (allTerminals.get(i).getText().equals("CONFIG") && + if (allTerminals.get(i).getText().equals(CONFIG_MAGIC_PREFIX) && allTerminals.get(i + 1).getText().equals("(") && allTerminals.get(i + 3).getText().equals(")") ) { @@ -236,7 +241,7 @@ public class LiveDataParserPanel { } @NotNull - public 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 reference = new AtomicReference<>(); LiveDataParserPanel livePanel = new LiveDataParserPanel(uiContext, new VariableValueSource() { @@ -245,9 +250,15 @@ public class LiveDataParserPanel { byte[] bytes = reference.get(); if (bytes == null) return null; - Field f = Field.findField(values, "", name); + 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(); -// System.out.println("getValue " + f); + if (log.debugEnabled()) { + log.debug("getValue(" + name + "): " + number); + } // convert Number to Boolean return number != 0; } @@ -256,6 +267,8 @@ public class LiveDataParserPanel { refreshActionsMap.put(live_data_e, new RefreshActions() { @Override public void refresh(BinaryProtocol bp, byte[] response) { + if (log.debugEnabled()) + log.debug("Got data " + response.length + " bytes"); reference.set(response); livePanel.refresh(); } diff --git a/java_console/ui/src/main/java/com/rusefi/livedata/ParseResult.java b/java_console/ui/src/main/java/com/rusefi/livedata/ParseResult.java index 0ed0fbe635..ec218271e6 100644 --- a/java_console/ui/src/main/java/com/rusefi/livedata/ParseResult.java +++ b/java_console/ui/src/main/java/com/rusefi/livedata/ParseResult.java @@ -8,7 +8,7 @@ import java.util.List; public class ParseResult { static ParseResult VOID = new ParseResult(Collections.emptyList()); - private List configTokens; + private final List configTokens; public ParseResult(List configTokens) { this.configTokens = configTokens;