diff --git a/DFReader.py b/DFReader.py index 5b629276d..b25c1089d 100644 --- a/DFReader.py +++ b/DFReader.py @@ -560,15 +560,15 @@ class DFMetaData(object): def __init__(self, parent): self.parent = parent self.data = None - self.tried = False + self.metadata_load_attempted = False def reset(self): '''clear cached data''' self.data = None - self.tried = False + self.metadata_load_attempted = False # Copy of function in mp_util, to avoid dependency on MavProxy - def dot_mavproxy(self,name=None): + def dot_mavproxy(self, name=None): '''return a path to store mavproxy data''' if 'HOME' not in os.environ: dir = os.path.join(os.environ['LOCALAPPDATA'], '.mavproxy') @@ -578,34 +578,33 @@ def dot_mavproxy(self,name=None): return dir return os.path.join(dir, name) - def metadata_tree(self,verbose=False): - '''return a map between a log message and its metadata. May return None if data is not available''' + def metadata_tree(self, verbose=False): + ''' return a map between a log message and its metadata. May return + None if data is not available ''' # If we've already tried loading data, use it if we have it # This avoid repeated attempts, when the file is not there if self.metadata_load_attempted: return self.data - self.tried = True + self.metadata_load_attempted = True # Get file name, based on vehicle type - mapping = { mavutil.mavlink.MAV_TYPE_GROUND_ROVER : "Rover", - mavutil.mavlink.MAV_TYPE_FIXED_WING : "Plane", - mavutil.mavlink.MAV_TYPE_QUADROTOR : "Copter", - mavutil.mavlink.MAV_TYPE_HELICOPTER : "Copter", - mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER : "Tracker", - mavutil.mavlink.MAV_TYPE_SUBMARINE : "Sub", - mavutil.mavlink.MAV_TYPE_AIRSHIP : "Blimp", - } + mapping = {mavutil.mavlink.MAV_TYPE_GROUND_ROVER : "Rover", + mavutil.mavlink.MAV_TYPE_FIXED_WING : "Plane", + mavutil.mavlink.MAV_TYPE_QUADROTOR : "Copter", + mavutil.mavlink.MAV_TYPE_HELICOPTER : "Copter", + mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER : "Tracker", + mavutil.mavlink.MAV_TYPE_SUBMARINE : "Sub", + mavutil.mavlink.MAV_TYPE_AIRSHIP : "Blimp", + } if self.parent.mav_type not in mapping: return None - path = self.dot_mavproxy(os.path.join("LogMessages","%s.xml" % mapping[self.parent.mav_type])) - else: - return None + path = self.dot_mavproxy(os.path.join("LogMessages", "%s.xml" % mapping[self.parent.mav_type])) # Does the file exist? if not os.path.exists(path): if verbose: print("Can't find '%s'\nPlease run 'logmessage download' first" % path) return None # Read in the XML - xml = open(path,'rb').read() + xml = open(path, 'rb').read() from lxml import objectify objectify.enable_recursive_str() tree = objectify.fromstring(xml) @@ -617,33 +616,36 @@ def metadata_tree(self,verbose=False): self.data = data return self.data - def print_help(self,msg): + def print_help(self, msg): '''print help for a log message''' data = self.metadata_tree(verbose=True) - if data is None or msg not in data: + if data is None: + return + if msg not in data: + print("No help found for message: %s" % msg) return node = data[msg] # Message name and description - print("Log Message: %s\n%s\n" % (msg,node.description.text)) + print("Log Message: %s\n%s\n" % (msg, node.description.text)) # Protect against replay messages which dont list their fields - if not hasattr(node.fields,'field'): + if not hasattr(node.fields, 'field'): return - # Loop through fields - for f in node.fields.field: - units = f.get('units') - dtype = f.get('type') - addstr = '' - if units: - addstr = "[%s] " % units - elif 'char' in dtype: - addstr = "[%s] " % dtype - elif hasattr(f,'enum'): - addstr = "[enum] " - elif hasattr(f,'bitmask'): - addstr = "[bitmask] " - print("%s %s: %s" % (f.get('name'),addstr,f.description.text)) - - def get_description(self,msg): + # Loop through fields + for f in node.fields.field: + units = f.get('units') + dtype = f.get('type') + addstr = '' + if units: + addstr = "[%s] " % units + elif 'char' in dtype: + addstr = "[%s] " % dtype + elif hasattr(f, 'enum'): + addstr = "[enum] " + elif hasattr(f, 'bitmask'): + addstr = "[bitmask] " + print("%s %s: %s" % (f.get('name'), addstr, f.description.text)) + + def get_description(self, msg): '''get the description of a log message''' data = self.metadata_tree() if data is None: