TS plugin progress
This commit is contained in:
parent
8b6c2f47a9
commit
d917022cb2
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -47,8 +47,8 @@ public class PersistentConfiguration {
|
|||
e.writeObject(config);
|
||||
e.close();
|
||||
System.out.println("Saved settings to " + CONFIG_FILE_NAME);
|
||||
} catch (FileNotFoundException e1) {
|
||||
System.out.println("Error saving " + CONFIG_FILE_NAME);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Error saving " + CONFIG_FILE_NAME + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ 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.AuthTokenPanel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
@ -61,7 +62,7 @@ public class ConsoleTools {
|
|||
|
||||
private static void uploadTune(String[] args) throws IOException {
|
||||
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);
|
||||
Online.upload(new File(fileName), authToken);
|
||||
}
|
||||
|
@ -108,11 +109,11 @@ public class ConsoleTools {
|
|||
private static void setAuthToken(String[] args) {
|
||||
String newToken = args[1];
|
||||
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() {
|
||||
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
|
||||
String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.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");
|
||||
|
@ -225,7 +226,7 @@ public class ConsoleTools {
|
|||
|
||||
Msq tune = Msq.toMsq(image);
|
||||
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);
|
||||
Online.upload(new File(Msq.outputXmlFileName), authToken);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ 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 {
|
||||
|
|
|
@ -14,42 +14,25 @@ import java.awt.event.ActionEvent;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.rusefi.ui.AuthTokenPanel.TOKEN_WARNING;
|
||||
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||
|
||||
public class OnlineTab {
|
||||
private static final String TOKEN_WARNING = "Please copy token from your forum profile";
|
||||
|
||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
public OnlineTab() {
|
||||
JTextField textField = new JTextField();
|
||||
textField.setPreferredSize(new Dimension(200, 24));
|
||||
|
||||
String authToken = getConfig().getRoot().getProperty(Online.AUTH_TOKEN);
|
||||
if (authToken.trim().isEmpty())
|
||||
authToken = TOKEN_WARNING;
|
||||
|
||||
textField.setText(authToken);
|
||||
AuthTokenPanel authTokenPanel = new AuthTokenPanel();
|
||||
|
||||
content.add(Misc.getRusEFI_online_manual());
|
||||
|
||||
content.add(textField);
|
||||
|
||||
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);
|
||||
|
||||
content.add(authTokenPanel.getContent());
|
||||
|
||||
JButton upload = new JButton("Upload");
|
||||
upload.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String text = textField.getText();
|
||||
String text = authTokenPanel.getToken();
|
||||
if (text.contains(TOKEN_WARNING)) {
|
||||
JOptionPane.showMessageDialog(content, "Does not work without auth token");
|
||||
return;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
<component name="ProjectModuleManager">
|
||||
<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/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$/ts_plugin.iml" filepath="$PROJECT_DIR$/ts_plugin.iml" />
|
||||
</modules>
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
>
|
||||
<src path="${console_path}/shared_ui/src"/>
|
||||
<src path="${console_path}/inifile/src"/>
|
||||
<src path="${console_path}/logging/src"/>
|
||||
<src path="${console_path}/models/src"/>
|
||||
<src path="src"/>
|
||||
</javac>
|
||||
|
||||
|
|
|
@ -5,22 +5,27 @@ import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
|||
import com.efiAnalytics.plugin.ecu.ControllerException;
|
||||
import com.efiAnalytics.plugin.ecu.ControllerParameter;
|
||||
import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer;
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
import com.rusefi.ui.AuthTokenPanel;
|
||||
import com.rusefi.ui.storage.PersistentConfiguration;
|
||||
import com.rusefi.ui.util.Misc;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class TsPlugin implements ApplicationPlugin {
|
||||
private ControllerAccess controllerAccess;
|
||||
private JPanel content = new JPanel(new BorderLayout());
|
||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
public TsPlugin() {
|
||||
content.add(Misc.getRusEFI_online_manual());
|
||||
content.add(new AuthTokenPanel().getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,49 +51,58 @@ public class TsPlugin implements ApplicationPlugin {
|
|||
@Override
|
||||
public void initialize(ControllerAccess controllerAccess) {
|
||||
this.controllerAccess = controllerAccess;
|
||||
for (String config : controllerAccess.getEcuConfigurationNames()) {
|
||||
System.out.println("EcuConfigurationName " + config);
|
||||
}
|
||||
printEcuConfigurationNames(controllerAccess);
|
||||
|
||||
uploadCurrentTune(controllerAccess);
|
||||
}
|
||||
|
||||
private static String uploadCurrentTune(ControllerAccess controllerAccess) {
|
||||
Msq msq = new Msq();
|
||||
|
||||
String configurationName = getConfigurationName();
|
||||
ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer();
|
||||
String[] parameterNames = controllerParameterServer.getParameterNames(configurationName);
|
||||
try {
|
||||
String[] parameterNames = controllerParameterServer.getParameterNames(configurationName);
|
||||
for (String parameterName : parameterNames) {
|
||||
ControllerParameter cp = controllerParameterServer.getControllerParameter(configurationName, parameterName);
|
||||
String type = cp.getParamClass();
|
||||
String value;
|
||||
if (ControllerParameter.PARAM_CLASS_BITS.equals(type)) {
|
||||
value = cp.getStringValue();
|
||||
System.out.println("bits " + parameterName + ": " + value);
|
||||
System.out.println("TsPlugin bits " + parameterName + ": " + value);
|
||||
} else if (ControllerParameter.PARAM_CLASS_SCALAR.equals(type)) {
|
||||
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)) {
|
||||
value = getArrayValue(cp.getArrayValues());
|
||||
} else if ("string".equals(type)) {
|
||||
System.out.println("TsPlugin name=" + parameterName + " string=" + cp.getStringValue());
|
||||
value = cp.getStringValue();
|
||||
} else {
|
||||
System.out.println("name=" + parameterName + " type " + type + "/" + cp.getStringValue());
|
||||
System.out.println("TsPlugin name=" + parameterName + " unexpected type " + type + "/" + cp.getStringValue());
|
||||
value = cp.getStringValue();
|
||||
}
|
||||
|
||||
msq.getPage().constant.add(new Constant(parameterName, cp.getUnits(), value));
|
||||
}
|
||||
|
||||
try {
|
||||
msq.writeXmlFile("plugin.xml");
|
||||
} catch (JAXBException | IOException e) {
|
||||
System.out.println("Error writing XML: " + e);
|
||||
}
|
||||
|
||||
} catch (ControllerException e) {
|
||||
e.printStackTrace();
|
||||
Path tempDirWithPrefix = Files.createTempDirectory("rusefi_ts_plugin");
|
||||
String fileName = tempDirWithPrefix + File.separator + "plugin.xml";
|
||||
msq.writeXmlFile(fileName);
|
||||
return fileName;
|
||||
} catch (JAXBException | IOException | ControllerException e) {
|
||||
System.out.println("Error writing XML: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
for (int rowIndex = 0; rowIndex < arrayValues.length; rowIndex++) {
|
||||
double[] array = arrayValues[rowIndex];
|
||||
|
@ -100,6 +114,7 @@ public class TsPlugin implements ApplicationPlugin {
|
|||
}
|
||||
}
|
||||
sb.append("\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getConfigurationName() {
|
||||
|
@ -129,7 +144,8 @@ public class TsPlugin implements ApplicationPlugin {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
System.out.printf("TsPlugin#close");
|
||||
PersistentConfiguration.getConfig().save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue