@@ -19,6 +19,7 @@ import (
1919 "encoding/json"
2020 "fmt"
2121 "io"
22+ "strings"
2223 "sync"
2324 "time"
2425
@@ -67,6 +68,23 @@ type discoveryMessage struct {
6768 Port * Port `json:"port"` // Used in add and remove events
6869}
6970
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+
7088// Port containts metadata about a port to connect to a board.
7189type Port struct {
7290 Address string `json:"address"`
@@ -149,6 +167,7 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
149167 disc .incomingMessagesError = err
150168 disc .statusMutex .Unlock ()
151169 close (outChan )
170+ logrus .Errorf ("stopped discovery %s decode loop" , disc .id )
152171 // TODO: Try restarting process some times before closing it completely
153172 }
154173
@@ -158,6 +177,7 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
158177 closeAndReportError (err )
159178 return
160179 }
180+ logrus .Infof ("from discovery %s received message %s" , disc .id , msg )
161181 if msg .EventType == "add" {
162182 if msg .Port == nil {
163183 closeAndReportError (errors .New (tr ("invalid 'add' message: missing port" )))
@@ -209,6 +229,7 @@ func (disc *PluggableDiscovery) waitMessage(timeout time.Duration) (*discoveryMe
209229}
210230
211231func (disc * PluggableDiscovery ) sendCommand (command string ) error {
232+ logrus .Infof ("sending command %s to discovery %s" , strings .TrimSpace (command ), disc )
212233 data := []byte (command )
213234 for {
214235 n , err := disc .outgoingCommandsPipe .Write (data )
@@ -223,22 +244,26 @@ func (disc *PluggableDiscovery) sendCommand(command string) error {
223244}
224245
225246func (disc * PluggableDiscovery ) runProcess () error {
247+ logrus .Infof ("starting discovery %s process" , disc .id )
226248 if err := disc .process .Start (); err != nil {
227249 return err
228250 }
229251 disc .statusMutex .Lock ()
230252 defer disc .statusMutex .Unlock ()
231253 disc .state = Alive
254+ logrus .Infof ("started discovery %s process" , disc .id )
232255 return nil
233256}
234257
235258func (disc * PluggableDiscovery ) killProcess () error {
259+ logrus .Infof ("killing discovery %s process" , disc .id )
236260 if err := disc .process .Kill (); err != nil {
237261 return err
238262 }
239263 disc .statusMutex .Lock ()
240264 defer disc .statusMutex .Unlock ()
241265 disc .state = Dead
266+ logrus .Infof ("killed discovery %s process" , disc .id )
242267 return nil
243268}
244269
0 commit comments