mirror of https://github.com/rusefi/rusefi-1.git
clutch input via CAN #3605
This commit is contained in:
parent
ec423ff09e
commit
373e564ea2
|
@ -57,7 +57,6 @@ public class ConfigDefinition {
|
||||||
*/
|
*/
|
||||||
public static boolean needZeroInit = true;
|
public static boolean needZeroInit = true;
|
||||||
public static String definitionInputFile = null;
|
public static String definitionInputFile = null;
|
||||||
private static String fieldLookupFile = null;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
|
@ -104,6 +103,7 @@ public class ConfigDefinition {
|
||||||
// disable the lazy checks because we use timestamps to detect changes
|
// disable the lazy checks because we use timestamps to detect changes
|
||||||
LazyFile.setLazyFileEnabled(true);
|
LazyFile.setLazyFileEnabled(true);
|
||||||
|
|
||||||
|
List<ConfigurationConsumer> destinations = new ArrayList<>();
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
|
|
||||||
for (int i = 0; i < args.length - 1; i += 2) {
|
for (int i = 0; i < args.length - 1; i += 2) {
|
||||||
|
@ -138,7 +138,10 @@ public class ConfigDefinition {
|
||||||
javaDestinationFileName = args[i + 1];
|
javaDestinationFileName = args[i + 1];
|
||||||
break;
|
break;
|
||||||
case "-field_lookup_file":
|
case "-field_lookup_file":
|
||||||
fieldLookupFile = args[i + 1];
|
destinations.add(new GetConfigValueConsumer(args[i + 1]));
|
||||||
|
break;
|
||||||
|
case "-output_lookup_file":
|
||||||
|
destinations.add(new GetOutputValueConsumer(args[i + 1]));
|
||||||
break;
|
break;
|
||||||
case "-readfile":
|
case "-readfile":
|
||||||
String keyName = args[i + 1];
|
String keyName = args[i + 1];
|
||||||
|
@ -254,7 +257,6 @@ 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<>();
|
|
||||||
if (TS_OUTPUTS_DESTINATION != null) {
|
if (TS_OUTPUTS_DESTINATION != null) {
|
||||||
destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_DESTINATION + File.separator + "generated/output_channels.ini", state));
|
destinations.add(new OutputsSectionConsumer(TS_OUTPUTS_DESTINATION + File.separator + "generated/output_channels.ini", state));
|
||||||
destinations.add(new DataLogConsumer(TS_OUTPUTS_DESTINATION + File.separator + "generated/data_logs.ini"));
|
destinations.add(new DataLogConsumer(TS_OUTPUTS_DESTINATION + File.separator + "generated/data_logs.ini"));
|
||||||
|
@ -274,8 +276,6 @@ public class ConfigDefinition {
|
||||||
if (destCHeaderFileName != null) {
|
if (destCHeaderFileName != null) {
|
||||||
destinations.add(new CHeaderConsumer(state.variableRegistry, destCHeaderFileName));
|
destinations.add(new CHeaderConsumer(state.variableRegistry, destCHeaderFileName));
|
||||||
}
|
}
|
||||||
if (fieldLookupFile!=null)
|
|
||||||
destinations.add(new GetConfigValueConsumer(fieldLookupFile));
|
|
||||||
if (javaDestinationFileName != null) {
|
if (javaDestinationFileName != null) {
|
||||||
destinations.add(new FileJavaFieldsConsumer(state, javaDestinationFileName));
|
destinations.add(new FileJavaFieldsConsumer(state, javaDestinationFileName));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,21 +16,21 @@ import static com.rusefi.output.DataLogConsumer.UNUSED;
|
||||||
public class GetConfigValueConsumer extends AbstractConfigurationConsumer {
|
public class GetConfigValueConsumer extends AbstractConfigurationConsumer {
|
||||||
private static final String CONFIG_ENGINE_CONFIGURATION = "config->engineConfiguration.";
|
private static final String CONFIG_ENGINE_CONFIGURATION = "config->engineConfiguration.";
|
||||||
private static final String ENGINE_CONFIGURATION = "engineConfiguration.";
|
private static final String ENGINE_CONFIGURATION = "engineConfiguration.";
|
||||||
private static final String FILE_HEADER = "#include \"pch.h\"\n";
|
static final String FILE_HEADER = "#include \"pch.h\"\n";
|
||||||
private static final String GET_METHOD_HEADER = "float getConfigValueByName(const char *name) {\n";
|
private static final String GET_METHOD_HEADER = "float getConfigValueByName(const char *name) {\n";
|
||||||
private static final String GET_METHOD_FOOTER = "\treturn EFI_ERROR_CODE;\n" + "}\n";
|
static final String GET_METHOD_FOOTER = "\treturn EFI_ERROR_CODE;\n" + "}\n";
|
||||||
private static final String SET_METHOD_HEADER = "void setConfigValueByName(const char *name, float value) {\n";
|
private static final String SET_METHOD_HEADER = "void setConfigValueByName(const char *name, float value) {\n";
|
||||||
private static final String SET_METHOD_FOOTER = "}\n";
|
private static final String SET_METHOD_FOOTER = "}\n";
|
||||||
private final StringBuilder getterBody = new StringBuilder();
|
private final StringBuilder getterBody = new StringBuilder();
|
||||||
private final StringBuilder setterBody = new StringBuilder();
|
private final StringBuilder setterBody = new StringBuilder();
|
||||||
private final String outputFIleName;
|
private final String outputFileName;
|
||||||
|
|
||||||
public GetConfigValueConsumer(String outputFIleName) {
|
public GetConfigValueConsumer(String outputFileName) {
|
||||||
System.out.println("Hello " + getClass() + " " + outputFIleName);
|
System.out.println("Hello " + getClass() + " " + outputFileName);
|
||||||
this.outputFIleName = outputFIleName;
|
this.outputFileName = outputFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeStringToFile(@Nullable String fileName, String content) throws IOException {
|
public static void writeStringToFile(@Nullable String fileName, String content) throws IOException {
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
FileWriter fw = new FileWriter(fileName);
|
FileWriter fw = new FileWriter(fileName);
|
||||||
fw.write(content);
|
fw.write(content);
|
||||||
|
@ -42,7 +42,7 @@ public class GetConfigValueConsumer extends AbstractConfigurationConsumer {
|
||||||
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
|
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
|
||||||
if (state.stack.isEmpty()) {
|
if (state.stack.isEmpty()) {
|
||||||
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
|
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
|
||||||
this::process, ".");
|
this::processConfig, ".");
|
||||||
iterator.loop();
|
iterator.loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,10 @@ public class GetConfigValueConsumer extends AbstractConfigurationConsumer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endFile() throws IOException {
|
public void endFile() throws IOException {
|
||||||
writeStringToFile(outputFIleName, getContent());
|
writeStringToFile(outputFileName, getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String process(ReaderState readerState, ConfigField cf, String prefix) {
|
private String processConfig(ReaderState readerState, ConfigField cf, String prefix) {
|
||||||
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
|
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public class GetConfigValueConsumer extends AbstractConfigurationConsumer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String getCompareName(String userName) {
|
static String getCompareName(String userName) {
|
||||||
return "\tif (strEqualCaseInsensitive(name, \"" + userName + "\"))\n";
|
return "\tif (strEqualCaseInsensitive(name, \"" + userName + "\"))\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.rusefi.output;
|
||||||
|
|
||||||
|
import com.rusefi.ConfigField;
|
||||||
|
import com.rusefi.ReaderState;
|
||||||
|
import com.rusefi.TypesHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static com.rusefi.output.ConfigStructure.ALIGNMENT_FILL_AT;
|
||||||
|
import static com.rusefi.output.DataLogConsumer.UNUSED;
|
||||||
|
import static com.rusefi.output.GetConfigValueConsumer.FILE_HEADER;
|
||||||
|
import static com.rusefi.output.GetConfigValueConsumer.getCompareName;
|
||||||
|
|
||||||
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
|
public class GetOutputValueConsumer extends AbstractConfigurationConsumer {
|
||||||
|
private final StringBuilder getterBody = new StringBuilder();
|
||||||
|
private final String fileName;
|
||||||
|
|
||||||
|
public GetOutputValueConsumer(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
|
||||||
|
if (state.stack.isEmpty()) {
|
||||||
|
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
|
||||||
|
this::processOutput, ".");
|
||||||
|
iterator.loop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String processOutput(ReaderState readerState, ConfigField cf, String prefix) {
|
||||||
|
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if (cf.isArray() || cf.isFromIterate() || cf.isDirective())
|
||||||
|
return "";
|
||||||
|
if (!TypesHelper.isPrimitive(cf.getType())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String userName = prefix + cf.getName();
|
||||||
|
String javaName = "tsOutputChannels->" + prefix;
|
||||||
|
|
||||||
|
getterBody.append(getCompareName(userName));
|
||||||
|
getterBody.append("\t\treturn " + javaName + cf.getName() + ";\n");
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endFile() throws IOException {
|
||||||
|
GetConfigValueConsumer.writeStringToFile(fileName, getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return FILE_HEADER +
|
||||||
|
"float getOutputValueByName(const char *name) {\n" + getterBody + GetConfigValueConsumer.GET_METHOD_FOOTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,10 +2,7 @@ package com.rusefi.test;
|
||||||
|
|
||||||
import com.rusefi.BitState;
|
import com.rusefi.BitState;
|
||||||
import com.rusefi.ReaderState;
|
import com.rusefi.ReaderState;
|
||||||
import com.rusefi.output.DataLogConsumer;
|
import com.rusefi.output.*;
|
||||||
import com.rusefi.output.GaugeConsumer;
|
|
||||||
import com.rusefi.output.GetConfigValueConsumer;
|
|
||||||
import com.rusefi.output.OutputsSectionConsumer;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -115,6 +112,26 @@ public class OutputsTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateGetOutputs() throws IOException {
|
||||||
|
String test = "struct_no_prefix ts_outputs_s\n" +
|
||||||
|
"bit issue_294_31,\"si_example\",\"nada_example\"\n" +
|
||||||
|
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
|
||||||
|
"int hwChannel;\n" +
|
||||||
|
"end_struct\n";
|
||||||
|
ReaderState state = new ReaderState();
|
||||||
|
|
||||||
|
GetOutputValueConsumer outputValueConsumer = new GetOutputValueConsumer(null);
|
||||||
|
state.readBufferedReader(test, Collections.singletonList(outputValueConsumer));
|
||||||
|
assertEquals(
|
||||||
|
"#include \"pch.h\"\n" +
|
||||||
|
"float getOutputValueByName(const char *name) {\n" +
|
||||||
|
"\tif (strEqualCaseInsensitive(name, \"hwChannel\"))\n" +
|
||||||
|
"\t\treturn tsOutputChannels->hwChannel;\n" +
|
||||||
|
"\treturn EFI_ERROR_CODE;\n" +
|
||||||
|
"}\n", outputValueConsumer.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStructArrayAndCharArgument() throws IOException {
|
public void testStructArrayAndCharArgument() throws IOException {
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
|
|
Loading…
Reference in New Issue