only:refactoring: singleton is not amazing
This commit is contained in:
parent
9cae8ecc8c
commit
417d81aa25
|
@ -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<String, DialogModel> dialogs = new TreeMap<>();
|
||||
private Map<String, DialogModel.Field> allFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
private final Map<String, DialogModel> dialogs = new TreeMap<>();
|
||||
private final Map<String, DialogModel.Field> allFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
// this is only used while reading model - TODO extract reader
|
||||
private List<DialogModel.Field> fieldsOfCurrentDialog = new ArrayList<>();
|
||||
private final List<DialogModel.Field> fieldsOfCurrentDialog = new ArrayList<>();
|
||||
public Map<String, IniField> allIniFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
public Map<String, String> tooltips = new TreeMap<>();
|
||||
public Map<String, String> protocolMeta = new TreeMap<>();
|
||||
private boolean isConstantsSection;
|
||||
private String currentSection;
|
||||
private String currentYBins;
|
||||
private String currentXBins;
|
||||
private final Map<String, String> xBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
private final Map<String, String> 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]");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class SettingsTab {
|
|||
}
|
||||
|
||||
public void showContent() {
|
||||
final Map<String, DialogModel> dialogs = IniFileModel.getInstance().getDialogs();
|
||||
final Map<String, DialogModel> 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));
|
||||
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue