Skip to content

Commit 3a08b07

Browse files
cmaglieRoberto Sora
authored and
Roberto Sora
committed
Do not try to identify non-usb ports via vid/pid (#448)
* Do not try to identify non-usb ports via vid/pid * Added test TestBoardDetectionViaAPIWithNonUSBPort
1 parent 00ee257 commit 3a08b07

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Diff for: commands/board/list.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
9090
return retVal, nil
9191
}
9292

93+
func identifyViaCloudAPI(port *commands.BoardPort) ([]*rpc.BoardListItem, error) {
94+
// If the port is not USB do not try identification via cloud
95+
id := port.IdentificationPrefs
96+
if !id.ContainsKey("vid") || !id.ContainsKey("pid") {
97+
return nil, ErrNotFound
98+
}
99+
100+
logrus.Debug("Querying builder API for board identification...")
101+
return apiByVidPid(id.Get("vid"), id.Get("pid"))
102+
}
103+
93104
// List FIXMEDOC
94105
func List(instanceID int32) ([]*rpc.DetectedPort, error) {
95106
m.Lock()
@@ -119,13 +130,9 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) {
119130
}
120131

121132
// if installed cores didn't recognize the board, try querying
122-
// the builder API
133+
// the builder API if the board is a USB device port
123134
if len(b) == 0 {
124-
logrus.Debug("Querying builder API for board identification...")
125-
items, err := apiByVidPid(
126-
port.IdentificationPrefs.Get("vid"),
127-
port.IdentificationPrefs.Get("pid"),
128-
)
135+
items, err := identifyViaCloudAPI(port)
129136
if err == ErrNotFound {
130137
// the board couldn't be detected, print a warning
131138
logrus.Debug("Board not recognized")

Diff for: commands/board/list_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"net/http/httptest"
2222
"testing"
2323

24+
"github.com/arduino/arduino-cli/commands"
25+
"github.com/arduino/go-properties-orderedmap"
2426
"github.com/stretchr/testify/require"
2527
)
2628

@@ -91,3 +93,12 @@ func TestGetByVidPidMalformedResponse(t *testing.T) {
9193
require.Equal(t, "wrong format in server response", err.Error())
9294
require.Len(t, res, 0)
9395
}
96+
97+
func TestBoardDetectionViaAPIWithNonUSBPort(t *testing.T) {
98+
port := &commands.BoardPort{
99+
IdentificationPrefs: properties.NewMap(),
100+
}
101+
items, err := identifyViaCloudAPI(port)
102+
require.Equal(t, err, ErrNotFound)
103+
require.Empty(t, items)
104+
}

Diff for: go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ require (
4343
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45
4444
golang.org/x/net v0.0.0-20190311183353-d8887717615a
4545
golang.org/x/text v0.3.0
46-
google.golang.org/appengine v1.4.0 // indirect
4746
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
4847
google.golang.org/grpc v1.21.1
4948
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect

0 commit comments

Comments
 (0)