Skip to content

Commit 5ab1ecd

Browse files
committed
Add board properties to board list command and gRPC function
1 parent fdae9b9 commit 5ab1ecd

19 files changed

+365
-406
lines changed

cli/board/list.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ func watchList(cmd *cobra.Command, inst *rpc.Instance) {
9191
for event := range eventsChan {
9292
feedback.PrintResult(watchEvent{
9393
Type: event.EventType,
94-
Address: event.Port.Address,
95-
Protocol: event.Port.Protocol,
96-
ProtocolLabel: event.Port.ProtocolLabel,
97-
Boards: event.Port.Boards,
98-
SerialNumber: event.Port.SerialNumber,
94+
Address: event.Port.Port.Address,
95+
Protocol: event.Port.Port.Protocol,
96+
ProtocolLabel: event.Port.Port.ProtocolLabel,
97+
Boards: event.Port.MatchingBoards,
9998
Error: event.Error,
10099
})
101100
}
@@ -117,20 +116,21 @@ func (dr result) String() string {
117116
}
118117

119118
sort.Slice(dr.ports, func(i, j int) bool {
120-
x, y := dr.ports[i], dr.ports[j]
119+
x, y := dr.ports[i].Port, dr.ports[j].Port
121120
return x.GetProtocol() < y.GetProtocol() ||
122121
(x.GetProtocol() == y.GetProtocol() && x.GetAddress() < y.GetAddress())
123122
})
124123

125124
t := table.New()
126125
t.SetHeader("Port", "Type", "Board Name", "FQBN", "Core")
127-
for _, port := range dr.ports {
126+
for _, detectedPort := range dr.ports {
127+
port := detectedPort.Port
128128
address := port.GetProtocol() + "://" + port.GetAddress()
129129
if port.GetProtocol() == "serial" {
130130
address = port.GetAddress()
131131
}
132132
protocol := port.GetProtocolLabel()
133-
if boards := port.GetBoards(); len(boards) > 0 {
133+
if boards := detectedPort.GetMatchingBoards(); len(boards) > 0 {
134134
sort.Slice(boards, func(i, j int) bool {
135135
x, y := boards[i], boards[j]
136136
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFqbn() < y.GetFqbn())
@@ -168,7 +168,6 @@ type watchEvent struct {
168168
Protocol string `json:"protocol,omitempty"`
169169
ProtocolLabel string `json:"protocol_label,omitempty"`
170170
Boards []*rpc.BoardListItem `json:"boards,omitempty"`
171-
SerialNumber string `json:"serial_number,omitempty"`
172171
Error string `json:"error,omitempty"`
173172
}
174173

commands/board/list.go

+6-21
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
9191
retVal = append(retVal, &rpc.BoardListItem{
9292
Name: name,
9393
Fqbn: fqbn,
94-
Vid: vid,
95-
Pid: pid,
9694
})
9795
} else {
9896
return nil, errors.Wrap(err, "error querying Arduino Cloud Api")
@@ -127,8 +125,6 @@ func identify(pm *packagemanager.PackageManager, port *discovery.Port) ([]*rpc.B
127125
Name: board.Name(),
128126
Fqbn: board.FQBN(),
129127
Platform: platform,
130-
Vid: port.Properties.Get("vid"),
131-
Pid: port.Properties.Get("pid"),
132128
})
133129
}
134130

@@ -212,14 +208,11 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
212208

213209
// boards slice can be empty at this point if neither the cores nor the
214210
// API managed to recognize the connected board
215-
p := &rpc.DetectedPort{
216-
Address: port.Address,
217-
Protocol: port.Protocol,
218-
ProtocolLabel: port.ProtocolLabel,
219-
Boards: boards,
220-
SerialNumber: port.Properties.Get("serialNumber"),
211+
b := &rpc.DetectedPort{
212+
Port: port.ToRPC(),
213+
MatchingBoards: boards,
221214
}
222-
retVal = append(retVal, p)
215+
retVal = append(retVal, b)
223216
}
224217

225218
return retVal, nil
@@ -249,16 +242,8 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
249242
for {
250243
select {
251244
case event := <-eventsChan:
252-
serialNumber := ""
253-
if props := event.Port.Properties; props != nil {
254-
serialNumber = props.Get("serialNumber")
255-
}
256-
257245
port := &rpc.DetectedPort{
258-
Address: event.Port.Address,
259-
Protocol: event.Port.Protocol,
260-
ProtocolLabel: event.Port.ProtocolLabel,
261-
SerialNumber: serialNumber,
246+
Port: event.Port.ToRPC(),
262247
}
263248

264249
boardsError := ""
@@ -267,7 +252,7 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
267252
if err != nil {
268253
boardsError = err.Error()
269254
}
270-
port.Boards = boards
255+
port.MatchingBoards = boards
271256
}
272257
outChan <- &rpc.BoardListWatchResponse{
273258
EventType: event.Type,

docs/UPGRADING.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## Unreleased
66

7-
### gRPC interface `UploadRequest`, `UploadUsingProgrammerRequest` and `BurnBootloaderRequest` arguments type change
7+
### gRPC interface `UploadRequest`, `UploadUsingProgrammerRequest`, `BurnBootloaderRequest`, `DetectedPort` arguments changes
88

99
`UploadRequest`, `UploadUsingProgrammerRequest` and `BurnBootloaderRequest` had their `port` argument change from type
1010
`string` to `Port`.
@@ -27,7 +27,42 @@ message Port {
2727
}
2828
```
2929

30-
This change is necessary for the Pluggable Discovery.
30+
The gRPC interface message `DetectedPort` has been changed from:
31+
32+
```
33+
message DetectedPort {
34+
// Address of the port (e.g., `serial:///dev/ttyACM0`).
35+
string address = 1;
36+
// Protocol of the port (e.g., `serial`).
37+
string protocol = 2;
38+
// A human friendly description of the protocol (e.g., "Serial Port (USB)").
39+
string protocol_label = 3;
40+
// The boards attached to the port.
41+
repeated BoardListItem boards = 4;
42+
// Serial number of connected board
43+
string serial_number = 5;
44+
}
45+
```
46+
47+
to:
48+
49+
```
50+
message DetectedPort {
51+
// The possible boards attached to the port.
52+
repeated BoardListItem matching_boards = 1;
53+
// The port details
54+
Port port = 2;
55+
}
56+
```
57+
58+
The properties previously contained directly in the message are now stored in the `port` property.
59+
60+
This changes are necessary for the Pluggable Discovery.
61+
62+
### gRPC interface `BoardListItem` change
63+
64+
The `vid` and `pid` properties of the `BoardListItem` have been removed. They used to only be available when requesting
65+
connected board lists, now that information is stored in the `port` property of `DetectedPort`.
3166

3267
### Change public library interface
3368

0 commit comments

Comments
 (0)