mirror of https://github.com/rusefi/rusefi-1.git
auto-sync
This commit is contained in:
parent
d137a51e08
commit
2cacb9f92c
|
@ -26,9 +26,10 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
|||
*
|
||||
* @see StartupFrame
|
||||
* @see com.rusefi.ui.engine.EngineSnifferPanel
|
||||
* @see com.rusefi.StartupFrame
|
||||
*/
|
||||
public class Launcher extends FrameHelper {
|
||||
public static final int CONSOLE_VERSION = 20150223;
|
||||
public static final int CONSOLE_VERSION = 20150228;
|
||||
public static final boolean SHOW_STIMULATOR = true;
|
||||
public static final String TAB_INDEX = "main_tab";
|
||||
private final String port;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi;
|
|||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
import com.rusefi.maintenance.FirmwareFlasher;
|
||||
import com.rusefi.maintenance.ProcessStatusWindow;
|
||||
import com.rusefi.ui.util.HorizontalLine;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
import com.rusefi.ui.util.URLLabel;
|
||||
|
@ -61,15 +62,15 @@ public class StartupFrame {
|
|||
ports.addAll(Arrays.asList(SerialPortList.getPortNames()));
|
||||
ports.addAll(TcpConnector.getAvailablePorts());
|
||||
|
||||
JPanel startupOptions = new JPanel(new VerticalFlowLayout());
|
||||
startupOptions.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10),
|
||||
JPanel leftPanel = new JPanel(new VerticalFlowLayout());
|
||||
leftPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10),
|
||||
BorderFactory.createLineBorder(Color.darkGray)));
|
||||
|
||||
if (!ports.isEmpty()) {
|
||||
final JPanel connectPanel = new JPanel(new FlowLayout());
|
||||
addPortSelection(ports, connectPanel);
|
||||
startupOptions.add(connectPanel);
|
||||
startupOptions.add(new HorizontalLine());
|
||||
leftPanel.add(connectPanel);
|
||||
leftPanel.add(new HorizontalLine());
|
||||
}
|
||||
|
||||
final JButton buttonLogViewer = new JButton();
|
||||
|
@ -82,29 +83,34 @@ public class StartupFrame {
|
|||
}
|
||||
});
|
||||
|
||||
startupOptions.add(buttonLogViewer);
|
||||
startupOptions.add(new HorizontalLine());
|
||||
leftPanel.add(buttonLogViewer);
|
||||
leftPanel.add(new HorizontalLine());
|
||||
|
||||
startupOptions.add(SimulatorHelper.createSimulatorComponent(this));
|
||||
leftPanel.add(SimulatorHelper.createSimulatorComponent(this));
|
||||
|
||||
if (FirmwareFlasher.isWindows()) {
|
||||
startupOptions.add(new HorizontalLine());
|
||||
startupOptions.add(FirmwareFlasher.getContent());
|
||||
if (ProcessStatusWindow.isWindows()) {
|
||||
leftPanel.add(new HorizontalLine());
|
||||
leftPanel.add(FirmwareFlasher.getContent());
|
||||
}
|
||||
|
||||
startupOptions.add(new HorizontalLine());
|
||||
startupOptions.add(new URLLabel(LINK_TEXT, URI));
|
||||
leftPanel.add(new HorizontalLine());
|
||||
|
||||
JPanel rightPanel = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
JPanel content = new JPanel(new BorderLayout());
|
||||
content.add(startupOptions, BorderLayout.WEST);
|
||||
|
||||
ImageIcon logoIcon = loadIcon(LOGO);
|
||||
if (logoIcon != null) {
|
||||
JLabel logo = new JLabel(logoIcon);
|
||||
logo.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
|
||||
content.add(logo, BorderLayout.EAST);
|
||||
URLLabel.addUrlAction(logo, URLLabel.createUri(URI));
|
||||
logo.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
rightPanel.add(logo);
|
||||
}
|
||||
rightPanel.add(new URLLabel(LINK_TEXT, URI));
|
||||
|
||||
JPanel content = new JPanel(new BorderLayout());
|
||||
content.add(leftPanel, BorderLayout.WEST);
|
||||
content.add(rightPanel, BorderLayout.EAST);
|
||||
frame.add(content);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.rusefi.ui.util.FrameHelper;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
@ -13,33 +10,20 @@ import java.io.*;
|
|||
* (c) Andrey Belomutskiy 2013-2015
|
||||
* 2/4/15
|
||||
*/
|
||||
public class FirmwareFlasher {
|
||||
public static final String IMAGE_FILE = "rusefi.bin";
|
||||
public class FirmwareFlasher extends ProcessStatusWindow {
|
||||
private static final String IMAGE_FILE = "rusefi.bin";
|
||||
private static final String OPEN_OCD_COMMAND = "openocd-0.8.0.exe -f interface/stlink-v2.cfg -f board/stm32f4discovery.cfg -c \"program " +
|
||||
IMAGE_FILE +
|
||||
" verify reset exit 0x08000000\"";
|
||||
public static final String SUCCESS_MESSAGE_TAG = "shutdown command invoked";
|
||||
private static final String SUCCESS_MESSAGE_TAG = "shutdown command invoked";
|
||||
|
||||
private final JButton button = new JButton("Program Firmware");
|
||||
private final JTextArea log = new JTextArea();
|
||||
private final JScrollPane messagesScroll = new JScrollPane(log, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(400, 400);
|
||||
}
|
||||
};
|
||||
|
||||
public FirmwareFlasher() {
|
||||
log.setLineWrap(true);
|
||||
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
FrameHelper f = new FrameHelper();
|
||||
f.getFrame().setTitle("rusEfi Firmware Flasher");
|
||||
f.showFrame(messagesScroll, false);
|
||||
UiUtils.centerWindow(f.getFrame());
|
||||
log.setText(""); // let's remove stuff from previous invocation
|
||||
showFrame();
|
||||
|
||||
Thread openOcdThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
|
@ -58,19 +42,7 @@ public class FirmwareFlasher {
|
|||
appendMsg(IMAGE_FILE + " not found, cannot proceed !!!");
|
||||
return;
|
||||
}
|
||||
appendMsg("Executing " + OPEN_OCD_COMMAND);
|
||||
StringBuffer output = new StringBuffer();
|
||||
StringBuffer error = new StringBuffer();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(OPEN_OCD_COMMAND);
|
||||
startStreamThread(p, p.getInputStream(), output);
|
||||
startStreamThread(p, p.getErrorStream(), error);
|
||||
p.waitFor();
|
||||
} catch (IOException e) {
|
||||
appendMsg("IOError: " + e);
|
||||
} catch (InterruptedException e) {
|
||||
appendMsg("WaitError: " + e);
|
||||
}
|
||||
StringBuffer error = executeCommand(OPEN_OCD_COMMAND);
|
||||
if (error.toString().contains(SUCCESS_MESSAGE_TAG)) {
|
||||
appendMsg("!!! Looks good!!!");
|
||||
} else {
|
||||
|
@ -78,55 +50,6 @@ public class FirmwareFlasher {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method listens to a data stream from the process, appends messages to UI
|
||||
* and accumulates output in a buffer
|
||||
*/
|
||||
private void startStreamThread(final Process p, final InputStream stream, final StringBuffer buffer) {
|
||||
final Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader bis = new BufferedReader(new InputStreamReader(stream));
|
||||
while (isRunning(p)) {
|
||||
String line = bis.readLine();
|
||||
if (line == null)
|
||||
break;
|
||||
appendMsg(line);
|
||||
buffer.append(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
appendMsg("Stream " + e);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private static boolean isRunning(Process p) {
|
||||
try {
|
||||
p.exitValue();
|
||||
return false;
|
||||
} catch (IllegalThreadStateException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void appendMsg(final String s) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.append(s + "\r\n");
|
||||
UiUtils.trueLayout(log);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
return System.getProperty("os.name").toLowerCase().contains("win");
|
||||
}
|
||||
|
||||
public static Component getContent() {
|
||||
return new FirmwareFlasher().button;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.rusefi.ui.util.FrameHelper;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class ProcessStatusWindow {
|
||||
protected final JTextArea log = new JTextArea();
|
||||
private final JScrollPane messagesScroll = new JScrollPane(log, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(400, 400);
|
||||
}
|
||||
};
|
||||
|
||||
public ProcessStatusWindow() {
|
||||
log.setLineWrap(true);
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
return System.getProperty("os.name").toLowerCase().contains("win");
|
||||
}
|
||||
|
||||
protected static boolean isRunning(Process p) {
|
||||
try {
|
||||
p.exitValue();
|
||||
return false;
|
||||
} catch (IllegalThreadStateException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void showFrame() {
|
||||
FrameHelper f = new FrameHelper();
|
||||
f.getFrame().setTitle("rusEfi Firmware Flasher");
|
||||
f.showFrame(messagesScroll, false);
|
||||
UiUtils.centerWindow(f.getFrame());
|
||||
log.setText(""); // let's remove stuff from previous invocation
|
||||
}
|
||||
|
||||
protected void appendMsg(final String s) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.append(s + "\r\n");
|
||||
UiUtils.trueLayout(log);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This method listens to a data stream from the process, appends messages to UI
|
||||
* and accumulates output in a buffer
|
||||
*/
|
||||
protected void startStreamThread(final Process p, final InputStream stream, final StringBuffer buffer) {
|
||||
final Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader bis = new BufferedReader(new InputStreamReader(stream));
|
||||
while (isRunning(p)) {
|
||||
String line = bis.readLine();
|
||||
if (line == null)
|
||||
break;
|
||||
appendMsg(line);
|
||||
buffer.append(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
appendMsg("Stream " + e);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
protected StringBuffer executeCommand(String command) {
|
||||
appendMsg("Executing " + command);
|
||||
StringBuffer output = new StringBuffer();
|
||||
StringBuffer error = new StringBuffer();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
startStreamThread(p, p.getInputStream(), output);
|
||||
startStreamThread(p, p.getErrorStream(), error);
|
||||
p.waitFor();
|
||||
} catch (IOException e) {
|
||||
appendMsg("IOError: " + e);
|
||||
} catch (InterruptedException e) {
|
||||
appendMsg("WaitError: " + e);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
}
|
|
@ -10,13 +10,16 @@ import java.net.URISyntaxException;
|
|||
|
||||
public class URLLabel extends JLabel {
|
||||
private String text;
|
||||
private URI uri;
|
||||
|
||||
public URLLabel(String text, URI uri) {
|
||||
setup(text, uri);
|
||||
}
|
||||
|
||||
public URLLabel(String text, String uri) {
|
||||
setup(text, createUri(uri));
|
||||
}
|
||||
|
||||
public static URI createUri(String uri) {
|
||||
URI oURI;
|
||||
try {
|
||||
oURI = new URI(uri);
|
||||
|
@ -27,18 +30,16 @@ public class URLLabel extends JLabel {
|
|||
// use the other constructor.
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
setup(text, oURI);
|
||||
return oURI;
|
||||
}
|
||||
|
||||
public void setup(String t, URI u) {
|
||||
public void setup(String t, final URI u) {
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
text = t;
|
||||
uri = u;
|
||||
setText(text);
|
||||
setToolTipText(uri.toString());
|
||||
setToolTipText(u.toString());
|
||||
addUrlAction(this, u);
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
open(uri);
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
setText(text, false);
|
||||
|
@ -50,6 +51,14 @@ public class URLLabel extends JLabel {
|
|||
});
|
||||
}
|
||||
|
||||
public static void addUrlAction(JComponent component, final URI u) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
open(u);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
setText(text, true);
|
||||
|
|
Loading…
Reference in New Issue