Skip to content

removed verbose options in commandline resolve, improved doc #264

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 4 commits into from
Jun 18, 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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)

arduino-create-agent
====================
Expand Down Expand Up @@ -232,7 +233,7 @@ You will receive an object of all the boards connected with USB or over the netw
}
```

## Open/Close ports
### Open/Close ports

To read input from a board connected to USB you must first open the port with the command

Expand Down Expand Up @@ -340,7 +341,7 @@ The payload is a json object that looks like this:
{
"board":"arduino:avr:leonardo",
"port":"/dev/ttyACM1",
"commandline":"\"{runtime.tools.avrdude.path}/bin/avrdude\" \"-C{runtime.tools.avrdude.path}/etc/avrdude.conf\" {upload.verbose} -patmega32u4 -cavr109 -P{serial.port} -b57600 -D \"-Uflash:w:{build.path}/{build.project_name}.hex:i\"",
"commandline":"\"{runtime.tools.avrdude.path}/bin/avrdude\" \"-C{runtime.tools.avrdude.path}/etc/avrdude.conf\" -v -patmega32u4 -cavr109 -P{serial.port} -b57600 -D \"-Uflash:w:{build.path}/{build.project_name}.hex:i\"",
"signature":"97db97ced2c",
"hex":"OjEwMDAwMDAwMEM5NEU1MDAwQzk0MEQwMTBDOTQwRDAxMEM5NDBEMDE2MQ0KOjEwMDAxMDAwMEM5NDBEMDEwQzk0M",
"filename":"Blink.ino.hex",
Expand All @@ -355,16 +356,13 @@ The payload is a json object that looks like this:
"wait_for_upload_port":true,
"use_1200bps_touch":true,
"network":false,
"params_verbose":"-v",
"params_quiet":"-q -q",
"verbose":true
}
}
```

- commandline is the command to execute to perform the upload. This is, for example, avrdude on a Leonardo.

- hex contains the sketch hex encoded in base64
- hex contains the sketch binary encoded in base64 (could decode in Intel hex or raw binary)

- signature is the signature of the commandline signed with the private key that matches the public key contained in the config.ini of the arduino-create-agent

