diff --git a/java_console/inifile/src/com/rusefi/tune/xml/Constant.java b/java_console/inifile/src/com/rusefi/tune/xml/Constant.java index cd10a1bd2a..aa0f1c1a71 100644 --- a/java_console/inifile/src/com/rusefi/tune/xml/Constant.java +++ b/java_console/inifile/src/com/rusefi/tune/xml/Constant.java @@ -4,9 +4,12 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlValue; public class Constant { - private final String name; - private final String units; - private final String value; + private String name; + private String units; + private String value; + + public Constant() { + } public Constant(String name, String units, String value) { this.name = name; @@ -29,4 +32,15 @@ public class Constant { return value; } + public void setName(String name) { + this.name = name; + } + + public void setUnits(String units) { + this.units = units; + } + + public void setValue(String value) { + this.value = value; + } } diff --git a/java_console/inifile/src/com/rusefi/tune/xml/Msq.java b/java_console/inifile/src/com/rusefi/tune/xml/Msq.java index b477355d4c..55e79acf54 100644 --- a/java_console/inifile/src/com/rusefi/tune/xml/Msq.java +++ b/java_console/inifile/src/com/rusefi/tune/xml/Msq.java @@ -8,9 +8,7 @@ import com.rusefi.xml.XmlUtil; import org.jetbrains.annotations.NotNull; import javax.xml.bind.JAXBException; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.*; import java.io.File; import java.io.IOException; @@ -18,7 +16,7 @@ import java.io.IOException; public class Msq { public static final String outputXmlFileName = PersistentConfiguration.RUSEFI_SETTINGS_FOLDER + File.separator + "output.msq"; - private final Page page = new Page(); + private Page page = new Page(); private final VersionInfo versionInfo; @@ -45,11 +43,6 @@ public class Msq { getPage().constant.add(new Constant(field.getName(), field.getUnits(), value)); } - @XmlAttribute - public String getXmlns() { - return "http://www.msefi.com/:msq"; - } - @XmlElement public Bibliography getBibliography() { return new Bibliography(); @@ -64,4 +57,18 @@ public class Msq { public Page getPage() { return page; } + + public void setPage(Page page) { + this.page = page; + } + + @XmlElement + public Settings getSettings() { + return new Settings(); + } + + @XmlElement + public UserComments getUserComments() { + return new UserComments(); + } } diff --git a/java_console/inifile/src/com/rusefi/tune/xml/Settings.java b/java_console/inifile/src/com/rusefi/tune/xml/Settings.java new file mode 100644 index 0000000000..0f0e3e97de --- /dev/null +++ b/java_console/inifile/src/com/rusefi/tune/xml/Settings.java @@ -0,0 +1,4 @@ +package com.rusefi.tune.xml; + +public class Settings { +} diff --git a/java_console/inifile/src/com/rusefi/tune/xml/UserComments.java b/java_console/inifile/src/com/rusefi/tune/xml/UserComments.java new file mode 100644 index 0000000000..d3dd3606ac --- /dev/null +++ b/java_console/inifile/src/com/rusefi/tune/xml/UserComments.java @@ -0,0 +1,4 @@ +package com.rusefi.tune.xml; + +public class UserComments { +} diff --git a/java_console/inifile/src/com/rusefi/tune/xml/VersionInfo.java b/java_console/inifile/src/com/rusefi/tune/xml/VersionInfo.java index b7477f641a..2f331a52ec 100644 --- a/java_console/inifile/src/com/rusefi/tune/xml/VersionInfo.java +++ b/java_console/inifile/src/com/rusefi/tune/xml/VersionInfo.java @@ -5,7 +5,10 @@ import com.rusefi.config.generated.Fields; import javax.xml.bind.annotation.XmlAttribute; public class VersionInfo { - private final String firmwareInfo; + private String firmwareInfo; + + public VersionInfo() { + } public VersionInfo(String firmwareInfo) { this.firmwareInfo = firmwareInfo; diff --git a/java_console/inifile/src/com/rusefi/tune/xml/package-info.java b/java_console/inifile/src/com/rusefi/tune/xml/package-info.java new file mode 100644 index 0000000000..6a84e494fa --- /dev/null +++ b/java_console/inifile/src/com/rusefi/tune/xml/package-info.java @@ -0,0 +1,8 @@ +@XmlSchema( + namespace = "http://www.msefi.com/:msq", + elementFormDefault = XmlNsForm.QUALIFIED +) +package com.rusefi.tune.xml; + +import javax.xml.bind.annotation.XmlNsForm; +import javax.xml.bind.annotation.XmlSchema; diff --git a/java_console/inifile/src/com/rusefi/ui/storage/PersistentConfiguration.java b/java_console/inifile/src/com/rusefi/ui/storage/PersistentConfiguration.java index 73ad2e6a8b..2dd0aeb5dd 100644 --- a/java_console/inifile/src/com/rusefi/ui/storage/PersistentConfiguration.java +++ b/java_console/inifile/src/com/rusefi/ui/storage/PersistentConfiguration.java @@ -26,7 +26,6 @@ public class PersistentConfiguration { } private PersistentConfiguration() { - registerShutdownHook(); } /** @@ -50,7 +49,7 @@ public class PersistentConfiguration { XMLDecoder e = new XMLDecoder(new BufferedInputStream(new FileInputStream(CONFIG_FILE_NAME))); config = (Map) e.readObject(); e.close(); - System.out.println("Got configuration from " + CONFIG_FILE_NAME); + System.out.println("Console configuration from " + CONFIG_FILE_NAME); } catch (Throwable e) { System.out.println("Console configuration not found " + CONFIG_FILE_NAME + ", using defaults"); } diff --git a/java_tools/ts_plugin/src/com/rusefi/TsPlugin.java b/java_tools/ts_plugin/src/com/rusefi/TsPlugin.java index 6c62a8f324..c0c9eaca3b 100644 --- a/java_tools/ts_plugin/src/com/rusefi/TsPlugin.java +++ b/java_tools/ts_plugin/src/com/rusefi/TsPlugin.java @@ -17,6 +17,8 @@ import javax.swing.*; import javax.xml.bind.JAXBException; import java.awt.event.ActionEvent; import java.io.IOException; +import java.util.Map; +import java.util.TreeMap; /** * by the way TS installs stuff into %user%\.efianalytics\TunerStudio\plugins folder @@ -73,6 +75,13 @@ public class TsPlugin implements ApplicationPlugin { Msq msq = new Msq(); String configurationName = getConfigurationName(); ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer(); + + Msq tsTune = TsTuneReader.readTsTune(configurationName); + Map byName = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + for (Constant c : tsTune.getPage().constant) { + byName.put(c.getName(), c); + } + try { String[] parameterNames = controllerParameterServer.getParameterNames(configurationName); for (String parameterName : parameterNames) { @@ -83,14 +92,23 @@ public class TsPlugin implements ApplicationPlugin { value = cp.getStringValue(); System.out.println("TsPlugin bits " + parameterName + ": " + value); } else if (ControllerParameter.PARAM_CLASS_SCALAR.equals(type)) { - value = cp.getStringValue(); + value = toString(cp.getScalarValue(), cp.getDecimalPlaces()); System.out.println("TsPlugin scalar " + parameterName + ": " + cp.getScalarValue() + "/" + cp.getStringValue()); } else if (ControllerParameter.PARAM_CLASS_ARRAY.equals(type)) { value = getArrayValue(cp.getArrayValues()); } else if ("string".equals(type)) { - System.out.println("TsPlugin name=" + parameterName + " string=" + cp.getStringValue()); - value = cp.getStringValue(); + //value = cp.getStringValue(); + // WOW hack + // TS does not provide values for string parameters?! so we read the file directly + Constant constant = byName.get(parameterName); + if (constant == null) { + System.out.println("Not found in TS tune " + parameterName); + value = null; + } else { + value = constant.getValue(); + System.out.println("TsPlugin name=" + parameterName + " string=" + cp.getStringValue() + "/h=" + value); + } } else { System.out.println("TsPlugin name=" + parameterName + " unexpected type " + type + "/" + cp.getStringValue()); value = cp.getStringValue(); @@ -108,6 +126,11 @@ public class TsPlugin implements ApplicationPlugin { } } + private static String toString(double scalarValue, int decimalPlaces) { + // todo: start using decimalPlaces parameter! + return Double.toString(scalarValue); + } + private void printEcuConfigurationNames(ControllerAccess controllerAccess) { for (String config : controllerAccess.getEcuConfigurationNames()) { System.out.println("EcuConfigurationName " + config); diff --git a/java_tools/ts_plugin/src/com/rusefi/TsTuneReader.java b/java_tools/ts_plugin/src/com/rusefi/TsTuneReader.java new file mode 100644 index 0000000000..9f6c15776b --- /dev/null +++ b/java_tools/ts_plugin/src/com/rusefi/TsTuneReader.java @@ -0,0 +1,37 @@ +package com.rusefi; + +import com.rusefi.tune.xml.Msq; +import com.rusefi.xml.XmlUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.filechooser.FileSystemView; +import java.io.File; + +public class TsTuneReader { + public static void main(String[] args) { + String ecuName = "dev"; + + Msq tune = readTsTune(ecuName); + System.out.println(tune); + } + + public static Msq readTsTune(String ecuName) { + String fileName = getTsTuneFileName(ecuName); + try { + return XmlUtil.readModel(Msq.class, fileName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + @NotNull + private static String getTsTuneFileName(String ecuName) { + JFileChooser fr = new JFileChooser(); + FileSystemView fw = fr.getFileSystemView(); + File defaultDirectory = fw.getDefaultDirectory(); + System.out.println(defaultDirectory); + + return defaultDirectory + File.separator + "TunerStudioProjects" + File.separator + ecuName + File.separator + "CurrentTune.msq"; + } +}