Skip to content

Board identification: always check vid.1/pid.1 #463

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
Nov 4, 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
10 changes: 5 additions & 5 deletions arduino/cores/packagemanager/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (pm *PackageManager) IdentifyBoard(idProps *properties.Map) []*cores.Board
return []*cores.Board{}
}

checkSuffix := func(props *properties.Map, s string) (checked bool, found bool) {
checkSuffix := func(props *properties.Map, s string) (present bool, matched bool) {
for k, v1 := range idProps.AsMap() {
v2, ok := props.GetOk(k + s)
if !ok {
Expand All @@ -45,17 +45,17 @@ func (pm *PackageManager) IdentifyBoard(idProps *properties.Map) []*cores.Board

foundBoards := []*cores.Board{}
for _, board := range pm.InstalledBoards() {
if _, found := checkSuffix(board.Properties, ""); found {
if _, matched := checkSuffix(board.Properties, ""); matched {
foundBoards = append(foundBoards, board)
continue
}
id := 0
for {
again, found := checkSuffix(board.Properties, fmt.Sprintf(".%d", id))
if found {
present, matched := checkSuffix(board.Properties, fmt.Sprintf(".%d", id))
if matched {
foundBoards = append(foundBoards, board)
}
if !again {
if !present && id > 0 { // Always check id 0 and 1 (https://github.com/arduino/arduino-cli/issues/456)
break
}
id++
Expand Down
21 changes: 21 additions & 0 deletions arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package packagemanager_test

import (
"fmt"
"net/url"
"testing"

Expand Down Expand Up @@ -295,3 +296,23 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
}
require.Equal(t, bossac18.InstallDir.String(), uploadProperties.Get("runtime.tools.bossac.path"))
}

func TestIdentifyBoard(t *testing.T) {
pm := packagemanager.NewPackageManager(customHardware, customHardware, customHardware, customHardware)
pm.LoadHardwareFromDirectory(customHardware)

identify := func(vid, pid string) []*cores.Board {
return pm.IdentifyBoard(properties.NewFromHashmap(map[string]string{
"vid": vid, "pid": pid,
}))
}
require.Equal(t, "[arduino:avr:uno]", fmt.Sprintf("%v", identify("0x2341", "0x0001")))

// Check indexed vid/pid format (vid.0/pid.0)
require.Equal(t, "[test:avr:a]", fmt.Sprintf("%v", identify("0x9999", "0x0001")))
require.Equal(t, "[test:avr:b]", fmt.Sprintf("%v", identify("0x9999", "0x0002")))
require.Equal(t, "[test:avr:c]", fmt.Sprintf("%v", identify("0x9999", "0x0003")))
require.Equal(t, "[test:avr:c]", fmt.Sprintf("%v", identify("0x9999", "0x0004")))
// https://github.com/arduino/arduino-cli/issues/456
require.Equal(t, "[test:avr:d]", fmt.Sprintf("%v", identify("0x9999", "0x0005")))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
a.name=Board A
a.vid=0x9999
a.pid=0x0001

b.name=Board B
b.vid.0=0x9999
b.pid.0=0x0002

c.name=Board C
c.vid.0=0x9999
c.pid.0=0x0003
c.vid.1=0x9999
c.pid.1=0x0004

d.name=Board D
d.vid.1=0x9999
d.pid.1=0x0005