Delayed A/C compressor switch #922
This commit is contained in:
parent
01669b7327
commit
fdf4049679
|
@ -0,0 +1,66 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigStructure;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FsioSettingsConsumer implements ConfigurationConsumer {
|
||||
private final CharArrayWriter content = new CharArrayWriter();
|
||||
private final CharArrayWriter enumDefinition = new CharArrayWriter();
|
||||
private final ReaderState state;
|
||||
|
||||
private int currentIndex = 1000;
|
||||
|
||||
public FsioSettingsConsumer(ReaderState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
public String getEnumDefinition() {
|
||||
return enumDefinition.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEndStruct(ConfigStructure structure) {
|
||||
if (state.stack.isEmpty()) {
|
||||
handleFields(structure.tsFields, "");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFields(List<ConfigField> tsFields, String prefix) {
|
||||
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
ConfigField cf = tsFields.get(i);
|
||||
writeOneField(cf, prefix);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void writeOneField(ConfigField configField, String prefix) {
|
||||
ConfigStructure cs = configField.getState().structures.get(configField.getType());
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
handleFields(cs.tsFields, prefix + extraPrefix);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (configField.isFsioVisible()) {
|
||||
|
||||
String nameWithPrefix = prefix + configField.getName();
|
||||
|
||||
enumDefinition.append("FSIO_SETTING_" + nameWithPrefix.toUpperCase() + " = " + currentIndex++ + ",\n");
|
||||
|
||||
|
||||
content.append(nameWithPrefix + "\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -39,14 +39,14 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
ConfigField next = i == tsFields.size() - 1 ? ConfigField.VOID : tsFields.get(i + 1);
|
||||
ConfigField cf = tsFields.get(i);
|
||||
tsPosition = writeJavaFields(cf, prefix, tsPosition, next, bitState.get());
|
||||
tsPosition = writeOneField(cf, prefix, tsPosition, next, bitState.get());
|
||||
|
||||
bitState.incrementBitIndex(cf, next);
|
||||
}
|
||||
return tsPosition;
|
||||
}
|
||||
|
||||
private int writeJavaFields(ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex) throws IOException {
|
||||
private int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex) throws IOException {
|
||||
ConfigStructure cs = configField.getState().structures.get(configField.getType());
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.rusefi.test;
|
|||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.VariableRegistry;
|
||||
import com.rusefi.output.ConfigurationConsumer;
|
||||
import com.rusefi.output.FsioSettingsConsumer;
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -69,7 +69,18 @@ public class ConfigFieldParserTest {
|
|||
}
|
||||
};
|
||||
|
||||
state.readBufferedReader(reader, Collections.<ConfigurationConsumer>singletonList(javaFieldsConsumer));
|
||||
|
||||
FsioSettingsConsumer fsioSettingsConsumer = new FsioSettingsConsumer(state) {
|
||||
@Override
|
||||
public void startFile() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endFile() {
|
||||
}
|
||||
};
|
||||
|
||||
state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer, fsioSettingsConsumer));
|
||||
|
||||
|
||||
assertEquals(javaFieldsConsumer.getJavaFieldsWriter(), "\tpublic static final Field OFFSET = Field.create(\"OFFSET\", 0, FieldType.INT16);\n" +
|
||||
|
@ -82,10 +93,21 @@ public class ConfigFieldParserTest {
|
|||
"\tpublic static final Field ETB_PERIODMS = Field.create(\"ETB_PERIODMS\", 10, FieldType.INT16);\n" +
|
||||
"\tpublic static final Field ETB_MINVALUE = Field.create(\"ETB_MINVALUE\", 12, FieldType.INT16);\n");
|
||||
|
||||
assertEquals(fsioSettingsConsumer.getContent(), "offset\n" +
|
||||
"minValue\n" +
|
||||
"alternatorControl_offset\n" +
|
||||
"alternatorControl_minValue\n" +
|
||||
"etb_offset\n" +
|
||||
"etb_minValue\n");
|
||||
|
||||
|
||||
assertEquals(fsioSettingsConsumer.getEnumDefinition(),
|
||||
"FSIO_SETTING_OFFSET = 1000,\n" +
|
||||
"FSIO_SETTING_MINVALUE = 1001,\n" +
|
||||
"FSIO_SETTING_ALTERNATORCONTROL_OFFSET = 1002,\n" +
|
||||
"FSIO_SETTING_ALTERNATORCONTROL_MINVALUE = 1003,\n" +
|
||||
"FSIO_SETTING_ETB_OFFSET = 1004,\n" +
|
||||
"FSIO_SETTING_ETB_MINVALUE = 1005,\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue