parent
07d8ac77bc
commit
359ff68778
|
@ -20,6 +20,7 @@ import static com.rusefi.ConfigField.BOOLEAN_T;
|
|||
*/
|
||||
public class ConfigStructure {
|
||||
public static final String ALIGNMENT_FILL_AT = "alignmentFill_at_";
|
||||
public static final String UNUSED_BIT_PREFIX = "unusedBit_";
|
||||
|
||||
public final String name;
|
||||
public final String comment;
|
||||
|
@ -114,7 +115,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, false, null, null);
|
||||
ConfigField bitField = new ConfigField(readerState, UNUSED_BIT_PREFIX + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, false, null, null);
|
||||
addBitField(bitField);
|
||||
}
|
||||
readingBitState.reset();
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FragmentDialogConsumer implements ConfigurationConsumer {
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
|
||||
private final StringBuilder indicatorPanel = new StringBuilder();
|
||||
private final String fragmentName;
|
||||
private boolean hasIndicators;
|
||||
|
||||
public FragmentDialogConsumer(String fragmentName) {
|
||||
this.fragmentName = fragmentName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFile() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endFile() throws IOException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
@Override
|
||||
int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex, ConfigField prev) throws IOException {
|
||||
if (configField.getName().startsWith(ConfigStructure.UNUSED_BIT_PREFIX))
|
||||
return 0;
|
||||
|
||||
if (configField.isBit()) {
|
||||
|
||||
if (!hasIndicators) {
|
||||
hasIndicators = true;
|
||||
indicatorPanel.append("indicatorPanel = " +
|
||||
fragmentName +
|
||||
"IndicatorPanel, 2\n");
|
||||
}
|
||||
indicatorPanel.append("indicator = {" + configField.getName() + "}, \"No\", \"Yes\"\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
fieldsStrategy.run(readerState, structure);
|
||||
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return indicatorPanel + sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.output.FragmentDialogConsumer;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class FragmentDialogConsumerTest {
|
||||
@Test
|
||||
public void generateFragmentDialog() throws IOException {
|
||||
ReaderState state = new ReaderState();
|
||||
String outputChannels = "" +
|
||||
"\n" +
|
||||
"" +
|
||||
"struct_no_prefix output_channels_s\n" +
|
||||
"bit sd_present\n" +
|
||||
"bit sd_present2\n" +
|
||||
"bit sd_present3\n" +
|
||||
"uint16_t autoscale RPMValue;;\"RPM\",1, 0, 0, 8000, 0\n" +
|
||||
"uint16_t rpmAcceleration;dRPM;\"RPM/s\",1, 0, 0, 5, 0\n" +
|
||||
"\tuint16_t autoscale speedToRpmRatio;;\"value\",{1/1}, 0, 0, 0, 0\n" +
|
||||
" float luaTimingMult;\n" +
|
||||
"\tuint8_t vehicleSpeedKph\n" +
|
||||
"\tint8_t autoscale internalMcuTemperature;mcu;\"deg C\",1, 0, 0, 0, 0\n" +
|
||||
"end_struct\n";
|
||||
|
||||
FragmentDialogConsumer fragmentDialogConsumer = new FragmentDialogConsumer("ac_state");
|
||||
|
||||
state.readBufferedReader(outputChannels, fragmentDialogConsumer);
|
||||
|
||||
assertEquals("indicatorPanel = ac_stateIndicatorPanel, 2\n" +
|
||||
"indicator = {sd_present}, \"No\", \"Yes\"\n" +
|
||||
"indicator = {sd_present2}, \"No\", \"Yes\"\n" +
|
||||
"indicator = {sd_present3}, \"No\", \"Yes\"\n",
|
||||
fragmentDialogConsumer.getContent());
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue