Beispiel #1
0
 def param_help_tree(self):
     '''return a "help tree", a map between a parameter and its metadata.  May return None if help is not available'''
     if self.xml_filepath is not None:
         print("param: using xml_filepath=%s" % self.xml_filepath)
         path = self.xml_filepath
     else:
         if self.vehicle_name is None:
             print("Unknown vehicle type")
             return None
         path = mp_util.dot_mavproxy("%s.xml" % self.vehicle_name)
         if not os.path.exists(path):
             print("Please run 'param download' first (vehicle_name=%s)" % self.vehicle_name)
             return None
     if not os.path.exists(path):
         print("Param XML (%s) does not exist" % path)
         return None
     xml = open(path,'rb').read()
     from lxml import objectify
     objectify.enable_recursive_str()
     tree = objectify.fromstring(xml)
     htree = {}
     for p in tree.vehicles.parameters.param:
         n = p.get('name').split(':')[1]
         htree[n] = p
     for lib in tree.libraries.parameters:
         for p in lib.param:
             n = p.get('name')
             htree[n] = p
     return htree
Beispiel #2
0
 def param_help_download(self):
     '''download XML files for parameters'''
     files = []
     for vehicle in ['Rover', 'ArduCopter', 'ArduPlane', 'ArduSub', 'AntennaTracker']:
         url = 'http://autotest.ardupilot.org/Parameters/%s/apm.pdef.xml.gz' % vehicle
         path = mp_util.dot_mavproxy("%s.xml" % vehicle)
         files.append((url, path))
         url = 'http://autotest.ardupilot.org/%s-defaults.parm' % vehicle
         if vehicle != 'AntennaTracker':
             # defaults not generated for AntennaTracker ATM
             path = mp_util.dot_mavproxy("%s-defaults.parm" % vehicle)
             files.append((url, path))
     try:
         child = multiproc.Process(target=mp_util.download_files, args=(files,))
         child.start()
     except Exception as e:
         print(e)
Beispiel #3
0
    def find_manifests(self):
        '''locate manifests and return filepaths thereof'''
        manifest_dir = mp_util.dot_mavproxy()

        ret = []
        for file in os.listdir(manifest_dir):
            try:
                file.index("manifest")
                ret.append(os.path.join(manifest_dir,file))
            except ValueError:
                pass
        return ret
Beispiel #4
0
    def __init__(self, mpstate):
        super(HelpModule, self).__init__(mpstate, "mavhelp", "Help and version information", public = True)
        self.enabled = False
        self.add_command('mavhelp', self.cmd_help, "help and version information", "<about|site>")
        self.have_list = False

        #versioning info
        #pkg_resources doesn't work in the windows exe build, so read the version file
        try:
            import pkg_resources
            self.version = pkg_resources.Environment()["mavproxy"][0].version
        except:
            start_script = mp_util.dot_mavproxy("version.txt")
            f = open(start_script, 'r')
            self.version = f.readline()
        self.host = platform.system() + platform.release()
        self.pythonversion = str(platform.python_version())
        if mp_util.has_wxpython:
            self.wxVersion = str(wx.__version__)
        else:
            self.wxVersion = ''

        #check for updates, if able
        pypi = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')
        available = None
        try:
            available = pypi.package_releases(')
        except socket.gaierror:
            pass
            
        if available:
            self.newversion = available[0]
        else:
            self.newversion = 'Error finding update'
            
        #and format the update string
        if not isinstance(self.newversion, basestring):
            self.newversion = "Error finding update"
        elif re.search('[a-zA-Z]', self.newversion):
            self.newversion = "Error finding update: " + self.newversion
        elif self.newversion.strip() == self.version.strip():
            self.newversion = "Running latest version"
        else:
            self.newversion = "New version " + self.newversion + " available (currently running " + self.version + ")"

        if mp_util.has_wxpython:
            self.menu_added_console = False
            self.menu = MPMenuSubMenu('Help',
                                  items=[MPMenuItem('website', 'website', '', handler=MPMenuOpenWeblink('https://ardupilot.org/mavproxy/index.html')),
                                         MPMenuItem('Check for Updates', 'Check for Updates', '', handler=MPMenuChildMessageDialog(title="Updates", message=self.newversion)),
                                         MPMenuItem('About', 'About', '', handler=MPMenuChildMessageDialog(title="About , message=self.about_string()))])
Beispiel #5
0
    def manifest_download(self):
        '''download manifest files'''
        if self.downloaders_lock.acquire(False):
            if len(self.downloaders):
                # there already exist downloader threads
                self.downloaders_lock.release()
                return

            for url in ['https://firmware.ardupilot.org/manifest.json']:
                filename = self.make_safe_filename_from_url(url)
                path = mp_util.dot_mavproxy("manifest-%s" % filename)
                self.downloaders[url] = threading.Thread(target=self.download_url, args=(url, path))
                self.downloaders[url].start()
            self.downloaders_lock.release()
        else:
            print("fw: Failed to acquire download lock")
Beispiel #6
0
    def handle_command(self, master, mpstate, args):
        '''handle parameter commands'''
        param_wildcard = "*"
        usage="Usage: param <fetch|ftp|save|set|show|load|preload|forceload|diff|download|check|help>"
        if len(args) < 1:
            print(usage)
            return
        if args[0] == "fetch":
            if len(args) == 1:
                self.fetch_all(master)
                if self.ftp_started:
                    print("Requested parameter list (ftp)")
                else:
                    print("Requested parameter list")
            else:
                found = False
                pname = args[1].upper()
                for p in self.mav_param.keys():
                    if fnmatch.fnmatch(p, pname):
                        master.param_fetch_one(p)
                        if p not in self.fetch_one:
                            self.fetch_one[p] = 0
                        self.fetch_one[p] += 1
                        found = True
                        print("Requested parameter %s" % p)
                if not found and args[1].find('*') == -1:
                    master.param_fetch_one(pname)
                    if pname not in self.fetch_one:
                        self.fetch_one[pname] = 0
                    self.fetch_one[pname] += 1
                    print("Requested parameter %s" % pname)
        elif args[0] == "ftp":
            self.ftp_start()

        elif args[0] == "save":
            if len(args) < 2:
                print("usage: param save <filename> [wildcard]")
                return
            if len(args) > 2:
                param_wildcard = args[2]
            else:
                param_wildcard = "*"
            self.mav_param.save(args[1].strip('"'), param_wildcard, verbose=True)
        elif args[0] == "diff":
            wildcard = '*'
            if len(args) < 2 or args[1].find('*') != -1:
                if self.vehicle_name is None:
                    print("Unknown vehicle type")
                    return
                filename = mp_util.dot_mavproxy("%s-defaults.parm" % self.vehicle_name)
                if not os.path.exists(filename):
                    print("Please run 'param download' first (vehicle_name=%s)" % self.vehicle_name)
                    return
                if len(args) >= 2:
                    wildcard = args[1]
            else:
                filename = args[1]
                if len(args) == 3:
                    wildcard = args[2]
            print("%-16.16s %12.12s %12.12s" % ('Parameter', 'Defaults', 'Current'))
            self.mav_param.diff(filename, wildcard=wildcard)
        elif args[0] == "set":
            if len(args) < 2:
                print("Usage: param set PARMNAME VALUE")
                return
            if len(args) == 2:
                self.mav_param.show(args[1])
                return
            param = args[1]
            value = args[2]
            if value.startswith('0x'):
                value = int(value, base=16)
            if not param.upper() in self.mav_param:
                print("Unable to find parameter '%s'" % param)
                return
            uname = param.upper()
            ptype = None
            if uname in self.param_types:
                ptype = self.param_types[uname]
            self.mav_param.mavset(master, uname, value, retries=3, parm_type=ptype)

            if (param.upper() == "WP_LOITER_RAD" or param.upper() == "LAND_BREAK_PATH"):
                #need to redraw rally points
                mpstate.module('rally').set_last_change(time.time())
                #need to redraw loiter points
                mpstate.module('wp').wploader.last_change = time.time()

        elif args[0] == "load":
            if len(args) < 2:
                print("Usage: param load <filename> [wildcard]")
                return
            if len(args) > 2:
                param_wildcard = args[2]
            else:
                param_wildcard = "*"
            self.mav_param.load(args[1].strip('"'), param_wildcard, master)
        elif args[0] == "preload":
            if len(args) < 2:
                print("Usage: param preload <filename>")
                return
            self.mav_param.load(args[1].strip('"'))
        elif args[0] == "forceload":
            if len(args) < 2:
                print("Usage: param forceload <filename> [wildcard]")
                return
            if len(args) > 2:
                param_wildcard = args[2]
            else:
                param_wildcard = "*"
            self.mav_param.load(args[1].strip('"'), param_wildcard, master, check=False)
        elif args[0] == "download":
            self.param_help_download()
        elif args[0] == "apropos":
            self.param_apropos(args[1:])
        elif args[0] == "check":
            self.param_check(args[1:])
        elif args[0] == "help":
            self.param_help(args[1:])
        elif args[0] == "set_xml_filepath":
            self.param_set_xml_filepath(args[1:])
        elif args[0] == "show":
            if len(args) > 1:
                pattern = args[1]
            else:
                pattern = "*"
            self.mav_param.show(pattern)
        elif args[0] == "status":
            print("Have %u/%u params" % (len(self.mav_param_set), self.mav_param_count))
        else:
            print(usage)