Skip to content

[WIP] Rework serial ports handling #4482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4a9d339
update liblistSerials to 1.0.7
facchinm Jan 25, 2016
d349acc
[AVR USB] move leds handling inside USB_Recv function
facchinm Jan 25, 2016
cd4871c
[AVR] [USB] Expose USB as 2.1 compatible
facchinm Jan 25, 2016
f027003
[AVR] [USB] Discover newer bootloader at runtime
facchinm Jan 25, 2016
3f07b8a
Avoid multiple concurrent compile/upload operations
facchinm Jan 25, 2016
2c6d8d0
Fix NPE when replacing unexisting strings
facchinm Jan 25, 2016
91b94c8
Rework Serial ports handling and add Board info menu
facchinm Jan 25, 2016
9568d8b
Merge branch 'master' into iserial2_complete
facchinm Jan 25, 2016
a0ac217
fix exception if remote upload fails on newer ssh client
facchinm Feb 4, 2016
5812d42
avoid NPE in CLI mode (boardInfo not yet initialized)
facchinm Feb 5, 2016
a9ed40a
Merge branch 'master' into iserial2_complete
facchinm Feb 9, 2016
a65f577
Avoid generating an exception if upload fails
facchinm Feb 11, 2016
da77080
Handle case with empty error message
facchinm Feb 11, 2016
1bc2121
add specifier to generated tool property keys
facchinm Feb 12, 2016
58f4ad0
initialize the error string as empty (not null)
facchinm Feb 15, 2016
162e2cb
update jmdns to 3.4.2
facchinm Feb 15, 2016
d403c9a
greatly simplify Network discovery code
facchinm Feb 15, 2016
f38056c
avoid notification popup to stay on top of EVERYTHING
facchinm Feb 23, 2016
5a2dfa4
avoid NPE if serial monitor is waiting too long for opening
facchinm Feb 23, 2016
9031af8
Merge remote-tracking branch 'origin/iserial2_complete' into nuy_test
facchinm Feb 23, 2016
e3561ac
try to avoid NPE if two threads modify library list
facchinm Mar 2, 2016
a86176d
set a real pty for sending ssh commands
facchinm Mar 2, 2016
f6bccab
propose updated library only if architecture compatible
facchinm Mar 3, 2016
b418316
Change message if requiring infos from Network port
facchinm Mar 3, 2016
1ada616
Fix randomic NPE when pressing menus during operations
facchinm Mar 8, 2016
b4286c7
Merge remote-tracking branch 'arduino/master' into iserial2_complete
facchinm Mar 8, 2016
a4ed0fa
Merge branch 'master' into iserial2_complete
facchinm Mar 10, 2016
09fbef6
Increase wait for upload port timeout to 5s on all platforms
sandeepmistry Feb 1, 2016
5a69e51
Add OS X specific delay after waiting for upload port, to prevent "Re…
sandeepmistry Feb 29, 2016
a63ec15
Apply extra 250ms after waitForUploadPort to all platforms
sandeepmistry Mar 10, 2016
944dcf1
TEST: jmdns hacking
facchinm Feb 19, 2016
a1efb61
Revert "set a real pty for sending ssh commands"
facchinm Mar 15, 2016
d64cb94
Merge remote-tracking branch 'arduino/master' into iserial2_complete
facchinm Mar 21, 2016
d1516f6
Enable links to directly open Lib/Board manager
facchinm Mar 22, 2016
2cd64e5
avoid NPE for synchronization issues on board list
facchinm Mar 25, 2016
dd970b2
Changed color of version text in About box
Mar 22, 2016
655be00
update arduino-builder to 1.3.15
facchinm Mar 25, 2016
60c3ca8
use hi-res icons for serial monitor and plotter
facchinm Mar 25, 2016
815ccf1
add a flag to pause polling for serial port
facchinm Mar 25, 2016
51dcc5d
Revert using 3 seconds poll on Windows
facchinm Apr 1, 2016
dfe75e8
Merge remote-tracking branch 'arduino/master' into iserial2_complete
facchinm Apr 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<classpathentry kind="lib" path="lib/jackson-databind-2.6.3.jar"/>
<classpathentry kind="lib" path="lib/jackson-module-mrbean-2.6.3.jar"/>
<classpathentry kind="lib" path="lib/java-semver-0.8.0.jar"/>
<classpathentry kind="lib" path="lib/jmdns-3.4.1.jar"/>
<classpathentry kind="lib" path="lib/jmdns-3.4.2.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-2.5.8.1+arduino.jar"/>
Expand Down
Binary file removed app/lib/jmdns-3.4.1.jar
Binary file not shown.
Binary file added app/lib/jmdns-3.4.2.jar
Binary file not shown.
10 changes: 8 additions & 2 deletions app/src/cc/arduino/UpdatableBoardsLibsFakeURLsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,28 @@ public void hyperlinkUpdate(HyperlinkEvent event) {
}

URL url = event.getURL();
openBoardLibManager(url);
}

public void openBoardLibManager(URL url) {
if (BOARDSMANAGER.equals(url.getHost())) {
try {
base.openBoardsManager("", "DropdownUpdatableCoresItem");
base.openBoardsManager(url.getRef() == null ? "": url.getRef() , url.getPath() == null ? "" : url.getPath().replace("/", ""));
} catch (Exception e) {
e.printStackTrace();
}
return;
}

System.out.println(url.getRef() + " " + url.getHost() + " " + url.getPath());

if (LIBRARYMANAGER.equals(url.getHost())) {
base.openLibraryManager("DropdownUpdatableLibrariesItem");
base.openLibraryManager(url.getRef() == null ? "": url.getRef() , url.getPath() == null ? "" : url.getPath().replace("/", ""));
return;
}

throw new IllegalArgumentException(url.getHost() + " is invalid");

}

}
4 changes: 2 additions & 2 deletions app/src/cc/arduino/contributions/ContributionsSelfCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public void run() {

String text;
if (updatableLibraries > 0 && updatablePlatforms <= 0) {
text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager/DropdownUpdatableLibrariesItem\">", "</a>");
} else if (updatableLibraries <= 0 && updatablePlatforms > 0) {
text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager/DropdownUpdatableCoresItem\">", "</a>");
} else {
text = I18n.format(tr("Updates available for some of your {0}boards{1} and {2}libraries{3}"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public boolean test(ContributedLibrary contributedLibrary) {
}
List<ContributedLibrary> libraries = BaseNoGui.librariesIndexer.getIndex().find(libraryName);
return libraries.stream()
.filter(library -> versionComparator.greaterThan(library.getParsedVersion(), installed.getParsedVersion()))
.filter(library -> versionComparator.greaterThan(library.getParsedVersion(), installed.getParsedVersion())
&& library.getArchitectures().containsAll(installed.getArchitectures()))
.count() > 0;
}
}
2 changes: 1 addition & 1 deletion app/src/cc/arduino/view/NotificationPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
super(parent, false);
setLayout(new FlowLayout());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
//setAlwaysOnTop(true);
setUndecorated(true);
setResizable(false);

Expand Down
7 changes: 5 additions & 2 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ public void rebuildImportMenu(JMenu importMenu) {
importMenu.removeAll();

JMenuItem menu = new JMenuItem(tr("Manage Libraries..."));
menu.addActionListener(e -> openLibraryManager(""));
menu.addActionListener(e -> openLibraryManager("", ""));
importMenu.add(menu);
importMenu.addSeparator();

Expand Down Expand Up @@ -1264,7 +1264,7 @@ public void onBoardOrPortChange() {
}
}

public void openLibraryManager(String dropdownItem) {
public void openLibraryManager(final String filterText, String dropdownItem) {
if (contributionsSelfCheck != null) {
contributionsSelfCheck.cancel();
}
Expand All @@ -1280,6 +1280,9 @@ protected void onIndexesUpdated() throws Exception {
if (StringUtils.isNotEmpty(dropdownItem)) {
selectDropdownItemByClassName(dropdownItem);
}
if (StringUtils.isNotEmpty(filterText)) {
setFilterText(filterText);
}
}
};
managerUI.setLocationRelativeTo(activeEditor);
Expand Down
115 changes: 101 additions & 14 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import cc.arduino.view.GoToLineNumber;
import cc.arduino.view.StubMenuListener;
import cc.arduino.view.findreplace.FindReplace;
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler;
import com.jcraft.jsch.JSchException;
import jssc.SerialPortException;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
Expand Down Expand Up @@ -145,6 +146,8 @@ public boolean test(Sketch sketch) {

private int numTools = 0;

public boolean avoidMultipleOperations = false;

private final EditorToolbar toolbar;
// these menus are shared so that they needn't be rebuilt for all windows
// each time a sketch is created, renamed, or moved.
Expand Down Expand Up @@ -197,7 +200,7 @@ public boolean test(Sketch sketch) {
private Runnable stopHandler;
Runnable exportHandler;
private Runnable exportAppHandler;

private Runnable timeoutUploadHandler;

public Editor(Base ibase, File file, int[] storedLocation, int[] defaultLocation, Platform platform) throws Exception {
super("Arduino");
Expand Down Expand Up @@ -811,6 +814,9 @@ public void actionPerformed(ActionEvent e) {
portMenu = new JMenu(tr("Port"));
populatePortMenu();
toolsMenu.add(portMenu);
item = new JMenuItem(tr("Get Board Info"));
item.addActionListener(e -> handleBoardInfo());
toolsMenu.add(item);
toolsMenu.addSeparator();

base.rebuildProgrammerMenu();
Expand Down Expand Up @@ -1015,9 +1021,15 @@ private SketchTextArea createTextArea() throws IOException {
textArea.setTabSize(PreferencesData.getInteger("editor.tabs.size"));
textArea.addHyperlinkListener(evt -> {
try {
platform.openURL(sketch.getFolder(), evt.getURL().toExternalForm());
} catch (Exception e) {
Base.showWarning(e.getMessage(), e.getMessage(), e);
UpdatableBoardsLibsFakeURLsHandler boardLibHandler = new UpdatableBoardsLibsFakeURLsHandler(base);
boardLibHandler.openBoardLibManager(evt.getURL());
}
catch (Exception e) {
try {
platform.openURL(sketch.getFolder(), evt.getURL().toExternalForm());
} catch (Exception f) {
Base.showWarning(f.getMessage(), f.getMessage(), f);
}
}
});
textArea.addCaretListener(e -> {
Expand Down Expand Up @@ -1641,6 +1653,7 @@ private void resetHandlers() {
stopHandler = new DefaultStopHandler();
exportHandler = new DefaultExportHandler();
exportAppHandler = new DefaultExportAppHandler();
timeoutUploadHandler = new TimeoutUploadHandler();
}


Expand Down Expand Up @@ -1972,6 +1985,7 @@ public void run() {

status.unprogress();
toolbar.deactivateRun();
avoidMultipleOperations = false;
}
}

Expand Down Expand Up @@ -2360,6 +2374,7 @@ synchronized public void handleExport(final boolean usingProgrammer) {
console.clear();
status.progress(tr("Uploading to I/O Board..."));

new Thread(timeoutUploadHandler).start();
new Thread(usingProgrammer ? exportAppHandler : exportHandler).start();
}

Expand Down Expand Up @@ -2399,6 +2414,7 @@ public void run() {
e.printStackTrace();
} finally {
populatePortMenu();
avoidMultipleOperations = false;
}
status.unprogress();
uploading = false;
Expand Down Expand Up @@ -2426,13 +2442,14 @@ private void resumeOrCloseSerialMonitor() {
}
}
try {
if (serialMonitor != null)
serialMonitor.resume(boardPort);
if (boardPort == null) {
serialMonitor.close();
handleSerial();
} else {
if (serialMonitor != null) {
serialMonitor.resume(boardPort);
if (boardPort == null) {
serialMonitor.close();
handleSerial();
} else {
serialMonitor.resume(boardPort);
}
}
} catch (Exception e) {
statusError(e);
Expand Down Expand Up @@ -2493,6 +2510,7 @@ public void run() {
} catch (Exception e) {
e.printStackTrace();
} finally {
avoidMultipleOperations = false;
populatePortMenu();
}
status.unprogress();
Expand All @@ -2507,6 +2525,20 @@ public void run() {
}
}

class TimeoutUploadHandler implements Runnable {

public void run() {
try {
//10 seconds, than reactivate upload functionality and let the programmer pid being killed
Thread.sleep(1000 * 10);
if (uploading) {
avoidMultipleOperations = false;
}
} catch (InterruptedException e) {
// noop
}
}
}

public void handleSerial() {
if(serialPlotter != null) {
Expand Down Expand Up @@ -2547,11 +2579,11 @@ public void handleSerial() {
}

serialMonitor = new MonitorFactory().newMonitor(port);
serialMonitor.setIconImage(getIconImage());
base.setIcon(serialMonitor);

// If currently uploading, disable the monitor (it will be later
// enabled when done uploading)
if (uploading) {
if (uploading || avoidMultipleOperations) {
try {
serialMonitor.suspend();
} catch (Exception e) {
Expand All @@ -2575,8 +2607,10 @@ public void handleSerial() {
}

try {
serialMonitor.open();
serialMonitor.setVisible(true);
if (!avoidMultipleOperations) {
serialMonitor.open();
}
success = true;
} catch (ConnectException e) {
statusError(tr("Unable to connect: is the sketch using the bridge?"));
Expand Down Expand Up @@ -2643,7 +2677,7 @@ public void handlePlotter() {
}

serialPlotter = new SerialPlotter(port);
serialPlotter.setIconImage(getIconImage());
base.setIcon(serialPlotter);

// If currently uploading, disable the plotter (it will be later
// enabled when done uploading)
Expand Down Expand Up @@ -2723,6 +2757,59 @@ private void handleBurnBootloader() {
}).start();
}

private void handleBoardInfo() {
console.clear();

String selectedPort = PreferencesData.get("serial.port");
List<BoardPort> ports = Base.getDiscoveryManager().discovery();

String label = "";
String vid = "";
String pid = "";
String iserial = "";
String protocol = "";
boolean found = false;

for (BoardPort port : ports) {
if (port.getAddress().equals(selectedPort)) {
label = port.getBoardName();
vid = port.getVID();
pid = port.getPID();
iserial = port.getISerial();
protocol = port.getProtocol();
found = true;
break;
}
}

if (!found) {
statusNotice(tr("Please select a port to obtain board info"));
return;
}

if (protocol.equals("network")) {
statusNotice(tr("Network port, can't obtain info"));
return;
}

if (vid == null || vid.equals("") || vid.equals("0000")) {
statusNotice(tr("Native serial port, can't obtain info"));
return;
}

if (iserial == null || iserial.equals("")) {
iserial = tr("Upload any sketch to obtain it");
}

if (label == null) {
label = tr("Unknown board");
}

String infos = I18n.format("BN: {0}\nVID: {1}\nPID: {2}\nSN: {3}", label, vid, pid, iserial);
JTextArea textArea = new JTextArea(infos);

JOptionPane.showMessageDialog(this, textArea, tr("Board Info"), JOptionPane.PLAIN_MESSAGE);
}

/**
* Handler for File &rarr; Page Setup.
Expand Down
5 changes: 5 additions & 0 deletions app/src/processing/app/EditorLineStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class EditorLineStatus extends JComponent {
String text = "";
String name = "";
String serialport = "";
String serialnumber = "";

public EditorLineStatus() {
background = Theme.getColor("linestatus.bgcolor");
Expand Down Expand Up @@ -129,6 +130,10 @@ public void setSerialPort(String serialport) {
this.serialport = serialport;
}

public void setSerialNumber(String serialnumber) {
this.serialnumber = serialnumber;
}

public Dimension getPreferredSize() {
return scale(new Dimension(300, height));
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/processing/app/EditorToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ public void mousePressed(MouseEvent e) {

switch (sel) {
case RUN:
editor.handleRun(false, editor.presentHandler, editor.runHandler);
if (!editor.avoidMultipleOperations) {
editor.handleRun(false, editor.presentHandler, editor.runHandler);
editor.avoidMultipleOperations = true;
}
break;

// case STOP:
Expand Down Expand Up @@ -370,7 +373,11 @@ public void mousePressed(MouseEvent e) {
break;

case EXPORT:
editor.handleExport(e.isShiftDown());
// launch a timeout timer which can reenable to upload button functionality an
if (!editor.avoidMultipleOperations) {
editor.handleExport(e.isShiftDown());
editor.avoidMultipleOperations = true;
}
break;

case SERIAL:
Expand Down
Loading