Skip to content

Commit

Permalink
Rework Serial ports handling and add Board info menu
Browse files Browse the repository at this point in the history
This commit introduces the concept of stateful board list (vs. original stateless) and board serial number.

The board is now an "entity" composed by the triplet port/vid/pid. These informations come from libListSerial "light" function. When the board list changes, it triggers a request for the additional infos to libListSerial. These information contains the serial number of the boards.

These brings a lighter and faster scanning process. Some logic has been introduced to handle a board with the S/N only exposed in the bootloader (like 32u4).
In this case the disappearing port acquires the bootloader's S/N

A menu (under Ports menu) shows the currently connected port info and can be used for bugreporting
  • Loading branch information
facchinm committed Jan 25, 2016
1 parent 2c6d8d0 commit 91b94c8
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 38 deletions.
49 changes: 49 additions & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,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 @@ -2782,6 +2785,52 @@ 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 = "";
boolean found = false;

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

if (!found) {
statusNotice(tr("Please select a port to obtain board 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 @@ -49,6 +49,7 @@ public class EditorLineStatus extends JComponent {
String text = "";
String name = "";
String serialport = "";
String serialnumber = "";


public EditorLineStatus() {
Expand Down Expand Up @@ -125,6 +126,10 @@ public void setSerialPort(String serialport) {
this.serialport = serialport;
}

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

public Dimension getPreferredSize() {
return new Dimension(300, high);
}
Expand Down
36 changes: 36 additions & 0 deletions arduino-core/src/cc/arduino/packages/BoardPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public class BoardPort {
private String address;
private String protocol;
private String boardName;
private String vid;
private String pid;
private String iserial;
private String label;
private final PreferencesMap prefs;
private boolean online;

public BoardPort() {
this.prefs = new PreferencesMap();
Expand Down Expand Up @@ -79,4 +83,36 @@ public String getLabel() {
return label;
}

public void setOnlineStatus(boolean online) {
this.online = online;
}

public boolean isOnline() {
return online;
}

public void setVIDPID(String vid, String pid) {
this.vid = vid;
this.pid = pid;
}

public String getVID() {
return vid;
}

public String getPID() {
return pid;
}

public void setISerial(String iserial) {
this.iserial = iserial;
}
public String getISerial() {
return iserial;
}

@Override
public String toString() {
return this.address+"_"+this.vid+"_"+this.pid;
}
}
1 change: 1 addition & 0 deletions arduino-core/src/cc/arduino/packages/Discovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ public interface Discovery {
* @return
*/
List<BoardPort> listDiscoveredBoards();
List<BoardPort> listDiscoveredBoards(boolean complete);

}
27 changes: 25 additions & 2 deletions arduino-core/src/cc/arduino/packages/DiscoveryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
public class DiscoveryManager {

private final List<Discovery> discoverers;
private final SerialDiscovery serialDiscoverer = new SerialDiscovery();
private final NetworkDiscovery networkDiscoverer = new NetworkDiscovery();

public DiscoveryManager() {
discoverers = new ArrayList<Discovery>();
discoverers.add(new SerialDiscovery());
discoverers.add(new NetworkDiscovery());
discoverers.add(serialDiscoverer);
discoverers.add(networkDiscoverer);

// Start all discoverers
for (Discovery d : discoverers) {
Expand All @@ -69,6 +71,10 @@ public DiscoveryManager() {
Runtime.getRuntime().addShutdownHook(closeHook);
}

public SerialDiscovery getSerialDiscoverer() {
return serialDiscoverer;
}

public List<BoardPort> discovery() {
List<BoardPort> res = new ArrayList<BoardPort>();
for (Discovery d : discoverers) {
Expand All @@ -77,6 +83,14 @@ public List<BoardPort> discovery() {
return res;
}

public List<BoardPort> discovery(boolean complete) {
List<BoardPort> res = new ArrayList<BoardPort>();
for (Discovery d : discoverers) {
res.addAll(d.listDiscoveredBoards(complete));
}
return res;
}

public BoardPort find(String address) {
for (BoardPort boardPort : discovery()) {
if (boardPort.getAddress().equals(address)) {
Expand All @@ -86,4 +100,13 @@ public BoardPort find(String address) {
return null;
}

public BoardPort find(String address, boolean complete) {
for (BoardPort boardPort : discovery(complete)) {
if (boardPort.getAddress().equals(address)) {
return boardPort;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public List<BoardPort> listDiscoveredBoards() {
}
}

@Override
public List<BoardPort> listDiscoveredBoards(boolean complete) {
synchronized (reachableBoardPorts) {
return new LinkedList<>(reachableBoardPorts);
}
}

public void setReachableBoardPorts(List<BoardPort> newReachableBoardPorts) {
synchronized (reachableBoardPorts) {
this.reachableBoardPorts.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,51 @@ public class SerialDiscovery implements Discovery {

private Timer serialBoardsListerTimer;
private final List<BoardPort> serialBoardPorts;
private SerialBoardsLister serialBoardsLister = new SerialBoardsLister(this);;

public SerialDiscovery() {
this.serialBoardPorts = new LinkedList<>();
}

@Override
public List<BoardPort> listDiscoveredBoards() {
return getSerialBoardPorts();
return getSerialBoardPorts(false);
}

private List<BoardPort> getSerialBoardPorts() {
synchronized (serialBoardPorts) {
return new LinkedList<>(serialBoardPorts);
}
public List<BoardPort> listDiscoveredBoards(boolean complete) {
return getSerialBoardPorts(complete);
}

private List<BoardPort> getSerialBoardPorts(boolean complete) {
if (complete) {
return new LinkedList<>(serialBoardPorts);
}
List<BoardPort> onlineBoardPorts = new LinkedList<>();
for (BoardPort port : serialBoardPorts) {
if (port.isOnline() == true) {
onlineBoardPorts.add(port);
}
}
return onlineBoardPorts;
}

public void setSerialBoardPorts(List<BoardPort> newSerialBoardPorts) {
synchronized (serialBoardPorts) {
serialBoardPorts.clear();
serialBoardPorts.addAll(newSerialBoardPorts);
}
}

public void forceRefresh() {
serialBoardsLister.retriggerDiscovery();
}

public void setUploadInProgress(boolean param) {
serialBoardsLister.uploadInProgress = param;
}

@Override
public void start() {
this.serialBoardsListerTimer = new Timer(SerialBoardsLister.class.getName());
new SerialBoardsLister(this).start(serialBoardsListerTimer);
serialBoardsLister.start(serialBoardsListerTimer);
}

@Override
Expand Down
Loading

0 comments on commit 91b94c8

Please sign in to comment.