automation around outputs section #197

refactoring: extract helper class & poke
This commit is contained in:
rusefillc 2021-11-28 13:13:13 -05:00
parent abcffad9be
commit 37e0a6b8d4
11 changed files with 67 additions and 18 deletions

View File

@ -3879,3 +3879,4 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
#else #else
addTool = afrTableGenerator, "AFR Table Generator", afrTableTbl addTool = afrTableGenerator, "AFR Table Generator", afrTableTbl
#endif #endif

Binary file not shown.

View File

@ -287,6 +287,7 @@ public class ConfigDefinition {
List<ConfigurationConsumer> destinations = new ArrayList<>(); List<ConfigurationConsumer> destinations = new ArrayList<>();
if (TS_OUTPUTS_SECTION != null) { if (TS_OUTPUTS_SECTION != null) {
destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_SECTION, state)); destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_SECTION, state));
destinations.add(new DataLogConsumer(state));
} }
if (tsInputFileFolder != null && needToUpdateTsFiles) { if (tsInputFileFolder != null && needToUpdateTsFiles) {
CharArrayWriter tsWriter = new CharArrayWriter(); CharArrayWriter tsWriter = new CharArrayWriter();

View File

@ -3,6 +3,7 @@ package com.rusefi;
import com.opensr5.ini.RawIniFile; import com.opensr5.ini.RawIniFile;
import com.opensr5.ini.field.EnumIniField; import com.opensr5.ini.field.EnumIniField;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import com.rusefi.output.ConfigStructure;
import com.rusefi.output.ConfigurationConsumer; import com.rusefi.output.ConfigurationConsumer;
import com.rusefi.util.SystemOut; import com.rusefi.util.SystemOut;

View File

@ -51,14 +51,13 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
int currentOffset = 0; int currentOffset = 0;
BitState bitState = new BitState(); FieldIterator iterator = new FieldIterator(structure.cFields);
for (int i = 0; i < structure.cFields.size(); i++) { for (int i = 0; i < structure.cFields.size(); i++) {
ConfigField cf = structure.cFields.get(i); iterator.start(i);
content.append(BaseCHeaderConsumer.getHeaderText(cf, currentOffset, bitState.get())); content.append(BaseCHeaderConsumer.getHeaderText(iterator.cf, currentOffset, iterator.bitState.get()));
ConfigField next = i == structure.cFields.size() - 1 ? ConfigField.VOID : structure.cFields.get(i + 1);
bitState.incrementBitIndex(cf, next); currentOffset += iterator.cf.getSize(iterator.next);
currentOffset += cf.getSize(next); iterator.end();
} }
content.append("\t/** total size " + currentOffset + "*/" + EOL); content.append("\t/** total size " + currentOffset + "*/" + EOL);

View File

@ -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.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -43,7 +46,7 @@ public class ConfigStructure {
this.withConstructor = withConstructor; this.withConstructor = withConstructor;
} }
void addBitField(ConfigField bitField) { public void addBitField(ConfigField bitField) {
addBoth(bitField); addBoth(bitField);
this.readingBitState.incrementBitIndex(bitField); this.readingBitState.incrementBitIndex(bitField);
} }
@ -57,17 +60,16 @@ public class ConfigStructure {
} }
public void addAlignmentFill(ReaderState state) { 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 * we make alignment decision based on C fields since we expect iteration and non-iteration fields
* to match in size * to match in size
*/ */
totalSize = 0; totalSize = 0;
FieldIterator iterator = new FieldIterator(cFields);
for (int i = 0; i < cFields.size(); i++) { for (int i = 0; i < cFields.size(); i++) {
ConfigField cf = cFields.get(i); iterator.start(i);
ConfigField next = i == cFields.size() - 1 ? ConfigField.VOID : cFields.get(i + 1); iterator.end();
bitState.incrementBitIndex(cf, next); totalSize += iterator.cf.getSize(iterator.next);
totalSize += cf.getSize(next);
} }
int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4); int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4);

View File

@ -1,7 +1,5 @@
package com.rusefi.output; package com.rusefi.output;
import com.rusefi.ConfigStructure;
import java.io.IOException; import java.io.IOException;
public interface ConfigurationConsumer { public interface ConfigurationConsumer {

View File

@ -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()) {
}
}
}

View File

@ -1,7 +1,6 @@
package com.rusefi.output; package com.rusefi.output;
import com.rusefi.ConfigField; import com.rusefi.ConfigField;
import com.rusefi.ConfigStructure;
import com.rusefi.ReaderState; import com.rusefi.ReaderState;
import java.io.CharArrayWriter; import java.io.CharArrayWriter;

View File

@ -1,6 +1,5 @@
package com.rusefi.output; package com.rusefi.output;
import com.rusefi.ConfigStructure;
import com.rusefi.ReaderState; import com.rusefi.ReaderState;
import java.io.*; import java.io.*;

View File

@ -2,6 +2,7 @@ package com.rusefi.test;
import com.rusefi.ReaderState; import com.rusefi.ReaderState;
import com.rusefi.output.ConfigurationConsumer; import com.rusefi.output.ConfigurationConsumer;
import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.OutputsSectionConsumer; import com.rusefi.output.OutputsSectionConsumer;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; 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())); "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));
}
} }