TS SD integration #1653
This commit is contained in:
parent
51b8da5b3d
commit
1b109fc52f
|
@ -2,32 +2,31 @@ package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
import com.rusefi.TsTuneReader;
|
import com.rusefi.TsTuneReader;
|
||||||
import com.rusefi.ui.util.FrameHelper;
|
import com.rusefi.ui.util.FrameHelper;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class LogUploadSelector {
|
public class LogUploadSelector {
|
||||||
private JPanel content = new JPanel(new VerticalFlowLayout());
|
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FrameHelper().showFrame(new LogUploadSelector().getContent());
|
new FrameHelper().showFrame(new LogUploadSelector().getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LogUploadSelector() {
|
public LogUploadSelector() {
|
||||||
|
|
||||||
String projectName = "dev";
|
String projectName = "dev";
|
||||||
String folder = TsTuneReader.getProjectsDir()
|
String folder = getLogsFolderDir(projectName);
|
||||||
+ File.separator + projectName + File.separator + "DataLogs";
|
|
||||||
|
|
||||||
|
|
||||||
for (String fileName : new File(folder).list((dir, name) -> name.endsWith(".mlg"))) {
|
for (String fileName : new File(folder).list((dir, name) -> name.endsWith(".mlg"))) {
|
||||||
System.out.println(fileName);
|
System.out.println(fileName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String getLogsFolderDir(String projectName) {
|
||||||
|
return TsTuneReader.getProjectsDir() + File.separator + projectName + File.separator + "DataLogs";
|
||||||
}
|
}
|
||||||
|
|
||||||
private JComponent getContent() {
|
private JComponent getContent() {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class PluginEntry implements TsPluginBody {
|
||||||
tabbedPane.addTab("Upload", uploadTab.getContent());
|
tabbedPane.addTab("Upload", uploadTab.getContent());
|
||||||
tabbedPane.addTab("Broadcast", broadcastTab.getContent());
|
tabbedPane.addTab("Broadcast", broadcastTab.getContent());
|
||||||
tabbedPane.addTab("Remote ECU", remoteTab.getContent());
|
tabbedPane.addTab("Remote ECU", remoteTab.getContent());
|
||||||
tabbedPane.addTab("Read SD Card", new SdCardReader().getContent());
|
tabbedPane.addTab("Read SD Card", new SdCardReader(controllerAccessSupplier).getContent());
|
||||||
content.add(tabbedPane);
|
content.add(tabbedPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.rusefi.ts_plugin;
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
import com.devexperts.logging.Logging;
|
import com.devexperts.logging.Logging;
|
||||||
|
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
||||||
import com.rusefi.autoupdate.AutoupdateUtil;
|
import com.rusefi.autoupdate.AutoupdateUtil;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.io.ConnectionStateListener;
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
|
@ -10,6 +11,8 @@ import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -18,6 +21,7 @@ import java.text.CharacterIterator;
|
||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static com.devexperts.logging.Logging.getLogging;
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
import static com.rusefi.config.generated.Fields.TS_SD_PROTOCOL_FETCH_INFO;
|
import static com.rusefi.config.generated.Fields.TS_SD_PROTOCOL_FETCH_INFO;
|
||||||
|
@ -41,15 +45,35 @@ public class SdCardReader {
|
||||||
public void onConnectionFailed() {
|
public void onConnectionFailed() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
private final Supplier<ControllerAccess> controllerAccessSupplier;
|
||||||
|
|
||||||
public SdCardReader() {
|
public SdCardReader(Supplier<ControllerAccess> controllerAccessSupplier) {
|
||||||
|
this.controllerAccessSupplier = controllerAccessSupplier;
|
||||||
JButton refresh = new JButton("Refresh");
|
JButton refresh = new JButton("Refresh");
|
||||||
refresh.addActionListener(e -> IO_THREAD.execute(this::requestFileList));
|
refresh.addActionListener(e -> IO_THREAD.execute(this::requestFileList));
|
||||||
|
|
||||||
JPanel topPanel = new JPanel(new BorderLayout());
|
JPanel topPanel = new JPanel(new BorderLayout());
|
||||||
|
JPanel lowPanel = new JPanel(new FlowLayout());
|
||||||
|
|
||||||
|
JButton open = new JButton("Open Destination Folder");
|
||||||
|
lowPanel.add(refresh);
|
||||||
|
lowPanel.add(open);
|
||||||
|
|
||||||
|
open.addActionListener(new AbstractAction() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
String folder = getDestinationFolder(controllerAccessSupplier);
|
||||||
|
Runtime.getRuntime().exec("explorer.exe /select," + folder + File.separator);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("Error", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
topPanel.add(connectPanel.getContent(), BorderLayout.NORTH);
|
topPanel.add(connectPanel.getContent(), BorderLayout.NORTH);
|
||||||
topPanel.add(status, BorderLayout.CENTER);
|
topPanel.add(status, BorderLayout.CENTER);
|
||||||
topPanel.add(AutoupdateUtil.wrap(refresh), BorderLayout.SOUTH);
|
topPanel.add(lowPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
content.add(topPanel, BorderLayout.NORTH);
|
content.add(topPanel, BorderLayout.NORTH);
|
||||||
content.add(fileList, BorderLayout.CENTER);
|
content.add(fileList, BorderLayout.CENTER);
|
||||||
|
@ -57,6 +81,12 @@ public class SdCardReader {
|
||||||
content.add(new JLabel("<html>This tab allows direct access to SD card<br/>Please be sure to disconnect Tuner Studio from ECU while downloading files using this tab"), BorderLayout.SOUTH);
|
content.add(new JLabel("<html>This tab allows direct access to SD card<br/>Please be sure to disconnect Tuner Studio from ECU while downloading files using this tab"), BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getDestinationFolder(Supplier<ControllerAccess> controllerAccessSupplier) {
|
||||||
|
String folder = LogUploadSelector.getLogsFolderDir(controllerAccessSupplier.get().getEcuConfigurationNames()[0]);
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
public Component getContent() {
|
public Component getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +208,7 @@ public class SdCardReader {
|
||||||
log.info("Download file " + IoStream.printHexBinary(response));
|
log.info("Download file " + IoStream.printHexBinary(response));
|
||||||
setStatus("Downloading " + fileName);
|
setStatus("Downloading " + fileName);
|
||||||
|
|
||||||
fos = new FileOutputStream("downloaded_" + fileName, false);
|
fos = new FileOutputStream(getDestinationFolder(controllerAccessSupplier) + File.separator + fileName, false);
|
||||||
int chunk = 0;
|
int chunk = 0;
|
||||||
int totalSize = 0;
|
int totalSize = 0;
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
Loading…
Reference in New Issue