TS plugin progress
This commit is contained in:
parent
8e3ea302d0
commit
73e206fde3
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package com.rusefi.tune.xml;
|
||||
|
||||
public class Settings {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.rusefi.tune.xml;
|
||||
|
||||
public class UserComments {
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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<String, Object>) 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");
|
||||
}
|
||||
|
|
|
@ -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<String, Constant> 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);
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue