Skip to content

Upgrade arduino-cli #88

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 8 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor port in address and protocol
  • Loading branch information
polldo committed Dec 16, 2021
commit 4b6156ed71dce1ea908fbc8062d8eecb23359373
4 changes: 2 additions & 2 deletions arduino/cli/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ func (c *commander) BoardList() ([]*rpc.DetectedPort, error) {

// UploadBin executes the 'arduino-cli upload -i' command
// and returns its result.
func (c *commander) UploadBin(fqbn, bin, port string) error {
func (c *commander) UploadBin(fqbn, bin, address, protocol string) error {
req := &rpc.UploadRequest{
Instance: c.Instance,
Fqbn: fqbn,
SketchPath: filepath.Dir(bin),
ImportFile: bin,
Port: &rpc.Port{Address: port},
Port: &rpc.Port{Address: address, Protocol: protocol},
Verbose: false,
}

Expand Down
2 changes: 1 addition & 1 deletion arduino/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ import (
// the arduino-cli commands in a programmatic way.
type Commander interface {
BoardList() ([]*rpc.DetectedPort, error)
UploadBin(fqbn, bin, port string) error
UploadBin(fqbn, bin, address, protocol string) error
//Compile() error
}
4 changes: 2 additions & 2 deletions arduino/grpc/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ func (c compileHandler) Compile() error {

// Upload executes the 'arduino-cli upload -i' command
// and returns its result.
func (c compileHandler) UploadBin(fqbn, bin, port string) error {
func (c compileHandler) UploadBin(fqbn, bin, address, protocol string) error {
stream, err := c.serviceClient.Upload(context.Background(),
&rpc.UploadRequest{
Instance: c.instance,
Fqbn: fqbn,
SketchPath: filepath.Dir(bin),
ImportFile: bin,
Port: &rpc.Port{Address: port},
Port: &rpc.Port{Address: address, Protocol: protocol},
Verbose: true,
})

Expand Down
18 changes: 10 additions & 8 deletions command/device/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ var (

// board contains details of a physical arduino board.
type board struct {
fqbn string
serial string
dType string
port string
fqbn string
serial string
dType string
address string
protocol string
}

// isCrypto checks if the board is a valid arduino board with a
Expand Down Expand Up @@ -78,10 +79,11 @@ func boardFromPorts(ports []*rpc.DetectedPort, params *CreateParams) *board {
boardFound := boardFilter(port.MatchingBoards, params)
if boardFound != nil {
b := &board{
fqbn: boardFound.Fqbn,
serial: port.Port.Properties["serialNumber"],
dType: strings.Split(boardFound.Fqbn, ":")[2],
port: port.Port.Address,
fqbn: boardFound.Fqbn,
serial: port.Port.Properties["serialNumber"],
dType: strings.Split(boardFound.Fqbn, ":")[2],
address: port.Port.Address,
protocol: port.Port.Protocol,
}
return b
}
Expand Down
16 changes: 8 additions & 8 deletions command/device/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ func TestBoardFromPorts(t *testing.T) {
name: "port-filter",
filter: &CreateParams{FQBN: nil, Port: stringPointer("ACM1")},
ports: portsTwoBoards,
want: &board{fqbn: "arduino:avr:uno", port: "ACM1"},
want: &board{fqbn: "arduino:avr:uno", address: "ACM1"},
},

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

{
Expand All @@ -90,7 +90,7 @@ func TestBoardFromPorts(t *testing.T) {
filter: &CreateParams{FQBN: nil, Port: nil},
ports: portsTwoBoards,
// first board found is selected
want: &board{fqbn: "arduino:samd:nano_33_iot", port: "ACM0"},
want: &board{fqbn: "arduino:samd:nano_33_iot", address: "ACM0"},
},

{
Expand All @@ -104,7 +104,7 @@ func TestBoardFromPorts(t *testing.T) {
name: "both-filter-found",
filter: &CreateParams{FQBN: stringPointer("arduino:avr:uno"), Port: stringPointer("ACM1")},
ports: portsTwoBoards,
want: &board{fqbn: "arduino:avr:uno", port: "ACM1"},
want: &board{fqbn: "arduino:avr:uno", address: "ACM1"},
},

{
Expand All @@ -123,14 +123,14 @@ func TestBoardFromPorts(t *testing.T) {
return

} else if got != nil && tt.want == nil {
t.Errorf("Expected nil board, received not nil board with port %s and fqbn %s", got.port, got.fqbn)
t.Errorf("Expected nil board, received not nil board with port %s and fqbn %s", got.address, got.fqbn)

} else if got == nil && tt.want != nil {
t.Errorf("Expected not nil board with port %s and fqbn %s, received a nil board", tt.want.port, tt.want.fqbn)
t.Errorf("Expected not nil board with port %s and fqbn %s, received a nil board", tt.want.address, tt.want.fqbn)

} else if got.port != tt.want.port || got.fqbn != tt.want.fqbn {
} else if got.address != tt.want.address || got.fqbn != tt.want.fqbn {
t.Errorf("Expected board with port %s and fqbn %s, received board with port %s and fqbn %s",
tt.want.port, tt.want.fqbn, got.port, got.fqbn)
tt.want.address, tt.want.fqbn, got.address, got.fqbn)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion command/device/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Create(params *CreateParams) (*DeviceInfo, error) {
"Try the 'create-lora' command instead if it's a LoRa device"+
" or 'create-generic' otherwise",
board.fqbn,
board.port,
board.address,
)
}

Expand Down
6 changes: 3 additions & 3 deletions command/device/createlora.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func CreateLora(params *CreateLoraParams) (*DeviceLoraInfo, error) {
" Try the 'create' command instead if it's a device with a supported crypto-chip"+
" or 'create-generic' otherwise",
board.fqbn,
board.port,
board.address,
)
}

Expand All @@ -96,13 +96,13 @@ func CreateLora(params *CreateLoraParams) (*DeviceLoraInfo, error) {
logrus.Infof("%s", "Uploading deveui sketch on the LoRa board")
errMsg := "Error while uploading the LoRa provisioning binary"
err = retry(deveuiUploadAttempts, deveuiUploadWait*time.Millisecond, errMsg, func() error {
return comm.UploadBin(board.fqbn, bin, board.port)
return comm.UploadBin(board.fqbn, bin, board.address, board.protocol)
})
if err != nil {
return nil, fmt.Errorf("failed to upload LoRa provisioning binary: %w", err)
}

eui, err := extractEUI(board.port)
eui, err := extractEUI(board.address)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions command/device/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func (p provision) run() error {
errMsg := "Error while uploading the provisioning sketch"
err = retry(5, time.Millisecond*1000, errMsg, func() error {
//serialutils.Reset(dev.port, true, nil)
return p.UploadBin(p.board.fqbn, bin, p.board.port)
fmt.Println(p.board.fqbn, bin, p.board.address)
return p.UploadBin(p.board.fqbn, bin, p.board.address, p.board.protocol)
})
if err != nil {
return err
Expand All @@ -98,7 +99,7 @@ func (p provision) run() error {
p.ser = serial.NewSerial()
errMsg = "Error while connecting to the board"
err = retry(5, time.Millisecond*1000, errMsg, func() error {
return p.ser.Connect(p.board.port)
return p.ser.Connect(p.board.address)
})
if err != nil {
return err
Expand Down