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 18:43:26 -04:00
parent 37db1559df
commit a5f5ec4029
7 changed files with 37 additions and 101 deletions

View File

@ -4,7 +4,7 @@ echo "This batch files reads rusefi_enums.h and produces auto_generated_enums.*
rm gen_enum_to_string.log
java -DSystemOut.name=gen_java_enum -cp ../java_tools/enum2string.jar com.rusefi.ToJavaEnum -enumInputFile controllers/algo/live_data_ids.h -outputPath ../java_console/ui/src/main/java/com/rusefi/enums
java -DSystemOut.name=gen_java_enum -cp ../java_tools/enum2string.jar com.rusefi.ToJavaEnum -enumInputFile controllers/algo/live_data_ids.h -outputPath ../java_console/io/src/main/java/com/rusefi/enums
java -DSystemOut.name=gen_enum_to_string \
-jar ../java_tools/enum2string.jar \

View File

@ -1,72 +1,45 @@
package com.rusefi.ldmp;
import com.rusefi.config.Field;
import com.rusefi.config.generated.*;
import com.rusefi.ui.livedocs.LiveDataContext;
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.enums.live_data_e;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public enum StateDictionary {
INSTANCE;
public static final int NONE = -1;
private Map<Integer, Field[]> map = new HashMap<>();
private Map<live_data_e, Field[]> map = new HashMap<>();
StateDictionary() {
register(Fields.LDS_SPEED_DENSITY_STATE_INDEX, EngineState.VALUES); // 2
register(Fields.LDS_ENGINE_STATE_INDEX, EngineState.VALUES); // 3
register(Fields.LDS_FUEL_TRIM_STATE_INDEX, EngineState.VALUES);
register(Fields.LDS_TPS_TPS_ENRICHMENT_STATE_INDEX, EngineState.VALUES); // 5
register(Fields.LDS_TRIGGER_CENTRAL_STATE_INDEX, TriggerCentral.VALUES);
register(Fields.LDS_ETB_PID_STATE_INDEX, PidState.VALUES); // 7
register(Fields.LDS_IDLE_PID_STATE_INDEX, PidState.VALUES);
// LDS_ALTERNATOR_PID_STATE_INDEX
// LDS_CJ125_PID_STATE_INDEX
register(Fields.LDS_TRIGGER_STATE_STATE_INDEX, TriggerState.VALUES); // 11
register(live_data_e.LDS_SPEED_DENSITY, EngineState.VALUES); // 2
register(live_data_e.LDS_ENGINE, EngineState.VALUES); // 3
register(live_data_e.LDS_FUEL_TRIM, EngineState.VALUES);
register(live_data_e.LDS_TPS_TPS_ENRICHMENT, EngineState.VALUES); // 5
register(live_data_e.LDS_TRIGGER_CENTRAL, TriggerCentral.VALUES);
register(live_data_e.LDS_ETB_PID, PidState.VALUES); // 7
register(live_data_e.LDS_IDLE_PID, PidState.VALUES);
// LDS_ALTERNATOR_PID
// LDS_CJ125_PID
register(live_data_e.LDS_TRIGGER_STATE, TriggerState.VALUES); // 11
}
private void register(int ldsIndex, Field[] values) {
private void register(live_data_e ldsIndex, Field[] values) {
map.put(ldsIndex, values);
}
public Field[] getValue(String state) {
String indexFieldName = getContextIndexFieldName(state);
LiveDataContext indexValue = getStateContext(indexFieldName);
return getFields(indexFieldName, indexValue);
}
@NotNull
public Field[] getFields(String indexFieldName, LiveDataContext indexValue) {
Field[] result = map.get(indexValue.getId());
public Field[] getFields(live_data_e indexFieldName) {
Field[] result = map.get(indexFieldName);
if (result == null) {
throw new IllegalStateException("Nothing for " + indexFieldName + "/" + indexValue);
throw new IllegalStateException("Nothing for " + indexFieldName);
}
return result;
}
@NotNull
public static String getContextIndexFieldName(String state) {
return "LDS_" + state.toUpperCase() + "_STATE_INDEX";
}
public static LiveDataContext getStateContext(String contextIndexFieldName) {
java.lang.reflect.Field field;
try {
field = Fields.class.getField(contextIndexFieldName);
} catch (NoSuchFieldException e) {
throw new IllegalStateException(e);
}
Objects.requireNonNull(field, "Field " + contextIndexFieldName);
int indexValue;
try {
indexValue = (int) field.get(null);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
return new LiveDataContext(indexValue);
}
}

View File

@ -1,40 +0,0 @@
package com.rusefi.ui.livedocs;
import java.util.Objects;
/**
* Type-safe unique structure identifier
* <p>
* Andrey Belomutskiy, (c) 2013-2020
*/
public class LiveDataContext {
private final int id;
public LiveDataContext(int id) {
this.id = id;
}
public int getId() {
return id;
}
@Override
public String toString() {
return "LiveDataContext{" +
"id=" + id +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LiveDataContext stateId = (LiveDataContext) o;
return id == stateId.id;
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}

View File

@ -1,15 +1,16 @@
package com.rusefi.ui.livedocs;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.enums.live_data_e;
/**
* Andrey Belomutskiy, (c) 2013-2020
*/
public abstract class LiveDocHolder {
private final LiveDataContext id;
private final live_data_e id;
private final RefreshActionsMap actions;
public LiveDocHolder(LiveDataContext id, RefreshActionsMap actions) {
public LiveDocHolder(live_data_e id, RefreshActionsMap actions) {
this.id = id;
this.actions = actions;
}
@ -18,14 +19,14 @@ public abstract class LiveDocHolder {
return actions;
}
public void update(BinaryProtocol binaryProtocol, LiveDataContext context, byte[] response) {
public void update(BinaryProtocol binaryProtocol, live_data_e context, byte[] response) {
for (RefreshActions action : actions.getActions().get(context))
action.refresh(binaryProtocol, response);
}
public abstract boolean isVisible();
public LiveDataContext getId() {
public live_data_e getId() {
return id;
}

View File

@ -3,6 +3,7 @@ package com.rusefi.ui.livedocs;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.Field;
import com.rusefi.config.generated.Fields;
import com.rusefi.enums.live_data_e;
import com.rusefi.ldmp.StateDictionary;
import java.util.ArrayList;
@ -28,21 +29,20 @@ public enum LiveDocsRegistry {
for (LiveDocHolder holder : liveDocs) {
boolean visible = holder.isVisible();
if (visible) {
for (LiveDataContext context : holder.getActions().getActions().keySet()) {
for (live_data_e context : holder.getActions().getActions().keySet()) {
refresh(binaryProtocol, holder, context);
}
}
}
}
private void refresh(BinaryProtocol binaryProtocol, LiveDocHolder holder, LiveDataContext context) {
int liveDocRequestId = context.getId();
Field[] values = StateDictionary.INSTANCE.getFields("refresh", context);
private void refresh(BinaryProtocol binaryProtocol, LiveDocHolder holder, live_data_e 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(liveDocRequestId)); // offset
putShort(packet, 1, swap16(context.ordinal())); // offset
putShort(packet, 3, swap16(size));
byte[] responseWithCode = binaryProtocol.executeCommand(packet, "get LiveDoc");

View File

@ -1,26 +1,28 @@
package com.rusefi.ui.livedocs;
import com.rusefi.enums.live_data_e;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RefreshActionsMap {
private final Map<LiveDataContext, List<RefreshActions>> actions = new HashMap<>();
private final Map<live_data_e, List<RefreshActions>> actions = new HashMap<>();
public void put(LiveDataContext context, RefreshActions refreshAction) {
public void put(live_data_e context, RefreshActions refreshAction) {
actions.putIfAbsent(context, new ArrayList<>());
actions.get(context).add(refreshAction);
}
public void addAll(RefreshActionsMap actions) {
for (Map.Entry<LiveDataContext, List<RefreshActions>> e : actions.actions.entrySet()) {
for (Map.Entry<live_data_e, List<RefreshActions>> e : actions.actions.entrySet()) {
for (RefreshActions action : e.getValue())
put(e.getKey(), action);
}
}
public Map<LiveDataContext, List<RefreshActions>> getActions() {
public Map<live_data_e, List<RefreshActions>> getActions() {
return actions;
}
}