diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java index 87b1ebd7f4..68ae31fc81 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java @@ -1,7 +1,6 @@ package com.opensr5.ini; import com.devexperts.logging.Logging; -import com.devexperts.util.IndexedSet; import com.opensr5.ini.field.*; import org.jetbrains.annotations.Nullable; @@ -26,23 +25,24 @@ public class IniFileModel { private static IniFileModel INSTANCE; private String dialogId; private String dialogUiName; - private Map dialogs = new TreeMap<>(); - private Map allFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + private final Map dialogs = new TreeMap<>(); + private final Map allFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); // this is only used while reading model - TODO extract reader - private List fieldsOfCurrentDialog = new ArrayList<>(); + private final List fieldsOfCurrentDialog = new ArrayList<>(); public Map allIniFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); public Map tooltips = new TreeMap<>(); public Map protocolMeta = new TreeMap<>(); private boolean isConstantsSection; - private String currentSection; private String currentYBins; private String currentXBins; private final Map xBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private final Map yBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); public static void main(String[] args) { - log.info("Dialogs: " + IniFileModel.getInstance().dialogs); + IniFileModel iniFile = new IniFileModel(); + iniFile.findAndReadIniFile(INI_FILE_PATH); + log.info("Dialogs: " + iniFile.dialogs); } private boolean isInSettingContextHelp = false; @@ -148,7 +148,6 @@ public class IniFileModel { if (first.startsWith("[") && first.endsWith("]")) { log.info("Section " + first); - currentSection = first; isConstantsSection = first.equals("[Constants]"); } diff --git a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java index dac9310961..9194e3c54e 100644 --- a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java +++ b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java @@ -31,8 +31,7 @@ public class Msq { } @NotNull - public static Msq valueOf(ConfigurationImage image, int totalConfigSize, String tsSignature) { - IniFileModel ini = IniFileModel.getInstance(); + public static Msq valueOf(ConfigurationImage image, int totalConfigSize, String tsSignature, IniFileModel ini) { Msq tune = create(totalConfigSize, tsSignature); for (String key : ini.allIniFields.keySet()) tune.loadConstant(ini, key, image); diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java index f936bbbc87..9ee26af2f4 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -2,6 +2,7 @@ package com.rusefi.binaryprotocol; import com.devexperts.logging.Logging; import com.opensr5.ConfigurationImage; +import com.opensr5.ini.IniFileModel; import com.opensr5.io.ConfigurationImageFile; import com.opensr5.io.DataListener; import com.rusefi.ConfigurationImageDiff; @@ -365,7 +366,7 @@ public class BinaryProtocol { if (arguments != null && arguments.saveFile) { try { ConfigurationImageFile.saveToFile(image, CONFIGURATION_RUSEFI_BINARY); - Msq tune = MsqFactory.valueOf(image); + Msq tune = MsqFactory.valueOf(image, IniFileModel.getInstance()); tune.writeXmlFile(CONFIGURATION_RUSEFI_XML); } catch (Exception e) { System.err.println("Ignoring " + e); diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/MsqFactory.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/MsqFactory.java index 6f4e4b67fc..825c7fa08f 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/MsqFactory.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/MsqFactory.java @@ -1,11 +1,12 @@ package com.rusefi.binaryprotocol; import com.opensr5.ConfigurationImage; +import com.opensr5.ini.IniFileModel; import com.rusefi.config.generated.Fields; import com.rusefi.tune.xml.Msq; public class MsqFactory { - public static Msq valueOf(ConfigurationImage image) { - return Msq.valueOf(image, Fields.TOTAL_CONFIG_SIZE, Fields.TS_SIGNATURE); + public static Msq valueOf(ConfigurationImage image, IniFileModel ini) { + return Msq.valueOf(image, Fields.TOTAL_CONFIG_SIZE, Fields.TS_SIGNATURE, ini); } } diff --git a/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java b/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java index cca1a250a8..981cc0e7f9 100644 --- a/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java +++ b/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java @@ -359,7 +359,7 @@ public class ConsoleTools { ConfigurationImage image = ConfigurationImageFile.readFromFile(inputBinaryFileName); System.out.println("Got " + image.getSize() + " of configuration from " + inputBinaryFileName); - Msq tune = MsqFactory.valueOf(image); + Msq tune = MsqFactory.valueOf(image, IniFileModel.getInstance()); tune.writeXmlFile(Online.outputXmlFileName); String authToken = AuthTokenPanel.getAuthToken(); System.out.println("Using " + authToken); diff --git a/java_console/ui/src/main/java/com/rusefi/ui/OnlineTab.java b/java_console/ui/src/main/java/com/rusefi/ui/OnlineTab.java index 1f4881d4ff..9417ee53df 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/OnlineTab.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/OnlineTab.java @@ -1,7 +1,7 @@ package com.rusefi.ui; +import com.opensr5.ini.IniFileModel; import com.rusefi.binaryprotocol.MsqFactory; -import com.rusefi.config.generated.Fields; import com.rusefi.tools.online.Online; import com.rusefi.tune.xml.Msq; import com.rusefi.ui.util.Misc; @@ -26,7 +26,7 @@ public class OnlineTab { upload.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - Msq tune = MsqFactory.valueOf(uiContext.getLinkManager().getCurrentStreamState().getControllerConfiguration()); + Msq tune = MsqFactory.valueOf(uiContext.getLinkManager().getCurrentStreamState().getControllerConfiguration(), uiContext.getIni()); Online.uploadTune(tune, authTokenPanel, content, null); } }); diff --git a/java_console/ui/src/main/java/com/rusefi/ui/UIContext.java b/java_console/ui/src/main/java/com/rusefi/ui/UIContext.java index bcfd4b8627..85e455c647 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/UIContext.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/UIContext.java @@ -1,5 +1,6 @@ package com.rusefi.ui; +import com.opensr5.ini.IniFileModel; import com.rusefi.SensorSnifferCentral; import com.rusefi.io.CommandQueue; import com.rusefi.io.LinkManager; @@ -22,4 +23,8 @@ public class UIContext { public CommandQueue getCommandQueue() { return linkManager.getCommandQueue(); } + + public IniFileModel getIni() { + return IniFileModel.getInstance(); + } } diff --git a/java_console/ui/src/main/java/com/rusefi/ui/console/SettingsTab.java b/java_console/ui/src/main/java/com/rusefi/ui/console/SettingsTab.java index b912dad9c4..b7b8a3b3bd 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/console/SettingsTab.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/console/SettingsTab.java @@ -42,7 +42,7 @@ public class SettingsTab { } public void showContent() { - final Map dialogs = IniFileModel.getInstance().getDialogs(); + final Map dialogs = uiContext.getIni().getDialogs(); if (dialogs.isEmpty()) { content.removeAll(); content.add(new JLabel("Meta data not found: " + RUSEFI_INI_PREFIX + "*" + RUSEFI_INI_SUFFIX)); @@ -134,7 +134,7 @@ public class SettingsTab { dialog.setText(name); dialogBody.removeAll(); - DialogModel m = IniFileModel.getInstance().getDialogs().get(name); + DialogModel m = uiContext.getIni().getDialogs().get(name); dialogBody.setLayout(new GridLayout(m.getFields().size(), 1)); diff --git a/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java b/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java index b108b64f24..31cc39b880 100644 --- a/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java +++ b/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java @@ -9,7 +9,6 @@ import com.rusefi.tools.tune.CurveData; import com.rusefi.tools.tune.TS2C; import com.rusefi.tune.xml.Constant; import com.rusefi.tune.xml.Msq; -import org.junit.Before; import org.junit.Test; import java.io.IOException; @@ -28,14 +27,10 @@ public class TuneReadWriteTest { private static final String TEST_BINARY_FILE = PATH + "current_configuration.rusefi_binary"; private static final int LEGACY_TOTAL_CONFIG_SIZE = 20000; - @Before - public void before() { - IniFileModel.getInstance().readIniFile(TEST_INI); - } + private final IniFileModel model = new IniFileModel().readIniFile(TEST_INI); @Test public void testIniReader() throws IOException { - IniFileModel model = IniFileModel.getInstance(); assertTrue(model.getTables().contains("fueltable")); assertEquals(21, model.getTables().size()); assertEquals("fuelRpmBins", model.getXBin("FUELTable")); @@ -110,7 +105,6 @@ public class TuneReadWriteTest { "}\n"; String tableReference = "config->ve"; - IniFileModel model = IniFileModel.getInstance(); String tableName = "veTable"; String copyMethodBody = TS2C.getCopyMethodBody(tableReference, model, tableName); @@ -133,7 +127,6 @@ public class TuneReadWriteTest { @Test public void testCopyCode() { String tableReference = "config->ve"; - IniFileModel model = IniFileModel.getInstance(); String tableName = "veTable"; String copyMethodBody = TS2C.getCopyMethodBody(tableReference, model, tableName); @@ -153,12 +146,12 @@ public class TuneReadWriteTest { assertNotNull(flow); assertEquals("2", flow.getDigits()); - ConfigurationImage tsBinaryData = tsTune.asImage(IniFileModel.getInstance(), LEGACY_TOTAL_CONFIG_SIZE); + ConfigurationImage tsBinaryData = tsTune.asImage(model, LEGACY_TOTAL_CONFIG_SIZE); System.out.println("Reading " + TEST_BINARY_FILE); ConfigurationImage fileBinaryData = ConfigurationImageFile.readFromFile(TEST_BINARY_FILE); - int mismatchCounter = compareImages(tsBinaryData, fileBinaryData); + int mismatchCounter = compareImages(tsBinaryData, fileBinaryData, model); assertEquals(0, mismatchCounter); } @@ -170,7 +163,7 @@ public class TuneReadWriteTest { String fileName = path.getFileName().toString(); // writing TS XML tune file with rusEFI code - Msq tuneFromBinary = MsqFactory.valueOf(fileBinaryData); + Msq tuneFromBinary = MsqFactory.valueOf(fileBinaryData, model); tuneFromBinary.writeXmlFile(fileName); Constant batteryCorrection = tuneFromBinary.findPage().findParameter("injector_battLagCorrBins"); @@ -198,14 +191,14 @@ public class TuneReadWriteTest { Msq tuneFromFile = Msq.readTune(fileName); assertNotNull(tuneFromFile.getVersionInfo().getSignature()); - ConfigurationImage binaryDataFromXml = tuneFromFile.asImage(IniFileModel.getInstance(), LEGACY_TOTAL_CONFIG_SIZE); + ConfigurationImage binaryDataFromXml = tuneFromFile.asImage(model, LEGACY_TOTAL_CONFIG_SIZE); - assertEquals(0, compareImages(binaryDataFromXml, fileBinaryData)); + assertEquals(0, compareImages(binaryDataFromXml, fileBinaryData, model)); // todo: looks like this is not removing the temporary file? Files.delete(path); } - private static int compareImages(ConfigurationImage image1, ConfigurationImage fileData) { + private static int compareImages(ConfigurationImage image1, ConfigurationImage fileData, IniFileModel ini) { byte[] tsBinaryDataContent = image1.getContent(); byte[] fileBinaryDataContent = fileData.getContent(); @@ -215,7 +208,7 @@ public class TuneReadWriteTest { byte tsByte = tsBinaryDataContent[i]; byte fileByte = fileBinaryDataContent[i]; if (tsByte != fileByte) { - IniField field = IniFileModel.getInstance().findByOffset(i); + IniField field = ini.findByOffset(i); System.out.println("Mismatch at offset=" + i + ", " + (field == null ? "(no field)" : field) + " runtime=" + tsByte + "/file=" + fileByte); mismatchCounter++; }