Skip to content

Commit 65cfa21

Browse files
authored
Merge branch 'arduino:master' into master
2 parents 2817249 + df2d30e commit 65cfa21

File tree

22 files changed

+355
-170
lines changed

22 files changed

+355
-170
lines changed

arduino/discovery/discovery_client/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
1414
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
1515
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
1616
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
17+
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
18+
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
1719
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
1820
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8=
1921
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=

arduino/discovery/discovery_client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func main() {
3737
log.Fatal("Error initializing discovery:", err)
3838
}
3939

40-
if err := disc.Hello(); err != nil {
40+
if err := disc.Run(); err != nil {
4141
log.Fatal("Error starting discovery:", err)
4242
}
4343
if err := disc.Start(); err != nil {

arduino/serialutils/serialutils.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package serialutils
1717

1818
import (
1919
"fmt"
20+
"strings"
2021
"time"
2122

2223
"github.com/pkg/errors"
@@ -86,9 +87,28 @@ type ResetProgressCallbacks struct {
8687
// If wait is true, this function will wait for a new port to appear and returns that
8788
// one, otherwise the empty string is returned if the new port can not be detected or
8889
// if the wait parameter is false.
90+
// If dryRun is set to true this function will only emulate the port reset without actually
91+
// performing it, this is useful to mockup for unit-testing and CI.
92+
// In dryRun mode if the `portToTouch` ends with `"999"` and wait is true, Reset will
93+
// return a new "bootloader" port as `portToTouch+"0"`.
8994
// The error is set if the port listing fails.
90-
func Reset(portToTouch string, wait bool, cb *ResetProgressCallbacks) (string, error) {
91-
last, err := getPortMap()
95+
func Reset(portToTouch string, wait bool, cb *ResetProgressCallbacks, dryRun bool) (string, error) {
96+
getPorts := getPortMap // non dry-run default
97+
if dryRun {
98+
emulatedPort := portToTouch
99+
getPorts = func() (map[string]bool, error) {
100+
res := map[string]bool{}
101+
if emulatedPort != "" {
102+
res[emulatedPort] = true
103+
}
104+
if strings.HasSuffix(emulatedPort, "999") {
105+
emulatedPort += "0"
106+
}
107+
return res, nil
108+
}
109+
}
110+
111+
last, err := getPorts()
92112
if cb != nil && cb.Debug != nil {
93113
cb.Debug(fmt.Sprintf("LAST: %v", last))
94114
}
@@ -103,8 +123,12 @@ func Reset(portToTouch string, wait bool, cb *ResetProgressCallbacks) (string, e
103123
if cb != nil && cb.TouchingPort != nil {
104124
cb.TouchingPort(portToTouch)
105125
}
106-
if err := TouchSerialPortAt1200bps(portToTouch); err != nil {
107-
fmt.Println("TOUCH: error during reset:", err)
126+
if dryRun {
127+
// do nothing!
128+
} else {
129+
if err := TouchSerialPortAt1200bps(portToTouch); err != nil {
130+
fmt.Println("TOUCH: error during reset:", err)
131+
}
108132
}
109133
}
110134

@@ -116,8 +140,12 @@ func Reset(portToTouch string, wait bool, cb *ResetProgressCallbacks) (string, e
116140
}
117141

118142
deadline := time.Now().Add(10 * time.Second)
143+
if dryRun {
144+
// use a much lower timeout in dryRun
145+
deadline = time.Now().Add(100 * time.Millisecond)
146+
}
119147
for time.Now().Before(deadline) {
120-
now, err := getPortMap()
148+
now, err := getPorts()
121149
if err != nil {
122150
return "", err
123151
}
@@ -146,7 +174,7 @@ func Reset(portToTouch string, wait bool, cb *ResetProgressCallbacks) (string, e
146174
// the USB serial port appearing and disappearing rapidly before
147175
// settling.
148176
// This check ensure that the port is stable after one second.
149-
check, err := getPortMap()
177+
check, err := getPorts()
150178
if err != nil {
151179
return "", err
152180
}

cli/burnbootloader/burnbootloader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
verbose bool
3434
verify bool
3535
programmer string
36+
dryRun bool
3637
)
3738

3839
// NewCommand created a new `burn-bootloader` command
@@ -51,6 +52,8 @@ func NewCommand() *cobra.Command {
5152
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
5253
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Turns on verbose mode.")
5354
burnBootloaderCommand.Flags().StringVarP(&programmer, "programmer", "P", "", "Use the specified programmer to upload.")
55+
burnBootloaderCommand.Flags().BoolVar(&dryRun, "dry-run", false, "Do not perform the actual upload, just log out actions")
56+
burnBootloaderCommand.Flags().MarkHidden("dry-run")
5457

5558
return burnBootloaderCommand
5659
}
@@ -65,6 +68,7 @@ func run(command *cobra.Command, args []string) {
6568
Verbose: verbose,
6669
Verify: verify,
6770
Programmer: programmer,
71+
DryRun: dryRun,
6872
}, os.Stdout, os.Stderr); err != nil {
6973
feedback.Errorf("Error during Upload: %v", err)
7074
os.Exit(errorcodes.ErrGeneric)

cli/upload/upload.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
importDir string
3939
importFile string
4040
programmer string
41+
dryRun bool
4142
)
4243

4344
// NewCommand created a new `upload` command
@@ -59,7 +60,8 @@ func NewCommand() *cobra.Command {
5960
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
6061
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
6162
uploadCommand.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload.")
62-
63+
uploadCommand.Flags().BoolVar(&dryRun, "dry-run", false, "Do not perform the actual upload, just log out actions")
64+
uploadCommand.Flags().MarkHidden("dry-run")
6365
return uploadCommand
6466
}
6567

@@ -97,6 +99,7 @@ func run(command *cobra.Command, args []string) {
9799
ImportFile: importFile,
98100
ImportDir: importDir,
99101
Programmer: programmer,
102+
DryRun: dryRun,
100103
}, os.Stdout, os.Stderr); err != nil {
101104
feedback.Errorf("Error during Upload: %v", err)
102105
os.Exit(errorcodes.ErrGeneric)

client_example/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ replace github.com/arduino/arduino-cli => ../
66

77
require (
88
github.com/arduino/arduino-cli v0.0.0-20200109150215-ffa84fdaab21
9-
google.golang.org/grpc v1.27.0
9+
google.golang.org/grpc v1.37.0
1010
)

0 commit comments

Comments
 (0)