mirror of https://github.com/rusefi/rusefi-1.git
parent
99716d83a9
commit
8674a8b830
Binary file not shown.
|
@ -30,7 +30,7 @@ import java.util.zip.CRC32;
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
public class ConfigDefinition {
|
public class ConfigDefinition {
|
||||||
private static final String SIGNATURE_HASH = "SIGNATURE_HASH";
|
private static final String SIGNATURE_HASH = "SIGNATURE_HASH";
|
||||||
private static String TS_OUTPUTS_SECTION = null;
|
private static String TS_OUTPUTS_DESTINATION = null;
|
||||||
public static String MESSAGE;
|
public static String MESSAGE;
|
||||||
|
|
||||||
private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml";
|
private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml";
|
||||||
|
@ -132,7 +132,7 @@ public class ConfigDefinition {
|
||||||
tsInputFileFolder = args[i + 1];
|
tsInputFileFolder = args[i + 1];
|
||||||
break;
|
break;
|
||||||
case "-ts_outputs_section":
|
case "-ts_outputs_section":
|
||||||
TS_OUTPUTS_SECTION = args[i + 1];
|
TS_OUTPUTS_DESTINATION = args[i + 1];
|
||||||
break;
|
break;
|
||||||
case KEY_C_DESTINATION:
|
case KEY_C_DESTINATION:
|
||||||
destCHeaderFileName = args[i + 1];
|
destCHeaderFileName = args[i + 1];
|
||||||
|
@ -285,9 +285,9 @@ public class ConfigDefinition {
|
||||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
||||||
|
|
||||||
List<ConfigurationConsumer> destinations = new ArrayList<>();
|
List<ConfigurationConsumer> destinations = new ArrayList<>();
|
||||||
if (TS_OUTPUTS_SECTION != null) {
|
if (TS_OUTPUTS_DESTINATION != null) {
|
||||||
destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_SECTION, state));
|
destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_DESTINATION + File.separator + "output_channels.ini", state));
|
||||||
destinations.add(new DataLogConsumer(state));
|
destinations.add(new DataLogConsumer(TS_OUTPUTS_DESTINATION + File.separator + "data_logs.ini", state));
|
||||||
}
|
}
|
||||||
if (tsInputFileFolder != null && needToUpdateTsFiles) {
|
if (tsInputFileFolder != null && needToUpdateTsFiles) {
|
||||||
CharArrayWriter tsWriter = new CharArrayWriter();
|
CharArrayWriter tsWriter = new CharArrayWriter();
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ConfigField {
|
||||||
private final String tsInfo;
|
private final String tsInfo;
|
||||||
private final boolean isIterate;
|
private final boolean isIterate;
|
||||||
private final ReaderState state;
|
private final ReaderState state;
|
||||||
private boolean fsioVisible;
|
private final boolean fsioVisible;
|
||||||
private final boolean hasAutoscale;
|
private final boolean hasAutoscale;
|
||||||
private final String individualName;
|
private final String individualName;
|
||||||
private final int indexWithinArray;
|
private final int indexWithinArray;
|
||||||
|
|
|
@ -8,7 +8,7 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
|
||||||
private static final String BOOLEAN_TYPE = "bool";
|
private static final String BOOLEAN_TYPE = "bool";
|
||||||
private final StringBuilder content = new StringBuilder();
|
private final StringBuilder content = new StringBuilder();
|
||||||
|
|
||||||
public static String getHeaderText(ConfigField configField, int currentOffset, int bitIndex) {
|
private static String getHeaderText(ConfigField configField, int currentOffset, int bitIndex) {
|
||||||
if (configField.isBit()) {
|
if (configField.isBit()) {
|
||||||
String comment = "\t/**" + EOL + ConfigDefinition.packComment(configField.getCommentContent(), "\t") + "\toffset " + currentOffset + " bit " + bitIndex + " */" + EOL;
|
String comment = "\t/**" + EOL + ConfigDefinition.packComment(configField.getCommentContent(), "\t") + "\toffset " + currentOffset + " bit " + bitIndex + " */" + EOL;
|
||||||
return comment + "\t" + BOOLEAN_TYPE + " " + configField.getName() + " : 1 {};" + EOL;
|
return comment + "\t" + BOOLEAN_TYPE + " " + configField.getName() + " : 1 {};" + EOL;
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
package com.rusefi.output;
|
package com.rusefi.output;
|
||||||
|
|
||||||
|
import com.rusefi.ConfigField;
|
||||||
import com.rusefi.ReaderState;
|
import com.rusefi.ReaderState;
|
||||||
|
import com.rusefi.TypesHelper;
|
||||||
|
|
||||||
|
import java.io.CharArrayWriter;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class DataLogConsumer implements ConfigurationConsumer {
|
import static org.abego.treelayout.internal.util.java.lang.string.StringUtil.quote;
|
||||||
private final ReaderState state;
|
|
||||||
|
|
||||||
public DataLogConsumer(ReaderState state) {
|
public class DataLogConsumer implements ConfigurationConsumer {
|
||||||
|
private final String fileName;
|
||||||
|
private final ReaderState state;
|
||||||
|
private final CharArrayWriter tsWriter = new CharArrayWriter();
|
||||||
|
|
||||||
|
public DataLogConsumer(String fileName, ReaderState state) {
|
||||||
|
this.fileName = fileName;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +36,52 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
||||||
public void handleEndStruct(ConfigStructure structure) throws IOException {
|
public void handleEndStruct(ConfigStructure structure) throws IOException {
|
||||||
if (state.stack.isEmpty()) {
|
if (state.stack.isEmpty()) {
|
||||||
|
|
||||||
|
FieldIterator iterator = new FieldIterator(structure.tsFields);
|
||||||
|
for (int i = 0; i < structure.tsFields.size(); i++) {
|
||||||
|
iterator.start(i);
|
||||||
|
|
||||||
|
tsWriter.append(handle(iterator.cf));
|
||||||
|
|
||||||
|
iterator.end();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileName != null) {
|
||||||
|
FileWriter fw = new FileWriter(fileName);
|
||||||
|
fw.write(tsWriter.toCharArray());
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String handle(ConfigField configField) {
|
||||||
|
if (configField.isBit()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configField.isArray()) {
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// entry = seconds, @@GAUGE_NAME_UPTIME@@,
|
||||||
|
// entry = RPMValue, @@GAUGE_NAME_RPM@@,
|
||||||
|
|
||||||
|
String typeString;
|
||||||
|
String autoscaleSpec = configField.autoscaleSpec();
|
||||||
|
if (TypesHelper.isFloat(configField.getType()) || (autoscaleSpec != null && !autoscaleSpec.equals("1, 1"))) {
|
||||||
|
typeString = "float, \"%.3f\"";
|
||||||
|
} else {
|
||||||
|
typeString = "int, \"%d\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
String comment = state.variableRegistry.applyVariables(configField.getComment());
|
||||||
|
if (comment.isEmpty() || comment.charAt(0) != '"')
|
||||||
|
comment = quote(comment);
|
||||||
|
|
||||||
|
return "entry = " + configField.getName() + ", " + comment + ", " + typeString + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public CharArrayWriter getTsWriter() {
|
||||||
|
return tsWriter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package com.rusefi.output;
|
package com.rusefi.output;
|
||||||
|
|
||||||
import com.opensr5.ini.field.IniField;
|
import com.opensr5.ini.field.IniField;
|
||||||
import com.rusefi.*;
|
import com.rusefi.ConfigField;
|
||||||
|
import com.rusefi.ReaderState;
|
||||||
|
import com.rusefi.TypesHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.rusefi.ToolUtil.EOL;
|
import static com.rusefi.ToolUtil.EOL;
|
||||||
|
|
||||||
|
@ -100,10 +101,9 @@ public class TsOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Writer tsHeader, int tsPosition) throws IOException {
|
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Writer tsHeader, int tsPosition) throws IOException {
|
||||||
List<ConfigField> tsFields = configStructure.tsFields;
|
FieldIterator iterator = new FieldIterator(configStructure.tsFields);
|
||||||
FieldIterator iterator = new FieldIterator(tsFields);
|
|
||||||
int prevTsPosition = tsPosition;
|
int prevTsPosition = tsPosition;
|
||||||
for (int i = 0; i < tsFields.size(); i++) {
|
for (int i = 0; i < configStructure.tsFields.size(); i++) {
|
||||||
iterator.start(i);
|
iterator.start(i);
|
||||||
|
|
||||||
// if duplicate names, use previous position
|
// if duplicate names, use previous position
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
package com.rusefi.test;
|
package com.rusefi.test;
|
||||||
|
|
||||||
import com.rusefi.ReaderState;
|
import com.rusefi.ReaderState;
|
||||||
import com.rusefi.output.ConfigurationConsumer;
|
|
||||||
import com.rusefi.output.DataLogConsumer;
|
import com.rusefi.output.DataLogConsumer;
|
||||||
import com.rusefi.output.OutputsSectionConsumer;
|
import com.rusefi.output.OutputsSectionConsumer;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.CharArrayWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class OutputsTest {
|
public class OutputsTest {
|
||||||
@Test
|
@Test
|
||||||
public void generateSomething() throws IOException {
|
public void generateSomething() throws IOException {
|
||||||
|
@ -29,7 +26,7 @@ public class OutputsTest {
|
||||||
state.readBufferedReader(reader, Collections.singletonList(tsProjectConsumer));
|
state.readBufferedReader(reader, Collections.singletonList(tsProjectConsumer));
|
||||||
|
|
||||||
|
|
||||||
Assert.assertEquals("afr_type = scalar, F32, 0, \"ms\", 1, 0\n" +
|
assertEquals("afr_type = scalar, F32, 0, \"ms\", 1, 0\n" +
|
||||||
"afr_typet = scalar, U08, 4, \"ms\", 1, 0\n" +
|
"afr_typet = scalar, U08, 4, \"ms\", 1, 0\n" +
|
||||||
"isForcedInduction = bits, U32, 5, [0:0]\n" +
|
"isForcedInduction = bits, U32, 5, [0:0]\n" +
|
||||||
"enableFan1WithAc = bits, U32, 5, [1:1]\n" +
|
"enableFan1WithAc = bits, U32, 5, [1:1]\n" +
|
||||||
|
@ -71,15 +68,22 @@ public class OutputsTest {
|
||||||
public void generateDataLog() throws IOException {
|
public void generateDataLog() throws IOException {
|
||||||
String test = "struct total\n" +
|
String test = "struct total\n" +
|
||||||
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
|
"uint16_t autoscale speedToRpmRatio;s2rpm;\"value\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
|
||||||
"uint8_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
"uint8_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
|
"uint8_t autoscale vehicleSpeedKph;;\"kph\",1, 0, 0, 0, 0\n" +
|
||||||
"bit isForcedInduction;Does the vehicle have a turbo or supercharger?\n" +
|
"bit isForcedInduction;Does the vehicle have a turbo or supercharger?\n" +
|
||||||
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
|
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
|
state.variableRegistry.register("PACK_MULT_PERCENT", 100);
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
BufferedReader reader = new BufferedReader(new StringReader(test));
|
||||||
|
|
||||||
DataLogConsumer dataLogConsumer = new DataLogConsumer(state);
|
DataLogConsumer dataLogConsumer = new DataLogConsumer(null, state);
|
||||||
state.readBufferedReader(reader, Collections.singletonList(dataLogConsumer));
|
state.readBufferedReader(reader, Collections.singletonList(dataLogConsumer));
|
||||||
|
assertEquals("entry = afr_type, \"PID dTime\", float, \"%.3f\"\n" +
|
||||||
|
"entry = speedToRpmRatio, \"s2rpm\", float, \"%.3f\"\n" +
|
||||||
|
"entry = afr_typet, \"PID dTime\", int, \"%d\"\n" +
|
||||||
|
"entry = vehicleSpeedKph, \"\", int, \"%d\"\n", new String(dataLogConsumer.getTsWriter().toCharArray()));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue