@@ -5,11 +5,6 @@ import (
5
5
"bytes"
6
6
"encoding/json"
7
7
"fmt"
8
- log "github.com/Sirupsen/logrus"
9
- "github.com/facchinm/go-serial"
10
- "github.com/mattn/go-shellwords"
11
- "github.com/sfreiberg/simplessh"
12
- "github.com/xrash/smetrics"
13
8
"io"
14
9
"mime/multipart"
15
10
"net/http"
@@ -21,6 +16,12 @@ import (
21
16
"strconv"
22
17
"strings"
23
18
"time"
19
+
20
+ log "github.com/Sirupsen/logrus"
21
+ "github.com/facchinm/go-serial"
22
+ "github.com/mattn/go-shellwords"
23
+ "github.com/sfreiberg/simplessh"
24
+ "github.com/xrash/smetrics"
24
25
)
25
26
26
27
var compiling = false
@@ -31,15 +32,15 @@ func colonToUnderscore(input string) string {
31
32
}
32
33
33
34
type basicAuthData struct {
34
- UserName string
35
- Password string
35
+ Username string `json:"username"`
36
+ Password string `json:"password"`
36
37
}
37
38
38
39
type boardExtraInfo struct {
39
- use_1200bps_touch bool
40
- wait_for_upload_port bool
41
- networkPort bool
42
- authdata basicAuthData
40
+ Use1200bpsTouch bool `json:"use_100bps_touch"`
41
+ WaitForUploadPort bool `json:"wait_for_upload_port"`
42
+ Network bool `json:"network"`
43
+ Auth basicAuthData `json:"auth"`
43
44
}
44
45
45
46
// Scp uploads sourceFile to remote machine like native scp console app.
@@ -90,15 +91,15 @@ func spProgramSSHNetwork(portname string, boardname string, filePath string, com
90
91
log .Println ("Starting network upload" )
91
92
log .Println ("Board Name: " + boardname )
92
93
93
- if authdata .UserName == "" {
94
- authdata .UserName = "root"
94
+ if authdata .Username == "" {
95
+ authdata .Username = "root"
95
96
}
96
97
97
98
if authdata .Password == "" {
98
99
authdata .Password = "arduino"
99
100
}
100
101
101
- ssh_client , err := simplessh .ConnectWithPassword (portname + ":22" , authdata .UserName , authdata .Password )
102
+ ssh_client , err := simplessh .ConnectWithPassword (portname + ":22" , authdata .Username , authdata .Password )
102
103
if err != nil {
103
104
log .Println ("Error connecting via ssh" )
104
105
return err
@@ -133,8 +134,8 @@ func spProgramNetwork(portname string, boardname string, filePath string, authda
133
134
log .Println ("Starting network upload" )
134
135
log .Println ("Board Name: " + boardname )
135
136
136
- if authdata .UserName == "" {
137
- authdata .UserName = "root"
137
+ if authdata .Username == "" {
138
+ authdata .Username = "root"
138
139
}
139
140
140
141
if authdata .Password == "" {
@@ -182,8 +183,8 @@ func spProgramNetwork(portname string, boardname string, filePath string, authda
182
183
}
183
184
// Don't forget to set the content type, this will contain the boundary.
184
185
req .Header .Set ("Content-Type" , w .FormDataContentType ())
185
- if authdata .UserName != "" {
186
- req .SetBasicAuth (authdata .UserName , authdata .Password )
186
+ if authdata .Username != "" {
187
+ req .SetBasicAuth (authdata .Username , authdata .Password )
187
188
}
188
189
189
190
//h.broadcastSys <- []byte("Start flashing with command " + cmdString)
@@ -211,8 +212,8 @@ func spProgramNetwork(portname string, boardname string, filePath string, authda
211
212
func spProgramLocal (portname string , boardname string , filePath string , commandline string , extraInfo boardExtraInfo ) error {
212
213
213
214
var err error
214
- if extraInfo .use_1200bps_touch {
215
- portname , err = touch_port_1200bps (portname , extraInfo .wait_for_upload_port )
215
+ if extraInfo .Use1200bpsTouch {
216
+ portname , err = touch_port_1200bps (portname , extraInfo .WaitForUploadPort )
216
217
}
217
218
218
219
if err != nil {
@@ -264,11 +265,11 @@ func spProgramRW(portname string, boardname string, filePath string, commandline
264
265
265
266
var err error
266
267
267
- if extraInfo .networkPort {
268
- err = spProgramNetwork (portname , boardname , filePath , extraInfo .authdata )
268
+ if extraInfo .Network {
269
+ err = spProgramNetwork (portname , boardname , filePath , extraInfo .Auth )
269
270
if err != nil {
270
271
// no http method available, try ssh upload
271
- err = spProgramSSHNetwork (portname , boardname , filePath , commandline , extraInfo .authdata )
272
+ err = spProgramSSHNetwork (portname , boardname , filePath , commandline , extraInfo .Auth )
272
273
}
273
274
} else {
274
275
err = spProgramLocal (portname , boardname , filePath , commandline , extraInfo )
@@ -423,7 +424,7 @@ func findNewPortName(slice1 []string, slice2 []string) string {
423
424
return ""
424
425
}
425
426
426
- func touch_port_1200bps (portname string , wait_for_upload_port bool ) (string , error ) {
427
+ func touch_port_1200bps (portname string , WaitForUploadPort bool ) (string , error ) {
427
428
initialPortName := portname
428
429
log .Println ("Restarting in bootloader mode" )
429
430
@@ -455,7 +456,7 @@ func touch_port_1200bps(portname string, wait_for_upload_port bool) (string, err
455
456
}()
456
457
457
458
// wait for port to disappear
458
- if wait_for_upload_port {
459
+ if WaitForUploadPort {
459
460
for {
460
461
ports , _ = serial .GetPortsList ()
461
462
log .Println (ports )
@@ -471,7 +472,7 @@ func touch_port_1200bps(portname string, wait_for_upload_port bool) (string, err
471
472
}
472
473
473
474
// wait for port to reappear
474
- if wait_for_upload_port {
475
+ if WaitForUploadPort {
475
476
after_reset_ports , _ := serial .GetPortsList ()
476
477
log .Println (after_reset_ports )
477
478
for {
0 commit comments