XML config output progress
This commit is contained in:
parent
0312e27a06
commit
9ef019cf12
|
@ -2,6 +2,7 @@ logs/
|
||||||
rusefi_console_properties.xml
|
rusefi_console_properties.xml
|
||||||
output.c
|
output.c
|
||||||
currenttune.msq
|
currenttune.msq
|
||||||
|
output.msq
|
||||||
rusefi.ini
|
rusefi.ini
|
||||||
openocd
|
openocd
|
||||||
DfuSe
|
DfuSe
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package com.opensr5.ini;
|
package com.opensr5.ini;
|
||||||
|
|
||||||
import com.opensr5.ini.field.ArrayIniField;
|
import com.opensr5.ini.field.*;
|
||||||
import com.opensr5.ini.field.EnumIniField;
|
|
||||||
import com.opensr5.ini.field.IniField;
|
|
||||||
import com.opensr5.ini.field.ScalarIniField;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -141,6 +138,7 @@ public class IniFileModel {
|
||||||
if (list.get(1).equals(FIELD_TYPE_SCALAR)) {
|
if (list.get(1).equals(FIELD_TYPE_SCALAR)) {
|
||||||
registerField(ScalarIniField.parse(list));
|
registerField(ScalarIniField.parse(list));
|
||||||
} else if (list.get(1).equals(FIELD_TYPE_STRING)) {
|
} else if (list.get(1).equals(FIELD_TYPE_STRING)) {
|
||||||
|
registerField(StringIniField.parse(list));
|
||||||
} else if (list.get(1).equals(FIELD_TYPE_ARRAY)) {
|
} else if (list.get(1).equals(FIELD_TYPE_ARRAY)) {
|
||||||
registerField(ArrayIniField.parse(list));
|
registerField(ArrayIniField.parse(list));
|
||||||
} else if (list.get(1).equals(FIELD_TYPE_BITS)) {
|
} else if (list.get(1).equals(FIELD_TYPE_BITS)) {
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.opensr5.ini.field;
|
||||||
|
|
||||||
|
import com.opensr5.ConfigurationImage;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class StringIniField extends IniField {
|
||||||
|
private final int size;
|
||||||
|
|
||||||
|
public StringIniField(String name, int offset, int size) {
|
||||||
|
super(name, offset);
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValue(ConfigurationImage image) {
|
||||||
|
String value = new String(image.getContent(), getOffset(), size);
|
||||||
|
value = value.trim();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IniField parse(LinkedList<String> list) {
|
||||||
|
String name = list.get(0);
|
||||||
|
int offset = Integer.parseInt(list.get(3));
|
||||||
|
if (!list.get(2).equalsIgnoreCase("ASCII"))
|
||||||
|
throw new IllegalStateException("Do not understand " + name + " at " + offset);
|
||||||
|
int size = Integer.parseInt(list.get(4));
|
||||||
|
return new StringIniField(name, offset, size);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,12 +15,14 @@ import com.rusefi.io.IoStream;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||||
import com.rusefi.maintenance.ExecHelper;
|
import com.rusefi.maintenance.ExecHelper;
|
||||||
|
import com.rusefi.tools.online.Online;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
import com.rusefi.tune.xml.Msq;
|
import com.rusefi.tune.xml.Msq;
|
||||||
import com.rusefi.xml.XmlUtil;
|
import com.rusefi.xml.XmlUtil;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -208,9 +210,9 @@ public class ConsoleTools {
|
||||||
System.err.println("Binary file input expected");
|
System.err.println("Binary file input expected");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
String fileName = args[1];
|
String inputBinaryFileName = args[1];
|
||||||
ConfigurationImage image = ConfigurationImageFile.readFromFile(fileName);
|
ConfigurationImage image = ConfigurationImageFile.readFromFile(inputBinaryFileName);
|
||||||
System.out.println("Got " + image.getSize() + " of configuration from " + fileName);
|
System.out.println("Got " + image.getSize() + " of configuration from " + inputBinaryFileName);
|
||||||
|
|
||||||
IniFileModel ini = IniFileModel.getInstance(Launcher.INI_FILE_PATH);
|
IniFileModel ini = IniFileModel.getInstance(Launcher.INI_FILE_PATH);
|
||||||
|
|
||||||
|
@ -219,8 +221,9 @@ public class ConsoleTools {
|
||||||
|
|
||||||
// handle(tune, ini, "injector_battLagCorrBins");
|
// handle(tune, ini, "injector_battLagCorrBins");
|
||||||
|
|
||||||
|
String outputXmlFile = "output.msq";
|
||||||
XmlUtil.writeXml(tune, Msq.class, "a.msq");
|
XmlUtil.writeXml(tune, Msq.class, outputXmlFile);
|
||||||
|
Online.upload(new File(outputXmlFile), "x");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handle(Msq tune, IniFileModel ini, String key, ConfigurationImage image) {
|
private static void handle(Msq tune, IniFileModel ini, String key, ConfigurationImage image) {
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.rusefi.tools.online;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
public class Online {
|
||||||
|
static final String charset = "UTF-8";
|
||||||
|
static final String url = "https://rusefi.com/online/upload.php";
|
||||||
|
static String CRLF = "\r\n"; // Line separator required by multipart/form-data.
|
||||||
|
|
||||||
|
public static void upload(File xmlFile, String authTokenValue) throws IOException {
|
||||||
|
String boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value.
|
||||||
|
|
||||||
|
URLConnection connection = new URL(url).openConnection();
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||||
|
|
||||||
|
try (
|
||||||
|
OutputStream output = connection.getOutputStream();
|
||||||
|
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
|
||||||
|
) {
|
||||||
|
sendParameter(boundary, writer, "auth_token", authTokenValue);
|
||||||
|
|
||||||
|
// Send text file.
|
||||||
|
writer.append("--" + boundary).append(CRLF);
|
||||||
|
writer.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + xmlFile.getName() + "\"").append(CRLF);
|
||||||
|
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF); // Text file itself must be saved in this charset!
|
||||||
|
writer.append(CRLF).flush();
|
||||||
|
Files.copy(xmlFile.toPath(), output);
|
||||||
|
output.flush(); // Important before continuing with writer!
|
||||||
|
writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
|
||||||
|
|
||||||
|
// End of multipart/form-data.
|
||||||
|
writer.append("--" + boundary + "--").append(CRLF).flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int responseCode = ((HttpURLConnection) connection).getResponseCode();
|
||||||
|
System.out.println(responseCode); // Should be 200
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendParameter(String boundary, PrintWriter writer, String parameterName, String value) {
|
||||||
|
// Send normal param.
|
||||||
|
writer.append("--" + boundary).append(CRLF);
|
||||||
|
writer.append("Content-Disposition: form-data; name=\"" + parameterName +"\"").append(CRLF);
|
||||||
|
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
|
||||||
|
writer.append(CRLF).append(value).append(CRLF).flush();
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,12 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
public class Msq {
|
public class Msq {
|
||||||
private final Page page = new Page();
|
private final Page page = new Page();
|
||||||
|
|
||||||
|
private final VersionInfo versionInfo;
|
||||||
|
|
||||||
|
public Msq() {
|
||||||
|
versionInfo = new VersionInfo("rusEFI+2020");
|
||||||
|
}
|
||||||
|
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
public String getXmlns() {
|
public String getXmlns() {
|
||||||
return "http://www.msefi.com/:msq";
|
return "http://www.msefi.com/:msq";
|
||||||
|
@ -20,7 +26,7 @@ public class Msq {
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
public VersionInfo getVersionInfo() {
|
public VersionInfo getVersionInfo() {
|
||||||
return new VersionInfo();
|
return versionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
|
|
|
@ -5,6 +5,12 @@ import com.rusefi.config.generated.Fields;
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
|
||||||
public class VersionInfo {
|
public class VersionInfo {
|
||||||
|
private final String firmwareInfo;
|
||||||
|
|
||||||
|
public VersionInfo(String firmwareInfo) {
|
||||||
|
this.firmwareInfo = firmwareInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return "5.0";
|
return "5.0";
|
||||||
|
@ -12,7 +18,7 @@ public class VersionInfo {
|
||||||
|
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
public String getFirmwareInfo() {
|
public String getFirmwareInfo() {
|
||||||
return "rusEFI+v20200513%4022811";
|
return firmwareInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
|
|
Loading…
Reference in New Issue