@@ -12,6 +12,7 @@ import (
12
12
"encoding/json"
13
13
"encoding/pem"
14
14
"errors"
15
+ "fmt"
15
16
"io/ioutil"
16
17
"net/http"
17
18
"path/filepath"
@@ -129,17 +130,19 @@ func uploadHandler(c *gin.Context) {
129
130
// Resolve commandline
130
131
commandline , err := programmer .Resolve (data .Port , data .Board , filePath , data .Commandline , data .Extra , & Tools )
131
132
if err != nil {
132
-
133
+ send ( map [ string ] string { "ProgrammerStatus" : "Error" , "Msg" : err . Error ()})
133
134
return
134
135
}
135
136
137
+ l := PLogger {Verbose : data .Extra .Verbose }
138
+
136
139
// Upload
137
140
if data .Extra .Network {
138
141
send (map [string ]string {"ProgrammerStatus" : "Starting" , "Cmd" : "Network" })
139
- err = programmer .Network (data .Port , data .Board , filePath , commandline , data .Extra .Auth , nil )
142
+ err = programmer .Network (data .Port , data .Board , filePath , commandline , data .Extra .Auth , l )
140
143
} else {
141
144
send (map [string ]string {"ProgrammerStatus" : "Starting" , "Cmd" : "Serial" })
142
- err = programmer .Serial (data .Port , commandline , data .Extra , nil )
145
+ err = programmer .Serial (data .Port , commandline , data .Extra , l )
143
146
}
144
147
145
148
// Handle result
@@ -153,6 +156,24 @@ func uploadHandler(c *gin.Context) {
153
156
c .String (http .StatusAccepted , "" )
154
157
}
155
158
159
+ // PLogger sends the info from the programmer to the websocket
160
+ type PLogger struct {
161
+ Verbose bool
162
+ }
163
+
164
+ // Debug only sends messages if verbose is true
165
+ func (l PLogger ) Debug (args ... interface {}) {
166
+ if l .Verbose {
167
+ l .Info (args ... )
168
+ }
169
+ }
170
+
171
+ // Info always send messages
172
+ func (l PLogger ) Info (args ... interface {}) {
173
+ output := fmt .Sprint (args ... )
174
+ send (map [string ]string {"ProgrammerStatus" : "Busy" , "Msg" : output })
175
+ }
176
+
156
177
func send (args map [string ]string ) {
157
178
mapB , _ := json .Marshal (args )
158
179
h .broadcastSys <- mapB
0 commit comments