RE TS plugin to have continues tune auto-upload feature #1605

This commit is contained in:
rusefi 2020-07-15 00:23:43 -04:00
parent 6edf92ba3d
commit 7a77e53c59
6 changed files with 85 additions and 23 deletions

View File

@ -0,0 +1,36 @@
package com.rusefi.ts_plugin;
import com.opensr5.ini.IniFileMetaInfo;
import com.opensr5.ini.RawIniFile;
import com.rusefi.TsTuneReader;
import org.jetbrains.annotations.Nullable;
import java.io.FileNotFoundException;
public class MetaDataCache {
private static String cachedProjectName;
private static IniFileMetaInfo cache;
@Nullable
public synchronized static IniFileMetaInfo getModel(String projectName) {
if (projectName == null)
return null;
if (!projectName.equals(cachedProjectName)) {
cache = null;
}
if (cache == null) {
System.out.println("Reading meta " + projectName);
String modeFileName = TsTuneReader.getProjectModeFileName(projectName);
try {
cache = new IniFileMetaInfo(RawIniFile.read(modeFileName));
} catch (FileNotFoundException e) {
System.out.println("No luck reading " + modeFileName + ": " + e);
return null;
}
cachedProjectName = projectName;
}
return cache;
}
}

View File

@ -14,7 +14,6 @@ import com.rusefi.ts_plugin.util.ManifestHelper;
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.AuthTokenPanel;
import com.rusefi.ui.storage.PersistentConfiguration;
import com.rusefi.ui.util.URLLabel; import com.rusefi.ui.util.URLLabel;
import org.apache.http.concurrent.FutureCallback; import org.apache.http.concurrent.FutureCallback;
import org.putgemin.VerticalFlowLayout; import org.putgemin.VerticalFlowLayout;
@ -50,13 +49,7 @@ public class PluginEntry implements TsPluginBody {
} }
}); });
ControllerParameterChangeListener listener = new ControllerParameterChangeListener() { private final ControllerParameterChangeListener listener;
@Override
public void parameterValueChanged(String parameterName) {
System.out.println("Parameter value changed " + parameterName);
timer.restart();
}
};
/** /**
* the real constructor - this one is invoked via reflection * the real constructor - this one is invoked via reflection
@ -70,6 +63,13 @@ public class PluginEntry implements TsPluginBody {
timer.stop(); timer.stop();
timer.setRepeats(false); timer.setRepeats(false);
this.controllerAccessSupplier = controllerAccessSupplier; this.controllerAccessSupplier = controllerAccessSupplier;
listener = parameterName -> {
// System.out.println("Parameter value changed " + parameterName);
timer.restart();
if (UploadView.isAutoUpload()) {
UploadQueue.enqueue(controllerAccessSupplier.get(), currentConfiguration);
}
};
upload.setBackground(new Color(0x90EE90)); upload.setBackground(new Color(0x90EE90));
new Thread(new Runnable() { new Thread(new Runnable() {
@ -205,11 +205,11 @@ public class PluginEntry implements TsPluginBody {
public JComponent getContent() { public JComponent getContent() {
return content; return content;
} }
/*
public void close() { public void close() {
PersistentConfiguration.getConfig().save(); PersistentConfiguration.getConfig().save();
} }
*/
private String getConfigurationName() { private String getConfigurationName() {
ControllerAccess controllerAccess = controllerAccessSupplier.get(); ControllerAccess controllerAccess = controllerAccessSupplier.get();
if (controllerAccess == null) { if (controllerAccess == null) {

View File

@ -4,12 +4,14 @@ 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.opensr5.ini.IniFileMetaInfo;
import com.rusefi.TsTuneReader; import com.rusefi.TsTuneReader;
import com.rusefi.tools.online.Online; 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.tune.xml.Page; import com.rusefi.tune.xml.Page;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import java.io.IOException; import java.io.IOException;
@ -17,12 +19,29 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.TreeMap; import java.util.TreeMap;
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) {
Msq msq = grabTune(controllerAccess, configurationName);
if (msq == null)
return null;
try {
String fileName = Online.outputXmlFileName;
msq.writeXmlFile(fileName);
return msq;
} catch (JAXBException | IOException e) {
System.out.println("Error writing XML: " + e);
return null;
}
}
@Nullable
public static Msq grabTune(ControllerAccess controllerAccess, String configurationName) {
Objects.requireNonNull(controllerAccess, "controllerAccess"); Objects.requireNonNull(controllerAccess, "controllerAccess");
Msq msq = Msq.create(Fields.TOTAL_CONFIG_SIZE, Fields.TS_SIGNATURE); IniFileMetaInfo meta = MetaDataCache.getModel(configurationName);
if (meta == null)
return null;
Msq msq = Msq.create(meta.getTotalSize(), meta.getSignature());
ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer(); ControllerParameterServer controllerParameterServer = controllerAccess.getControllerParameterServer();
Objects.requireNonNull(controllerParameterServer, "controllerParameterServer"); Objects.requireNonNull(controllerParameterServer, "controllerParameterServer");
@ -31,16 +50,13 @@ public class TuneUploder {
try { try {
String[] parameterNames = controllerParameterServer.getParameterNames(configurationName); String[] parameterNames = controllerParameterServer.getParameterNames(configurationName);
for (String parameterName : parameterNames) { for (String parameterName : parameterNames) {
handleParameter(configurationName, msq, controllerParameterServer, fileSystemValues, parameterName); applyParameterValue(configurationName, msq, controllerParameterServer, fileSystemValues, parameterName);
} }
} catch (ControllerException e) {
String fileName = Online.outputXmlFileName; System.out.println("Error saving configuration: " + e);
msq.writeXmlFile(fileName);
return msq;
} catch (JAXBException | IOException | ControllerException e) {
System.out.println("Error writing XML: " + e);
return null; return null;
} }
return msq;
} }
@NotNull @NotNull
@ -60,7 +76,7 @@ public class TuneUploder {
return byName; return byName;
} }
private static void handleParameter(String configurationName, Msq msq, ControllerParameterServer controllerParameterServer, Map<String, Constant> byName, String parameterName) throws ControllerException { private static void applyParameterValue(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"); Objects.requireNonNull(cp, "ControllerParameter");
String type = cp.getParamClass(); String type = cp.getParamClass();

View File

@ -0,0 +1,10 @@
package com.rusefi.ts_plugin;
import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.rusefi.tune.xml.Msq;
public class UploadQueue {
public static void enqueue(ControllerAccess controllerAccess, String configurationName) {
Msq msq = TuneUploder.grabTune(controllerAccess, configurationName);
}
}

View File

@ -2,7 +2,6 @@ package com.rusefi.ts_plugin;
import com.rusefi.tools.online.UploadResult; import com.rusefi.tools.online.UploadResult;
import com.rusefi.ui.storage.PersistentConfiguration; import com.rusefi.ui.storage.PersistentConfiguration;
import org.json.simple.JSONArray;
import org.putgemin.VerticalFlowLayout; import org.putgemin.VerticalFlowLayout;
import javax.swing.*; import javax.swing.*;
@ -34,7 +33,7 @@ public class UploadView {
uploadState.setVisible(false); uploadState.setVisible(false);
} }
private static boolean isAutoUpload() { public static boolean isAutoUpload() {
return PersistentConfiguration.getConfig().getRoot().getBoolProperty(AUTO_UPLOAD, false); return PersistentConfiguration.getConfig().getRoot().getBoolProperty(AUTO_UPLOAD, false);
} }

View File

@ -6,6 +6,7 @@ public interface TsPluginBody {
String GET_VERSION = "getVersion"; String GET_VERSION = "getVersion";
JComponent getContent(); JComponent getContent();
/*
void close(); void close();
*/
} }