generate java enum from C enum? generate both C and java from yaml? #2102
This commit is contained in:
parent
4b4314e86d
commit
4192aee6de
|
@ -170,8 +170,7 @@ UNUSED25 = 25,
|
||||||
PROTEUS_MIATA_NB2 = 67,
|
PROTEUS_MIATA_NB2 = 67,
|
||||||
MRE_M111 = 68,
|
MRE_M111 = 68,
|
||||||
|
|
||||||
|
HELLEN_NB2 = 69,
|
||||||
HELLEN_NB2 = ET_HELLEN_NB2,
|
|
||||||
|
|
||||||
SUBARUEG33_DEFAULTS = 70,
|
SUBARUEG33_DEFAULTS = 70,
|
||||||
|
|
||||||
|
@ -197,7 +196,7 @@ UNUSED25 = 25,
|
||||||
|
|
||||||
HELLEN_121_NISSAN_8_CYL = 85,
|
HELLEN_121_NISSAN_8_CYL = 85,
|
||||||
|
|
||||||
HELLEN_NB2_36 = ET_HELLEN_NB2_36,
|
HELLEN_NB2_36 = 86,
|
||||||
|
|
||||||
HELLEN_121_NISSAN_ALMERA_N16 = 87,
|
HELLEN_121_NISSAN_ALMERA_N16 = 87,
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -69,6 +69,13 @@ public class ReaderState {
|
||||||
String key = enumFamily.getKey() + "_" + enumValue.getKey();
|
String key = enumFamily.getKey() + "_" + enumValue.getKey();
|
||||||
String value = enumValue.getValue().getValue();
|
String value = enumValue.getValue().getValue();
|
||||||
variableRegistry.register(key, value);
|
variableRegistry.register(key, value);
|
||||||
|
|
||||||
|
try {
|
||||||
|
int numericValue = enumValue.getValue().getIntValue();
|
||||||
|
variableRegistry.registerHex(key, numericValue);
|
||||||
|
} catch (NumberFormatException ignore) {
|
||||||
|
// ENUM_32_BITS would be an example of a non-numeric enum, let's just skip for now
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.test;
|
package com.rusefi.test;
|
||||||
|
|
||||||
|
import com.rusefi.EnumsReader;
|
||||||
import com.rusefi.ReaderState;
|
import com.rusefi.ReaderState;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class EnumAsTsVariable {
|
public class EnumAsTsVariable {
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,8 +24,13 @@ public class EnumAsTsVariable {
|
||||||
"Force_4b_firing_order = ENUM_32_BITS,\n" +
|
"Force_4b_firing_order = ENUM_32_BITS,\n" +
|
||||||
"} firing_order_e;")));
|
"} firing_order_e;")));
|
||||||
|
|
||||||
|
EnumsReader.EnumState state = readerState.enumsReader.getEnums().get("firing_order_e");
|
||||||
|
assertNotNull(state);
|
||||||
|
|
||||||
|
String data = readerState.variableRegistry.get("firing_order_e_FO_1");
|
||||||
|
assertEquals("0", data);
|
||||||
|
|
||||||
assertEquals("0", readerState.variableRegistry.applyVariables("@@firing_order_e_FO_1@@"));
|
assertEquals("0", readerState.variableRegistry.applyVariables("@@firing_order_e_FO_1@@"));
|
||||||
|
assertEquals("\\x00\\x00", readerState.variableRegistry.applyVariables("@@firing_order_e_FO_1_16_hex@@"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ public class VariableRegistry {
|
||||||
registerHex(name, value);
|
registerHex(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerHex(String name, int value) {
|
public void registerHex(String name, int value) {
|
||||||
register(name + _HEX_SUFFIX, Integer.toString(value, 16));
|
register(name + _HEX_SUFFIX, Integer.toString(value, 16));
|
||||||
String _16_hex = String.format("\\\\x%02x\\\\x%02x", (value >> 8) & 0xFF, value & 0xFF);
|
String _16_hex = String.format("\\\\x%02x\\\\x%02x", (value >> 8) & 0xFF, value & 0xFF);
|
||||||
register(name + _16_HEX_SUFFIX, _16_hex);
|
register(name + _16_HEX_SUFFIX, _16_hex);
|
||||||
|
|
Loading…
Reference in New Issue