mirror of https://github.com/rusefi/rusefi-1.git
live data progress
This commit is contained in:
parent
f27b4dbd95
commit
921bc1af74
|
@ -264,7 +264,8 @@ public class BinaryProtocol {
|
||||||
String text = requestPendingMessages();
|
String text = requestPendingMessages();
|
||||||
if (text != null)
|
if (text != null)
|
||||||
listener.onDataArrived((text + "\r\n").getBytes());
|
listener.onDataArrived((text + "\r\n").getBytes());
|
||||||
LiveDocsRegistry.INSTANCE.refresh(BinaryProtocol.this);
|
LiveDocsRegistry.LiveDataProvider liveDataProvider = LiveDocsRegistry.getLiveDataProvider(BinaryProtocol.this);
|
||||||
|
LiveDocsRegistry.INSTANCE.refresh(liveDataProvider);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ public abstract class LiveDocHolder {
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(BinaryProtocol binaryProtocol, byte[] response) {
|
public void update(byte[] response) {
|
||||||
action.refresh(binaryProtocol, response);
|
action.refresh(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isVisible();
|
public abstract boolean isVisible();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.config.Field;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.enums.live_data_e;
|
import com.rusefi.enums.live_data_e;
|
||||||
import com.rusefi.ldmp.StateDictionary;
|
import com.rusefi.ldmp.StateDictionary;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -25,33 +26,48 @@ public enum LiveDocsRegistry {
|
||||||
liveDocs.add(holder);
|
liveDocs.add(holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(BinaryProtocol binaryProtocol) {
|
public void refresh(LiveDataProvider liveDataProvider) {
|
||||||
for (LiveDocHolder holder : liveDocs) {
|
for (LiveDocHolder holder : liveDocs) {
|
||||||
boolean visible = holder.isVisible();
|
boolean visible = holder.isVisible();
|
||||||
if (visible) {
|
if (visible) {
|
||||||
live_data_e context = holder.getId();
|
live_data_e context = holder.getId();
|
||||||
refresh(binaryProtocol, holder, context);
|
refresh(holder, context, liveDataProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(BinaryProtocol binaryProtocol, LiveDocHolder holder, live_data_e context) {
|
private void refresh(LiveDocHolder holder, live_data_e context, LiveDataProvider liveDataProvider) {
|
||||||
Field[] values = StateDictionary.INSTANCE.getFields(context);
|
|
||||||
int size = Field.getStructureSize(values);
|
|
||||||
|
|
||||||
byte[] packet = new byte[5];
|
byte[] response = liveDataProvider.provide(context);
|
||||||
packet[0] = Fields.TS_GET_STRUCT;
|
if (response == null)
|
||||||
putShort(packet, 1, swap16(context.ordinal())); // offset
|
|
||||||
putShort(packet, 3, swap16(size));
|
|
||||||
|
|
||||||
byte[] responseWithCode = binaryProtocol.executeCommand(packet, "get LiveDoc");
|
|
||||||
if (responseWithCode == null || responseWithCode.length != (size + 1) || responseWithCode[0] != Fields.TS_RESPONSE_OK)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
byte[] response = new byte[size];
|
holder.update(response);
|
||||||
|
|
||||||
System.arraycopy(responseWithCode, 1, response, 0, size);
|
|
||||||
|
|
||||||
holder.update(binaryProtocol, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static LiveDataProvider getLiveDataProvider(BinaryProtocol binaryProtocol) {
|
||||||
|
return context -> {
|
||||||
|
Field[] values = StateDictionary.INSTANCE.getFields(context);
|
||||||
|
int size = Field.getStructureSize(values);
|
||||||
|
byte[] packet = new byte[5];
|
||||||
|
packet[0] = Fields.TS_GET_STRUCT;
|
||||||
|
putShort(packet, 1, swap16(context.ordinal())); // offset
|
||||||
|
putShort(packet, 3, swap16(size));
|
||||||
|
|
||||||
|
byte[] responseWithCode = binaryProtocol.executeCommand(packet, "get LiveDoc");
|
||||||
|
if (responseWithCode == null || responseWithCode.length != (size + 1) || responseWithCode[0] != Fields.TS_RESPONSE_OK)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
byte[] response = new byte[size];
|
||||||
|
|
||||||
|
System.arraycopy(responseWithCode, 1, response, 0, size);
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface LiveDataProvider {
|
||||||
|
byte[] provide(live_data_e context);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.rusefi.ui.livedocs;
|
package com.rusefi.ui.livedocs;
|
||||||
|
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
|
||||||
|
|
||||||
public abstract class RefreshActions {
|
public abstract class RefreshActions {
|
||||||
public abstract void refresh(BinaryProtocol bp, byte[] response);
|
public abstract void refresh(byte[] response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this panel shows a live view of rusEFI firmware C/C++ code
|
* this panel shows a live view of rusEFI firmware C/C++ code
|
||||||
|
* @see LiveDataParserPanelSandbox
|
||||||
*/
|
*/
|
||||||
public class LiveDataParserPanel {
|
public class LiveDataParserPanel {
|
||||||
private static final String CONFIG_MAGIC_PREFIX = "engineConfiguration";
|
private static final String CONFIG_MAGIC_PREFIX = "engineConfiguration";
|
||||||
|
@ -263,7 +264,7 @@ public class LiveDataParserPanel {
|
||||||
}, fileName);
|
}, fileName);
|
||||||
RefreshActions refreshAction = new RefreshActions() {
|
RefreshActions refreshAction = new RefreshActions() {
|
||||||
@Override
|
@Override
|
||||||
public void refresh(BinaryProtocol bp, byte[] response) {
|
public void refresh(byte[] response) {
|
||||||
if (log.debugEnabled())
|
if (log.debugEnabled())
|
||||||
log.debug("Got data " + response.length + " bytes");
|
log.debug("Got data " + response.length + " bytes");
|
||||||
reference.set(response);
|
reference.set(response);
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.rusefi.livedata;
|
||||||
|
|
||||||
|
import com.rusefi.enums.live_data_e;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
|
import com.rusefi.ui.livedocs.LiveDocsRegistry;
|
||||||
|
import com.rusefi.ui.util.FrameHelper;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class LiveDataParserPanelSandbox {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
UIContext context = new UIContext();
|
||||||
|
|
||||||
|
JPanel panel = LiveDataParserPanel.createLiveDataParserContent(context,
|
||||||
|
LiveDataView.BOOST_CONTROL);
|
||||||
|
|
||||||
|
LiveDocsRegistry.INSTANCE.refresh(new LiveDocsRegistry.LiveDataProvider() {
|
||||||
|
@Override
|
||||||
|
public byte[] provide(live_data_e context) {
|
||||||
|
System.out.println("provide");
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
new FrameHelper().showFrame(panel);
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import java.net.URISyntaxException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
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;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -63,6 +64,6 @@ public class LiveDataParserTest {
|
||||||
|
|
||||||
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
|
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
|
||||||
ParseResult parseResult = LiveDataParserPanel.applyVariables(VariableValueSource.VOID, sourceCode, SourceCodePainter.VOID, tree);
|
ParseResult parseResult = LiveDataParserPanel.applyVariables(VariableValueSource.VOID, sourceCode, SourceCodePainter.VOID, tree);
|
||||||
assertTrue(!parseResult.getConfigTokens().isEmpty());
|
assertFalse(parseResult.getConfigTokens().isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue