toolset progress
This commit is contained in:
parent
e1d9e7a349
commit
7882e9b2e1
|
@ -1,7 +1,10 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.board_generator.BoardReader;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.util.LazyFile;
|
||||
import com.rusefi.util.SystemOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -33,6 +36,36 @@ public class VariableRegistry {
|
|||
public VariableRegistry() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CharSequence getEnumOptionsForTunerStudio(EnumsReader enumsReader, VariableRegistry variableRegistry, TreeMap<Integer, String> valueNameById, String enumName) {
|
||||
for (Value value : enumsReader.getEnums().get(enumName).values()) {
|
||||
if (value.getValue().contains("ENUM_32_BITS"))
|
||||
continue;
|
||||
|
||||
if (isNumeric(value.getValue())) {
|
||||
valueNameById.put(value.getIntValue(), value.getName());
|
||||
} else {
|
||||
String valueFromRegistry = variableRegistry.get(value.getValue());
|
||||
if (valueFromRegistry == null)
|
||||
throw new IllegalStateException("No value for " + value);
|
||||
int intValue = Integer.parseInt(valueFromRegistry);
|
||||
valueNameById.put(intValue, value.getName());
|
||||
}
|
||||
}
|
||||
|
||||
int maxValue = valueNameById.lastKey();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i <= maxValue; i++) {
|
||||
if (sb.length() > 0)
|
||||
sb.append(", ");
|
||||
|
||||
String value = valueNameById.getOrDefault(i, BoardReader.INVALID);
|
||||
sb.append("\"" + value + "\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method replaces variables references like @@var@@ with actual values
|
||||
* An exception is thrown if we do not have such variable
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.board_generator;
|
||||
|
||||
import com.rusefi.EnumToString;
|
||||
import com.rusefi.EnumsReader;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.util.LazyFile;
|
||||
|
@ -19,13 +20,12 @@ import java.util.Objects;
|
|||
* the primary generation to avoid the intermediate file.
|
||||
*/
|
||||
public class BoardReader {
|
||||
private static final String INVALID = "INVALID";
|
||||
public static final String INVALID = "INVALID";
|
||||
|
||||
private static final String KEY_BOARD_NAME = "-board";
|
||||
private static final String YAML_INPUT_NAME = "-yaml";
|
||||
private static final String OUTPUT_FILE_NAME = "-output_file";
|
||||
private static final String KEY_FIRMWARE_PATH = "-firmware_path";
|
||||
private final static String KEY_ENUM_INPUT_FILE = "-enumInputFile";
|
||||
|
||||
private static final String MAPPING_YAML = "mapping.yaml";
|
||||
|
||||
|
@ -52,9 +52,9 @@ public class BoardReader {
|
|||
yamlInputFile = args[i + 1];
|
||||
} else if (key.equals(KEY_FIRMWARE_PATH)) {
|
||||
firmwarePath = args[i + 1];
|
||||
} else if (key.equals(KEY_ENUM_INPUT_FILE)) {
|
||||
} else if (key.equals(EnumToString.KEY_ENUM_INPUT_FILE)) {
|
||||
String inputFile = args[i + 1];
|
||||
enumsReader.process(new FileReader(firmwarePath + File.separator + inputFile));
|
||||
enumsReader.process(firmwarePath, inputFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,15 +118,18 @@ public class BoardReader {
|
|||
|
||||
private static int getMaxValue(Collection<Value> values) {
|
||||
int result = -1;
|
||||
for (Value v : values)
|
||||
for (Value v : values) {
|
||||
result = Math.max(result, v.getIntValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Value findByOrdinal(int ordinal, Collection<Value> values) {
|
||||
for (Value v : values)
|
||||
if (v.getValue().equals(String.valueOf(ordinal)))
|
||||
for (Value v : values) {
|
||||
if (v.getValue().equals(String.valueOf(ordinal))) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ConfigDefinition;
|
||||
import com.rusefi.EnumsReader;
|
||||
import com.rusefi.VariableRegistry;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ConfigDefinitionTest {
|
||||
private static final String FIRMWARE = "../../firmware";
|
||||
|
||||
@Test
|
||||
public void testEnumIntoType() throws IOException {
|
||||
EnumsReader enumsReader = new EnumsReader();
|
||||
enumsReader.process(FIRMWARE, "controllers/algo/rusefi_enums.h");
|
||||
|
||||
VariableRegistry variableRegistry = new VariableRegistry();
|
||||
|
||||
ConfigDefinition.readPrependValues(variableRegistry, FIRMWARE + File.separator + "integration/rusefi_config.txt");
|
||||
|
||||
TreeMap<Integer, String> valueNameById = new TreeMap<>();
|
||||
|
||||
CharSequence sb = VariableRegistry.getEnumOptionsForTunerStudio(enumsReader, variableRegistry, valueNameById, "engine_type_e");
|
||||
|
||||
System.out.println(sb);
|
||||
assertNotNull(sb);
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ public class EnumToString {
|
|||
private final static StringBuilder headerFileContent = new StringBuilder();
|
||||
|
||||
private final static String KEY_INPUT_PATH = "-enumInputPath";
|
||||
private final static String KEY_ENUM_INPUT_FILE = "-enumInputFile";
|
||||
public final static String KEY_ENUM_INPUT_FILE = "-enumInputFile";
|
||||
private final static String KEY_OUTPUT = "-outputPath";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
|
|
@ -3,9 +3,7 @@ package com.rusefi;
|
|||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.util.SystemOut;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
@ -14,6 +12,10 @@ public class EnumsReader {
|
|||
|
||||
private final Map<String, Map<String, Value>> enums = new TreeMap<>();
|
||||
|
||||
public void process(String path, String fileName) throws IOException {
|
||||
process(new FileReader(path + File.separator + fileName));
|
||||
}
|
||||
|
||||
public void process(Reader in) throws IOException {
|
||||
boolean isInsideEnum = false;
|
||||
BufferedReader reader = new BufferedReader(in);
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.rusefi.enum_reader;
|
|||
|
||||
public class Value implements Comparable<Value> {
|
||||
private final String name;
|
||||
private String value;
|
||||
private final String value;
|
||||
|
||||
public Value(String name, String value) {
|
||||
this.name = name;
|
||||
|
|
Loading…
Reference in New Issue