Skip to content

Commit 243fc68

Browse files
committed
Rework Serial ports handling and add Board info menu
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
1 parent c11ceb7 commit 243fc68

File tree

11 files changed

+257
-38
lines changed

11 files changed

+257
-38
lines changed

app/src/processing/app/Editor.java

+49
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ public void actionPerformed(ActionEvent e) {
814814
portMenu = new JMenu(tr("Port"));
815815
populatePortMenu();
816816
toolsMenu.add(portMenu);
817+
item = new JMenuItem(tr("Get Board Info"));
818+
item.addActionListener(e -> handleBoardInfo());
819+
toolsMenu.add(item);
817820
toolsMenu.addSeparator();
818821

819822
base.rebuildProgrammerMenu();
@@ -2753,6 +2756,52 @@ private void handleBurnBootloader() {
27532756
}).start();
27542757
}
27552758

2759+
private void handleBoardInfo() {
2760+
console.clear();
2761+
2762+
String selectedPort = PreferencesData.get("serial.port");
2763+
List<BoardPort> ports = Base.getDiscoveryManager().discovery();
2764+
2765+
String label = "";
2766+
String vid = "";
2767+
String pid = "";
2768+
String iserial = "";
2769+
boolean found = false;
2770+
2771+
for (BoardPort port : ports) {
2772+
if (port.getAddress().equals(selectedPort)) {
2773+
label = port.getBoardName();
2774+
vid = port.getVID();
2775+
pid = port.getPID();
2776+
iserial = port.getISerial();
2777+
found = true;
2778+
break;
2779+
}
2780+
}
2781+
2782+
if (!found) {
2783+
statusNotice(tr("Please select a port to obtain board info"));
2784+
return;
2785+
}
2786+
2787+
if (vid == null || vid.equals("") || vid.equals("0000")) {
2788+
statusNotice(tr("Native serial port, can't obtain info"));
2789+
return;
2790+
}
2791+
2792+
if (iserial == null || iserial.equals("")) {
2793+
iserial = tr("Upload any sketch to obtain it");
2794+
}
2795+
2796+
if (label == null) {
2797+
label = tr("Unknown board");
2798+
}
2799+
2800+
String infos = I18n.format("BN: {0}\nVID: {1}\nPID: {2}\nSN: {3}", label, vid, pid, iserial);
2801+
JTextArea textArea = new JTextArea(infos);
2802+
2803+
JOptionPane.showMessageDialog(this, textArea, tr("Board Info"), JOptionPane.PLAIN_MESSAGE);
2804+
}
27562805

27572806
/**
27582807
* Handler for File &rarr; Page Setup.

app/src/processing/app/EditorLineStatus.java

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class EditorLineStatus extends JComponent {
5252
String text = "";
5353
String name = "";
5454
String serialport = "";
55+
String serialnumber = "";
5556

5657
public EditorLineStatus() {
5758
background = Theme.getColor("linestatus.bgcolor");
@@ -129,6 +130,10 @@ public void setSerialPort(String serialport) {
129130
this.serialport = serialport;
130131
}
131132

133+
public void setSerialNumber(String serialnumber) {
134+
this.serialnumber = serialnumber;
135+
}
136+
132137
public Dimension getPreferredSize() {
133138
return scale(new Dimension(300, height));
134139
}

arduino-core/src/cc/arduino/packages/BoardPort.java

+36
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ public class BoardPort {
3636
private String address;
3737
private String protocol;
3838
private String boardName;
39+
private String vid;
40+
private String pid;
41+
private String iserial;
3942
private String label;
4043
private final PreferencesMap prefs;
44+
private boolean online;
4145

4246
public BoardPort() {
4347
this.prefs = new PreferencesMap();
@@ -79,4 +83,36 @@ public String getLabel() {
7983
return label;
8084
}
8185

86+
public void setOnlineStatus(boolean online) {
87+
this.online = online;
88+
}
89+
90+
public boolean isOnline() {
91+
return online;
92+
}
93+
94+
public void setVIDPID(String vid, String pid) {
95+
this.vid = vid;
96+
this.pid = pid;
97+
}
98+
99+
public String getVID() {
100+
return vid;
101+
}
102+
103+
public String getPID() {
104+
return pid;
105+
}
106+
107+
public void setISerial(String iserial) {
108+
this.iserial = iserial;
109+
}
110+
public String getISerial() {
111+
return iserial;
112+
}
113+
114+
@Override
115+
public String toString() {
116+
return this.address+"_"+this.vid+"_"+this.pid;
117+
}
82118
}

arduino-core/src/cc/arduino/packages/Discovery.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ public interface Discovery {
5151
* @return
5252
*/
5353
List<BoardPort> listDiscoveredBoards();
54+
List<BoardPort> listDiscoveredBoards(boolean complete);
5455

5556
}

arduino-core/src/cc/arduino/packages/DiscoveryManager.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
public class DiscoveryManager {
4141

4242
private final List<Discovery> discoverers;
43+
private final SerialDiscovery serialDiscoverer = new SerialDiscovery();
44+
private final NetworkDiscovery networkDiscoverer = new NetworkDiscovery();
4345

4446
public DiscoveryManager() {
4547
discoverers = new ArrayList<Discovery>();
46-
discoverers.add(new SerialDiscovery());
47-
discoverers.add(new NetworkDiscovery());
48+
discoverers.add(serialDiscoverer);
49+
discoverers.add(networkDiscoverer);
4850

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

74+
public SerialDiscovery getSerialDiscoverer() {
75+
return serialDiscoverer;
76+
}
77+
7278
public List<BoardPort> discovery() {
7379
List<BoardPort> res = new ArrayList<BoardPort>();
7480
for (Discovery d : discoverers) {
@@ -77,6 +83,14 @@ public List<BoardPort> discovery() {
7783
return res;
7884
}
7985

86+
public List<BoardPort> discovery(boolean complete) {
87+
List<BoardPort> res = new ArrayList<BoardPort>();
88+
for (Discovery d : discoverers) {
89+
res.addAll(d.listDiscoveredBoards(complete));
90+
}
91+
return res;
92+
}
93+
8094
public BoardPort find(String address) {
8195
for (BoardPort boardPort : discovery()) {
8296
if (boardPort.getAddress().equals(address)) {
@@ -86,4 +100,13 @@ public BoardPort find(String address) {
86100
return null;
87101
}
88102

103+
public BoardPort find(String address, boolean complete) {
104+
for (BoardPort boardPort : discovery(complete)) {
105+
if (boardPort.getAddress().equals(address)) {
106+
return boardPort;
107+
}
108+
}
109+
return null;
110+
}
111+
89112
}

arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public List<BoardPort> listDiscoveredBoards() {
6767
}
6868
}
6969

70+
@Override
71+
public List<BoardPort> listDiscoveredBoards(boolean complete) {
72+
synchronized (reachableBoardPorts) {
73+
return new LinkedList<>(reachableBoardPorts);
74+
}
75+
}
76+
7077
public void setReachableBoardPorts(List<BoardPort> newReachableBoardPorts) {
7178
synchronized (reachableBoardPorts) {
7279
this.reachableBoardPorts.clear();

arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java

+26-8
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,51 @@ public class SerialDiscovery implements Discovery {
4141

4242
private Timer serialBoardsListerTimer;
4343
private final List<BoardPort> serialBoardPorts;
44+
private SerialBoardsLister serialBoardsLister = new SerialBoardsLister(this);;
4445

4546
public SerialDiscovery() {
4647
this.serialBoardPorts = new LinkedList<>();
4748
}
4849

4950
@Override
5051
public List<BoardPort> listDiscoveredBoards() {
51-
return getSerialBoardPorts();
52+
return getSerialBoardPorts(false);
5253
}
5354

54-
private List<BoardPort> getSerialBoardPorts() {
55-
synchronized (serialBoardPorts) {
56-
return new LinkedList<>(serialBoardPorts);
57-
}
55+
public List<BoardPort> listDiscoveredBoards(boolean complete) {
56+
return getSerialBoardPorts(complete);
57+
}
58+
59+
private List<BoardPort> getSerialBoardPorts(boolean complete) {
60+
if (complete) {
61+
return new LinkedList<>(serialBoardPorts);
62+
}
63+
List<BoardPort> onlineBoardPorts = new LinkedList<>();
64+
for (BoardPort port : serialBoardPorts) {
65+
if (port.isOnline() == true) {
66+
onlineBoardPorts.add(port);
67+
}
68+
}
69+
return onlineBoardPorts;
5870
}
5971

6072
public void setSerialBoardPorts(List<BoardPort> newSerialBoardPorts) {
61-
synchronized (serialBoardPorts) {
6273
serialBoardPorts.clear();
6374
serialBoardPorts.addAll(newSerialBoardPorts);
64-
}
75+
}
76+
77+
public void forceRefresh() {
78+
serialBoardsLister.retriggerDiscovery();
79+
}
80+
81+
public void setUploadInProgress(boolean param) {
82+
serialBoardsLister.uploadInProgress = param;
6583
}
6684

6785
@Override
6886
public void start() {
6987
this.serialBoardsListerTimer = new Timer(SerialBoardsLister.class.getName());
70-
new SerialBoardsLister(this).start(serialBoardsListerTimer);
88+
serialBoardsLister.start(serialBoardsListerTimer);
7189
}
7290

7391
@Override

0 commit comments

Comments
 (0)