Skip to content

Commit 1323486

Browse files
matteosuppofacchinm
authored andcommitted
Rename programmer in upload
1 parent 63f619f commit 1323486

11 files changed

+46
-49
lines changed

Diff for: conn.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"path/filepath"
1919

2020
log "github.com/Sirupsen/logrus"
21-
"github.com/arduino/arduino-create-agent/programmer"
21+
"github.com/arduino/arduino-create-agent/upload"
2222
"github.com/arduino/arduino-create-agent/utilities"
2323
"github.com/gin-gonic/gin"
2424
"github.com/googollee/go-socket.io"
@@ -63,7 +63,7 @@ type Upload struct {
6363
Rewrite string `json:"rewrite"`
6464
Commandline string `json:"commandline"`
6565
Signature string `json:"signature"`
66-
Extra programmer.Extra `json:"extra"`
66+
Extra upload.Extra `json:"extra"`
6767
Hex []byte `json:"hex"`
6868
Filename string `json:"filename"`
6969
ExtraFiles []AdditionalFile `json:"extrafiles"`
@@ -128,35 +128,35 @@ func uploadHandler(c *gin.Context) {
128128

129129
go func() {
130130
// Resolve commandline
131-
commandline, err := programmer.Resolve(data.Port, data.Board, filePath, data.Commandline, data.Extra, &Tools)
131+
commandline, err := upload.Resolve(data.Port, data.Board, filePath, data.Commandline, data.Extra, &Tools)
132132
if err != nil {
133-
send(map[string]string{"ProgrammerStatus": "Error", "Msg": err.Error()})
133+
send(map[string]string{"uploadStatus": "Error", "Msg": err.Error()})
134134
return
135135
}
136136

137137
l := PLogger{Verbose: data.Extra.Verbose}
138138

139139
// Upload
140140
if data.Extra.Network {
141-
send(map[string]string{"ProgrammerStatus": "Starting", "Cmd": "Network"})
142-
err = programmer.Network(data.Port, data.Board, filePath, commandline, data.Extra.Auth, l)
141+
send(map[string]string{"uploadStatus": "Starting", "Cmd": "Network"})
142+
err = upload.Network(data.Port, data.Board, filePath, commandline, data.Extra.Auth, l)
143143
} else {
144-
send(map[string]string{"ProgrammerStatus": "Starting", "Cmd": "Serial"})
145-
err = programmer.Serial(data.Port, commandline, data.Extra, l)
144+
send(map[string]string{"uploadStatus": "Starting", "Cmd": "Serial"})
145+
err = upload.Serial(data.Port, commandline, data.Extra, l)
146146
}
147147

148148
// Handle result
149149
if err != nil {
150-
send(map[string]string{"ProgrammerStatus": "Error", "Msg": err.Error()})
150+
send(map[string]string{"uploadStatus": "Error", "Msg": err.Error()})
151151
return
152152
}
153-
send(map[string]string{"ProgrammerStatus": "Done", "Flash": "Ok"})
153+
send(map[string]string{"uploadStatus": "Done", "Flash": "Ok"})
154154
}()
155155

156156
c.String(http.StatusAccepted, "")
157157
}
158158

159-
// PLogger sends the info from the programmer to the websocket
159+
// PLogger sends the info from the upload to the websocket
160160
type PLogger struct {
161161
Verbose bool
162162
}
@@ -172,7 +172,7 @@ func (l PLogger) Debug(args ...interface{}) {
172172
func (l PLogger) Info(args ...interface{}) {
173173
output := fmt.Sprint(args...)
174174
log.Println(output)
175-
send(map[string]string{"ProgrammerStatus": "Busy", "Msg": output})
175+
send(map[string]string{"uploadStatus": "Busy", "Msg": output})
176176
}
177177

178178
func send(args map[string]string) {

Diff for: discovery.go

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func getPorts() ([]OsSerialPort, error) {
126126
arrPorts := []OsSerialPort{}
127127
go func(results chan *bonjour.ServiceEntry, exitCh chan<- bool) {
128128
for e := range results {
129+
log.Printf("%+v", e)
129130
if e.AddrIPv4 != nil {
130131
arrPorts = append(arrPorts, OsSerialPort{Name: e.AddrIPv4.String(), IdProduct: e.Instance, IdVendor: strings.Join(e.Text[:], " "), NetworkPort: true})
131132
}

Diff for: hub.go

+9-13
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ package main
33
import (
44
"fmt"
55

6-
log "github.com/Sirupsen/logrus"
7-
"github.com/arduino/arduino-create-agent/programmer"
8-
"github.com/kardianos/osext"
9-
//"os"
10-
"os/exec"
11-
//"path"
12-
//"path/filepath"
13-
//"runtime"
14-
//"debug"
156
"encoding/json"
167
"io"
178
"os"
9+
"os/exec"
1810
"runtime"
1911
"runtime/debug"
2012
"strconv"
2113
"strings"
14+
15+
log "github.com/Sirupsen/logrus"
16+
"github.com/arduino/arduino-create-agent/upload"
17+
"github.com/kardianos/osext"
2218
)
2319

2420
type hub struct {
@@ -169,12 +165,12 @@ func checkCmd(m []byte) {
169165
go spErr("You did not specify a port to close")
170166
}
171167

172-
} else if strings.HasPrefix(sl, "killprogrammer") {
168+
} else if strings.HasPrefix(sl, "killupload") {
173169
// kill the running process (assumes singleton for now)
174170
go func() {
175-
programmer.Kill()
176-
h.broadcastSys <- []byte("{\"ProgrammerStatus\": \"Killed\"}")
177-
log.Println("{\"ProgrammerStatus\": \"Killed\"}")
171+
upload.Kill()
172+
h.broadcastSys <- []byte("{\"uploadStatus\": \"Killed\"}")
173+
log.Println("{\"uploadStatus\": \"Killed\"}")
178174
}()
179175

180176
} else if strings.HasPrefix(sl, "sendjsonraw") {

Diff for: serial.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"time"
1313

1414
log "github.com/Sirupsen/logrus"
15-
"github.com/arduino/arduino-create-agent/programmer"
15+
"github.com/arduino/arduino-create-agent/upload"
1616
)
1717

1818
type writeRequest struct {
@@ -455,7 +455,7 @@ func discoverLoop() {
455455

456456
go func() {
457457
for {
458-
if !programmer.Busy {
458+
if !upload.Busy {
459459
spListDual(false)
460460
}
461461
time.Sleep(2 * time.Second)

Diff for: programmer/README.md renamed to upload/README.md

File renamed without changes.

Diff for: programmer/doc.go renamed to upload/doc.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package programmer allows to upload sketches into a board connected to the computer
1+
// Package upload allows to upload sketches into a board connected to the computer
22
// It can do it via serial port or via network
33
//
44
// **Usage for a serial upload**
@@ -7,7 +7,7 @@
77
//
88
// ```go
99
// commandline = ``"/usr/bin/avrdude" "-C/usr/bin/avrdude.conf" -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./sketch.hex:i"``
10-
// err := programmer.Serial("/dev/ttyACM0", commandline, programmer.Extra{}, nil)
10+
// err := upload.Serial("/dev/ttyACM0", commandline, upload.Extra{}, nil)
1111
// ```
1212
//
1313
// note that the commandline contains the path of the sketch (sketch.hex)
@@ -17,7 +17,7 @@
1717
// Make sure that you have a compiled sketch somewhere on your disk
1818
//
1919
// ```go
20-
// err := programmer.Network("127.0.10.120", "arduino:avr:yun, "./sketch.hex", "", programmer.Auth{}, nil)
20+
// err := upload.Network("127.0.10.120", "arduino:avr:yun, "./sketch.hex", "", upload.Auth{}, nil)
2121
// ```
2222
//
2323
// The commandline can be empty or it can contain instructions (depends on the board)
@@ -28,7 +28,7 @@
2828
//
2929
// ```go
3030
// t := tools.Tools{}
31-
// commandline = programmer.Resolve("/dev/ttyACM0", "arduino:avr:leonardo", "./sketch.hex", commandline, programmer.Extra{}, t)
31+
// commandline = upload.Resolve("/dev/ttyACM0", "arduino:avr:leonardo", "./sketch.hex", commandline, upload.Extra{}, t)
3232
// ```
3333
//
3434
// t must implement the locater interface (the Tools package does!)
@@ -39,6 +39,6 @@
3939
// ```go
4040
// logger := logrus.New()
4141
// logger.Level = logrus.DebugLevel
42-
// programmer.Serial("/dev/ttyACM0", commandline, programmer.Extra{}, logger)
42+
// upload.Serial("/dev/ttyACM0", commandline, upload.Extra{}, logger)
4343
// ```
44-
package programmer
44+
package upload

Diff for: programmer/programmer.go renamed to upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package programmer
1+
package upload
22

33
import (
44
"bufio"

Diff for: programmer/programmer_test.go renamed to upload/upload_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package programmer_test
1+
package upload_test
22

33
import (
44
"log"
55
"strings"
66
"testing"
77

88
"github.com/Sirupsen/logrus"
9-
"github.com/arduino/arduino-create-agent/programmer"
9+
"github.com/arduino/arduino-create-agent/upload"
1010
homedir "github.com/mitchellh/go-homedir"
1111
)
1212

@@ -21,11 +21,11 @@ var TestSerialData = []struct {
2121
Name string
2222
Port string
2323
Commandline string
24-
Extra programmer.Extra
24+
Extra upload.Extra
2525
}{
2626
{
2727
"leonardo", "/dev/ttyACM0",
28-
`"~/.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}},
28+
`"~/.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:./upload_test.hex:i"`, upload.Extra{Use1200bpsTouch: true, WaitForUploadPort: true}},
2929
}
3030

3131
func TestSerial(t *testing.T) {
@@ -36,7 +36,7 @@ func TestSerial(t *testing.T) {
3636

3737
for _, test := range TestSerialData {
3838
commandline := strings.Replace(test.Commandline, "~", home, -1)
39-
err := programmer.Serial(test.Port, commandline, test.Extra, logger)
39+
err := upload.Serial(test.Port, commandline, test.Extra, logger)
4040
log.Println(err)
4141
}
4242
}
@@ -47,11 +47,11 @@ var TestNetworkData = []struct {
4747
Board string
4848
File string
4949
Commandline string
50-
Auth programmer.Auth
50+
Auth upload.Auth
5151
}{
5252
{
5353
"yun", "", "", "",
54-
``, programmer.Auth{}},
54+
``, upload.Auth{}},
5555
}
5656

5757
func TestNetwork(t *testing.T) {
@@ -62,7 +62,7 @@ func TestNetwork(t *testing.T) {
6262

6363
for _, test := range TestNetworkData {
6464
commandline := strings.Replace(test.Commandline, "~", home, -1)
65-
err := programmer.Network(test.Port, test.Board, test.File, commandline, test.Auth, logger)
65+
err := upload.Network(test.Port, test.Board, test.File, commandline, test.Auth, logger)
6666
log.Println(err)
6767
}
6868
}
@@ -72,17 +72,17 @@ var TestResolveData = []struct {
7272
Board string
7373
File string
7474
Commandline string
75-
Extra programmer.Extra
75+
Extra upload.Extra
7676
Result string
7777
}{
78-
{"/dev/ttyACM0", "arduino:avr:leonardo", "./programmer_test.hex",
79-
`"{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},
80-
`"$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:./programmer_test.hex:i"`},
78+
{"/dev/ttyACM0", "arduino:avr:leonardo", "./upload_test.hex",
79+
`"{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},
80+
`"$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"`},
8181
}
8282

8383
func TestResolve(t *testing.T) {
8484
for _, test := range TestResolveData {
85-
result, _ := programmer.Resolve(test.Port, test.Board, test.File, test.Commandline, test.Extra, mockTools{})
85+
result, _ := upload.Resolve(test.Port, test.Board, test.File, test.Commandline, test.Extra, mockTools{})
8686
if result != test.Result {
8787
t.Error("expected " + test.Result + ", got " + result)
8888
continue
File renamed without changes.

Diff for: programmer/utils.go renamed to upload/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package programmer
1+
package upload
22

33
// Logger is an interface implemented by most loggers (like logrus)
44
type Logger interface {

Diff for: programmer/utils_test.go renamed to upload/utils_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package programmer
1+
package upload
22

33
import "testing"
44

0 commit comments

Comments
 (0)