TS plugin progress

This commit is contained in:
rusefi 2020-06-04 00:32:35 -04:00
parent 8b6c2f47a9
commit d917022cb2
9 changed files with 98 additions and 49 deletions

View File

@ -0,0 +1,46 @@
package com.rusefi.ui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class AuthTokenPanel {
public static final String TOKEN_WARNING = "Please copy token from your forum profile";
public static final String AUTH_TOKEN = "auth_token";
private JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JTextField textField = new JTextField();
public AuthTokenPanel() {
textField.setPreferredSize(new Dimension(200, 24));
String authToken = getConfig().getRoot().getProperty(AUTH_TOKEN);
if (authToken.trim().isEmpty())
authToken = TOKEN_WARNING;
textField.setText(authToken);
JButton save = new JButton("Save");
save.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
getConfig().getRoot().setProperty(AUTH_TOKEN, textField.getText());
}
});
content.add(textField);
content.add(save);
}
public JPanel getContent() {
return content;
}
public String getToken() {
return textField.getText();
}
}

View File

@ -47,8 +47,8 @@ public class PersistentConfiguration {
e.writeObject(config); e.writeObject(config);
e.close(); e.close();
System.out.println("Saved settings to " + CONFIG_FILE_NAME); System.out.println("Saved settings to " + CONFIG_FILE_NAME);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e) {
System.out.println("Error saving " + CONFIG_FILE_NAME); System.out.println("Error saving " + CONFIG_FILE_NAME + e);
} }
} }

View File

@ -17,6 +17,7 @@ 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.tools.online.Online;
import com.rusefi.tune.xml.Msq; import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.AuthTokenPanel;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
@ -61,7 +62,7 @@ public class ConsoleTools {
private static void uploadTune(String[] args) throws IOException { private static void uploadTune(String[] args) throws IOException {
String fileName = args[1]; String fileName = args[1];
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN); String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.AUTH_TOKEN);
System.out.println("Trying to upload " + fileName + " using " + authToken); System.out.println("Trying to upload " + fileName + " using " + authToken);
Online.upload(new File(fileName), authToken); Online.upload(new File(fileName), authToken);
} }
@ -108,11 +109,11 @@ public class ConsoleTools {
private static void setAuthToken(String[] args) { private static void setAuthToken(String[] args) {
String newToken = args[1]; String newToken = args[1];
System.out.println("Saving auth token " + newToken); System.out.println("Saving auth token " + newToken);
getConfig().getRoot().setProperty(Online.AUTH_TOKEN, newToken); getConfig().getRoot().setProperty(AuthTokenPanel.AUTH_TOKEN, newToken);
} }
private static void printAuthToken() { private static void printAuthToken() {
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN); String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.AUTH_TOKEN);
if (authToken.trim().isEmpty()) { if (authToken.trim().isEmpty()) {
System.out.println("Auth token not defined. Please use " + SET_AUTH_TOKEN + " command"); 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"); System.out.println("\tPlease see https://github.com/rusefi/rusefi/wiki/Online");
@ -225,7 +226,7 @@ public class ConsoleTools {
Msq tune = Msq.toMsq(image); Msq tune = Msq.toMsq(image);
tune.writeXmlFile(Msq.outputXmlFileName); tune.writeXmlFile(Msq.outputXmlFileName);
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN); String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.AUTH_TOKEN);
System.out.println("Using " + authToken); System.out.println("Using " + authToken);
Online.upload(new File(Msq.outputXmlFileName), authToken); Online.upload(new File(Msq.outputXmlFileName), authToken);
} }

View File

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

View File

