diff --git a/firmware/gen_config_board.sh b/firmware/gen_config_board.sh index 60fc75327f..2eef8a3aa6 100755 --- a/firmware/gen_config_board.sh +++ b/firmware/gen_config_board.sh @@ -45,7 +45,7 @@ java -DSystemOut.name=logs/gen_config_board \ $COMMON_GEN_CONFIG \ -romraider integration \ -tool gen_config.sh \ - -field_lookup_file controllers/lua/generated/value_lookup_generated.cpp \ + -field_lookup_file controllers/lua/generated/value_lookup_generated.cpp \ -board ${BOARDNAME} \ -ts_output_name generated/${INI} \ -signature tunerstudio/generated/signature_${SHORT_BOARDNAME}.txt \ diff --git a/firmware/gen_config_common.sh b/firmware/gen_config_common.sh index b451959ed5..3e03fd44ea 100755 --- a/firmware/gen_config_common.sh +++ b/firmware/gen_config_common.sh @@ -1,3 +1,4 @@ + COMMON_GEN_CONFIG="-jar ../java_tools/ConfigDefinition.jar \ -enumInputFile controllers/algo/engine_types.h \ -enumInputFile controllers/algo/rusefi_enums.h \ @@ -5,6 +6,7 @@ COMMON_GEN_CONFIG="-jar ../java_tools/ConfigDefinition.jar \ -readfile DATALOG_SECTION console/binary/generated/data_logs.ini \ -ts_destination tunerstudio \ -firing_order controllers/algo/firing_order.h \ + -triggerFolder ../unit_tests \ -with_c_defines false \ -initialize_to_zero false \ -definition integration/rusefi_config.txt" diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 4409581c46..0506f789f2 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1907,15 +1907,12 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" ; see also in firmware '[doesTriggerImplyOperationMode]' tag field = "What kind of engine", twoStroke - field = "Skipped wheel location", skippedWheelOnCam, { twoStroke == 0 } - field = "#Please use '4 stroke with cam' only if primary trigger sensor is actually on cam" - field = "#Separate cam input not part of Trigger Pattern does not count here" + field = "Skipped wheel location", skippedWheelOnCam, { twoStroke == 0 && (@@TRIGGER_TYPE_WITHOUT_KNOWN_LOCATION@@) } field = "With VR sensors only rising edge has reliable position" field = "use only rising edge", useOnlyRisingEdgeForTrigger field = "!Reminder that 4-stroke cycle is 720 degrees" field = "!For well-known trigger types use '0' trigger angle offset" field = "Trigger Angle Advance", globalTriggerAngleOffset - field = "Display logic signals", displayLogicLevelsInEngineSniffer dialog = triggerConfiguration_gap, "Trigger Gap Override" field = "!This is a pretty advanced feature for when you are debugging trigger synchronization" @@ -1955,11 +1952,16 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" dialog = triggerInputs, "Trigger Inputs" field = "#Cam is primary if you have cam sensor as part of trigger shape" - field = "Cam Sensor (Primary channel)", triggerInputPins1, 1, { ambiguousOperationMode == @@operation_mode_e_FOUR_STROKE_CAM_SENSOR@@ } - field = "Crank Sensor (Primary channel)", triggerInputPins1, 1, { ambiguousOperationMode != @@operation_mode_e_FOUR_STROKE_CAM_SENSOR@@ } + ; cam if + ; two-stroke, or + ; trigger without known location and cam selected, or + ; ! trigger is crank based + field = "Cam Sensor (Primary channel)", triggerInputPins1, 1, { twoStroke == 1 || ((@@TRIGGER_TYPE_WITHOUT_KNOWN_LOCATION@@) && skippedWheelOnCam) || ! (@@TRIGGER_CRANK_BASED) } + field = "Crank Sensor (Primary channel)", triggerInputPins1, 1, { !(twoStroke == 1 || ((@@TRIGGER_TYPE_WITHOUT_KNOWN_LOCATION@@) && skippedWheelOnCam) || ! (@@TRIGGER_CRANK_BASED)) } + field = "Invert Primary", invertPrimaryTriggerSignal - field = "Secondary channel", triggerInputPins2, { triggerInputPins1 != 0 && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL@@ && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL_60_2@@ && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL_36_1@@ && trigger_type != @@trigger_type_e_TT_ONE@@ && trigger_type != @@trigger_type_e_TT_60_2_VW@@ && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL_36_2@@} - field = "Invert Secondary", invertSecondaryTriggerSignal, { triggerInputPins2 != 0 && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL@@ && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL_60_2@@ && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL_36_1@@ && trigger_type != @@trigger_type_e_TT_ONE@@ && trigger_type != @@trigger_type_e_TT_60_2_VW@@ && trigger_type != @@trigger_type_e_TT_TOOTHED_WHEEL_36_2@@} + field = "Secondary channel", triggerInputPins2, { triggerInputPins1 != 0 && (@@TRIGGER_TYPE_WITH_SECOND_WHEEL)) } + field = "Invert Secondary", invertSecondaryTriggerSignal, { triggerInputPins2 != 0 && (@@TRIGGER_TYPE_WITH_SECOND_WHEEL)) } field = "#VVT or Cam for 60/2 goes below" field = "#If your engine has no exhaust cam sensor, use intake cam inputs" field = "Cam sensor bank 1 intake", camInputs1, { vvtMode1 != @@vvt_mode_e_VVT_INACTIVE@@ } @@ -1971,8 +1973,9 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" dialog = triggerConfiguration - panel = triggerConfiguration_settings, North, { consumeObdSensors == 0 } - panel = triggerInputs, South, { consumeObdSensors == 0 } + panel = triggerConfiguration_settings, {1}, { consumeObdSensors == 0 } + panel = triggerInputs, {1}, { consumeObdSensors == 0 } + field = "Display logic signals", displayLogicLevelsInEngineSniffer ; Engine->Injection Settings dialog = injChars, "Injector Settings", yAxis diff --git a/java_console/ui/src/main/java/com/rusefi/trigger/TriggerImage.java b/java_console/ui/src/main/java/com/rusefi/trigger/TriggerImage.java index 6d96bc03db..9a284fd84d 100644 --- a/java_console/ui/src/main/java/com/rusefi/trigger/TriggerImage.java +++ b/java_console/ui/src/main/java/com/rusefi/trigger/TriggerImage.java @@ -1,7 +1,6 @@ package com.rusefi.trigger; import com.rusefi.StartupFrame; -import com.rusefi.config.generated.Fields; import com.rusefi.enums.trigger_type_e; import com.rusefi.ui.engine.UpDownImage; import com.rusefi.ui.util.FrameHelper; @@ -11,10 +10,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Date; @@ -27,10 +23,8 @@ import java.util.List; * Andrey Belomutskiy, (c) 2013-2020 */ public class TriggerImage { - private static final String TRIGGERTYPE = "TRIGGERTYPE"; private static final String OUTPUT_FOLDER = "triggers"; private static final String TOP_MESSAGE = StartupFrame.LINK_TEXT; - private static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests"; private static final int WHEEL_BORDER = 20; private static final int WHEEL_DIAMETER = 500; @@ -104,7 +98,7 @@ public class TriggerImage { public static void main(String[] args) throws InvocationTargetException, InterruptedException { final String workingFolder; if (args.length < 1) { - workingFolder = DEFAULT_WORK_FOLDER; + workingFolder = TriggerWheelInfo.DEFAULT_WORK_FOLDER; } else { workingFolder = args[0]; } @@ -138,40 +132,12 @@ public class TriggerImage { }); SwingUtilities.invokeAndWait(() -> { - try { - generateImages(workingFolder, wheelInfo -> onWheel(triggerPanel, topPanel, content, wheelInfo)); - } catch (IOException e) { - throw new IllegalStateException(e); - } + TriggerWheelInfo.readWheels(workingFolder, wheelInfo -> onWheel(triggerPanel, topPanel, content, wheelInfo)); }); Thread.sleep(1000L * sleepAtEnd); System.exit(-1); } - private static void generateImages(String workingFolder, TriggerWheelInfo.TriggerWheelInfoConsumer consumer) throws IOException { - String fileName = workingFolder + File.separator + Fields.TRIGGERS_FILE_NAME; - BufferedReader br = new BufferedReader(new FileReader(fileName)); - - System.out.println("Reading " + fileName); - String line; - while ((line = br.readLine()) != null) { - if (line.trim().startsWith("#")) { - // skipping a comment - continue; - } - - if (line.startsWith(TRIGGERTYPE)) { - readTrigger(br, line, consumer); - } - } - } - - private static void readTrigger(BufferedReader reader, String line, TriggerWheelInfo.TriggerWheelInfoConsumer consumer) throws IOException { - TriggerWheelInfo triggerWheelInfo = TriggerWheelInfo.readTriggerWheelInfo(line, reader); - - consumer.onWheel(triggerWheelInfo); - } - private static void onWheel(TriggerPanel triggerPanel, JPanel topPanel, JPanel content, TriggerWheelInfo triggerWheelInfo) { if (onlyOneTrigger != null && findByOrdinal(triggerWheelInfo.getId()) != onlyOneTrigger) return; diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index 3959000f37..12af8ec045 100644 Binary files a/java_tools/ConfigDefinition.jar and b/java_tools/ConfigDefinition.jar differ diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java index 65c6c06db9..e9fdf6789b 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java @@ -3,6 +3,7 @@ package com.rusefi; import com.rusefi.newparse.ParseState; import com.rusefi.newparse.parsing.Definition; import com.rusefi.output.*; +import com.rusefi.trigger.TriggerWheelTSLogic; import com.rusefi.util.IoUtils; import com.rusefi.util.SystemOut; @@ -72,6 +73,7 @@ public class ConfigDefinition { List prependFiles = new ArrayList<>(); String romRaiderInputFile = null; String firingEnumFileName = null; + String triggersFolder = null; String signatureDestination = null; String signaturePrependFile = null; List enumInputFiles = new ArrayList<>(); @@ -134,6 +136,9 @@ public class ConfigDefinition { firingEnumFileName = args[i + 1]; inputFiles.add(firingEnumFileName); break; + case "-triggerFolder": + triggersFolder = args[i + 1]; + break; case KEY_ROMRAIDER_DESTINATION: romRaiderDestination = args[i + 1]; break; @@ -188,6 +193,8 @@ public class ConfigDefinition { ExtraUtil.handleFiringOrder(firingEnumFileName, state.variableRegistry, parseState); + new TriggerWheelTSLogic().execute(triggersFolder, state.variableRegistry); + for (String prependFile : prependFiles) state.variableRegistry.readPrependValues(prependFile); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/FiringOrderTSLogic.java b/java_tools/configuration_definition/src/main/java/com/rusefi/FiringOrderTSLogic.java index e5367b2cbb..45c618efc6 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/FiringOrderTSLogic.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/FiringOrderTSLogic.java @@ -21,6 +21,7 @@ public class FiringOrderTSLogic { private static final String FIRING_ORDER_PREFIX = "FO_"; public static void main(String[] args) throws IOException { + // sandbox code invoke("../firmware/controllers/algo/firing_order.h"); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelInfo.java b/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelInfo.java index bdcbac775f..4771eef4a5 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelInfo.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelInfo.java @@ -1,9 +1,9 @@ package com.rusefi.trigger; +import com.rusefi.config.generated.Fields; import org.jetbrains.annotations.NotNull; -import java.io.BufferedReader; -import java.io.IOException; +import java.io.*; import java.util.List; import java.util.stream.Collectors; @@ -13,23 +13,34 @@ import static com.rusefi.config.generated.Fields.TRIGGER_HAS_SECOND_CHANNEL; import static com.rusefi.config.generated.Fields.TRIGGER_HARDCODED_OPERATION_MODE; public class TriggerWheelInfo { + private static final String TRIGGERTYPE = "TRIGGERTYPE"; + static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests"; + private final int id; private final boolean isSecondWheelCam; private final double tdcPosition; private final String triggerName; private final List signals; private final boolean isCrankBased; + private final boolean hasSecondChannel; + private final boolean hardcodedOperationMode; - public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List signals, boolean isCrankBased, boolean isSecondWheelCam) { + public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List signals, + boolean isCrankBased, + boolean isSecondWheelCam, + boolean hasSecondChannel, + boolean hardcodedOperationMode) { this.id = id; this.isSecondWheelCam = isSecondWheelCam; this.tdcPosition = tdcPosition; this.triggerName = triggerName; this.signals = signals; this.isCrankBased = isCrankBased; + this.hasSecondChannel = hasSecondChannel; + this.hardcodedOperationMode = hardcodedOperationMode; } - public static TriggerWheelInfo readTriggerWheelInfo(String line, BufferedReader reader) throws IOException { + private static TriggerWheelInfo readTriggerWheelInfo(String line, BufferedReader reader) throws IOException { String[] tokens = line.split(" "); String idStr = tokens[1]; int eventCount = Integer.parseInt(tokens[2]); @@ -44,6 +55,8 @@ public class TriggerWheelInfo { boolean isCrankBased = false; boolean isSecondWheelCam = false; + boolean hasSecondChannel = false; + boolean hardcodedOperationMode = false; while (true) { line = reader.readLine(); if (line == null || line.trim().startsWith("#")) @@ -59,9 +72,10 @@ public class TriggerWheelInfo { isSecondWheelCam = Boolean.parseBoolean(keyValue[1]); break; case TRIGGER_HAS_SECOND_CHANNEL: - Boolean.parseBoolean(keyValue[1]); + hasSecondChannel = Boolean.parseBoolean(keyValue[1]); break; case TRIGGER_HARDCODED_OPERATION_MODE: + hardcodedOperationMode = Boolean.parseBoolean(keyValue[1]); break; default: throw new IllegalStateException("Unexpected key/value: " + line); @@ -70,7 +84,38 @@ public class TriggerWheelInfo { List signals = TriggerSignalReader.readSignals(reader, eventCount); - return new TriggerWheelInfo(id, tdcPosition, triggerName, signals, isCrankBased, isSecondWheelCam); + return new TriggerWheelInfo(id, tdcPosition, triggerName, + signals, + isCrankBased, + isSecondWheelCam, + hasSecondChannel, + hardcodedOperationMode + ); + } + + static void readWheels(String workingFolder, TriggerWheelInfoConsumer consumer) { + String fileName = workingFolder + File.separator + Fields.TRIGGERS_FILE_NAME; + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(fileName)); + + System.out.println("Reading " + fileName); + String line; + while ((line = br.readLine()) != null) { + if (line.trim().startsWith("#")) { + // skipping a comment + continue; + } + + if (line.startsWith(TRIGGERTYPE)) { + TriggerWheelInfo triggerWheelInfo = readTriggerWheelInfo(line, br); + + consumer.onWheel(triggerWheelInfo); + } + } + } catch (IOException e) { + throw new IllegalStateException(e); + } } @NotNull @@ -138,6 +183,18 @@ public class TriggerWheelInfo { return signals; } + public boolean isCrankBased() { + return isCrankBased; + } + + public boolean isHasSecondChannel() { + return hasSecondChannel; + } + + public boolean isHardcodedOperationMode() { + return hardcodedOperationMode; + } + public interface TriggerWheelInfoConsumer { void onWheel(TriggerWheelInfo wheelInfo); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelTSLogic.java b/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelTSLogic.java new file mode 100644 index 0000000000..090d71f744 --- /dev/null +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/trigger/TriggerWheelTSLogic.java @@ -0,0 +1,58 @@ +package com.rusefi.trigger; + +import com.rusefi.VariableRegistry; + +import static com.rusefi.trigger.TriggerWheelInfo.DEFAULT_WORK_FOLDER; + +public class TriggerWheelTSLogic { + + private static final String TRIGGER_TYPE_WITHOUT_KNOWN_LOCATION = "TRIGGER_TYPE_WITHOUT_KNOWN_LOCATION"; + private static final String TRIGGER_TYPE_WITH_SECOND_WHEEL = "TRIGGER_TYPE_WITH_SECOND_WHEEL"; + private static final String TRIGGER_CRANK_BASED = "TRIGGER_CRANK_BASED"; + + public static void main(String[] args) { + // sandbox code + VariableRegistry variableRegistry = new VariableRegistry(); + new TriggerWheelTSLogic().execute(DEFAULT_WORK_FOLDER, variableRegistry); + } + + public void execute(String folder, VariableRegistry variableRegistry) { + if (folder == null) { + System.out.println("Folder not specified"); + return; + } + StringBuilder triggerTypesWithoutKnownLocation = new StringBuilder(); + StringBuilder triggerTypesWithSecondWheel = new StringBuilder(); + StringBuilder triggerTypesCrankBased = new StringBuilder(); + + + TriggerWheelInfo.readWheels(folder, wheelInfo -> { + System.out.println("onWheel " + wheelInfo.getTriggerName()); + + if (!wheelInfo.isHardcodedOperationMode()) { + appendOrIfNotEmpty(triggerTypesWithoutKnownLocation); + triggerTypesWithoutKnownLocation.append("trigger_type == ").append(wheelInfo.getId()); + } + + if (wheelInfo.isHasSecondChannel()) { + appendOrIfNotEmpty(triggerTypesWithSecondWheel); + triggerTypesWithSecondWheel.append("trigger_type == ").append(wheelInfo.getId()); + } + + if (wheelInfo.isCrankBased()) { + appendOrIfNotEmpty(triggerTypesCrankBased); + triggerTypesCrankBased.append("trigger_type == ").append(wheelInfo.getId()); + } + + }); + + variableRegistry.register(TRIGGER_TYPE_WITHOUT_KNOWN_LOCATION, triggerTypesWithoutKnownLocation.toString()); + variableRegistry.register(TRIGGER_TYPE_WITH_SECOND_WHEEL, triggerTypesWithSecondWheel.toString()); + variableRegistry.register(TRIGGER_CRANK_BASED, triggerTypesCrankBased.toString()); + } + + private void appendOrIfNotEmpty(StringBuilder triggerTypesWithSecondWheel) { + if (triggerTypesWithSecondWheel.length() > 0) + triggerTypesWithSecondWheel.append(" || "); + } +}