Skip to content

Commit

Permalink
Add board properties to board list command and gRPC function
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Jul 22, 2021
1 parent fdae9b9 commit 5ab1ecd
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 406 deletions.
17 changes: 8 additions & 9 deletions cli/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ func watchList(cmd *cobra.Command, inst *rpc.Instance) {
for event := range eventsChan {
feedback.PrintResult(watchEvent{
Type: event.EventType,
Address: event.Port.Address,
Protocol: event.Port.Protocol,
ProtocolLabel: event.Port.ProtocolLabel,
Boards: event.Port.Boards,
SerialNumber: event.Port.SerialNumber,
Address: event.Port.Port.Address,
Protocol: event.Port.Port.Protocol,
ProtocolLabel: event.Port.Port.ProtocolLabel,
Boards: event.Port.MatchingBoards,
Error: event.Error,
})
}
Expand All @@ -117,20 +116,21 @@ func (dr result) String() string {
}

sort.Slice(dr.ports, func(i, j int) bool {
x, y := dr.ports[i], dr.ports[j]
x, y := dr.ports[i].Port, dr.ports[j].Port
return x.GetProtocol() < y.GetProtocol() ||
(x.GetProtocol() == y.GetProtocol() && x.GetAddress() < y.GetAddress())
})

t := table.New()
t.SetHeader("Port", "Type", "Board Name", "FQBN", "Core")
for _, port := range dr.ports {
for _, detectedPort := range dr.ports {
port := detectedPort.Port
address := port.GetProtocol() + "://" + port.GetAddress()
if port.GetProtocol() == "serial" {
address = port.GetAddress()
}
protocol := port.GetProtocolLabel()
if boards := port.GetBoards(); len(boards) > 0 {
if boards := detectedPort.GetMatchingBoards(); len(boards) > 0 {
sort.Slice(boards, func(i, j int) bool {
x, y := boards[i], boards[j]
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFqbn() < y.GetFqbn())
Expand Down Expand Up @@ -168,7 +168,6 @@ type watchEvent struct {
Protocol string `json:"protocol,omitempty"`
ProtocolLabel string `json:"protocol_label,omitempty"`
Boards []*rpc.BoardListItem `json:"boards,omitempty"`
SerialNumber string `json:"serial_number,omitempty"`
Error string `json:"error,omitempty"`
}

Expand Down
27 changes: 6 additions & 21 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
retVal = append(retVal, &rpc.BoardListItem{
Name: name,
Fqbn: fqbn,
Vid: vid,
Pid: pid,
})
} else {
return nil, errors.Wrap(err, "error querying Arduino Cloud Api")
Expand Down Expand Up @@ -127,8 +125,6 @@ func identify(pm *packagemanager.PackageManager, port *discovery.Port) ([]*rpc.B
Name: board.Name(),
Fqbn: board.FQBN(),
Platform: platform,
Vid: port.Properties.Get("vid"),
Pid: port.Properties.Get("pid"),
})
}

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

// boards slice can be empty at this point if neither the cores nor the
// API managed to recognize the connected board
p := &rpc.DetectedPort{
Address: port.Address,
Protocol: port.Protocol,
ProtocolLabel: port.ProtocolLabel,
Boards: boards,
SerialNumber: port.Properties.Get("serialNumber"),
b := &rpc.DetectedPort{
Port: port.ToRPC(),
MatchingBoards: boards,
}
retVal = append(retVal, p)
retVal = append(retVal, b)
}

return retVal, nil
Expand Down Expand Up @@ -249,16 +242,8 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
for {
select {
case event := <-eventsChan:
serialNumber := ""
if props := event.Port.Properties; props != nil {
serialNumber = props.Get("serialNumber")
}

port := &rpc.DetectedPort{
Address: event.Port.Address,
Protocol: event.Port.Protocol,
ProtocolLabel: event.Port.ProtocolLabel,
SerialNumber: serialNumber,
Port: event.Port.ToRPC(),
}

boardsError := ""
Expand All @@ -267,7 +252,7 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
if err != nil {
boardsError = err.Error()
}
port.Boards = boards
port.MatchingBoards = boards
}
outChan <- &rpc.BoardListWatchResponse{
EventType: event.Type,
Expand Down
39 changes: 37 additions & 2 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Here you can find a list of migration guides to handle breaking changes between

## Unreleased

### gRPC interface `UploadRequest`, `UploadUsingProgrammerRequest` and `BurnBootloaderRequest` arguments type change
### gRPC interface `UploadRequest`, `UploadUsingProgrammerRequest`, `BurnBootloaderRequest`, `DetectedPort` arguments changes

`UploadRequest`, `UploadUsingProgrammerRequest` and `BurnBootloaderRequest` had their `port` argument change from type
`string` to `Port`.
Expand All @@ -27,7 +27,42 @@ message Port {
}
```

This change is necessary for the Pluggable Discovery.
The gRPC interface message `DetectedPort` has been changed from:

```
message DetectedPort {
// Address of the port (e.g., `serial:///dev/ttyACM0`).
string address = 1;
// Protocol of the port (e.g., `serial`).
string protocol = 2;
// A human friendly description of the protocol (e.g., "Serial Port (USB)").
string protocol_label = 3;
// The boards attached to the port.
repeated BoardListItem boards = 4;
// Serial number of connected board
string serial_number = 5;
}
```

to:

```
message DetectedPort {
// The possible boards attached to the port.
repeated BoardListItem matching_boards = 1;
// The port details
Port port = 2;
}
```

The properties previously contained directly in the message are now stored in the `port` property.

This changes are necessary for the Pluggable Discovery.

### gRPC interface `BoardListItem` change

The `vid` and `pid` properties of the `BoardListItem` have been removed. They used to only be available when requesting
connected board lists, now that information is stored in the `port` property of `DetectedPort`.

### Change public library interface

Expand Down
Loading

0 comments on commit 5ab1ecd

Please sign in to comment.