@@ -381,13 +381,50 @@ def sendPosition(
381381 p .time = timeSec
382382 logging .debug (f"p.time:{ p .time } " )
383383
384- return self .sendData (
384+ if wantResponse :
385+ onResponse = self .onResponsePosition
386+ else :
387+ onResponse = None
388+
389+ d = self .sendData (
385390 p ,
386391 destinationId ,
387392 portNum = portnums_pb2 .PortNum .POSITION_APP ,
388393 wantAck = wantAck ,
389394 wantResponse = wantResponse ,
395+ onResponse = onResponse ,
390396 )
397+ if wantResponse :
398+ self .waitForPosition ()
399+ return d
400+
401+ def onResponsePosition (self , p ):
402+ """on response for position"""
403+ if p ["decoded" ]["portnum" ] == 'POSITION_APP' :
404+ self ._acknowledgment .receivedPosition = True
405+ position = mesh_pb2 .Position ()
406+ position .ParseFromString (p ["decoded" ]["payload" ])
407+
408+ ret = "Position received: "
409+ if position .latitude_i != 0 and position .longitude_i != 0 :
410+ ret += f"({ position .latitude_i * 10 ** - 7 } , { position .longitude_i * 10 ** - 7 } )"
411+ else :
412+ ret += "(unknown)"
413+ if position .altitude != 0 :
414+ ret += f" { position .altitude } m"
415+
416+ if position .precision_bits not in [0 ,32 ]:
417+ ret += f" precision:{ position .precision_bits } "
418+ elif position .precision_bits == 32 :
419+ ret += " full precision"
420+ elif position .precision_bits == 0 :
421+ ret += " position disabled"
422+
423+ print (ret )
424+
425+ elif p ["decoded" ]["portnum" ] == 'ROUTING_APP' :
426+ if p ["decoded" ]["routing" ]["errorReason" ] == 'NO_RESPONSE' :
427+ our_exit ("No response from node. At least firmware 2.1.22 is required on the destination node." )
391428
392429 def sendTraceRoute (self , dest : Union [int , str ], hopLimit : int ):
393430 """Send the trace route"""
@@ -445,11 +482,6 @@ def sendTelemetry(self, destinationId=BROADCAST_ADDR, wantResponse=False):
445482 else :
446483 onResponse = None
447484
448- if destinationId .startswith ("!" ):
449- destinationId = int (destinationId [1 :], 16 )
450- else :
451- destinationId = int (destinationId )
452-
453485 self .sendData (
454486 r ,
455487 destinationId = destinationId ,
@@ -573,6 +605,12 @@ def waitForTelemetry(self):
573605 if not success :
574606 raise MeshInterface .MeshInterfaceError ("Timed out waiting for telemetry" )
575607
608+ def waitForPosition (self ):
609+ """Wait for position"""
610+ success = self ._timeout .waitForPosition (self ._acknowledgment )
611+ if not success :
612+ raise MeshInterface .MeshInterfaceError ("Timed out waiting for position" )
613+
576614 def getMyNodeInfo (self ) -> Optional [Dict ]:
577615 """Get info about my node."""
578616 if self .myInfo is None or self .nodesByNum is None :
0 commit comments