command line tune upload

This commit is contained in:
rusefi 2020-05-31 15:02:46 -04:00
parent 4405ce80a4
commit 76277ee6d8
3 changed files with 17 additions and 9 deletions

View File

@ -13,12 +13,10 @@ import com.rusefi.config.generated.Fields;
import com.rusefi.core.EngineState;
import com.rusefi.core.ResponseBuffer;
import com.rusefi.io.*;
import com.rusefi.io.serial.PortHolder;
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
import com.rusefi.maintenance.ExecHelper;
import com.rusefi.tools.online.Online;
import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.OnlineTab;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.JAXBException;
@ -53,6 +51,7 @@ public class ConsoleTools {
registerTool("print_auth_token", args -> printAuthToken(), "Print current rusEFI Online authentication token.");
registerTool(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI authentication token.");
registerTool("upload_tune", ConsoleTools::uploadTune, "Upload specified tune file using auth token from settings");
registerTool("detect", ConsoleTools::detect, "Find attached rusEFI");
@ -60,6 +59,13 @@ public class ConsoleTools {
registerTool(Fields.CMD_REBOOT_DFU, args -> sendCommand(Fields.CMD_REBOOT_DFU), "Sends a command to switch rusEFI controller into DFU mode.");
}
private static void uploadTune(String[] args) throws IOException {
String fileName = args[1];
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
System.out.println("Trying to upload " + fileName + " using " + authToken);
Online.upload(new File(fileName), authToken);
}
private static void registerTool(String command, ConsoleTool callback, String help) {
TOOLS.put(command, callback);
toolsHelp.put(command, help);
@ -101,11 +107,12 @@ public class ConsoleTools {
private static void setAuthToken(String[] args) {
String newToken = args[1];
getConfig().getRoot().setProperty(OnlineTab.AUTH_TOKEN, newToken);
System.out.println("Saving auth token " + newToken);
getConfig().getRoot().setProperty(Online.AUTH_TOKEN, newToken);
}
private static void printAuthToken() {
String authToken = getConfig().getRoot().getProperty(OnlineTab.AUTH_TOKEN);
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
if (authToken.trim().isEmpty()) {
System.out.println("Auth token not defined. Please use " + SET_AUTH_TOKEN + " command");
System.out.println("\tPlease see https://github.com/rusefi/rusefi/wiki/Online");
@ -208,7 +215,6 @@ public class ConsoleTools {
}
private static void convertBinaryToXml(String[] args) throws IOException, JAXBException {
if (args.length < 2) {
System.err.println("Binary file input expected");
System.exit(-1);
@ -219,7 +225,9 @@ public class ConsoleTools {
Msq tune = Msq.toMsq(image);
tune.writeXmlFile(Msq.outputXmlFileName);
Online.upload(new File(Msq.outputXmlFileName), "x");
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
System.out.println("Using " + authToken);
Online.upload(new File(Msq.outputXmlFileName), authToken);
}
public static long classBuildTimeMillis() throws URISyntaxException, IllegalStateException, IllegalArgumentException {

View File

@ -13,6 +13,7 @@ import org.apache.http.util.EntityUtils;
import java.io.*;
public class Online {
public static final String AUTH_TOKEN = "auth_token";
private static final String url = "https://rusefi.com/online/upload.php";
public static void upload(File xmlFile, String authTokenValue) throws IOException {

View File

@ -17,7 +17,6 @@ import java.io.IOException;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class OnlineTab {
public static final String AUTH_TOKEN = "auth_token";
private static final String TOKEN_WARNING = "Please copy token from your forum profile";
private final JPanel content = new JPanel(new VerticalFlowLayout());
@ -26,7 +25,7 @@ public class OnlineTab {
JTextField textField = new JTextField();
textField.setPreferredSize(new Dimension(200, 24));
String authToken = getConfig().getRoot().getProperty(AUTH_TOKEN);
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
if (authToken.trim().isEmpty())
authToken = TOKEN_WARNING;
@ -40,7 +39,7 @@ public class OnlineTab {
save.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
getConfig().getRoot().setProperty(AUTH_TOKEN, textField.getText());
getConfig().getRoot().setProperty(Online.AUTH_TOKEN, textField.getText());
}
});
content.add(save);