Skip to content

Do not try to identify non-usb ports using vid/pid #448

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 2 commits into from
Oct 18, 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
19 changes: 13 additions & 6 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
return retVal, nil
}

func identifyViaCloudAPI(port *commands.BoardPort) ([]*rpc.BoardListItem, error) {
// If the port is not USB do not try identification via cloud
id := port.IdentificationPrefs
if !id.ContainsKey("vid") || !id.ContainsKey("pid") {
return nil, ErrNotFound
}

logrus.Debug("Querying builder API for board identification...")
return apiByVidPid(id.Get("vid"), id.Get("pid"))
}

// List FIXMEDOC
func List(instanceID int32) ([]*rpc.DetectedPort, error) {
m.Lock()
Expand Down Expand Up @@ -119,13 +130,9 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) {
}

// if installed cores didn't recognize the board, try querying
// the builder API
// the builder API if the board is a USB device port
if len(b) == 0 {
logrus.Debug("Querying builder API for board identification...")
items, err := apiByVidPid(
port.IdentificationPrefs.Get("vid"),
port.IdentificationPrefs.Get("pid"),
)
items, err := identifyViaCloudAPI(port)
if err == ErrNotFound {
// the board couldn't be detected, print a warning
logrus.Debug("Board not recognized")
Expand Down
11 changes: 11 additions & 0 deletions commands/board/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"net/http/httptest"
"testing"

"github.com/arduino/arduino-cli/commands"
"github.com/arduino/go-properties-orderedmap"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -91,3 +93,12 @@ func TestGetByVidPidMalformedResponse(t *testing.T) {
require.Equal(t, "wrong format in server response", err.Error())
require.Len(t, res, 0)
}

func TestBoardDetectionViaAPIWithNonUSBPort(t *testing.T) {
port := &commands.BoardPort{
IdentificationPrefs: properties.NewMap(),
}
items, err := identifyViaCloudAPI(port)
require.Equal(t, err, ErrNotFound)
require.Empty(t, items)
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45
golang.org/x/net v0.0.0-20190311183353-d8887717615a
golang.org/x/text v0.3.0
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
google.golang.org/grpc v1.21.1
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
Expand Down