Skip to content

Commit 6a77998

Browse files
matteosuppofacchinm
authored andcommitted
Call programmer
1 parent 81634e2 commit 6a77998

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

programmer/programmer.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/arduino/arduino-create-agent/utilities"
1313
"github.com/facchinm/go-serial"
14+
shellwords "github.com/mattn/go-shellwords"
1415
"github.com/pkg/errors"
1516
)
1617

@@ -84,18 +85,18 @@ func Resolve(port, board, file, commandline string, extra Extra, t locater) (str
8485
}
8586

8687
// Do performs a command on a port with a board attached to it
87-
func Do(port, board, file, commandline string, extra Extra, t locater, l logger) {
88-
debug(l, port, board, file, commandline)
88+
func Do(port, commandline string, extra Extra, l logger) error {
8989
if extra.Network {
9090
doNetwork()
9191
} else {
92-
doSerial(port, board, file, commandline, extra, t, l)
92+
return doSerial(port, commandline, extra, l)
9393
}
94+
return nil
9495
}
9596

9697
func doNetwork() {}
9798

98-
func doSerial(port, board, file, commandline string, extra Extra, t locater, l logger) error {
99+
func doSerial(port, commandline string, extra Extra, l logger) error {
99100
// some boards needs to be resetted
100101
if extra.Use1200bpsTouch {
101102
var err error
@@ -105,7 +106,12 @@ func doSerial(port, board, file, commandline string, extra Extra, t locater, l l
105106
}
106107
}
107108

108-
return nil
109+
z, err := shellwords.Parse(commandline)
110+
if err != nil {
111+
return errors.Wrapf(err, "Parse commandline")
112+
}
113+
114+
return program(z[0], z[1:], l)
109115
}
110116

111117
// reset opens the port at 1200bps. It returns the new port name (which could change
@@ -246,7 +252,7 @@ func program(binary string, args []string, l logger) error {
246252

247253
go func() {
248254
for stderrCopy.Scan() {
249-
info(l, stdoutCopy.Text())
255+
info(l, stderrCopy.Text())
250256
}
251257
}()
252258

programmer/programmer_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package programmer_test
22

33
import (
4+
"log"
5+
"strings"
46
"testing"
57

68
"github.com/Sirupsen/logrus"
79
"github.com/arduino/arduino-create-agent/programmer"
10+
homedir "github.com/mitchellh/go-homedir"
811
)
912

1013
type mockTools struct{}
@@ -16,21 +19,24 @@ func (mockTools) GetLocation(el string) (string, error) {
1619
var TestSerialData = []struct {
1720
Name string
1821
Port string
19-
Board string
20-
File string
2122
Commandline string
2223
Extra programmer.Extra
2324
}{
24-
{"leonardo", "/dev/ttyACM0", "arduino:avr:leonardo", "./programmer_test.hex",
25-
`"{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"`, programmer.Extra{Use1200bpsTouch: true, WaitForUploadPort: true}},
25+
{
26+
"leonardo", "/dev/ttyACM0",
27+
`"~/.arduino-create/avrdude/6.3.0-arduino6/bin/avrdude" "-C~/.arduino-create/avrdude/6.3.0-arduino6/etc/avrdude.conf" -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./programmer_test.hex:i"`, programmer.Extra{Use1200bpsTouch: true, WaitForUploadPort: true}},
2628
}
2729

2830
func TestSerial(t *testing.T) {
2931
logger := logrus.New()
3032
logger.Level = logrus.DebugLevel
3133

34+
home, _ := homedir.Dir()
35+
3236
for _, test := range TestSerialData {
33-
programmer.Do(test.Port, test.Board, test.File, test.Commandline, test.Extra, mockTools{}, logger)
37+
commandline := strings.Replace(test.Commandline, "~", home, -1)
38+
err := programmer.Do(test.Port, commandline, test.Extra, logger)
39+
log.Println(err)
3440
}
3541
t.Fail()
3642
}

0 commit comments

Comments
 (0)