Skip to content

Clean up plugglable discovery and refactor serial-discovery usage #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of going through a dynamic loading mechanism that will always return just the serial discovery, we use it directly

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