only:Improve toolset for default tune canned tune generation #4871
This commit is contained in:
parent
c471441942
commit
9049af27da
|
@ -155,7 +155,7 @@ public class IniFileModel {
|
||||||
if (isConstantsSection) {
|
if (isConstantsSection) {
|
||||||
if (isInsidePageDefinition) {
|
if (isInsidePageDefinition) {
|
||||||
if (list.size() > 1)
|
if (list.size() > 1)
|
||||||
handleFieldDefinition(list);
|
handleFieldDefinition(list, line);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (list.size() > 1) {
|
if (list.size() > 1) {
|
||||||
|
@ -225,7 +225,7 @@ public class IniFileModel {
|
||||||
list.removeFirst();
|
list.removeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFieldDefinition(LinkedList<String> list) {
|
private void handleFieldDefinition(LinkedList<String> list, RawIniFile.Line line) {
|
||||||
switch (list.get(1)) {
|
switch (list.get(1)) {
|
||||||
case FIELD_TYPE_SCALAR:
|
case FIELD_TYPE_SCALAR:
|
||||||
registerField(ScalarIniField.parse(list));
|
registerField(ScalarIniField.parse(list));
|
||||||
|
@ -237,7 +237,7 @@ public class IniFileModel {
|
||||||
registerField(ArrayIniField.parse(list));
|
registerField(ArrayIniField.parse(list));
|
||||||
break;
|
break;
|
||||||
case FIELD_TYPE_BITS:
|
case FIELD_TYPE_BITS:
|
||||||
registerField(EnumIniField.parse(list));
|
registerField(EnumIniField.parse(list, line));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected " + list);
|
throw new IllegalStateException("Unexpected " + list);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.opensr5.ini.field;
|
package com.opensr5.ini.field;
|
||||||
|
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
|
import com.opensr5.ini.IniFileReader;
|
||||||
|
import com.opensr5.ini.RawIniFile;
|
||||||
import com.rusefi.config.FieldType;
|
import com.rusefi.config.FieldType;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -9,15 +11,18 @@ import javax.management.ObjectName;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class EnumIniField extends IniField {
|
public class EnumIniField extends IniField {
|
||||||
private final FieldType type;
|
private final FieldType type;
|
||||||
private final List<String> enums;
|
private final EnumKeyValueMap enums;
|
||||||
private final int bitPosition;
|
private final int bitPosition;
|
||||||
// weird format where 'one bit' width means 0 and "two bits" means "1"
|
// weird format where 'one bit' width means 0 and "two bits" means "1"
|
||||||
private final int bitSize0;
|
private final int bitSize0;
|
||||||
|
|
||||||
public EnumIniField(String name, int offset, FieldType type, List<String> enums, int bitPosition, int bitSize0) {
|
public EnumIniField(String name, int offset, FieldType type, EnumKeyValueMap enums, int bitPosition, int bitSize0) {
|
||||||
super(name, offset);
|
super(name, offset);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.enums = enums;
|
this.enums = enums;
|
||||||
|
@ -38,7 +43,7 @@ public class EnumIniField extends IniField {
|
||||||
return bitSize0;
|
return bitSize0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getEnums() {
|
public EnumKeyValueMap getEnums() {
|
||||||
return enums;
|
return enums;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +112,7 @@ public class EnumIniField extends IniField {
|
||||||
return ordinal;
|
return ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumIniField parse(LinkedList<String> list) {
|
public static EnumIniField parse(LinkedList<String> list, RawIniFile.Line line) {
|
||||||
String name = list.get(0);
|
String name = list.get(0);
|
||||||
FieldType type = FieldType.parseTs(list.get(2));
|
FieldType type = FieldType.parseTs(list.get(2));
|
||||||
int offset = Integer.parseInt(list.get(3));
|
int offset = Integer.parseInt(list.get(3));
|
||||||
|
@ -117,11 +122,17 @@ public class EnumIniField extends IniField {
|
||||||
int bitPosition = parseBitRange.getBitPosition();
|
int bitPosition = parseBitRange.getBitPosition();
|
||||||
int bitSize0 = parseBitRange.getBitSize0();
|
int bitSize0 = parseBitRange.getBitSize0();
|
||||||
|
|
||||||
List<String> enums = list.subList(5, list.size());
|
EnumKeyValueMap enums = EnumKeyValueMap.valueOf(line.getRawText());
|
||||||
|
|
||||||
return new EnumIniField(name, offset, type, enums, bitPosition, bitSize0);
|
return new EnumIniField(name, offset, type, enums, bitPosition, bitSize0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int ordinalIndexOf(String str, String substr, int n) {
|
||||||
|
int pos = str.indexOf(substr);
|
||||||
|
while (--n > 0 && pos != -1)
|
||||||
|
pos = str.indexOf(substr, pos + 1);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
public static class ParseBitRange {
|
public static class ParseBitRange {
|
||||||
private int bitPosition;
|
private int bitPosition;
|
||||||
private int bitSize0;
|
private int bitSize0;
|
||||||
|
@ -144,4 +155,57 @@ public class EnumIniField extends IniField {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class EnumKeyValueMap {
|
||||||
|
private static final String STARTS_WITH_NUMBERS_OPTIONAL_SPACES_AND_EQUALS = "^\\d+\\s*=.*";
|
||||||
|
private static Pattern IS_KEY_VALUE_SYNTAX = Pattern.compile(STARTS_WITH_NUMBERS_OPTIONAL_SPACES_AND_EQUALS);
|
||||||
|
|
||||||
|
private final Map<Integer, String> keyValues;
|
||||||
|
|
||||||
|
public EnumKeyValueMap(Map<Integer, String> keyValues) {
|
||||||
|
this.keyValues = keyValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EnumKeyValueMap valueOf(String rawText) {
|
||||||
|
Map<Integer, String> keyValues = new TreeMap<>();
|
||||||
|
|
||||||
|
int interestingIndex = EnumIniField.ordinalIndexOf(rawText, ",", 4);
|
||||||
|
// yes that could have been done with a regex as well
|
||||||
|
String interestingPart = rawText.substring(interestingIndex + /*skipping comma*/1).trim();
|
||||||
|
boolean isKeyValueSyntax = IS_KEY_VALUE_SYNTAX.matcher(interestingPart).matches();
|
||||||
|
int offset = 5;
|
||||||
|
String[] tokens = IniFileReader.splitTokens(rawText);
|
||||||
|
|
||||||
|
if (isKeyValueSyntax) {
|
||||||
|
for (int i = 0; i < tokens.length - offset; i += 2) {
|
||||||
|
keyValues.put(Integer.valueOf(tokens[i + offset]), tokens[i + offset + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < tokens.length - offset; i++) {
|
||||||
|
keyValues.put(i, tokens[i + offset]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new EnumKeyValueMap(keyValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return keyValues.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(int ordinal) {
|
||||||
|
return keyValues.get(ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int indexOf(String value) {
|
||||||
|
for (Map.Entry<Integer, String> e : keyValues.entrySet()) {
|
||||||
|
if (e.getValue().equals(value))
|
||||||
|
return e.getKey();
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Nothing for " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.opensr5.ini.test;
|
||||||
|
|
||||||
|
import com.opensr5.ini.field.EnumIniField;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class IniEnumDecoderTest {
|
||||||
|
@Test
|
||||||
|
public void testKeyValueSyntax() {
|
||||||
|
String line = "engineType = bits, S32, 0, [0:6], 0=\"DEFAULT_FRANKENSO\",97=\"ALPHAX_8CHAN_SBC\",24=\"BMW_M73_M\",50=\"BMW_M73_MRE\",51=\"BMW_M73_MRE_SLAVE\",35=\"CAMARO_4\",65=\"CITROEN_TU3JP\",38=\"DISCOVERY_PDM\",2=\"DODGE_NEON_1995\",46=\"DODGE_NEON_2003_CRANK\",64=\"DODGE_RAM\",61=\"EEPROM_BENCH_ENGINE\",58=\"ETB_BENCH_ENGINE\",3=\"FORD_ASPIRE_1996\",11=\"FORD_COYOTE\",14=\"FORD_ESCORT_GT\",7=\"FORD_INLINE_6_1995\",40=\"FRANKENSO_BMW_M73_F\",47=\"FRANKENSO_MAZDA_MIATA_2003\",56=\"FRANKENSO_MAZDA_MIATA_NA8\",41=\"FRANKENSO_MIATA_NA6_MAP\",49=\"FRANKENSO_QA_ENGINE\",8=\"GY6_139QMB\",33=\"HELLEN72_ETB\",84=\"HELLEN_121_NISSAN_4_CYL\",72=\"HELLEN_121_NISSAN_6_CYL\",85=\"HELLEN_121_NISSAN_8_CYL\",87=\"HELLEN_121_NISSAN_ALMERA_N16\",71=\"HELLEN_121_VAG_4_CYL\",77=\"HELLEN_121_VAG_5_CYL\",81=\"HELLEN_121_VAG_8_CYL\",78=\"HELLEN_121_VAG_V6_CYL\",79=\"HELLEN_121_VAG_VR6_CYL\",36=\"HELLEN_128_MERCEDES_4_CYL\",88=\"HELLEN_128_MERCEDES_6_CYL\",89=\"HELLEN_128_MERCEDES_8_CYL\",75=\"HELLEN_134_BMW\",82=\"HELLEN_154_HYUNDAI_COUPE_BK1\",95=\"HELLEN_154_HYUNDAI_COUPE_BK2\",76=\"HELLEN_154_VAG\",73=\"HELLEN_55_BMW\",74=\"HELLEN_88_BMW\",34=\"HELLEN_NA6\",10=\"HELLEN_NA8_96\",80=\"HELLEN_NA94\",83=\"HELLEN_NB1\",94=\"HELLEN_NB1_36\",69=\"HELLEN_NB2\",86=\"HELLEN_NB2_36\",43=\"HONDA_600\",60=\"L9779_BENCH_ENGINE\",55=\"MAZDA_MIATA_2003_BOARD_TEST\",54=\"MAZDA_MIATA_2003_NA_RAIL\",21=\"MIATA_1996\",1=\"MIATA_PROTEUS_TCU\",99=\"MINIMAL_PINS\",12=\"MITSUBISHI_3A92\",16=\"MITSUBISHI_4G93\",31=\"MRE_BOARD_NEW_TEST\",23=\"MRE_BODY_CONTROL\",68=\"MRE_M111\",20=\"MRE_MIATA_94_MAP\",66=\"MRE_MIATA_NA6_MAP\",4=\"MRE_SECONDARY_CAN\",37=\"MRE_SUBARU_EJ18\",62=\"MRE_VW_B6\",5=\"NISSAN_PRIMERA\",30=\"PROTEUS_ANALOG_PWM_TEST\",63=\"PROTEUS_BMW_M73\",9=\"PROTEUS_E65_6H_MAN_IN_THE_MIDDLE\",27=\"PROTEUS_GM_LS_4\",6=\"PROTEUS_HARLEY\",90=\"PROTEUS_HONDA_K\",91=\"PROTEUS_HONDA_OBD2A\",104=\"PROTEUS_HYUNDAI_PB\",25=\"PROTEUS_LUA_DEMO\",17=\"PROTEUS_M111\",67=\"PROTEUS_MIATA_NB2\",93=\"PROTEUS_N73\",103=\"PROTEUS_NISSAN_VQ35\",42=\"PROTEUS_QC_TEST_BOARD\",98=\"PROTEUS_SBC\",92=\"PROTEUS_VAG_80_18T\",39=\"PROTEUS_VW_B6\",29=\"SACHS\",70=\"SUBARUEG33_DEFAULTS\",22=\"SUBARU_2003_WRX\",100=\"TEST_100\",101=\"TEST_101\",102=\"TEST_102\",18=\"TEST_33816\",28=\"TEST_CRANK_ENGINE\",48=\"TEST_DC_WASTEGATE_DISCOVERY\",26=\"TEST_ENGINE\",45=\"TEST_ENGINE_VVT\",52=\"TEST_ISSUE_366_BOTH\",53=\"TEST_ISSUE_366_RISE\",19=\"TEST_ROTARY\",59=\"TLE8888_BENCH_ENGINE\",13=\"TOYOTA_1NZ_FE\",44=\"TOYOTA_2JZ_GTE_VVTi\",15=\"UNUSED_15\",57=\"UNUSED_57\",32=\"VW_ABA\",96=\"WASTEGATE_PROTEUS_TEST\"";
|
||||||
|
|
||||||
|
EnumIniField.EnumKeyValueMap m = EnumIniField.EnumKeyValueMap.valueOf(line);
|
||||||
|
|
||||||
|
assertEquals(105, m.size());
|
||||||
|
assertEquals("DEFAULT_FRANKENSO", m.get(0));
|
||||||
|
assertEquals("MIATA_PROTEUS_TCU", m.get(1));
|
||||||
|
|
||||||
|
assertEquals(0, m.indexOf("DEFAULT_FRANKENSO"));
|
||||||
|
assertEquals(24, m.indexOf("BMW_M73_M"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testArraySyntax() {
|
||||||
|
String line = "engineType = bits, S32, 0, [0:6], \"DEFAULT_FRANKENSO\",\"ALPHAX_8CHAN_SBC\"";
|
||||||
|
EnumIniField.EnumKeyValueMap m = EnumIniField.EnumKeyValueMap.valueOf(line);
|
||||||
|
assertEquals(2, m.size());
|
||||||
|
|
||||||
|
assertEquals("DEFAULT_FRANKENSO", m.get(0));
|
||||||
|
assertEquals("ALPHAX_8CHAN_SBC", m.get(1));
|
||||||
|
|
||||||
|
assertEquals(0, m.indexOf("DEFAULT_FRANKENSO"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue