only:Improve toolset for default tune canned tune generation #4871
This commit is contained in:
parent
7bb7ff295c
commit
cd563d215f
|
@ -26,6 +26,8 @@ dependencies {
|
||||||
implementation global_libs.json
|
implementation global_libs.json
|
||||||
implementation ts_plugin_libs.httpclient
|
implementation ts_plugin_libs.httpclient
|
||||||
|
|
||||||
|
testImplementation project(':config_definition')
|
||||||
|
|
||||||
// junit 4.13 does not mix well with httpclient :(
|
// junit 4.13 does not mix well with httpclient :(
|
||||||
testImplementation group: 'junit', name: 'junit', version: '4.8.2'
|
testImplementation group: 'junit', name: 'junit', version: '4.8.2'
|
||||||
testFixturesImplementation global_libs.mockito
|
testFixturesImplementation global_libs.mockito
|
||||||
|
|
|
@ -2,13 +2,20 @@ package com.rusefi.tune;
|
||||||
|
|
||||||
import com.opensr5.ini.DialogModel;
|
import com.opensr5.ini.DialogModel;
|
||||||
import com.opensr5.ini.IniFileModel;
|
import com.opensr5.ini.IniFileModel;
|
||||||
|
import com.rusefi.*;
|
||||||
import com.rusefi.core.preferences.storage.Node;
|
import com.rusefi.core.preferences.storage.Node;
|
||||||
import com.rusefi.tools.tune.TuneTools;
|
import com.rusefi.tools.tune.TuneTools;
|
||||||
|
import com.rusefi.output.ConfigStructure;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
import com.rusefi.tune.xml.Msq;
|
import com.rusefi.tune.xml.Msq;
|
||||||
import com.rusefi.tune.xml.Page;
|
import com.rusefi.tune.xml.Page;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.rusefi.VariableRegistry.unquote;
|
||||||
import static com.rusefi.tune.TuneReadWriteTest.SRC_TEST_RESOURCES;
|
import static com.rusefi.tune.TuneReadWriteTest.SRC_TEST_RESOURCES;
|
||||||
import static com.rusefi.tune.TuneReadWriteTest.TEST_INI;
|
import static com.rusefi.tune.TuneReadWriteTest.TEST_INI;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -26,6 +33,13 @@ public class LoadOlderTuneTest {
|
||||||
IniFileModel ini = new IniFileModel().readIniFile(TEST_INI);
|
IniFileModel ini = new IniFileModel().readIniFile(TEST_INI);
|
||||||
assertFalse(ini.fieldsInUiOrder.isEmpty());
|
assertFalse(ini.fieldsInUiOrder.isEmpty());
|
||||||
|
|
||||||
|
List<String> options = Files.readAllLines(Paths.get("../../" + ConfigDefinition.CONFIG_PATH));
|
||||||
|
String[] totalArgs = options.toArray(new String[0]);
|
||||||
|
|
||||||
|
RootHolder.ROOT = "../../firmware/";
|
||||||
|
ReaderStateImpl state = new ReaderStateImpl();
|
||||||
|
ConfigDefinition.doJob(totalArgs, state);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (DialogModel.Field f : ini.fieldsInUiOrder) {
|
for (DialogModel.Field f : ini.fieldsInUiOrder) {
|
||||||
String name = f.getKey();
|
String name = f.getKey();
|
||||||
|
@ -38,15 +52,55 @@ public class LoadOlderTuneTest {
|
||||||
|
|
||||||
boolean isSameValue = simplerSpaces(defaultValue.getValue()).equals(simplerSpaces(customValue.getValue()));
|
boolean isSameValue = simplerSpaces(defaultValue.getValue()).equals(simplerSpaces(customValue.getValue()));
|
||||||
if (!isSameValue) {
|
if (!isSameValue) {
|
||||||
if (!Node.isNumeric(customValue.getValue())) {
|
ConfigStructure s = state.getStructures().get("engine_configuration_s");
|
||||||
// todo: smarter logic for enums
|
System.out.println(s);
|
||||||
|
ConfigField cf = s.getTsFieldByName(name);
|
||||||
|
if (cf == null) {
|
||||||
|
System.out.println("Not found " + name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sb.append("\tengineConfiguration->" + customValue.getName() + " = " + customValue.getValue() + ";\n");
|
|
||||||
|
if (cf.getType().equals("boolean")) {
|
||||||
|
// todo
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!Node.isNumeric(customValue.getValue())) {
|
||||||
|
// todo: smarter logic for enums
|
||||||
|
|
||||||
|
String type = cf.getType();
|
||||||
|
if (isHardwareEnum(type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EnumsReader.EnumState sourceCodeEnum = state.getEnumsReader().getEnums().get(type);
|
||||||
|
if (sourceCodeEnum == null) {
|
||||||
|
System.out.println("No info for " + type);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String customEnum = state.getTsCustomLine().get(type);
|
||||||
|
|
||||||
|
int ordinal;
|
||||||
|
try {
|
||||||
|
ordinal = TuneTools.resolveEnumByName(customEnum, unquote(customValue.getValue()));
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
System.out.println("Looks like things were renamed: " + customValue.getValue() + " not found in " + customEnum);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(cf + " " + sourceCodeEnum + " " + customEnum + " " + ordinal);
|
||||||
|
|
||||||
|
String sourceCodeValue = sourceCodeEnum.findByValue(ordinal);
|
||||||
|
sb.append(TuneTools.getAssignmentCode(customValue.getName(), sourceCodeValue));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sb.append(TuneTools.getAssignmentCode(customValue.getName(), customValue.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("\tengineConfiguration->cylindersCount = 4;\n" +
|
assertEquals("\tengineConfiguration->ignitionMode = IM_ONE_COIL;\n" +
|
||||||
|
"\tengineConfiguration->cylindersCount = 4;\n" +
|
||||||
"\tengineConfiguration->tps1SecondaryMin = 0.0;\n" +
|
"\tengineConfiguration->tps1SecondaryMin = 0.0;\n" +
|
||||||
"\tengineConfiguration->tps1SecondaryMax = 1000.0;\n" +
|
"\tengineConfiguration->tps1SecondaryMax = 1000.0;\n" +
|
||||||
"\tengineConfiguration->tps2SecondaryMin = 0.0;\n" +
|
"\tengineConfiguration->tps2SecondaryMin = 0.0;\n" +
|
||||||
|
@ -55,8 +109,18 @@ public class LoadOlderTuneTest {
|
||||||
"\tengineConfiguration->mc33_hvolt = 0.0;\n" +
|
"\tengineConfiguration->mc33_hvolt = 0.0;\n" +
|
||||||
"\tengineConfiguration->mc33_i_boost = 0.0;\n" +
|
"\tengineConfiguration->mc33_i_boost = 0.0;\n" +
|
||||||
"\tengineConfiguration->mc33_i_peak = 0.0;\n" +
|
"\tengineConfiguration->mc33_i_peak = 0.0;\n" +
|
||||||
"\tengineConfiguration->mc33_i_hold = 0.0;\n" +
|
"\tengineConfiguration->mc33_i_hold ", sb.substring(0, 500));
|
||||||
"\tengineConfiguration->mc33_t_max_boost = 0.", sb.substring(0, 500));
|
}
|
||||||
|
|
||||||
|
private static boolean isHardwareEnum(String type) {
|
||||||
|
switch (type) {
|
||||||
|
case "output_pin_e":
|
||||||
|
case "brain_input_pin_e":
|
||||||
|
case "adc_channel_e":
|
||||||
|
case "Gpio":
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object simplerSpaces(String value) {
|
private static Object simplerSpaces(String value) {
|
||||||
|
|
|
@ -183,7 +183,7 @@
|
||||||
<constant name="injectionMode">"Sequential"</constant>
|
<constant name="injectionMode">"Sequential"</constant>
|
||||||
<constant digits="2" name="extraInjectionOffset" units="deg">0.0</constant>
|
<constant digits="2" name="extraInjectionOffset" units="deg">0.0</constant>
|
||||||
<constant digits="2" name="crankingTimingAngle" units="deg">0.0</constant>
|
<constant digits="2" name="crankingTimingAngle" units="deg">0.0</constant>
|
||||||
<constant name="ignitionMode">"One coil"</constant>
|
<constant name="ignitionMode">"Single coil"</constant>
|
||||||
<constant digits="0" name="ignitionOffset" units="RPM">0.0</constant>
|
<constant digits="0" name="ignitionOffset" units="RPM">0.0</constant>
|
||||||
<constant name="timingMode">"dynamic"</constant>
|
<constant name="timingMode">"dynamic"</constant>
|
||||||
<constant digits="0" name="fixedModeTiming" units="RPM">50.0</constant>
|
<constant digits="0" name="fixedModeTiming" units="RPM">50.0</constant>
|
||||||
|
|
|
@ -184,7 +184,7 @@ page = 1
|
||||||
injectionMode = bits, U32, 428, [0:7], "Simultaneous", "Sequential", "Batch", "Single Point"
|
injectionMode = bits, U32, 428, [0:7], "Simultaneous", "Sequential", "Batch", "Single Point"
|
||||||
extraInjectionOffset = scalar, F32, 432, "deg", 1, 0.0, -720, 720, 2
|
extraInjectionOffset = scalar, F32, 432, "deg", 1, 0.0, -720, 720, 2
|
||||||
crankingTimingAngle = scalar, F32, 436, "deg", 1, 0.0, -360, 360, 2
|
crankingTimingAngle = scalar, F32, 436, "deg", 1, 0.0, -360, 360, 2
|
||||||
ignitionMode = bits, U32, 440, [0:7], "One coil", "Individual Coils", "Wasted", "Two distributors"
|
ignitionMode = bits, U32, 440, [0:7], "Single coil", "Individual Coils", "Wasted", "Two distributors"
|
||||||
ignitionOffset = scalar, F32, 444, "RPM", 1, 0, 0, 3000.0, 0
|
ignitionOffset = scalar, F32, 444, "RPM", 1, 0, 0, 3000.0, 0
|
||||||
timingMode = bits, U32, 448 [0:0], "dynamic", "fixed"
|
timingMode = bits, U32, 448 [0:0], "dynamic", "fixed"
|
||||||
fixedModeTiming = scalar, F32, 452, "RPM", 1, 0, 0, 3000.0, 0
|
fixedModeTiming = scalar, F32, 452, "RPM", 1, 0, 0, 3000.0, 0
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.rusefi.tools.tune;
|
package com.rusefi.tools.tune;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class TuneTools {
|
public class TuneTools {
|
||||||
private static String quote(String string) {
|
private static String quote(String string) {
|
||||||
return "\"" + string + "\"";
|
return "\"" + string + "\"";
|
||||||
|
@ -16,4 +18,9 @@ public class TuneTools {
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Enum name [" + key + "] not found in " + tsCustomLine);
|
throw new IllegalStateException("Enum name [" + key + "] not found in " + tsCustomLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String getAssignmentCode(String name, String value) {
|
||||||
|
return "\tengineConfiguration->" + name + " = " + value + ";\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class ConfigDefinition {
|
||||||
private static final String KEY_SIGNATURE_DESTINATION = "-signature_destination";
|
private static final String KEY_SIGNATURE_DESTINATION = "-signature_destination";
|
||||||
private static final String KEY_ZERO_INIT = "-initialize_to_zero";
|
private static final String KEY_ZERO_INIT = "-initialize_to_zero";
|
||||||
private static final String KEY_BOARD_NAME = "-board";
|
private static final String KEY_BOARD_NAME = "-board";
|
||||||
|
public static final String CONFIG_PATH = "java_tools/configuration_definition/src/main/resources/config_definition.options";
|
||||||
/**
|
/**
|
||||||
* This flag controls if we assign default zero value (useful while generating structures used for class inheritance)
|
* This flag controls if we assign default zero value (useful while generating structures used for class inheritance)
|
||||||
* versus not assigning default zero value like we need for non-class headers
|
* versus not assigning default zero value like we need for non-class headers
|
||||||
|
@ -41,7 +42,7 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
List<String> options = Files.readAllLines(Paths.get("../java_tools/configuration_definition/src/main/resources/config_definition.options"));
|
List<String> options = Files.readAllLines(Paths.get("../" + CONFIG_PATH));
|
||||||
options.addAll(Arrays.asList(args));
|
options.addAll(Arrays.asList(args));
|
||||||
String[] totalArgs = options.toArray(new String[0]);
|
String[] totalArgs = options.toArray(new String[0]);
|
||||||
if (totalArgs.length < 2) {
|
if (totalArgs.length < 2) {
|
||||||
|
@ -63,7 +64,7 @@ public class ConfigDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doJob(String[] args, ReaderStateImpl state) throws IOException {
|
public static void doJob(String[] args, ReaderStateImpl state) throws IOException {
|
||||||
SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args));
|
SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args));
|
||||||
|
|
||||||
String tsInputFileFolder = null;
|
String tsInputFileFolder = null;
|
||||||
|
@ -146,7 +147,7 @@ public class ConfigDefinition {
|
||||||
case EnumToString.KEY_ENUM_INPUT_FILE: {
|
case EnumToString.KEY_ENUM_INPUT_FILE: {
|
||||||
String enumInputFile = args[i + 1];
|
String enumInputFile = args[i + 1];
|
||||||
enumInputFiles.add(enumInputFile);
|
enumInputFiles.add(enumInputFile);
|
||||||
state.read(new FileReader(enumInputFile));
|
state.read(new FileReader(RootHolder.ROOT + enumInputFile));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "-ts_output_name":
|
case "-ts_output_name":
|
||||||
|
|
|
@ -3,10 +3,7 @@ package com.rusefi.output;
|
||||||
import com.rusefi.*;
|
import com.rusefi.*;
|
||||||
import com.rusefi.parse.TypesHelper;
|
import com.rusefi.parse.TypesHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.rusefi.ConfigFieldImpl.BOOLEAN_T;
|
import static com.rusefi.ConfigFieldImpl.BOOLEAN_T;
|
||||||
|
|
||||||
|
@ -26,6 +23,8 @@ public class ConfigStructureImpl implements ConfigStructure {
|
||||||
private final List<ConfigField> cFields = new ArrayList<>();
|
private final List<ConfigField> cFields = new ArrayList<>();
|
||||||
private final List<ConfigField> tsFields = new ArrayList<>();
|
private final List<ConfigField> tsFields = new ArrayList<>();
|
||||||
|
|
||||||
|
private final Map<String, ConfigField> tsFieldsMap = new TreeMap<>();
|
||||||
|
|
||||||
private int totalSize;
|
private int totalSize;
|
||||||
|
|
||||||
private final BitState readingBitState = new BitState();
|
private final BitState readingBitState = new BitState();
|
||||||
|
@ -88,7 +87,7 @@ public class ConfigStructureImpl implements ConfigStructure {
|
||||||
|
|
||||||
public void addBoth(ConfigFieldImpl cf) {
|
public void addBoth(ConfigFieldImpl cf) {
|
||||||
addC(cf);
|
addC(cf);
|
||||||
tsFields.add(cf);
|
addTs(cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addC(ConfigFieldImpl cf) {
|
public void addC(ConfigFieldImpl cf) {
|
||||||
|
@ -107,6 +106,12 @@ public class ConfigStructureImpl implements ConfigStructure {
|
||||||
|
|
||||||
public void addTs(ConfigFieldImpl cf) {
|
public void addTs(ConfigFieldImpl cf) {
|
||||||
tsFields.add(cf);
|
tsFields.add(cf);
|
||||||
|
tsFieldsMap.put(cf.getName(), cf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigField getTsFieldByName(String name) {
|
||||||
|
return tsFieldsMap.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBitPadding(ReaderStateImpl readerState) {
|
public void addBitPadding(ReaderStateImpl readerState) {
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class PinoutLogic {
|
||||||
|
|
||||||
for (int i = 0; i < values.size(); i++) {
|
for (int i = 0; i < values.size(); i++) {
|
||||||
appendCommaIfNeeded(simpleForm);
|
appendCommaIfNeeded(simpleForm);
|
||||||
String key = findKey(enumList, i);
|
String key = enumList.findByValue(i);
|
||||||
|
|
||||||
String value = values.get(i);
|
String value = values.get(i);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -123,17 +123,6 @@ public class PinoutLogic {
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String findKey(EnumsReader.EnumState enumList, int i) {
|
|
||||||
String key = "";
|
|
||||||
for (Map.Entry<String, Value> entry : enumList.entrySet()) {
|
|
||||||
if (entry.getValue().getIntValue() == i) {
|
|
||||||
key = entry.getKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void readMetaInfo(File yamlFile, Reader reader) {
|
private void readMetaInfo(File yamlFile, Reader reader) {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
|
|
|
@ -9,6 +9,8 @@ public interface ConfigStructure {
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
ConfigField getTsFieldByName(String name);
|
||||||
|
|
||||||
int getTotalSize();
|
int getTotalSize();
|
||||||
|
|
||||||
List<ConfigField> getTsFields();
|
List<ConfigField> getTsFields();
|
||||||
|
|
|
@ -155,6 +155,17 @@ public class EnumsReader {
|
||||||
this.isEnumClass = isEnumClass;
|
this.isEnumClass = isEnumClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String findByValue(int i) {
|
||||||
|
String key = "";
|
||||||
|
for (Map.Entry<String, Value> entry : entrySet()) {
|
||||||
|
if (entry.getValue().getIntValue() == i) {
|
||||||
|
key = entry.getKey();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<Value> values() {
|
public Collection<Value> values() {
|
||||||
return values.values();
|
return values.values();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue