Skip to content

Commit 7946379

Browse files
author
Luca Bianconi
committed
feat: filter boards by fqbn in connected list
1 parent a63aff4 commit 7946379

File tree

17 files changed

+134
-96
lines changed

17 files changed

+134
-96
lines changed

commands/board/list.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
205205
}
206206
defer release()
207207

208+
var requestedFqbn *cores.FQBN
209+
if f := req.GetFqbn(); f != "" {
210+
var err error
211+
requestedFqbn, err = cores.ParseFQBN(f)
212+
if err != nil {
213+
return nil, nil, &arduino.InvalidFQBNError{Cause: err}
214+
}
215+
}
216+
208217
dm := pme.DiscoveryManager()
209218
discoveryStartErrors = dm.Start()
210219
time.Sleep(time.Duration(req.GetTimeout()) * time.Millisecond)
@@ -222,11 +231,23 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
222231
Port: port.ToRPC(),
223232
MatchingBoards: boards,
224233
}
225-
retVal = append(retVal, b)
234+
235+
if requestedFqbn == nil || hasMatchingBoard(b, requestedFqbn) {
236+
retVal = append(retVal, b)
237+
}
226238
}
227239
return retVal, discoveryStartErrors, nil
228240
}
229241

242+
func hasMatchingBoard(b *rpc.DetectedPort, requestedFqbn *cores.FQBN) bool {
243+
for _, detectedBoard := range b.MatchingBoards {
244+
if detectedBoard.Fqbn == requestedFqbn.String() {
245+
return true
246+
}
247+
}
248+
return false
249+
}
250+
230251
// Watch returns a channel that receives boards connection and disconnection events.
231252
// It also returns a callback function that must be used to stop and dispose the watch.
232253
func Watch(req *rpc.BoardListWatchRequest) (<-chan *rpc.BoardListWatchResponse, func(), error) {

internal/cli/board/list.go

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func initListCommand() *cobra.Command {
4747
}
4848

4949
timeoutArg.AddToCommand(listCommand)
50+
fqbn.AddToCommand(listCommand)
5051
listCommand.Flags().BoolVarP(&watch, "watch", "w", false, tr("Command keeps running and prints list of connected boards whenever there is a change."))
5152

5253
return listCommand
@@ -66,6 +67,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
6667
ports, discvoeryErrors, err := board.List(&rpc.BoardListRequest{
6768
Instance: inst,
6869
Timeout: timeoutArg.Get().Milliseconds(),
70+
Fqbn: fqbn.String(),
6971
})
7072
if err != nil {
7173
feedback.Warning(tr("Error detecting boards: %v", err))

rpc/cc/arduino/cli/commands/v1/board.pb.go

+94-82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/board.proto

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ message BoardListRequest {
152152
Instance instance = 1;
153153
// Search for boards for the given time (in milliseconds)
154154
int64 timeout = 2;
155+
// The fully qualified board name of the board you want information about
156+
// (e.g., `arduino:avr:uno`).
157+
string fqbn = 3;
155158
}
156159

157160
message BoardListResponse {

rpc/cc/arduino/cli/commands/v1/commands.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/commands_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/common.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/compile.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/core.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/lib.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/monitor.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/port.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/upload.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/debug/v1/debug.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/debug/v1/debug_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/settings/v1/settings.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/settings/v1/settings_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)