Skip to content

Fix fqbn case #81

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
Dec 13, 2021
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
2 changes: 1 addition & 1 deletion cli/device/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func runCreateCommand(cmd *cobra.Command, args []string) {
params.Port = &createFlags.port
}
if createFlags.fqbn != "" {
params.Fqbn = &createFlags.fqbn
params.FQBN = &createFlags.fqbn
}

dev, err := device.Create(params)
Expand Down
2 changes: 1 addition & 1 deletion cli/device/createlora.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func runCreateLoraCommand(cmd *cobra.Command, args []string) {
params.Port = &createLoraFlags.port
}
if createLoraFlags.fqbn != "" {
params.Fqbn = &createLoraFlags.fqbn
params.FQBN = &createLoraFlags.fqbn
}

dev, err := device.CreateLora(params)
Expand Down
4 changes: 2 additions & 2 deletions command/device/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func portFilter(port *rpc.DetectedPort, params *CreateParams) bool {
// - a board if it is found.
// - nil if no board matching the fqbn parameter is found.
func boardFilter(boards []*rpc.BoardListItem, params *CreateParams) (board *rpc.BoardListItem) {
if params.Fqbn == nil {
if params.FQBN == nil {
return boards[0]
}
for _, b := range boards {
if b.Fqbn == *params.Fqbn {
if b.Fqbn == *params.FQBN {
return b
}
}
Expand Down
14 changes: 7 additions & 7 deletions command/device/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,50 +66,50 @@ func TestBoardFromPorts(t *testing.T) {

{
name: "port-filter",
filter: &CreateParams{Fqbn: nil, Port: stringPointer("ACM1")},
filter: &CreateParams{FQBN: nil, Port: stringPointer("ACM1")},
ports: portsTwoBoards,
want: &board{fqbn: "arduino:avr:uno", port: "ACM1"},
},

{
name: "fqbn-filter",
filter: &CreateParams{Fqbn: stringPointer("arduino:avr:uno"), Port: nil},
filter: &CreateParams{FQBN: stringPointer("arduino:avr:uno"), Port: nil},
ports: portsTwoBoards,
want: &board{fqbn: "arduino:avr:uno", port: "ACM1"},
},

{
name: "no-filter-noboards",
filter: &CreateParams{Fqbn: nil, Port: nil},
filter: &CreateParams{FQBN: nil, Port: nil},
ports: portsNoBoards,
want: nil,
},

{
name: "no-filter",
filter: &CreateParams{Fqbn: nil, Port: nil},
filter: &CreateParams{FQBN: nil, Port: nil},
ports: portsTwoBoards,
// first board found is selected
want: &board{fqbn: "arduino:samd:nano_33_iot", port: "ACM0"},
},

{
name: "both-filter-noboards",
filter: &CreateParams{Fqbn: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM1")},
filter: &CreateParams{FQBN: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM1")},
ports: portsNoBoards,
want: nil,
},

{
name: "both-filter-found",
filter: &CreateParams{Fqbn: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM1")},
filter: &CreateParams{FQBN: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM1")},
ports: portsTwoBoards,
want: &board{fqbn: "arduino:avr:uno", port: "ACM1"},
},

{
name: "both-filter-notfound",
filter: &CreateParams{Fqbn: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM0")},
filter: &CreateParams{FQBN: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM0")},
ports: portsTwoBoards,
want: nil,
},
Expand Down
2 changes: 1 addition & 1 deletion command/device/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
type CreateParams struct {
Name string // Device name
Port *string // Serial port - Optional - If omitted then each serial port is analyzed
Fqbn *string // Board FQBN - Optional - If omitted then the first device found gets selected
FQBN *string // Board FQBN - Optional - If omitted then the first device found gets selected
}

// Create command is used to provision a new arduino device
Expand Down
4 changes: 2 additions & 2 deletions internal/binary/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Index struct {

// IndexBoard describes all the binaries available for a specific board
type IndexBoard struct {
Fqbn string `json:"fqbn"`
FQBN string `json:"fqbn"`
Provision *IndexBin `json:"provision"`
}

Expand Down Expand Up @@ -98,7 +98,7 @@ func LoadIndex() (*Index, error) {
// Returns nil if the binary is not found
func (i *Index) FindProvisionBin(fqbn string) *IndexBin {
for _, b := range i.Boards {
if b.Fqbn == fqbn {
if b.FQBN == fqbn {
return b.Provision
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/binary/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestFindProvisionBin(t *testing.T) {
)
index := &Index{
Boards: []IndexBoard{
{Fqbn: fqbnOK1, Provision: &IndexBin{URL: "mkr"}},
{Fqbn: fqbnOK2, Provision: &IndexBin{URL: "nano"}},
{FQBN: fqbnOK1, Provision: &IndexBin{URL: "mkr"}},
{FQBN: fqbnOK2, Provision: &IndexBin{URL: "nano"}},
},
}

Expand Down