From 5e1add9e46fef1668be7386edb3755c7cc2d0de8 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 18 Oct 2019 12:17:06 +0200 Subject: [PATCH 1/2] Do not try to identify non-usb ports via vid/pid --- commands/board/list.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commands/board/list.go b/commands/board/list.go index 577aa478b6c..9c9df8fd2d8 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -119,8 +119,11 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) { } // if installed cores didn't recognize the board, try querying - // the builder API - if len(b) == 0 { + // the builder API if the board is a USB device port + if len(b) == 0 && + port.IdentificationPrefs.ContainsKey("vid") && + port.IdentificationPrefs.ContainsKey("pid") { + logrus.Debug("Querying builder API for board identification...") items, err := apiByVidPid( port.IdentificationPrefs.Get("vid"), From ca2b84e273f2f8b4fde8987f189789d7ba3d3c7c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 18 Oct 2019 16:31:50 +0200 Subject: [PATCH 2/2] Added test TestBoardDetectionViaAPIWithNonUSBPort --- commands/board/list.go | 22 +++++++++++++--------- commands/board/list_test.go | 11 +++++++++++ go.mod | 1 - 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/commands/board/list.go b/commands/board/list.go index 9c9df8fd2d8..c89f06fe75d 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -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() @@ -120,15 +131,8 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) { // if installed cores didn't recognize the board, try querying // the builder API if the board is a USB device port - if len(b) == 0 && - port.IdentificationPrefs.ContainsKey("vid") && - port.IdentificationPrefs.ContainsKey("pid") { - - logrus.Debug("Querying builder API for board identification...") - items, err := apiByVidPid( - port.IdentificationPrefs.Get("vid"), - port.IdentificationPrefs.Get("pid"), - ) + if len(b) == 0 { + items, err := identifyViaCloudAPI(port) if err == ErrNotFound { // the board couldn't be detected, print a warning logrus.Debug("Board not recognized") diff --git a/commands/board/list_test.go b/commands/board/list_test.go index 4014e791f4a..d8600681c22 100644 --- a/commands/board/list_test.go +++ b/commands/board/list_test.go @@ -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" ) @@ -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) +} diff --git a/go.mod b/go.mod index 8427598d575..b0ae9aa7f2e 100644 --- a/go.mod +++ b/go.mod @@ -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