RE TS plugin to have continues tune auto-upload feature #1605
This commit is contained in:
parent
491a9cfa6e
commit
a053d5f471
|
@ -38,24 +38,25 @@ public class IniFileModel {
|
||||||
private boolean isInSettingContextHelp = false;
|
private boolean isInSettingContextHelp = false;
|
||||||
private boolean isInsidePageDefinition;
|
private boolean isInsidePageDefinition;
|
||||||
|
|
||||||
public void findAndReadIniFile(String iniFilePath) {
|
public IniFileModel findAndReadIniFile(String iniFilePath) {
|
||||||
String fileName = findMetaInfoFile(iniFilePath);
|
String fileName = findMetaInfoFile(iniFilePath);
|
||||||
readIniFile(fileName);
|
return readIniFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readIniFile(String fileName) {
|
public IniFileModel readIniFile(String fileName) {
|
||||||
File input = null;
|
File input = null;
|
||||||
if (fileName != null)
|
if (fileName != null)
|
||||||
input = new File(fileName);
|
input = new File(fileName);
|
||||||
if (fileName == null || !input.exists()) {
|
if (fileName == null || !input.exists()) {
|
||||||
System.out.println("No such file: " + RUSEFI_INI_PREFIX + "*" + RUSEFI_INI_SUFFIX);
|
System.out.println("No such file: " + fileName);
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Reading " + fileName);
|
System.out.println("Reading " + fileName);
|
||||||
RawIniFile content = IniFileReader.read(input);
|
RawIniFile content = IniFileReader.read(input);
|
||||||
|
|
||||||
readIniFile(content);
|
readIniFile(content);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IniFileModel readIniFile(RawIniFile content) {
|
public IniFileModel readIniFile(RawIniFile content) {
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
package com.rusefi.ts_plugin;
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
||||||
|
import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer;
|
||||||
|
import com.opensr5.ini.IniFileModel;
|
||||||
|
import com.rusefi.TsTuneReader;
|
||||||
import com.rusefi.ui.util.FrameHelper;
|
import com.rusefi.ui.util.FrameHelper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -10,10 +18,29 @@ import static org.mockito.Mockito.when;
|
||||||
* @see PluginLauncherSandbox
|
* @see PluginLauncherSandbox
|
||||||
*/
|
*/
|
||||||
public class PluginBodySandbox {
|
public class PluginBodySandbox {
|
||||||
|
|
||||||
|
private static final String PROJECT_NAME = "dev";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
String iniFile = TsTuneReader.getProjectsDir() +
|
||||||
|
File.separator + PROJECT_NAME +
|
||||||
|
File.separator + "projectCfg" +
|
||||||
|
File.separator + "mainController.ini";
|
||||||
|
IniFileModel model = new IniFileModel().readIniFile(iniFile);
|
||||||
|
Objects.requireNonNull(model, "model");
|
||||||
|
java.util.List<String> fieldNamesList = new ArrayList<>(model.allIniFields.keySet());
|
||||||
|
String[] parameterNames = fieldNamesList.toArray(new String[0]);
|
||||||
|
|
||||||
|
|
||||||
|
ControllerParameterServer controllerParameterServer = mock(ControllerParameterServer.class);
|
||||||
|
when(controllerParameterServer.getParameterNames(any())).thenReturn(parameterNames);
|
||||||
|
|
||||||
|
ControllerAccess controllerAccess = mock(ControllerAccess.class);
|
||||||
|
when(controllerAccess.getEcuConfigurationNames()).thenReturn(new String[]{PROJECT_NAME});
|
||||||
|
when(controllerAccess.getControllerParameterServer()).thenReturn(controllerParameterServer);
|
||||||
|
|
||||||
|
|
||||||
new FrameHelper().showFrame(new PluginEntry(() -> {
|
new FrameHelper().showFrame(new PluginEntry(() -> {
|
||||||
ControllerAccess controllerAccess = mock(ControllerAccess.class);
|
|
||||||
when(controllerAccess.getEcuConfigurationNames()).thenReturn(new String[]{"dev"});
|
|
||||||
return controllerAccess;
|
return controllerAccess;
|
||||||
}).getContent());
|
}).getContent());
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class PluginEntry implements TsPluginBody {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Msq tune = TuneUploder.writeCurrentTune(ControllerAccess.getInstance(), configurationName);
|
Msq tune = TuneUploder.writeCurrentTune(controllerAccessSupplier.get(), configurationName);
|
||||||
Online.uploadTune(tune, tokenPanel, content, new FutureCallback<JSONArray>() {
|
Online.uploadTune(tune, tokenPanel, content, new FutureCallback<JSONArray>() {
|
||||||
@Override
|
@Override
|
||||||
public void completed(JSONArray array) {
|
public void completed(JSONArray array) {
|
||||||
|
|
|
@ -15,13 +15,16 @@ import javax.xml.bind.JAXBException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
|
|
||||||
public class TuneUploder {
|
public class TuneUploder {
|
||||||
static Msq writeCurrentTune(ControllerAccess controllerAccess, String configurationName) {
|
static Msq writeCurrentTune(ControllerAccess controllerAccess, String configurationName) {
|
||||||
|
Objects.requireNonNull(controllerAccess, "controllerAccess");
|
||||||
Msq msq = Msq.create(Fields.TOTAL_CONFIG_SIZE, Fields.TS_SIGNATURE);
|
Msq msq = Msq.create(Fields.TOTAL_CONFIG_SIZE, Fields.TS_SIGNATURE);
|
||||||
ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer();
|
ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer();
|
||||||
|
Objects.requireNonNull(controllerParameterServer, "controllerParameterServer");
|
||||||
|
|
||||||
Map<String, Constant> fileSystemValues = getFileSystemValues(configurationName);
|
Map<String, Constant> fileSystemValues = getFileSystemValues(configurationName);
|
||||||
|
|
||||||
|
@ -59,6 +62,7 @@ public class TuneUploder {
|
||||||
|
|
||||||
private static void handleParameter(String configurationName, Msq msq, ControllerParameterServer controllerParameterServer, Map<String, Constant> byName, String parameterName) throws ControllerException {
|
private static void handleParameter(String configurationName, Msq msq, ControllerParameterServer controllerParameterServer, Map<String, Constant> byName, String parameterName) throws ControllerException {
|
||||||
ControllerParameter cp = controllerParameterServer.getControllerParameter(configurationName, parameterName);
|
ControllerParameter cp = controllerParameterServer.getControllerParameter(configurationName, parameterName);
|
||||||
|
Objects.requireNonNull(cp, "ControllerParameter");
|
||||||
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)) {
|
||||||
|
|
|
@ -1,26 +1,42 @@
|
||||||
package com.rusefi.ts_plugin;
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
|
import com.rusefi.ui.storage.PersistentConfiguration;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
public class UploadView {
|
public class UploadView {
|
||||||
private final JComponent content = new JPanel(new VerticalFlowLayout());
|
private final JComponent content = new JPanel(new VerticalFlowLayout());
|
||||||
|
|
||||||
|
private static final String AUTO_UPLOAD = "AUTO_UPLOAD";
|
||||||
|
|
||||||
private final JLabel uploadState = new JLabel();
|
private final JLabel uploadState = new JLabel();
|
||||||
private final JLabel projectWarning = new JLabel(UploaderStatus.NO_PROJECT);
|
private final JLabel projectWarning = new JLabel(UploaderStatus.NO_PROJECT);
|
||||||
private final JLabel tuneInfo = new JLabel();
|
private final JLabel tuneInfo = new JLabel();
|
||||||
|
private final JCheckBox autoUpload = new JCheckBox("Continuous auto-upload");
|
||||||
|
|
||||||
public UploadView() {
|
public UploadView() {
|
||||||
content.add(projectWarning);
|
content.add(projectWarning);
|
||||||
content.add(tuneInfo);
|
content.add(tuneInfo);
|
||||||
content.add(uploadState);
|
content.add(uploadState);
|
||||||
|
|
||||||
|
autoUpload.setSelected(isAutoUpload());
|
||||||
|
autoUpload.addActionListener(new AbstractAction() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PersistentConfiguration.getConfig().getRoot().setProperty(AUTO_UPLOAD, autoUpload.isSelected());
|
||||||
|
}
|
||||||
|
});
|
||||||
uploadState.setVisible(false);
|
uploadState.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAutoUpload() {
|
||||||
|
return PersistentConfiguration.getConfig().getRoot().getBoolProperty(AUTO_UPLOAD, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void setResult(JSONArray array) {
|
public void setResult(JSONArray array) {
|
||||||
uploadState.setText(array.get(0).toString());
|
uploadState.setText(array.get(0).toString());
|
||||||
uploadState.setVisible(true);
|
uploadState.setVisible(true);
|
||||||
|
|
Loading…
Reference in New Issue