id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
235,500
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/mp_tile.py
MPTile.downloader
def downloader(self): '''the download thread''' while self.tiles_pending() > 0: time.sleep(self.tile_delay) keys = sorted(self._download_pending.keys()) # work out which one to download next, choosing by request_time tile_info = self._download_pending[keys[0]] for key in keys: if self._download_pending[key].request_time > tile_info.request_time: tile_info = self._download_pending[key] url = tile_info.url(self.service) path = self.tile_to_path(tile_info) key = tile_info.key() try: if self.debug: print("Downloading %s [%u left]" % (url, len(keys))) req = url_request(url) if url.find('google') != -1: req.add_header('Referer', 'https://maps.google.com/') resp = url_open(req) headers = resp.info() except url_error as e: #print('Error loading %s' % url) if not key in self._tile_cache: self._tile_cache[key] = self._unavailable self._download_pending.pop(key) if self.debug: print("Failed %s: %s" % (url, str(e))) continue if 'content-type' not in headers or headers['content-type'].find('image') == -1: if not key in self._tile_cache: self._tile_cache[key] = self._unavailable self._download_pending.pop(key) if self.debug: print("non-image response %s" % url) continue else: img = resp.read() # see if its a blank/unavailable tile md5 = hashlib.md5(img).hexdigest() if md5 in BLANK_TILES: if self.debug: print("blank tile %s" % url) if not key in self._tile_cache: self._tile_cache[key] = self._unavailable self._download_pending.pop(key) continue mp_util.mkdir_p(os.path.dirname(path)) h = open(path+'.tmp','wb') h.write(img) h.close() try: os.unlink(path) except Exception: pass os.rename(path+'.tmp', path) self._download_pending.pop(key) self._download_thread = None
python
def downloader(self): '''the download thread''' while self.tiles_pending() > 0: time.sleep(self.tile_delay) keys = sorted(self._download_pending.keys()) # work out which one to download next, choosing by request_time tile_info = self._download_pending[keys[0]] for key in keys: if self._download_pending[key].request_time > tile_info.request_time: tile_info = self._download_pending[key] url = tile_info.url(self.service) path = self.tile_to_path(tile_info) key = tile_info.key() try: if self.debug: print("Downloading %s [%u left]" % (url, len(keys))) req = url_request(url) if url.find('google') != -1: req.add_header('Referer', 'https://maps.google.com/') resp = url_open(req) headers = resp.info() except url_error as e: #print('Error loading %s' % url) if not key in self._tile_cache: self._tile_cache[key] = self._unavailable self._download_pending.pop(key) if self.debug: print("Failed %s: %s" % (url, str(e))) continue if 'content-type' not in headers or headers['content-type'].find('image') == -1: if not key in self._tile_cache: self._tile_cache[key] = self._unavailable self._download_pending.pop(key) if self.debug: print("non-image response %s" % url) continue else: img = resp.read() # see if its a blank/unavailable tile md5 = hashlib.md5(img).hexdigest() if md5 in BLANK_TILES: if self.debug: print("blank tile %s" % url) if not key in self._tile_cache: self._tile_cache[key] = self._unavailable self._download_pending.pop(key) continue mp_util.mkdir_p(os.path.dirname(path)) h = open(path+'.tmp','wb') h.write(img) h.close() try: os.unlink(path) except Exception: pass os.rename(path+'.tmp', path) self._download_pending.pop(key) self._download_thread = None
[ "def", "downloader", "(", "self", ")", ":", "while", "self", ".", "tiles_pending", "(", ")", ">", "0", ":", "time", ".", "sleep", "(", "self", ".", "tile_delay", ")", "keys", "=", "sorted", "(", "self", ".", "_download_pending", ".", "keys", "(", ")", ")", "# work out which one to download next, choosing by request_time", "tile_info", "=", "self", ".", "_download_pending", "[", "keys", "[", "0", "]", "]", "for", "key", "in", "keys", ":", "if", "self", ".", "_download_pending", "[", "key", "]", ".", "request_time", ">", "tile_info", ".", "request_time", ":", "tile_info", "=", "self", ".", "_download_pending", "[", "key", "]", "url", "=", "tile_info", ".", "url", "(", "self", ".", "service", ")", "path", "=", "self", ".", "tile_to_path", "(", "tile_info", ")", "key", "=", "tile_info", ".", "key", "(", ")", "try", ":", "if", "self", ".", "debug", ":", "print", "(", "\"Downloading %s [%u left]\"", "%", "(", "url", ",", "len", "(", "keys", ")", ")", ")", "req", "=", "url_request", "(", "url", ")", "if", "url", ".", "find", "(", "'google'", ")", "!=", "-", "1", ":", "req", ".", "add_header", "(", "'Referer'", ",", "'https://maps.google.com/'", ")", "resp", "=", "url_open", "(", "req", ")", "headers", "=", "resp", ".", "info", "(", ")", "except", "url_error", "as", "e", ":", "#print('Error loading %s' % url)", "if", "not", "key", "in", "self", ".", "_tile_cache", ":", "self", ".", "_tile_cache", "[", "key", "]", "=", "self", ".", "_unavailable", "self", ".", "_download_pending", ".", "pop", "(", "key", ")", "if", "self", ".", "debug", ":", "print", "(", "\"Failed %s: %s\"", "%", "(", "url", ",", "str", "(", "e", ")", ")", ")", "continue", "if", "'content-type'", "not", "in", "headers", "or", "headers", "[", "'content-type'", "]", ".", "find", "(", "'image'", ")", "==", "-", "1", ":", "if", "not", "key", "in", "self", ".", "_tile_cache", ":", "self", ".", "_tile_cache", "[", "key", "]", "=", "self", ".", "_unavailable", "self", ".", "_download_pending", ".", "pop", "(", "key", ")", "if", "self", ".", "debug", ":", "print", "(", "\"non-image response %s\"", "%", "url", ")", "continue", "else", ":", "img", "=", "resp", ".", "read", "(", ")", "# see if its a blank/unavailable tile", "md5", "=", "hashlib", ".", "md5", "(", "img", ")", ".", "hexdigest", "(", ")", "if", "md5", "in", "BLANK_TILES", ":", "if", "self", ".", "debug", ":", "print", "(", "\"blank tile %s\"", "%", "url", ")", "if", "not", "key", "in", "self", ".", "_tile_cache", ":", "self", ".", "_tile_cache", "[", "key", "]", "=", "self", ".", "_unavailable", "self", ".", "_download_pending", ".", "pop", "(", "key", ")", "continue", "mp_util", ".", "mkdir_p", "(", "os", ".", "path", ".", "dirname", "(", "path", ")", ")", "h", "=", "open", "(", "path", "+", "'.tmp'", ",", "'wb'", ")", "h", ".", "write", "(", "img", ")", "h", ".", "close", "(", ")", "try", ":", "os", ".", "unlink", "(", "path", ")", "except", "Exception", ":", "pass", "os", ".", "rename", "(", "path", "+", "'.tmp'", ",", "path", ")", "self", ".", "_download_pending", ".", "pop", "(", "key", ")", "self", ".", "_download_thread", "=", "None" ]
the download thread
[ "the", "download", "thread" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_tile.py#L250-L313
235,501
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.cmd_fw
def cmd_fw(self, args): '''execute command defined in args''' if len(args) == 0: print(self.usage()) return rest = args[1:] if args[0] == "manifest": self.cmd_fw_manifest(rest) elif args[0] == "list": self.cmd_fw_list(rest) elif args[0] == "download": self.cmd_fw_download(rest) elif args[0] in ["help","usage"]: self.cmd_fw_help(rest) else: print(self.usage())
python
def cmd_fw(self, args): '''execute command defined in args''' if len(args) == 0: print(self.usage()) return rest = args[1:] if args[0] == "manifest": self.cmd_fw_manifest(rest) elif args[0] == "list": self.cmd_fw_list(rest) elif args[0] == "download": self.cmd_fw_download(rest) elif args[0] in ["help","usage"]: self.cmd_fw_help(rest) else: print(self.usage())
[ "def", "cmd_fw", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "==", "0", ":", "print", "(", "self", ".", "usage", "(", ")", ")", "return", "rest", "=", "args", "[", "1", ":", "]", "if", "args", "[", "0", "]", "==", "\"manifest\"", ":", "self", ".", "cmd_fw_manifest", "(", "rest", ")", "elif", "args", "[", "0", "]", "==", "\"list\"", ":", "self", ".", "cmd_fw_list", "(", "rest", ")", "elif", "args", "[", "0", "]", "==", "\"download\"", ":", "self", ".", "cmd_fw_download", "(", "rest", ")", "elif", "args", "[", "0", "]", "in", "[", "\"help\"", ",", "\"usage\"", "]", ":", "self", ".", "cmd_fw_help", "(", "rest", ")", "else", ":", "print", "(", "self", ".", "usage", "(", ")", ")" ]
execute command defined in args
[ "execute", "command", "defined", "in", "args" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L47-L62
235,502
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.frame_from_firmware
def frame_from_firmware(self, firmware): '''extract information from firmware, return pretty string to user''' # see Tools/scripts/generate-manifest for this map: frame_to_mavlink_dict = { "quad": "QUADROTOR", "hexa": "HEXAROTOR", "y6": "ARDUPILOT_Y6", "tri": "TRICOPTER", "octa": "OCTOROTOR", "octa-quad": "ARDUPILOT_OCTAQUAD", "heli": "HELICOPTER", "Plane": "FIXED_WING", "Tracker": "ANTENNA_TRACKER", "Rover": "GROUND_ROVER", "PX4IO": "ARDUPILOT_PX4IO", } mavlink_to_frame_dict = { v : k for k,v in frame_to_mavlink_dict.items() } x = firmware["mav-type"] if firmware["mav-autopilot"] != "ARDUPILOTMEGA": return x if x in mavlink_to_frame_dict: return mavlink_to_frame_dict[x] return x
python
def frame_from_firmware(self, firmware): '''extract information from firmware, return pretty string to user''' # see Tools/scripts/generate-manifest for this map: frame_to_mavlink_dict = { "quad": "QUADROTOR", "hexa": "HEXAROTOR", "y6": "ARDUPILOT_Y6", "tri": "TRICOPTER", "octa": "OCTOROTOR", "octa-quad": "ARDUPILOT_OCTAQUAD", "heli": "HELICOPTER", "Plane": "FIXED_WING", "Tracker": "ANTENNA_TRACKER", "Rover": "GROUND_ROVER", "PX4IO": "ARDUPILOT_PX4IO", } mavlink_to_frame_dict = { v : k for k,v in frame_to_mavlink_dict.items() } x = firmware["mav-type"] if firmware["mav-autopilot"] != "ARDUPILOTMEGA": return x if x in mavlink_to_frame_dict: return mavlink_to_frame_dict[x] return x
[ "def", "frame_from_firmware", "(", "self", ",", "firmware", ")", ":", "# see Tools/scripts/generate-manifest for this map:", "frame_to_mavlink_dict", "=", "{", "\"quad\"", ":", "\"QUADROTOR\"", ",", "\"hexa\"", ":", "\"HEXAROTOR\"", ",", "\"y6\"", ":", "\"ARDUPILOT_Y6\"", ",", "\"tri\"", ":", "\"TRICOPTER\"", ",", "\"octa\"", ":", "\"OCTOROTOR\"", ",", "\"octa-quad\"", ":", "\"ARDUPILOT_OCTAQUAD\"", ",", "\"heli\"", ":", "\"HELICOPTER\"", ",", "\"Plane\"", ":", "\"FIXED_WING\"", ",", "\"Tracker\"", ":", "\"ANTENNA_TRACKER\"", ",", "\"Rover\"", ":", "\"GROUND_ROVER\"", ",", "\"PX4IO\"", ":", "\"ARDUPILOT_PX4IO\"", ",", "}", "mavlink_to_frame_dict", "=", "{", "v", ":", "k", "for", "k", ",", "v", "in", "frame_to_mavlink_dict", ".", "items", "(", ")", "}", "x", "=", "firmware", "[", "\"mav-type\"", "]", "if", "firmware", "[", "\"mav-autopilot\"", "]", "!=", "\"ARDUPILOTMEGA\"", ":", "return", "x", "if", "x", "in", "mavlink_to_frame_dict", ":", "return", "mavlink_to_frame_dict", "[", "x", "]", "return", "x" ]
extract information from firmware, return pretty string to user
[ "extract", "information", "from", "firmware", "return", "pretty", "string", "to", "user" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L64-L87
235,503
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.row_is_filtered
def row_is_filtered(self, row_subs, filters): '''returns True if row should NOT be included according to filters''' for filtername in filters: filtervalue = filters[filtername] if filtername in row_subs: row_subs_value = row_subs[filtername] if str(row_subs_value) != str(filtervalue): return True else: print("fw: Unknown filter keyword (%s)" % (filtername,)) return False
python
def row_is_filtered(self, row_subs, filters): '''returns True if row should NOT be included according to filters''' for filtername in filters: filtervalue = filters[filtername] if filtername in row_subs: row_subs_value = row_subs[filtername] if str(row_subs_value) != str(filtervalue): return True else: print("fw: Unknown filter keyword (%s)" % (filtername,)) return False
[ "def", "row_is_filtered", "(", "self", ",", "row_subs", ",", "filters", ")", ":", "for", "filtername", "in", "filters", ":", "filtervalue", "=", "filters", "[", "filtername", "]", "if", "filtername", "in", "row_subs", ":", "row_subs_value", "=", "row_subs", "[", "filtername", "]", "if", "str", "(", "row_subs_value", ")", "!=", "str", "(", "filtervalue", ")", ":", "return", "True", "else", ":", "print", "(", "\"fw: Unknown filter keyword (%s)\"", "%", "(", "filtername", ",", ")", ")", "return", "False" ]
returns True if row should NOT be included according to filters
[ "returns", "True", "if", "row", "should", "NOT", "be", "included", "according", "to", "filters" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L98-L108
235,504
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.filters_from_args
def filters_from_args(self, args): '''take any argument of the form name=value anmd put it into a dict; return that and the remaining arguments''' filters = dict() remainder = [] for arg in args: try: equals = arg.index('=') # anything ofthe form key-value is taken as a filter filters[arg[0:equals]] = arg[equals+1:]; except ValueError: remainder.append(arg) return (filters,remainder)
python
def filters_from_args(self, args): '''take any argument of the form name=value anmd put it into a dict; return that and the remaining arguments''' filters = dict() remainder = [] for arg in args: try: equals = arg.index('=') # anything ofthe form key-value is taken as a filter filters[arg[0:equals]] = arg[equals+1:]; except ValueError: remainder.append(arg) return (filters,remainder)
[ "def", "filters_from_args", "(", "self", ",", "args", ")", ":", "filters", "=", "dict", "(", ")", "remainder", "=", "[", "]", "for", "arg", "in", "args", ":", "try", ":", "equals", "=", "arg", ".", "index", "(", "'='", ")", "# anything ofthe form key-value is taken as a filter", "filters", "[", "arg", "[", "0", ":", "equals", "]", "]", "=", "arg", "[", "equals", "+", "1", ":", "]", "except", "ValueError", ":", "remainder", ".", "append", "(", "arg", ")", "return", "(", "filters", ",", "remainder", ")" ]
take any argument of the form name=value anmd put it into a dict; return that and the remaining arguments
[ "take", "any", "argument", "of", "the", "form", "name", "=", "value", "anmd", "put", "it", "into", "a", "dict", ";", "return", "that", "and", "the", "remaining", "arguments" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L110-L121
235,505
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.all_firmwares
def all_firmwares(self): ''' return firmware entries from all manifests''' all = [] for manifest in self.manifests: for firmware in manifest["firmware"]: all.append(firmware) return all
python
def all_firmwares(self): ''' return firmware entries from all manifests''' all = [] for manifest in self.manifests: for firmware in manifest["firmware"]: all.append(firmware) return all
[ "def", "all_firmwares", "(", "self", ")", ":", "all", "=", "[", "]", "for", "manifest", "in", "self", ".", "manifests", ":", "for", "firmware", "in", "manifest", "[", "\"firmware\"", "]", ":", "all", ".", "append", "(", "firmware", ")", "return", "all" ]
return firmware entries from all manifests
[ "return", "firmware", "entries", "from", "all", "manifests" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L123-L129
235,506
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.rows_for_firmwares
def rows_for_firmwares(self, firmwares): '''provide user-readable text for a firmware entry''' rows = [] i = 0 for firmware in firmwares: frame = self.frame_from_firmware(firmware) row = { "seq": i, "platform": firmware["platform"], "frame": frame, # "type": firmware["mav-type"], "releasetype": firmware["mav-firmware-version-type"], "latest": firmware["latest"], "git-sha": firmware["git-sha"][0:7], "format": firmware["format"], "_firmware": firmware, } (major,minor,patch) = self.semver_from_firmware(firmware) if major is None: row["version"] = "" row["major"] = "" row["minor"] = "" row["patch"] = "" else: row["version"] = firmware["mav-firmware-version"] row["major"] = major row["minor"] = minor row["patch"] = patch i += 1 rows.append(row) return rows
python
def rows_for_firmwares(self, firmwares): '''provide user-readable text for a firmware entry''' rows = [] i = 0 for firmware in firmwares: frame = self.frame_from_firmware(firmware) row = { "seq": i, "platform": firmware["platform"], "frame": frame, # "type": firmware["mav-type"], "releasetype": firmware["mav-firmware-version-type"], "latest": firmware["latest"], "git-sha": firmware["git-sha"][0:7], "format": firmware["format"], "_firmware": firmware, } (major,minor,patch) = self.semver_from_firmware(firmware) if major is None: row["version"] = "" row["major"] = "" row["minor"] = "" row["patch"] = "" else: row["version"] = firmware["mav-firmware-version"] row["major"] = major row["minor"] = minor row["patch"] = patch i += 1 rows.append(row) return rows
[ "def", "rows_for_firmwares", "(", "self", ",", "firmwares", ")", ":", "rows", "=", "[", "]", "i", "=", "0", "for", "firmware", "in", "firmwares", ":", "frame", "=", "self", ".", "frame_from_firmware", "(", "firmware", ")", "row", "=", "{", "\"seq\"", ":", "i", ",", "\"platform\"", ":", "firmware", "[", "\"platform\"", "]", ",", "\"frame\"", ":", "frame", ",", "# \"type\": firmware[\"mav-type\"],", "\"releasetype\"", ":", "firmware", "[", "\"mav-firmware-version-type\"", "]", ",", "\"latest\"", ":", "firmware", "[", "\"latest\"", "]", ",", "\"git-sha\"", ":", "firmware", "[", "\"git-sha\"", "]", "[", "0", ":", "7", "]", ",", "\"format\"", ":", "firmware", "[", "\"format\"", "]", ",", "\"_firmware\"", ":", "firmware", ",", "}", "(", "major", ",", "minor", ",", "patch", ")", "=", "self", ".", "semver_from_firmware", "(", "firmware", ")", "if", "major", "is", "None", ":", "row", "[", "\"version\"", "]", "=", "\"\"", "row", "[", "\"major\"", "]", "=", "\"\"", "row", "[", "\"minor\"", "]", "=", "\"\"", "row", "[", "\"patch\"", "]", "=", "\"\"", "else", ":", "row", "[", "\"version\"", "]", "=", "firmware", "[", "\"mav-firmware-version\"", "]", "row", "[", "\"major\"", "]", "=", "major", "row", "[", "\"minor\"", "]", "=", "minor", "row", "[", "\"patch\"", "]", "=", "patch", "i", "+=", "1", "rows", ".", "append", "(", "row", ")", "return", "rows" ]
provide user-readable text for a firmware entry
[ "provide", "user", "-", "readable", "text", "for", "a", "firmware", "entry" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L131-L163
235,507
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.filter_rows
def filter_rows(self, filters, rows): '''returns rows as filtered by filters''' ret = [] for row in rows: if not self.row_is_filtered(row, filters): ret.append(row) return ret
python
def filter_rows(self, filters, rows): '''returns rows as filtered by filters''' ret = [] for row in rows: if not self.row_is_filtered(row, filters): ret.append(row) return ret
[ "def", "filter_rows", "(", "self", ",", "filters", ",", "rows", ")", ":", "ret", "=", "[", "]", "for", "row", "in", "rows", ":", "if", "not", "self", ".", "row_is_filtered", "(", "row", ",", "filters", ")", ":", "ret", ".", "append", "(", "row", ")", "return", "ret" ]
returns rows as filtered by filters
[ "returns", "rows", "as", "filtered", "by", "filters" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L165-L171
235,508
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.filtered_rows_from_args
def filtered_rows_from_args(self, args): '''extracts filters from args, rows from manifests, returns filtered rows''' if len(self.manifests) == 0: print("fw: No manifests downloaded. Try 'manifest download'") return None (filters,remainder) = self.filters_from_args(args) all = self.all_firmwares() rows = self.rows_for_firmwares(all) filtered = self.filter_rows(filters, rows) return (filtered, remainder)
python
def filtered_rows_from_args(self, args): '''extracts filters from args, rows from manifests, returns filtered rows''' if len(self.manifests) == 0: print("fw: No manifests downloaded. Try 'manifest download'") return None (filters,remainder) = self.filters_from_args(args) all = self.all_firmwares() rows = self.rows_for_firmwares(all) filtered = self.filter_rows(filters, rows) return (filtered, remainder)
[ "def", "filtered_rows_from_args", "(", "self", ",", "args", ")", ":", "if", "len", "(", "self", ".", "manifests", ")", "==", "0", ":", "print", "(", "\"fw: No manifests downloaded. Try 'manifest download'\"", ")", "return", "None", "(", "filters", ",", "remainder", ")", "=", "self", ".", "filters_from_args", "(", "args", ")", "all", "=", "self", ".", "all_firmwares", "(", ")", "rows", "=", "self", ".", "rows_for_firmwares", "(", "all", ")", "filtered", "=", "self", ".", "filter_rows", "(", "filters", ",", "rows", ")", "return", "(", "filtered", ",", "remainder", ")" ]
extracts filters from args, rows from manifests, returns filtered rows
[ "extracts", "filters", "from", "args", "rows", "from", "manifests", "returns", "filtered", "rows" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L173-L183
235,509
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.cmd_fw_list
def cmd_fw_list(self, args): '''cmd handler for list''' stuff = self.filtered_rows_from_args(args) if stuff is None: return (filtered, remainder) = stuff print("") print(" seq platform frame major.minor.patch releasetype latest git-sha format") for row in filtered: print("{seq:>5} {platform:<13} {frame:<10} {version:<10} {releasetype:<9} {latest:<6} {git-sha} {format}".format(**row))
python
def cmd_fw_list(self, args): '''cmd handler for list''' stuff = self.filtered_rows_from_args(args) if stuff is None: return (filtered, remainder) = stuff print("") print(" seq platform frame major.minor.patch releasetype latest git-sha format") for row in filtered: print("{seq:>5} {platform:<13} {frame:<10} {version:<10} {releasetype:<9} {latest:<6} {git-sha} {format}".format(**row))
[ "def", "cmd_fw_list", "(", "self", ",", "args", ")", ":", "stuff", "=", "self", ".", "filtered_rows_from_args", "(", "args", ")", "if", "stuff", "is", "None", ":", "return", "(", "filtered", ",", "remainder", ")", "=", "stuff", "print", "(", "\"\"", ")", "print", "(", "\" seq platform frame major.minor.patch releasetype latest git-sha format\"", ")", "for", "row", "in", "filtered", ":", "print", "(", "\"{seq:>5} {platform:<13} {frame:<10} {version:<10} {releasetype:<9} {latest:<6} {git-sha} {format}\"", ".", "format", "(", "*", "*", "row", ")", ")" ]
cmd handler for list
[ "cmd", "handler", "for", "list" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L185-L194
235,510
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.cmd_fw_download
def cmd_fw_download(self, args): '''cmd handler for downloading firmware''' stuff = self.filtered_rows_from_args(args) if stuff is None: return (filtered, remainder) = stuff if len(filtered) == 0: print("fw: No firmware specified") return if len(filtered) > 1: print("fw: No single firmware specified") return firmware = filtered[0]["_firmware"] url = firmware["url"] try: print("fw: URL: %s" % (url,)) filename=os.path.basename(url) files = [] files.append((url,filename)) child = multiproc.Process(target=mp_util.download_files, args=(files,)) child.start() except Exception as e: print("fw: download failed") print(e)
python
def cmd_fw_download(self, args): '''cmd handler for downloading firmware''' stuff = self.filtered_rows_from_args(args) if stuff is None: return (filtered, remainder) = stuff if len(filtered) == 0: print("fw: No firmware specified") return if len(filtered) > 1: print("fw: No single firmware specified") return firmware = filtered[0]["_firmware"] url = firmware["url"] try: print("fw: URL: %s" % (url,)) filename=os.path.basename(url) files = [] files.append((url,filename)) child = multiproc.Process(target=mp_util.download_files, args=(files,)) child.start() except Exception as e: print("fw: download failed") print(e)
[ "def", "cmd_fw_download", "(", "self", ",", "args", ")", ":", "stuff", "=", "self", ".", "filtered_rows_from_args", "(", "args", ")", "if", "stuff", "is", "None", ":", "return", "(", "filtered", ",", "remainder", ")", "=", "stuff", "if", "len", "(", "filtered", ")", "==", "0", ":", "print", "(", "\"fw: No firmware specified\"", ")", "return", "if", "len", "(", "filtered", ")", ">", "1", ":", "print", "(", "\"fw: No single firmware specified\"", ")", "return", "firmware", "=", "filtered", "[", "0", "]", "[", "\"_firmware\"", "]", "url", "=", "firmware", "[", "\"url\"", "]", "try", ":", "print", "(", "\"fw: URL: %s\"", "%", "(", "url", ",", ")", ")", "filename", "=", "os", ".", "path", ".", "basename", "(", "url", ")", "files", "=", "[", "]", "files", ".", "append", "(", "(", "url", ",", "filename", ")", ")", "child", "=", "multiproc", ".", "Process", "(", "target", "=", "mp_util", ".", "download_files", ",", "args", "=", "(", "files", ",", ")", ")", "child", ".", "start", "(", ")", "except", "Exception", "as", "e", ":", "print", "(", "\"fw: download failed\"", ")", "print", "(", "e", ")" ]
cmd handler for downloading firmware
[ "cmd", "handler", "for", "downloading", "firmware" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L196-L221
235,511
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.find_manifests
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
python
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
[ "def", "find_manifests", "(", "self", ")", ":", "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" ]
locate manifests and return filepaths thereof
[ "locate", "manifests", "and", "return", "filepaths", "thereof" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L231-L242
235,512
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.cmd_fw_manifest_purge
def cmd_fw_manifest_purge(self): '''remove all downloaded manifests''' for filepath in self.find_manifests(): os.unlink(filepath) self.manifests_parse()
python
def cmd_fw_manifest_purge(self): '''remove all downloaded manifests''' for filepath in self.find_manifests(): os.unlink(filepath) self.manifests_parse()
[ "def", "cmd_fw_manifest_purge", "(", "self", ")", ":", "for", "filepath", "in", "self", ".", "find_manifests", "(", ")", ":", "os", ".", "unlink", "(", "filepath", ")", "self", ".", "manifests_parse", "(", ")" ]
remove all downloaded manifests
[ "remove", "all", "downloaded", "manifests" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L253-L257
235,513
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.cmd_fw_manifest
def cmd_fw_manifest(self, args): '''cmd handler for manipulating manifests''' if len(args) == 0: print(self.fw_manifest_usage()) return rest = args[1:] if args[0] == "download": return self.manifest_download() if args[0] == "list": return self.cmd_fw_manifest_list() if args[0] == "load": return self.cmd_fw_manifest_load() if args[0] == "purge": return self.cmd_fw_manifest_purge() if args[0] == "help": return self.cmd_fw_manifest_help() else: print("fw: Unknown manifest option (%s)" % args[0]) print(fw_manifest_usage())
python
def cmd_fw_manifest(self, args): '''cmd handler for manipulating manifests''' if len(args) == 0: print(self.fw_manifest_usage()) return rest = args[1:] if args[0] == "download": return self.manifest_download() if args[0] == "list": return self.cmd_fw_manifest_list() if args[0] == "load": return self.cmd_fw_manifest_load() if args[0] == "purge": return self.cmd_fw_manifest_purge() if args[0] == "help": return self.cmd_fw_manifest_help() else: print("fw: Unknown manifest option (%s)" % args[0]) print(fw_manifest_usage())
[ "def", "cmd_fw_manifest", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "==", "0", ":", "print", "(", "self", ".", "fw_manifest_usage", "(", ")", ")", "return", "rest", "=", "args", "[", "1", ":", "]", "if", "args", "[", "0", "]", "==", "\"download\"", ":", "return", "self", ".", "manifest_download", "(", ")", "if", "args", "[", "0", "]", "==", "\"list\"", ":", "return", "self", ".", "cmd_fw_manifest_list", "(", ")", "if", "args", "[", "0", "]", "==", "\"load\"", ":", "return", "self", ".", "cmd_fw_manifest_load", "(", ")", "if", "args", "[", "0", "]", "==", "\"purge\"", ":", "return", "self", ".", "cmd_fw_manifest_purge", "(", ")", "if", "args", "[", "0", "]", "==", "\"help\"", ":", "return", "self", ".", "cmd_fw_manifest_help", "(", ")", "else", ":", "print", "(", "\"fw: Unknown manifest option (%s)\"", "%", "args", "[", "0", "]", ")", "print", "(", "fw_manifest_usage", "(", ")", ")" ]
cmd handler for manipulating manifests
[ "cmd", "handler", "for", "manipulating", "manifests" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L259-L277
235,514
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.manifest_parse
def manifest_parse(self, path): '''parse manifest at path, return JSON object''' print("fw: parsing manifests") content = open(path).read() return json.loads(content)
python
def manifest_parse(self, path): '''parse manifest at path, return JSON object''' print("fw: parsing manifests") content = open(path).read() return json.loads(content)
[ "def", "manifest_parse", "(", "self", ",", "path", ")", ":", "print", "(", "\"fw: parsing manifests\"", ")", "content", "=", "open", "(", "path", ")", ".", "read", "(", ")", "return", "json", ".", "loads", "(", "content", ")" ]
parse manifest at path, return JSON object
[ "parse", "manifest", "at", "path", "return", "JSON", "object" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L279-L283
235,515
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.manifest_path_is_old
def manifest_path_is_old(self, path): '''return true if path is more than a day old''' mtime = os.path.getmtime(path) return (time.time() - mtime) > 24*60*60
python
def manifest_path_is_old(self, path): '''return true if path is more than a day old''' mtime = os.path.getmtime(path) return (time.time() - mtime) > 24*60*60
[ "def", "manifest_path_is_old", "(", "self", ",", "path", ")", ":", "mtime", "=", "os", ".", "path", ".", "getmtime", "(", "path", ")", "return", "(", "time", ".", "time", "(", ")", "-", "mtime", ")", ">", "24", "*", "60", "*", "60" ]
return true if path is more than a day old
[ "return", "true", "if", "path", "is", "more", "than", "a", "day", "old" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L289-L292
235,516
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.manifests_parse
def manifests_parse(self): '''parse manifests present on system''' self.manifests = [] for manifest_path in self.find_manifests(): if self.manifest_path_is_old(manifest_path): print("fw: Manifest (%s) is old; consider 'manifest download'" % (manifest_path)) manifest = self.manifest_parse(manifest_path) if self.semver_major(manifest["format-version"]) != 1: print("fw: Manifest (%s) has major version %d; MAVProxy only understands version 1" % (manifest_path,manifest["format-version"])) continue self.manifests.append(manifest)
python
def manifests_parse(self): '''parse manifests present on system''' self.manifests = [] for manifest_path in self.find_manifests(): if self.manifest_path_is_old(manifest_path): print("fw: Manifest (%s) is old; consider 'manifest download'" % (manifest_path)) manifest = self.manifest_parse(manifest_path) if self.semver_major(manifest["format-version"]) != 1: print("fw: Manifest (%s) has major version %d; MAVProxy only understands version 1" % (manifest_path,manifest["format-version"])) continue self.manifests.append(manifest)
[ "def", "manifests_parse", "(", "self", ")", ":", "self", ".", "manifests", "=", "[", "]", "for", "manifest_path", "in", "self", ".", "find_manifests", "(", ")", ":", "if", "self", ".", "manifest_path_is_old", "(", "manifest_path", ")", ":", "print", "(", "\"fw: Manifest (%s) is old; consider 'manifest download'\"", "%", "(", "manifest_path", ")", ")", "manifest", "=", "self", ".", "manifest_parse", "(", "manifest_path", ")", "if", "self", ".", "semver_major", "(", "manifest", "[", "\"format-version\"", "]", ")", "!=", "1", ":", "print", "(", "\"fw: Manifest (%s) has major version %d; MAVProxy only understands version 1\"", "%", "(", "manifest_path", ",", "manifest", "[", "\"format-version\"", "]", ")", ")", "continue", "self", ".", "manifests", ".", "append", "(", "manifest", ")" ]
parse manifests present on system
[ "parse", "manifests", "present", "on", "system" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L294-L304
235,517
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.make_safe_filename_from_url
def make_safe_filename_from_url(self, url): '''return a version of url safe for use as a filename''' r = re.compile("([^a-zA-Z0-9_.-])") filename = r.sub(lambda m : "%" + str(hex(ord(str(m.group(1))))).upper(), url) return filename
python
def make_safe_filename_from_url(self, url): '''return a version of url safe for use as a filename''' r = re.compile("([^a-zA-Z0-9_.-])") filename = r.sub(lambda m : "%" + str(hex(ord(str(m.group(1))))).upper(), url) return filename
[ "def", "make_safe_filename_from_url", "(", "self", ",", "url", ")", ":", "r", "=", "re", ".", "compile", "(", "\"([^a-zA-Z0-9_.-])\"", ")", "filename", "=", "r", ".", "sub", "(", "lambda", "m", ":", "\"%\"", "+", "str", "(", "hex", "(", "ord", "(", "str", "(", "m", ".", "group", "(", "1", ")", ")", ")", ")", ")", ".", "upper", "(", ")", ",", "url", ")", "return", "filename" ]
return a version of url safe for use as a filename
[ "return", "a", "version", "of", "url", "safe", "for", "use", "as", "a", "filename" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L324-L328
235,518
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_firmware.py
FirmwareModule.manifest_download
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 ['http://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")
python
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 ['http://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")
[ "def", "manifest_download", "(", "self", ")", ":", "if", "self", ".", "downloaders_lock", ".", "acquire", "(", "False", ")", ":", "if", "len", "(", "self", ".", "downloaders", ")", ":", "# there already exist downloader threads", "self", ".", "downloaders_lock", ".", "release", "(", ")", "return", "for", "url", "in", "[", "'http://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\"", ")" ]
download manifest files
[ "download", "manifest", "files" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_firmware.py#L330-L345
235,519
ArduPilot/MAVProxy
MAVProxy/tools/mavflightview.py
colour_for_point
def colour_for_point(mlog, point, instance, options): global colour_expression_exceptions, colour_source_max, colour_source_min '''indicate a colour to be used to plot point''' source = getattr(options, "colour_source", "flightmode") if source == "flightmode": return colour_for_point_flightmode(mlog, point, instance, options) # evaluate source as an expression which should return a # number in the range 0..255 try: v = eval(source, globals(),mlog.messages) except Exception as e: str_e = str(e) try: count = colour_expression_exceptions[str_e] except KeyError: colour_expression_exceptions[str_e] = 0 count = 0 if count > 100: print("Too many exceptions processing (%s): %s" % (source, str_e)) sys.exit(1) colour_expression_exceptions[str_e] += 1 v = 0 # we don't use evaluate_expression as we want the exceptions... # v = mavutil.evaluate_expression(source, mlog.messages) if v is None: v = 0 elif isinstance(v, str): print("colour expression returned a string: %s" % v) sys.exit(1) elif v < 0: print("colour expression returned %d (< 0)" % v) v = 0 elif v > 255: print("colour expression returned %d (> 255)" % v) v = 255 if v < colour_source_min: colour_source_min = v if v > colour_source_max: colour_source_max = v r = 255 g = 255 b = v return (b,b,b)
python
def colour_for_point(mlog, point, instance, options): global colour_expression_exceptions, colour_source_max, colour_source_min '''indicate a colour to be used to plot point''' source = getattr(options, "colour_source", "flightmode") if source == "flightmode": return colour_for_point_flightmode(mlog, point, instance, options) # evaluate source as an expression which should return a # number in the range 0..255 try: v = eval(source, globals(),mlog.messages) except Exception as e: str_e = str(e) try: count = colour_expression_exceptions[str_e] except KeyError: colour_expression_exceptions[str_e] = 0 count = 0 if count > 100: print("Too many exceptions processing (%s): %s" % (source, str_e)) sys.exit(1) colour_expression_exceptions[str_e] += 1 v = 0 # we don't use evaluate_expression as we want the exceptions... # v = mavutil.evaluate_expression(source, mlog.messages) if v is None: v = 0 elif isinstance(v, str): print("colour expression returned a string: %s" % v) sys.exit(1) elif v < 0: print("colour expression returned %d (< 0)" % v) v = 0 elif v > 255: print("colour expression returned %d (> 255)" % v) v = 255 if v < colour_source_min: colour_source_min = v if v > colour_source_max: colour_source_max = v r = 255 g = 255 b = v return (b,b,b)
[ "def", "colour_for_point", "(", "mlog", ",", "point", ",", "instance", ",", "options", ")", ":", "global", "colour_expression_exceptions", ",", "colour_source_max", ",", "colour_source_min", "source", "=", "getattr", "(", "options", ",", "\"colour_source\"", ",", "\"flightmode\"", ")", "if", "source", "==", "\"flightmode\"", ":", "return", "colour_for_point_flightmode", "(", "mlog", ",", "point", ",", "instance", ",", "options", ")", "# evaluate source as an expression which should return a", "# number in the range 0..255", "try", ":", "v", "=", "eval", "(", "source", ",", "globals", "(", ")", ",", "mlog", ".", "messages", ")", "except", "Exception", "as", "e", ":", "str_e", "=", "str", "(", "e", ")", "try", ":", "count", "=", "colour_expression_exceptions", "[", "str_e", "]", "except", "KeyError", ":", "colour_expression_exceptions", "[", "str_e", "]", "=", "0", "count", "=", "0", "if", "count", ">", "100", ":", "print", "(", "\"Too many exceptions processing (%s): %s\"", "%", "(", "source", ",", "str_e", ")", ")", "sys", ".", "exit", "(", "1", ")", "colour_expression_exceptions", "[", "str_e", "]", "+=", "1", "v", "=", "0", "# we don't use evaluate_expression as we want the exceptions...", "# v = mavutil.evaluate_expression(source, mlog.messages)", "if", "v", "is", "None", ":", "v", "=", "0", "elif", "isinstance", "(", "v", ",", "str", ")", ":", "print", "(", "\"colour expression returned a string: %s\"", "%", "v", ")", "sys", ".", "exit", "(", "1", ")", "elif", "v", "<", "0", ":", "print", "(", "\"colour expression returned %d (< 0)\"", "%", "v", ")", "v", "=", "0", "elif", "v", ">", "255", ":", "print", "(", "\"colour expression returned %d (> 255)\"", "%", "v", ")", "v", "=", "255", "if", "v", "<", "colour_source_min", ":", "colour_source_min", "=", "v", "if", "v", ">", "colour_source_max", ":", "colour_source_max", "=", "v", "r", "=", "255", "g", "=", "255", "b", "=", "v", "return", "(", "b", ",", "b", ",", "b", ")" ]
indicate a colour to be used to plot point
[ "indicate", "a", "colour", "to", "be", "used", "to", "plot", "point" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/mavflightview.py#L154-L201
235,520
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_restserver.py
mavlink_to_json
def mavlink_to_json(msg): '''Translate mavlink python messages in json string''' ret = '\"%s\": {' % msg._type for fieldname in msg._fieldnames: data = getattr(msg, fieldname) ret += '\"%s\" : \"%s\", ' % (fieldname, data) ret = ret[0:-2] + '}' return ret
python
def mavlink_to_json(msg): '''Translate mavlink python messages in json string''' ret = '\"%s\": {' % msg._type for fieldname in msg._fieldnames: data = getattr(msg, fieldname) ret += '\"%s\" : \"%s\", ' % (fieldname, data) ret = ret[0:-2] + '}' return ret
[ "def", "mavlink_to_json", "(", "msg", ")", ":", "ret", "=", "'\\\"%s\\\": {'", "%", "msg", ".", "_type", "for", "fieldname", "in", "msg", ".", "_fieldnames", ":", "data", "=", "getattr", "(", "msg", ",", "fieldname", ")", "ret", "+=", "'\\\"%s\\\" : \\\"%s\\\", '", "%", "(", "fieldname", ",", "data", ")", "ret", "=", "ret", "[", "0", ":", "-", "2", "]", "+", "'}'", "return", "ret" ]
Translate mavlink python messages in json string
[ "Translate", "mavlink", "python", "messages", "in", "json", "string" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_restserver.py#L18-L25
235,521
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_restserver.py
mpstatus_to_json
def mpstatus_to_json(status): '''Translate MPStatus in json string''' msg_keys = list(status.msgs.keys()) data = '{' for key in msg_keys[:-1]: data += mavlink_to_json(status.msgs[key]) + ',' data += mavlink_to_json(status.msgs[msg_keys[-1]]) data += '}' return data
python
def mpstatus_to_json(status): '''Translate MPStatus in json string''' msg_keys = list(status.msgs.keys()) data = '{' for key in msg_keys[:-1]: data += mavlink_to_json(status.msgs[key]) + ',' data += mavlink_to_json(status.msgs[msg_keys[-1]]) data += '}' return data
[ "def", "mpstatus_to_json", "(", "status", ")", ":", "msg_keys", "=", "list", "(", "status", ".", "msgs", ".", "keys", "(", ")", ")", "data", "=", "'{'", "for", "key", "in", "msg_keys", "[", ":", "-", "1", "]", ":", "data", "+=", "mavlink_to_json", "(", "status", ".", "msgs", "[", "key", "]", ")", "+", "','", "data", "+=", "mavlink_to_json", "(", "status", ".", "msgs", "[", "msg_keys", "[", "-", "1", "]", "]", ")", "data", "+=", "'}'", "return", "data" ]
Translate MPStatus in json string
[ "Translate", "MPStatus", "in", "json", "string" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_restserver.py#L27-L35
235,522
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_restserver.py
RestServer.set_ip_port
def set_ip_port(self, ip, port): '''set ip and port''' self.address = ip self.port = port self.stop() self.start()
python
def set_ip_port(self, ip, port): '''set ip and port''' self.address = ip self.port = port self.stop() self.start()
[ "def", "set_ip_port", "(", "self", ",", "ip", ",", "port", ")", ":", "self", ".", "address", "=", "ip", "self", ".", "port", "=", "port", "self", ".", "stop", "(", ")", "self", ".", "start", "(", ")" ]
set ip and port
[ "set", "ip", "and", "port" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_restserver.py#L59-L64
235,523
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_restserver.py
RestServer.request
def request(self, arg=None): '''Deal with requests''' if not self.status: return '{"result": "No message"}' try: status_dict = json.loads(mpstatus_to_json(self.status)) except Exception as e: print(e) return # If no key, send the entire json if not arg: return json.dumps(status_dict) # Get item from path new_dict = status_dict args = arg.split('/') for key in args: if key in new_dict: new_dict = new_dict[key] else: return '{"key": "%s", "last_dict": %s}' % (key, json.dumps(new_dict)) return json.dumps(new_dict)
python
def request(self, arg=None): '''Deal with requests''' if not self.status: return '{"result": "No message"}' try: status_dict = json.loads(mpstatus_to_json(self.status)) except Exception as e: print(e) return # If no key, send the entire json if not arg: return json.dumps(status_dict) # Get item from path new_dict = status_dict args = arg.split('/') for key in args: if key in new_dict: new_dict = new_dict[key] else: return '{"key": "%s", "last_dict": %s}' % (key, json.dumps(new_dict)) return json.dumps(new_dict)
[ "def", "request", "(", "self", ",", "arg", "=", "None", ")", ":", "if", "not", "self", ".", "status", ":", "return", "'{\"result\": \"No message\"}'", "try", ":", "status_dict", "=", "json", ".", "loads", "(", "mpstatus_to_json", "(", "self", ".", "status", ")", ")", "except", "Exception", "as", "e", ":", "print", "(", "e", ")", "return", "# If no key, send the entire json", "if", "not", "arg", ":", "return", "json", ".", "dumps", "(", "status_dict", ")", "# Get item from path", "new_dict", "=", "status_dict", "args", "=", "arg", ".", "split", "(", "'/'", ")", "for", "key", "in", "args", ":", "if", "key", "in", "new_dict", ":", "new_dict", "=", "new_dict", "[", "key", "]", "else", ":", "return", "'{\"key\": \"%s\", \"last_dict\": %s}'", "%", "(", "key", ",", "json", ".", "dumps", "(", "new_dict", ")", ")", "return", "json", ".", "dumps", "(", "new_dict", ")" ]
Deal with requests
[ "Deal", "with", "requests" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_restserver.py#L93-L117
235,524
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_battery.py
BatteryModule.power_status_update
def power_status_update(self, POWER_STATUS): '''update POWER_STATUS warnings level''' now = time.time() Vservo = POWER_STATUS.Vservo * 0.001 Vcc = POWER_STATUS.Vcc * 0.001 self.high_servo_voltage = max(self.high_servo_voltage, Vservo) if self.high_servo_voltage > 1 and Vservo < self.settings.servowarn: if now - self.last_servo_warn_time > 30: self.last_servo_warn_time = now self.say("Servo volt %.1f" % Vservo) if Vservo < 1: # prevent continuous announcements on power down self.high_servo_voltage = Vservo if Vcc > 0 and Vcc < self.settings.vccwarn: if now - self.last_vcc_warn_time > 30: self.last_vcc_warn_time = now self.say("Vcc %.1f" % Vcc)
python
def power_status_update(self, POWER_STATUS): '''update POWER_STATUS warnings level''' now = time.time() Vservo = POWER_STATUS.Vservo * 0.001 Vcc = POWER_STATUS.Vcc * 0.001 self.high_servo_voltage = max(self.high_servo_voltage, Vservo) if self.high_servo_voltage > 1 and Vservo < self.settings.servowarn: if now - self.last_servo_warn_time > 30: self.last_servo_warn_time = now self.say("Servo volt %.1f" % Vservo) if Vservo < 1: # prevent continuous announcements on power down self.high_servo_voltage = Vservo if Vcc > 0 and Vcc < self.settings.vccwarn: if now - self.last_vcc_warn_time > 30: self.last_vcc_warn_time = now self.say("Vcc %.1f" % Vcc)
[ "def", "power_status_update", "(", "self", ",", "POWER_STATUS", ")", ":", "now", "=", "time", ".", "time", "(", ")", "Vservo", "=", "POWER_STATUS", ".", "Vservo", "*", "0.001", "Vcc", "=", "POWER_STATUS", ".", "Vcc", "*", "0.001", "self", ".", "high_servo_voltage", "=", "max", "(", "self", ".", "high_servo_voltage", ",", "Vservo", ")", "if", "self", ".", "high_servo_voltage", ">", "1", "and", "Vservo", "<", "self", ".", "settings", ".", "servowarn", ":", "if", "now", "-", "self", ".", "last_servo_warn_time", ">", "30", ":", "self", ".", "last_servo_warn_time", "=", "now", "self", ".", "say", "(", "\"Servo volt %.1f\"", "%", "Vservo", ")", "if", "Vservo", "<", "1", ":", "# prevent continuous announcements on power down", "self", ".", "high_servo_voltage", "=", "Vservo", "if", "Vcc", ">", "0", "and", "Vcc", "<", "self", ".", "settings", ".", "vccwarn", ":", "if", "now", "-", "self", ".", "last_vcc_warn_time", ">", "30", ":", "self", ".", "last_vcc_warn_time", "=", "now", "self", ".", "say", "(", "\"Vcc %.1f\"", "%", "Vcc", ")" ]
update POWER_STATUS warnings level
[ "update", "POWER_STATUS", "warnings", "level" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_battery.py#L101-L118
235,525
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_gasheli.py
GasHeliModule.valid_starter_settings
def valid_starter_settings(self): '''check starter settings''' if self.gasheli_settings.ignition_chan <= 0 or self.gasheli_settings.ignition_chan > 8: print("Invalid ignition channel %d" % self.gasheli_settings.ignition_chan) return False if self.gasheli_settings.starter_chan <= 0 or self.gasheli_settings.starter_chan > 14: print("Invalid starter channel %d" % self.gasheli_settings.starter_chan) return False return True
python
def valid_starter_settings(self): '''check starter settings''' if self.gasheli_settings.ignition_chan <= 0 or self.gasheli_settings.ignition_chan > 8: print("Invalid ignition channel %d" % self.gasheli_settings.ignition_chan) return False if self.gasheli_settings.starter_chan <= 0 or self.gasheli_settings.starter_chan > 14: print("Invalid starter channel %d" % self.gasheli_settings.starter_chan) return False return True
[ "def", "valid_starter_settings", "(", "self", ")", ":", "if", "self", ".", "gasheli_settings", ".", "ignition_chan", "<=", "0", "or", "self", ".", "gasheli_settings", ".", "ignition_chan", ">", "8", ":", "print", "(", "\"Invalid ignition channel %d\"", "%", "self", ".", "gasheli_settings", ".", "ignition_chan", ")", "return", "False", "if", "self", ".", "gasheli_settings", ".", "starter_chan", "<=", "0", "or", "self", ".", "gasheli_settings", ".", "starter_chan", ">", "14", ":", "print", "(", "\"Invalid starter channel %d\"", "%", "self", ".", "gasheli_settings", ".", "starter_chan", ")", "return", "False", "return", "True" ]
check starter settings
[ "check", "starter", "settings" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gasheli.py#L73-L81
235,526
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_gasheli.py
GasHeliModule.cmd_gasheli
def cmd_gasheli(self, args): '''gas help commands''' usage = "Usage: gasheli <start|stop|set>" if len(args) < 1: print(usage) return if args[0] == "start": self.start_motor() elif args[0] == "stop": self.stop_motor() elif args[0] == "set": self.gasheli_settings.command(args[1:]) else: print(usage)
python
def cmd_gasheli(self, args): '''gas help commands''' usage = "Usage: gasheli <start|stop|set>" if len(args) < 1: print(usage) return if args[0] == "start": self.start_motor() elif args[0] == "stop": self.stop_motor() elif args[0] == "set": self.gasheli_settings.command(args[1:]) else: print(usage)
[ "def", "cmd_gasheli", "(", "self", ",", "args", ")", ":", "usage", "=", "\"Usage: gasheli <start|stop|set>\"", "if", "len", "(", "args", ")", "<", "1", ":", "print", "(", "usage", ")", "return", "if", "args", "[", "0", "]", "==", "\"start\"", ":", "self", ".", "start_motor", "(", ")", "elif", "args", "[", "0", "]", "==", "\"stop\"", ":", "self", ".", "stop_motor", "(", ")", "elif", "args", "[", "0", "]", "==", "\"set\"", ":", "self", ".", "gasheli_settings", ".", "command", "(", "args", "[", "1", ":", "]", ")", "else", ":", "print", "(", "usage", ")" ]
gas help commands
[ "gas", "help", "commands" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gasheli.py#L135-L148
235,527
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.wploader
def wploader(self): '''per-sysid wploader''' if self.target_system not in self.wploader_by_sysid: self.wploader_by_sysid[self.target_system] = mavwp.MAVWPLoader() return self.wploader_by_sysid[self.target_system]
python
def wploader(self): '''per-sysid wploader''' if self.target_system not in self.wploader_by_sysid: self.wploader_by_sysid[self.target_system] = mavwp.MAVWPLoader() return self.wploader_by_sysid[self.target_system]
[ "def", "wploader", "(", "self", ")", ":", "if", "self", ".", "target_system", "not", "in", "self", ".", "wploader_by_sysid", ":", "self", ".", "wploader_by_sysid", "[", "self", ".", "target_system", "]", "=", "mavwp", ".", "MAVWPLoader", "(", ")", "return", "self", ".", "wploader_by_sysid", "[", "self", ".", "target_system", "]" ]
per-sysid wploader
[ "per", "-", "sysid", "wploader" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L60-L64
235,528
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.send_wp_requests
def send_wp_requests(self, wps=None): '''send some more WP requests''' if wps is None: wps = self.missing_wps_to_request() tnow = time.time() for seq in wps: #print("REQUESTING %u/%u (%u)" % (seq, self.wploader.expected_count, i)) self.wp_requested[seq] = tnow self.master.waypoint_request_send(seq)
python
def send_wp_requests(self, wps=None): '''send some more WP requests''' if wps is None: wps = self.missing_wps_to_request() tnow = time.time() for seq in wps: #print("REQUESTING %u/%u (%u)" % (seq, self.wploader.expected_count, i)) self.wp_requested[seq] = tnow self.master.waypoint_request_send(seq)
[ "def", "send_wp_requests", "(", "self", ",", "wps", "=", "None", ")", ":", "if", "wps", "is", "None", ":", "wps", "=", "self", ".", "missing_wps_to_request", "(", ")", "tnow", "=", "time", ".", "time", "(", ")", "for", "seq", "in", "wps", ":", "#print(\"REQUESTING %u/%u (%u)\" % (seq, self.wploader.expected_count, i))", "self", ".", "wp_requested", "[", "seq", "]", "=", "tnow", "self", ".", "master", ".", "waypoint_request_send", "(", "seq", ")" ]
send some more WP requests
[ "send", "some", "more", "WP", "requests" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L79-L87
235,529
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.wp_status
def wp_status(self): '''show status of wp download''' try: print("Have %u of %u waypoints" % (self.wploader.count()+len(self.wp_received), self.wploader.expected_count)) except Exception: print("Have %u waypoints" % (self.wploader.count()+len(self.wp_received)))
python
def wp_status(self): '''show status of wp download''' try: print("Have %u of %u waypoints" % (self.wploader.count()+len(self.wp_received), self.wploader.expected_count)) except Exception: print("Have %u waypoints" % (self.wploader.count()+len(self.wp_received)))
[ "def", "wp_status", "(", "self", ")", ":", "try", ":", "print", "(", "\"Have %u of %u waypoints\"", "%", "(", "self", ".", "wploader", ".", "count", "(", ")", "+", "len", "(", "self", ".", "wp_received", ")", ",", "self", ".", "wploader", ".", "expected_count", ")", ")", "except", "Exception", ":", "print", "(", "\"Have %u waypoints\"", "%", "(", "self", ".", "wploader", ".", "count", "(", ")", "+", "len", "(", "self", ".", "wp_received", ")", ")", ")" ]
show status of wp download
[ "show", "status", "of", "wp", "download" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L89-L94
235,530
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.wp_slope
def wp_slope(self): '''show slope of waypoints''' last_w = None for i in range(1, self.wploader.count()): w = self.wploader.wp(i) if w.command not in [mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, mavutil.mavlink.MAV_CMD_NAV_LAND]: continue if last_w is not None: if last_w.frame != w.frame: print("WARNING: frame change %u -> %u at %u" % (last_w.frame, w.frame, i)) delta_alt = last_w.z - w.z if delta_alt == 0: slope = "Level" else: delta_xy = mp_util.gps_distance(w.x, w.y, last_w.x, last_w.y) slope = "%.1f" % (delta_xy / delta_alt) print("WP%u: slope %s" % (i, slope)) last_w = w
python
def wp_slope(self): '''show slope of waypoints''' last_w = None for i in range(1, self.wploader.count()): w = self.wploader.wp(i) if w.command not in [mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, mavutil.mavlink.MAV_CMD_NAV_LAND]: continue if last_w is not None: if last_w.frame != w.frame: print("WARNING: frame change %u -> %u at %u" % (last_w.frame, w.frame, i)) delta_alt = last_w.z - w.z if delta_alt == 0: slope = "Level" else: delta_xy = mp_util.gps_distance(w.x, w.y, last_w.x, last_w.y) slope = "%.1f" % (delta_xy / delta_alt) print("WP%u: slope %s" % (i, slope)) last_w = w
[ "def", "wp_slope", "(", "self", ")", ":", "last_w", "=", "None", "for", "i", "in", "range", "(", "1", ",", "self", ".", "wploader", ".", "count", "(", ")", ")", ":", "w", "=", "self", ".", "wploader", ".", "wp", "(", "i", ")", "if", "w", ".", "command", "not", "in", "[", "mavutil", ".", "mavlink", ".", "MAV_CMD_NAV_WAYPOINT", ",", "mavutil", ".", "mavlink", ".", "MAV_CMD_NAV_LAND", "]", ":", "continue", "if", "last_w", "is", "not", "None", ":", "if", "last_w", ".", "frame", "!=", "w", ".", "frame", ":", "print", "(", "\"WARNING: frame change %u -> %u at %u\"", "%", "(", "last_w", ".", "frame", ",", "w", ".", "frame", ",", "i", ")", ")", "delta_alt", "=", "last_w", ".", "z", "-", "w", ".", "z", "if", "delta_alt", "==", "0", ":", "slope", "=", "\"Level\"", "else", ":", "delta_xy", "=", "mp_util", ".", "gps_distance", "(", "w", ".", "x", ",", "w", ".", "y", ",", "last_w", ".", "x", ",", "last_w", ".", "y", ")", "slope", "=", "\"%.1f\"", "%", "(", "delta_xy", "/", "delta_alt", ")", "print", "(", "\"WP%u: slope %s\"", "%", "(", "i", ",", "slope", ")", ")", "last_w", "=", "w" ]
show slope of waypoints
[ "show", "slope", "of", "waypoints" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L97-L114
235,531
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.save_waypoints_csv
def save_waypoints_csv(self, filename): '''save waypoints to a file in a human readable CSV file''' try: #need to remove the leading and trailing quotes in filename self.wploader.savecsv(filename.strip('"')) except Exception as msg: print("Failed to save %s - %s" % (filename, msg)) return print("Saved %u waypoints to CSV %s" % (self.wploader.count(), filename))
python
def save_waypoints_csv(self, filename): '''save waypoints to a file in a human readable CSV file''' try: #need to remove the leading and trailing quotes in filename self.wploader.savecsv(filename.strip('"')) except Exception as msg: print("Failed to save %s - %s" % (filename, msg)) return print("Saved %u waypoints to CSV %s" % (self.wploader.count(), filename))
[ "def", "save_waypoints_csv", "(", "self", ",", "filename", ")", ":", "try", ":", "#need to remove the leading and trailing quotes in filename", "self", ".", "wploader", ".", "savecsv", "(", "filename", ".", "strip", "(", "'\"'", ")", ")", "except", "Exception", "as", "msg", ":", "print", "(", "\"Failed to save %s - %s\"", "%", "(", "filename", ",", "msg", ")", ")", "return", "print", "(", "\"Saved %u waypoints to CSV %s\"", "%", "(", "self", ".", "wploader", ".", "count", "(", ")", ",", "filename", ")", ")" ]
save waypoints to a file in a human readable CSV file
[ "save", "waypoints", "to", "a", "file", "in", "a", "human", "readable", "CSV", "file" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L293-L301
235,532
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.get_home
def get_home(self): '''get home location''' if 'HOME_POSITION' in self.master.messages: h = self.master.messages['HOME_POSITION'] return mavutil.mavlink.MAVLink_mission_item_message(self.target_system, self.target_component, 0, 0, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, h.latitude*1.0e-7, h.longitude*1.0e-7, h.altitude*1.0e-3) if self.wploader.count() > 0: return self.wploader.wp(0) return None
python
def get_home(self): '''get home location''' if 'HOME_POSITION' in self.master.messages: h = self.master.messages['HOME_POSITION'] return mavutil.mavlink.MAVLink_mission_item_message(self.target_system, self.target_component, 0, 0, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, h.latitude*1.0e-7, h.longitude*1.0e-7, h.altitude*1.0e-3) if self.wploader.count() > 0: return self.wploader.wp(0) return None
[ "def", "get_home", "(", "self", ")", ":", "if", "'HOME_POSITION'", "in", "self", ".", "master", ".", "messages", ":", "h", "=", "self", ".", "master", ".", "messages", "[", "'HOME_POSITION'", "]", "return", "mavutil", ".", "mavlink", ".", "MAVLink_mission_item_message", "(", "self", ".", "target_system", ",", "self", ".", "target_component", ",", "0", ",", "0", ",", "mavutil", ".", "mavlink", ".", "MAV_CMD_NAV_WAYPOINT", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "h", ".", "latitude", "*", "1.0e-7", ",", "h", ".", "longitude", "*", "1.0e-7", ",", "h", ".", "altitude", "*", "1.0e-3", ")", "if", "self", ".", "wploader", ".", "count", "(", ")", ">", "0", ":", "return", "self", ".", "wploader", ".", "wp", "(", "0", ")", "return", "None" ]
get home location
[ "get", "home", "location" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L313-L326
235,533
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.nofly_add
def nofly_add(self): '''add a square flight exclusion zone''' try: latlon = self.module('map').click_position except Exception: print("No position chosen") return loader = self.wploader (center_lat, center_lon) = latlon points = [] points.append(mp_util.gps_offset(center_lat, center_lon, -25, 25)) points.append(mp_util.gps_offset(center_lat, center_lon, 25, 25)) points.append(mp_util.gps_offset(center_lat, center_lon, 25, -25)) points.append(mp_util.gps_offset(center_lat, center_lon, -25, -25)) start_idx = loader.count() for p in points: wp = mavutil.mavlink.MAVLink_mission_item_message(0, 0, 0, 0, mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, 0, 1, 4, 0, 0, 0, p[0], p[1], 0) loader.add(wp) self.loading_waypoints = True self.loading_waypoint_lasttime = time.time() self.master.mav.mission_write_partial_list_send(self.target_system, self.target_component, start_idx, start_idx+4) print("Added nofly zone")
python
def nofly_add(self): '''add a square flight exclusion zone''' try: latlon = self.module('map').click_position except Exception: print("No position chosen") return loader = self.wploader (center_lat, center_lon) = latlon points = [] points.append(mp_util.gps_offset(center_lat, center_lon, -25, 25)) points.append(mp_util.gps_offset(center_lat, center_lon, 25, 25)) points.append(mp_util.gps_offset(center_lat, center_lon, 25, -25)) points.append(mp_util.gps_offset(center_lat, center_lon, -25, -25)) start_idx = loader.count() for p in points: wp = mavutil.mavlink.MAVLink_mission_item_message(0, 0, 0, 0, mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, 0, 1, 4, 0, 0, 0, p[0], p[1], 0) loader.add(wp) self.loading_waypoints = True self.loading_waypoint_lasttime = time.time() self.master.mav.mission_write_partial_list_send(self.target_system, self.target_component, start_idx, start_idx+4) print("Added nofly zone")
[ "def", "nofly_add", "(", "self", ")", ":", "try", ":", "latlon", "=", "self", ".", "module", "(", "'map'", ")", ".", "click_position", "except", "Exception", ":", "print", "(", "\"No position chosen\"", ")", "return", "loader", "=", "self", ".", "wploader", "(", "center_lat", ",", "center_lon", ")", "=", "latlon", "points", "=", "[", "]", "points", ".", "append", "(", "mp_util", ".", "gps_offset", "(", "center_lat", ",", "center_lon", ",", "-", "25", ",", "25", ")", ")", "points", ".", "append", "(", "mp_util", ".", "gps_offset", "(", "center_lat", ",", "center_lon", ",", "25", ",", "25", ")", ")", "points", ".", "append", "(", "mp_util", ".", "gps_offset", "(", "center_lat", ",", "center_lon", ",", "25", ",", "-", "25", ")", ")", "points", ".", "append", "(", "mp_util", ".", "gps_offset", "(", "center_lat", ",", "center_lon", ",", "-", "25", ",", "-", "25", ")", ")", "start_idx", "=", "loader", ".", "count", "(", ")", "for", "p", "in", "points", ":", "wp", "=", "mavutil", ".", "mavlink", ".", "MAVLink_mission_item_message", "(", "0", ",", "0", ",", "0", ",", "0", ",", "mavutil", ".", "mavlink", ".", "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION", ",", "0", ",", "1", ",", "4", ",", "0", ",", "0", ",", "0", ",", "p", "[", "0", "]", ",", "p", "[", "1", "]", ",", "0", ")", "loader", ".", "add", "(", "wp", ")", "self", ".", "loading_waypoints", "=", "True", "self", ".", "loading_waypoint_lasttime", "=", "time", ".", "time", "(", ")", "self", ".", "master", ".", "mav", ".", "mission_write_partial_list_send", "(", "self", ".", "target_system", ",", "self", ".", "target_component", ",", "start_idx", ",", "start_idx", "+", "4", ")", "print", "(", "\"Added nofly zone\"", ")" ]
add a square flight exclusion zone
[ "add", "a", "square", "flight", "exclusion", "zone" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L368-L392
235,534
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.cmd_wp_changealt
def cmd_wp_changealt(self, args): '''handle wp change target alt of multiple waypoints''' if len(args) < 2: print("usage: wp changealt WPNUM NEWALT <NUMWP>") return idx = int(args[0]) if idx < 1 or idx > self.wploader.count(): print("Invalid wp number %u" % idx) return newalt = float(args[1]) if len(args) >= 3: count = int(args[2]) else: count = 1 for wpnum in range(idx, idx+count): wp = self.wploader.wp(wpnum) if not self.wploader.is_location_command(wp.command): continue wp.z = newalt wp.target_system = self.target_system wp.target_component = self.target_component self.wploader.set(wp, wpnum) self.loading_waypoints = True self.loading_waypoint_lasttime = time.time() self.master.mav.mission_write_partial_list_send(self.target_system, self.target_component, idx, idx+count) print("Changed alt for WPs %u:%u to %f" % (idx, idx+(count-1), newalt))
python
def cmd_wp_changealt(self, args): '''handle wp change target alt of multiple waypoints''' if len(args) < 2: print("usage: wp changealt WPNUM NEWALT <NUMWP>") return idx = int(args[0]) if idx < 1 or idx > self.wploader.count(): print("Invalid wp number %u" % idx) return newalt = float(args[1]) if len(args) >= 3: count = int(args[2]) else: count = 1 for wpnum in range(idx, idx+count): wp = self.wploader.wp(wpnum) if not self.wploader.is_location_command(wp.command): continue wp.z = newalt wp.target_system = self.target_system wp.target_component = self.target_component self.wploader.set(wp, wpnum) self.loading_waypoints = True self.loading_waypoint_lasttime = time.time() self.master.mav.mission_write_partial_list_send(self.target_system, self.target_component, idx, idx+count) print("Changed alt for WPs %u:%u to %f" % (idx, idx+(count-1), newalt))
[ "def", "cmd_wp_changealt", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "<", "2", ":", "print", "(", "\"usage: wp changealt WPNUM NEWALT <NUMWP>\"", ")", "return", "idx", "=", "int", "(", "args", "[", "0", "]", ")", "if", "idx", "<", "1", "or", "idx", ">", "self", ".", "wploader", ".", "count", "(", ")", ":", "print", "(", "\"Invalid wp number %u\"", "%", "idx", ")", "return", "newalt", "=", "float", "(", "args", "[", "1", "]", ")", "if", "len", "(", "args", ")", ">=", "3", ":", "count", "=", "int", "(", "args", "[", "2", "]", ")", "else", ":", "count", "=", "1", "for", "wpnum", "in", "range", "(", "idx", ",", "idx", "+", "count", ")", ":", "wp", "=", "self", ".", "wploader", ".", "wp", "(", "wpnum", ")", "if", "not", "self", ".", "wploader", ".", "is_location_command", "(", "wp", ".", "command", ")", ":", "continue", "wp", ".", "z", "=", "newalt", "wp", ".", "target_system", "=", "self", ".", "target_system", "wp", ".", "target_component", "=", "self", ".", "target_component", "self", ".", "wploader", ".", "set", "(", "wp", ",", "wpnum", ")", "self", ".", "loading_waypoints", "=", "True", "self", ".", "loading_waypoint_lasttime", "=", "time", ".", "time", "(", ")", "self", ".", "master", ".", "mav", ".", "mission_write_partial_list_send", "(", "self", ".", "target_system", ",", "self", ".", "target_component", ",", "idx", ",", "idx", "+", "count", ")", "print", "(", "\"Changed alt for WPs %u:%u to %f\"", "%", "(", "idx", ",", "idx", "+", "(", "count", "-", "1", ")", ",", "newalt", ")", ")" ]
handle wp change target alt of multiple waypoints
[ "handle", "wp", "change", "target", "alt", "of", "multiple", "waypoints" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L535-L564
235,535
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.cmd_wp_remove
def cmd_wp_remove(self, args): '''handle wp remove''' if len(args) != 1: print("usage: wp remove WPNUM") return idx = int(args[0]) if idx < 0 or idx >= self.wploader.count(): print("Invalid wp number %u" % idx) return wp = self.wploader.wp(idx) # setup for undo self.undo_wp = copy.copy(wp) self.undo_wp_idx = idx self.undo_type = "remove" self.wploader.remove(wp) self.fix_jumps(idx, -1) self.send_all_waypoints() print("Removed WP %u" % idx)
python
def cmd_wp_remove(self, args): '''handle wp remove''' if len(args) != 1: print("usage: wp remove WPNUM") return idx = int(args[0]) if idx < 0 or idx >= self.wploader.count(): print("Invalid wp number %u" % idx) return wp = self.wploader.wp(idx) # setup for undo self.undo_wp = copy.copy(wp) self.undo_wp_idx = idx self.undo_type = "remove" self.wploader.remove(wp) self.fix_jumps(idx, -1) self.send_all_waypoints() print("Removed WP %u" % idx)
[ "def", "cmd_wp_remove", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "!=", "1", ":", "print", "(", "\"usage: wp remove WPNUM\"", ")", "return", "idx", "=", "int", "(", "args", "[", "0", "]", ")", "if", "idx", "<", "0", "or", "idx", ">=", "self", ".", "wploader", ".", "count", "(", ")", ":", "print", "(", "\"Invalid wp number %u\"", "%", "idx", ")", "return", "wp", "=", "self", ".", "wploader", ".", "wp", "(", "idx", ")", "# setup for undo", "self", ".", "undo_wp", "=", "copy", ".", "copy", "(", "wp", ")", "self", ".", "undo_wp_idx", "=", "idx", "self", ".", "undo_type", "=", "\"remove\"", "self", ".", "wploader", ".", "remove", "(", "wp", ")", "self", ".", "fix_jumps", "(", "idx", ",", "-", "1", ")", "self", ".", "send_all_waypoints", "(", ")", "print", "(", "\"Removed WP %u\"", "%", "idx", ")" ]
handle wp remove
[ "handle", "wp", "remove" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L580-L599
235,536
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.cmd_wp_undo
def cmd_wp_undo(self): '''handle wp undo''' if self.undo_wp_idx == -1 or self.undo_wp is None: print("No undo information") return wp = self.undo_wp if self.undo_type == 'move': wp.target_system = self.target_system wp.target_component = self.target_component self.loading_waypoints = True self.loading_waypoint_lasttime = time.time() self.master.mav.mission_write_partial_list_send(self.target_system, self.target_component, self.undo_wp_idx, self.undo_wp_idx) self.wploader.set(wp, self.undo_wp_idx) print("Undid WP move") elif self.undo_type == 'remove': self.wploader.insert(self.undo_wp_idx, wp) self.fix_jumps(self.undo_wp_idx, 1) self.send_all_waypoints() print("Undid WP remove") else: print("bad undo type") self.undo_wp = None self.undo_wp_idx = -1
python
def cmd_wp_undo(self): '''handle wp undo''' if self.undo_wp_idx == -1 or self.undo_wp is None: print("No undo information") return wp = self.undo_wp if self.undo_type == 'move': wp.target_system = self.target_system wp.target_component = self.target_component self.loading_waypoints = True self.loading_waypoint_lasttime = time.time() self.master.mav.mission_write_partial_list_send(self.target_system, self.target_component, self.undo_wp_idx, self.undo_wp_idx) self.wploader.set(wp, self.undo_wp_idx) print("Undid WP move") elif self.undo_type == 'remove': self.wploader.insert(self.undo_wp_idx, wp) self.fix_jumps(self.undo_wp_idx, 1) self.send_all_waypoints() print("Undid WP remove") else: print("bad undo type") self.undo_wp = None self.undo_wp_idx = -1
[ "def", "cmd_wp_undo", "(", "self", ")", ":", "if", "self", ".", "undo_wp_idx", "==", "-", "1", "or", "self", ".", "undo_wp", "is", "None", ":", "print", "(", "\"No undo information\"", ")", "return", "wp", "=", "self", ".", "undo_wp", "if", "self", ".", "undo_type", "==", "'move'", ":", "wp", ".", "target_system", "=", "self", ".", "target_system", "wp", ".", "target_component", "=", "self", ".", "target_component", "self", ".", "loading_waypoints", "=", "True", "self", ".", "loading_waypoint_lasttime", "=", "time", ".", "time", "(", ")", "self", ".", "master", ".", "mav", ".", "mission_write_partial_list_send", "(", "self", ".", "target_system", ",", "self", ".", "target_component", ",", "self", ".", "undo_wp_idx", ",", "self", ".", "undo_wp_idx", ")", "self", ".", "wploader", ".", "set", "(", "wp", ",", "self", ".", "undo_wp_idx", ")", "print", "(", "\"Undid WP move\"", ")", "elif", "self", ".", "undo_type", "==", "'remove'", ":", "self", ".", "wploader", ".", "insert", "(", "self", ".", "undo_wp_idx", ",", "wp", ")", "self", ".", "fix_jumps", "(", "self", ".", "undo_wp_idx", ",", "1", ")", "self", ".", "send_all_waypoints", "(", ")", "print", "(", "\"Undid WP remove\"", ")", "else", ":", "print", "(", "\"bad undo type\"", ")", "self", ".", "undo_wp", "=", "None", "self", ".", "undo_wp_idx", "=", "-", "1" ]
handle wp undo
[ "handle", "wp", "undo" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L601-L625
235,537
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.csv_line
def csv_line(self, line): '''turn a list of values into a CSV line''' self.csv_sep = "," return self.csv_sep.join(['"' + str(x) + '"' for x in line])
python
def csv_line(self, line): '''turn a list of values into a CSV line''' self.csv_sep = "," return self.csv_sep.join(['"' + str(x) + '"' for x in line])
[ "def", "csv_line", "(", "self", ",", "line", ")", ":", "self", ".", "csv_sep", "=", "\",\"", "return", "self", ".", "csv_sep", ".", "join", "(", "[", "'\"'", "+", "str", "(", "x", ")", "+", "'\"'", "for", "x", "in", "line", "]", ")" ]
turn a list of values into a CSV line
[ "turn", "a", "list", "of", "values", "into", "a", "CSV", "line" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L778-L781
235,538
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_wp.py
WPModule.savecsv
def savecsv(self, filename): '''save waypoints to a file in human-readable CSV file''' f = open(filename, mode='w') headers = ["Seq", "Frame", "Cmd", "P1", "P2", "P3", "P4", "X", "Y", "Z"] print(self.csv_line(headers)) f.write(self.csv_line(headers) + "\n") for w in self.wploader.wpoints: if getattr(w, 'comment', None): # f.write("# %s\n" % w.comment) pass out_list = [ w.seq, self.pretty_enum_value('MAV_FRAME', w.frame), self.pretty_enum_value('MAV_CMD', w.command), self.pretty_parameter_value(w.param1), self.pretty_parameter_value(w.param2), self.pretty_parameter_value(w.param3), self.pretty_parameter_value(w.param4), self.pretty_parameter_value(w.x), self.pretty_parameter_value(w.y), self.pretty_parameter_value(w.z), ] print(self.csv_line(out_list)) f.write(self.csv_line(out_list) + "\n") f.close()
python
def savecsv(self, filename): '''save waypoints to a file in human-readable CSV file''' f = open(filename, mode='w') headers = ["Seq", "Frame", "Cmd", "P1", "P2", "P3", "P4", "X", "Y", "Z"] print(self.csv_line(headers)) f.write(self.csv_line(headers) + "\n") for w in self.wploader.wpoints: if getattr(w, 'comment', None): # f.write("# %s\n" % w.comment) pass out_list = [ w.seq, self.pretty_enum_value('MAV_FRAME', w.frame), self.pretty_enum_value('MAV_CMD', w.command), self.pretty_parameter_value(w.param1), self.pretty_parameter_value(w.param2), self.pretty_parameter_value(w.param3), self.pretty_parameter_value(w.param4), self.pretty_parameter_value(w.x), self.pretty_parameter_value(w.y), self.pretty_parameter_value(w.z), ] print(self.csv_line(out_list)) f.write(self.csv_line(out_list) + "\n") f.close()
[ "def", "savecsv", "(", "self", ",", "filename", ")", ":", "f", "=", "open", "(", "filename", ",", "mode", "=", "'w'", ")", "headers", "=", "[", "\"Seq\"", ",", "\"Frame\"", ",", "\"Cmd\"", ",", "\"P1\"", ",", "\"P2\"", ",", "\"P3\"", ",", "\"P4\"", ",", "\"X\"", ",", "\"Y\"", ",", "\"Z\"", "]", "print", "(", "self", ".", "csv_line", "(", "headers", ")", ")", "f", ".", "write", "(", "self", ".", "csv_line", "(", "headers", ")", "+", "\"\\n\"", ")", "for", "w", "in", "self", ".", "wploader", ".", "wpoints", ":", "if", "getattr", "(", "w", ",", "'comment'", ",", "None", ")", ":", "# f.write(\"# %s\\n\" % w.comment)", "pass", "out_list", "=", "[", "w", ".", "seq", ",", "self", ".", "pretty_enum_value", "(", "'MAV_FRAME'", ",", "w", ".", "frame", ")", ",", "self", ".", "pretty_enum_value", "(", "'MAV_CMD'", ",", "w", ".", "command", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "param1", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "param2", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "param3", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "param4", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "x", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "y", ")", ",", "self", ".", "pretty_parameter_value", "(", "w", ".", "z", ")", ",", "]", "print", "(", "self", ".", "csv_line", "(", "out_list", ")", ")", "f", ".", "write", "(", "self", ".", "csv_line", "(", "out_list", ")", "+", "\"\\n\"", ")", "f", ".", "close", "(", ")" ]
save waypoints to a file in human-readable CSV file
[ "save", "waypoints", "to", "a", "file", "in", "human", "-", "readable", "CSV", "file" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_wp.py#L787-L810
235,539
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_joystick/findjoy.py
list_joysticks
def list_joysticks(): '''Print a list of available joysticks''' print('Available joysticks:') print() for jid in range(pygame.joystick.get_count()): j = pygame.joystick.Joystick(jid) print('({}) {}'.format(jid, j.get_name()))
python
def list_joysticks(): '''Print a list of available joysticks''' print('Available joysticks:') print() for jid in range(pygame.joystick.get_count()): j = pygame.joystick.Joystick(jid) print('({}) {}'.format(jid, j.get_name()))
[ "def", "list_joysticks", "(", ")", ":", "print", "(", "'Available joysticks:'", ")", "print", "(", ")", "for", "jid", "in", "range", "(", "pygame", ".", "joystick", ".", "get_count", "(", ")", ")", ":", "j", "=", "pygame", ".", "joystick", ".", "Joystick", "(", "jid", ")", "print", "(", "'({}) {}'", ".", "format", "(", "jid", ",", "j", ".", "get_name", "(", ")", ")", ")" ]
Print a list of available joysticks
[ "Print", "a", "list", "of", "available", "joysticks" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_joystick/findjoy.py#L30-L37
235,540
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_joystick/findjoy.py
select_joystick
def select_joystick(): '''Allow user to select a joystick from a menu''' list_joysticks() while True: print('Select a joystick (L to list, Q to quit)'), choice = sys.stdin.readline().strip() if choice.lower() == 'l': list_joysticks() elif choice.lower() == 'q': return elif choice.isdigit(): jid = int(choice) if jid not in range(pygame.joystick.get_count()): print('Invalid joystick.') continue break else: print('What?') return jid
python
def select_joystick(): '''Allow user to select a joystick from a menu''' list_joysticks() while True: print('Select a joystick (L to list, Q to quit)'), choice = sys.stdin.readline().strip() if choice.lower() == 'l': list_joysticks() elif choice.lower() == 'q': return elif choice.isdigit(): jid = int(choice) if jid not in range(pygame.joystick.get_count()): print('Invalid joystick.') continue break else: print('What?') return jid
[ "def", "select_joystick", "(", ")", ":", "list_joysticks", "(", ")", "while", "True", ":", "print", "(", "'Select a joystick (L to list, Q to quit)'", ")", ",", "choice", "=", "sys", ".", "stdin", ".", "readline", "(", ")", ".", "strip", "(", ")", "if", "choice", ".", "lower", "(", ")", "==", "'l'", ":", "list_joysticks", "(", ")", "elif", "choice", ".", "lower", "(", ")", "==", "'q'", ":", "return", "elif", "choice", ".", "isdigit", "(", ")", ":", "jid", "=", "int", "(", "choice", ")", "if", "jid", "not", "in", "range", "(", "pygame", ".", "joystick", ".", "get_count", "(", ")", ")", ":", "print", "(", "'Invalid joystick.'", ")", "continue", "break", "else", ":", "print", "(", "'What?'", ")", "return", "jid" ]
Allow user to select a joystick from a menu
[ "Allow", "user", "to", "select", "a", "joystick", "from", "a", "menu" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_joystick/findjoy.py#L40-L62
235,541
ArduPilot/MAVProxy
MAVProxy/modules/lib/MacOS/wxversion.py
select
def select(versions, optionsRequired=False): """ Search for a wxPython installation that matches version. If one is found then sys.path is modified so that version will be imported with a 'import wx', otherwise a VersionError exception is raised. This function should only be called once at the beginning of the application before wxPython is imported. :param versions: Specifies the version to look for, it can either be a string or a list of strings. Each string is compared to the installed wxPythons and the best match is inserted into the sys.path, allowing an 'import wx' to find that version. The version string is composed of the dotted version number (at least 2 of the 4 components) optionally followed by hyphen ('-') separated options (wx port, unicode/ansi, flavour, etc.) A match is determined by how much of the installed version matches what is given in the version parameter. If the version number components don't match then the score is zero, otherwise the score is increased for every specified optional component that is specified and that matches. Please note, however, that it is possible for a match to be selected that doesn't exactly match the versions requested. The only component that is required to be matched is the version number. If you need to require a match on the other components as well, then please use the optional ``optionsRequired`` parameter described next. :param optionsRequired: Allows you to specify that the other components of the version string (such as the port name or character type) are also required to be present for an installed version to be considered a match. Using this parameter allows you to change the selection from a soft, as close as possible match to a hard, exact match. """ if type(versions) == str: versions = [versions] global _selected if _selected is not None: # A version was previously selected, ensure that it matches # this new request for ver in versions: if _selected.Score(_wxPackageInfo(ver), optionsRequired) > 0: return # otherwise, raise an exception raise VersionError("A previously selected wx version does not match the new request.") # If we get here then this is the first time wxversion is used, # ensure that wxPython hasn't been imported yet. if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'): raise AlreadyImportedError("wxversion.select() must be called before wxPython is imported") # Look for a matching version and manipulate the sys.path as # needed to allow it to be imported. installed = _find_installed(True) bestMatch = _get_best_match(installed, versions, optionsRequired) if bestMatch is None: raise VersionError("Requested version of wxPython not found") sys.path.insert(0, bestMatch.pathname) # q.v. Bug #1409256 path64 = re.sub('/lib/','/lib64/',bestMatch.pathname) if os.path.isdir(path64): sys.path.insert(0, path64) _selected = bestMatch
python
def select(versions, optionsRequired=False): """ Search for a wxPython installation that matches version. If one is found then sys.path is modified so that version will be imported with a 'import wx', otherwise a VersionError exception is raised. This function should only be called once at the beginning of the application before wxPython is imported. :param versions: Specifies the version to look for, it can either be a string or a list of strings. Each string is compared to the installed wxPythons and the best match is inserted into the sys.path, allowing an 'import wx' to find that version. The version string is composed of the dotted version number (at least 2 of the 4 components) optionally followed by hyphen ('-') separated options (wx port, unicode/ansi, flavour, etc.) A match is determined by how much of the installed version matches what is given in the version parameter. If the version number components don't match then the score is zero, otherwise the score is increased for every specified optional component that is specified and that matches. Please note, however, that it is possible for a match to be selected that doesn't exactly match the versions requested. The only component that is required to be matched is the version number. If you need to require a match on the other components as well, then please use the optional ``optionsRequired`` parameter described next. :param optionsRequired: Allows you to specify that the other components of the version string (such as the port name or character type) are also required to be present for an installed version to be considered a match. Using this parameter allows you to change the selection from a soft, as close as possible match to a hard, exact match. """ if type(versions) == str: versions = [versions] global _selected if _selected is not None: # A version was previously selected, ensure that it matches # this new request for ver in versions: if _selected.Score(_wxPackageInfo(ver), optionsRequired) > 0: return # otherwise, raise an exception raise VersionError("A previously selected wx version does not match the new request.") # If we get here then this is the first time wxversion is used, # ensure that wxPython hasn't been imported yet. if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'): raise AlreadyImportedError("wxversion.select() must be called before wxPython is imported") # Look for a matching version and manipulate the sys.path as # needed to allow it to be imported. installed = _find_installed(True) bestMatch = _get_best_match(installed, versions, optionsRequired) if bestMatch is None: raise VersionError("Requested version of wxPython not found") sys.path.insert(0, bestMatch.pathname) # q.v. Bug #1409256 path64 = re.sub('/lib/','/lib64/',bestMatch.pathname) if os.path.isdir(path64): sys.path.insert(0, path64) _selected = bestMatch
[ "def", "select", "(", "versions", ",", "optionsRequired", "=", "False", ")", ":", "if", "type", "(", "versions", ")", "==", "str", ":", "versions", "=", "[", "versions", "]", "global", "_selected", "if", "_selected", "is", "not", "None", ":", "# A version was previously selected, ensure that it matches", "# this new request", "for", "ver", "in", "versions", ":", "if", "_selected", ".", "Score", "(", "_wxPackageInfo", "(", "ver", ")", ",", "optionsRequired", ")", ">", "0", ":", "return", "# otherwise, raise an exception", "raise", "VersionError", "(", "\"A previously selected wx version does not match the new request.\"", ")", "# If we get here then this is the first time wxversion is used, ", "# ensure that wxPython hasn't been imported yet.", "if", "sys", ".", "modules", ".", "has_key", "(", "'wx'", ")", "or", "sys", ".", "modules", ".", "has_key", "(", "'wxPython'", ")", ":", "raise", "AlreadyImportedError", "(", "\"wxversion.select() must be called before wxPython is imported\"", ")", "# Look for a matching version and manipulate the sys.path as", "# needed to allow it to be imported.", "installed", "=", "_find_installed", "(", "True", ")", "bestMatch", "=", "_get_best_match", "(", "installed", ",", "versions", ",", "optionsRequired", ")", "if", "bestMatch", "is", "None", ":", "raise", "VersionError", "(", "\"Requested version of wxPython not found\"", ")", "sys", ".", "path", ".", "insert", "(", "0", ",", "bestMatch", ".", "pathname", ")", "# q.v. Bug #1409256", "path64", "=", "re", ".", "sub", "(", "'/lib/'", ",", "'/lib64/'", ",", "bestMatch", ".", "pathname", ")", "if", "os", ".", "path", ".", "isdir", "(", "path64", ")", ":", "sys", ".", "path", ".", "insert", "(", "0", ",", "path64", ")", "_selected", "=", "bestMatch" ]
Search for a wxPython installation that matches version. If one is found then sys.path is modified so that version will be imported with a 'import wx', otherwise a VersionError exception is raised. This function should only be called once at the beginning of the application before wxPython is imported. :param versions: Specifies the version to look for, it can either be a string or a list of strings. Each string is compared to the installed wxPythons and the best match is inserted into the sys.path, allowing an 'import wx' to find that version. The version string is composed of the dotted version number (at least 2 of the 4 components) optionally followed by hyphen ('-') separated options (wx port, unicode/ansi, flavour, etc.) A match is determined by how much of the installed version matches what is given in the version parameter. If the version number components don't match then the score is zero, otherwise the score is increased for every specified optional component that is specified and that matches. Please note, however, that it is possible for a match to be selected that doesn't exactly match the versions requested. The only component that is required to be matched is the version number. If you need to require a match on the other components as well, then please use the optional ``optionsRequired`` parameter described next. :param optionsRequired: Allows you to specify that the other components of the version string (such as the port name or character type) are also required to be present for an installed version to be considered a match. Using this parameter allows you to change the selection from a soft, as close as possible match to a hard, exact match.
[ "Search", "for", "a", "wxPython", "installation", "that", "matches", "version", ".", "If", "one", "is", "found", "then", "sys", ".", "path", "is", "modified", "so", "that", "version", "will", "be", "imported", "with", "a", "import", "wx", "otherwise", "a", "VersionError", "exception", "is", "raised", ".", "This", "function", "should", "only", "be", "called", "once", "at", "the", "beginning", "of", "the", "application", "before", "wxPython", "is", "imported", "." ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/wxversion.py#L89-L159
235,542
ArduPilot/MAVProxy
MAVProxy/modules/lib/MacOS/wxversion.py
ensureMinimal
def ensureMinimal(minVersion, optionsRequired=False): """ Checks to see if the default version of wxPython is greater-than or equal to `minVersion`. If not then it will try to find an installed version that is >= minVersion. If none are available then a message is displayed that will inform the user and will offer to open their web browser to the wxPython downloads page, and will then exit the application. """ assert type(minVersion) == str # ensure that wxPython hasn't been imported yet. if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'): raise AlreadyImportedError("wxversion.ensureMinimal() must be called before wxPython is imported") bestMatch = None minv = _wxPackageInfo(minVersion) # check the default version first defaultPath = _find_default() if defaultPath: defv = _wxPackageInfo(defaultPath, True) if defv >= minv and minv.CheckOptions(defv, optionsRequired): bestMatch = defv # if still no match then check look at all installed versions if bestMatch is None: installed = _find_installed() # The list is in reverse sorted order, so find the first # one that is big enough and optionally matches the # options for inst in installed: if inst >= minv and minv.CheckOptions(inst, optionsRequired): bestMatch = inst break # if still no match then prompt the user if bestMatch is None: if _EM_DEBUG: # We'll do it this way just for the test code below raise VersionError("Requested version of wxPython not found") import wx, webbrowser versions = "\n".join([" "+ver for ver in getInstalled()]) app = wx.App() result = wx.MessageBox("This application requires a version of wxPython " "greater than or equal to %s, but a matching version " "was not found.\n\n" "You currently have these version(s) installed:\n%s\n\n" "Would you like to download a new version of wxPython?\n" % (minVersion, versions), "wxPython Upgrade Needed", style=wx.YES_NO) if result == wx.YES: webbrowser.open(UPDATE_URL) app.MainLoop() sys.exit() sys.path.insert(0, bestMatch.pathname) # q.v. Bug #1409256 path64 = re.sub('/lib/','/lib64/',bestMatch.pathname) if os.path.isdir(path64): sys.path.insert(0, path64) global _selected _selected = bestMatch
python
def ensureMinimal(minVersion, optionsRequired=False): """ Checks to see if the default version of wxPython is greater-than or equal to `minVersion`. If not then it will try to find an installed version that is >= minVersion. If none are available then a message is displayed that will inform the user and will offer to open their web browser to the wxPython downloads page, and will then exit the application. """ assert type(minVersion) == str # ensure that wxPython hasn't been imported yet. if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'): raise AlreadyImportedError("wxversion.ensureMinimal() must be called before wxPython is imported") bestMatch = None minv = _wxPackageInfo(minVersion) # check the default version first defaultPath = _find_default() if defaultPath: defv = _wxPackageInfo(defaultPath, True) if defv >= minv and minv.CheckOptions(defv, optionsRequired): bestMatch = defv # if still no match then check look at all installed versions if bestMatch is None: installed = _find_installed() # The list is in reverse sorted order, so find the first # one that is big enough and optionally matches the # options for inst in installed: if inst >= minv and minv.CheckOptions(inst, optionsRequired): bestMatch = inst break # if still no match then prompt the user if bestMatch is None: if _EM_DEBUG: # We'll do it this way just for the test code below raise VersionError("Requested version of wxPython not found") import wx, webbrowser versions = "\n".join([" "+ver for ver in getInstalled()]) app = wx.App() result = wx.MessageBox("This application requires a version of wxPython " "greater than or equal to %s, but a matching version " "was not found.\n\n" "You currently have these version(s) installed:\n%s\n\n" "Would you like to download a new version of wxPython?\n" % (minVersion, versions), "wxPython Upgrade Needed", style=wx.YES_NO) if result == wx.YES: webbrowser.open(UPDATE_URL) app.MainLoop() sys.exit() sys.path.insert(0, bestMatch.pathname) # q.v. Bug #1409256 path64 = re.sub('/lib/','/lib64/',bestMatch.pathname) if os.path.isdir(path64): sys.path.insert(0, path64) global _selected _selected = bestMatch
[ "def", "ensureMinimal", "(", "minVersion", ",", "optionsRequired", "=", "False", ")", ":", "assert", "type", "(", "minVersion", ")", "==", "str", "# ensure that wxPython hasn't been imported yet.", "if", "sys", ".", "modules", ".", "has_key", "(", "'wx'", ")", "or", "sys", ".", "modules", ".", "has_key", "(", "'wxPython'", ")", ":", "raise", "AlreadyImportedError", "(", "\"wxversion.ensureMinimal() must be called before wxPython is imported\"", ")", "bestMatch", "=", "None", "minv", "=", "_wxPackageInfo", "(", "minVersion", ")", "# check the default version first", "defaultPath", "=", "_find_default", "(", ")", "if", "defaultPath", ":", "defv", "=", "_wxPackageInfo", "(", "defaultPath", ",", "True", ")", "if", "defv", ">=", "minv", "and", "minv", ".", "CheckOptions", "(", "defv", ",", "optionsRequired", ")", ":", "bestMatch", "=", "defv", "# if still no match then check look at all installed versions", "if", "bestMatch", "is", "None", ":", "installed", "=", "_find_installed", "(", ")", "# The list is in reverse sorted order, so find the first", "# one that is big enough and optionally matches the", "# options", "for", "inst", "in", "installed", ":", "if", "inst", ">=", "minv", "and", "minv", ".", "CheckOptions", "(", "inst", ",", "optionsRequired", ")", ":", "bestMatch", "=", "inst", "break", "# if still no match then prompt the user", "if", "bestMatch", "is", "None", ":", "if", "_EM_DEBUG", ":", "# We'll do it this way just for the test code below", "raise", "VersionError", "(", "\"Requested version of wxPython not found\"", ")", "import", "wx", ",", "webbrowser", "versions", "=", "\"\\n\"", ".", "join", "(", "[", "\" \"", "+", "ver", "for", "ver", "in", "getInstalled", "(", ")", "]", ")", "app", "=", "wx", ".", "App", "(", ")", "result", "=", "wx", ".", "MessageBox", "(", "\"This application requires a version of wxPython \"", "\"greater than or equal to %s, but a matching version \"", "\"was not found.\\n\\n\"", "\"You currently have these version(s) installed:\\n%s\\n\\n\"", "\"Would you like to download a new version of wxPython?\\n\"", "%", "(", "minVersion", ",", "versions", ")", ",", "\"wxPython Upgrade Needed\"", ",", "style", "=", "wx", ".", "YES_NO", ")", "if", "result", "==", "wx", ".", "YES", ":", "webbrowser", ".", "open", "(", "UPDATE_URL", ")", "app", ".", "MainLoop", "(", ")", "sys", ".", "exit", "(", ")", "sys", ".", "path", ".", "insert", "(", "0", ",", "bestMatch", ".", "pathname", ")", "# q.v. Bug #1409256", "path64", "=", "re", ".", "sub", "(", "'/lib/'", ",", "'/lib64/'", ",", "bestMatch", ".", "pathname", ")", "if", "os", ".", "path", ".", "isdir", "(", "path64", ")", ":", "sys", ".", "path", ".", "insert", "(", "0", ",", "path64", ")", "global", "_selected", "_selected", "=", "bestMatch" ]
Checks to see if the default version of wxPython is greater-than or equal to `minVersion`. If not then it will try to find an installed version that is >= minVersion. If none are available then a message is displayed that will inform the user and will offer to open their web browser to the wxPython downloads page, and will then exit the application.
[ "Checks", "to", "see", "if", "the", "default", "version", "of", "wxPython", "is", "greater", "-", "than", "or", "equal", "to", "minVersion", ".", "If", "not", "then", "it", "will", "try", "to", "find", "an", "installed", "version", "that", "is", ">", "=", "minVersion", ".", "If", "none", "are", "available", "then", "a", "message", "is", "displayed", "that", "will", "inform", "the", "user", "and", "will", "offer", "to", "open", "their", "web", "browser", "to", "the", "wxPython", "downloads", "page", "and", "will", "then", "exit", "the", "application", "." ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/wxversion.py#L168-L230
235,543
ArduPilot/MAVProxy
MAVProxy/modules/lib/MacOS/wxversion.py
checkInstalled
def checkInstalled(versions, optionsRequired=False): """ Check if there is a version of wxPython installed that matches one of the versions given. Returns True if so, False if not. This can be used to determine if calling `select` will succeed or not. :param versions: Same as in `select`, either a string or a list of strings specifying the version(s) to check for. :param optionsRequired: Same as in `select`. """ if type(versions) == str: versions = [versions] installed = _find_installed() bestMatch = _get_best_match(installed, versions, optionsRequired) return bestMatch is not None
python
def checkInstalled(versions, optionsRequired=False): """ Check if there is a version of wxPython installed that matches one of the versions given. Returns True if so, False if not. This can be used to determine if calling `select` will succeed or not. :param versions: Same as in `select`, either a string or a list of strings specifying the version(s) to check for. :param optionsRequired: Same as in `select`. """ if type(versions) == str: versions = [versions] installed = _find_installed() bestMatch = _get_best_match(installed, versions, optionsRequired) return bestMatch is not None
[ "def", "checkInstalled", "(", "versions", ",", "optionsRequired", "=", "False", ")", ":", "if", "type", "(", "versions", ")", "==", "str", ":", "versions", "=", "[", "versions", "]", "installed", "=", "_find_installed", "(", ")", "bestMatch", "=", "_get_best_match", "(", "installed", ",", "versions", ",", "optionsRequired", ")", "return", "bestMatch", "is", "not", "None" ]
Check if there is a version of wxPython installed that matches one of the versions given. Returns True if so, False if not. This can be used to determine if calling `select` will succeed or not. :param versions: Same as in `select`, either a string or a list of strings specifying the version(s) to check for. :param optionsRequired: Same as in `select`.
[ "Check", "if", "there", "is", "a", "version", "of", "wxPython", "installed", "that", "matches", "one", "of", "the", "versions", "given", ".", "Returns", "True", "if", "so", "False", "if", "not", ".", "This", "can", "be", "used", "to", "determine", "if", "calling", "select", "will", "succeed", "or", "not", "." ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/wxversion.py#L235-L251
235,544
ArduPilot/MAVProxy
MAVProxy/modules/lib/MacOS/wxversion.py
getInstalled
def getInstalled(): """ Returns a list of strings representing the installed wxPython versions that are found on the system. """ installed = _find_installed() return [os.path.basename(p.pathname)[3:] for p in installed]
python
def getInstalled(): """ Returns a list of strings representing the installed wxPython versions that are found on the system. """ installed = _find_installed() return [os.path.basename(p.pathname)[3:] for p in installed]
[ "def", "getInstalled", "(", ")", ":", "installed", "=", "_find_installed", "(", ")", "return", "[", "os", ".", "path", ".", "basename", "(", "p", ".", "pathname", ")", "[", "3", ":", "]", "for", "p", "in", "installed", "]" ]
Returns a list of strings representing the installed wxPython versions that are found on the system.
[ "Returns", "a", "list", "of", "strings", "representing", "the", "installed", "wxPython", "versions", "that", "are", "found", "on", "the", "system", "." ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/wxversion.py#L255-L261
235,545
ArduPilot/MAVProxy
MAVProxy/tools/MAVExplorer.py
flightmode_colours
def flightmode_colours(): '''return mapping of flight mode to colours''' from MAVProxy.modules.lib.grapher import flightmode_colours mapping = {} idx = 0 for (mode,t0,t1) in flightmodes: if not mode in mapping: mapping[mode] = flightmode_colours[idx] idx += 1 if idx >= len(flightmode_colours): idx = 0 return mapping
python
def flightmode_colours(): '''return mapping of flight mode to colours''' from MAVProxy.modules.lib.grapher import flightmode_colours mapping = {} idx = 0 for (mode,t0,t1) in flightmodes: if not mode in mapping: mapping[mode] = flightmode_colours[idx] idx += 1 if idx >= len(flightmode_colours): idx = 0 return mapping
[ "def", "flightmode_colours", "(", ")", ":", "from", "MAVProxy", ".", "modules", ".", "lib", ".", "grapher", "import", "flightmode_colours", "mapping", "=", "{", "}", "idx", "=", "0", "for", "(", "mode", ",", "t0", ",", "t1", ")", "in", "flightmodes", ":", "if", "not", "mode", "in", "mapping", ":", "mapping", "[", "mode", "]", "=", "flightmode_colours", "[", "idx", "]", "idx", "+=", "1", "if", "idx", ">=", "len", "(", "flightmode_colours", ")", ":", "idx", "=", "0", "return", "mapping" ]
return mapping of flight mode to colours
[ "return", "mapping", "of", "flight", "mode", "to", "colours" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L279-L290
235,546
ArduPilot/MAVProxy
MAVProxy/tools/MAVExplorer.py
cmd_fft
def cmd_fft(args): '''display fft from log''' from MAVProxy.modules.lib import mav_fft if len(args) > 0: condition = args[0] else: condition = None child = multiproc.Process(target=mav_fft.mavfft_display, args=[mestate.filename,condition]) child.start()
python
def cmd_fft(args): '''display fft from log''' from MAVProxy.modules.lib import mav_fft if len(args) > 0: condition = args[0] else: condition = None child = multiproc.Process(target=mav_fft.mavfft_display, args=[mestate.filename,condition]) child.start()
[ "def", "cmd_fft", "(", "args", ")", ":", "from", "MAVProxy", ".", "modules", ".", "lib", "import", "mav_fft", "if", "len", "(", "args", ")", ">", "0", ":", "condition", "=", "args", "[", "0", "]", "else", ":", "condition", "=", "None", "child", "=", "multiproc", ".", "Process", "(", "target", "=", "mav_fft", ".", "mavfft_display", ",", "args", "=", "[", "mestate", ".", "filename", ",", "condition", "]", ")", "child", ".", "start", "(", ")" ]
display fft from log
[ "display", "fft", "from", "log" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L354-L362
235,547
ArduPilot/MAVProxy
MAVProxy/tools/MAVExplorer.py
cmd_save
def cmd_save(args): '''save a graph''' child = multiproc.Process(target=save_process, args=[mestate.last_graph, mestate.child_pipe_send_console, mestate.child_pipe_send_graph, mestate.status.msgs]) child.start()
python
def cmd_save(args): '''save a graph''' child = multiproc.Process(target=save_process, args=[mestate.last_graph, mestate.child_pipe_send_console, mestate.child_pipe_send_graph, mestate.status.msgs]) child.start()
[ "def", "cmd_save", "(", "args", ")", ":", "child", "=", "multiproc", ".", "Process", "(", "target", "=", "save_process", ",", "args", "=", "[", "mestate", ".", "last_graph", ",", "mestate", ".", "child_pipe_send_console", ",", "mestate", ".", "child_pipe_send_graph", ",", "mestate", ".", "status", ".", "msgs", "]", ")", "child", ".", "start", "(", ")" ]
save a graph
[ "save", "a", "graph" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L450-L453
235,548
ArduPilot/MAVProxy
MAVProxy/tools/MAVExplorer.py
cmd_loadfile
def cmd_loadfile(args): '''callback from menu to load a log file''' if len(args) != 1: fileargs = " ".join(args) else: fileargs = args[0] if not os.path.exists(fileargs): print("Error loading file ", fileargs); return if os.name == 'nt': #convert slashes in Windows fileargs = fileargs.replace("\\", "/") loadfile(fileargs.strip('"'))
python
def cmd_loadfile(args): '''callback from menu to load a log file''' if len(args) != 1: fileargs = " ".join(args) else: fileargs = args[0] if not os.path.exists(fileargs): print("Error loading file ", fileargs); return if os.name == 'nt': #convert slashes in Windows fileargs = fileargs.replace("\\", "/") loadfile(fileargs.strip('"'))
[ "def", "cmd_loadfile", "(", "args", ")", ":", "if", "len", "(", "args", ")", "!=", "1", ":", "fileargs", "=", "\" \"", ".", "join", "(", "args", ")", "else", ":", "fileargs", "=", "args", "[", "0", "]", "if", "not", "os", ".", "path", ".", "exists", "(", "fileargs", ")", ":", "print", "(", "\"Error loading file \"", ",", "fileargs", ")", "return", "if", "os", ".", "name", "==", "'nt'", ":", "#convert slashes in Windows", "fileargs", "=", "fileargs", ".", "replace", "(", "\"\\\\\"", ",", "\"/\"", ")", "loadfile", "(", "fileargs", ".", "strip", "(", "'\"'", ")", ")" ]
callback from menu to load a log file
[ "callback", "from", "menu", "to", "load", "a", "log", "file" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L499-L511
235,549
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_GPSInput.py
GPSInputModule.cmd_port
def cmd_port(self, args): 'handle port selection' if len(args) != 1: print("Usage: port <number>") return self.port.close() self.portnum = int(args[0]) self.port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.port.bind((self.ip, self.portnum)) self.port.setblocking(0) mavutil.set_close_on_exec(self.port.fileno()) print("Listening for GPS INPUT packets on UDP://%s:%s" % (self.ip, self.portnum))
python
def cmd_port(self, args): 'handle port selection' if len(args) != 1: print("Usage: port <number>") return self.port.close() self.portnum = int(args[0]) self.port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.port.bind((self.ip, self.portnum)) self.port.setblocking(0) mavutil.set_close_on_exec(self.port.fileno()) print("Listening for GPS INPUT packets on UDP://%s:%s" % (self.ip, self.portnum))
[ "def", "cmd_port", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "!=", "1", ":", "print", "(", "\"Usage: port <number>\"", ")", "return", "self", ".", "port", ".", "close", "(", ")", "self", ".", "portnum", "=", "int", "(", "args", "[", "0", "]", ")", "self", ".", "port", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET", ",", "socket", ".", "SOCK_DGRAM", ")", "self", ".", "port", ".", "setsockopt", "(", "socket", ".", "SOL_SOCKET", ",", "socket", ".", "SO_REUSEADDR", ",", "1", ")", "self", ".", "port", ".", "bind", "(", "(", "self", ".", "ip", ",", "self", ".", "portnum", ")", ")", "self", ".", "port", ".", "setblocking", "(", "0", ")", "mavutil", ".", "set_close_on_exec", "(", "self", ".", "port", ".", "fileno", "(", ")", ")", "print", "(", "\"Listening for GPS INPUT packets on UDP://%s:%s\"", "%", "(", "self", ".", "ip", ",", "self", ".", "portnum", ")", ")" ]
handle port selection
[ "handle", "port", "selection" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_GPSInput.py#L97-L110
235,550
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_magical/wxvehicle.py
Vehicle.RunScript
def RunScript(self, script): ''' Actuate on the vehicle through a script. The script is a sequence of commands. Each command is a sequence with the first element as the command name and the remaining values as parameters. The script is executed asynchronously by a timer with a period of 0.1 seconds. At each timer tick, the next command is executed if it's ready for execution. If a command name starts with '.', then the remaining characters are a method name and the arguments are passed to the method call. For example, the command ('.SetEuler', 0, math.pi / 2, 0) sets the vehicle nose up. The methods available for that type of command are in the class property script_available_methods. The other possible commands are: - wait(sec): wait for sec seconds. Because of the timer period, some inaccuracy is expected depending on the value of sec. - restart: go back to the first command. Example:: vehicle.RunScript(( ('.SetEuler', 0, 0, 0), # Set vehicle level ('wait', 2), # Wait for 2 seconds # Rotate continuously on the x-axis at a rate of 90 degrees per # second ('.SetAngvel', (1, 0, 0), math.pi / 2), ('wait', 5), # Let the vehicle rotating for 5 seconds ('restart',), # Restart the script )) ''' self.script = script self.script_command = 0 self.script_command_start_time = 0 self.script_command_state = 'ready' self.script_timer.Start(100) self.script_wait_time = 0
python
def RunScript(self, script): ''' Actuate on the vehicle through a script. The script is a sequence of commands. Each command is a sequence with the first element as the command name and the remaining values as parameters. The script is executed asynchronously by a timer with a period of 0.1 seconds. At each timer tick, the next command is executed if it's ready for execution. If a command name starts with '.', then the remaining characters are a method name and the arguments are passed to the method call. For example, the command ('.SetEuler', 0, math.pi / 2, 0) sets the vehicle nose up. The methods available for that type of command are in the class property script_available_methods. The other possible commands are: - wait(sec): wait for sec seconds. Because of the timer period, some inaccuracy is expected depending on the value of sec. - restart: go back to the first command. Example:: vehicle.RunScript(( ('.SetEuler', 0, 0, 0), # Set vehicle level ('wait', 2), # Wait for 2 seconds # Rotate continuously on the x-axis at a rate of 90 degrees per # second ('.SetAngvel', (1, 0, 0), math.pi / 2), ('wait', 5), # Let the vehicle rotating for 5 seconds ('restart',), # Restart the script )) ''' self.script = script self.script_command = 0 self.script_command_start_time = 0 self.script_command_state = 'ready' self.script_timer.Start(100) self.script_wait_time = 0
[ "def", "RunScript", "(", "self", ",", "script", ")", ":", "self", ".", "script", "=", "script", "self", ".", "script_command", "=", "0", "self", ".", "script_command_start_time", "=", "0", "self", ".", "script_command_state", "=", "'ready'", "self", ".", "script_timer", ".", "Start", "(", "100", ")", "self", ".", "script_wait_time", "=", "0" ]
Actuate on the vehicle through a script. The script is a sequence of commands. Each command is a sequence with the first element as the command name and the remaining values as parameters. The script is executed asynchronously by a timer with a period of 0.1 seconds. At each timer tick, the next command is executed if it's ready for execution. If a command name starts with '.', then the remaining characters are a method name and the arguments are passed to the method call. For example, the command ('.SetEuler', 0, math.pi / 2, 0) sets the vehicle nose up. The methods available for that type of command are in the class property script_available_methods. The other possible commands are: - wait(sec): wait for sec seconds. Because of the timer period, some inaccuracy is expected depending on the value of sec. - restart: go back to the first command. Example:: vehicle.RunScript(( ('.SetEuler', 0, 0, 0), # Set vehicle level ('wait', 2), # Wait for 2 seconds # Rotate continuously on the x-axis at a rate of 90 degrees per # second ('.SetAngvel', (1, 0, 0), math.pi / 2), ('wait', 5), # Let the vehicle rotating for 5 seconds ('restart',), # Restart the script ))
[ "Actuate", "on", "the", "vehicle", "through", "a", "script", ".", "The", "script", "is", "a", "sequence", "of", "commands", ".", "Each", "command", "is", "a", "sequence", "with", "the", "first", "element", "as", "the", "command", "name", "and", "the", "remaining", "values", "as", "parameters", "." ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_magical/wxvehicle.py#L140-L178
235,551
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_ppp.py
PPPModule.ppp_read
def ppp_read(self, ppp_fd): '''called from main select loop in mavproxy when the pppd child sends us some data''' buf = os.read(ppp_fd, 100) if len(buf) == 0: # EOF on the child fd self.stop_ppp_link() return print("ppp packet len=%u" % len(buf)) master = self.master master.mav.ppp_send(len(buf), buf)
python
def ppp_read(self, ppp_fd): '''called from main select loop in mavproxy when the pppd child sends us some data''' buf = os.read(ppp_fd, 100) if len(buf) == 0: # EOF on the child fd self.stop_ppp_link() return print("ppp packet len=%u" % len(buf)) master = self.master master.mav.ppp_send(len(buf), buf)
[ "def", "ppp_read", "(", "self", ",", "ppp_fd", ")", ":", "buf", "=", "os", ".", "read", "(", "ppp_fd", ",", "100", ")", "if", "len", "(", "buf", ")", "==", "0", ":", "# EOF on the child fd", "self", ".", "stop_ppp_link", "(", ")", "return", "print", "(", "\"ppp packet len=%u\"", "%", "len", "(", "buf", ")", ")", "master", "=", "self", ".", "master", "master", ".", "mav", ".", "ppp_send", "(", "len", "(", "buf", ")", ",", "buf", ")" ]
called from main select loop in mavproxy when the pppd child sends us some data
[ "called", "from", "main", "select", "loop", "in", "mavproxy", "when", "the", "pppd", "child", "sends", "us", "some", "data" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L23-L33
235,552
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_ppp.py
PPPModule.start_ppp_link
def start_ppp_link(self): '''startup the link''' cmd = ['pppd'] cmd.extend(self.command) (self.pid, self.ppp_fd) = pty.fork() if self.pid == 0: os.execvp("pppd", cmd) raise RuntimeError("pppd exited") if self.ppp_fd == -1: print("Failed to create link fd") return # ensure fd is non-blocking fcntl.fcntl(self.ppp_fd, fcntl.F_SETFL, fcntl.fcntl(self.ppp_fd, fcntl.F_GETFL) | os.O_NONBLOCK) self.byte_count = 0 self.packet_count = 0 # ask mavproxy to add us to the select loop self.mpself.select_extra[self.ppp_fd] = (self.ppp_read, self.ppp_fd)
python
def start_ppp_link(self): '''startup the link''' cmd = ['pppd'] cmd.extend(self.command) (self.pid, self.ppp_fd) = pty.fork() if self.pid == 0: os.execvp("pppd", cmd) raise RuntimeError("pppd exited") if self.ppp_fd == -1: print("Failed to create link fd") return # ensure fd is non-blocking fcntl.fcntl(self.ppp_fd, fcntl.F_SETFL, fcntl.fcntl(self.ppp_fd, fcntl.F_GETFL) | os.O_NONBLOCK) self.byte_count = 0 self.packet_count = 0 # ask mavproxy to add us to the select loop self.mpself.select_extra[self.ppp_fd] = (self.ppp_read, self.ppp_fd)
[ "def", "start_ppp_link", "(", "self", ")", ":", "cmd", "=", "[", "'pppd'", "]", "cmd", ".", "extend", "(", "self", ".", "command", ")", "(", "self", ".", "pid", ",", "self", ".", "ppp_fd", ")", "=", "pty", ".", "fork", "(", ")", "if", "self", ".", "pid", "==", "0", ":", "os", ".", "execvp", "(", "\"pppd\"", ",", "cmd", ")", "raise", "RuntimeError", "(", "\"pppd exited\"", ")", "if", "self", ".", "ppp_fd", "==", "-", "1", ":", "print", "(", "\"Failed to create link fd\"", ")", "return", "# ensure fd is non-blocking", "fcntl", ".", "fcntl", "(", "self", ".", "ppp_fd", ",", "fcntl", ".", "F_SETFL", ",", "fcntl", ".", "fcntl", "(", "self", ".", "ppp_fd", ",", "fcntl", ".", "F_GETFL", ")", "|", "os", ".", "O_NONBLOCK", ")", "self", ".", "byte_count", "=", "0", "self", ".", "packet_count", "=", "0", "# ask mavproxy to add us to the select loop", "self", ".", "mpself", ".", "select_extra", "[", "self", ".", "ppp_fd", "]", "=", "(", "self", ".", "ppp_read", ",", "self", ".", "ppp_fd", ")" ]
startup the link
[ "startup", "the", "link" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L35-L53
235,553
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_ppp.py
PPPModule.stop_ppp_link
def stop_ppp_link(self): '''stop the link''' if self.ppp_fd == -1: return try: self.mpself.select_extra.pop(self.ppp_fd) os.close(self.ppp_fd) os.waitpid(self.pid, 0) except Exception: pass self.pid = -1 self.ppp_fd = -1 print("stopped ppp link")
python
def stop_ppp_link(self): '''stop the link''' if self.ppp_fd == -1: return try: self.mpself.select_extra.pop(self.ppp_fd) os.close(self.ppp_fd) os.waitpid(self.pid, 0) except Exception: pass self.pid = -1 self.ppp_fd = -1 print("stopped ppp link")
[ "def", "stop_ppp_link", "(", "self", ")", ":", "if", "self", ".", "ppp_fd", "==", "-", "1", ":", "return", "try", ":", "self", ".", "mpself", ".", "select_extra", ".", "pop", "(", "self", ".", "ppp_fd", ")", "os", ".", "close", "(", "self", ".", "ppp_fd", ")", "os", ".", "waitpid", "(", "self", ".", "pid", ",", "0", ")", "except", "Exception", ":", "pass", "self", ".", "pid", "=", "-", "1", "self", ".", "ppp_fd", "=", "-", "1", "print", "(", "\"stopped ppp link\"", ")" ]
stop the link
[ "stop", "the", "link" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L56-L68
235,554
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_ppp.py
PPPModule.cmd_ppp
def cmd_ppp(self, args): '''set ppp parameters and start link''' usage = "ppp <command|start|stop>" if len(args) == 0: print(usage) return if args[0] == "command": if len(args) == 1: print("ppp.command=%s" % " ".join(self.command)) else: self.command = args[1:] elif args[0] == "start": self.start_ppp_link() elif args[0] == "stop": self.stop_ppp_link() elif args[0] == "status": self.console.writeln("%u packets %u bytes" % (self.packet_count, self.byte_count))
python
def cmd_ppp(self, args): '''set ppp parameters and start link''' usage = "ppp <command|start|stop>" if len(args) == 0: print(usage) return if args[0] == "command": if len(args) == 1: print("ppp.command=%s" % " ".join(self.command)) else: self.command = args[1:] elif args[0] == "start": self.start_ppp_link() elif args[0] == "stop": self.stop_ppp_link() elif args[0] == "status": self.console.writeln("%u packets %u bytes" % (self.packet_count, self.byte_count))
[ "def", "cmd_ppp", "(", "self", ",", "args", ")", ":", "usage", "=", "\"ppp <command|start|stop>\"", "if", "len", "(", "args", ")", "==", "0", ":", "print", "(", "usage", ")", "return", "if", "args", "[", "0", "]", "==", "\"command\"", ":", "if", "len", "(", "args", ")", "==", "1", ":", "print", "(", "\"ppp.command=%s\"", "%", "\" \"", ".", "join", "(", "self", ".", "command", ")", ")", "else", ":", "self", ".", "command", "=", "args", "[", "1", ":", "]", "elif", "args", "[", "0", "]", "==", "\"start\"", ":", "self", ".", "start_ppp_link", "(", ")", "elif", "args", "[", "0", "]", "==", "\"stop\"", ":", "self", ".", "stop_ppp_link", "(", ")", "elif", "args", "[", "0", "]", "==", "\"status\"", ":", "self", ".", "console", ".", "writeln", "(", "\"%u packets %u bytes\"", "%", "(", "self", ".", "packet_count", ",", "self", ".", "byte_count", ")", ")" ]
set ppp parameters and start link
[ "set", "ppp", "parameters", "and", "start", "link" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L71-L87
235,555
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.module_matching
def module_matching(self, name): '''Find a list of modules matching a wildcard pattern''' import fnmatch ret = [] for mname in self.mpstate.public_modules.keys(): if fnmatch.fnmatch(mname, name): ret.append(self.mpstate.public_modules[mname]) return ret
python
def module_matching(self, name): '''Find a list of modules matching a wildcard pattern''' import fnmatch ret = [] for mname in self.mpstate.public_modules.keys(): if fnmatch.fnmatch(mname, name): ret.append(self.mpstate.public_modules[mname]) return ret
[ "def", "module_matching", "(", "self", ",", "name", ")", ":", "import", "fnmatch", "ret", "=", "[", "]", "for", "mname", "in", "self", ".", "mpstate", ".", "public_modules", ".", "keys", "(", ")", ":", "if", "fnmatch", ".", "fnmatch", "(", "mname", ",", "name", ")", ":", "ret", ".", "append", "(", "self", ".", "mpstate", ".", "public_modules", "[", "mname", "]", ")", "return", "ret" ]
Find a list of modules matching a wildcard pattern
[ "Find", "a", "list", "of", "modules", "matching", "a", "wildcard", "pattern" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L63-L70
235,556
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.get_time
def get_time(self): '''get time, using ATTITUDE.time_boot_ms if in SITL with SIM_SPEEDUP != 1''' systime = time.time() - self.mpstate.start_time_s if not self.mpstate.is_sitl: return systime try: speedup = int(self.get_mav_param('SIM_SPEEDUP',1)) except Exception: return systime if speedup != 1: return self.mpstate.attitude_time_s return systime
python
def get_time(self): '''get time, using ATTITUDE.time_boot_ms if in SITL with SIM_SPEEDUP != 1''' systime = time.time() - self.mpstate.start_time_s if not self.mpstate.is_sitl: return systime try: speedup = int(self.get_mav_param('SIM_SPEEDUP',1)) except Exception: return systime if speedup != 1: return self.mpstate.attitude_time_s return systime
[ "def", "get_time", "(", "self", ")", ":", "systime", "=", "time", ".", "time", "(", ")", "-", "self", ".", "mpstate", ".", "start_time_s", "if", "not", "self", ".", "mpstate", ".", "is_sitl", ":", "return", "systime", "try", ":", "speedup", "=", "int", "(", "self", ".", "get_mav_param", "(", "'SIM_SPEEDUP'", ",", "1", ")", ")", "except", "Exception", ":", "return", "systime", "if", "speedup", "!=", "1", ":", "return", "self", ".", "mpstate", ".", "attitude_time_s", "return", "systime" ]
get time, using ATTITUDE.time_boot_ms if in SITL with SIM_SPEEDUP != 1
[ "get", "time", "using", "ATTITUDE", ".", "time_boot_ms", "if", "in", "SITL", "with", "SIM_SPEEDUP", "!", "=", "1" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L72-L83
235,557
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.dist_string
def dist_string(self, val_meters): '''return a distance as a string''' if self.settings.dist_unit == 'nm': return "%.1fnm" % (val_meters * 0.000539957) if self.settings.dist_unit == 'miles': return "%.1fmiles" % (val_meters * 0.000621371) return "%um" % val_meters
python
def dist_string(self, val_meters): '''return a distance as a string''' if self.settings.dist_unit == 'nm': return "%.1fnm" % (val_meters * 0.000539957) if self.settings.dist_unit == 'miles': return "%.1fmiles" % (val_meters * 0.000621371) return "%um" % val_meters
[ "def", "dist_string", "(", "self", ",", "val_meters", ")", ":", "if", "self", ".", "settings", ".", "dist_unit", "==", "'nm'", ":", "return", "\"%.1fnm\"", "%", "(", "val_meters", "*", "0.000539957", ")", "if", "self", ".", "settings", ".", "dist_unit", "==", "'miles'", ":", "return", "\"%.1fmiles\"", "%", "(", "val_meters", "*", "0.000621371", ")", "return", "\"%um\"", "%", "val_meters" ]
return a distance as a string
[ "return", "a", "distance", "as", "a", "string" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L150-L156
235,558
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.speed_convert_units
def speed_convert_units(self, val_ms): '''return a speed in configured units''' if self.settings.speed_unit == 'knots': return val_ms * 1.94384 elif self.settings.speed_unit == 'mph': return val_ms * 2.23694 return val_ms
python
def speed_convert_units(self, val_ms): '''return a speed in configured units''' if self.settings.speed_unit == 'knots': return val_ms * 1.94384 elif self.settings.speed_unit == 'mph': return val_ms * 2.23694 return val_ms
[ "def", "speed_convert_units", "(", "self", ",", "val_ms", ")", ":", "if", "self", ".", "settings", ".", "speed_unit", "==", "'knots'", ":", "return", "val_ms", "*", "1.94384", "elif", "self", ".", "settings", ".", "speed_unit", "==", "'mph'", ":", "return", "val_ms", "*", "2.23694", "return", "val_ms" ]
return a speed in configured units
[ "return", "a", "speed", "in", "configured", "units" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L170-L176
235,559
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.set_prompt
def set_prompt(self, prompt): '''set prompt for command line''' if prompt and self.settings.vehicle_name: # add in optional vehicle name prompt = self.settings.vehicle_name + ':' + prompt self.mpstate.rl.set_prompt(prompt)
python
def set_prompt(self, prompt): '''set prompt for command line''' if prompt and self.settings.vehicle_name: # add in optional vehicle name prompt = self.settings.vehicle_name + ':' + prompt self.mpstate.rl.set_prompt(prompt)
[ "def", "set_prompt", "(", "self", ",", "prompt", ")", ":", "if", "prompt", "and", "self", ".", "settings", ".", "vehicle_name", ":", "# add in optional vehicle name", "prompt", "=", "self", ".", "settings", ".", "vehicle_name", "+", "':'", "+", "prompt", "self", ".", "mpstate", ".", "rl", ".", "set_prompt", "(", "prompt", ")" ]
set prompt for command line
[ "set", "prompt", "for", "command", "line" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L184-L189
235,560
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.link_label
def link_label(link): '''return a link label as a string''' if hasattr(link, 'label'): label = link.label else: label = str(link.linknum+1) return label
python
def link_label(link): '''return a link label as a string''' if hasattr(link, 'label'): label = link.label else: label = str(link.linknum+1) return label
[ "def", "link_label", "(", "link", ")", ":", "if", "hasattr", "(", "link", ",", "'label'", ")", ":", "label", "=", "link", ".", "label", "else", ":", "label", "=", "str", "(", "link", ".", "linknum", "+", "1", ")", "return", "label" ]
return a link label as a string
[ "return", "a", "link", "label", "as", "a", "string" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L192-L198
235,561
ArduPilot/MAVProxy
MAVProxy/modules/lib/mp_module.py
MPModule.is_primary_vehicle
def is_primary_vehicle(self, msg): '''see if a msg is from our primary vehicle''' sysid = msg.get_srcSystem() if self.target_system == 0 or self.target_system == sysid: return True return False
python
def is_primary_vehicle(self, msg): '''see if a msg is from our primary vehicle''' sysid = msg.get_srcSystem() if self.target_system == 0 or self.target_system == sysid: return True return False
[ "def", "is_primary_vehicle", "(", "self", ",", "msg", ")", ":", "sysid", "=", "msg", ".", "get_srcSystem", "(", ")", "if", "self", ".", "target_system", "==", "0", "or", "self", ".", "target_system", "==", "sysid", ":", "return", "True", "return", "False" ]
see if a msg is from our primary vehicle
[ "see", "if", "a", "msg", "is", "from", "our", "primary", "vehicle" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L200-L205
235,562
ArduPilot/MAVProxy
MAVProxy/modules/lib/grapher.py
MavGraph.next_flightmode_colour
def next_flightmode_colour(self): '''allocate a colour to be used for a flight mode''' if self.flightmode_colour_index > len(flightmode_colours): print("Out of colours; reusing") self.flightmode_colour_index = 0 ret = flightmode_colours[self.flightmode_colour_index] self.flightmode_colour_index += 1 return ret
python
def next_flightmode_colour(self): '''allocate a colour to be used for a flight mode''' if self.flightmode_colour_index > len(flightmode_colours): print("Out of colours; reusing") self.flightmode_colour_index = 0 ret = flightmode_colours[self.flightmode_colour_index] self.flightmode_colour_index += 1 return ret
[ "def", "next_flightmode_colour", "(", "self", ")", ":", "if", "self", ".", "flightmode_colour_index", ">", "len", "(", "flightmode_colours", ")", ":", "print", "(", "\"Out of colours; reusing\"", ")", "self", ".", "flightmode_colour_index", "=", "0", "ret", "=", "flightmode_colours", "[", "self", ".", "flightmode_colour_index", "]", "self", ".", "flightmode_colour_index", "+=", "1", "return", "ret" ]
allocate a colour to be used for a flight mode
[ "allocate", "a", "colour", "to", "be", "used", "for", "a", "flight", "mode" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L146-L153
235,563
ArduPilot/MAVProxy
MAVProxy/modules/lib/grapher.py
MavGraph.flightmode_colour
def flightmode_colour(self, flightmode): '''return colour to be used for rendering a flight mode background''' if flightmode not in self.flightmode_colourmap: self.flightmode_colourmap[flightmode] = self.next_flightmode_colour() return self.flightmode_colourmap[flightmode]
python
def flightmode_colour(self, flightmode): '''return colour to be used for rendering a flight mode background''' if flightmode not in self.flightmode_colourmap: self.flightmode_colourmap[flightmode] = self.next_flightmode_colour() return self.flightmode_colourmap[flightmode]
[ "def", "flightmode_colour", "(", "self", ",", "flightmode", ")", ":", "if", "flightmode", "not", "in", "self", ".", "flightmode_colourmap", ":", "self", ".", "flightmode_colourmap", "[", "flightmode", "]", "=", "self", ".", "next_flightmode_colour", "(", ")", "return", "self", ".", "flightmode_colourmap", "[", "flightmode", "]" ]
return colour to be used for rendering a flight mode background
[ "return", "colour", "to", "be", "used", "for", "rendering", "a", "flight", "mode", "background" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L155-L159
235,564
ArduPilot/MAVProxy
MAVProxy/modules/lib/grapher.py
MavGraph.setup_xrange
def setup_xrange(self, xrange): '''setup plotting ticks on x axis''' if self.xaxis: return xrange *= 24 * 60 * 60 interval = 1 intervals = [ 1, 2, 5, 10, 15, 30, 60, 120, 240, 300, 600, 900, 1800, 3600, 7200, 5*3600, 10*3600, 24*3600 ] for interval in intervals: if xrange / interval < 12: break self.locator = matplotlib.dates.SecondLocator(interval=interval) self.ax1.xaxis.set_major_locator(self.locator)
python
def setup_xrange(self, xrange): '''setup plotting ticks on x axis''' if self.xaxis: return xrange *= 24 * 60 * 60 interval = 1 intervals = [ 1, 2, 5, 10, 15, 30, 60, 120, 240, 300, 600, 900, 1800, 3600, 7200, 5*3600, 10*3600, 24*3600 ] for interval in intervals: if xrange / interval < 12: break self.locator = matplotlib.dates.SecondLocator(interval=interval) self.ax1.xaxis.set_major_locator(self.locator)
[ "def", "setup_xrange", "(", "self", ",", "xrange", ")", ":", "if", "self", ".", "xaxis", ":", "return", "xrange", "*=", "24", "*", "60", "*", "60", "interval", "=", "1", "intervals", "=", "[", "1", ",", "2", ",", "5", ",", "10", ",", "15", ",", "30", ",", "60", ",", "120", ",", "240", ",", "300", ",", "600", ",", "900", ",", "1800", ",", "3600", ",", "7200", ",", "5", "*", "3600", ",", "10", "*", "3600", ",", "24", "*", "3600", "]", "for", "interval", "in", "intervals", ":", "if", "xrange", "/", "interval", "<", "12", ":", "break", "self", ".", "locator", "=", "matplotlib", ".", "dates", ".", "SecondLocator", "(", "interval", "=", "interval", ")", "self", ".", "ax1", ".", "xaxis", ".", "set_major_locator", "(", "self", ".", "locator", ")" ]
setup plotting ticks on x axis
[ "setup", "plotting", "ticks", "on", "x", "axis" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L161-L173
235,565
ArduPilot/MAVProxy
MAVProxy/modules/lib/grapher.py
MavGraph.xlim_changed
def xlim_changed(self, axsubplot): '''called when x limits are changed''' xrange = axsubplot.get_xbound() xlim = axsubplot.get_xlim() self.setup_xrange(xrange[1] - xrange[0]) if self.draw_events == 0: # ignore limit change before first draw event return if self.xlim_pipe is not None and axsubplot == self.ax1 and xlim != self.xlim: self.xlim = xlim #print('send', self.graph_num, xlim) self.xlim_pipe[1].send(xlim)
python
def xlim_changed(self, axsubplot): '''called when x limits are changed''' xrange = axsubplot.get_xbound() xlim = axsubplot.get_xlim() self.setup_xrange(xrange[1] - xrange[0]) if self.draw_events == 0: # ignore limit change before first draw event return if self.xlim_pipe is not None and axsubplot == self.ax1 and xlim != self.xlim: self.xlim = xlim #print('send', self.graph_num, xlim) self.xlim_pipe[1].send(xlim)
[ "def", "xlim_changed", "(", "self", ",", "axsubplot", ")", ":", "xrange", "=", "axsubplot", ".", "get_xbound", "(", ")", "xlim", "=", "axsubplot", ".", "get_xlim", "(", ")", "self", ".", "setup_xrange", "(", "xrange", "[", "1", "]", "-", "xrange", "[", "0", "]", ")", "if", "self", ".", "draw_events", "==", "0", ":", "# ignore limit change before first draw event", "return", "if", "self", ".", "xlim_pipe", "is", "not", "None", "and", "axsubplot", "==", "self", ".", "ax1", "and", "xlim", "!=", "self", ".", "xlim", ":", "self", ".", "xlim", "=", "xlim", "#print('send', self.graph_num, xlim)", "self", ".", "xlim_pipe", "[", "1", "]", ".", "send", "(", "xlim", ")" ]
called when x limits are changed
[ "called", "when", "x", "limits", "are", "changed" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L175-L186
235,566
ArduPilot/MAVProxy
MAVProxy/modules/lib/grapher.py
MavGraph.timestamp_to_days
def timestamp_to_days(self, timestamp): '''convert log timestamp to days''' if self.tday_base is None: try: self.tday_base = matplotlib.dates.date2num(datetime.datetime.fromtimestamp(timestamp+self.timeshift)) self.tday_basetime = timestamp except ValueError: # this can happen if the log is corrupt # ValueError: year is out of range return 0 sec_to_days = 1.0 / (60*60*24) return self.tday_base + (timestamp - self.tday_basetime) * sec_to_days
python
def timestamp_to_days(self, timestamp): '''convert log timestamp to days''' if self.tday_base is None: try: self.tday_base = matplotlib.dates.date2num(datetime.datetime.fromtimestamp(timestamp+self.timeshift)) self.tday_basetime = timestamp except ValueError: # this can happen if the log is corrupt # ValueError: year is out of range return 0 sec_to_days = 1.0 / (60*60*24) return self.tday_base + (timestamp - self.tday_basetime) * sec_to_days
[ "def", "timestamp_to_days", "(", "self", ",", "timestamp", ")", ":", "if", "self", ".", "tday_base", "is", "None", ":", "try", ":", "self", ".", "tday_base", "=", "matplotlib", ".", "dates", ".", "date2num", "(", "datetime", ".", "datetime", ".", "fromtimestamp", "(", "timestamp", "+", "self", ".", "timeshift", ")", ")", "self", ".", "tday_basetime", "=", "timestamp", "except", "ValueError", ":", "# this can happen if the log is corrupt", "# ValueError: year is out of range", "return", "0", "sec_to_days", "=", "1.0", "/", "(", "60", "*", "60", "*", "24", ")", "return", "self", ".", "tday_base", "+", "(", "timestamp", "-", "self", ".", "tday_basetime", ")", "*", "sec_to_days" ]
convert log timestamp to days
[ "convert", "log", "timestamp", "to", "days" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L362-L373
235,567
ArduPilot/MAVProxy
MAVProxy/modules/lib/grapher.py
MavGraph.xlim_change_check
def xlim_change_check(self, idx): '''handle xlim change requests from queue''' if not self.xlim_pipe[1].poll(): return xlim = self.xlim_pipe[1].recv() if xlim is None: return #print("recv: ", self.graph_num, xlim) if self.ax1 is not None and xlim != self.xlim: self.xlim = xlim self.fig.canvas.toolbar.push_current() #print("setting: ", self.graph_num, xlim) self.ax1.set_xlim(xlim) # trigger the timer, this allows us to setup a v slow animation, # which saves a lot of CPU self.ani.event_source._on_timer()
python
def xlim_change_check(self, idx): '''handle xlim change requests from queue''' if not self.xlim_pipe[1].poll(): return xlim = self.xlim_pipe[1].recv() if xlim is None: return #print("recv: ", self.graph_num, xlim) if self.ax1 is not None and xlim != self.xlim: self.xlim = xlim self.fig.canvas.toolbar.push_current() #print("setting: ", self.graph_num, xlim) self.ax1.set_xlim(xlim) # trigger the timer, this allows us to setup a v slow animation, # which saves a lot of CPU self.ani.event_source._on_timer()
[ "def", "xlim_change_check", "(", "self", ",", "idx", ")", ":", "if", "not", "self", ".", "xlim_pipe", "[", "1", "]", ".", "poll", "(", ")", ":", "return", "xlim", "=", "self", ".", "xlim_pipe", "[", "1", "]", ".", "recv", "(", ")", "if", "xlim", "is", "None", ":", "return", "#print(\"recv: \", self.graph_num, xlim)", "if", "self", ".", "ax1", "is", "not", "None", "and", "xlim", "!=", "self", ".", "xlim", ":", "self", ".", "xlim", "=", "xlim", "self", ".", "fig", ".", "canvas", ".", "toolbar", ".", "push_current", "(", ")", "#print(\"setting: \", self.graph_num, xlim)", "self", ".", "ax1", ".", "set_xlim", "(", "xlim", ")", "# trigger the timer, this allows us to setup a v slow animation,", "# which saves a lot of CPU", "self", ".", "ani", ".", "event_source", ".", "_on_timer", "(", ")" ]
handle xlim change requests from queue
[ "handle", "xlim", "change", "requests", "from", "queue" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L429-L444
235,568
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_misc.py
MiscModule.cmd_lockup_autopilot
def cmd_lockup_autopilot(self, args): '''lockup autopilot for watchdog testing''' if len(args) > 0 and args[0] == 'IREALLYMEANIT': print("Sending lockup command") self.master.mav.command_long_send(self.settings.target_system, self.settings.target_component, mavutil.mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0, 42, 24, 71, 93, 0, 0, 0) else: print("Invalid lockup command")
python
def cmd_lockup_autopilot(self, args): '''lockup autopilot for watchdog testing''' if len(args) > 0 and args[0] == 'IREALLYMEANIT': print("Sending lockup command") self.master.mav.command_long_send(self.settings.target_system, self.settings.target_component, mavutil.mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0, 42, 24, 71, 93, 0, 0, 0) else: print("Invalid lockup command")
[ "def", "cmd_lockup_autopilot", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", ">", "0", "and", "args", "[", "0", "]", "==", "'IREALLYMEANIT'", ":", "print", "(", "\"Sending lockup command\"", ")", "self", ".", "master", ".", "mav", ".", "command_long_send", "(", "self", ".", "settings", ".", "target_system", ",", "self", ".", "settings", ".", "target_component", ",", "mavutil", ".", "mavlink", ".", "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN", ",", "0", ",", "42", ",", "24", ",", "71", ",", "93", ",", "0", ",", "0", ",", "0", ")", "else", ":", "print", "(", "\"Invalid lockup command\"", ")" ]
lockup autopilot for watchdog testing
[ "lockup", "autopilot", "for", "watchdog", "testing" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L147-L155
235,569
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_misc.py
MiscModule.cmd_gethome
def cmd_gethome(self, args): '''get home position''' self.master.mav.command_long_send(self.settings.target_system, 0, mavutil.mavlink.MAV_CMD_GET_HOME_POSITION, 0, 0, 0, 0, 0, 0, 0, 0)
python
def cmd_gethome(self, args): '''get home position''' self.master.mav.command_long_send(self.settings.target_system, 0, mavutil.mavlink.MAV_CMD_GET_HOME_POSITION, 0, 0, 0, 0, 0, 0, 0, 0)
[ "def", "cmd_gethome", "(", "self", ",", "args", ")", ":", "self", ".", "master", ".", "mav", ".", "command_long_send", "(", "self", ".", "settings", ".", "target_system", ",", "0", ",", "mavutil", ".", "mavlink", ".", "MAV_CMD_GET_HOME_POSITION", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ")" ]
get home position
[ "get", "home", "position" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L215-L220
235,570
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_misc.py
MiscModule.cmd_led
def cmd_led(self, args): '''send LED pattern as override''' if len(args) < 3: print("Usage: led RED GREEN BLUE <RATE>") return pattern = [0] * 24 pattern[0] = int(args[0]) pattern[1] = int(args[1]) pattern[2] = int(args[2]) if len(args) == 4: plen = 4 pattern[3] = int(args[3]) else: plen = 3 self.master.mav.led_control_send(self.settings.target_system, self.settings.target_component, 0, 0, plen, pattern)
python
def cmd_led(self, args): '''send LED pattern as override''' if len(args) < 3: print("Usage: led RED GREEN BLUE <RATE>") return pattern = [0] * 24 pattern[0] = int(args[0]) pattern[1] = int(args[1]) pattern[2] = int(args[2]) if len(args) == 4: plen = 4 pattern[3] = int(args[3]) else: plen = 3 self.master.mav.led_control_send(self.settings.target_system, self.settings.target_component, 0, 0, plen, pattern)
[ "def", "cmd_led", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "<", "3", ":", "print", "(", "\"Usage: led RED GREEN BLUE <RATE>\"", ")", "return", "pattern", "=", "[", "0", "]", "*", "24", "pattern", "[", "0", "]", "=", "int", "(", "args", "[", "0", "]", ")", "pattern", "[", "1", "]", "=", "int", "(", "args", "[", "1", "]", ")", "pattern", "[", "2", "]", "=", "int", "(", "args", "[", "2", "]", ")", "if", "len", "(", "args", ")", "==", "4", ":", "plen", "=", "4", "pattern", "[", "3", "]", "=", "int", "(", "args", "[", "3", "]", ")", "else", ":", "plen", "=", "3", "self", ".", "master", ".", "mav", ".", "led_control_send", "(", "self", ".", "settings", ".", "target_system", ",", "self", ".", "settings", ".", "target_component", ",", "0", ",", "0", ",", "plen", ",", "pattern", ")" ]
send LED pattern as override
[ "send", "LED", "pattern", "as", "override" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L222-L240
235,571
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_misc.py
MiscModule.cmd_oreoled
def cmd_oreoled(self, args): '''send LED pattern as override, using OreoLED conventions''' if len(args) < 4: print("Usage: oreoled LEDNUM RED GREEN BLUE <RATE>") return lednum = int(args[0]) pattern = [0] * 24 pattern[0] = ord('R') pattern[1] = ord('G') pattern[2] = ord('B') pattern[3] = ord('0') pattern[4] = 0 pattern[5] = int(args[1]) pattern[6] = int(args[2]) pattern[7] = int(args[3]) self.master.mav.led_control_send(self.settings.target_system, self.settings.target_component, lednum, 255, 8, pattern)
python
def cmd_oreoled(self, args): '''send LED pattern as override, using OreoLED conventions''' if len(args) < 4: print("Usage: oreoled LEDNUM RED GREEN BLUE <RATE>") return lednum = int(args[0]) pattern = [0] * 24 pattern[0] = ord('R') pattern[1] = ord('G') pattern[2] = ord('B') pattern[3] = ord('0') pattern[4] = 0 pattern[5] = int(args[1]) pattern[6] = int(args[2]) pattern[7] = int(args[3]) self.master.mav.led_control_send(self.settings.target_system, self.settings.target_component, lednum, 255, 8, pattern)
[ "def", "cmd_oreoled", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "<", "4", ":", "print", "(", "\"Usage: oreoled LEDNUM RED GREEN BLUE <RATE>\"", ")", "return", "lednum", "=", "int", "(", "args", "[", "0", "]", ")", "pattern", "=", "[", "0", "]", "*", "24", "pattern", "[", "0", "]", "=", "ord", "(", "'R'", ")", "pattern", "[", "1", "]", "=", "ord", "(", "'G'", ")", "pattern", "[", "2", "]", "=", "ord", "(", "'B'", ")", "pattern", "[", "3", "]", "=", "ord", "(", "'0'", ")", "pattern", "[", "4", "]", "=", "0", "pattern", "[", "5", "]", "=", "int", "(", "args", "[", "1", "]", ")", "pattern", "[", "6", "]", "=", "int", "(", "args", "[", "2", "]", ")", "pattern", "[", "7", "]", "=", "int", "(", "args", "[", "3", "]", ")", "self", ".", "master", ".", "mav", ".", "led_control_send", "(", "self", ".", "settings", ".", "target_system", ",", "self", ".", "settings", ".", "target_component", ",", "lednum", ",", "255", ",", "8", ",", "pattern", ")" ]
send LED pattern as override, using OreoLED conventions
[ "send", "LED", "pattern", "as", "override", "using", "OreoLED", "conventions" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L242-L260
235,572
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_misc.py
MiscModule.cmd_playtune
def cmd_playtune(self, args): '''send PLAY_TUNE message''' if len(args) < 1: print("Usage: playtune TUNE") return tune = args[0] str1 = tune[0:30] str2 = tune[30:] if sys.version_info.major >= 3 and not isinstance(str1, bytes): str1 = bytes(str1, "ascii") if sys.version_info.major >= 3 and not isinstance(str2, bytes): str2 = bytes(str2, "ascii") self.master.mav.play_tune_send(self.settings.target_system, self.settings.target_component, str1, str2)
python
def cmd_playtune(self, args): '''send PLAY_TUNE message''' if len(args) < 1: print("Usage: playtune TUNE") return tune = args[0] str1 = tune[0:30] str2 = tune[30:] if sys.version_info.major >= 3 and not isinstance(str1, bytes): str1 = bytes(str1, "ascii") if sys.version_info.major >= 3 and not isinstance(str2, bytes): str2 = bytes(str2, "ascii") self.master.mav.play_tune_send(self.settings.target_system, self.settings.target_component, str1, str2)
[ "def", "cmd_playtune", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "<", "1", ":", "print", "(", "\"Usage: playtune TUNE\"", ")", "return", "tune", "=", "args", "[", "0", "]", "str1", "=", "tune", "[", "0", ":", "30", "]", "str2", "=", "tune", "[", "30", ":", "]", "if", "sys", ".", "version_info", ".", "major", ">=", "3", "and", "not", "isinstance", "(", "str1", ",", "bytes", ")", ":", "str1", "=", "bytes", "(", "str1", ",", "\"ascii\"", ")", "if", "sys", ".", "version_info", ".", "major", ">=", "3", "and", "not", "isinstance", "(", "str2", ",", "bytes", ")", ":", "str2", "=", "bytes", "(", "str2", ",", "\"ascii\"", ")", "self", ".", "master", ".", "mav", ".", "play_tune_send", "(", "self", ".", "settings", ".", "target_system", ",", "self", ".", "settings", ".", "target_component", ",", "str1", ",", "str2", ")" ]
send PLAY_TUNE message
[ "send", "PLAY_TUNE", "message" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L269-L283
235,573
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_misc.py
MiscModule.cmd_devid
def cmd_devid(self, args): '''decode device IDs from parameters''' for p in self.mav_param.keys(): if p.startswith('COMPASS_DEV_ID'): mp_util.decode_devid(self.mav_param[p], p) if p.startswith('INS_') and p.endswith('_ID'): mp_util.decode_devid(self.mav_param[p], p)
python
def cmd_devid(self, args): '''decode device IDs from parameters''' for p in self.mav_param.keys(): if p.startswith('COMPASS_DEV_ID'): mp_util.decode_devid(self.mav_param[p], p) if p.startswith('INS_') and p.endswith('_ID'): mp_util.decode_devid(self.mav_param[p], p)
[ "def", "cmd_devid", "(", "self", ",", "args", ")", ":", "for", "p", "in", "self", ".", "mav_param", ".", "keys", "(", ")", ":", "if", "p", ".", "startswith", "(", "'COMPASS_DEV_ID'", ")", ":", "mp_util", ".", "decode_devid", "(", "self", ".", "mav_param", "[", "p", "]", ",", "p", ")", "if", "p", ".", "startswith", "(", "'INS_'", ")", "and", "p", ".", "endswith", "(", "'_ID'", ")", ":", "mp_util", ".", "decode_devid", "(", "self", ".", "mav_param", "[", "p", "]", ",", "p", ")" ]
decode device IDs from parameters
[ "decode", "device", "IDs", "from", "parameters" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L314-L320
235,574
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.add_menu
def add_menu(self, menu): '''add to the default popup menu''' from MAVProxy.modules.mavproxy_map import mp_slipmap self.default_popup.add(menu) self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True))
python
def add_menu(self, menu): '''add to the default popup menu''' from MAVProxy.modules.mavproxy_map import mp_slipmap self.default_popup.add(menu) self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True))
[ "def", "add_menu", "(", "self", ",", "menu", ")", ":", "from", "MAVProxy", ".", "modules", ".", "mavproxy_map", "import", "mp_slipmap", "self", ".", "default_popup", ".", "add", "(", "menu", ")", "self", ".", "map", ".", "add_object", "(", "mp_slipmap", ".", "SlipDefaultPopup", "(", "self", ".", "default_popup", ",", "combine", "=", "True", ")", ")" ]
add to the default popup menu
[ "add", "to", "the", "default", "popup", "menu" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L114-L118
235,575
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.colour_for_wp
def colour_for_wp(self, wp_num): '''return a tuple describing the colour a waypoint should appear on the map''' wp = self.module('wp').wploader.wp(wp_num) command = wp.command return self._colour_for_wp_command.get(command, (0,255,0))
python
def colour_for_wp(self, wp_num): '''return a tuple describing the colour a waypoint should appear on the map''' wp = self.module('wp').wploader.wp(wp_num) command = wp.command return self._colour_for_wp_command.get(command, (0,255,0))
[ "def", "colour_for_wp", "(", "self", ",", "wp_num", ")", ":", "wp", "=", "self", ".", "module", "(", "'wp'", ")", ".", "wploader", ".", "wp", "(", "wp_num", ")", "command", "=", "wp", ".", "command", "return", "self", ".", "_colour_for_wp_command", ".", "get", "(", "command", ",", "(", "0", ",", "255", ",", "0", ")", ")" ]
return a tuple describing the colour a waypoint should appear on the map
[ "return", "a", "tuple", "describing", "the", "colour", "a", "waypoint", "should", "appear", "on", "the", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L175-L179
235,576
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.label_for_waypoint
def label_for_waypoint(self, wp_num): '''return the label the waypoint which should appear on the map''' wp = self.module('wp').wploader.wp(wp_num) command = wp.command if command not in self._label_suffix_for_wp_command: return str(wp_num) return str(wp_num) + "(" + self._label_suffix_for_wp_command[command] + ")"
python
def label_for_waypoint(self, wp_num): '''return the label the waypoint which should appear on the map''' wp = self.module('wp').wploader.wp(wp_num) command = wp.command if command not in self._label_suffix_for_wp_command: return str(wp_num) return str(wp_num) + "(" + self._label_suffix_for_wp_command[command] + ")"
[ "def", "label_for_waypoint", "(", "self", ",", "wp_num", ")", ":", "wp", "=", "self", ".", "module", "(", "'wp'", ")", ".", "wploader", ".", "wp", "(", "wp_num", ")", "command", "=", "wp", ".", "command", "if", "command", "not", "in", "self", ".", "_label_suffix_for_wp_command", ":", "return", "str", "(", "wp_num", ")", "return", "str", "(", "wp_num", ")", "+", "\"(\"", "+", "self", ".", "_label_suffix_for_wp_command", "[", "command", "]", "+", "\")\"" ]
return the label the waypoint which should appear on the map
[ "return", "the", "label", "the", "waypoint", "which", "should", "appear", "on", "the", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L181-L187
235,577
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.remove_mission_nofly
def remove_mission_nofly(self, key, selection_index): '''remove a mission nofly polygon''' if not self.validate_nofly(): print("NoFly invalid") return print("NoFly valid") idx = self.selection_index_to_idx(key, selection_index) wploader = self.module('wp').wploader if idx < 0 or idx >= wploader.count(): print("Invalid wp number %u" % idx) return wp = wploader.wp(idx) if wp.command != mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION: print("Not an exclusion point (%u)" % idx) return # we know the list is valid. Search for the start of the sequence to delete tmp_idx = idx while tmp_idx > 0: tmp = wploader.wp(tmp_idx-1) if (tmp.command != wp.command or tmp.param1 != wp.param1): break tmp_idx -= 1 start_idx_to_delete = idx - ((idx-tmp_idx)%int(wp.param1)) for i in range(int(start_idx_to_delete+wp.param1)-1,start_idx_to_delete-1,-1): # remove in reverse order as wploader.remove re-indexes print("Removing at %u" % i) deadun = wploader.wp(i) wploader.remove(deadun) self.module('wp').send_all_waypoints()
python
def remove_mission_nofly(self, key, selection_index): '''remove a mission nofly polygon''' if not self.validate_nofly(): print("NoFly invalid") return print("NoFly valid") idx = self.selection_index_to_idx(key, selection_index) wploader = self.module('wp').wploader if idx < 0 or idx >= wploader.count(): print("Invalid wp number %u" % idx) return wp = wploader.wp(idx) if wp.command != mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION: print("Not an exclusion point (%u)" % idx) return # we know the list is valid. Search for the start of the sequence to delete tmp_idx = idx while tmp_idx > 0: tmp = wploader.wp(tmp_idx-1) if (tmp.command != wp.command or tmp.param1 != wp.param1): break tmp_idx -= 1 start_idx_to_delete = idx - ((idx-tmp_idx)%int(wp.param1)) for i in range(int(start_idx_to_delete+wp.param1)-1,start_idx_to_delete-1,-1): # remove in reverse order as wploader.remove re-indexes print("Removing at %u" % i) deadun = wploader.wp(i) wploader.remove(deadun) self.module('wp').send_all_waypoints()
[ "def", "remove_mission_nofly", "(", "self", ",", "key", ",", "selection_index", ")", ":", "if", "not", "self", ".", "validate_nofly", "(", ")", ":", "print", "(", "\"NoFly invalid\"", ")", "return", "print", "(", "\"NoFly valid\"", ")", "idx", "=", "self", ".", "selection_index_to_idx", "(", "key", ",", "selection_index", ")", "wploader", "=", "self", ".", "module", "(", "'wp'", ")", ".", "wploader", "if", "idx", "<", "0", "or", "idx", ">=", "wploader", ".", "count", "(", ")", ":", "print", "(", "\"Invalid wp number %u\"", "%", "idx", ")", "return", "wp", "=", "wploader", ".", "wp", "(", "idx", ")", "if", "wp", ".", "command", "!=", "mavutil", ".", "mavlink", ".", "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION", ":", "print", "(", "\"Not an exclusion point (%u)\"", "%", "idx", ")", "return", "# we know the list is valid. Search for the start of the sequence to delete", "tmp_idx", "=", "idx", "while", "tmp_idx", ">", "0", ":", "tmp", "=", "wploader", ".", "wp", "(", "tmp_idx", "-", "1", ")", "if", "(", "tmp", ".", "command", "!=", "wp", ".", "command", "or", "tmp", ".", "param1", "!=", "wp", ".", "param1", ")", ":", "break", "tmp_idx", "-=", "1", "start_idx_to_delete", "=", "idx", "-", "(", "(", "idx", "-", "tmp_idx", ")", "%", "int", "(", "wp", ".", "param1", ")", ")", "for", "i", "in", "range", "(", "int", "(", "start_idx_to_delete", "+", "wp", ".", "param1", ")", "-", "1", ",", "start_idx_to_delete", "-", "1", ",", "-", "1", ")", ":", "# remove in reverse order as wploader.remove re-indexes", "print", "(", "\"Removing at %u\"", "%", "i", ")", "deadun", "=", "wploader", ".", "wp", "(", "i", ")", "wploader", ".", "remove", "(", "deadun", ")", "self", ".", "module", "(", "'wp'", ")", ".", "send_all_waypoints", "(", ")" ]
remove a mission nofly polygon
[ "remove", "a", "mission", "nofly", "polygon" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L345-L378
235,578
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.handle_menu_event
def handle_menu_event(self, obj): '''handle a popup menu event from the map''' menuitem = obj.menuitem if menuitem.returnkey.startswith('# '): cmd = menuitem.returnkey[2:] if menuitem.handler is not None: if menuitem.handler_result is None: return cmd += menuitem.handler_result self.mpstate.functions.process_stdin(cmd) elif menuitem.returnkey == 'popupRallyRemove': self.remove_rally(obj.selected[0].objkey) elif menuitem.returnkey == 'popupRallyMove': self.move_rally(obj.selected[0].objkey) elif menuitem.returnkey == 'popupMissionSet': self.set_mission(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupMissionRemoveNoFly': self.remove_mission_nofly(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupMissionRemove': self.remove_mission(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupMissionMove': self.move_mission(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupFenceRemove': self.remove_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupFenceMove': self.move_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'showPosition': self.show_position()
python
def handle_menu_event(self, obj): '''handle a popup menu event from the map''' menuitem = obj.menuitem if menuitem.returnkey.startswith('# '): cmd = menuitem.returnkey[2:] if menuitem.handler is not None: if menuitem.handler_result is None: return cmd += menuitem.handler_result self.mpstate.functions.process_stdin(cmd) elif menuitem.returnkey == 'popupRallyRemove': self.remove_rally(obj.selected[0].objkey) elif menuitem.returnkey == 'popupRallyMove': self.move_rally(obj.selected[0].objkey) elif menuitem.returnkey == 'popupMissionSet': self.set_mission(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupMissionRemoveNoFly': self.remove_mission_nofly(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupMissionRemove': self.remove_mission(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupMissionMove': self.move_mission(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupFenceRemove': self.remove_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'popupFenceMove': self.move_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info) elif menuitem.returnkey == 'showPosition': self.show_position()
[ "def", "handle_menu_event", "(", "self", ",", "obj", ")", ":", "menuitem", "=", "obj", ".", "menuitem", "if", "menuitem", ".", "returnkey", ".", "startswith", "(", "'# '", ")", ":", "cmd", "=", "menuitem", ".", "returnkey", "[", "2", ":", "]", "if", "menuitem", ".", "handler", "is", "not", "None", ":", "if", "menuitem", ".", "handler_result", "is", "None", ":", "return", "cmd", "+=", "menuitem", ".", "handler_result", "self", ".", "mpstate", ".", "functions", ".", "process_stdin", "(", "cmd", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupRallyRemove'", ":", "self", ".", "remove_rally", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupRallyMove'", ":", "self", ".", "move_rally", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupMissionSet'", ":", "self", ".", "set_mission", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ",", "obj", ".", "selected", "[", "0", "]", ".", "extra_info", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupMissionRemoveNoFly'", ":", "self", ".", "remove_mission_nofly", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ",", "obj", ".", "selected", "[", "0", "]", ".", "extra_info", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupMissionRemove'", ":", "self", ".", "remove_mission", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ",", "obj", ".", "selected", "[", "0", "]", ".", "extra_info", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupMissionMove'", ":", "self", ".", "move_mission", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ",", "obj", ".", "selected", "[", "0", "]", ".", "extra_info", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupFenceRemove'", ":", "self", ".", "remove_fencepoint", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ",", "obj", ".", "selected", "[", "0", "]", ".", "extra_info", ")", "elif", "menuitem", ".", "returnkey", "==", "'popupFenceMove'", ":", "self", ".", "move_fencepoint", "(", "obj", ".", "selected", "[", "0", "]", ".", "objkey", ",", "obj", ".", "selected", "[", "0", "]", ".", "extra_info", ")", "elif", "menuitem", ".", "returnkey", "==", "'showPosition'", ":", "self", ".", "show_position", "(", ")" ]
handle a popup menu event from the map
[ "handle", "a", "popup", "menu", "event", "from", "the", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L394-L421
235,579
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.map_callback
def map_callback(self, obj): '''called when an event happens on the slipmap''' from MAVProxy.modules.mavproxy_map import mp_slipmap if isinstance(obj, mp_slipmap.SlipMenuEvent): self.handle_menu_event(obj) return if not isinstance(obj, mp_slipmap.SlipMouseEvent): return if obj.event.leftIsDown and self.moving_rally is not None: self.click_position = obj.latlon self.click_time = time.time() self.mpstate.functions.process_stdin("rally move %u" % self.moving_rally) self.moving_rally = None return if obj.event.rightIsDown and self.moving_rally is not None: print("Cancelled rally move") self.moving_rally = None return if obj.event.leftIsDown and self.moving_wp is not None: self.click_position = obj.latlon self.click_time = time.time() self.mpstate.functions.process_stdin("wp move %u" % self.moving_wp) self.moving_wp = None return if obj.event.leftIsDown and self.moving_fencepoint is not None: self.click_position = obj.latlon self.click_time = time.time() self.mpstate.functions.process_stdin("fence move %u" % (self.moving_fencepoint+1)) self.moving_fencepoint = None return if obj.event.rightIsDown and self.moving_wp is not None: print("Cancelled wp move") self.moving_wp = None return if obj.event.rightIsDown and self.moving_fencepoint is not None: print("Cancelled fence move") self.moving_fencepoint = None return elif obj.event.leftIsDown: if time.time() - self.click_time > 0.1: self.click_position = obj.latlon self.click_time = time.time() self.drawing_update() if self.module('misseditor') is not None: self.module('misseditor').update_map_click_position(self.click_position) if obj.event.rightIsDown: if self.draw_callback is not None: self.drawing_end() return if time.time() - self.click_time > 0.1: self.click_position = obj.latlon self.click_time = time.time()
python
def map_callback(self, obj): '''called when an event happens on the slipmap''' from MAVProxy.modules.mavproxy_map import mp_slipmap if isinstance(obj, mp_slipmap.SlipMenuEvent): self.handle_menu_event(obj) return if not isinstance(obj, mp_slipmap.SlipMouseEvent): return if obj.event.leftIsDown and self.moving_rally is not None: self.click_position = obj.latlon self.click_time = time.time() self.mpstate.functions.process_stdin("rally move %u" % self.moving_rally) self.moving_rally = None return if obj.event.rightIsDown and self.moving_rally is not None: print("Cancelled rally move") self.moving_rally = None return if obj.event.leftIsDown and self.moving_wp is not None: self.click_position = obj.latlon self.click_time = time.time() self.mpstate.functions.process_stdin("wp move %u" % self.moving_wp) self.moving_wp = None return if obj.event.leftIsDown and self.moving_fencepoint is not None: self.click_position = obj.latlon self.click_time = time.time() self.mpstate.functions.process_stdin("fence move %u" % (self.moving_fencepoint+1)) self.moving_fencepoint = None return if obj.event.rightIsDown and self.moving_wp is not None: print("Cancelled wp move") self.moving_wp = None return if obj.event.rightIsDown and self.moving_fencepoint is not None: print("Cancelled fence move") self.moving_fencepoint = None return elif obj.event.leftIsDown: if time.time() - self.click_time > 0.1: self.click_position = obj.latlon self.click_time = time.time() self.drawing_update() if self.module('misseditor') is not None: self.module('misseditor').update_map_click_position(self.click_position) if obj.event.rightIsDown: if self.draw_callback is not None: self.drawing_end() return if time.time() - self.click_time > 0.1: self.click_position = obj.latlon self.click_time = time.time()
[ "def", "map_callback", "(", "self", ",", "obj", ")", ":", "from", "MAVProxy", ".", "modules", ".", "mavproxy_map", "import", "mp_slipmap", "if", "isinstance", "(", "obj", ",", "mp_slipmap", ".", "SlipMenuEvent", ")", ":", "self", ".", "handle_menu_event", "(", "obj", ")", "return", "if", "not", "isinstance", "(", "obj", ",", "mp_slipmap", ".", "SlipMouseEvent", ")", ":", "return", "if", "obj", ".", "event", ".", "leftIsDown", "and", "self", ".", "moving_rally", "is", "not", "None", ":", "self", ".", "click_position", "=", "obj", ".", "latlon", "self", ".", "click_time", "=", "time", ".", "time", "(", ")", "self", ".", "mpstate", ".", "functions", ".", "process_stdin", "(", "\"rally move %u\"", "%", "self", ".", "moving_rally", ")", "self", ".", "moving_rally", "=", "None", "return", "if", "obj", ".", "event", ".", "rightIsDown", "and", "self", ".", "moving_rally", "is", "not", "None", ":", "print", "(", "\"Cancelled rally move\"", ")", "self", ".", "moving_rally", "=", "None", "return", "if", "obj", ".", "event", ".", "leftIsDown", "and", "self", ".", "moving_wp", "is", "not", "None", ":", "self", ".", "click_position", "=", "obj", ".", "latlon", "self", ".", "click_time", "=", "time", ".", "time", "(", ")", "self", ".", "mpstate", ".", "functions", ".", "process_stdin", "(", "\"wp move %u\"", "%", "self", ".", "moving_wp", ")", "self", ".", "moving_wp", "=", "None", "return", "if", "obj", ".", "event", ".", "leftIsDown", "and", "self", ".", "moving_fencepoint", "is", "not", "None", ":", "self", ".", "click_position", "=", "obj", ".", "latlon", "self", ".", "click_time", "=", "time", ".", "time", "(", ")", "self", ".", "mpstate", ".", "functions", ".", "process_stdin", "(", "\"fence move %u\"", "%", "(", "self", ".", "moving_fencepoint", "+", "1", ")", ")", "self", ".", "moving_fencepoint", "=", "None", "return", "if", "obj", ".", "event", ".", "rightIsDown", "and", "self", ".", "moving_wp", "is", "not", "None", ":", "print", "(", "\"Cancelled wp move\"", ")", "self", ".", "moving_wp", "=", "None", "return", "if", "obj", ".", "event", ".", "rightIsDown", "and", "self", ".", "moving_fencepoint", "is", "not", "None", ":", "print", "(", "\"Cancelled fence move\"", ")", "self", ".", "moving_fencepoint", "=", "None", "return", "elif", "obj", ".", "event", ".", "leftIsDown", ":", "if", "time", ".", "time", "(", ")", "-", "self", ".", "click_time", ">", "0.1", ":", "self", ".", "click_position", "=", "obj", ".", "latlon", "self", ".", "click_time", "=", "time", ".", "time", "(", ")", "self", ".", "drawing_update", "(", ")", "if", "self", ".", "module", "(", "'misseditor'", ")", "is", "not", "None", ":", "self", ".", "module", "(", "'misseditor'", ")", ".", "update_map_click_position", "(", "self", ".", "click_position", ")", "if", "obj", ".", "event", ".", "rightIsDown", ":", "if", "self", ".", "draw_callback", "is", "not", "None", ":", "self", ".", "drawing_end", "(", ")", "return", "if", "time", ".", "time", "(", ")", "-", "self", ".", "click_time", ">", "0.1", ":", "self", ".", "click_position", "=", "obj", ".", "latlon", "self", ".", "click_time", "=", "time", ".", "time", "(", ")" ]
called when an event happens on the slipmap
[ "called", "when", "an", "event", "happens", "on", "the", "slipmap" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L424-L477
235,580
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.drawing_end
def drawing_end(self): '''end line drawing''' from MAVProxy.modules.mavproxy_map import mp_slipmap if self.draw_callback is None: return self.draw_callback(self.draw_line) self.draw_callback = None self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True)) self.map.add_object(mp_slipmap.SlipClearLayer('Drawing'))
python
def drawing_end(self): '''end line drawing''' from MAVProxy.modules.mavproxy_map import mp_slipmap if self.draw_callback is None: return self.draw_callback(self.draw_line) self.draw_callback = None self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True)) self.map.add_object(mp_slipmap.SlipClearLayer('Drawing'))
[ "def", "drawing_end", "(", "self", ")", ":", "from", "MAVProxy", ".", "modules", ".", "mavproxy_map", "import", "mp_slipmap", "if", "self", ".", "draw_callback", "is", "None", ":", "return", "self", ".", "draw_callback", "(", "self", ".", "draw_line", ")", "self", ".", "draw_callback", "=", "None", "self", ".", "map", ".", "add_object", "(", "mp_slipmap", ".", "SlipDefaultPopup", "(", "self", ".", "default_popup", ",", "combine", "=", "True", ")", ")", "self", ".", "map", ".", "add_object", "(", "mp_slipmap", ".", "SlipClearLayer", "(", "'Drawing'", ")", ")" ]
end line drawing
[ "end", "line", "drawing" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L517-L525
235,581
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.draw_lines
def draw_lines(self, callback): '''draw a series of connected lines on the map, calling callback when done''' from MAVProxy.modules.mavproxy_map import mp_slipmap self.draw_callback = callback self.draw_line = [] self.map.add_object(mp_slipmap.SlipDefaultPopup(None))
python
def draw_lines(self, callback): '''draw a series of connected lines on the map, calling callback when done''' from MAVProxy.modules.mavproxy_map import mp_slipmap self.draw_callback = callback self.draw_line = [] self.map.add_object(mp_slipmap.SlipDefaultPopup(None))
[ "def", "draw_lines", "(", "self", ",", "callback", ")", ":", "from", "MAVProxy", ".", "modules", ".", "mavproxy_map", "import", "mp_slipmap", "self", ".", "draw_callback", "=", "callback", "self", ".", "draw_line", "=", "[", "]", "self", ".", "map", ".", "add_object", "(", "mp_slipmap", ".", "SlipDefaultPopup", "(", "None", ")", ")" ]
draw a series of connected lines on the map, calling callback when done
[ "draw", "a", "series", "of", "connected", "lines", "on", "the", "map", "calling", "callback", "when", "done" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L527-L532
235,582
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.cmd_set_originpos
def cmd_set_originpos(self, args): '''called when user selects "Set Origin" on map''' (lat, lon) = (self.click_position[0], self.click_position[1]) print("Setting origin to: ", lat, lon) self.master.mav.set_gps_global_origin_send( self.settings.target_system, lat*10000000, # lat lon*10000000, # lon 0*1000)
python
def cmd_set_originpos(self, args): '''called when user selects "Set Origin" on map''' (lat, lon) = (self.click_position[0], self.click_position[1]) print("Setting origin to: ", lat, lon) self.master.mav.set_gps_global_origin_send( self.settings.target_system, lat*10000000, # lat lon*10000000, # lon 0*1000)
[ "def", "cmd_set_originpos", "(", "self", ",", "args", ")", ":", "(", "lat", ",", "lon", ")", "=", "(", "self", ".", "click_position", "[", "0", "]", ",", "self", ".", "click_position", "[", "1", "]", ")", "print", "(", "\"Setting origin to: \"", ",", "lat", ",", "lon", ")", "self", ".", "master", ".", "mav", ".", "set_gps_global_origin_send", "(", "self", ".", "settings", ".", "target_system", ",", "lat", "*", "10000000", ",", "# lat", "lon", "*", "10000000", ",", "# lon", "0", "*", "1000", ")" ]
called when user selects "Set Origin" on map
[ "called", "when", "user", "selects", "Set", "Origin", "on", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L580-L588
235,583
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.cmd_center
def cmd_center(self, args): '''control center of view''' if len(args) < 3: print("map center LAT LON") return lat = float(args[1]) lon = float(args[2]) self.map.set_center(lat, lon)
python
def cmd_center(self, args): '''control center of view''' if len(args) < 3: print("map center LAT LON") return lat = float(args[1]) lon = float(args[2]) self.map.set_center(lat, lon)
[ "def", "cmd_center", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "<", "3", ":", "print", "(", "\"map center LAT LON\"", ")", "return", "lat", "=", "float", "(", "args", "[", "1", "]", ")", "lon", "=", "float", "(", "args", "[", "2", "]", ")", "self", ".", "map", ".", "set_center", "(", "lat", ",", "lon", ")" ]
control center of view
[ "control", "center", "of", "view" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L598-L605
235,584
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.cmd_follow
def cmd_follow(self, args): '''control following of vehicle''' if len(args) < 2: print("map follow 0|1") return follow = int(args[1]) self.map.set_follow(follow)
python
def cmd_follow(self, args): '''control following of vehicle''' if len(args) < 2: print("map follow 0|1") return follow = int(args[1]) self.map.set_follow(follow)
[ "def", "cmd_follow", "(", "self", ",", "args", ")", ":", "if", "len", "(", "args", ")", "<", "2", ":", "print", "(", "\"map follow 0|1\"", ")", "return", "follow", "=", "int", "(", "args", "[", "1", "]", ")", "self", ".", "map", ".", "set_follow", "(", "follow", ")" ]
control following of vehicle
[ "control", "following", "of", "vehicle" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L607-L613
235,585
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_map/__init__.py
MapModule.set_secondary_vehicle_position
def set_secondary_vehicle_position(self, m): '''show 2nd vehicle on map''' if m.get_type() != 'GLOBAL_POSITION_INT': return (lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01) if abs(lat) < 1.0e-3 and abs(lon) > 1.0e-3: return # hack for OBC2016 alt = self.ElevationMap.GetElevation(lat, lon) agl = m.alt * 0.001 - alt agl_s = str(int(agl)) + 'm' self.create_vehicle_icon('VehiclePos2', 'blue', follow=False, vehicle_type='plane') self.map.set_position('VehiclePos2', (lat, lon), rotation=heading, label=agl_s, colour=(0,255,255))
python
def set_secondary_vehicle_position(self, m): '''show 2nd vehicle on map''' if m.get_type() != 'GLOBAL_POSITION_INT': return (lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01) if abs(lat) < 1.0e-3 and abs(lon) > 1.0e-3: return # hack for OBC2016 alt = self.ElevationMap.GetElevation(lat, lon) agl = m.alt * 0.001 - alt agl_s = str(int(agl)) + 'm' self.create_vehicle_icon('VehiclePos2', 'blue', follow=False, vehicle_type='plane') self.map.set_position('VehiclePos2', (lat, lon), rotation=heading, label=agl_s, colour=(0,255,255))
[ "def", "set_secondary_vehicle_position", "(", "self", ",", "m", ")", ":", "if", "m", ".", "get_type", "(", ")", "!=", "'GLOBAL_POSITION_INT'", ":", "return", "(", "lat", ",", "lon", ",", "heading", ")", "=", "(", "m", ".", "lat", "*", "1.0e-7", ",", "m", ".", "lon", "*", "1.0e-7", ",", "m", ".", "hdg", "*", "0.01", ")", "if", "abs", "(", "lat", ")", "<", "1.0e-3", "and", "abs", "(", "lon", ")", ">", "1.0e-3", ":", "return", "# hack for OBC2016", "alt", "=", "self", ".", "ElevationMap", ".", "GetElevation", "(", "lat", ",", "lon", ")", "agl", "=", "m", ".", "alt", "*", "0.001", "-", "alt", "agl_s", "=", "str", "(", "int", "(", "agl", ")", ")", "+", "'m'", "self", ".", "create_vehicle_icon", "(", "'VehiclePos2'", ",", "'blue'", ",", "follow", "=", "False", ",", "vehicle_type", "=", "'plane'", ")", "self", ".", "map", ".", "set_position", "(", "'VehiclePos2'", ",", "(", "lat", ",", "lon", ")", ",", "rotation", "=", "heading", ",", "label", "=", "agl_s", ",", "colour", "=", "(", "0", ",", "255", ",", "255", ")", ")" ]
show 2nd vehicle on map
[ "show", "2nd", "vehicle", "on", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L615-L627
235,586
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.cmd_param
def cmd_param(self, args): '''control kml reading''' usage = "Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>" if len(args) < 1: print(usage) return elif args[0] == "clear": self.clearkml() elif args[0] == "snapwp": self.cmd_snap_wp(args[1:]) elif args[0] == "snapfence": self.cmd_snap_fence(args[1:]) elif args[0] == "load": if len(args) != 2: print("usage: kml load <filename>") return self.loadkml(args[1]) elif args[0] == "layers": for layer in self.curlayers: print("Found layer: " + layer) elif args[0] == "toggle": self.togglekml(args[1]) elif args[0] == "fence": self.fencekml(args[1]) else: print(usage) return
python
def cmd_param(self, args): '''control kml reading''' usage = "Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>" if len(args) < 1: print(usage) return elif args[0] == "clear": self.clearkml() elif args[0] == "snapwp": self.cmd_snap_wp(args[1:]) elif args[0] == "snapfence": self.cmd_snap_fence(args[1:]) elif args[0] == "load": if len(args) != 2: print("usage: kml load <filename>") return self.loadkml(args[1]) elif args[0] == "layers": for layer in self.curlayers: print("Found layer: " + layer) elif args[0] == "toggle": self.togglekml(args[1]) elif args[0] == "fence": self.fencekml(args[1]) else: print(usage) return
[ "def", "cmd_param", "(", "self", ",", "args", ")", ":", "usage", "=", "\"Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>\"", "if", "len", "(", "args", ")", "<", "1", ":", "print", "(", "usage", ")", "return", "elif", "args", "[", "0", "]", "==", "\"clear\"", ":", "self", ".", "clearkml", "(", ")", "elif", "args", "[", "0", "]", "==", "\"snapwp\"", ":", "self", ".", "cmd_snap_wp", "(", "args", "[", "1", ":", "]", ")", "elif", "args", "[", "0", "]", "==", "\"snapfence\"", ":", "self", ".", "cmd_snap_fence", "(", "args", "[", "1", ":", "]", ")", "elif", "args", "[", "0", "]", "==", "\"load\"", ":", "if", "len", "(", "args", ")", "!=", "2", ":", "print", "(", "\"usage: kml load <filename>\"", ")", "return", "self", ".", "loadkml", "(", "args", "[", "1", "]", ")", "elif", "args", "[", "0", "]", "==", "\"layers\"", ":", "for", "layer", "in", "self", ".", "curlayers", ":", "print", "(", "\"Found layer: \"", "+", "layer", ")", "elif", "args", "[", "0", "]", "==", "\"toggle\"", ":", "self", ".", "togglekml", "(", "args", "[", "1", "]", ")", "elif", "args", "[", "0", "]", "==", "\"fence\"", ":", "self", ".", "fencekml", "(", "args", "[", "1", "]", ")", "else", ":", "print", "(", "usage", ")", "return" ]
control kml reading
[ "control", "kml", "reading" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L48-L74
235,587
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.cmd_snap_wp
def cmd_snap_wp(self, args): '''snap waypoints to KML''' threshold = 10.0 if len(args) > 0: threshold = float(args[0]) wpmod = self.module('wp') wploader = wpmod.wploader changed = False for i in range(1,wploader.count()): w = wploader.wp(i) if not wploader.is_location_command(w.command): continue lat = w.x lon = w.y best = None best_dist = (threshold+1)*3 for (snap_lat,snap_lon) in self.snap_points: dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon) if dist < best_dist: best_dist = dist best = (snap_lat, snap_lon) if best is not None and best_dist <= threshold: if w.x != best[0] or w.y != best[1]: w.x = best[0] w.y = best[1] print("Snapping WP %u to %f %f" % (i, w.x, w.y)) wploader.set(w, i) changed = True elif best is not None: if best_dist <= (threshold+1)*3: print("Not snapping wp %u dist %.1f" % (i, best_dist)) if changed: wpmod.send_all_waypoints()
python
def cmd_snap_wp(self, args): '''snap waypoints to KML''' threshold = 10.0 if len(args) > 0: threshold = float(args[0]) wpmod = self.module('wp') wploader = wpmod.wploader changed = False for i in range(1,wploader.count()): w = wploader.wp(i) if not wploader.is_location_command(w.command): continue lat = w.x lon = w.y best = None best_dist = (threshold+1)*3 for (snap_lat,snap_lon) in self.snap_points: dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon) if dist < best_dist: best_dist = dist best = (snap_lat, snap_lon) if best is not None and best_dist <= threshold: if w.x != best[0] or w.y != best[1]: w.x = best[0] w.y = best[1] print("Snapping WP %u to %f %f" % (i, w.x, w.y)) wploader.set(w, i) changed = True elif best is not None: if best_dist <= (threshold+1)*3: print("Not snapping wp %u dist %.1f" % (i, best_dist)) if changed: wpmod.send_all_waypoints()
[ "def", "cmd_snap_wp", "(", "self", ",", "args", ")", ":", "threshold", "=", "10.0", "if", "len", "(", "args", ")", ">", "0", ":", "threshold", "=", "float", "(", "args", "[", "0", "]", ")", "wpmod", "=", "self", ".", "module", "(", "'wp'", ")", "wploader", "=", "wpmod", ".", "wploader", "changed", "=", "False", "for", "i", "in", "range", "(", "1", ",", "wploader", ".", "count", "(", ")", ")", ":", "w", "=", "wploader", ".", "wp", "(", "i", ")", "if", "not", "wploader", ".", "is_location_command", "(", "w", ".", "command", ")", ":", "continue", "lat", "=", "w", ".", "x", "lon", "=", "w", ".", "y", "best", "=", "None", "best_dist", "=", "(", "threshold", "+", "1", ")", "*", "3", "for", "(", "snap_lat", ",", "snap_lon", ")", "in", "self", ".", "snap_points", ":", "dist", "=", "mp_util", ".", "gps_distance", "(", "lat", ",", "lon", ",", "snap_lat", ",", "snap_lon", ")", "if", "dist", "<", "best_dist", ":", "best_dist", "=", "dist", "best", "=", "(", "snap_lat", ",", "snap_lon", ")", "if", "best", "is", "not", "None", "and", "best_dist", "<=", "threshold", ":", "if", "w", ".", "x", "!=", "best", "[", "0", "]", "or", "w", ".", "y", "!=", "best", "[", "1", "]", ":", "w", ".", "x", "=", "best", "[", "0", "]", "w", ".", "y", "=", "best", "[", "1", "]", "print", "(", "\"Snapping WP %u to %f %f\"", "%", "(", "i", ",", "w", ".", "x", ",", "w", ".", "y", ")", ")", "wploader", ".", "set", "(", "w", ",", "i", ")", "changed", "=", "True", "elif", "best", "is", "not", "None", ":", "if", "best_dist", "<=", "(", "threshold", "+", "1", ")", "*", "3", ":", "print", "(", "\"Not snapping wp %u dist %.1f\"", "%", "(", "i", ",", "best_dist", ")", ")", "if", "changed", ":", "wpmod", ".", "send_all_waypoints", "(", ")" ]
snap waypoints to KML
[ "snap", "waypoints", "to", "KML" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L76-L108
235,588
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.cmd_snap_fence
def cmd_snap_fence(self, args): '''snap fence to KML''' threshold = 10.0 if len(args) > 0: threshold = float(args[0]) fencemod = self.module('fence') loader = fencemod.fenceloader changed = False for i in range(0,loader.count()): fp = loader.point(i) lat = fp.lat lon = fp.lng best = None best_dist = (threshold+1)*3 for (snap_lat,snap_lon) in self.snap_points: dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon) if dist < best_dist: best_dist = dist best = (snap_lat, snap_lon) if best is not None and best_dist <= threshold: if best[0] != lat or best[1] != lon: loader.move(i, best[0], best[1]) print("Snapping fence point %u to %f %f" % (i, best[0], best[1])) changed = True elif best is not None: if best_dist <= (threshold+1)*3: print("Not snapping fence point %u dist %.1f" % (i, best_dist)) if changed: fencemod.send_fence()
python
def cmd_snap_fence(self, args): '''snap fence to KML''' threshold = 10.0 if len(args) > 0: threshold = float(args[0]) fencemod = self.module('fence') loader = fencemod.fenceloader changed = False for i in range(0,loader.count()): fp = loader.point(i) lat = fp.lat lon = fp.lng best = None best_dist = (threshold+1)*3 for (snap_lat,snap_lon) in self.snap_points: dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon) if dist < best_dist: best_dist = dist best = (snap_lat, snap_lon) if best is not None and best_dist <= threshold: if best[0] != lat or best[1] != lon: loader.move(i, best[0], best[1]) print("Snapping fence point %u to %f %f" % (i, best[0], best[1])) changed = True elif best is not None: if best_dist <= (threshold+1)*3: print("Not snapping fence point %u dist %.1f" % (i, best_dist)) if changed: fencemod.send_fence()
[ "def", "cmd_snap_fence", "(", "self", ",", "args", ")", ":", "threshold", "=", "10.0", "if", "len", "(", "args", ")", ">", "0", ":", "threshold", "=", "float", "(", "args", "[", "0", "]", ")", "fencemod", "=", "self", ".", "module", "(", "'fence'", ")", "loader", "=", "fencemod", ".", "fenceloader", "changed", "=", "False", "for", "i", "in", "range", "(", "0", ",", "loader", ".", "count", "(", ")", ")", ":", "fp", "=", "loader", ".", "point", "(", "i", ")", "lat", "=", "fp", ".", "lat", "lon", "=", "fp", ".", "lng", "best", "=", "None", "best_dist", "=", "(", "threshold", "+", "1", ")", "*", "3", "for", "(", "snap_lat", ",", "snap_lon", ")", "in", "self", ".", "snap_points", ":", "dist", "=", "mp_util", ".", "gps_distance", "(", "lat", ",", "lon", ",", "snap_lat", ",", "snap_lon", ")", "if", "dist", "<", "best_dist", ":", "best_dist", "=", "dist", "best", "=", "(", "snap_lat", ",", "snap_lon", ")", "if", "best", "is", "not", "None", "and", "best_dist", "<=", "threshold", ":", "if", "best", "[", "0", "]", "!=", "lat", "or", "best", "[", "1", "]", "!=", "lon", ":", "loader", ".", "move", "(", "i", ",", "best", "[", "0", "]", ",", "best", "[", "1", "]", ")", "print", "(", "\"Snapping fence point %u to %f %f\"", "%", "(", "i", ",", "best", "[", "0", "]", ",", "best", "[", "1", "]", ")", ")", "changed", "=", "True", "elif", "best", "is", "not", "None", ":", "if", "best_dist", "<=", "(", "threshold", "+", "1", ")", "*", "3", ":", "print", "(", "\"Not snapping fence point %u dist %.1f\"", "%", "(", "i", ",", "best_dist", ")", ")", "if", "changed", ":", "fencemod", ".", "send_fence", "(", ")" ]
snap fence to KML
[ "snap", "fence", "to", "KML" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L110-L139
235,589
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.fencekml
def fencekml(self, layername): '''set a layer as the geofence''' #Strip quotation marks if neccessary if layername.startswith('"') and layername.endswith('"'): layername = layername[1:-1] #for each point in the layer, add it in for layer in self.allayers: if layer.key == layername: #clear the current fence self.fenceloader.clear() if len(layer.points) < 3: return self.fenceloader.target_system = self.target_system self.fenceloader.target_component = self.target_component #send centrepoint to fence[0] as the return point bounds = mp_util.polygon_bounds(layer.points) (lat, lon, width, height) = bounds center = (lat+width/2, lon+height/2) self.fenceloader.add_latlon(center[0], center[1]) for lat, lon in layer.points: #add point self.fenceloader.add_latlon(lat, lon) #and send self.send_fence()
python
def fencekml(self, layername): '''set a layer as the geofence''' #Strip quotation marks if neccessary if layername.startswith('"') and layername.endswith('"'): layername = layername[1:-1] #for each point in the layer, add it in for layer in self.allayers: if layer.key == layername: #clear the current fence self.fenceloader.clear() if len(layer.points) < 3: return self.fenceloader.target_system = self.target_system self.fenceloader.target_component = self.target_component #send centrepoint to fence[0] as the return point bounds = mp_util.polygon_bounds(layer.points) (lat, lon, width, height) = bounds center = (lat+width/2, lon+height/2) self.fenceloader.add_latlon(center[0], center[1]) for lat, lon in layer.points: #add point self.fenceloader.add_latlon(lat, lon) #and send self.send_fence()
[ "def", "fencekml", "(", "self", ",", "layername", ")", ":", "#Strip quotation marks if neccessary", "if", "layername", ".", "startswith", "(", "'\"'", ")", "and", "layername", ".", "endswith", "(", "'\"'", ")", ":", "layername", "=", "layername", "[", "1", ":", "-", "1", "]", "#for each point in the layer, add it in", "for", "layer", "in", "self", ".", "allayers", ":", "if", "layer", ".", "key", "==", "layername", ":", "#clear the current fence", "self", ".", "fenceloader", ".", "clear", "(", ")", "if", "len", "(", "layer", ".", "points", ")", "<", "3", ":", "return", "self", ".", "fenceloader", ".", "target_system", "=", "self", ".", "target_system", "self", ".", "fenceloader", ".", "target_component", "=", "self", ".", "target_component", "#send centrepoint to fence[0] as the return point", "bounds", "=", "mp_util", ".", "polygon_bounds", "(", "layer", ".", "points", ")", "(", "lat", ",", "lon", ",", "width", ",", "height", ")", "=", "bounds", "center", "=", "(", "lat", "+", "width", "/", "2", ",", "lon", "+", "height", "/", "2", ")", "self", ".", "fenceloader", ".", "add_latlon", "(", "center", "[", "0", "]", ",", "center", "[", "1", "]", ")", "for", "lat", ",", "lon", "in", "layer", ".", "points", ":", "#add point", "self", ".", "fenceloader", ".", "add_latlon", "(", "lat", ",", "lon", ")", "#and send", "self", ".", "send_fence", "(", ")" ]
set a layer as the geofence
[ "set", "a", "layer", "as", "the", "geofence" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L141-L165
235,590
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.togglekml
def togglekml(self, layername): '''toggle the display of a kml''' #Strip quotation marks if neccessary if layername.startswith('"') and layername.endswith('"'): layername = layername[1:-1] #toggle layer off (plus associated text element) if layername in self.curlayers: for layer in self.curlayers: if layer == layername: self.mpstate.map.remove_object(layer) self.curlayers.remove(layername) if layername in self.curtextlayers: for clayer in self.curtextlayers: if clayer == layername: self.mpstate.map.remove_object(clayer) self.curtextlayers.remove(clayer) #toggle layer on (plus associated text element) else: for layer in self.allayers: if layer.key == layername: self.mpstate.map.add_object(layer) self.curlayers.append(layername) for alayer in self.alltextlayers: if alayer.key == layername: self.mpstate.map.add_object(alayer) self.curtextlayers.append(layername) self.menu_needs_refreshing = True
python
def togglekml(self, layername): '''toggle the display of a kml''' #Strip quotation marks if neccessary if layername.startswith('"') and layername.endswith('"'): layername = layername[1:-1] #toggle layer off (plus associated text element) if layername in self.curlayers: for layer in self.curlayers: if layer == layername: self.mpstate.map.remove_object(layer) self.curlayers.remove(layername) if layername in self.curtextlayers: for clayer in self.curtextlayers: if clayer == layername: self.mpstate.map.remove_object(clayer) self.curtextlayers.remove(clayer) #toggle layer on (plus associated text element) else: for layer in self.allayers: if layer.key == layername: self.mpstate.map.add_object(layer) self.curlayers.append(layername) for alayer in self.alltextlayers: if alayer.key == layername: self.mpstate.map.add_object(alayer) self.curtextlayers.append(layername) self.menu_needs_refreshing = True
[ "def", "togglekml", "(", "self", ",", "layername", ")", ":", "#Strip quotation marks if neccessary", "if", "layername", ".", "startswith", "(", "'\"'", ")", "and", "layername", ".", "endswith", "(", "'\"'", ")", ":", "layername", "=", "layername", "[", "1", ":", "-", "1", "]", "#toggle layer off (plus associated text element)", "if", "layername", "in", "self", ".", "curlayers", ":", "for", "layer", "in", "self", ".", "curlayers", ":", "if", "layer", "==", "layername", ":", "self", ".", "mpstate", ".", "map", ".", "remove_object", "(", "layer", ")", "self", ".", "curlayers", ".", "remove", "(", "layername", ")", "if", "layername", "in", "self", ".", "curtextlayers", ":", "for", "clayer", "in", "self", ".", "curtextlayers", ":", "if", "clayer", "==", "layername", ":", "self", ".", "mpstate", ".", "map", ".", "remove_object", "(", "clayer", ")", "self", ".", "curtextlayers", ".", "remove", "(", "clayer", ")", "#toggle layer on (plus associated text element)", "else", ":", "for", "layer", "in", "self", ".", "allayers", ":", "if", "layer", ".", "key", "==", "layername", ":", "self", ".", "mpstate", ".", "map", ".", "add_object", "(", "layer", ")", "self", ".", "curlayers", ".", "append", "(", "layername", ")", "for", "alayer", "in", "self", ".", "alltextlayers", ":", "if", "alayer", ".", "key", "==", "layername", ":", "self", ".", "mpstate", ".", "map", ".", "add_object", "(", "alayer", ")", "self", ".", "curtextlayers", ".", "append", "(", "layername", ")", "self", ".", "menu_needs_refreshing", "=", "True" ]
toggle the display of a kml
[ "toggle", "the", "display", "of", "a", "kml" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L209-L235
235,591
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.clearkml
def clearkml(self): '''Clear the kmls from the map''' #go through all the current layers and remove them for layer in self.curlayers: self.mpstate.map.remove_object(layer) for layer in self.curtextlayers: self.mpstate.map.remove_object(layer) self.allayers = [] self.curlayers = [] self.alltextlayers = [] self.curtextlayers = [] self.menu_needs_refreshing = True
python
def clearkml(self): '''Clear the kmls from the map''' #go through all the current layers and remove them for layer in self.curlayers: self.mpstate.map.remove_object(layer) for layer in self.curtextlayers: self.mpstate.map.remove_object(layer) self.allayers = [] self.curlayers = [] self.alltextlayers = [] self.curtextlayers = [] self.menu_needs_refreshing = True
[ "def", "clearkml", "(", "self", ")", ":", "#go through all the current layers and remove them", "for", "layer", "in", "self", ".", "curlayers", ":", "self", ".", "mpstate", ".", "map", ".", "remove_object", "(", "layer", ")", "for", "layer", "in", "self", ".", "curtextlayers", ":", "self", ".", "mpstate", ".", "map", ".", "remove_object", "(", "layer", ")", "self", ".", "allayers", "=", "[", "]", "self", ".", "curlayers", "=", "[", "]", "self", ".", "alltextlayers", "=", "[", "]", "self", ".", "curtextlayers", "=", "[", "]", "self", ".", "menu_needs_refreshing", "=", "True" ]
Clear the kmls from the map
[ "Clear", "the", "kmls", "from", "the", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L237-L248
235,592
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.loadkml
def loadkml(self, filename): '''Load a kml from file and put it on the map''' #Open the zip file nodes = self.readkmz(filename) self.snap_points = [] #go through each object in the kml... for n in nodes: point = self.readObject(n) #and place any polygons on the map if self.mpstate.map is not None and point[0] == 'Polygon': self.snap_points.extend(point[2]) #print("Adding " + point[1]) newcolour = (random.randint(0, 255), 0, random.randint(0, 255)) curpoly = mp_slipmap.SlipPolygon(point[1], point[2], layer=2, linewidth=2, colour=newcolour) self.mpstate.map.add_object(curpoly) self.allayers.append(curpoly) self.curlayers.append(point[1]) #and points - barrell image and text if self.mpstate.map is not None and point[0] == 'Point': #print("Adding " + point[1]) icon = self.mpstate.map.icon('barrell.png') curpoint = mp_slipmap.SlipIcon(point[1], latlon = (point[2][0][0], point[2][0][1]), layer=3, img=icon, rotation=0, follow=False) curtext = mp_slipmap.SlipLabel(point[1], point = (point[2][0][0], point[2][0][1]), layer=4, label=point[1], colour=(0,255,255)) self.mpstate.map.add_object(curpoint) self.mpstate.map.add_object(curtext) self.allayers.append(curpoint) self.alltextlayers.append(curtext) self.curlayers.append(point[1]) self.curtextlayers.append(point[1]) self.menu_needs_refreshing = True
python
def loadkml(self, filename): '''Load a kml from file and put it on the map''' #Open the zip file nodes = self.readkmz(filename) self.snap_points = [] #go through each object in the kml... for n in nodes: point = self.readObject(n) #and place any polygons on the map if self.mpstate.map is not None and point[0] == 'Polygon': self.snap_points.extend(point[2]) #print("Adding " + point[1]) newcolour = (random.randint(0, 255), 0, random.randint(0, 255)) curpoly = mp_slipmap.SlipPolygon(point[1], point[2], layer=2, linewidth=2, colour=newcolour) self.mpstate.map.add_object(curpoly) self.allayers.append(curpoly) self.curlayers.append(point[1]) #and points - barrell image and text if self.mpstate.map is not None and point[0] == 'Point': #print("Adding " + point[1]) icon = self.mpstate.map.icon('barrell.png') curpoint = mp_slipmap.SlipIcon(point[1], latlon = (point[2][0][0], point[2][0][1]), layer=3, img=icon, rotation=0, follow=False) curtext = mp_slipmap.SlipLabel(point[1], point = (point[2][0][0], point[2][0][1]), layer=4, label=point[1], colour=(0,255,255)) self.mpstate.map.add_object(curpoint) self.mpstate.map.add_object(curtext) self.allayers.append(curpoint) self.alltextlayers.append(curtext) self.curlayers.append(point[1]) self.curtextlayers.append(point[1]) self.menu_needs_refreshing = True
[ "def", "loadkml", "(", "self", ",", "filename", ")", ":", "#Open the zip file", "nodes", "=", "self", ".", "readkmz", "(", "filename", ")", "self", ".", "snap_points", "=", "[", "]", "#go through each object in the kml...", "for", "n", "in", "nodes", ":", "point", "=", "self", ".", "readObject", "(", "n", ")", "#and place any polygons on the map", "if", "self", ".", "mpstate", ".", "map", "is", "not", "None", "and", "point", "[", "0", "]", "==", "'Polygon'", ":", "self", ".", "snap_points", ".", "extend", "(", "point", "[", "2", "]", ")", "#print(\"Adding \" + point[1])", "newcolour", "=", "(", "random", ".", "randint", "(", "0", ",", "255", ")", ",", "0", ",", "random", ".", "randint", "(", "0", ",", "255", ")", ")", "curpoly", "=", "mp_slipmap", ".", "SlipPolygon", "(", "point", "[", "1", "]", ",", "point", "[", "2", "]", ",", "layer", "=", "2", ",", "linewidth", "=", "2", ",", "colour", "=", "newcolour", ")", "self", ".", "mpstate", ".", "map", ".", "add_object", "(", "curpoly", ")", "self", ".", "allayers", ".", "append", "(", "curpoly", ")", "self", ".", "curlayers", ".", "append", "(", "point", "[", "1", "]", ")", "#and points - barrell image and text", "if", "self", ".", "mpstate", ".", "map", "is", "not", "None", "and", "point", "[", "0", "]", "==", "'Point'", ":", "#print(\"Adding \" + point[1])", "icon", "=", "self", ".", "mpstate", ".", "map", ".", "icon", "(", "'barrell.png'", ")", "curpoint", "=", "mp_slipmap", ".", "SlipIcon", "(", "point", "[", "1", "]", ",", "latlon", "=", "(", "point", "[", "2", "]", "[", "0", "]", "[", "0", "]", ",", "point", "[", "2", "]", "[", "0", "]", "[", "1", "]", ")", ",", "layer", "=", "3", ",", "img", "=", "icon", ",", "rotation", "=", "0", ",", "follow", "=", "False", ")", "curtext", "=", "mp_slipmap", ".", "SlipLabel", "(", "point", "[", "1", "]", ",", "point", "=", "(", "point", "[", "2", "]", "[", "0", "]", "[", "0", "]", ",", "point", "[", "2", "]", "[", "0", "]", "[", "1", "]", ")", ",", "layer", "=", "4", ",", "label", "=", "point", "[", "1", "]", ",", "colour", "=", "(", "0", ",", "255", ",", "255", ")", ")", "self", ".", "mpstate", ".", "map", ".", "add_object", "(", "curpoint", ")", "self", ".", "mpstate", ".", "map", ".", "add_object", "(", "curtext", ")", "self", ".", "allayers", ".", "append", "(", "curpoint", ")", "self", ".", "alltextlayers", ".", "append", "(", "curtext", ")", "self", ".", "curlayers", ".", "append", "(", "point", "[", "1", "]", ")", "self", ".", "curtextlayers", ".", "append", "(", "point", "[", "1", "]", ")", "self", ".", "menu_needs_refreshing", "=", "True" ]
Load a kml from file and put it on the map
[ "Load", "a", "kml", "from", "file", "and", "put", "it", "on", "the", "map" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L250-L286
235,593
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.idle_task
def idle_task(self): '''handle GUI elements''' if not self.menu_needs_refreshing: return if self.module('map') is not None and not self.menu_added_map: self.menu_added_map = True self.module('map').add_menu(self.menu) #(re)create the menu if mp_util.has_wxpython and self.menu_added_map: # we don't dynamically update these yet due to a wx bug self.menu.items = [ MPMenuItem('Clear', 'Clear', '# kml clear'), MPMenuItem('Load', 'Load', '# kml load ', handler=MPMenuCallFileDialog(flags=('open',), title='KML Load', wildcard='*.kml;*.kmz')), self.menu_fence, MPMenuSeparator() ] self.menu_fence.items = [] for layer in self.allayers: #if it's a polygon, add it to the "set Geofence" list if isinstance(layer, mp_slipmap.SlipPolygon): self.menu_fence.items.append(MPMenuItem(layer.key, layer.key, '# kml fence \"' + layer.key + '\"')) #then add all the layers to the menu, ensuring to check the active layers #text elements aren't included on the menu if layer.key in self.curlayers and layer.key[-5:] != "-text": self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=True)) elif layer.key[-5:] != "-text": self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=False)) #and add the menu to the map popu menu self.module('map').add_menu(self.menu) self.menu_needs_refreshing = False
python
def idle_task(self): '''handle GUI elements''' if not self.menu_needs_refreshing: return if self.module('map') is not None and not self.menu_added_map: self.menu_added_map = True self.module('map').add_menu(self.menu) #(re)create the menu if mp_util.has_wxpython and self.menu_added_map: # we don't dynamically update these yet due to a wx bug self.menu.items = [ MPMenuItem('Clear', 'Clear', '# kml clear'), MPMenuItem('Load', 'Load', '# kml load ', handler=MPMenuCallFileDialog(flags=('open',), title='KML Load', wildcard='*.kml;*.kmz')), self.menu_fence, MPMenuSeparator() ] self.menu_fence.items = [] for layer in self.allayers: #if it's a polygon, add it to the "set Geofence" list if isinstance(layer, mp_slipmap.SlipPolygon): self.menu_fence.items.append(MPMenuItem(layer.key, layer.key, '# kml fence \"' + layer.key + '\"')) #then add all the layers to the menu, ensuring to check the active layers #text elements aren't included on the menu if layer.key in self.curlayers and layer.key[-5:] != "-text": self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=True)) elif layer.key[-5:] != "-text": self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=False)) #and add the menu to the map popu menu self.module('map').add_menu(self.menu) self.menu_needs_refreshing = False
[ "def", "idle_task", "(", "self", ")", ":", "if", "not", "self", ".", "menu_needs_refreshing", ":", "return", "if", "self", ".", "module", "(", "'map'", ")", "is", "not", "None", "and", "not", "self", ".", "menu_added_map", ":", "self", ".", "menu_added_map", "=", "True", "self", ".", "module", "(", "'map'", ")", ".", "add_menu", "(", "self", ".", "menu", ")", "#(re)create the menu", "if", "mp_util", ".", "has_wxpython", "and", "self", ".", "menu_added_map", ":", "# we don't dynamically update these yet due to a wx bug", "self", ".", "menu", ".", "items", "=", "[", "MPMenuItem", "(", "'Clear'", ",", "'Clear'", ",", "'# kml clear'", ")", ",", "MPMenuItem", "(", "'Load'", ",", "'Load'", ",", "'# kml load '", ",", "handler", "=", "MPMenuCallFileDialog", "(", "flags", "=", "(", "'open'", ",", ")", ",", "title", "=", "'KML Load'", ",", "wildcard", "=", "'*.kml;*.kmz'", ")", ")", ",", "self", ".", "menu_fence", ",", "MPMenuSeparator", "(", ")", "]", "self", ".", "menu_fence", ".", "items", "=", "[", "]", "for", "layer", "in", "self", ".", "allayers", ":", "#if it's a polygon, add it to the \"set Geofence\" list", "if", "isinstance", "(", "layer", ",", "mp_slipmap", ".", "SlipPolygon", ")", ":", "self", ".", "menu_fence", ".", "items", ".", "append", "(", "MPMenuItem", "(", "layer", ".", "key", ",", "layer", ".", "key", ",", "'# kml fence \\\"'", "+", "layer", ".", "key", "+", "'\\\"'", ")", ")", "#then add all the layers to the menu, ensuring to check the active layers", "#text elements aren't included on the menu", "if", "layer", ".", "key", "in", "self", ".", "curlayers", "and", "layer", ".", "key", "[", "-", "5", ":", "]", "!=", "\"-text\"", ":", "self", ".", "menu", ".", "items", ".", "append", "(", "MPMenuCheckbox", "(", "layer", ".", "key", ",", "layer", ".", "key", ",", "'# kml toggle \\\"'", "+", "layer", ".", "key", "+", "'\\\"'", ",", "checked", "=", "True", ")", ")", "elif", "layer", ".", "key", "[", "-", "5", ":", "]", "!=", "\"-text\"", ":", "self", ".", "menu", ".", "items", ".", "append", "(", "MPMenuCheckbox", "(", "layer", ".", "key", ",", "layer", ".", "key", ",", "'# kml toggle \\\"'", "+", "layer", ".", "key", "+", "'\\\"'", ",", "checked", "=", "False", ")", ")", "#and add the menu to the map popu menu", "self", ".", "module", "(", "'map'", ")", ".", "add_menu", "(", "self", ".", "menu", ")", "self", ".", "menu_needs_refreshing", "=", "False" ]
handle GUI elements
[ "handle", "GUI", "elements" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L289-L313
235,594
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_kmlread.py
KmlReadModule.readkmz
def readkmz(self, filename): '''reads in a kmz file and returns xml nodes''' #Strip quotation marks if neccessary filename.strip('"') #Open the zip file (as applicable) if filename[-4:] == '.kml': fo = open(filename, "r") fstring = fo.read() fo.close() elif filename[-4:] == '.kmz': zip=ZipFile(filename) for z in zip.filelist: if z.filename[-4:] == '.kml': fstring=zip.read(z) break else: raise Exception("Could not find kml file in %s" % filename) else: raise Exception("Is not a valid kml or kmz file in %s" % filename) #send into the xml parser kmlstring = parseString(fstring) #get all the placenames nodes=kmlstring.getElementsByTagName('Placemark') return nodes
python
def readkmz(self, filename): '''reads in a kmz file and returns xml nodes''' #Strip quotation marks if neccessary filename.strip('"') #Open the zip file (as applicable) if filename[-4:] == '.kml': fo = open(filename, "r") fstring = fo.read() fo.close() elif filename[-4:] == '.kmz': zip=ZipFile(filename) for z in zip.filelist: if z.filename[-4:] == '.kml': fstring=zip.read(z) break else: raise Exception("Could not find kml file in %s" % filename) else: raise Exception("Is not a valid kml or kmz file in %s" % filename) #send into the xml parser kmlstring = parseString(fstring) #get all the placenames nodes=kmlstring.getElementsByTagName('Placemark') return nodes
[ "def", "readkmz", "(", "self", ",", "filename", ")", ":", "#Strip quotation marks if neccessary", "filename", ".", "strip", "(", "'\"'", ")", "#Open the zip file (as applicable) ", "if", "filename", "[", "-", "4", ":", "]", "==", "'.kml'", ":", "fo", "=", "open", "(", "filename", ",", "\"r\"", ")", "fstring", "=", "fo", ".", "read", "(", ")", "fo", ".", "close", "(", ")", "elif", "filename", "[", "-", "4", ":", "]", "==", "'.kmz'", ":", "zip", "=", "ZipFile", "(", "filename", ")", "for", "z", "in", "zip", ".", "filelist", ":", "if", "z", ".", "filename", "[", "-", "4", ":", "]", "==", "'.kml'", ":", "fstring", "=", "zip", ".", "read", "(", "z", ")", "break", "else", ":", "raise", "Exception", "(", "\"Could not find kml file in %s\"", "%", "filename", ")", "else", ":", "raise", "Exception", "(", "\"Is not a valid kml or kmz file in %s\"", "%", "filename", ")", "#send into the xml parser", "kmlstring", "=", "parseString", "(", "fstring", ")", "#get all the placenames", "nodes", "=", "kmlstring", ".", "getElementsByTagName", "(", "'Placemark'", ")", "return", "nodes" ]
reads in a kmz file and returns xml nodes
[ "reads", "in", "a", "kmz", "file", "and", "returns", "xml", "nodes" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L318-L344
235,595
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_asterix.py
AsterixModule.cmd_asterix
def cmd_asterix(self, args): '''asterix command parser''' usage = "usage: asterix <set|start|stop|restart|status>" if len(args) == 0: print(usage) return if args[0] == "set": self.asterix_settings.command(args[1:]) elif args[0] == "start": self.start_listener() elif args[0] == "stop": self.stop_listener() elif args[0] == "restart": self.stop_listener() self.start_listener() elif args[0] == "status": self.print_status() else: print(usage)
python
def cmd_asterix(self, args): '''asterix command parser''' usage = "usage: asterix <set|start|stop|restart|status>" if len(args) == 0: print(usage) return if args[0] == "set": self.asterix_settings.command(args[1:]) elif args[0] == "start": self.start_listener() elif args[0] == "stop": self.stop_listener() elif args[0] == "restart": self.stop_listener() self.start_listener() elif args[0] == "status": self.print_status() else: print(usage)
[ "def", "cmd_asterix", "(", "self", ",", "args", ")", ":", "usage", "=", "\"usage: asterix <set|start|stop|restart|status>\"", "if", "len", "(", "args", ")", "==", "0", ":", "print", "(", "usage", ")", "return", "if", "args", "[", "0", "]", "==", "\"set\"", ":", "self", ".", "asterix_settings", ".", "command", "(", "args", "[", "1", ":", "]", ")", "elif", "args", "[", "0", "]", "==", "\"start\"", ":", "self", ".", "start_listener", "(", ")", "elif", "args", "[", "0", "]", "==", "\"stop\"", ":", "self", ".", "stop_listener", "(", ")", "elif", "args", "[", "0", "]", "==", "\"restart\"", ":", "self", ".", "stop_listener", "(", ")", "self", ".", "start_listener", "(", ")", "elif", "args", "[", "0", "]", "==", "\"status\"", ":", "self", ".", "print_status", "(", ")", "else", ":", "print", "(", "usage", ")" ]
asterix command parser
[ "asterix", "command", "parser" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L99-L117
235,596
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_asterix.py
AsterixModule.start_listener
def start_listener(self): '''start listening for packets''' if self.sock is not None: self.sock.close() self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind(('', self.asterix_settings.port)) self.sock.setblocking(False) print("Started on port %u" % self.asterix_settings.port)
python
def start_listener(self): '''start listening for packets''' if self.sock is not None: self.sock.close() self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind(('', self.asterix_settings.port)) self.sock.setblocking(False) print("Started on port %u" % self.asterix_settings.port)
[ "def", "start_listener", "(", "self", ")", ":", "if", "self", ".", "sock", "is", "not", "None", ":", "self", ".", "sock", ".", "close", "(", ")", "self", ".", "sock", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET", ",", "socket", ".", "SOCK_DGRAM", ",", "socket", ".", "IPPROTO_UDP", ")", "self", ".", "sock", ".", "setsockopt", "(", "socket", ".", "SOL_SOCKET", ",", "socket", ".", "SO_REUSEADDR", ",", "1", ")", "self", ".", "sock", ".", "bind", "(", "(", "''", ",", "self", ".", "asterix_settings", ".", "port", ")", ")", "self", ".", "sock", ".", "setblocking", "(", "False", ")", "print", "(", "\"Started on port %u\"", "%", "self", ".", "asterix_settings", ".", "port", ")" ]
start listening for packets
[ "start", "listening", "for", "packets" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L119-L127
235,597
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_asterix.py
AsterixModule.stop_listener
def stop_listener(self): '''stop listening for packets''' if self.sock is not None: self.sock.close() self.sock = None self.tracks = {}
python
def stop_listener(self): '''stop listening for packets''' if self.sock is not None: self.sock.close() self.sock = None self.tracks = {}
[ "def", "stop_listener", "(", "self", ")", ":", "if", "self", ".", "sock", "is", "not", "None", ":", "self", ".", "sock", ".", "close", "(", ")", "self", ".", "sock", "=", "None", "self", ".", "tracks", "=", "{", "}" ]
stop listening for packets
[ "stop", "listening", "for", "packets" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L129-L134
235,598
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_asterix.py
AsterixModule.set_secondary_vehicle_position
def set_secondary_vehicle_position(self, m): '''store second vehicle position for filtering purposes''' if m.get_type() != 'GLOBAL_POSITION_INT': return (lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01) if abs(lat) < 1.0e-3 and abs(lon) < 1.0e-3: return self.vehicle2_pos = VehiclePos(m)
python
def set_secondary_vehicle_position(self, m): '''store second vehicle position for filtering purposes''' if m.get_type() != 'GLOBAL_POSITION_INT': return (lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01) if abs(lat) < 1.0e-3 and abs(lon) < 1.0e-3: return self.vehicle2_pos = VehiclePos(m)
[ "def", "set_secondary_vehicle_position", "(", "self", ",", "m", ")", ":", "if", "m", ".", "get_type", "(", ")", "!=", "'GLOBAL_POSITION_INT'", ":", "return", "(", "lat", ",", "lon", ",", "heading", ")", "=", "(", "m", ".", "lat", "*", "1.0e-7", ",", "m", ".", "lon", "*", "1.0e-7", ",", "m", ".", "hdg", "*", "0.01", ")", "if", "abs", "(", "lat", ")", "<", "1.0e-3", "and", "abs", "(", "lon", ")", "<", "1.0e-3", ":", "return", "self", ".", "vehicle2_pos", "=", "VehiclePos", "(", "m", ")" ]
store second vehicle position for filtering purposes
[ "store", "second", "vehicle", "position", "for", "filtering", "purposes" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L136-L143
235,599
ArduPilot/MAVProxy
MAVProxy/modules/mavproxy_asterix.py
AsterixModule.could_collide_hor
def could_collide_hor(self, vpos, adsb_pkt): '''return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds''' margin = self.asterix_settings.filter_dist_xy timeout = self.asterix_settings.filter_time alat = adsb_pkt.lat * 1.0e-7 alon = adsb_pkt.lon * 1.0e-7 avel = adsb_pkt.hor_velocity * 0.01 vvel = sqrt(vpos.vx**2 + vpos.vy**2) dist = mp_util.gps_distance(vpos.lat, vpos.lon, alat, alon) dist -= avel * timeout dist -= vvel * timeout if dist <= margin: return True return False
python
def could_collide_hor(self, vpos, adsb_pkt): '''return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds''' margin = self.asterix_settings.filter_dist_xy timeout = self.asterix_settings.filter_time alat = adsb_pkt.lat * 1.0e-7 alon = adsb_pkt.lon * 1.0e-7 avel = adsb_pkt.hor_velocity * 0.01 vvel = sqrt(vpos.vx**2 + vpos.vy**2) dist = mp_util.gps_distance(vpos.lat, vpos.lon, alat, alon) dist -= avel * timeout dist -= vvel * timeout if dist <= margin: return True return False
[ "def", "could_collide_hor", "(", "self", ",", "vpos", ",", "adsb_pkt", ")", ":", "margin", "=", "self", ".", "asterix_settings", ".", "filter_dist_xy", "timeout", "=", "self", ".", "asterix_settings", ".", "filter_time", "alat", "=", "adsb_pkt", ".", "lat", "*", "1.0e-7", "alon", "=", "adsb_pkt", ".", "lon", "*", "1.0e-7", "avel", "=", "adsb_pkt", ".", "hor_velocity", "*", "0.01", "vvel", "=", "sqrt", "(", "vpos", ".", "vx", "**", "2", "+", "vpos", ".", "vy", "**", "2", ")", "dist", "=", "mp_util", ".", "gps_distance", "(", "vpos", ".", "lat", ",", "vpos", ".", "lon", ",", "alat", ",", "alon", ")", "dist", "-=", "avel", "*", "timeout", "dist", "-=", "vvel", "*", "timeout", "if", "dist", "<=", "margin", ":", "return", "True", "return", "False" ]
return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds
[ "return", "true", "if", "vehicle", "could", "come", "within", "filter_dist_xy", "meters", "of", "adsb", "vehicle", "in", "timeout", "seconds" ]
f50bdeff33064876f7dc8dc4683d278ff47f75d5
https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L145-L158