automation around outputs section #197
refactoring: extract helper class & poke
This commit is contained in:
parent
a6800cd384
commit
d76d0f3326
|
@ -3879,3 +3879,4 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
|
|||
#else
|
||||
addTool = afrTableGenerator, "AFR Table Generator", afrTableTbl
|
||||
#endif
|
||||
|
||||
|
|
Binary file not shown.
|
@ -287,6 +287,7 @@ public class ConfigDefinition {
|
|||
List<ConfigurationConsumer> destinations = new ArrayList<>();
|
||||
if (TS_OUTPUTS_SECTION != null) {
|
||||
destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_SECTION, state));
|
||||
destinations.add(new DataLogConsumer(state));
|
||||
}
|
||||
if (tsInputFileFolder != null && needToUpdateTsFiles) {
|
||||
CharArrayWriter tsWriter = new CharArrayWriter();
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi;
|
|||
import com.opensr5.ini.RawIniFile;
|
||||
import com.opensr5.ini.field.EnumIniField;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.output.ConfigStructure;
|
||||
import com.rusefi.output.ConfigurationConsumer;
|
||||
import com.rusefi.util.SystemOut;
|
||||
|
||||
|
|
|
@ -51,14 +51,13 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
|
|||
|
||||
int currentOffset = 0;
|
||||
|
||||
BitState bitState = new BitState();
|
||||
FieldIterator iterator = new FieldIterator(structure.cFields);
|
||||
for (int i = 0; i < structure.cFields.size(); i++) {
|
||||
ConfigField cf = structure.cFields.get(i);
|
||||
content.append(BaseCHeaderConsumer.getHeaderText(cf, currentOffset, bitState.get()));
|
||||
ConfigField next = i == structure.cFields.size() - 1 ? ConfigField.VOID : structure.cFields.get(i + 1);
|
||||
iterator.start(i);
|
||||
content.append(BaseCHeaderConsumer.getHeaderText(iterator.cf, currentOffset, iterator.bitState.get()));
|
||||
|
||||
bitState.incrementBitIndex(cf, next);
|
||||
currentOffset += cf.getSize(next);
|
||||
currentOffset += iterator.cf.getSize(iterator.next);
|
||||
iterator.end();
|
||||
}
|
||||
|
||||
content.append("\t/** total size " + currentOffset + "*/" + EOL);
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.rusefi;
|
||||
package com.rusefi.output;
|
||||
|
||||
import com.fathzer.soft.javaluator.Parameters;
|
||||
import com.rusefi.BitState;
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -43,7 +46,7 @@ public class ConfigStructure {
|
|||
this.withConstructor = withConstructor;
|
||||
}
|
||||
|
||||
void addBitField(ConfigField bitField) {
|
||||
public void addBitField(ConfigField bitField) {
|
||||
addBoth(bitField);
|
||||
this.readingBitState.incrementBitIndex(bitField);
|
||||
}
|
||||
|
@ -57,17 +60,16 @@ public class ConfigStructure {
|
|||
}
|
||||
|
||||
public void addAlignmentFill(ReaderState state) {
|
||||
BitState bitState = new BitState();
|
||||
/**
|
||||
* we make alignment decision based on C fields since we expect iteration and non-iteration fields
|
||||
* to match in size
|
||||
*/
|
||||
totalSize = 0;
|
||||
FieldIterator iterator = new FieldIterator(cFields);
|
||||
for (int i = 0; i < cFields.size(); i++) {
|
||||
ConfigField cf = cFields.get(i);
|
||||
ConfigField next = i == cFields.size() - 1 ? ConfigField.VOID : cFields.get(i + 1);
|
||||
bitState.incrementBitIndex(cf, next);
|
||||
totalSize += cf.getSize(next);
|
||||
iterator.start(i);
|
||||
iterator.end();
|
||||
totalSize += iterator.cf.getSize(iterator.next);
|
||||
}
|
||||
|
||||
int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4);
|
|
@ -1,7 +1,5 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigStructure;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ConfigurationConsumer {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DataLogConsumer implements ConfigurationConsumer {
|
||||
private final ReaderState state;
|
||||
|
||||
public DataLogConsumer(ReaderState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFile() throws IOException {
|
||||
System.out.println("startFile");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endFile() throws IOException {
|
||||
System.out.println("endFile");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEndStruct(ConfigStructure structure) throws IOException {
|
||||
if (state.stack.isEmpty()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigStructure;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigStructure;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.*;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.test;
|
|||
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.output.ConfigurationConsumer;
|
||||
import com.rusefi.output.DataLogConsumer;
|
||||
import com.rusefi.output.OutputsSectionConsumer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -65,4 +66,20 @@ public class OutputsTest {
|
|||
"alignmentFill_at_9 = array, U08, 9, [3], \"units\", 1, 0\n", new String(tsProjectConsumer.getTsWriter().toCharArray()));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateDataLog() throws IOException {
|
||||
String test = "struct total\n" +
|
||||
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"uint8_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"bit isForcedInduction;Does the vehicle have a turbo or supercharger?\n" +
|
||||
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
|
||||
"end_struct\n";
|
||||
ReaderState state = new ReaderState();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
||||
|
||||
DataLogConsumer dataLogConsumer = new DataLogConsumer(state);
|
||||
state.readBufferedReader(reader, Collections.singletonList(dataLogConsumer));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue