diff --git a/firmware/.gitignore b/firmware/.gitignore index 4dde7496f3..02c65c8d52 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -1,2 +1,5 @@ openocd benchmark.txt +gen_config.log +gen_config_board.log +gen_enum_to_string.log diff --git a/firmware/controllers/algo/auto_generated_enums.cpp b/firmware/controllers/algo/auto_generated_enums.cpp index 77f6413a8e..6c3c8f6b7f 100644 --- a/firmware/controllers/algo/auto_generated_enums.cpp +++ b/firmware/controllers/algo/auto_generated_enums.cpp @@ -1,10 +1,10 @@ #include "global.h" #include "rusefi_enums.h" #include "rusefi_hw_enums.h" -// auto-generated from rusefi_hw_enums.h -// auto-generated from rusefi_enums.h +// was generated automatically by rusEfi tool from rusefi_hw_enums.h +// was generated automatically by rusEfi tool from rusefi_enums.h // by enum2string.jar tool -// on Tue Jun 04 12:17:32 EDT 2019 +// on Mon Jun 17 19:49:25 EDT 2019 // see also gen_config_and_enums.bat @@ -533,8 +533,6 @@ case Force_4_bytes_size_cranking_ignition_mode: } const char *getDebug_mode_e(debug_mode_e value){ switch(value) { -case DBG_ETB_LOGIC: - return "DBG_ETB_LOGIC"; case DBG_36: return "DBG_36"; case DBG_37: @@ -567,6 +565,8 @@ case DBG_ELECTRONIC_THROTTLE_PID: return "DBG_ELECTRONIC_THROTTLE_PID"; case DBG_EL_ACCEL: return "DBG_EL_ACCEL"; +case DBG_ETB_LOGIC: + return "DBG_ETB_LOGIC"; case DBG_EXECUTOR: return "DBG_EXECUTOR"; case DBG_FSIO_ADC: @@ -751,6 +751,8 @@ case MIATA_NA6_MAP: return "MIATA_NA6_MAP"; case MIATA_NA6_VAF: return "MIATA_NA6_VAF"; +case MICRO_RUS_EFI: + return "MICRO_RUS_EFI"; case MINIMAL_PINS: return "MINIMAL_PINS"; case MINI_COOPER_R50: @@ -785,8 +787,6 @@ case TEST_ISSUE_366_BOTH: return "TEST_ISSUE_366_BOTH"; case TEST_ISSUE_366_RISE: return "TEST_ISSUE_366_RISE"; -case MICRO_RUS_EFI: - return "MICRO_RUS_EFI"; case TLE8888_BENCH_ENGINE: return "TLE8888_BENCH_ENGINE"; case TOYOTA_2JZ_GTE_VVTi: diff --git a/firmware/controllers/algo/auto_generated_enums.h b/firmware/controllers/algo/auto_generated_enums.h index 1b86ea3c4d..b261f14ec9 100644 --- a/firmware/controllers/algo/auto_generated_enums.h +++ b/firmware/controllers/algo/auto_generated_enums.h @@ -1,7 +1,7 @@ -// auto-generated from rusefi_hw_enums.h -// auto-generated from rusefi_enums.h +// was generated automatically by rusEfi tool from rusefi_hw_enums.h +// was generated automatically by rusEfi tool from rusefi_enums.h // by enum2string.jar tool -// on Tue Jun 04 12:17:32 EDT 2019 +// on Mon Jun 17 19:49:25 EDT 2019 // see also gen_config_and_enums.bat diff --git a/firmware/gen_config.bat b/firmware/gen_config.bat index ef540e6617..17355aa087 100644 --- a/firmware/gen_config.bat +++ b/firmware/gen_config.bat @@ -2,13 +2,16 @@ rem This batch files reads rusefi_config.txt and produses firmware persistent configuration headers rem the storage section of rusefi.ini is updated as well +rm gen_config.log +rm gen_config_board.log rem lazy is broken - TS input is not considered a change rm build/config.gen mkdir build -java -Drusefi.generator.lazyfile.enabled=true ^ +java -DSystemOut.name=gen_config ^ + -Drusefi.generator.lazyfile.enabled=true ^ -jar ../java_tools/ConfigDefinition.jar ^ -definition integration\rusefi_config.txt ^ -romraider integration ^ diff --git a/firmware/gen_config_board.bat b/firmware/gen_config_board.bat index 42a5f49551..d2389f9f59 100644 --- a/firmware/gen_config_board.bat +++ b/firmware/gen_config_board.bat @@ -16,7 +16,8 @@ echo BOARDNAME=%BOARDNAME% rem lazy is broken - TS input is not considered a change rm build/config.gen -java -cp ../java_tools/ConfigDefinition.jar;../java_tools/configuration_definition/lib/snakeyaml.jar ^ +java -DSystemOut.name=gen_config_board ^ + -cp ../java_tools/ConfigDefinition.jar;../java_tools/configuration_definition/lib/snakeyaml.jar ^ com.rusefi.board_generator.BoardReader ^ -board %BOARDNAME% ^ -firmware_path . ^ @@ -25,7 +26,8 @@ java -cp ../java_tools/ConfigDefinition.jar;../java_tools/configuration_definiti -enumInputFile controllers/algo/rusefi_hw_enums.h -java -jar ../java_tools/ConfigDefinition.jar ^ +java -DSystemOut.name=gen_config_board ^ + -jar ../java_tools/ConfigDefinition.jar ^ -definition integration\rusefi_config.txt ^ -ts_destination tunerstudio ^ -ts_output_name rusefi_%BOARDNAME%.ini ^ diff --git a/firmware/gen_enum_to_string.bat b/firmware/gen_enum_to_string.bat index d23d53b833..f01ba2c86a 100644 --- a/firmware/gen_enum_to_string.bat +++ b/firmware/gen_enum_to_string.bat @@ -1,6 +1,9 @@ rem This batch files reads rusefi_enums.h and produses auto_generated_enums.* files -java -jar ../java_tools/enum2string.jar ^ +rm gen_enum_to_string.log + +java -DSystemOut.name=gen_enum_to_string ^ + -jar ../java_tools/enum2string.jar ^ -inputPath . ^ -outputPath controllers/algo ^ -enumInputFile controllers/algo/rusefi_enums.h ^ diff --git a/java_console/models/src/com/rusefi/config/generated/Fields.java b/java_console/models/src/com/rusefi/config/generated/Fields.java index 7b8c788ba8..3c1dca38e4 100644 --- a/java_console/models/src/com/rusefi/config/generated/Fields.java +++ b/java_console/models/src/com/rusefi/config/generated/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config.generated; -// this file was generated automatically by ConfigDefinition.jar based on integration\rusefi_config.txt Sun Jun 16 22:17:51 EDT 2019 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on integration\rusefi_config.txt Mon Jun 17 19:57:03 EDT 2019 import com.rusefi.config.*; diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index fa9277d76f..aac6694d40 100644 Binary files a/java_tools/ConfigDefinition.jar and b/java_tools/ConfigDefinition.jar differ diff --git a/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java b/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java index b14957ec7b..67ccabbb41 100644 --- a/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java +++ b/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java @@ -4,12 +4,12 @@ import com.rusefi.output.CHeaderConsumer; import com.rusefi.output.ConfigurationConsumer; import com.rusefi.output.JavaFieldsConsumer; import com.rusefi.output.TSProjectConsumer; +import com.rusefi.util.IoUtils; import com.rusefi.util.LazyFile; +import com.rusefi.util.SystemOut; import java.io.*; import java.math.BigInteger; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -23,8 +23,7 @@ import java.util.List; @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public class ConfigDefinition { public static final String EOL = "\n"; - public static final Charset CHARSET = StandardCharsets.ISO_8859_1; - public static final String GENERATED_AUTOMATICALLY_TAG = "was generated automatically by ConfigDefinition.jar based on "; + public static final String GENERATED_AUTOMATICALLY_TAG = LazyFile.LAZY_FILE_TAG + "ConfigDefinition.jar based on "; public static String MESSAGE; private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml"; @@ -45,7 +44,7 @@ public class ConfigDefinition { try { doJob(args); } catch (Throwable e) { - System.out.println(e); + SystemOut.println(e); e.printStackTrace(); System.exit(-1); } @@ -53,7 +52,7 @@ public class ConfigDefinition { private static void doJob(String[] args) throws IOException { if (args.length < 2) { - System.out.println("Please specify\r\n" + SystemOut.println("Please specify\r\n" + KEY_DEFINITION + " x\r\n" + KEY_TS_DESTINATION + " x\r\n" + KEY_C_DESTINATION + " x\r\n" @@ -100,14 +99,14 @@ public class ConfigDefinition { MESSAGE = GENERATED_AUTOMATICALLY_TAG + definitionInputFile + " " + new Date(); - System.out.println("Reading from " + definitionInputFile); + SystemOut.println("Reading from " + definitionInputFile); String currentMD5 = getDefinitionMD5(definitionInputFile); if (skipRebuildFile != null) { boolean nothingToDoHere = needToSkipRebuild(skipRebuildFile, currentMD5); if (nothingToDoHere) { - System.out.println("Nothing to do here according to " + skipRebuildFile + " hash " + currentMD5); + SystemOut.println("Nothing to do here according to " + skipRebuildFile + " hash " + currentMD5); return; } } @@ -115,7 +114,7 @@ public class ConfigDefinition { for (String prependFile : prependFiles) readPrependValues(prependFile); - BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), CHARSET.name())); + BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name())); ReaderState state = new ReaderState(); List destinations = new ArrayList<>(); @@ -145,7 +144,7 @@ public class ConfigDefinition { processTextTemplate(inputFileName, romRaiderDestination); } if (skipRebuildFile != null) { - System.out.println("Writing " + currentMD5 + " to " + skipRebuildFile); + SystemOut.println("Writing " + currentMD5 + " to " + skipRebuildFile); PrintWriter writer = new PrintWriter(new FileWriter(skipRebuildFile)); writer.write(currentMD5); writer.close(); @@ -186,8 +185,8 @@ public class ConfigDefinition { } private static void processTextTemplate(String inputFileName, String outputFileName) throws IOException { - System.out.println("Reading from " + inputFileName); - System.out.println("Writing to " + outputFileName); + SystemOut.println("Reading from " + inputFileName); + SystemOut.println("Writing to " + outputFileName); VariableRegistry.INSTANCE.put("generator_message", ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + new Date()); diff --git a/java_tools/configuration_definition/src/com/rusefi/ConfigField.java b/java_tools/configuration_definition/src/com/rusefi/ConfigField.java index 7c19487760..9060f5d670 100644 --- a/java_tools/configuration_definition/src/com/rusefi/ConfigField.java +++ b/java_tools/configuration_definition/src/com/rusefi/ConfigField.java @@ -1,9 +1,8 @@ package com.rusefi; +import com.rusefi.util.SystemOut; import com.rusefi.test.ConfigFieldParserTest; -import java.io.IOException; -import java.io.Writer; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -101,9 +100,9 @@ public class ConfigField { boolean isIterate = "iterate".equalsIgnoreCase(matcher.group(5)); ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySize, tsInfo, isIterate); - System.out.println("type " + type); - System.out.println("name " + name); - System.out.println("comment " + comment); + SystemOut.println("type " + type); + SystemOut.println("name " + name); + SystemOut.println("comment " + comment); return field; } diff --git a/java_tools/configuration_definition/src/com/rusefi/ReaderState.java b/java_tools/configuration_definition/src/com/rusefi/ReaderState.java index 929db38d4e..f45860c454 100644 --- a/java_tools/configuration_definition/src/com/rusefi/ReaderState.java +++ b/java_tools/configuration_definition/src/com/rusefi/ReaderState.java @@ -1,6 +1,7 @@ package com.rusefi; import com.rusefi.output.ConfigurationConsumer; +import com.rusefi.util.SystemOut; import java.io.BufferedReader; import java.io.IOException; @@ -147,14 +148,14 @@ public class ReaderState { } ConfigStructure structure = new ConfigStructure(name, comment, withPrefix); state.stack.push(structure); - System.out.println("Starting structure " + structure.getName()); + SystemOut.println("Starting structure " + structure.getName()); } private static void handleEndStruct(ReaderState state, List consumers) throws IOException { if (state.stack.isEmpty()) throw new IllegalStateException("Unexpected end_struct"); ConfigStructure structure = state.stack.pop(); - System.out.println("Ending structure " + structure.getName()); + SystemOut.println("Ending structure " + structure.getName()); structure.addAlignmentFill(state); state.structures.put(structure.getName(), structure); diff --git a/java_tools/configuration_definition/src/com/rusefi/TypesHelper.java b/java_tools/configuration_definition/src/com/rusefi/TypesHelper.java index 8653be6cac..3fca979637 100644 --- a/java_tools/configuration_definition/src/com/rusefi/TypesHelper.java +++ b/java_tools/configuration_definition/src/com/rusefi/TypesHelper.java @@ -1,5 +1,7 @@ package com.rusefi; +import com.rusefi.util.SystemOut; + import java.util.Objects; /** @@ -64,7 +66,7 @@ public class TypesHelper { return "S08"; if (UINT8_T.equals(type)) return "U08"; - System.out.println("No TS type convesion for " + type); + SystemOut.println("No TS type conversion for " + type); return type; } diff --git a/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java b/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java index 92dbc80c6c..4fec5fbe29 100644 --- a/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java +++ b/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java @@ -1,6 +1,7 @@ package com.rusefi; import com.rusefi.util.LazyFile; +import com.rusefi.util.SystemOut; import java.io.IOException; import java.util.*; @@ -51,10 +52,10 @@ public class VariableRegistry extends TreeMap { public void register(String var, String value) { if (containsKey(var)) { - System.out.println("Not redefining " + var); + SystemOut.println("Not redefining " + var); return; } - System.out.println("Registering " + var + " as " + value); + SystemOut.println("Registering " + var + " as " + value); put(var, value); cAllDefinitions.put(var, "#define " + var + " " + value + EOL); @@ -65,11 +66,11 @@ public class VariableRegistry extends TreeMap { private void tryToRegisterAsInteger(String var, String value) { try { int intValue = Integer.parseInt(value); - System.out.println("key [" + var + "] value: " + intValue); + SystemOut.println("key [" + var + "] value: " + intValue); intValues.put(var, intValue); javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL); } catch (NumberFormatException e) { - System.out.println("Not an integer: " + value); + SystemOut.println("Not an integer: " + value); if (isQuoted(value) && !var.trim().endsWith(ConfigField.ENUM_SUFFIX)) { // quoted and not with enum suffix means plain string define statement @@ -96,7 +97,7 @@ public class VariableRegistry extends TreeMap { } public void writeNumericsToFile(String fileName) throws IOException { - System.out.println("Writing to " + fileName); + SystemOut.println("Writing to " + fileName); LazyFile cHeader = new LazyFile(fileName); cHeader.write("//\n// " + ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + ConfigDefinition.definitionInputFile + "\n//\n\n"); diff --git a/java_tools/configuration_definition/src/com/rusefi/board_generator/BoardReader.java b/java_tools/configuration_definition/src/com/rusefi/board_generator/BoardReader.java index 54ad0dca8a..4dc1fa00fc 100644 --- a/java_tools/configuration_definition/src/com/rusefi/board_generator/BoardReader.java +++ b/java_tools/configuration_definition/src/com/rusefi/board_generator/BoardReader.java @@ -2,6 +2,7 @@ package com.rusefi.board_generator; import com.rusefi.EnumsReader; import com.rusefi.enum_reader.Value; +import com.rusefi.util.SystemOut; import org.yaml.snakeyaml.Yaml; import java.io.*; @@ -18,7 +19,7 @@ public class BoardReader { public static void main(String[] args) throws IOException { if (args.length < 2) { - System.out.println("Please specify\r\n" + SystemOut.println("Please specify\r\n" + KEY_BOARD_NAME + " x\r\n" + KEY_FIRMWARE_PATH + " x\r\n" ); @@ -44,7 +45,7 @@ public class BoardReader { Yaml yaml = new Yaml(); Map data = yaml.load(new FileReader(firmwarePath + "/config/boards/" + boardName + "/mapping.yaml")); - System.out.println(data); + SystemOut.println(data); BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath + File.separator + boardName + "_prefix.txt")); @@ -65,7 +66,7 @@ public class BoardReader { Map enumMap = EnumsReader.enums.get(headerEnumName); Objects.requireNonNull(enumMap, "enum for " + headerEnumName); - System.out.println(enumMap.size()); + SystemOut.println(enumMap.size()); StringBuffer sb = new StringBuffer(); diff --git a/java_tools/configuration_definition/src/com/rusefi/ldmp/LiveDocsMetaParser.java b/java_tools/configuration_definition/src/com/rusefi/ldmp/LiveDocsMetaParser.java index 99f0a04dc0..4ff12551ea 100644 --- a/java_tools/configuration_definition/src/com/rusefi/ldmp/LiveDocsMetaParser.java +++ b/java_tools/configuration_definition/src/com/rusefi/ldmp/LiveDocsMetaParser.java @@ -1,5 +1,7 @@ package com.rusefi.ldmp; +import com.rusefi.util.SystemOut; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -33,12 +35,12 @@ public class LiveDocsMetaParser { public static void main(String[] args) throws IOException { String fileName = args[0]; String destinationPath = args[1]; - System.out.println(fileName); + SystemOut.println(fileName); if (!new File(fileName).exists()) throw new IllegalStateException("Not found " + fileName); String content = readLineByLine(fileName); List r = parse(content); - System.out.println(r); + SystemOut.println(r); String className = "ThermistorMeta"; @@ -53,27 +55,27 @@ public class LiveDocsMetaParser { List result = new ArrayList<>(); string = string.replaceAll("[()>]", " "); - System.out.println(string); + SystemOut.println(string); Scanner s = new Scanner(string); while (s.hasNext()) { String token = s.next(); - //System.out.println(token); + //SystemOut.println(token); if (DISPLAY_CONFIG.equals(token)) { if (s.hasNext()) { String config = s.next(); - System.out.println("REQ CONF " + config); + SystemOut.println("REQ CONF " + config); result.add(new ConfigRequest(config)); } } else if (DISPLAY_TEXT.equals(token)) { if (s.hasNext()) { String config = s.next(); - System.out.println("REQ TEXT " + config); + SystemOut.println("REQ TEXT " + config); result.add(new TextRequest(config)); } } else if (DISPLAY_FIELD.equals(token)) { if (s.hasNext()) { String config = s.next(); - System.out.println("REQ FIELD " + config); + SystemOut.println("REQ FIELD " + config); result.add(new FieldRequest(config)); } } else if (DISPLAY_IF.equals(token)) { @@ -84,7 +86,7 @@ public class LiveDocsMetaParser { String config = s.next(); - System.out.println("REQ TEXT " + config); + SystemOut.println("REQ TEXT " + config); IfRequest ifRequest = new IfRequest(variable); result.add(ifRequest); @@ -110,7 +112,7 @@ public class LiveDocsMetaParser { } else if (DISPLAY_SENSOR.equals(token)) { if (s.hasNext()) { String config = s.next(); - System.out.println("REQ SENSOR " + config); + SystemOut.println("REQ SENSOR " + config); result.add(new SensorRequest(config)); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/output/CHeaderConsumer.java b/java_tools/configuration_definition/src/com/rusefi/output/CHeaderConsumer.java index 682aa4dec8..d98701ac7a 100644 --- a/java_tools/configuration_definition/src/com/rusefi/output/CHeaderConsumer.java +++ b/java_tools/configuration_definition/src/com/rusefi/output/CHeaderConsumer.java @@ -5,6 +5,7 @@ import com.rusefi.ConfigField; import com.rusefi.ConfigStructure; import com.rusefi.TypesHelper; import com.rusefi.util.LazyFile; +import com.rusefi.util.SystemOut; import java.io.IOException; @@ -18,7 +19,7 @@ public class CHeaderConsumer implements ConfigurationConsumer { private final LazyFile cHeader; public CHeaderConsumer(String destCHeader) { - System.out.println("Writing C header to " + destCHeader); + SystemOut.println("Writing C header to " + destCHeader); cHeader = new LazyFile(destCHeader); cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL); cHeader.write("// begin" + EOL); diff --git a/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java b/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java index 07d37814dc..53cc1101b0 100644 --- a/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java +++ b/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java @@ -2,10 +2,11 @@ package com.rusefi.output; import com.rusefi.*; import com.rusefi.util.LazyFile; +import com.rusefi.util.SystemOut; import java.io.*; -import static com.rusefi.ConfigDefinition.CHARSET; +import static com.rusefi.util.IoUtils.CHARSET; import static com.rusefi.ConfigDefinition.EOL; public class TSProjectConsumer implements ConfigurationConsumer { @@ -100,7 +101,7 @@ public class TSProjectConsumer implements ConfigurationConsumer { private void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException { TsFileContent tsContent = readTsFile(tsPath); - System.out.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME); + SystemOut.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME); // File.getPath() would eliminate potential separator at the end of the path String fileName = new File(tsPath).getPath() + File.separator + TS_FILE_OUTPUT_NAME; diff --git a/java_tools/enum2string.jar b/java_tools/enum2string.jar index f5279a1afa..f7fda2b10e 100644 Binary files a/java_tools/enum2string.jar and b/java_tools/enum2string.jar differ diff --git a/java_tools/enum_to_string/src/com/rusefi/EnumToString.java b/java_tools/enum_to_string/src/com/rusefi/EnumToString.java index 9ef241a160..9a1c44af97 100644 --- a/java_tools/enum_to_string/src/com/rusefi/EnumToString.java +++ b/java_tools/enum_to_string/src/com/rusefi/EnumToString.java @@ -1,6 +1,8 @@ package com.rusefi; import com.rusefi.enum_reader.Value; +import com.rusefi.util.LazyFile; +import com.rusefi.util.SystemOut; import java.io.*; import java.util.*; @@ -30,7 +32,7 @@ public class EnumToString { public static void main(String[] args) throws IOException { if (args.length < 4) { - System.out.println("Please specify at least\n\n" + + SystemOut.println("Please specify at least\n\n" + KEY_INPUT_PATH + "XXX\r\n" + // KEY_INPUT_FILE + "XXX" + KEY_OUTPUT + "XXX\r\n" @@ -63,7 +65,7 @@ public class EnumToString { cppFileContent.insert(0, includesSection); headerFileContent.insert(0, includesSection); - System.out.println("includesSection:\r\n" + includesSection + "end of includesSection\r\n"); + SystemOut.println("includesSection:\r\n" + includesSection + "end of includesSection\r\n"); cppFileContent.insert(0, "#include \"global.h\"\r\n"); headerFileContent.insert(0, bothFilesHeader.toString()); @@ -75,21 +77,22 @@ public class EnumToString { } private static void writeCppAndHeaderFiles(String outFileName) throws IOException { - BufferedWriter bw = new BufferedWriter(new FileWriter(outFileName + ".cpp")); + LazyFile bw = new LazyFile(outFileName + ".cpp"); bw.write(cppFileContent.toString()); bw.close(); - bw = new BufferedWriter(new FileWriter(outFileName + ".h")); + bw = new LazyFile(outFileName + ".h"); bw.write(headerFileContent.toString()); bw.close(); } private static void consumeFile(String inputPath, String inFileName) throws IOException { File f = new File(inputPath + File.separator + inFileName); - System.out.println("Reading from " + inFileName); + SystemOut.println("Reading from " + inFileName); String simpleFileName = f.getName(); - bothFilesHeader.insert(0, "// auto-generated from " + simpleFileName + "\r\n"); + bothFilesHeader.insert(0, "// " + + LazyFile.LAZY_FILE_TAG + " from " + simpleFileName + "\r\n"); includesSection.append("#include \"" + simpleFileName + "\"\r\n"); EnumsReader.process(new FileReader(inFileName)); diff --git a/java_tools/enum_to_string/src/com/rusefi/EnumsReader.java b/java_tools/enum_to_string/src/com/rusefi/EnumsReader.java index 60ecfc38d1..6b13895e6f 100644 --- a/java_tools/enum_to_string/src/com/rusefi/EnumsReader.java +++ b/java_tools/enum_to_string/src/com/rusefi/EnumsReader.java @@ -1,14 +1,13 @@ package com.rusefi; import com.rusefi.enum_reader.Value; +import com.rusefi.util.SystemOut; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.util.Map; -import java.util.Set; import java.util.TreeMap; -import java.util.TreeSet; public class EnumsReader { private final static Map currentValues = new TreeMap<>(); @@ -23,13 +22,13 @@ public class EnumsReader { line = removeSpaces(line); if (line.startsWith("typedefenum{") || line.startsWith("typedefenum__attribute__")) { - System.out.println("Entering enum"); + SystemOut.println("Entering enum"); currentValues.clear(); isInsideEnum = true; } else if (line.startsWith("}") && line.endsWith(";")) { isInsideEnum = false; line = line.substring(1, line.length() - 1); - System.out.println("Ending enum " + line); + SystemOut.println("Ending enum " + line); enums.put(line, new TreeMap<>(currentValues)); } else { line = line.replaceAll("//.+", ""); @@ -42,7 +41,7 @@ public class EnumsReader { value = line.substring(index + 1); line = line.substring(0, index); } - System.out.println("Line " + line); + SystemOut.println("Line " + line); currentValues.put(line, new Value(line, value)); } } diff --git a/java_tools/enum_to_string/src/com/rusefi/util/IoUtils.java b/java_tools/enum_to_string/src/com/rusefi/util/IoUtils.java new file mode 100644 index 0000000000..291a6de1d7 --- /dev/null +++ b/java_tools/enum_to_string/src/com/rusefi/util/IoUtils.java @@ -0,0 +1,8 @@ +package com.rusefi.util; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +public class IoUtils { + public static final Charset CHARSET = StandardCharsets.ISO_8859_1; +} diff --git a/java_tools/configuration_definition/src/com/rusefi/util/LazyFile.java b/java_tools/enum_to_string/src/com/rusefi/util/LazyFile.java similarity index 70% rename from java_tools/configuration_definition/src/com/rusefi/util/LazyFile.java rename to java_tools/enum_to_string/src/com/rusefi/util/LazyFile.java index 90822376bd..0a520d8f0a 100644 --- a/java_tools/configuration_definition/src/com/rusefi/util/LazyFile.java +++ b/java_tools/enum_to_string/src/com/rusefi/util/LazyFile.java @@ -1,10 +1,6 @@ package com.rusefi.util; -import com.rusefi.ConfigDefinition; - import java.io.*; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.Scanner; import java.util.regex.Pattern; @@ -13,11 +9,12 @@ import java.util.regex.Pattern; * This file would override file content only of content has changed, disregarding the magic tag line. */ public class LazyFile { + public static final String LAZY_FILE_TAG = "was generated automatically by rusEfi tool "; private static final String PROPERTY_NAME = "rusefi.generator.lazyfile.enabled"; private static boolean ENABLED = Boolean.getBoolean(PROPERTY_NAME); static { - System.out.println(PROPERTY_NAME + "=" + ENABLED); + SystemOut.println(PROPERTY_NAME + "=" + ENABLED); } private String filename; @@ -31,7 +28,7 @@ public class LazyFile { public void write(String line) { content.append(line); - if (!line.contains(ConfigDefinition.GENERATED_AUTOMATICALLY_TAG)) + if (!line.contains(LAZY_FILE_TAG)) contentWithoutTag.append(line); } @@ -39,20 +36,20 @@ public class LazyFile { String fileContent = unifySpaces(readCurrentContent(filename)); String newContent = unifySpaces(contentWithoutTag.toString().trim()); if (fileContent.equals(newContent)) { - System.out.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content"); + SystemOut.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content"); return; } for (int i = 0; i < Math.min(fileContent.length(), newContent.length()); i++) { if (fileContent.charAt(i) != newContent.charAt(i)) { - System.out.println(getClass().getSimpleName() + " " + filename + ": Not same at " + i); + SystemOut.println(getClass().getSimpleName() + " " + filename + ": Not same at " + i); if (i > 15 && i < fileContent.length() - 6 && i < newContent.length() - 6) { - System.out.println("file " + fileContent.substring(i - 15, i + 5)); - System.out.println("newContent " + newContent.substring(i - 15, i + 5)); + SystemOut.println("file " + fileContent.substring(i - 15, i + 5)); + SystemOut.println("newContent " + newContent.substring(i - 15, i + 5)); } break; } } - Writer fw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename), ConfigDefinition.CHARSET)); + Writer fw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename), IoUtils.CHARSET)); fw.write(content.toString()); fw.close(); } @@ -64,12 +61,12 @@ public class LazyFile { private String readCurrentContent(String filename) throws IOException { if (!new File(filename).exists()) return ""; - Scanner in = new Scanner(Paths.get(filename), ConfigDefinition.CHARSET.name()); + Scanner in = new Scanner(Paths.get(filename), IoUtils.CHARSET.name()); Pattern pat = Pattern.compile(".*\\R|.+\\z"); String line; StringBuffer sb = new StringBuffer(); while ((line = in.findWithinHorizon(pat, 0)) != null) { - if (!line.contains(ConfigDefinition.GENERATED_AUTOMATICALLY_TAG)) + if (!line.contains(LAZY_FILE_TAG)) sb.append(line); } return sb.toString(); diff --git a/java_tools/enum_to_string/src/com/rusefi/util/SystemOut.java b/java_tools/enum_to_string/src/com/rusefi/util/SystemOut.java new file mode 100644 index 0000000000..1c7a19eefe --- /dev/null +++ b/java_tools/enum_to_string/src/com/rusefi/util/SystemOut.java @@ -0,0 +1,47 @@ +package com.rusefi.util; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Utility class which writes same line both to stdout and file + */ +//@ThreadSafe +public class SystemOut { + private static final String LOG = ".log"; + private static PrintWriter logFile; + + public static void println(String line) { + System.out.println(line); + try { + openFileIfNeeded(); + logFile.write(line + "\r\n"); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + private static synchronized void openFileIfNeeded() throws IOException { + if (logFile != null) + return; + String fileName = System.getProperty("SystemOut.name", "rusefi_tool") + LOG; + System.out.println("Opening " + fileName); + logFile = new PrintWriter(new FileWriter(fileName, true)); + } + + @SuppressWarnings("ThrowablePrintedToSystemOut") + public static void println(Throwable param) { + System.out.println(param); + try { + openFileIfNeeded(); + param.printStackTrace(logFile); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + public static void println(Object object) { + println(object == null ? "(null)" : object.toString()); + } +}