he owes me one now
This commit is contained in:
parent
1b1ffd6a96
commit
94c2f3a4cd
|
@ -340,7 +340,7 @@ bit issue_294_27;
|
||||||
bit issue_294_28;
|
bit issue_294_28;
|
||||||
bit issue_294_29;
|
bit issue_294_29;
|
||||||
bit issue_294_30;
|
bit issue_294_30;
|
||||||
bit issue_294_31;
|
bit issue_294_31,si_example,nada_example;
|
||||||
|
|
||||||
|
|
||||||
int16_t tpsMin;Closed throttle. todo: extract these two fields into a structure\nSee also tps1_1AdcChannel\nset tps_min X;"ADC", 1, 0, 0, 1023, 0
|
int16_t tpsMin;Closed throttle. todo: extract these two fields into a structure\nSee also tps1_1AdcChannel\nset tps_min X;"ADC", 1, 0, 0, 1023, 0
|
||||||
|
|
Binary file not shown.
|
@ -13,7 +13,7 @@ import java.util.regex.Pattern;
|
||||||
* 1/15/15
|
* 1/15/15
|
||||||
*/
|
*/
|
||||||
public class ConfigField {
|
public class ConfigField {
|
||||||
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, 1, null, false, false, null, -1);
|
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, 1, null, false, false, null, -1, null, null);
|
||||||
|
|
||||||
private static final String typePattern = "([\\w\\d_]+)(\\[([\\w\\d]+)(\\s([\\w\\d]+))?\\])?";
|
private static final String typePattern = "([\\w\\d_]+)(\\[([\\w\\d]+)(\\s([\\w\\d]+))?\\])?";
|
||||||
private static final String namePattern = "[[\\w\\d\\s_]]+";
|
private static final String namePattern = "[[\\w\\d\\s_]]+";
|
||||||
|
@ -38,7 +38,12 @@ public class ConfigField {
|
||||||
private boolean fsioVisible;
|
private boolean fsioVisible;
|
||||||
private final String individualName;
|
private final String individualName;
|
||||||
private final int indexWithinArray;
|
private final int indexWithinArray;
|
||||||
|
private final String trueName;
|
||||||
|
private final String falseName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo: one day someone should convert this into a builder
|
||||||
|
*/
|
||||||
public ConfigField(ReaderState state,
|
public ConfigField(ReaderState state,
|
||||||
String name,
|
String name,
|
||||||
String comment,
|
String comment,
|
||||||
|
@ -47,10 +52,14 @@ public class ConfigField {
|
||||||
int arraySize,
|
int arraySize,
|
||||||
String tsInfo,
|
String tsInfo,
|
||||||
boolean isIterate,
|
boolean isIterate,
|
||||||
boolean fsioVisible, String individualName, int indexWithinArray) {
|
boolean fsioVisible,
|
||||||
|
String individualName,
|
||||||
|
int indexWithinArray, String trueName, String falseName) {
|
||||||
this.fsioVisible = fsioVisible;
|
this.fsioVisible = fsioVisible;
|
||||||
this.individualName = individualName;
|
this.individualName = individualName;
|
||||||
this.indexWithinArray = indexWithinArray;
|
this.indexWithinArray = indexWithinArray;
|
||||||
|
this.trueName = trueName == null ? "true" : trueName;
|
||||||
|
this.falseName = falseName == null ? "false" : falseName;
|
||||||
Objects.requireNonNull(name, comment + " " + type);
|
Objects.requireNonNull(name, comment + " " + type);
|
||||||
assertNoWhitespaces(name);
|
assertNoWhitespaces(name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -69,6 +78,14 @@ public class ConfigField {
|
||||||
this.isIterate = isIterate;
|
this.isIterate = isIterate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTrueName() {
|
||||||
|
return trueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFalseName() {
|
||||||
|
return falseName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCFieldName() {
|
public String getCFieldName() {
|
||||||
return getIndividualName() == null ? getName() : getIndividualName() + "["
|
return getIndividualName() == null ? getName() : getIndividualName() + "["
|
||||||
+ (getIndexWithinArray() - 1) + "]";
|
+ (getIndexWithinArray() - 1) + "]";
|
||||||
|
@ -127,7 +144,7 @@ public class ConfigField {
|
||||||
|
|
||||||
|
|
||||||
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySize,
|
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySize,
|
||||||
tsInfo, isIterate, isFsioVisible, null, -1);
|
tsInfo, isIterate, isFsioVisible, null, -1, null, null);
|
||||||
SystemOut.println("type " + type);
|
SystemOut.println("type " + type);
|
||||||
SystemOut.println("name " + name);
|
SystemOut.println("name " + name);
|
||||||
SystemOut.println("comment " + comment);
|
SystemOut.println("comment " + comment);
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class ConfigStructure {
|
||||||
if (fillSize != 0) {
|
if (fillSize != 0) {
|
||||||
ConfigField fill = new ConfigField(state, "alignmentFill_at_" + totalSize, "need 4 byte alignment",
|
ConfigField fill = new ConfigField(state, "alignmentFill_at_" + totalSize, "need 4 byte alignment",
|
||||||
"" + fillSize,
|
"" + fillSize,
|
||||||
TypesHelper.UINT8_T, fillSize, null, false, false, null, -1);
|
TypesHelper.UINT8_T, fillSize, null, false, false, null, -1, null, null);
|
||||||
addBoth(fill);
|
addBoth(fill);
|
||||||
}
|
}
|
||||||
totalSize += fillSize;
|
totalSize += fillSize;
|
||||||
|
@ -91,7 +91,7 @@ public class ConfigStructure {
|
||||||
return;
|
return;
|
||||||
int sizeAtStartOfPadding = cFields.size();
|
int sizeAtStartOfPadding = cFields.size();
|
||||||
while (readingBitState.get() < 32) {
|
while (readingBitState.get() < 32) {
|
||||||
ConfigField bitField = new ConfigField(readerState, "unusedBit_" + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, 0, null, false, false, null, -1);
|
ConfigField bitField = new ConfigField(readerState, "unusedBit_" + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, 0, null, false, false, null, -1, null, null);
|
||||||
addBitField(bitField);
|
addBitField(bitField);
|
||||||
}
|
}
|
||||||
readingBitState.reset();
|
readingBitState.reset();
|
||||||
|
|
|
@ -19,7 +19,7 @@ import static com.rusefi.ConfigField.BOOLEAN_T;
|
||||||
* 12/19/18
|
* 12/19/18
|
||||||
*/
|
*/
|
||||||
public class ReaderState {
|
public class ReaderState {
|
||||||
private static final String BIT = "bit";
|
public static final String BIT = "bit";
|
||||||
protected static final String DEFINE = "#define";
|
protected static final String DEFINE = "#define";
|
||||||
private static final String CUSTOM = "custom";
|
private static final String CUSTOM = "custom";
|
||||||
private static final String END_STRUCT = "end_struct";
|
private static final String END_STRUCT = "end_struct";
|
||||||
|
@ -44,8 +44,12 @@ public class ReaderState {
|
||||||
bitName = line.substring(0, index);
|
bitName = line.substring(0, index);
|
||||||
comment = line.substring(index + 1);
|
comment = line.substring(index + 1);
|
||||||
}
|
}
|
||||||
|
String bitNameParts[] = bitName.split(",");
|
||||||
|
|
||||||
ConfigField bitField = new ConfigField(state, bitName, comment, null, BOOLEAN_T, 0, null, false, false, null, -1);
|
String trueName = bitNameParts.length > 1 ? bitNameParts[1] : null;
|
||||||
|
String falseName = bitNameParts.length > 2 ? bitNameParts[2] : null;
|
||||||
|
|
||||||
|
ConfigField bitField = new ConfigField(state, bitNameParts[0], comment, null, BOOLEAN_T, 0, null, false, false, null, -1, trueName, falseName);
|
||||||
if (state.stack.isEmpty())
|
if (state.stack.isEmpty())
|
||||||
throw new IllegalStateException("Parent structure expected");
|
throw new IllegalStateException("Parent structure expected");
|
||||||
ConfigStructure structure = state.stack.peek();
|
ConfigStructure structure = state.stack.peek();
|
||||||
|
@ -210,7 +214,7 @@ public class ReaderState {
|
||||||
structure.addC(cf);
|
structure.addC(cf);
|
||||||
for (int i = 1; i <= cf.getArraySize(); i++) {
|
for (int i = 1; i <= cf.getArraySize(); i++) {
|
||||||
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
|
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
|
||||||
cf.getType(), 1, cf.getTsInfo(), false, false, cf.getName(), i);
|
cf.getType(), 1, cf.getTsInfo(), false, false, cf.getName(), i, null, null);
|
||||||
structure.addTs(element);
|
structure.addTs(element);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
||||||
tsHeader.write("= bits, U32, ");
|
tsHeader.write("= bits, U32, ");
|
||||||
tsHeader.write("\t" + tsPosition + ", [");
|
tsHeader.write("\t" + tsPosition + ", [");
|
||||||
tsHeader.write(bitIndex + ":" + bitIndex);
|
tsHeader.write(bitIndex + ":" + bitIndex);
|
||||||
tsHeader.write("], \"false\", \"true\"");
|
tsHeader.write("], \"" + configField.getFalseName() + "\", \"" + configField.getTrueName() + "\"");
|
||||||
tsHeader.write(EOL);
|
tsHeader.write(EOL);
|
||||||
|
|
||||||
tsPosition += configField.getSize(next);
|
tsPosition += configField.getSize(next);
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.rusefi.test;
|
||||||
|
|
||||||
import com.rusefi.ReaderState;
|
import com.rusefi.ReaderState;
|
||||||
import com.rusefi.TsFileContent;
|
import com.rusefi.TsFileContent;
|
||||||
import com.rusefi.output.JavaFieldsConsumer;
|
|
||||||
import com.rusefi.output.TSProjectConsumer;
|
import com.rusefi.output.TSProjectConsumer;
|
||||||
import com.rusefi.util.Output;
|
import com.rusefi.util.Output;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -10,13 +9,16 @@ import org.junit.Test;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class BitParsingTest {
|
public class BitParsingTest {
|
||||||
@Test
|
@Test
|
||||||
public void testBitParser() throws IOException {
|
public void testBitParser() throws IOException {
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
|
|
||||||
String inputString = "struct pid_s\nbit activateAuxPid1;\n" +
|
String inputString = "struct pid_s\n" +
|
||||||
"bit fieldName;\n" +
|
ReaderState.BIT + " fieldName\n" +
|
||||||
|
ReaderState.BIT + " fieldName2,si,nada;comment\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(inputString));
|
BufferedReader reader = new BufferedReader(new StringReader(inputString));
|
||||||
|
|
||||||
|
@ -32,6 +34,8 @@ public class BitParsingTest {
|
||||||
|
|
||||||
System.out.printf("start[" + sw.toString() + "]end");
|
System.out.printf("start[" + sw.toString() + "]end");
|
||||||
|
|
||||||
|
assertTrue(sw.toString().contains("\"false\", \"true\""));
|
||||||
|
assertTrue(sw.toString().contains("\"nada\", \"si\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Output createOutput(StringWriter sw) {
|
private Output createOutput(StringWriter sw) {
|
||||||
|
|
Loading…
Reference in New Issue