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.ui.util.FrameHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
public class LogUploadSelector {
|
||||
private JPanel content = new JPanel(new VerticalFlowLayout());
|
||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
public static void main(String[] args) {
|
||||
new FrameHelper().showFrame(new LogUploadSelector().getContent());
|
||||
}
|
||||
|
||||
|
||||
public LogUploadSelector() {
|
||||
|
||||
String projectName = "dev";
|
||||
String folder = TsTuneReader.getProjectsDir()
|
||||
+ File.separator + projectName + File.separator + "DataLogs";
|
||||
|
||||
String folder = getLogsFolderDir(projectName);
|
||||
|
||||
for (String fileName : new File(folder).list((dir, name) -> name.endsWith(".mlg"))) {
|
||||
System.out.println(fileName);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getLogsFolderDir(String projectName) {
|
||||
return TsTuneReader.getProjectsDir() + File.separator + projectName + File.separator + "DataLogs";
|
||||
}
|
||||
|
||||
private JComponent getContent() {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PluginEntry implements TsPluginBody {
|
|||
tabbedPane.addTab("Upload", uploadTab.getContent());
|
||||
tabbedPane.addTab("Broadcast", broadcastTab.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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
||||
import com.rusefi.autoupdate.AutoupdateUtil;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
|
@ -10,6 +11,8 @@ import org.putgemin.VerticalFlowLayout;
|
|||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -18,6 +21,7 @@ import java.text.CharacterIterator;
|
|||
import java.text.StringCharacterIterator;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
import static com.rusefi.config.generated.Fields.TS_SD_PROTOCOL_FETCH_INFO;
|
||||
|
@ -41,15 +45,35 @@ public class SdCardReader {
|
|||
public void onConnectionFailed() {
|
||||
}
|
||||
});
|
||||
private final Supplier<ControllerAccess> controllerAccessSupplier;
|
||||
|
||||
public SdCardReader() {
|
||||
public SdCardReader(Supplier<ControllerAccess> controllerAccessSupplier) {
|
||||
this.controllerAccessSupplier = controllerAccessSupplier;
|
||||
JButton refresh = new JButton("Refresh");
|
||||
refresh.addActionListener(e -> IO_THREAD.execute(this::requestFileList));
|
||||
|
||||
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(status, BorderLayout.CENTER);
|
||||
topPanel.add(AutoupdateUtil.wrap(refresh), BorderLayout.SOUTH);
|
||||
topPanel.add(lowPanel, BorderLayout.SOUTH);
|
||||
|
||||
content.add(topPanel, BorderLayout.NORTH);
|
||||
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);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getDestinationFolder(Supplier<ControllerAccess> controllerAccessSupplier) {
|
||||
String folder = LogUploadSelector.getLogsFolderDir(controllerAccessSupplier.get().getEcuConfigurationNames()[0]);
|
||||
return folder;
|
||||
}
|
||||
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
|
@ -178,7 +208,7 @@ public class SdCardReader {
|
|||
log.info("Download file " + IoStream.printHexBinary(response));
|
||||
setStatus("Downloading " + fileName);
|
||||
|
||||
fos = new FileOutputStream("downloaded_" + fileName, false);
|
||||
fos = new FileOutputStream(getDestinationFolder(controllerAccessSupplier) + File.separator + fileName, false);
|
||||
int chunk = 0;
|
||||
int totalSize = 0;
|
||||
long start = System.currentTimeMillis();
|
||||
|
|
Loading…
Reference in New Issue