Whatever we call it, whatever we implement it - we need live data / remote view into rusEFI actual state #3353
progress
This commit is contained in:
parent
9c42b38297
commit
37db1559df
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
* @file live_data_ids.h
|
||||||
|
*
|
||||||
|
* Live Documentation Structure
|
||||||
|
* these indexes are used by custom protocol command TS_GET_STRUCT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LDS_SPEED_DENSITY,
|
||||||
|
LDS_ENGINE,
|
||||||
|
LDS_FUEL_TRIM,
|
||||||
|
LDS_TPS_TPS_ENRICHMENT,
|
||||||
|
LDS_TRIGGER_CENTRAL,
|
||||||
|
LDS_ETB_PID,
|
||||||
|
LDS_IDLE_PID,
|
||||||
|
LDS_ALTERNATOR_PID,
|
||||||
|
LDS_CJ125_PID,
|
||||||
|
LDS_TRIGGER_STATE,
|
||||||
|
LDS_AC_CONTROL
|
||||||
|
} live_data_e;
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "efifeatures.h"
|
#include "efifeatures.h"
|
||||||
#include "obd_error_codes.h"
|
#include "obd_error_codes.h"
|
||||||
|
#include "live_data_ids.h"
|
||||||
#include "rusefi_generated.h"
|
#include "rusefi_generated.h"
|
||||||
// we do not want to start the search for header from current folder so we use brackets here
|
// we do not want to start the search for header from current folder so we use brackets here
|
||||||
// https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename
|
// https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename
|
||||||
|
|
|
@ -4,6 +4,8 @@ echo "This batch files reads rusefi_enums.h and produces auto_generated_enums.*
|
||||||
|
|
||||||
rm gen_enum_to_string.log
|
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_enum_to_string \
|
java -DSystemOut.name=gen_enum_to_string \
|
||||||
-jar ../java_tools/enum2string.jar \
|
-jar ../java_tools/enum2string.jar \
|
||||||
-outputPath controllers/algo \
|
-outputPath controllers/algo \
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.rusefi.enums;
|
||||||
|
//auto-generated by ToJavaEnum.java
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public enum live_data_e {
|
||||||
|
LDS_SPEED_DENSITY,
|
||||||
|
LDS_ENGINE,
|
||||||
|
LDS_FUEL_TRIM,
|
||||||
|
LDS_TPS_TPS_ENRICHMENT,
|
||||||
|
LDS_TRIGGER_CENTRAL,
|
||||||
|
LDS_ETB_PID,
|
||||||
|
LDS_IDLE_PID,
|
||||||
|
LDS_ALTERNATOR_PID,
|
||||||
|
LDS_CJ125_PID,
|
||||||
|
LDS_TRIGGER_STATE,
|
||||||
|
LDS_AC_CONTROL,
|
||||||
|
}
|
Binary file not shown.
|
@ -26,37 +26,17 @@ public class EnumToString {
|
||||||
|
|
||||||
private final static StringBuilder headerFileContent = new StringBuilder();
|
private final static StringBuilder headerFileContent = new StringBuilder();
|
||||||
|
|
||||||
private final static String KEY_INPUT_PATH = "-enumInputPath";
|
|
||||||
public final static String KEY_ENUM_INPUT_FILE = "-enumInputFile";
|
public final static String KEY_ENUM_INPUT_FILE = "-enumInputFile";
|
||||||
private final static String KEY_OUTPUT = "-outputPath";
|
|
||||||
private final static String KEY_OUTPUT_FILE = "-generatedFile";
|
|
||||||
private static String fileSuffix = "enums";
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
if (args.length < 4) {
|
InvokeReader invokeReader = new InvokeReader(args).invoke();
|
||||||
SystemOut.println("Please specify at least\n\n" +
|
String outputPath = invokeReader.getOutputPath();
|
||||||
KEY_ENUM_INPUT_FILE + "XXX\n" +
|
|
||||||
KEY_OUTPUT + "XXX\n"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String inputPath = ".";
|
|
||||||
String outputPath = null;
|
|
||||||
EnumsReader enumsReader = new EnumsReader();
|
EnumsReader enumsReader = new EnumsReader();
|
||||||
EnumToString state = new EnumToString();
|
EnumToString state = new EnumToString();
|
||||||
for (int i = 0; i < args.length - 1; i += 2) {
|
|
||||||
String key = args[i];
|
for (String inputFile : invokeReader.getInputFiles()) {
|
||||||
if (key.equals(KEY_INPUT_PATH)) {
|
state.consumeFile(enumsReader, invokeReader.getInputPath(), inputFile);
|
||||||
inputPath = Objects.requireNonNull(args[i + 1], KEY_INPUT_PATH);
|
|
||||||
} else if (key.equals(KEY_ENUM_INPUT_FILE)) {
|
|
||||||
String headerInputFile = args[i + 1];
|
|
||||||
state.consumeFile(enumsReader, inputPath, headerInputFile);
|
|
||||||
} else if (key.equals(KEY_OUTPUT_FILE)) {
|
|
||||||
fileSuffix = args[i + 1];
|
|
||||||
} else if (key.equals(KEY_OUTPUT)) {
|
|
||||||
outputPath = args[i + 1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
headerFileContent.append("#pragma once\n");
|
headerFileContent.append("#pragma once\n");
|
||||||
|
@ -75,7 +55,7 @@ public class EnumToString {
|
||||||
|
|
||||||
new File(outputPath).mkdirs();
|
new File(outputPath).mkdirs();
|
||||||
state.writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_" +
|
state.writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_" +
|
||||||
fileSuffix);
|
InvokeReader.fileSuffix);
|
||||||
SystemOut.close();
|
SystemOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,15 +69,14 @@ public class EnumToString {
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void consumeFile(EnumsReader enumsReader, String inputPath, String headerInputFileName) throws IOException {
|
public void consumeFile(EnumsReader enumsReader, String inputPath, String headerInputFileName) throws IOException {
|
||||||
Objects.requireNonNull(inputPath, "inputPath");
|
Objects.requireNonNull(inputPath, "inputPath");
|
||||||
File f = new File(inputPath + File.separator + headerInputFileName);
|
File f = new File(inputPath + File.separator + headerInputFileName);
|
||||||
SystemOut.println("Reading enums from " + headerInputFileName);
|
SystemOut.println("Reading enums from " + headerInputFileName);
|
||||||
String simpleFileName = f.getName();
|
|
||||||
|
|
||||||
bothFilesHeader.insert(0, "// " + LazyFile.LAZY_FILE_TAG + " from " + simpleFileName + " ");
|
bothFilesHeader.insert(0, "// " + LazyFile.LAZY_FILE_TAG + " from " + f.getName() + " ");
|
||||||
|
|
||||||
includesSection.append("#include \"" + simpleFileName + "\"\n");
|
includesSection.append("#include \"" + f.getName() + "\"\n");
|
||||||
enumsReader.read(new FileReader(f));
|
enumsReader.read(new FileReader(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,4 +121,5 @@ public class EnumToString {
|
||||||
public String getCppFileContent() {
|
public String getCppFileContent() {
|
||||||
return cppFileContent.toString();
|
return cppFileContent.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,23 @@ package com.rusefi;
|
||||||
import com.rusefi.enum_reader.Value;
|
import com.rusefi.enum_reader.Value;
|
||||||
import com.rusefi.util.SystemOut;
|
import com.rusefi.util.SystemOut;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public class EnumsReader {
|
public class EnumsReader {
|
||||||
private final Map<String, Value> currentValues = new TreeMap<>();
|
private final Map<String, Value> currentValues = new TreeMap<>();
|
||||||
|
|
||||||
private final Map<String, Map<String, Value>> enums = new TreeMap<>();
|
private final Map<String, Map<String, Value>> enums = new TreeMap<>();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
static List<Value> getSortedByOrder(Map<String, Value> brain_pin_e) {
|
||||||
|
Set<Value> byOrdinal = new TreeSet<>(Comparator.comparingInt(Value::getIntValue));
|
||||||
|
byOrdinal.addAll(brain_pin_e.values());
|
||||||
|
return new ArrayList<>(byOrdinal);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String /*enum name*/, Map<String/*enum member*/, Value>> getEnums() {
|
public Map<String /*enum name*/, Map<String/*enum member*/, Value>> getEnums() {
|
||||||
return enums;
|
return enums;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +32,9 @@ public class EnumsReader {
|
||||||
boolean isInsideEnum = false;
|
boolean isInsideEnum = false;
|
||||||
BufferedReader reader = new BufferedReader(in);
|
BufferedReader reader = new BufferedReader(in);
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
|
boolean withAutoValue = false;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
line = removeSpaces(line);
|
line = removeSpaces(line);
|
||||||
|
|
||||||
|
@ -31,11 +42,15 @@ public class EnumsReader {
|
||||||
if (line.startsWith("typedefenum{") || line.startsWith("typedefenum__attribute__")) {
|
if (line.startsWith("typedefenum{") || line.startsWith("typedefenum__attribute__")) {
|
||||||
SystemOut.println(" EnumsReader: Entering enum");
|
SystemOut.println(" EnumsReader: Entering enum");
|
||||||
currentValues.clear();
|
currentValues.clear();
|
||||||
|
withAutoValue = false;
|
||||||
isInsideEnum = true;
|
isInsideEnum = true;
|
||||||
} else if (line.startsWith("}") && line.endsWith(";")) {
|
} else if (line.startsWith("}") && line.endsWith(";")) {
|
||||||
isInsideEnum = false;
|
isInsideEnum = false;
|
||||||
line = line.substring(1, line.length() - 1);
|
line = line.substring(1, line.length() - 1);
|
||||||
SystemOut.println(" EnumsReader: Ending enum " + line + " found " + currentValues.size() + " values");
|
SystemOut.println(" EnumsReader: Ending enum " + line + " found " + currentValues.size() + " values");
|
||||||
|
if (withAutoValue)
|
||||||
|
validateValues(currentValues);
|
||||||
|
|
||||||
enums.put(line, new TreeMap<>(currentValues));
|
enums.put(line, new TreeMap<>(currentValues));
|
||||||
} else {
|
} else {
|
||||||
if (isInsideEnum) {
|
if (isInsideEnum) {
|
||||||
|
@ -46,6 +61,9 @@ public class EnumsReader {
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
value = line.substring(index + 1);
|
value = line.substring(index + 1);
|
||||||
line = line.substring(0, index);
|
line = line.substring(0, index);
|
||||||
|
} else {
|
||||||
|
value = Integer.toString(currentValues.size());
|
||||||
|
withAutoValue = true;
|
||||||
}
|
}
|
||||||
SystemOut.println(" EnumsReader: Line " + line);
|
SystemOut.println(" EnumsReader: Line " + line);
|
||||||
currentValues.put(line, new Value(line, value));
|
currentValues.put(line, new Value(line, value));
|
||||||
|
@ -58,6 +76,14 @@ public class EnumsReader {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateValues(Map<String, Value> currentValues) {
|
||||||
|
for (Map.Entry<String, Value> entry : currentValues.entrySet()) {
|
||||||
|
int v = entry.getValue().getIntValue();
|
||||||
|
if (v < 0 || v >= currentValues.size())
|
||||||
|
throw new IllegalStateException("Unexpected " + entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String removeSpaces(String line) {
|
private static String removeSpaces(String line) {
|
||||||
return line.replaceAll("\\s+", "");
|
return line.replaceAll("\\s+", "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.rusefi;
|
||||||
|
|
||||||
|
import com.rusefi.util.SystemOut;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
class InvokeReader {
|
||||||
|
private final static String KEY_INPUT_PATH = "-enumInputPath";
|
||||||
|
private final static String KEY_OUTPUT = "-outputPath";
|
||||||
|
private final static String KEY_OUTPUT_FILE = "-generatedFile";
|
||||||
|
public static String fileSuffix = "enums";
|
||||||
|
|
||||||
|
private String[] args;
|
||||||
|
private String outputPath;
|
||||||
|
private List<String> inputFiles = new ArrayList<>();
|
||||||
|
private String inputPath = ".";
|
||||||
|
|
||||||
|
public InvokeReader(String... args) {
|
||||||
|
if (args.length < 4) {
|
||||||
|
SystemOut.println("Please specify at least\n\n" +
|
||||||
|
EnumToString.KEY_ENUM_INPUT_FILE + "XXX\n" +
|
||||||
|
KEY_OUTPUT + "XXX\n"
|
||||||
|
);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInputPath() {
|
||||||
|
return inputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOutputPath() {
|
||||||
|
return outputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getInputFiles() {
|
||||||
|
return inputFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvokeReader invoke() throws IOException {
|
||||||
|
outputPath = null;
|
||||||
|
for (int i = 0; i < args.length - 1; i += 2) {
|
||||||
|
String key = args[i];
|
||||||
|
if (key.equals(KEY_INPUT_PATH)) {
|
||||||
|
inputPath = Objects.requireNonNull(args[i + 1], KEY_INPUT_PATH);
|
||||||
|
} else if (key.equals(EnumToString.KEY_ENUM_INPUT_FILE)) {
|
||||||
|
String headerInputFile = args[i + 1];
|
||||||
|
inputFiles.add(headerInputFile);
|
||||||
|
} else if (key.equals(KEY_OUTPUT_FILE)) {
|
||||||
|
fileSuffix = args[i + 1];
|
||||||
|
} else if (key.equals(KEY_OUTPUT)) {
|
||||||
|
outputPath = args[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.rusefi;
|
||||||
|
|
||||||
|
import com.rusefi.enum_reader.Value;
|
||||||
|
import com.rusefi.util.SystemOut;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ToJavaEnum {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
InvokeReader invokeReader = new InvokeReader(args).invoke();
|
||||||
|
String outputPath = invokeReader.getOutputPath();
|
||||||
|
|
||||||
|
EnumsReader enumsReader = new EnumsReader();
|
||||||
|
|
||||||
|
for (String inputFile : invokeReader.getInputFiles()) {
|
||||||
|
File f = new File(invokeReader.getInputPath() + File.separator + inputFile);
|
||||||
|
SystemOut.println("Reading enums from " + f);
|
||||||
|
|
||||||
|
enumsReader.read(new FileReader(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String /*enum name*/, Map<String/*enum member*/, Value>> e : enumsReader.getEnums().entrySet()) {
|
||||||
|
String java = generate(e.getKey(), e.getValue());
|
||||||
|
|
||||||
|
String fullFileName = outputPath + File.separator + e.getKey() + ".java";
|
||||||
|
BufferedWriter br = new BufferedWriter(new FileWriter(fullFileName));
|
||||||
|
br.write(java);
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String generate(String key, Map<String, Value> values) {
|
||||||
|
StringBuilder sb = new StringBuilder("package com.rusefi.enums;\n");
|
||||||
|
sb.append("//auto-generated by ToJavaEnum.java\n\n\n\n");
|
||||||
|
sb.append("public enum " + key + " {\n");
|
||||||
|
|
||||||
|
List<Value> sorted = EnumsReader.getSortedByOrder(values);
|
||||||
|
|
||||||
|
for (Value value : sorted) {
|
||||||
|
sb.append("\t" + value.getName() + ",\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("}\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.rusefi.EnumsReader.isKeyValueLine;
|
import static com.rusefi.EnumsReader.isKeyValueLine;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -94,5 +95,26 @@ public class EnumToStringTest {
|
||||||
"\tGPIO_HEX,\n" +
|
"\tGPIO_HEX,\n" +
|
||||||
"}brain_pin_e; // hello");
|
"}brain_pin_e; // hello");
|
||||||
EnumsReader enumsReader = new EnumsReader().read(reader);
|
EnumsReader enumsReader = new EnumsReader().read(reader);
|
||||||
|
Map<String, Value> brain_pin_e = enumsReader.getEnums().get("brain_pin_e");
|
||||||
|
assertEquals(2, brain_pin_e.get("GPIO_HEX").getIntValue());
|
||||||
|
|
||||||
|
List<Value> listByOrdinal = EnumsReader.getSortedByOrder(brain_pin_e);
|
||||||
|
assertEquals(0, listByOrdinal.get(0).getIntValue());
|
||||||
|
|
||||||
|
for (Map.Entry<String /*enum name*/, Map<String/*enum member*/, Value>> e : enumsReader.getEnums().entrySet()) {
|
||||||
|
|
||||||
|
String a = new ToJavaEnum().generate(e.getKey(), e.getValue());
|
||||||
|
|
||||||
|
assertEquals("package com.rusefi.enums;\n" +
|
||||||
|
"//auto-generated by ToJavaEnum.java\n" +
|
||||||
|
"\n" +
|
||||||
|
"\n" +
|
||||||
|
"\n" +
|
||||||
|
"public enum brain_pin_e {\n" +
|
||||||
|
"\tGPIO_UNASSIGNED,\n" +
|
||||||
|
"\tGPIO_INVALID,\n" +
|
||||||
|
"\tGPIO_HEX,\n" +
|
||||||
|
"}\n", a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue