@@ -19,6 +19,7 @@ import (
19
19
"encoding/json"
20
20
"fmt"
21
21
"io"
22
+ "strings"
22
23
"sync"
23
24
"time"
24
25
@@ -67,6 +68,23 @@ type discoveryMessage struct {
67
68
Port * Port `json:"port"` // Used in add and remove events
68
69
}
69
70
71
+ func (msg discoveryMessage ) String () string {
72
+ s := fmt .Sprintf ("type: %s" , msg .EventType )
73
+ if msg .Message != "" {
74
+ s = fmt .Sprintf ("%s, message: %s" , s , msg .Message )
75
+ }
76
+ if msg .ProtocolVersion != 0 {
77
+ s = fmt .Sprintf ("%s, protocol version: %d" , s , msg .ProtocolVersion )
78
+ }
79
+ if len (msg .Ports ) > 0 {
80
+ s = fmt .Sprintf ("%s, ports: %s" , s , msg .Ports )
81
+ }
82
+ if msg .Port != nil {
83
+ s = fmt .Sprintf ("%s, port: %s" , s , msg .Port )
84
+ }
85
+ return s
86
+ }
87
+
70
88
// Port containts metadata about a port to connect to a board.
71
89
type Port struct {
72
90
Address string `json:"address"`
@@ -149,6 +167,7 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
149
167
disc .incomingMessagesError = err
150
168
disc .statusMutex .Unlock ()
151
169
close (outChan )
170
+ logrus .Errorf ("stopped discovery %s decode loop" , disc .id )
152
171
// TODO: Try restarting process some times before closing it completely
153
172
}
154
173
@@ -158,6 +177,7 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
158
177
closeAndReportError (err )
159
178
return
160
179
}
180
+ logrus .Infof ("from discovery %s received message %s" , disc .id , msg )
161
181
if msg .EventType == "add" {
162
182
if msg .Port == nil {
163
183
closeAndReportError (errors .New (tr ("invalid 'add' message: missing port" )))
@@ -209,6 +229,7 @@ func (disc *PluggableDiscovery) waitMessage(timeout time.Duration) (*discoveryMe
209
229
}
210
230
211
231
func (disc * PluggableDiscovery ) sendCommand (command string ) error {
232
+ logrus .Infof ("sending command %s to discovery %s" , strings .TrimSpace (command ), disc )
212
233
data := []byte (command )
213
234
for {
214
235
n , err := disc .outgoingCommandsPipe .Write (data )
@@ -223,22 +244,26 @@ func (disc *PluggableDiscovery) sendCommand(command string) error {
223
244
}
224
245
225
246
func (disc * PluggableDiscovery ) runProcess () error {
247
+ logrus .Infof ("starting discovery %s process" , disc .id )
226
248
if err := disc .process .Start (); err != nil {
227
249
return err
228
250
}
229
251
disc .statusMutex .Lock ()
230
252
defer disc .statusMutex .Unlock ()
231
253
disc .state = Alive
254
+ logrus .Infof ("started discovery %s process" , disc .id )
232
255
return nil
233
256
}
234
257
235
258
func (disc * PluggableDiscovery ) killProcess () error {
259
+ logrus .Infof ("killing discovery %s process" , disc .id )
236
260
if err := disc .process .Kill (); err != nil {
237
261
return err
238
262
}
239
263
disc .statusMutex .Lock ()
240
264
defer disc .statusMutex .Unlock ()
241
265
disc .state = Dead
266
+ logrus .Infof ("killed discovery %s process" , disc .id )
242
267
return nil
243
268
}
244
269
0 commit comments