Skip to content

Commit

Permalink
clean up plugglable discovery and refactor serial-discovery usage (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
masci authored Aug 8, 2019
1 parent a57cf78 commit 7e547b0
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 356 deletions.
171 changes: 0 additions & 171 deletions arduino/discovery/discovery.go

This file was deleted.

3 changes: 1 addition & 2 deletions cli/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package board

import (
"context"
"fmt"
"os"
"sort"
Expand Down Expand Up @@ -61,7 +60,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
time.Sleep(timeout)
}

resp, err := board.List(context.Background(), &rpc.BoardListReq{Instance: instance.CreateInstance()})
resp, err := board.List(instance.CreateInstance().GetId())
if err != nil {
formatter.PrintError(err, "Error detecting boards")
os.Exit(errorcodes.ErrNetwork)
Expand Down
2 changes: 1 addition & 1 deletion commands/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// Attach FIXMEDOC
func Attach(ctx context.Context, req *rpc.BoardAttachReq, taskCB commands.TaskProgressCB) (*rpc.BoardAttachResp, error) {

pm := commands.GetPackageManager(req)
pm := commands.GetPackageManager(req.GetInstance().GetId())
if pm == nil {
return nil, errors.New("invalid instance")
}
Expand Down
2 changes: 1 addition & 1 deletion commands/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// Details FIXMEDOC
func Details(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsResp, error) {
pm := commands.GetPackageManager(req)
pm := commands.GetPackageManager(req.GetInstance().GetId())
if pm == nil {
return nil, errors.New("invalid instance")
}
Expand Down
58 changes: 32 additions & 26 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,50 @@
package board

import (
"context"
"errors"
"fmt"

"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/pkg/errors"
)

// List FIXMEDOC
func List(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp, error) {
pm := commands.GetPackageManager(req)
func List(instanceID int32) (*rpc.BoardListResp, error) {
pm := commands.GetPackageManager(instanceID)
if pm == nil {
return nil, errors.New("invalid instance")
}

serialDiscovery, err := commands.NewBuiltinSerialDiscovery(pm)
if err != nil {
return nil, errors.Wrap(err, "unable to instance serial-discovery")
}

if err := serialDiscovery.Start(); err != nil {
return nil, errors.Wrap(err, "unable to start serial-discovery")
}
defer serialDiscovery.Close()

resp := &rpc.BoardListResp{Ports: []*rpc.DetectedPort{}}
for _, disc := range commands.GetDiscoveries(req) {
ports, err := disc.List()
if err != nil {
fmt.Printf("Error getting port list from discovery %s: %s\n", disc.ID, err)
continue

ports, err := serialDiscovery.List()
if err != nil {
return nil, errors.Wrap(err, "error getting port list from serial-discovery")
}

for _, port := range ports {
b := []*rpc.BoardListItem{}
for _, board := range pm.IdentifyBoard(port.IdentificationPrefs) {
b = append(b, &rpc.BoardListItem{
Name: board.Name(),
FQBN: board.FQBN(),
})
}
for _, port := range ports {
b := []*rpc.BoardListItem{}
for _, board := range pm.IdentifyBoard(port.IdentificationPrefs) {
b = append(b, &rpc.BoardListItem{
Name: board.Name(),
FQBN: board.FQBN(),
})
}
p := &rpc.DetectedPort{
Address: port.Address,
Protocol: port.Protocol,
ProtocolLabel: port.ProtocolLabel,
Boards: b,
}
resp.Ports = append(resp.Ports, p)
p := &rpc.DetectedPort{
Address: port.Address,
Protocol: port.Protocol,
ProtocolLabel: port.ProtocolLabel,
Boards: b,
}
resp.Ports = append(resp.Ports, p)
}

return resp, nil
Expand Down
2 changes: 1 addition & 1 deletion commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// ListAll FIXMEDOC
func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllResp, error) {
pm := commands.GetPackageManager(req)
pm := commands.GetPackageManager(req.GetInstance().GetId())
if pm == nil {
return nil, errors.New("invalid instance")
}
Expand Down
Loading

0 comments on commit 7e547b0

Please sign in to comment.