@ -14,42 +14,25 @@ import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import static com.rusefi.ui.AuthTokenPanel.TOKEN_WARNING;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class OnlineTab { public class OnlineTab {
private static final String TOKEN_WARNING = "Please copy token from your forum profile";
private final JPanel content = new JPanel(new VerticalFlowLayout()); private final JPanel content = new JPanel(new VerticalFlowLayout());
public OnlineTab() { public OnlineTab() {
JTextField textField = new JTextField(); AuthTokenPanel authTokenPanel = new AuthTokenPanel();
textField.setPreferredSize(new Dimension(200, 24));
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
if (authToken.trim().isEmpty())
authToken = TOKEN_WARNING;
textField.setText(authToken);
content.add(Misc.getRusEFI_online_manual()); content.add(Misc.getRusEFI_online_manual());
content.add(textField); content.add(authTokenPanel.getContent());
JButton save = new JButton("Save");
save.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
getConfig().getRoot().setProperty(Online.AUTH_TOKEN, textField.getText());
}
});
content.add(save);
JButton upload = new JButton("Upload"); JButton upload = new JButton("Upload");
upload.addActionListener(new AbstractAction() { upload.addActionListener(new AbstractAction() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String text = textField.getText(); String text = authTokenPanel.getToken();
if (text.contains(TOKEN_WARNING)) { if (text.contains(TOKEN_WARNING)) {
JOptionPane.showMessageDialog(content, "Does not work without auth token"); JOptionPane.showMessageDialog(content, "Does not work without auth token");
return; return;

View File

@ -3,6 +3,8 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/../../java_console/inifile/inifile.iml" filepath="$PROJECT_DIR$/../../java_console/inifile/inifile.iml" /> <module fileurl="file://$PROJECT_DIR$/../../java_console/inifile/inifile.iml" filepath="$PROJECT_DIR$/../../java_console/inifile/inifile.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/logging/logging.iml" filepath="$PROJECT_DIR$/../../java_console/logging/logging.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/models/models.iml" filepath="$PROJECT_DIR$/../../java_console/models/models.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/shared_ui/shared_ui.iml" filepath="$PROJECT_DIR$/../../java_console/shared_ui/shared_ui.iml" /> <module fileurl="file://$PROJECT_DIR$/../../java_console/shared_ui/shared_ui.iml" filepath="$PROJECT_DIR$/../../java_console/shared_ui/shared_ui.iml" />
<module fileurl="file://$PROJECT_DIR$/ts_plugin.iml" filepath="$PROJECT_DIR$/ts_plugin.iml" /> <module fileurl="file://$PROJECT_DIR$/ts_plugin.iml" filepath="$PROJECT_DIR$/ts_plugin.iml" />
</modules> </modules>

View File

@ -16,6 +16,8 @@
> >
<src path="${console_path}/shared_ui/src"/> <src path="${console_path}/shared_ui/src"/>
<src path="${console_path}/inifile/src"/> <src path="${console_path}/inifile/src"/>
<src path="${console_path}/logging/src"/>
<src path="${console_path}/models/src"/>
<src path="src"/> <src path="src"/>
</javac> </javac>

View File

@ -5,22 +5,27 @@ import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.efiAnalytics.plugin.ecu.ControllerException; import com.efiAnalytics.plugin.ecu.ControllerException;
import com.efiAnalytics.plugin.ecu.ControllerParameter; import com.efiAnalytics.plugin.ecu.ControllerParameter;
import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer; import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer;
import com.rusefi.config.Field;
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.ui.AuthTokenPanel;
import com.rusefi.ui.storage.PersistentConfiguration;
import com.rusefi.ui.util.Misc; import com.rusefi.ui.util.Misc;
import org.putgemin.VerticalFlowLayout;
import javax.swing.*; import javax.swing.*;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import java.awt.*; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class TsPlugin implements ApplicationPlugin { public class TsPlugin implements ApplicationPlugin {
private ControllerAccess controllerAccess; private ControllerAccess controllerAccess;
private JPanel content = new JPanel(new BorderLayout()); private final JPanel content = new JPanel(new VerticalFlowLayout());
public TsPlugin() { public TsPlugin() {
content.add(Misc.getRusEFI_online_manual()); content.add(Misc.getRusEFI_online_manual());
content.add(new AuthTokenPanel().getContent());
} }
@Override @Override
@ -46,49 +51,58 @@ public class TsPlugin implements ApplicationPlugin {
@Override @Override
public void initialize(ControllerAccess controllerAccess) { public void initialize(ControllerAccess controllerAccess) {
this.controllerAccess = controllerAccess; this.controllerAccess = controllerAccess;
for (String config : controllerAccess.getEcuConfigurationNames()) { printEcuConfigurationNames(controllerAccess);
System.out.println("EcuConfigurationName " + config);
}
uploadCurrentTune(controllerAccess);
}
private static String uploadCurrentTune(ControllerAccess controllerAccess) {
Msq msq = new Msq(); Msq msq = new Msq();
String configurationName = getConfigurationName(); String configurationName = getConfigurationName();
ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer(); ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer();
String[] parameterNames = controllerParameterServer.getParameterNames(configurationName);
try { try {
String[] parameterNames = controllerParameterServer.getParameterNames(configurationName);
for (String parameterName : parameterNames) { for (String parameterName : parameterNames) {
ControllerParameter cp = controllerParameterServer.getControllerParameter(configurationName, parameterName); ControllerParameter cp = controllerParameterServer.getControllerParameter(configurationName, parameterName);
String type = cp.getParamClass(); String type = cp.getParamClass();
String value; String value;
if (ControllerParameter.PARAM_CLASS_BITS.equals(type)) { if (ControllerParameter.PARAM_CLASS_BITS.equals(type)) {
value = cp.getStringValue(); value = cp.getStringValue();
System.out.println("bits " + parameterName + ": " + value); System.out.println("TsPlugin bits " + parameterName + ": " + value);
} else if (ControllerParameter.PARAM_CLASS_SCALAR.equals(type)) { } else if (ControllerParameter.PARAM_CLASS_SCALAR.equals(type)) {
value = cp.getStringValue(); value = cp.getStringValue();
System.out.println("scalar " + parameterName + ": " + cp.getScalarValue() + "/" + cp.getStringValue()); System.out.println("TsPlugin scalar " + parameterName + ": " + cp.getScalarValue() + "/" + cp.getStringValue());
} else if (ControllerParameter.PARAM_CLASS_ARRAY.equals(type)) { } else if (ControllerParameter.PARAM_CLASS_ARRAY.equals(type)) {
value = getArrayValue(cp.getArrayValues()); value = getArrayValue(cp.getArrayValues());
} else if ("string".equals(type)) {
System.out.println("TsPlugin name=" + parameterName + " string=" + cp.getStringValue());
value = cp.getStringValue();
} else { } else {
System.out.println("name=" + parameterName + " type " + type + "/" + cp.getStringValue()); System.out.println("TsPlugin name=" + parameterName + " unexpected type " + type + "/" + cp.getStringValue());
value = cp.getStringValue(); value = cp.getStringValue();
} }
msq.getPage().constant.add(new Constant(parameterName, cp.getUnits(), value)); msq.getPage().constant.add(new Constant(parameterName, cp.getUnits(), value));
} }
try { Path tempDirWithPrefix = Files.createTempDirectory("rusefi_ts_plugin");
msq.writeXmlFile("plugin.xml"); String fileName = tempDirWithPrefix + File.separator + "plugin.xml";
} catch (JAXBException | IOException e) { msq.writeXmlFile(fileName);
System.out.println("Error writing XML: " + e); return fileName;
} } catch (JAXBException | IOException | ControllerException e) {
System.out.println("Error writing XML: " + e);
} catch (ControllerException e) { return null;
e.printStackTrace();
} }
} }
private String getArrayValue(double[][] arrayValues) { private void printEcuConfigurationNames(ControllerAccess controllerAccess) {
for (String config : controllerAccess.getEcuConfigurationNames()) {
System.out.println("EcuConfigurationName " + config);
}
}
private static String getArrayValue(double[][] arrayValues) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int rowIndex = 0; rowIndex < arrayValues.length; rowIndex++) { for (int rowIndex = 0; rowIndex < arrayValues.length; rowIndex++) {
double[] array = arrayValues[rowIndex]; double[] array = arrayValues[rowIndex];
@ -100,6 +114,7 @@ public class TsPlugin implements ApplicationPlugin {
} }
} }
sb.append("\n"); sb.append("\n");
return sb.toString();
} }
public static String getConfigurationName() { public static String getConfigurationName() {
@ -129,7 +144,8 @@ public class TsPlugin implements ApplicationPlugin {
@Override @Override
public void close() { public void close() {
System.out.printf("TsPlugin#close");
PersistentConfiguration.getConfig().save();
} }
@Override @Override