Expand All @@ -376,6 +374,10 @@ The results of the upload will be delivered via websocket with messages that loo
{"Flash":"Ok","ProgrammerStatus":"Done"}
```

### Javacript client library

You can install the [arduino-create-agent-js-client](https://github.com/arduino/arduino-create-agent-js-client) in your client application

---

## Development
Expand Down
6 changes: 3 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type Upload struct {
ExtraFiles []AdditionalFile `json:"extrafiles"`
}

var uploadStatusStr string = "ProgrammerStatus"
var uploadStatusStr = "ProgrammerStatus"

func uploadHandler(c *gin.Context) {

Expand Down Expand Up @@ -156,7 +156,7 @@ func uploadHandler(c *gin.Context) {
return
}

l := PLogger{Verbose: data.Extra.Verbose}
l := PLogger{Verbose: true}

// Upload
if data.Extra.Network {
Expand All @@ -183,7 +183,7 @@ type PLogger struct {
Verbose bool
}

// Debug only sends messages if verbose is true
// Debug only sends messages if verbose is true (always true for now)
func (l PLogger) Debug(args ...interface{}) {
if l.Verbose {
l.Info(args...)
Expand Down
3 changes: 0 additions & 3 deletions upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ type Extra struct {
WaitForUploadPort bool `json:"wait_for_upload_port"`
Network bool `json:"network"`
Auth Auth `json:"auth"`
Verbose bool `json:"verbose"`
ParamsVerbose string `json:"params_verbose"`
ParamsQuiet string `json:"params_quiet"`
}
```
Extra contains some options used during the upload
Expand Down
2 changes: 1 addition & 1 deletion upload/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// commandline = upload.Resolve("/dev/ttyACM0", "arduino:avr:leonardo", "./sketch.hex", commandline, upload.Extra{}, t)
// ```
//
// t must implement the locater interface (the Tools package does!)
// 't' must implement the locater interface (the Tools package does!)
//
// **Logging**
// If you're interested in the output of the commands, you can implement the logger interface. Here's an example:
Expand Down
19 changes: 5 additions & 14 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ type Auth struct {

// Extra contains some options used during the upload
type Extra struct {
Use1200bpsTouch bool `json:"use_1200bps_touch"`
WaitForUploadPort bool `json:"wait_for_upload_port"`
Network bool `json:"network"`
Auth Auth `json:"auth"`
Verbose bool `json:"verbose"`
ParamsVerbose string `json:"params_verbose"`
ParamsQuiet string `json:"params_quiet"`
SSH bool `json:"ssh,omitempty"`
Use1200bpsTouch bool `json:"use_1200bps_touch"`
WaitForUploadPort bool `json:"wait_for_upload_port"`
Network bool `json:"network"`
Auth Auth `json:"auth"`
SSH bool `json:"ssh,omitempty"`
}

// PartiallyResolve replaces some symbols in the commandline with the appropriate values
Expand All @@ -57,12 +54,6 @@ func PartiallyResolve(board, file, platformPath, commandline string, extra Extra
commandline = strings.Replace(commandline, "{network.password}", extra.Auth.Password, -1)
commandline = strings.Replace(commandline, "{runtime.platform.path}", filepath.ToSlash(platformPath), -1)

if extra.Verbose == true {
commandline = strings.Replace(commandline, "{upload.verbose}", extra.ParamsVerbose, -1)
} else {
commandline = strings.Replace(commandline, "{upload.verbose}", extra.ParamsQuiet, -1)
}

// search for runtime variables and replace with values from Locater
var runtimeRe = regexp.MustCompile("\\{(.*?)\\}")
runtimeVars := runtimeRe.FindAllString(commandline, -1)
Expand Down
40 changes: 25 additions & 15 deletions upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,23 @@ var TestNetworkData = []struct {
Name string
Port string
Board string
File string
Files []string
Commandline string
Auth upload.Auth
Extra upload.Extra
}{
{
"yun", "", "", "",
``, upload.Auth{}},
"yun",
"",
"",
[]string{"filename"},
"",
upload.Extra{
Use1200bpsTouch: true,
WaitForUploadPort: true,
Network: true,
Auth: upload.Auth{},
},
},
}

func TestNetwork(t *testing.T) {
Expand All @@ -62,27 +72,27 @@ func TestNetwork(t *testing.T) {

for _, test := range TestNetworkData {
commandline := strings.Replace(test.Commandline, "$HOME", home, -1)
err := upload.Network(test.Port, test.Board, test.File, commandline, test.Auth, logger)
err := upload.Network(test.Port, test.Board, test.Files, commandline, test.Extra.Auth, logger, test.Extra.SSH)
log.Println(err)
}
}

var TestResolveData = []struct {
Port string
Board string
File string
Commandline string
Extra upload.Extra
Result string
Board string
File string
PlatformPath string
Commandline string
Extra upload.Extra
Result string
}{
{"/dev/ttyACM0", "arduino:avr:leonardo", "./upload_test.hex",
`"{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" {upload.verbose} {upload.verify} -patmega32u4 -cavr109 -P{serial.port} -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"`, upload.Extra{Use1200bpsTouch: true, WaitForUploadPort: true},
`"$loc$loc{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" $loc{upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"`},
{"arduino:avr:leonardo", "./upload_test.hex", "",
`"{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" -v {upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"`, upload.Extra{Use1200bpsTouch: true, WaitForUploadPort: true},
`"$loc$loc{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" -v $loc{upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"`},
}

func TestResolve(t *testing.T) {
for _, test := range TestResolveData {
result, _ := upload.Resolve(test.Port, test.Board, test.File, test.Commandline, test.Extra, mockTools{})
result, _ := upload.PartiallyResolve(test.Board, test.File, test.PlatformPath, test.Commandline, test.Extra, mockTools{})
if result != test.Result {
t.Error("expected " + test.Result + ", got " + result)
continue
Expand Down