@@ -291,6 +291,29 @@ def sendPosition(self, latitude=0.0, longitude=0.0, altitude=0, timeSec=0,
291291 portNum = portnums_pb2 .PortNum .POSITION_APP ,
292292 wantAck = wantAck ,
293293 wantResponse = wantResponse )
294+
295+ def sendTraceRoute (self , dest , hopLimit ):
296+ r = mesh_pb2 .RouteDiscovery ()
297+ self .sendData (r , destinationId = dest , portNum = portnums_pb2 .PortNum .TRACEROUTE_APP ,
298+ wantResponse = True , onResponse = self .onResponseTraceRoute )
299+ # extend timeout based on number of nodes, limit by configured hopLimit
300+ waitFactor = min (len (self .nodes )- 1 , hopLimit )
301+ self .waitForTraceRoute (waitFactor )
302+
303+ def onResponseTraceRoute (self , p ):
304+ routeDiscovery = mesh_pb2 .RouteDiscovery ()
305+ routeDiscovery .ParseFromString (p ["decoded" ]["payload" ])
306+ asDict = google .protobuf .json_format .MessageToDict (routeDiscovery )
307+
308+ print ("Route traced:" )
309+ routeStr = self ._nodeNumToId (p ["to" ])
310+ if "route" in asDict :
311+ for nodeNum in asDict ["route" ]:
312+ routeStr += " --> " + self ._nodeNumToId (nodeNum )
313+ routeStr += " --> " + self ._nodeNumToId (p ["from" ])
314+ print (routeStr )
315+
316+ self ._acknowledgment .receivedTraceRoute = True
294317
295318 def _addResponseHandler (self , requestId , callback ):
296319 self .responseHandlers [requestId ] = ResponseHandler (callback )
@@ -365,6 +388,11 @@ def waitForAckNak(self):
365388 if not success :
366389 raise Exception ("Timed out waiting for an acknowledgment" )
367390
391+ def waitForTraceRoute (self , waitFactor ):
392+ success = self ._timeout .waitForTraceRoute (waitFactor , self ._acknowledgment )
393+ if not success :
394+ raise Exception ("Timed out waiting for traceroute" )
395+
368396 def getMyNodeInfo (self ):
369397 """Get info about my node."""
370398 if self .myInfo is None :
0 commit comments