Determine the correct mul/div for autoscale from the TS config line instead of specifying it twice. (#3470)

This commit is contained in:
Scott Smith 2021-11-05 16:26:25 -07:00 committed by GitHub
parent 3222881248
commit eb781f38b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 36 deletions

View File

@ -977,7 +977,7 @@ custom maf_sensor_type_e 4 bits, S32, @OFFSET@, [0:1], @@maf_sensor_type_e_enum@
pin_output_mode_e drv8860_csPinMode;
brain_pin_e drv8860_miso;
uint16_t[FUEL_LEVEL_TABLE_COUNT] autoscale<PACK_MULT_VOLTAGE> fuelLevelBins;;"volt", {1/@@PACK_MULT_VOLTAGE@@}, 0, 0, 5, 3
uint16_t[FUEL_LEVEL_TABLE_COUNT] autoscale fuelLevelBins;;"volt", {1/@@PACK_MULT_VOLTAGE@@}, 0, 0, 5, 3
output_pin_e[LUA_PWM_COUNT iterate] luaOutputPins
@ -1438,11 +1438,11 @@ tChargeMode_e tChargeMode;
int16_t idlerpmpid_iTermMin;iTerm min value;"", 1, 0, -30000, 30000, 0
spi_device_e tle6240spiDevice;
uint8_t autoscale<PACK_MULT_AFR_CFG> stoichRatioPrimary;+Stoichiometric ratio for your primary fuel. When Flex Fuel is enabled, this value is used when the Flex Fuel sensor indicates E0.\nE0 = 14.7\nE10 = 14.1\nE85 = 9.9\nE100 = 9.0;":1", {1/@@PACK_MULT_AFR_CFG@@}, 0, 5, 25, 1
uint8_t autoscale stoichRatioPrimary;+Stoichiometric ratio for your primary fuel. When Flex Fuel is enabled, this value is used when the Flex Fuel sensor indicates E0.\nE0 = 14.7\nE10 = 14.1\nE85 = 9.9\nE100 = 9.0;":1", {1/@@PACK_MULT_AFR_CFG@@}, 0, 5, 25, 1
int16_t idlerpmpid_iTermMax;iTerm max value;"", 1, 0, -30000, 30000, 0
spi_device_e mc33972spiDevice;
uint8_t autoscale<PACK_MULT_AFR_CFG> stoichRatioSecondary;+Stoichiometric ratio for your secondary fuel. This value is used when the Flex Fuel sensor indicates E100, typically 9.0;":1", {1/@@PACK_MULT_AFR_CFG@@}, 0, 5, 25, 1
uint8_t autoscale stoichRatioSecondary;+Stoichiometric ratio for your secondary fuel. This value is used when the Flex Fuel sensor indicates E100, typically 9.0;":1", {1/@@PACK_MULT_AFR_CFG@@}, 0, 5, 25, 1
uint8_t[2] unusedSpiPadding8;;"units", 1, 0, -20, 100, 0
@ -1564,7 +1564,7 @@ tcubinary_table_t tcuSolenoidTable;
float vssFilterReciprocal;+Good example: number of tooth on wheel, For Can 10 is a good number.;"Hz", 1, 0, 2, 20, 2
map_estimate_table_t mapEstimateTable;
uint16_t[FUEL_LOAD_COUNT] autoscale<TPS_2_BYTE_PACKING_MULT> mapEstimateTpsBins;;"% TPS", {1/@@TPS_2_BYTE_PACKING_MULT@@}, 0, 0, 100, 1
uint16_t[FUEL_LOAD_COUNT] autoscale mapEstimateTpsBins;;"% TPS", {1/@@TPS_2_BYTE_PACKING_MULT@@}, 0, 0, 100, 1
uint16_t[FUEL_RPM_COUNT] mapEstimateRpmBins;;"RPM", 1, 0, 0, 18000, 0
fsio_table_8x8_u8t vvtTable1;

Binary file not shown.

View File

@ -94,10 +94,8 @@ fieldOptionsList
arrayLengthSpec: numexpr (ArrayDimensionSeparator numexpr)?;
autoscale: Autoscale '<' numexpr '>';
scalarField: identifier autoscale? FsioVisible? identifier (fieldOptionsList)?;
arrayField: identifier '[' arrayLengthSpec Iterate? ']' autoscale? identifier SemicolonedString? (fieldOptionsList)?;
scalarField: identifier Autoscale? FsioVisible? identifier (fieldOptionsList)?;
arrayField: identifier '[' arrayLengthSpec Iterate? ']' Autoscale? identifier SemicolonedString? (fieldOptionsList)?;
bitField: Bit identifier (',' QuotedString ',' QuotedString)? ('(' 'comment' ':' QuotedString ')')? SemicolonedSuffix?;
unionField: 'union' ENDL+ fields 'end_union';

View File

@ -14,11 +14,11 @@ import java.util.regex.Pattern;
* 1/15/15
*/
public class ConfigField {
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, new int[0], null, false, false, null,null, -1, null, null);
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, new int[0], null, false, false, false, null, -1, null, null);
private static final String typePattern = "([\\w\\d_]+)(\\[([\\w\\d]+)(\\sx\\s([\\w\\d]+))?(\\s([\\w\\d]+))?\\])?";
private static final String namePattern = "[[\\w\\d\\s<>_]]+";
private static final String namePattern = "[[\\w\\d\\s_]]+";
private static final String commentPattern = ";([^;]*)";
private static final Pattern FIELD = Pattern.compile(typePattern + "\\s(" + namePattern + ")(" + commentPattern + ")?(;(.*))?");
@ -42,7 +42,7 @@ public class ConfigField {
private final boolean isIterate;
private final ReaderState state;
private boolean fsioVisible;
private final String autoscaleSpec;
private final boolean hasAutoscale;
private final String individualName;
private final int indexWithinArray;
private final String trueName;
@ -60,11 +60,11 @@ public class ConfigField {
String tsInfo,
boolean isIterate,
boolean fsioVisible,
String autoscaleSpec,
boolean hasAutoscale,
String individualName,
int indexWithinArray, String trueName, String falseName) {
this.fsioVisible = fsioVisible;
this.autoscaleSpec = autoscaleSpec;
this.hasAutoscale = hasAutoscale;
this.individualName = individualName;
this.indexWithinArray = indexWithinArray;
this.trueName = trueName == null ? "true" : trueName;
@ -143,14 +143,12 @@ public class ConfigField {
boolean isFsioVisible = Arrays.stream(nameTokens).anyMatch(s -> s.equalsIgnoreCase("fsio_visible"));
String autoscaleSpec = null;
boolean hasAutoscale = false;
for (String autoscaler : nameTokens) {
if (!autoscaler.startsWith("autoscale")) {
continue;
if (autoscaler.equals("autoscale")) {
hasAutoscale = true;
break;
}
autoscaleSpec = autoscaler.split("[<>]")[1];
break;
}
String comment = matcher.group(10);
@ -176,7 +174,7 @@ public class ConfigField {
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySizes,
tsInfo, isIterate, isFsioVisible, autoscaleSpec, null, -1, null, null);
tsInfo, isIterate, isFsioVisible, hasAutoscale, null, -1, null, null);
SystemOut.println("type " + type);
SystemOut.println("name " + name);
SystemOut.println("comment " + comment);
@ -261,7 +259,39 @@ public class ConfigField {
return fsioVisible;
}
public String autoscaleSpec() { return this.autoscaleSpec; }
public String autoscaleSpec() {
if (!hasAutoscale) {
return null;
}
String[] tokens = tsInfo.split("\\,");
String scale = tokens[1].trim();
double factor;
if (scale.startsWith("{") && scale.endsWith("}")) {
// Handle just basic division, not a full fledged eval loop
scale = scale.substring(1, scale.length() - 1);
String[] parts = scale.split("/");
factor = Double.parseDouble(parts[0]) / Double.parseDouble(parts[1]);
} else {
factor = Double.parseDouble(scale);
}
int mul, div;
if (factor < 1.d) {
mul = (int)Math.round(1. / factor);
div = 1;
} else {
mul = 1;
div = (int)factor;
}
// Verify accuracy
double factor2 = ((double)div) / mul;
double accuracy = Math.abs((factor2 / factor) - 1.);
if (accuracy > 0.0000001) {
// Don't want to deal with exception propogation; this should adequately not compile
return "$*@#$* Cannot accurately represent autoscale for " + tokens[1];
}
return mul + ", " + div;
}
public String getUnits() {
if (tsInfo == null)

View File

@ -82,7 +82,7 @@ public class ConfigStructure {
}
ConfigField fill = new ConfigField(state, ALIGNMENT_FILL_AT + totalSize, "need 4 byte alignment",
"" + fillSize,
TypesHelper.UINT8_T, fillSizeArray, "\"units\", 1, 0, -20, 100, 0", false, false, null, null, -1, null, null);
TypesHelper.UINT8_T, fillSizeArray, "\"units\", 1, 0, -20, 100, 0", false, false, false, null, -1, null, null);
addBoth(fill);
}
totalSize += fillSize;
@ -116,7 +116,7 @@ public class ConfigStructure {
return;
int sizeAtStartOfPadding = cFields.size();
while (readingBitState.get() < 32) {
ConfigField bitField = new ConfigField(readerState, "unusedBit_" + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, null, null, -1, null, null);
ConfigField bitField = new ConfigField(readerState, "unusedBit_" + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, false, null, -1, null, null);
addBitField(bitField);
}
readingBitState.reset();

View File

@ -52,7 +52,7 @@ public class ReaderState {
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
String falseName = bitNameParts.length > 2 ? bitNameParts[2].replaceAll("\"", "") : null;
ConfigField bitField = new ConfigField(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, null, null, -1, trueName, falseName);
ConfigField bitField = new ConfigField(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, false, null, -1, trueName, falseName);
if (state.stack.isEmpty())
throw new IllegalStateException("Parent structure expected");
ConfigStructure structure = state.stack.peek();
@ -246,7 +246,7 @@ public class ReaderState {
if (cf == null) {
if (ConfigField.isPreprocessorDirective(state, line)) {
cf = new ConfigField(state, "", line, null,
ConfigField.DIRECTIVE_T, new int[0], null, false, false, null, null, 0,
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false, null, 0,
null, null);
} else {
throw new IllegalStateException("Cannot parse line [" + line + "]");
@ -270,7 +270,7 @@ public class ReaderState {
structure.addC(cf);
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
cf.getType(), new int[0], cf.getTsInfo(), false, false, null, cf.getName(), i, null, null);
cf.getType(), new int[0], cf.getTsInfo(), false, false, false, cf.getName(), i, null, null);
structure.addTs(element);
}
} else if (cf.isDirective()) {

View File

@ -325,11 +325,7 @@ public class ParseState {
public void exitScalarField(RusefiConfigGrammarParser.ScalarFieldContext ctx) {
String type = ctx.identifier(0).getText();
String name = ctx.identifier(1).getText();
boolean autoscale = ctx.autoscale() != null;
if (autoscale) {
evalResults.remove();
}
boolean autoscale = ctx.Autoscale() != null;
// First check if this is an instance of a struct
if (structs.containsKey(type)) {
@ -432,11 +428,7 @@ public class ParseState {
int[] length = this.arrayDim;
// check if the iterate token is present
boolean iterate = ctx.Iterate() != null;
boolean autoscale = ctx.autoscale() != null;
if (autoscale) {
evalResults.remove();
}
boolean autoscale = ctx.Autoscale() != null;
// First check if this is an array of structs
if (structs.containsKey(type)) {