1414
1515from pymavlink import mavutil
1616from MAVProxy .modules .lib import mp_module
17+ from MAVProxy .modules .lib import mp_settings
1718from MAVProxy .modules .lib import mp_util
1819if mp_util .has_wxpython :
1920 from MAVProxy .modules .lib .mp_menu import MPMenuCallFileDialog
@@ -50,6 +51,33 @@ def __init__(self, mpstate, name, description, **args):
5051 self .upload_start = None
5152 self .last_get_home = time .time ()
5253 self .ftp_count = None
54+ self .mip_settings = mp_settings .MPSettings ([
55+ ('autorefresh' , int , 1 ),
56+ ])
57+
58+ class OpaqueInformation ():
59+ '''class to keep track of what sysid/compid pair has what'''
60+ def __init__ (self ):
61+ self .have_id = - 100 # meaning "we don't know"
62+ self .autopilot_id = - 100
63+ self .mission_stale = False
64+ self .mission_stale_warn_time = 0
65+ self .expected_opaque_id = None
66+
67+ def set_autopilot_id (self , value ):
68+ self .autopilot_id = value
69+
70+ def set_have_id (self , value ):
71+ self .have_id = value
72+
73+ def set_expected (self , value ):
74+ '''value we are expecting to have after a transfer'''
75+ self .expected_opaque_id = value
76+
77+ def transfer_complete (self ):
78+ self .have_id = self .expected_opaque_id
79+
80+ self .opaque = OpaqueInformation ()
5381
5482 if self .continue_mode and self .logdir is not None :
5583 waytxt = os .path .join (mpstate .status .logdir , self .save_filename ())
@@ -250,10 +278,7 @@ def mavlink_packet(self, m):
250278 if mtype in ['MISSION_COUNT' ]:
251279 if getattr (m , 'mission_type' , 0 ) != self .mav_mission_type ():
252280 return
253- if self .wp_op is None :
254- if self .wploader .expected_count != m .count :
255- self .console .writeln ("Mission is stale" )
256- else :
281+ if self .wp_op is not None :
257282 self .wploader .clear ()
258283 self .console .writeln ("Requesting %u %s t=%s now=%s" % (
259284 m .count ,
@@ -262,7 +287,10 @@ def mavlink_packet(self, m):
262287 time .asctime ()))
263288 self .wploader .expected_count = m .count
264289 self .send_wp_requests ()
290+ self .opaque .set_expected (getattr (m , 'opaque_id' , 0 ))
265291
292+ elif mtype in ['MISSION_CURRENT' ]:
293+ self .opaque .set_autopilot_id (getattr (m , self .MISSION_CURRENT_opaque_id_attribute (), 0 ))
266294 elif mtype in ['MISSION_ITEM' , 'MISSION_ITEM_INT' ] and self .wp_op is not None :
267295 if m .get_type () == 'MISSION_ITEM_INT' :
268296 if getattr (m , 'mission_type' , 0 ) != self .mav_mission_type ():
@@ -293,6 +321,7 @@ def mavlink_packet(self, m):
293321 self .wp_op = None
294322 self .wp_requested = {}
295323 self .wp_received = {}
324+ self .opaque .transfer_complete ()
296325
297326 elif mtype in frozenset (["MISSION_REQUEST" , "MISSION_REQUEST_INT" ]):
298327 self .process_waypoint_request (m , self .master )
@@ -309,6 +338,7 @@ def idle_task(self):
309338 self .send_wp_requests (wps )
310339
311340 self .idle_task_add_menu_items ()
341+ self .idle_task_check_opaque_id ()
312342
313343 def idle_task_add_menu_items (self ):
314344 '''check for load of other modules, add our items as required'''
@@ -331,7 +361,27 @@ def idle_task_add_menu_items(self):
331361 else :
332362 self .menu_added_map = False
333363
364+ def idle_task_check_opaque_id (self ):
365+ '''the vehicle may return an identifier for its onboard mission.
366+ Check it against what we think is on the vehicle, emit stale
367+ message if we detect a mismatch'''
368+ if self .opaque .have_id == self .opaque .autopilot_id :
369+ # reset so we work on things straight away:
370+ self .opaque .mission_stale_warn_time = 0
371+ return
372+ now = time .time ()
373+ if now - self .opaque .mission_stale_warn_time < 30 :
374+ return
375+ self .opaque .mission_stale_warn_time = now
376+ if self .mip_settings .autorefresh :
377+ self .say (f"Refreshing { self .itemstype ()} " )
378+ self .cmd_list ([])
379+ return
380+ self .opaque .mission_stale_warn_time = now
381+ self .say (f"{ self .itemstype ()} mismatch vehicle vs MAVProxy" )
382+
334383 def has_location (self , cmd_id ):
384+
335385 '''return True if a WP command has a location'''
336386 if cmd_id in mavutil .mavlink .enums ['MAV_CMD' ].keys ():
337387 cmd_enum = mavutil .mavlink .enums ['MAV_CMD' ][cmd_id ]
@@ -899,12 +949,16 @@ def commands(self):
899949 "savelocal" : self .cmd_savelocal ,
900950 "show" : (self .cmd_show , ["(FILENAME)" ]),
901951 "status" : self .cmd_status ,
952+ "setting" : self .setting ,
902953 }
903954
904955 def usage (self ):
905956 subcommands = "|" .join (sorted (self .commands ().keys ()))
906957 return "usage: %s <%s>" % (self .command_name (), subcommands )
907958
959+ def setting (self , args ):
960+ self .settings .command (args [1 :])
961+
908962 def cmd_wp (self , args ):
909963 '''waypoint commands'''
910964 if len (args ) < 1 :
0 commit comments