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 listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavplayback.py | App.slew | def slew(self, value):
'''move to a given position in the file'''
if float(value) != self.filepos:
pos = float(value) * self.filesize
self.mlog.f.seek(int(pos))
self.find_message() | python | def slew(self, value):
'''move to a given position in the file'''
if float(value) != self.filepos:
pos = float(value) * self.filesize
self.mlog.f.seek(int(pos))
self.find_message() | [
"def",
"slew",
"(",
"self",
",",
"value",
")",
":",
"if",
"float",
"(",
"value",
")",
"!=",
"self",
".",
"filepos",
":",
"pos",
"=",
"float",
"(",
"value",
")",
"*",
"self",
".",
"filesize",
"self",
".",
"mlog",
".",
"f",
".",
"seek",
"(",
"int... | move to a given position in the file | [
"move",
"to",
"a",
"given",
"position",
"in",
"the",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavplayback.py#L150-L155 | train | 230,100 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/live_graph_ui.py | GraphFrame.draw_plot | def draw_plot(self):
""" Redraws the plot
"""
import numpy, pylab
state = self.state
if len(self.data[0]) == 0:
print("no data to plot")
return
vhigh = max(self.data[0])
vlow = min(self.data[0])
for i in range(1,len(self.plot_data)):
vhigh = max(vhigh, max(self.data[i]))
vlow = min(vlow, min(self.data[i]))
ymin = vlow - 0.05*(vhigh-vlow)
ymax = vhigh + 0.05*(vhigh-vlow)
if ymin == ymax:
ymax = ymin + 0.1
ymin = ymin - 0.1
self.axes.set_ybound(lower=ymin, upper=ymax)
self.axes.grid(True, color='gray')
pylab.setp(self.axes.get_xticklabels(), visible=True)
pylab.setp(self.axes.get_legend().get_texts(), fontsize='small')
for i in range(len(self.plot_data)):
ydata = numpy.array(self.data[i])
xdata = self.xdata
if len(ydata) < len(self.xdata):
xdata = xdata[-len(ydata):]
self.plot_data[i].set_xdata(xdata)
self.plot_data[i].set_ydata(ydata)
self.canvas.draw() | python | def draw_plot(self):
""" Redraws the plot
"""
import numpy, pylab
state = self.state
if len(self.data[0]) == 0:
print("no data to plot")
return
vhigh = max(self.data[0])
vlow = min(self.data[0])
for i in range(1,len(self.plot_data)):
vhigh = max(vhigh, max(self.data[i]))
vlow = min(vlow, min(self.data[i]))
ymin = vlow - 0.05*(vhigh-vlow)
ymax = vhigh + 0.05*(vhigh-vlow)
if ymin == ymax:
ymax = ymin + 0.1
ymin = ymin - 0.1
self.axes.set_ybound(lower=ymin, upper=ymax)
self.axes.grid(True, color='gray')
pylab.setp(self.axes.get_xticklabels(), visible=True)
pylab.setp(self.axes.get_legend().get_texts(), fontsize='small')
for i in range(len(self.plot_data)):
ydata = numpy.array(self.data[i])
xdata = self.xdata
if len(ydata) < len(self.xdata):
xdata = xdata[-len(ydata):]
self.plot_data[i].set_xdata(xdata)
self.plot_data[i].set_ydata(ydata)
self.canvas.draw() | [
"def",
"draw_plot",
"(",
"self",
")",
":",
"import",
"numpy",
",",
"pylab",
"state",
"=",
"self",
".",
"state",
"if",
"len",
"(",
"self",
".",
"data",
"[",
"0",
"]",
")",
"==",
"0",
":",
"print",
"(",
"\"no data to plot\"",
")",
"return",
"vhigh",
... | Redraws the plot | [
"Redraws",
"the",
"plot"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/live_graph_ui.py#L90-L124 | train | 230,101 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | set_close_on_exec | def set_close_on_exec(fd):
'''set the clone on exec flag on a file descriptor. Ignore exceptions'''
try:
import fcntl
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
except Exception:
pass | python | def set_close_on_exec(fd):
'''set the clone on exec flag on a file descriptor. Ignore exceptions'''
try:
import fcntl
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
except Exception:
pass | [
"def",
"set_close_on_exec",
"(",
"fd",
")",
":",
"try",
":",
"import",
"fcntl",
"flags",
"=",
"fcntl",
".",
"fcntl",
"(",
"fd",
",",
"fcntl",
".",
"F_GETFD",
")",
"flags",
"|=",
"fcntl",
".",
"FD_CLOEXEC",
"fcntl",
".",
"fcntl",
"(",
"fd",
",",
"fcnt... | set the clone on exec flag on a file descriptor. Ignore exceptions | [
"set",
"the",
"clone",
"on",
"exec",
"flag",
"on",
"a",
"file",
"descriptor",
".",
"Ignore",
"exceptions"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L768-L776 | train | 230,102 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavlink_connection | def mavlink_connection(device, baud=115200, source_system=255,
planner_format=None, write=False, append=False,
robust_parsing=True, notimestamps=False, input=True,
dialect=None, autoreconnect=False, zero_time_base=False,
retries=3, use_native=default_native):
'''open a serial, UDP, TCP or file mavlink connection'''
global mavfile_global
if dialect is not None:
set_dialect(dialect)
if device.startswith('tcp:'):
return mavtcp(device[4:], source_system=source_system, retries=retries, use_native=use_native)
if device.startswith('tcpin:'):
return mavtcpin(device[6:], source_system=source_system, retries=retries, use_native=use_native)
if device.startswith('udpin:'):
return mavudp(device[6:], input=True, source_system=source_system, use_native=use_native)
if device.startswith('udpout:'):
return mavudp(device[7:], input=False, source_system=source_system, use_native=use_native)
if device.startswith('udpbcast:'):
return mavudp(device[9:], input=False, source_system=source_system, use_native=use_native, broadcast=True)
# For legacy purposes we accept the following syntax and let the caller to specify direction
if device.startswith('udp:'):
return mavudp(device[4:], input=input, source_system=source_system, use_native=use_native)
if device.lower().endswith('.bin') or device.lower().endswith('.px4log'):
# support dataflash logs
from pymavlink import DFReader
m = DFReader.DFReader_binary(device, zero_time_base=zero_time_base)
mavfile_global = m
return m
if device.endswith('.log'):
# support dataflash text logs
from pymavlink import DFReader
if DFReader.DFReader_is_text_log(device):
m = DFReader.DFReader_text(device, zero_time_base=zero_time_base)
mavfile_global = m
return m
# list of suffixes to prevent setting DOS paths as UDP sockets
logsuffixes = ['mavlink', 'log', 'raw', 'tlog' ]
suffix = device.split('.')[-1].lower()
if device.find(':') != -1 and not suffix in logsuffixes:
return mavudp(device, source_system=source_system, input=input, use_native=use_native)
if os.path.isfile(device):
if device.endswith(".elf") or device.find("/bin/") != -1:
print("executing '%s'" % device)
return mavchildexec(device, source_system=source_system, use_native=use_native)
else:
return mavlogfile(device, planner_format=planner_format, write=write,
append=append, robust_parsing=robust_parsing, notimestamps=notimestamps,
source_system=source_system, use_native=use_native)
return mavserial(device, baud=baud, source_system=source_system, autoreconnect=autoreconnect, use_native=use_native) | python | def mavlink_connection(device, baud=115200, source_system=255,
planner_format=None, write=False, append=False,
robust_parsing=True, notimestamps=False, input=True,
dialect=None, autoreconnect=False, zero_time_base=False,
retries=3, use_native=default_native):
'''open a serial, UDP, TCP or file mavlink connection'''
global mavfile_global
if dialect is not None:
set_dialect(dialect)
if device.startswith('tcp:'):
return mavtcp(device[4:], source_system=source_system, retries=retries, use_native=use_native)
if device.startswith('tcpin:'):
return mavtcpin(device[6:], source_system=source_system, retries=retries, use_native=use_native)
if device.startswith('udpin:'):
return mavudp(device[6:], input=True, source_system=source_system, use_native=use_native)
if device.startswith('udpout:'):
return mavudp(device[7:], input=False, source_system=source_system, use_native=use_native)
if device.startswith('udpbcast:'):
return mavudp(device[9:], input=False, source_system=source_system, use_native=use_native, broadcast=True)
# For legacy purposes we accept the following syntax and let the caller to specify direction
if device.startswith('udp:'):
return mavudp(device[4:], input=input, source_system=source_system, use_native=use_native)
if device.lower().endswith('.bin') or device.lower().endswith('.px4log'):
# support dataflash logs
from pymavlink import DFReader
m = DFReader.DFReader_binary(device, zero_time_base=zero_time_base)
mavfile_global = m
return m
if device.endswith('.log'):
# support dataflash text logs
from pymavlink import DFReader
if DFReader.DFReader_is_text_log(device):
m = DFReader.DFReader_text(device, zero_time_base=zero_time_base)
mavfile_global = m
return m
# list of suffixes to prevent setting DOS paths as UDP sockets
logsuffixes = ['mavlink', 'log', 'raw', 'tlog' ]
suffix = device.split('.')[-1].lower()
if device.find(':') != -1 and not suffix in logsuffixes:
return mavudp(device, source_system=source_system, input=input, use_native=use_native)
if os.path.isfile(device):
if device.endswith(".elf") or device.find("/bin/") != -1:
print("executing '%s'" % device)
return mavchildexec(device, source_system=source_system, use_native=use_native)
else:
return mavlogfile(device, planner_format=planner_format, write=write,
append=append, robust_parsing=robust_parsing, notimestamps=notimestamps,
source_system=source_system, use_native=use_native)
return mavserial(device, baud=baud, source_system=source_system, autoreconnect=autoreconnect, use_native=use_native) | [
"def",
"mavlink_connection",
"(",
"device",
",",
"baud",
"=",
"115200",
",",
"source_system",
"=",
"255",
",",
"planner_format",
"=",
"None",
",",
"write",
"=",
"False",
",",
"append",
"=",
"False",
",",
"robust_parsing",
"=",
"True",
",",
"notimestamps",
... | open a serial, UDP, TCP or file mavlink connection | [
"open",
"a",
"serial",
"UDP",
"TCP",
"or",
"file",
"mavlink",
"connection"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1192-L1244 | train | 230,103 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | is_printable | def is_printable(c):
'''see if a character is printable'''
global have_ascii
if have_ascii:
return ascii.isprint(c)
if isinstance(c, int):
ic = c
else:
ic = ord(c)
return ic >= 32 and ic <= 126 | python | def is_printable(c):
'''see if a character is printable'''
global have_ascii
if have_ascii:
return ascii.isprint(c)
if isinstance(c, int):
ic = c
else:
ic = ord(c)
return ic >= 32 and ic <= 126 | [
"def",
"is_printable",
"(",
"c",
")",
":",
"global",
"have_ascii",
"if",
"have_ascii",
":",
"return",
"ascii",
".",
"isprint",
"(",
"c",
")",
"if",
"isinstance",
"(",
"c",
",",
"int",
")",
":",
"ic",
"=",
"c",
"else",
":",
"ic",
"=",
"ord",
"(",
... | see if a character is printable | [
"see",
"if",
"a",
"character",
"is",
"printable"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1276-L1285 | train | 230,104 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | auto_detect_serial_win32 | def auto_detect_serial_win32(preferred_list=['*']):
'''try to auto-detect serial ports on win32'''
try:
from serial.tools.list_ports_windows import comports
list = sorted(comports())
except:
return []
ret = []
others = []
for port, description, hwid in list:
matches = False
p = SerialPort(port, description=description, hwid=hwid)
for preferred in preferred_list:
if fnmatch.fnmatch(description, preferred) or fnmatch.fnmatch(hwid, preferred):
matches = True
if matches:
ret.append(p)
else:
others.append(p)
if len(ret) > 0:
return ret
# now the rest
ret.extend(others)
return ret | python | def auto_detect_serial_win32(preferred_list=['*']):
'''try to auto-detect serial ports on win32'''
try:
from serial.tools.list_ports_windows import comports
list = sorted(comports())
except:
return []
ret = []
others = []
for port, description, hwid in list:
matches = False
p = SerialPort(port, description=description, hwid=hwid)
for preferred in preferred_list:
if fnmatch.fnmatch(description, preferred) or fnmatch.fnmatch(hwid, preferred):
matches = True
if matches:
ret.append(p)
else:
others.append(p)
if len(ret) > 0:
return ret
# now the rest
ret.extend(others)
return ret | [
"def",
"auto_detect_serial_win32",
"(",
"preferred_list",
"=",
"[",
"'*'",
"]",
")",
":",
"try",
":",
"from",
"serial",
".",
"tools",
".",
"list_ports_windows",
"import",
"comports",
"list",
"=",
"sorted",
"(",
"comports",
"(",
")",
")",
"except",
":",
"re... | try to auto-detect serial ports on win32 | [
"try",
"to",
"auto",
"-",
"detect",
"serial",
"ports",
"on",
"win32"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1309-L1332 | train | 230,105 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | auto_detect_serial_unix | def auto_detect_serial_unix(preferred_list=['*']):
'''try to auto-detect serial ports on unix'''
import glob
glist = glob.glob('/dev/ttyS*') + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob('/dev/serial/by-id/*')
ret = []
others = []
# try preferred ones first
for d in glist:
matches = False
for preferred in preferred_list:
if fnmatch.fnmatch(d, preferred):
matches = True
if matches:
ret.append(SerialPort(d))
else:
others.append(SerialPort(d))
if len(ret) > 0:
return ret
ret.extend(others)
return ret | python | def auto_detect_serial_unix(preferred_list=['*']):
'''try to auto-detect serial ports on unix'''
import glob
glist = glob.glob('/dev/ttyS*') + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob('/dev/serial/by-id/*')
ret = []
others = []
# try preferred ones first
for d in glist:
matches = False
for preferred in preferred_list:
if fnmatch.fnmatch(d, preferred):
matches = True
if matches:
ret.append(SerialPort(d))
else:
others.append(SerialPort(d))
if len(ret) > 0:
return ret
ret.extend(others)
return ret | [
"def",
"auto_detect_serial_unix",
"(",
"preferred_list",
"=",
"[",
"'*'",
"]",
")",
":",
"import",
"glob",
"glist",
"=",
"glob",
".",
"glob",
"(",
"'/dev/ttyS*'",
")",
"+",
"glob",
".",
"glob",
"(",
"'/dev/ttyUSB*'",
")",
"+",
"glob",
".",
"glob",
"(",
... | try to auto-detect serial ports on unix | [
"try",
"to",
"auto",
"-",
"detect",
"serial",
"ports",
"on",
"unix"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1337-L1356 | train | 230,106 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | auto_detect_serial | def auto_detect_serial(preferred_list=['*']):
'''try to auto-detect serial port'''
# see if
if os.name == 'nt':
return auto_detect_serial_win32(preferred_list=preferred_list)
return auto_detect_serial_unix(preferred_list=preferred_list) | python | def auto_detect_serial(preferred_list=['*']):
'''try to auto-detect serial port'''
# see if
if os.name == 'nt':
return auto_detect_serial_win32(preferred_list=preferred_list)
return auto_detect_serial_unix(preferred_list=preferred_list) | [
"def",
"auto_detect_serial",
"(",
"preferred_list",
"=",
"[",
"'*'",
"]",
")",
":",
"# see if ",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"return",
"auto_detect_serial_win32",
"(",
"preferred_list",
"=",
"preferred_list",
")",
"return",
"auto_detect_serial_unix... | try to auto-detect serial port | [
"try",
"to",
"auto",
"-",
"detect",
"serial",
"port"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1358-L1363 | train | 230,107 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mode_string_v09 | def mode_string_v09(msg):
'''mode string for 0.9 protocol'''
mode = msg.mode
nav_mode = msg.nav_mode
MAV_MODE_UNINIT = 0
MAV_MODE_MANUAL = 2
MAV_MODE_GUIDED = 3
MAV_MODE_AUTO = 4
MAV_MODE_TEST1 = 5
MAV_MODE_TEST2 = 6
MAV_MODE_TEST3 = 7
MAV_NAV_GROUNDED = 0
MAV_NAV_LIFTOFF = 1
MAV_NAV_HOLD = 2
MAV_NAV_WAYPOINT = 3
MAV_NAV_VECTOR = 4
MAV_NAV_RETURNING = 5
MAV_NAV_LANDING = 6
MAV_NAV_LOST = 7
MAV_NAV_LOITER = 8
cmode = (mode, nav_mode)
mapping = {
(MAV_MODE_UNINIT, MAV_NAV_GROUNDED) : "INITIALISING",
(MAV_MODE_MANUAL, MAV_NAV_VECTOR) : "MANUAL",
(MAV_MODE_TEST3, MAV_NAV_VECTOR) : "CIRCLE",
(MAV_MODE_GUIDED, MAV_NAV_VECTOR) : "GUIDED",
(MAV_MODE_TEST1, MAV_NAV_VECTOR) : "STABILIZE",
(MAV_MODE_TEST2, MAV_NAV_LIFTOFF) : "FBWA",
(MAV_MODE_AUTO, MAV_NAV_WAYPOINT) : "AUTO",
(MAV_MODE_AUTO, MAV_NAV_RETURNING) : "RTL",
(MAV_MODE_AUTO, MAV_NAV_LOITER) : "LOITER",
(MAV_MODE_AUTO, MAV_NAV_LIFTOFF) : "TAKEOFF",
(MAV_MODE_AUTO, MAV_NAV_LANDING) : "LANDING",
(MAV_MODE_AUTO, MAV_NAV_HOLD) : "LOITER",
(MAV_MODE_GUIDED, MAV_NAV_VECTOR) : "GUIDED",
(MAV_MODE_GUIDED, MAV_NAV_WAYPOINT) : "GUIDED",
(100, MAV_NAV_VECTOR) : "STABILIZE",
(101, MAV_NAV_VECTOR) : "ACRO",
(102, MAV_NAV_VECTOR) : "ALT_HOLD",
(107, MAV_NAV_VECTOR) : "CIRCLE",
(109, MAV_NAV_VECTOR) : "LAND",
}
if cmode in mapping:
return mapping[cmode]
return "Mode(%s,%s)" % cmode | python | def mode_string_v09(msg):
'''mode string for 0.9 protocol'''
mode = msg.mode
nav_mode = msg.nav_mode
MAV_MODE_UNINIT = 0
MAV_MODE_MANUAL = 2
MAV_MODE_GUIDED = 3
MAV_MODE_AUTO = 4
MAV_MODE_TEST1 = 5
MAV_MODE_TEST2 = 6
MAV_MODE_TEST3 = 7
MAV_NAV_GROUNDED = 0
MAV_NAV_LIFTOFF = 1
MAV_NAV_HOLD = 2
MAV_NAV_WAYPOINT = 3
MAV_NAV_VECTOR = 4
MAV_NAV_RETURNING = 5
MAV_NAV_LANDING = 6
MAV_NAV_LOST = 7
MAV_NAV_LOITER = 8
cmode = (mode, nav_mode)
mapping = {
(MAV_MODE_UNINIT, MAV_NAV_GROUNDED) : "INITIALISING",
(MAV_MODE_MANUAL, MAV_NAV_VECTOR) : "MANUAL",
(MAV_MODE_TEST3, MAV_NAV_VECTOR) : "CIRCLE",
(MAV_MODE_GUIDED, MAV_NAV_VECTOR) : "GUIDED",
(MAV_MODE_TEST1, MAV_NAV_VECTOR) : "STABILIZE",
(MAV_MODE_TEST2, MAV_NAV_LIFTOFF) : "FBWA",
(MAV_MODE_AUTO, MAV_NAV_WAYPOINT) : "AUTO",
(MAV_MODE_AUTO, MAV_NAV_RETURNING) : "RTL",
(MAV_MODE_AUTO, MAV_NAV_LOITER) : "LOITER",
(MAV_MODE_AUTO, MAV_NAV_LIFTOFF) : "TAKEOFF",
(MAV_MODE_AUTO, MAV_NAV_LANDING) : "LANDING",
(MAV_MODE_AUTO, MAV_NAV_HOLD) : "LOITER",
(MAV_MODE_GUIDED, MAV_NAV_VECTOR) : "GUIDED",
(MAV_MODE_GUIDED, MAV_NAV_WAYPOINT) : "GUIDED",
(100, MAV_NAV_VECTOR) : "STABILIZE",
(101, MAV_NAV_VECTOR) : "ACRO",
(102, MAV_NAV_VECTOR) : "ALT_HOLD",
(107, MAV_NAV_VECTOR) : "CIRCLE",
(109, MAV_NAV_VECTOR) : "LAND",
}
if cmode in mapping:
return mapping[cmode]
return "Mode(%s,%s)" % cmode | [
"def",
"mode_string_v09",
"(",
"msg",
")",
":",
"mode",
"=",
"msg",
".",
"mode",
"nav_mode",
"=",
"msg",
".",
"nav_mode",
"MAV_MODE_UNINIT",
"=",
"0",
"MAV_MODE_MANUAL",
"=",
"2",
"MAV_MODE_GUIDED",
"=",
"3",
"MAV_MODE_AUTO",
"=",
"4",
"MAV_MODE_TEST1",
"=",... | mode string for 0.9 protocol | [
"mode",
"string",
"for",
"0",
".",
"9",
"protocol"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1365-L1412 | train | 230,108 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mode_mapping_bynumber | def mode_mapping_bynumber(mav_type):
'''return dictionary mapping mode numbers to name, or None if unknown'''
map = None
if mav_type in [mavlink.MAV_TYPE_QUADROTOR,
mavlink.MAV_TYPE_HELICOPTER,
mavlink.MAV_TYPE_HEXAROTOR,
mavlink.MAV_TYPE_OCTOROTOR,
mavlink.MAV_TYPE_COAXIAL,
mavlink.MAV_TYPE_TRICOPTER]:
map = mode_mapping_acm
if mav_type == mavlink.MAV_TYPE_FIXED_WING:
map = mode_mapping_apm
if mav_type == mavlink.MAV_TYPE_GROUND_ROVER:
map = mode_mapping_rover
if mav_type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
map = mode_mapping_tracker
if map is None:
return None
return map | python | def mode_mapping_bynumber(mav_type):
'''return dictionary mapping mode numbers to name, or None if unknown'''
map = None
if mav_type in [mavlink.MAV_TYPE_QUADROTOR,
mavlink.MAV_TYPE_HELICOPTER,
mavlink.MAV_TYPE_HEXAROTOR,
mavlink.MAV_TYPE_OCTOROTOR,
mavlink.MAV_TYPE_COAXIAL,
mavlink.MAV_TYPE_TRICOPTER]:
map = mode_mapping_acm
if mav_type == mavlink.MAV_TYPE_FIXED_WING:
map = mode_mapping_apm
if mav_type == mavlink.MAV_TYPE_GROUND_ROVER:
map = mode_mapping_rover
if mav_type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
map = mode_mapping_tracker
if map is None:
return None
return map | [
"def",
"mode_mapping_bynumber",
"(",
"mav_type",
")",
":",
"map",
"=",
"None",
"if",
"mav_type",
"in",
"[",
"mavlink",
".",
"MAV_TYPE_QUADROTOR",
",",
"mavlink",
".",
"MAV_TYPE_HELICOPTER",
",",
"mavlink",
".",
"MAV_TYPE_HEXAROTOR",
",",
"mavlink",
".",
"MAV_TYP... | return dictionary mapping mode numbers to name, or None if unknown | [
"return",
"dictionary",
"mapping",
"mode",
"numbers",
"to",
"name",
"or",
"None",
"if",
"unknown"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1595-L1613 | train | 230,109 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mode_string_v10 | def mode_string_v10(msg):
'''mode string for 1.0 protocol, from heartbeat'''
if msg.autopilot == mavlink.MAV_AUTOPILOT_PX4:
return interpret_px4_mode(msg.base_mode, msg.custom_mode)
if not msg.base_mode & mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED:
return "Mode(0x%08x)" % msg.base_mode
if msg.type in [ mavlink.MAV_TYPE_QUADROTOR, mavlink.MAV_TYPE_HEXAROTOR,
mavlink.MAV_TYPE_OCTOROTOR, mavlink.MAV_TYPE_TRICOPTER,
mavlink.MAV_TYPE_COAXIAL,
mavlink.MAV_TYPE_HELICOPTER ]:
if msg.custom_mode in mode_mapping_acm:
return mode_mapping_acm[msg.custom_mode]
if msg.type == mavlink.MAV_TYPE_FIXED_WING:
if msg.custom_mode in mode_mapping_apm:
return mode_mapping_apm[msg.custom_mode]
if msg.type == mavlink.MAV_TYPE_GROUND_ROVER:
if msg.custom_mode in mode_mapping_rover:
return mode_mapping_rover[msg.custom_mode]
if msg.type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
if msg.custom_mode in mode_mapping_tracker:
return mode_mapping_tracker[msg.custom_mode]
return "Mode(%u)" % msg.custom_mode | python | def mode_string_v10(msg):
'''mode string for 1.0 protocol, from heartbeat'''
if msg.autopilot == mavlink.MAV_AUTOPILOT_PX4:
return interpret_px4_mode(msg.base_mode, msg.custom_mode)
if not msg.base_mode & mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED:
return "Mode(0x%08x)" % msg.base_mode
if msg.type in [ mavlink.MAV_TYPE_QUADROTOR, mavlink.MAV_TYPE_HEXAROTOR,
mavlink.MAV_TYPE_OCTOROTOR, mavlink.MAV_TYPE_TRICOPTER,
mavlink.MAV_TYPE_COAXIAL,
mavlink.MAV_TYPE_HELICOPTER ]:
if msg.custom_mode in mode_mapping_acm:
return mode_mapping_acm[msg.custom_mode]
if msg.type == mavlink.MAV_TYPE_FIXED_WING:
if msg.custom_mode in mode_mapping_apm:
return mode_mapping_apm[msg.custom_mode]
if msg.type == mavlink.MAV_TYPE_GROUND_ROVER:
if msg.custom_mode in mode_mapping_rover:
return mode_mapping_rover[msg.custom_mode]
if msg.type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
if msg.custom_mode in mode_mapping_tracker:
return mode_mapping_tracker[msg.custom_mode]
return "Mode(%u)" % msg.custom_mode | [
"def",
"mode_string_v10",
"(",
"msg",
")",
":",
"if",
"msg",
".",
"autopilot",
"==",
"mavlink",
".",
"MAV_AUTOPILOT_PX4",
":",
"return",
"interpret_px4_mode",
"(",
"msg",
".",
"base_mode",
",",
"msg",
".",
"custom_mode",
")",
"if",
"not",
"msg",
".",
"base... | mode string for 1.0 protocol, from heartbeat | [
"mode",
"string",
"for",
"1",
".",
"0",
"protocol",
"from",
"heartbeat"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1616-L1637 | train | 230,110 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.auto_mavlink_version | def auto_mavlink_version(self, buf):
'''auto-switch mavlink protocol version'''
global mavlink
if len(buf) == 0:
return
try:
magic = ord(buf[0])
except:
magic = buf[0]
if not magic in [ 85, 254, 253 ]:
return
self.first_byte = False
if self.WIRE_PROTOCOL_VERSION == "0.9" and magic == 254:
self.WIRE_PROTOCOL_VERSION = "1.0"
set_dialect(current_dialect)
elif self.WIRE_PROTOCOL_VERSION == "1.0" and magic == 85:
self.WIRE_PROTOCOL_VERSION = "0.9"
os.environ['MAVLINK09'] = '1'
set_dialect(current_dialect)
elif self.WIRE_PROTOCOL_VERSION != "2.0" and magic == 253:
self.WIRE_PROTOCOL_VERSION = "2.0"
os.environ['MAVLINK20'] = '1'
set_dialect(current_dialect)
else:
return
# switch protocol
(callback, callback_args, callback_kwargs) = (self.mav.callback,
self.mav.callback_args,
self.mav.callback_kwargs)
self.mav = mavlink.MAVLink(self, srcSystem=self.source_system)
self.mav.robust_parsing = self.robust_parsing
self.WIRE_PROTOCOL_VERSION = mavlink.WIRE_PROTOCOL_VERSION
(self.mav.callback, self.mav.callback_args, self.mav.callback_kwargs) = (callback,
callback_args,
callback_kwargs) | python | def auto_mavlink_version(self, buf):
'''auto-switch mavlink protocol version'''
global mavlink
if len(buf) == 0:
return
try:
magic = ord(buf[0])
except:
magic = buf[0]
if not magic in [ 85, 254, 253 ]:
return
self.first_byte = False
if self.WIRE_PROTOCOL_VERSION == "0.9" and magic == 254:
self.WIRE_PROTOCOL_VERSION = "1.0"
set_dialect(current_dialect)
elif self.WIRE_PROTOCOL_VERSION == "1.0" and magic == 85:
self.WIRE_PROTOCOL_VERSION = "0.9"
os.environ['MAVLINK09'] = '1'
set_dialect(current_dialect)
elif self.WIRE_PROTOCOL_VERSION != "2.0" and magic == 253:
self.WIRE_PROTOCOL_VERSION = "2.0"
os.environ['MAVLINK20'] = '1'
set_dialect(current_dialect)
else:
return
# switch protocol
(callback, callback_args, callback_kwargs) = (self.mav.callback,
self.mav.callback_args,
self.mav.callback_kwargs)
self.mav = mavlink.MAVLink(self, srcSystem=self.source_system)
self.mav.robust_parsing = self.robust_parsing
self.WIRE_PROTOCOL_VERSION = mavlink.WIRE_PROTOCOL_VERSION
(self.mav.callback, self.mav.callback_args, self.mav.callback_kwargs) = (callback,
callback_args,
callback_kwargs) | [
"def",
"auto_mavlink_version",
"(",
"self",
",",
"buf",
")",
":",
"global",
"mavlink",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
":",
"return",
"try",
":",
"magic",
"=",
"ord",
"(",
"buf",
"[",
"0",
"]",
")",
"except",
":",
"magic",
"=",
"buf",
"[... | auto-switch mavlink protocol version | [
"auto",
"-",
"switch",
"mavlink",
"protocol",
"version"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L154-L188 | train | 230,111 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.select | def select(self, timeout):
'''wait for up to timeout seconds for more data'''
if self.fd is None:
time.sleep(min(timeout,0.5))
return True
try:
(rin, win, xin) = select.select([self.fd], [], [], timeout)
except select.error:
return False
return len(rin) == 1 | python | def select(self, timeout):
'''wait for up to timeout seconds for more data'''
if self.fd is None:
time.sleep(min(timeout,0.5))
return True
try:
(rin, win, xin) = select.select([self.fd], [], [], timeout)
except select.error:
return False
return len(rin) == 1 | [
"def",
"select",
"(",
"self",
",",
"timeout",
")",
":",
"if",
"self",
".",
"fd",
"is",
"None",
":",
"time",
".",
"sleep",
"(",
"min",
"(",
"timeout",
",",
"0.5",
")",
")",
"return",
"True",
"try",
":",
"(",
"rin",
",",
"win",
",",
"xin",
")",
... | wait for up to timeout seconds for more data | [
"wait",
"for",
"up",
"to",
"timeout",
"seconds",
"for",
"more",
"data"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L203-L212 | train | 230,112 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.packet_loss | def packet_loss(self):
'''packet loss as a percentage'''
if self.mav_count == 0:
return 0
return (100.0*self.mav_loss)/(self.mav_count+self.mav_loss) | python | def packet_loss(self):
'''packet loss as a percentage'''
if self.mav_count == 0:
return 0
return (100.0*self.mav_loss)/(self.mav_count+self.mav_loss) | [
"def",
"packet_loss",
"(",
"self",
")",
":",
"if",
"self",
".",
"mav_count",
"==",
"0",
":",
"return",
"0",
"return",
"(",
"100.0",
"*",
"self",
".",
"mav_loss",
")",
"/",
"(",
"self",
".",
"mav_count",
"+",
"self",
".",
"mav_loss",
")"
] | packet loss as a percentage | [
"packet",
"loss",
"as",
"a",
"percentage"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L295-L299 | train | 230,113 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.recv_match | def recv_match(self, condition=None, type=None, blocking=False, timeout=None):
'''recv the next MAVLink message that matches the given condition
type can be a string or a list of strings'''
if type is not None and not isinstance(type, list):
type = [type]
start_time = time.time()
while True:
if timeout is not None:
now = time.time()
if now < start_time:
start_time = now # If an external process rolls back system time, we should not spin forever.
if start_time + timeout < time.time():
return None
m = self.recv_msg()
if m is None:
if blocking:
for hook in self.idle_hooks:
hook(self)
if timeout is None:
self.select(0.05)
else:
self.select(timeout/2)
continue
return None
if type is not None and not m.get_type() in type:
continue
if not evaluate_condition(condition, self.messages):
continue
return m | python | def recv_match(self, condition=None, type=None, blocking=False, timeout=None):
'''recv the next MAVLink message that matches the given condition
type can be a string or a list of strings'''
if type is not None and not isinstance(type, list):
type = [type]
start_time = time.time()
while True:
if timeout is not None:
now = time.time()
if now < start_time:
start_time = now # If an external process rolls back system time, we should not spin forever.
if start_time + timeout < time.time():
return None
m = self.recv_msg()
if m is None:
if blocking:
for hook in self.idle_hooks:
hook(self)
if timeout is None:
self.select(0.05)
else:
self.select(timeout/2)
continue
return None
if type is not None and not m.get_type() in type:
continue
if not evaluate_condition(condition, self.messages):
continue
return m | [
"def",
"recv_match",
"(",
"self",
",",
"condition",
"=",
"None",
",",
"type",
"=",
"None",
",",
"blocking",
"=",
"False",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"type",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"type",
",",
"list",
... | recv the next MAVLink message that matches the given condition
type can be a string or a list of strings | [
"recv",
"the",
"next",
"MAVLink",
"message",
"that",
"matches",
"the",
"given",
"condition",
"type",
"can",
"be",
"a",
"string",
"or",
"a",
"list",
"of",
"strings"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L331-L359 | train | 230,114 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.setup_logfile | def setup_logfile(self, logfile, mode='w'):
'''start logging to the given logfile, with timestamps'''
self.logfile = open(logfile, mode=mode) | python | def setup_logfile(self, logfile, mode='w'):
'''start logging to the given logfile, with timestamps'''
self.logfile = open(logfile, mode=mode) | [
"def",
"setup_logfile",
"(",
"self",
",",
"logfile",
",",
"mode",
"=",
"'w'",
")",
":",
"self",
".",
"logfile",
"=",
"open",
"(",
"logfile",
",",
"mode",
"=",
"mode",
")"
] | start logging to the given logfile, with timestamps | [
"start",
"logging",
"to",
"the",
"given",
"logfile",
"with",
"timestamps"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L373-L375 | train | 230,115 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.setup_logfile_raw | def setup_logfile_raw(self, logfile, mode='w'):
'''start logging raw bytes to the given logfile, without timestamps'''
self.logfile_raw = open(logfile, mode=mode) | python | def setup_logfile_raw(self, logfile, mode='w'):
'''start logging raw bytes to the given logfile, without timestamps'''
self.logfile_raw = open(logfile, mode=mode) | [
"def",
"setup_logfile_raw",
"(",
"self",
",",
"logfile",
",",
"mode",
"=",
"'w'",
")",
":",
"self",
".",
"logfile_raw",
"=",
"open",
"(",
"logfile",
",",
"mode",
"=",
"mode",
")"
] | start logging raw bytes to the given logfile, without timestamps | [
"start",
"logging",
"raw",
"bytes",
"to",
"the",
"given",
"logfile",
"without",
"timestamps"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L377-L379 | train | 230,116 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.param_fetch_all | def param_fetch_all(self):
'''initiate fetch of all parameters'''
if time.time() - getattr(self, 'param_fetch_start', 0) < 2.0:
# don't fetch too often
return
self.param_fetch_start = time.time()
self.param_fetch_in_progress = True
self.mav.param_request_list_send(self.target_system, self.target_component) | python | def param_fetch_all(self):
'''initiate fetch of all parameters'''
if time.time() - getattr(self, 'param_fetch_start', 0) < 2.0:
# don't fetch too often
return
self.param_fetch_start = time.time()
self.param_fetch_in_progress = True
self.mav.param_request_list_send(self.target_system, self.target_component) | [
"def",
"param_fetch_all",
"(",
"self",
")",
":",
"if",
"time",
".",
"time",
"(",
")",
"-",
"getattr",
"(",
"self",
",",
"'param_fetch_start'",
",",
"0",
")",
"<",
"2.0",
":",
"# don't fetch too often",
"return",
"self",
".",
"param_fetch_start",
"=",
"time... | initiate fetch of all parameters | [
"initiate",
"fetch",
"of",
"all",
"parameters"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L385-L392 | train | 230,117 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.param_fetch_one | def param_fetch_one(self, name):
'''initiate fetch of one parameter'''
try:
idx = int(name)
self.mav.param_request_read_send(self.target_system, self.target_component, "", idx)
except Exception:
self.mav.param_request_read_send(self.target_system, self.target_component, name, -1) | python | def param_fetch_one(self, name):
'''initiate fetch of one parameter'''
try:
idx = int(name)
self.mav.param_request_read_send(self.target_system, self.target_component, "", idx)
except Exception:
self.mav.param_request_read_send(self.target_system, self.target_component, name, -1) | [
"def",
"param_fetch_one",
"(",
"self",
",",
"name",
")",
":",
"try",
":",
"idx",
"=",
"int",
"(",
"name",
")",
"self",
".",
"mav",
".",
"param_request_read_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"\"\"",
",",
... | initiate fetch of one parameter | [
"initiate",
"fetch",
"of",
"one",
"parameter"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L394-L400 | train | 230,118 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.time_since | def time_since(self, mtype):
'''return the time since the last message of type mtype was received'''
if not mtype in self.messages:
return time.time() - self.start_time
return time.time() - self.messages[mtype]._timestamp | python | def time_since(self, mtype):
'''return the time since the last message of type mtype was received'''
if not mtype in self.messages:
return time.time() - self.start_time
return time.time() - self.messages[mtype]._timestamp | [
"def",
"time_since",
"(",
"self",
",",
"mtype",
")",
":",
"if",
"not",
"mtype",
"in",
"self",
".",
"messages",
":",
"return",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"start_time",
"return",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
... | return the time since the last message of type mtype was received | [
"return",
"the",
"time",
"since",
"the",
"last",
"message",
"of",
"type",
"mtype",
"was",
"received"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L402-L406 | train | 230,119 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.param_set_send | def param_set_send(self, parm_name, parm_value, parm_type=None):
'''wrapper for parameter set'''
if self.mavlink10():
if parm_type == None:
parm_type = mavlink.MAVLINK_TYPE_FLOAT
self.mav.param_set_send(self.target_system, self.target_component,
parm_name, parm_value, parm_type)
else:
self.mav.param_set_send(self.target_system, self.target_component,
parm_name, parm_value) | python | def param_set_send(self, parm_name, parm_value, parm_type=None):
'''wrapper for parameter set'''
if self.mavlink10():
if parm_type == None:
parm_type = mavlink.MAVLINK_TYPE_FLOAT
self.mav.param_set_send(self.target_system, self.target_component,
parm_name, parm_value, parm_type)
else:
self.mav.param_set_send(self.target_system, self.target_component,
parm_name, parm_value) | [
"def",
"param_set_send",
"(",
"self",
",",
"parm_name",
",",
"parm_value",
",",
"parm_type",
"=",
"None",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"if",
"parm_type",
"==",
"None",
":",
"parm_type",
"=",
"mavlink",
".",
"MAVLINK_TYPE_FLOAT",... | wrapper for parameter set | [
"wrapper",
"for",
"parameter",
"set"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L408-L417 | train | 230,120 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.waypoint_request_list_send | def waypoint_request_list_send(self):
'''wrapper for waypoint_request_list_send'''
if self.mavlink10():
self.mav.mission_request_list_send(self.target_system, self.target_component)
else:
self.mav.waypoint_request_list_send(self.target_system, self.target_component) | python | def waypoint_request_list_send(self):
'''wrapper for waypoint_request_list_send'''
if self.mavlink10():
self.mav.mission_request_list_send(self.target_system, self.target_component)
else:
self.mav.waypoint_request_list_send(self.target_system, self.target_component) | [
"def",
"waypoint_request_list_send",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"mission_request_list_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
")",
"else",
":",
"self"... | wrapper for waypoint_request_list_send | [
"wrapper",
"for",
"waypoint_request_list_send"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L419-L424 | train | 230,121 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.waypoint_clear_all_send | def waypoint_clear_all_send(self):
'''wrapper for waypoint_clear_all_send'''
if self.mavlink10():
self.mav.mission_clear_all_send(self.target_system, self.target_component)
else:
self.mav.waypoint_clear_all_send(self.target_system, self.target_component) | python | def waypoint_clear_all_send(self):
'''wrapper for waypoint_clear_all_send'''
if self.mavlink10():
self.mav.mission_clear_all_send(self.target_system, self.target_component)
else:
self.mav.waypoint_clear_all_send(self.target_system, self.target_component) | [
"def",
"waypoint_clear_all_send",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"mission_clear_all_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
")",
"else",
":",
"self",
".... | wrapper for waypoint_clear_all_send | [
"wrapper",
"for",
"waypoint_clear_all_send"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L426-L431 | train | 230,122 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.waypoint_request_send | def waypoint_request_send(self, seq):
'''wrapper for waypoint_request_send'''
if self.mavlink10():
self.mav.mission_request_send(self.target_system, self.target_component, seq)
else:
self.mav.waypoint_request_send(self.target_system, self.target_component, seq) | python | def waypoint_request_send(self, seq):
'''wrapper for waypoint_request_send'''
if self.mavlink10():
self.mav.mission_request_send(self.target_system, self.target_component, seq)
else:
self.mav.waypoint_request_send(self.target_system, self.target_component, seq) | [
"def",
"waypoint_request_send",
"(",
"self",
",",
"seq",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"mission_request_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"seq",
")",
"... | wrapper for waypoint_request_send | [
"wrapper",
"for",
"waypoint_request_send"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L433-L438 | train | 230,123 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.waypoint_set_current_send | def waypoint_set_current_send(self, seq):
'''wrapper for waypoint_set_current_send'''
if self.mavlink10():
self.mav.mission_set_current_send(self.target_system, self.target_component, seq)
else:
self.mav.waypoint_set_current_send(self.target_system, self.target_component, seq) | python | def waypoint_set_current_send(self, seq):
'''wrapper for waypoint_set_current_send'''
if self.mavlink10():
self.mav.mission_set_current_send(self.target_system, self.target_component, seq)
else:
self.mav.waypoint_set_current_send(self.target_system, self.target_component, seq) | [
"def",
"waypoint_set_current_send",
"(",
"self",
",",
"seq",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"mission_set_current_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"seq",
... | wrapper for waypoint_set_current_send | [
"wrapper",
"for",
"waypoint_set_current_send"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L440-L445 | train | 230,124 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.waypoint_current | def waypoint_current(self):
'''return current waypoint'''
if self.mavlink10():
m = self.recv_match(type='MISSION_CURRENT', blocking=True)
else:
m = self.recv_match(type='WAYPOINT_CURRENT', blocking=True)
return m.seq | python | def waypoint_current(self):
'''return current waypoint'''
if self.mavlink10():
m = self.recv_match(type='MISSION_CURRENT', blocking=True)
else:
m = self.recv_match(type='WAYPOINT_CURRENT', blocking=True)
return m.seq | [
"def",
"waypoint_current",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"m",
"=",
"self",
".",
"recv_match",
"(",
"type",
"=",
"'MISSION_CURRENT'",
",",
"blocking",
"=",
"True",
")",
"else",
":",
"m",
"=",
"self",
".",
"recv_... | return current waypoint | [
"return",
"current",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L447-L453 | train | 230,125 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.waypoint_count_send | def waypoint_count_send(self, seq):
'''wrapper for waypoint_count_send'''
if self.mavlink10():
self.mav.mission_count_send(self.target_system, self.target_component, seq)
else:
self.mav.waypoint_count_send(self.target_system, self.target_component, seq) | python | def waypoint_count_send(self, seq):
'''wrapper for waypoint_count_send'''
if self.mavlink10():
self.mav.mission_count_send(self.target_system, self.target_component, seq)
else:
self.mav.waypoint_count_send(self.target_system, self.target_component, seq) | [
"def",
"waypoint_count_send",
"(",
"self",
",",
"seq",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"mission_count_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"seq",
")",
"else... | wrapper for waypoint_count_send | [
"wrapper",
"for",
"waypoint_count_send"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L455-L460 | train | 230,126 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_mode_auto | def set_mode_auto(self):
'''enter auto mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_MISSION_START, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_SET_AUTO = 13
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_SET_AUTO) | python | def set_mode_auto(self):
'''enter auto mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_MISSION_START, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_SET_AUTO = 13
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_SET_AUTO) | [
"def",
"set_mode_auto",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mavlink",
".",
"MAV_CMD_MISSION_START",... | enter auto mode | [
"enter",
"auto",
"mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L482-L489 | train | 230,127 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_mode | def set_mode(self, mode, custom_mode = 0, custom_sub_mode = 0):
'''set arbitrary flight mode'''
mav_autopilot = self.field('HEARTBEAT', 'autopilot', None)
if mav_autopilot == mavlink.MAV_AUTOPILOT_PX4:
self.set_mode_px4(mode, custom_mode, custom_sub_mode)
else:
self.set_mode_apm(mode) | python | def set_mode(self, mode, custom_mode = 0, custom_sub_mode = 0):
'''set arbitrary flight mode'''
mav_autopilot = self.field('HEARTBEAT', 'autopilot', None)
if mav_autopilot == mavlink.MAV_AUTOPILOT_PX4:
self.set_mode_px4(mode, custom_mode, custom_sub_mode)
else:
self.set_mode_apm(mode) | [
"def",
"set_mode",
"(",
"self",
",",
"mode",
",",
"custom_mode",
"=",
"0",
",",
"custom_sub_mode",
"=",
"0",
")",
":",
"mav_autopilot",
"=",
"self",
".",
"field",
"(",
"'HEARTBEAT'",
",",
"'autopilot'",
",",
"None",
")",
"if",
"mav_autopilot",
"==",
"mav... | set arbitrary flight mode | [
"set",
"arbitrary",
"flight",
"mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L543-L549 | train | 230,128 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_mode_rtl | def set_mode_rtl(self):
'''enter RTL mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_RETURN = 3
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_RETURN) | python | def set_mode_rtl(self):
'''enter RTL mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_RETURN = 3
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_RETURN) | [
"def",
"set_mode_rtl",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mavlink",
".",
"MAV_CMD_NAV_RETURN_TO_LA... | enter RTL mode | [
"enter",
"RTL",
"mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L551-L558 | train | 230,129 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_mode_manual | def set_mode_manual(self):
'''enter MANUAL mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_DO_SET_MODE, 0,
mavlink.MAV_MODE_MANUAL_ARMED,
0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_SET_MANUAL = 12
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_SET_MANUAL) | python | def set_mode_manual(self):
'''enter MANUAL mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_DO_SET_MODE, 0,
mavlink.MAV_MODE_MANUAL_ARMED,
0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_SET_MANUAL = 12
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_SET_MANUAL) | [
"def",
"set_mode_manual",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mavlink",
".",
"MAV_CMD_DO_SET_MODE",... | enter MANUAL mode | [
"enter",
"MANUAL",
"mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L560-L569 | train | 230,130 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_mode_fbwa | def set_mode_fbwa(self):
'''enter FBWA mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_DO_SET_MODE, 0,
mavlink.MAV_MODE_STABILIZE_ARMED,
0, 0, 0, 0, 0, 0)
else:
print("Forcing FBWA not supported") | python | def set_mode_fbwa(self):
'''enter FBWA mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_DO_SET_MODE, 0,
mavlink.MAV_MODE_STABILIZE_ARMED,
0, 0, 0, 0, 0, 0)
else:
print("Forcing FBWA not supported") | [
"def",
"set_mode_fbwa",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mavlink",
".",
"MAV_CMD_DO_SET_MODE",
... | enter FBWA mode | [
"enter",
"FBWA",
"mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L571-L579 | train | 230,131 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_mode_loiter | def set_mode_loiter(self):
'''enter LOITER mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_NAV_LOITER_UNLIM, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_LOITER = 27
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_LOITER) | python | def set_mode_loiter(self):
'''enter LOITER mode'''
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_NAV_LOITER_UNLIM, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_LOITER = 27
self.mav.action_send(self.target_system, self.target_component, MAV_ACTION_LOITER) | [
"def",
"set_mode_loiter",
"(",
"self",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mavlink",
".",
"MAV_CMD_NAV_LOITER_UN... | enter LOITER mode | [
"enter",
"LOITER",
"mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L581-L588 | train | 230,132 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_servo | def set_servo(self, channel, pwm):
'''set a servo value'''
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_DO_SET_SERVO, 0,
channel, pwm,
0, 0, 0, 0, 0) | python | def set_servo(self, channel, pwm):
'''set a servo value'''
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_DO_SET_SERVO, 0,
channel, pwm,
0, 0, 0, 0, 0) | [
"def",
"set_servo",
"(",
"self",
",",
"channel",
",",
"pwm",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mavlink",
".",
"MAV_CMD_DO_SET_SERVO",
",",
"0",
",",
"chann... | set a servo value | [
"set",
"a",
"servo",
"value"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L590-L595 | train | 230,133 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.set_relay | def set_relay(self, relay_pin=0, state=True):
'''Set relay_pin to value of state'''
if self.mavlink10():
self.mav.command_long_send(
self.target_system, # target_system
self.target_component, # target_component
mavlink.MAV_CMD_DO_SET_RELAY, # command
0, # Confirmation
relay_pin, # Relay Number
int(state), # state (1 to indicate arm)
0, # param3 (all other params meaningless)
0, # param4
0, # param5
0, # param6
0) # param7
else:
print("Setting relays not supported.") | python | def set_relay(self, relay_pin=0, state=True):
'''Set relay_pin to value of state'''
if self.mavlink10():
self.mav.command_long_send(
self.target_system, # target_system
self.target_component, # target_component
mavlink.MAV_CMD_DO_SET_RELAY, # command
0, # Confirmation
relay_pin, # Relay Number
int(state), # state (1 to indicate arm)
0, # param3 (all other params meaningless)
0, # param4
0, # param5
0, # param6
0) # param7
else:
print("Setting relays not supported.") | [
"def",
"set_relay",
"(",
"self",
",",
"relay_pin",
"=",
"0",
",",
"state",
"=",
"True",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"self",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"target_system",
",",
"# target_system",
"s... | Set relay_pin to value of state | [
"Set",
"relay_pin",
"to",
"value",
"of",
"state"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L598-L614 | train | 230,134 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.reboot_autopilot | def reboot_autopilot(self, hold_in_bootloader=False):
'''reboot the autopilot'''
if self.mavlink10():
if hold_in_bootloader:
param1 = 3
else:
param1 = 1
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
param1, 0, 0, 0, 0, 0, 0)
# send an old style reboot immediately afterwards in case it is an older firmware
# that doesn't understand the new convention
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
1, 0, 0, 0, 0, 0, 0) | python | def reboot_autopilot(self, hold_in_bootloader=False):
'''reboot the autopilot'''
if self.mavlink10():
if hold_in_bootloader:
param1 = 3
else:
param1 = 1
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
param1, 0, 0, 0, 0, 0, 0)
# send an old style reboot immediately afterwards in case it is an older firmware
# that doesn't understand the new convention
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
1, 0, 0, 0, 0, 0, 0) | [
"def",
"reboot_autopilot",
"(",
"self",
",",
"hold_in_bootloader",
"=",
"False",
")",
":",
"if",
"self",
".",
"mavlink10",
"(",
")",
":",
"if",
"hold_in_bootloader",
":",
"param1",
"=",
"3",
"else",
":",
"param1",
"=",
"1",
"self",
".",
"mav",
".",
"co... | reboot the autopilot | [
"reboot",
"the",
"autopilot"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L632-L646 | train | 230,135 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.location | def location(self, relative_alt=False):
'''return current location'''
self.wait_gps_fix()
# wait for another VFR_HUD, to ensure we have correct altitude
self.recv_match(type='VFR_HUD', blocking=True)
self.recv_match(type='GLOBAL_POSITION_INT', blocking=True)
if relative_alt:
alt = self.messages['GLOBAL_POSITION_INT'].relative_alt*0.001
else:
alt = self.messages['VFR_HUD'].alt
return location(self.messages['GPS_RAW_INT'].lat*1.0e-7,
self.messages['GPS_RAW_INT'].lon*1.0e-7,
alt,
self.messages['VFR_HUD'].heading) | python | def location(self, relative_alt=False):
'''return current location'''
self.wait_gps_fix()
# wait for another VFR_HUD, to ensure we have correct altitude
self.recv_match(type='VFR_HUD', blocking=True)
self.recv_match(type='GLOBAL_POSITION_INT', blocking=True)
if relative_alt:
alt = self.messages['GLOBAL_POSITION_INT'].relative_alt*0.001
else:
alt = self.messages['VFR_HUD'].alt
return location(self.messages['GPS_RAW_INT'].lat*1.0e-7,
self.messages['GPS_RAW_INT'].lon*1.0e-7,
alt,
self.messages['VFR_HUD'].heading) | [
"def",
"location",
"(",
"self",
",",
"relative_alt",
"=",
"False",
")",
":",
"self",
".",
"wait_gps_fix",
"(",
")",
"# wait for another VFR_HUD, to ensure we have correct altitude",
"self",
".",
"recv_match",
"(",
"type",
"=",
"'VFR_HUD'",
",",
"blocking",
"=",
"T... | return current location | [
"return",
"current",
"location"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L657-L670 | train | 230,136 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.motors_armed | def motors_armed(self):
'''return true if motors armed'''
if not 'HEARTBEAT' in self.messages:
return False
m = self.messages['HEARTBEAT']
return (m.base_mode & mavlink.MAV_MODE_FLAG_SAFETY_ARMED) != 0 | python | def motors_armed(self):
'''return true if motors armed'''
if not 'HEARTBEAT' in self.messages:
return False
m = self.messages['HEARTBEAT']
return (m.base_mode & mavlink.MAV_MODE_FLAG_SAFETY_ARMED) != 0 | [
"def",
"motors_armed",
"(",
"self",
")",
":",
"if",
"not",
"'HEARTBEAT'",
"in",
"self",
".",
"messages",
":",
"return",
"False",
"m",
"=",
"self",
".",
"messages",
"[",
"'HEARTBEAT'",
"]",
"return",
"(",
"m",
".",
"base_mode",
"&",
"mavlink",
".",
"MAV... | return true if motors armed | [
"return",
"true",
"if",
"motors",
"armed"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L704-L709 | train | 230,137 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.field | def field(self, type, field, default=None):
'''convenient function for returning an arbitrary MAVLink
field with a default'''
if not type in self.messages:
return default
return getattr(self.messages[type], field, default) | python | def field(self, type, field, default=None):
'''convenient function for returning an arbitrary MAVLink
field with a default'''
if not type in self.messages:
return default
return getattr(self.messages[type], field, default) | [
"def",
"field",
"(",
"self",
",",
"type",
",",
"field",
",",
"default",
"=",
"None",
")",
":",
"if",
"not",
"type",
"in",
"self",
".",
"messages",
":",
"return",
"default",
"return",
"getattr",
"(",
"self",
".",
"messages",
"[",
"type",
"]",
",",
"... | convenient function for returning an arbitrary MAVLink
field with a default | [
"convenient",
"function",
"for",
"returning",
"an",
"arbitrary",
"MAVLink",
"field",
"with",
"a",
"default"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L726-L731 | train | 230,138 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.setup_signing | def setup_signing(self, secret_key, sign_outgoing=True, allow_unsigned_callback=None, initial_timestamp=None, link_id=None):
'''setup for MAVLink2 signing'''
self.mav.signing.secret_key = secret_key
self.mav.signing.sign_outgoing = sign_outgoing
self.mav.signing.allow_unsigned_callback = allow_unsigned_callback
if link_id is None:
# auto-increment the link_id for each link
global global_link_id
link_id = global_link_id
global_link_id = min(global_link_id + 1, 255)
self.mav.signing.link_id = link_id
if initial_timestamp is None:
# timestamp is time since 1/1/2015
epoch_offset = 1420070400
now = max(time.time(), epoch_offset)
initial_timestamp = now - epoch_offset
initial_timestamp = int(initial_timestamp * 100 * 1000)
# initial_timestamp is in 10usec units
self.mav.signing.timestamp = initial_timestamp | python | def setup_signing(self, secret_key, sign_outgoing=True, allow_unsigned_callback=None, initial_timestamp=None, link_id=None):
'''setup for MAVLink2 signing'''
self.mav.signing.secret_key = secret_key
self.mav.signing.sign_outgoing = sign_outgoing
self.mav.signing.allow_unsigned_callback = allow_unsigned_callback
if link_id is None:
# auto-increment the link_id for each link
global global_link_id
link_id = global_link_id
global_link_id = min(global_link_id + 1, 255)
self.mav.signing.link_id = link_id
if initial_timestamp is None:
# timestamp is time since 1/1/2015
epoch_offset = 1420070400
now = max(time.time(), epoch_offset)
initial_timestamp = now - epoch_offset
initial_timestamp = int(initial_timestamp * 100 * 1000)
# initial_timestamp is in 10usec units
self.mav.signing.timestamp = initial_timestamp | [
"def",
"setup_signing",
"(",
"self",
",",
"secret_key",
",",
"sign_outgoing",
"=",
"True",
",",
"allow_unsigned_callback",
"=",
"None",
",",
"initial_timestamp",
"=",
"None",
",",
"link_id",
"=",
"None",
")",
":",
"self",
".",
"mav",
".",
"signing",
".",
"... | setup for MAVLink2 signing | [
"setup",
"for",
"MAVLink2",
"signing"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L740-L758 | train | 230,139 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavfile.disable_signing | def disable_signing(self):
'''disable MAVLink2 signing'''
self.mav.signing.secret_key = None
self.mav.signing.sign_outgoing = False
self.mav.signing.allow_unsigned_callback = None
self.mav.signing.link_id = 0
self.mav.signing.timestamp = 0 | python | def disable_signing(self):
'''disable MAVLink2 signing'''
self.mav.signing.secret_key = None
self.mav.signing.sign_outgoing = False
self.mav.signing.allow_unsigned_callback = None
self.mav.signing.link_id = 0
self.mav.signing.timestamp = 0 | [
"def",
"disable_signing",
"(",
"self",
")",
":",
"self",
".",
"mav",
".",
"signing",
".",
"secret_key",
"=",
"None",
"self",
".",
"mav",
".",
"signing",
".",
"sign_outgoing",
"=",
"False",
"self",
".",
"mav",
".",
"signing",
".",
"allow_unsigned_callback",... | disable MAVLink2 signing | [
"disable",
"MAVLink2",
"signing"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L760-L766 | train | 230,140 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavlogfile.scan_timestamp | def scan_timestamp(self, tbuf):
'''scan forward looking in a tlog for a timestamp in a reasonable range'''
while True:
(tusec,) = struct.unpack('>Q', tbuf)
t = tusec * 1.0e-6
if abs(t - self._last_timestamp) <= 3*24*60*60:
break
c = self.f.read(1)
if len(c) != 1:
break
tbuf = tbuf[1:] + c
return t | python | def scan_timestamp(self, tbuf):
'''scan forward looking in a tlog for a timestamp in a reasonable range'''
while True:
(tusec,) = struct.unpack('>Q', tbuf)
t = tusec * 1.0e-6
if abs(t - self._last_timestamp) <= 3*24*60*60:
break
c = self.f.read(1)
if len(c) != 1:
break
tbuf = tbuf[1:] + c
return t | [
"def",
"scan_timestamp",
"(",
"self",
",",
"tbuf",
")",
":",
"while",
"True",
":",
"(",
"tusec",
",",
")",
"=",
"struct",
".",
"unpack",
"(",
"'>Q'",
",",
"tbuf",
")",
"t",
"=",
"tusec",
"*",
"1.0e-6",
"if",
"abs",
"(",
"t",
"-",
"self",
".",
"... | scan forward looking in a tlog for a timestamp in a reasonable range | [
"scan",
"forward",
"looking",
"in",
"a",
"tlog",
"for",
"a",
"timestamp",
"in",
"a",
"reasonable",
"range"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1073-L1084 | train | 230,141 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavlogfile.pre_message | def pre_message(self):
'''read timestamp if needed'''
# read the timestamp
if self.filesize != 0:
self.percent = (100.0 * self.f.tell()) / self.filesize
if self.notimestamps:
return
if self.planner_format:
tbuf = self.f.read(21)
if len(tbuf) != 21 or tbuf[0] != '-' or tbuf[20] != ':':
raise RuntimeError('bad planner timestamp %s' % tbuf)
hnsec = self._two64 + float(tbuf[0:20])
t = hnsec * 1.0e-7 # convert to seconds
t -= 719163 * 24 * 60 * 60 # convert to 1970 base
self._link = 0
else:
tbuf = self.f.read(8)
if len(tbuf) != 8:
return
(tusec,) = struct.unpack('>Q', tbuf)
t = tusec * 1.0e-6
if (self._last_timestamp is not None and
self._last_message.get_type() == "BAD_DATA" and
abs(t - self._last_timestamp) > 3*24*60*60):
t = self.scan_timestamp(tbuf)
self._link = tusec & 0x3
self._timestamp = t | python | def pre_message(self):
'''read timestamp if needed'''
# read the timestamp
if self.filesize != 0:
self.percent = (100.0 * self.f.tell()) / self.filesize
if self.notimestamps:
return
if self.planner_format:
tbuf = self.f.read(21)
if len(tbuf) != 21 or tbuf[0] != '-' or tbuf[20] != ':':
raise RuntimeError('bad planner timestamp %s' % tbuf)
hnsec = self._two64 + float(tbuf[0:20])
t = hnsec * 1.0e-7 # convert to seconds
t -= 719163 * 24 * 60 * 60 # convert to 1970 base
self._link = 0
else:
tbuf = self.f.read(8)
if len(tbuf) != 8:
return
(tusec,) = struct.unpack('>Q', tbuf)
t = tusec * 1.0e-6
if (self._last_timestamp is not None and
self._last_message.get_type() == "BAD_DATA" and
abs(t - self._last_timestamp) > 3*24*60*60):
t = self.scan_timestamp(tbuf)
self._link = tusec & 0x3
self._timestamp = t | [
"def",
"pre_message",
"(",
"self",
")",
":",
"# read the timestamp",
"if",
"self",
".",
"filesize",
"!=",
"0",
":",
"self",
".",
"percent",
"=",
"(",
"100.0",
"*",
"self",
".",
"f",
".",
"tell",
"(",
")",
")",
"/",
"self",
".",
"filesize",
"if",
"s... | read timestamp if needed | [
"read",
"timestamp",
"if",
"needed"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1087-L1113 | train | 230,142 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | mavlogfile.post_message | def post_message(self, msg):
'''add timestamp to message'''
# read the timestamp
super(mavlogfile, self).post_message(msg)
if self.planner_format:
self.f.read(1) # trailing newline
self.timestamp = msg._timestamp
self._last_message = msg
if msg.get_type() != "BAD_DATA":
self._last_timestamp = msg._timestamp
msg._link = self._link | python | def post_message(self, msg):
'''add timestamp to message'''
# read the timestamp
super(mavlogfile, self).post_message(msg)
if self.planner_format:
self.f.read(1) # trailing newline
self.timestamp = msg._timestamp
self._last_message = msg
if msg.get_type() != "BAD_DATA":
self._last_timestamp = msg._timestamp
msg._link = self._link | [
"def",
"post_message",
"(",
"self",
",",
"msg",
")",
":",
"# read the timestamp",
"super",
"(",
"mavlogfile",
",",
"self",
")",
".",
"post_message",
"(",
"msg",
")",
"if",
"self",
".",
"planner_format",
":",
"self",
".",
"f",
".",
"read",
"(",
"1",
")"... | add timestamp to message | [
"add",
"timestamp",
"to",
"message"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1115-L1125 | train | 230,143 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | periodic_event.trigger | def trigger(self):
'''return True if we should trigger now'''
tnow = time.time()
if tnow < self.last_time:
print("Warning, time moved backwards. Restarting timer.")
self.last_time = tnow
if self.last_time + (1.0/self.frequency) <= tnow:
self.last_time = tnow
return True
return False | python | def trigger(self):
'''return True if we should trigger now'''
tnow = time.time()
if tnow < self.last_time:
print("Warning, time moved backwards. Restarting timer.")
self.last_time = tnow
if self.last_time + (1.0/self.frequency) <= tnow:
self.last_time = tnow
return True
return False | [
"def",
"trigger",
"(",
"self",
")",
":",
"tnow",
"=",
"time",
".",
"time",
"(",
")",
"if",
"tnow",
"<",
"self",
".",
"last_time",
":",
"print",
"(",
"\"Warning, time moved backwards. Restarting timer.\"",
")",
"self",
".",
"last_time",
"=",
"tnow",
"if",
"... | return True if we should trigger now | [
"return",
"True",
"if",
"we",
"should",
"trigger",
"now"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1256-L1267 | train | 230,144 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | MavlinkSerialPort.write | def write(self, b):
'''write some bytes'''
from . import mavutil
self.debug("sending '%s' (0x%02x) of len %u\n" % (b, ord(b[0]), len(b)), 2)
while len(b) > 0:
n = len(b)
if n > 70:
n = 70
buf = [ord(x) for x in b[:n]]
buf.extend([0]*(70-len(buf)))
self.mav.mav.serial_control_send(self.port,
mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE |
mavutil.mavlink.SERIAL_CONTROL_FLAG_RESPOND,
0,
0,
n,
buf)
b = b[n:] | python | def write(self, b):
'''write some bytes'''
from . import mavutil
self.debug("sending '%s' (0x%02x) of len %u\n" % (b, ord(b[0]), len(b)), 2)
while len(b) > 0:
n = len(b)
if n > 70:
n = 70
buf = [ord(x) for x in b[:n]]
buf.extend([0]*(70-len(buf)))
self.mav.mav.serial_control_send(self.port,
mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE |
mavutil.mavlink.SERIAL_CONTROL_FLAG_RESPOND,
0,
0,
n,
buf)
b = b[n:] | [
"def",
"write",
"(",
"self",
",",
"b",
")",
":",
"from",
".",
"import",
"mavutil",
"self",
".",
"debug",
"(",
"\"sending '%s' (0x%02x) of len %u\\n\"",
"%",
"(",
"b",
",",
"ord",
"(",
"b",
"[",
"0",
"]",
")",
",",
"len",
"(",
"b",
")",
")",
",",
... | write some bytes | [
"write",
"some",
"bytes"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1696-L1713 | train | 230,145 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | MavlinkSerialPort._recv | def _recv(self):
'''read some bytes into self.buf'''
from . import mavutil
start_time = time.time()
while time.time() < start_time + self.timeout:
m = self.mav.recv_match(condition='SERIAL_CONTROL.count!=0',
type='SERIAL_CONTROL', blocking=False, timeout=0)
if m is not None and m.count != 0:
break
self.mav.mav.serial_control_send(self.port,
mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE |
mavutil.mavlink.SERIAL_CONTROL_FLAG_RESPOND,
0,
0,
0, [0]*70)
m = self.mav.recv_match(condition='SERIAL_CONTROL.count!=0',
type='SERIAL_CONTROL', blocking=True, timeout=0.01)
if m is not None and m.count != 0:
break
if m is not None:
if self._debug > 2:
print(m)
data = m.data[:m.count]
self.buf += ''.join(str(chr(x)) for x in data) | python | def _recv(self):
'''read some bytes into self.buf'''
from . import mavutil
start_time = time.time()
while time.time() < start_time + self.timeout:
m = self.mav.recv_match(condition='SERIAL_CONTROL.count!=0',
type='SERIAL_CONTROL', blocking=False, timeout=0)
if m is not None and m.count != 0:
break
self.mav.mav.serial_control_send(self.port,
mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE |
mavutil.mavlink.SERIAL_CONTROL_FLAG_RESPOND,
0,
0,
0, [0]*70)
m = self.mav.recv_match(condition='SERIAL_CONTROL.count!=0',
type='SERIAL_CONTROL', blocking=True, timeout=0.01)
if m is not None and m.count != 0:
break
if m is not None:
if self._debug > 2:
print(m)
data = m.data[:m.count]
self.buf += ''.join(str(chr(x)) for x in data) | [
"def",
"_recv",
"(",
"self",
")",
":",
"from",
".",
"import",
"mavutil",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"while",
"time",
".",
"time",
"(",
")",
"<",
"start_time",
"+",
"self",
".",
"timeout",
":",
"m",
"=",
"self",
".",
"mav",
... | read some bytes into self.buf | [
"read",
"some",
"bytes",
"into",
"self",
".",
"buf"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1715-L1738 | train | 230,146 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | MavlinkSerialPort.read | def read(self, n):
'''read some bytes'''
if len(self.buf) == 0:
self._recv()
if len(self.buf) > 0:
if n > len(self.buf):
n = len(self.buf)
ret = self.buf[:n]
self.buf = self.buf[n:]
if self._debug >= 2:
for b in ret:
self.debug("read 0x%x" % ord(b), 2)
return ret
return '' | python | def read(self, n):
'''read some bytes'''
if len(self.buf) == 0:
self._recv()
if len(self.buf) > 0:
if n > len(self.buf):
n = len(self.buf)
ret = self.buf[:n]
self.buf = self.buf[n:]
if self._debug >= 2:
for b in ret:
self.debug("read 0x%x" % ord(b), 2)
return ret
return '' | [
"def",
"read",
"(",
"self",
",",
"n",
")",
":",
"if",
"len",
"(",
"self",
".",
"buf",
")",
"==",
"0",
":",
"self",
".",
"_recv",
"(",
")",
"if",
"len",
"(",
"self",
".",
"buf",
")",
">",
"0",
":",
"if",
"n",
">",
"len",
"(",
"self",
".",
... | read some bytes | [
"read",
"some",
"bytes"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1740-L1753 | train | 230,147 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py | MavlinkSerialPort.flushInput | def flushInput(self):
'''flush any pending input'''
self.buf = ''
saved_timeout = self.timeout
self.timeout = 0.5
self._recv()
self.timeout = saved_timeout
self.buf = ''
self.debug("flushInput") | python | def flushInput(self):
'''flush any pending input'''
self.buf = ''
saved_timeout = self.timeout
self.timeout = 0.5
self._recv()
self.timeout = saved_timeout
self.buf = ''
self.debug("flushInput") | [
"def",
"flushInput",
"(",
"self",
")",
":",
"self",
".",
"buf",
"=",
"''",
"saved_timeout",
"=",
"self",
".",
"timeout",
"self",
".",
"timeout",
"=",
"0.5",
"self",
".",
"_recv",
"(",
")",
"self",
".",
"timeout",
"=",
"saved_timeout",
"self",
".",
"b... | flush any pending input | [
"flush",
"any",
"pending",
"input"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavutil.py#L1755-L1763 | train | 230,148 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_nsh.py | NSHModule.stop | def stop(self):
'''stop nsh input'''
self.mpstate.rl.set_prompt(self.status.flightmode + "> ")
self.mpstate.functions.input_handler = None
self.started = False
# unlock the port
mav = self.master.mav
mav.serial_control_send(self.serial_settings.port,
0,
0, self.serial_settings.baudrate,
0, [0]*70) | python | def stop(self):
'''stop nsh input'''
self.mpstate.rl.set_prompt(self.status.flightmode + "> ")
self.mpstate.functions.input_handler = None
self.started = False
# unlock the port
mav = self.master.mav
mav.serial_control_send(self.serial_settings.port,
0,
0, self.serial_settings.baudrate,
0, [0]*70) | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"mpstate",
".",
"rl",
".",
"set_prompt",
"(",
"self",
".",
"status",
".",
"flightmode",
"+",
"\"> \"",
")",
"self",
".",
"mpstate",
".",
"functions",
".",
"input_handler",
"=",
"None",
"self",
".",
"... | stop nsh input | [
"stop",
"nsh",
"input"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_nsh.py#L38-L48 | train | 230,149 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_nsh.py | NSHModule.cmd_nsh | def cmd_nsh(self, args):
'''nsh shell commands'''
usage = "Usage: nsh <start|stop|set>"
if len(args) < 1:
print(usage)
return
if args[0] == "start":
self.mpstate.functions.input_handler = self.send
self.started = True
self.mpstate.rl.set_prompt("")
elif args[0] == "stop":
self.stop()
elif args[0] == "set":
self.serial_settings.command(args[1:])
else:
print(usage) | python | def cmd_nsh(self, args):
'''nsh shell commands'''
usage = "Usage: nsh <start|stop|set>"
if len(args) < 1:
print(usage)
return
if args[0] == "start":
self.mpstate.functions.input_handler = self.send
self.started = True
self.mpstate.rl.set_prompt("")
elif args[0] == "stop":
self.stop()
elif args[0] == "set":
self.serial_settings.command(args[1:])
else:
print(usage) | [
"def",
"cmd_nsh",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"Usage: nsh <start|stop|set>\"",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"start\"",
":",
"self",
".... | nsh shell commands | [
"nsh",
"shell",
"commands"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_nsh.py#L91-L106 | train | 230,150 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.process_waypoint_request | def process_waypoint_request(self, m, master):
'''process a waypoint request from the master'''
if (not self.loading_waypoints or
time.time() > self.loading_waypoint_lasttime + 10.0):
self.loading_waypoints = False
self.console.error("not loading waypoints")
return
if m.seq >= self.wploader.count():
self.console.error("Request for bad waypoint %u (max %u)" % (m.seq, self.wploader.count()))
return
wp = self.wploader.wp(m.seq)
wp.target_system = self.target_system
wp.target_component = self.target_component
self.master.mav.send(self.wploader.wp(m.seq))
self.loading_waypoint_lasttime = time.time()
self.console.writeln("Sent waypoint %u : %s" % (m.seq, self.wploader.wp(m.seq)))
if m.seq == self.wploader.count() - 1:
self.loading_waypoints = False
self.console.writeln("Sent all %u waypoints" % self.wploader.count()) | python | def process_waypoint_request(self, m, master):
'''process a waypoint request from the master'''
if (not self.loading_waypoints or
time.time() > self.loading_waypoint_lasttime + 10.0):
self.loading_waypoints = False
self.console.error("not loading waypoints")
return
if m.seq >= self.wploader.count():
self.console.error("Request for bad waypoint %u (max %u)" % (m.seq, self.wploader.count()))
return
wp = self.wploader.wp(m.seq)
wp.target_system = self.target_system
wp.target_component = self.target_component
self.master.mav.send(self.wploader.wp(m.seq))
self.loading_waypoint_lasttime = time.time()
self.console.writeln("Sent waypoint %u : %s" % (m.seq, self.wploader.wp(m.seq)))
if m.seq == self.wploader.count() - 1:
self.loading_waypoints = False
self.console.writeln("Sent all %u waypoints" % self.wploader.count()) | [
"def",
"process_waypoint_request",
"(",
"self",
",",
"m",
",",
"master",
")",
":",
"if",
"(",
"not",
"self",
".",
"loading_waypoints",
"or",
"time",
".",
"time",
"(",
")",
">",
"self",
".",
"loading_waypoint_lasttime",
"+",
"10.0",
")",
":",
"self",
".",... | process a waypoint request from the master | [
"process",
"a",
"waypoint",
"request",
"from",
"the",
"master"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L120-L138 | train | 230,151 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.send_all_waypoints | def send_all_waypoints(self):
'''send all waypoints to vehicle'''
self.master.waypoint_clear_all_send()
if self.wploader.count() == 0:
return
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.waypoint_count_send(self.wploader.count()) | python | def send_all_waypoints(self):
'''send all waypoints to vehicle'''
self.master.waypoint_clear_all_send()
if self.wploader.count() == 0:
return
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.waypoint_count_send(self.wploader.count()) | [
"def",
"send_all_waypoints",
"(",
"self",
")",
":",
"self",
".",
"master",
".",
"waypoint_clear_all_send",
"(",
")",
"if",
"self",
".",
"wploader",
".",
"count",
"(",
")",
"==",
"0",
":",
"return",
"self",
".",
"loading_waypoints",
"=",
"True",
"self",
"... | send all waypoints to vehicle | [
"send",
"all",
"waypoints",
"to",
"vehicle"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L140-L147 | train | 230,152 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.load_waypoints | def load_waypoints(self, filename):
'''load waypoints from a file'''
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
try:
self.wploader.load(filename)
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
print("Loaded %u waypoints from %s" % (self.wploader.count(), filename))
self.send_all_waypoints() | python | def load_waypoints(self, filename):
'''load waypoints from a file'''
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
try:
self.wploader.load(filename)
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
print("Loaded %u waypoints from %s" % (self.wploader.count(), filename))
self.send_all_waypoints() | [
"def",
"load_waypoints",
"(",
"self",
",",
"filename",
")",
":",
"self",
".",
"wploader",
".",
"target_system",
"=",
"self",
".",
"target_system",
"self",
".",
"wploader",
".",
"target_component",
"=",
"self",
".",
"target_component",
"try",
":",
"self",
"."... | load waypoints from a file | [
"load",
"waypoints",
"from",
"a",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L149-L159 | train | 230,153 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.update_waypoints | def update_waypoints(self, filename, wpnum):
'''update waypoints from a file'''
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
try:
self.wploader.load(filename)
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
if self.wploader.count() == 0:
print("No waypoints found in %s" % filename)
return
if wpnum == -1:
print("Loaded %u updated waypoints from %s" % (self.wploader.count(), filename))
elif wpnum >= self.wploader.count():
print("Invalid waypoint number %u" % wpnum)
return
else:
print("Loaded updated waypoint %u from %s" % (wpnum, filename))
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
if wpnum == -1:
start = 0
end = self.wploader.count()-1
else:
start = wpnum
end = wpnum
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
start, end) | python | def update_waypoints(self, filename, wpnum):
'''update waypoints from a file'''
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
try:
self.wploader.load(filename)
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
if self.wploader.count() == 0:
print("No waypoints found in %s" % filename)
return
if wpnum == -1:
print("Loaded %u updated waypoints from %s" % (self.wploader.count(), filename))
elif wpnum >= self.wploader.count():
print("Invalid waypoint number %u" % wpnum)
return
else:
print("Loaded updated waypoint %u from %s" % (wpnum, filename))
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
if wpnum == -1:
start = 0
end = self.wploader.count()-1
else:
start = wpnum
end = wpnum
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
start, end) | [
"def",
"update_waypoints",
"(",
"self",
",",
"filename",
",",
"wpnum",
")",
":",
"self",
".",
"wploader",
".",
"target_system",
"=",
"self",
".",
"target_system",
"self",
".",
"wploader",
".",
"target_component",
"=",
"self",
".",
"target_component",
"try",
... | update waypoints from a file | [
"update",
"waypoints",
"from",
"a",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L161-L191 | train | 230,154 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.get_default_frame | def get_default_frame(self):
'''default frame for waypoints'''
if self.settings.terrainalt == 'Auto':
if self.get_mav_param('TERRAIN_FOLLOW',0) == 1:
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
if self.settings.terrainalt == 'True':
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT | python | def get_default_frame(self):
'''default frame for waypoints'''
if self.settings.terrainalt == 'Auto':
if self.get_mav_param('TERRAIN_FOLLOW',0) == 1:
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
if self.settings.terrainalt == 'True':
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT | [
"def",
"get_default_frame",
"(",
"self",
")",
":",
"if",
"self",
".",
"settings",
".",
"terrainalt",
"==",
"'Auto'",
":",
"if",
"self",
".",
"get_mav_param",
"(",
"'TERRAIN_FOLLOW'",
",",
"0",
")",
"==",
"1",
":",
"return",
"mavutil",
".",
"mavlink",
"."... | default frame for waypoints | [
"default",
"frame",
"for",
"waypoints"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L202-L210 | train | 230,155 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.wp_draw_callback | def wp_draw_callback(self, points):
'''callback from drawing waypoints'''
if len(points) < 3:
return
from MAVProxy.modules.lib import mp_util
home = self.wploader.wp(0)
self.wploader.clear()
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
self.wploader.add(home)
if self.get_default_frame() == mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
use_terrain = True
else:
use_terrain = False
for p in points:
self.wploader.add_latlonalt(p[0], p[1], self.settings.wpalt, terrain_alt=use_terrain)
self.send_all_waypoints() | python | def wp_draw_callback(self, points):
'''callback from drawing waypoints'''
if len(points) < 3:
return
from MAVProxy.modules.lib import mp_util
home = self.wploader.wp(0)
self.wploader.clear()
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
self.wploader.add(home)
if self.get_default_frame() == mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
use_terrain = True
else:
use_terrain = False
for p in points:
self.wploader.add_latlonalt(p[0], p[1], self.settings.wpalt, terrain_alt=use_terrain)
self.send_all_waypoints() | [
"def",
"wp_draw_callback",
"(",
"self",
",",
"points",
")",
":",
"if",
"len",
"(",
"points",
")",
"<",
"3",
":",
"return",
"from",
"MAVProxy",
".",
"modules",
".",
"lib",
"import",
"mp_util",
"home",
"=",
"self",
".",
"wploader",
".",
"wp",
"(",
"0",... | callback from drawing waypoints | [
"callback",
"from",
"drawing",
"waypoints"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L212-L228 | train | 230,156 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.wp_loop | def wp_loop(self):
'''close the loop on a mission'''
loader = self.wploader
if loader.count() < 2:
print("Not enough waypoints (%u)" % loader.count())
return
wp = loader.wp(loader.count()-2)
if wp.command == mavutil.mavlink.MAV_CMD_DO_JUMP:
print("Mission is already looped")
return
wp = mavutil.mavlink.MAVLink_mission_item_message(0, 0, 0, 0, mavutil.mavlink.MAV_CMD_DO_JUMP,
0, 1, 1, -1, 0, 0, 0, 0, 0)
loader.add(wp)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.waypoint_count_send(self.wploader.count())
print("Closed loop on mission") | python | def wp_loop(self):
'''close the loop on a mission'''
loader = self.wploader
if loader.count() < 2:
print("Not enough waypoints (%u)" % loader.count())
return
wp = loader.wp(loader.count()-2)
if wp.command == mavutil.mavlink.MAV_CMD_DO_JUMP:
print("Mission is already looped")
return
wp = mavutil.mavlink.MAVLink_mission_item_message(0, 0, 0, 0, mavutil.mavlink.MAV_CMD_DO_JUMP,
0, 1, 1, -1, 0, 0, 0, 0, 0)
loader.add(wp)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.waypoint_count_send(self.wploader.count())
print("Closed loop on mission") | [
"def",
"wp_loop",
"(",
"self",
")",
":",
"loader",
"=",
"self",
".",
"wploader",
"if",
"loader",
".",
"count",
"(",
")",
"<",
"2",
":",
"print",
"(",
"\"Not enough waypoints (%u)\"",
"%",
"loader",
".",
"count",
"(",
")",
")",
"return",
"wp",
"=",
"l... | close the loop on a mission | [
"close",
"the",
"loop",
"on",
"a",
"mission"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L230-L246 | train | 230,157 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.set_home_location | def set_home_location(self):
'''set home location from last map click'''
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
lat = float(latlon[0])
lon = float(latlon[1])
if self.wploader.count() == 0:
self.wploader.add_latlonalt(lat, lon, 0)
w = self.wploader.wp(0)
w.x = lat
w.y = lon
self.wploader.set(w, 0)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
0, 0) | python | def set_home_location(self):
'''set home location from last map click'''
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
lat = float(latlon[0])
lon = float(latlon[1])
if self.wploader.count() == 0:
self.wploader.add_latlonalt(lat, lon, 0)
w = self.wploader.wp(0)
w.x = lat
w.y = lon
self.wploader.set(w, 0)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
0, 0) | [
"def",
"set_home_location",
"(",
"self",
")",
":",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"lat",
"=",
"float",
"(",
"latlo... | set home location from last map click | [
"set",
"home",
"location",
"from",
"last",
"map",
"click"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L248-L267 | train | 230,158 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.cmd_wp_move | def cmd_wp_move(self, args):
'''handle wp move'''
if len(args) != 1:
print("usage: wp move WPNUM")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
wp = self.wploader.wp(idx)
# setup for undo
self.undo_wp = copy.copy(wp)
self.undo_wp_idx = idx
self.undo_type = "move"
(lat, lon) = latlon
if getattr(self.console, 'ElevationMap', None) is not None and wp.frame != mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
alt1 = self.console.ElevationMap.GetElevation(lat, lon)
alt2 = self.console.ElevationMap.GetElevation(wp.x, wp.y)
if alt1 is not None and alt2 is not None:
wp.z += alt1 - alt2
wp.x = lat
wp.y = lon
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,
idx, idx)
self.wploader.set(wp, idx)
print("Moved WP %u to %f, %f at %.1fm" % (idx, lat, lon, wp.z)) | python | def cmd_wp_move(self, args):
'''handle wp move'''
if len(args) != 1:
print("usage: wp move WPNUM")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
wp = self.wploader.wp(idx)
# setup for undo
self.undo_wp = copy.copy(wp)
self.undo_wp_idx = idx
self.undo_type = "move"
(lat, lon) = latlon
if getattr(self.console, 'ElevationMap', None) is not None and wp.frame != mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
alt1 = self.console.ElevationMap.GetElevation(lat, lon)
alt2 = self.console.ElevationMap.GetElevation(wp.x, wp.y)
if alt1 is not None and alt2 is not None:
wp.z += alt1 - alt2
wp.x = lat
wp.y = lon
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,
idx, idx)
self.wploader.set(wp, idx)
print("Moved WP %u to %f, %f at %.1fm" % (idx, lat, lon, wp.z)) | [
"def",
"cmd_wp_move",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"print",
"(",
"\"usage: wp move WPNUM\"",
")",
"return",
"idx",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"if",
"idx",
"<",
"1",
"or",
"id... | handle wp move | [
"handle",
"wp",
"move"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L270-L311 | train | 230,159 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py | WPModule.cmd_wp_param | def cmd_wp_param(self, args):
'''handle wp parameter change'''
if len(args) < 2:
print("usage: wp param WPNUM PNUM <VALUE>")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
wp = self.wploader.wp(idx)
param = [wp.param1, wp.param2, wp.param3, wp.param4]
pnum = int(args[1])
if pnum < 1 or pnum > 4:
print("Invalid param number %u" % pnum)
return
if len(args) == 2:
print("Param %u: %f" % (pnum, param[pnum-1]))
return
param[pnum-1] = float(args[2])
wp.param1 = param[0]
wp.param2 = param[1]
wp.param3 = param[2]
wp.param4 = param[3]
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,
idx, idx)
self.wploader.set(wp, idx)
print("Set param %u for %u to %f" % (pnum, idx, param[pnum-1])) | python | def cmd_wp_param(self, args):
'''handle wp parameter change'''
if len(args) < 2:
print("usage: wp param WPNUM PNUM <VALUE>")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
wp = self.wploader.wp(idx)
param = [wp.param1, wp.param2, wp.param3, wp.param4]
pnum = int(args[1])
if pnum < 1 or pnum > 4:
print("Invalid param number %u" % pnum)
return
if len(args) == 2:
print("Param %u: %f" % (pnum, param[pnum-1]))
return
param[pnum-1] = float(args[2])
wp.param1 = param[0]
wp.param2 = param[1]
wp.param3 = param[2]
wp.param4 = param[3]
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,
idx, idx)
self.wploader.set(wp, idx)
print("Set param %u for %u to %f" % (pnum, idx, param[pnum-1])) | [
"def",
"cmd_wp_param",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"2",
":",
"print",
"(",
"\"usage: wp param WPNUM PNUM <VALUE>\"",
")",
"return",
"idx",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"if",
"idx",
"<",
"1",... | handle wp parameter change | [
"handle",
"wp",
"parameter",
"change"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L432-L466 | train | 230,160 |
JdeRobot/base | src/libs/comm_py/comm/ros/listenerCamera.py | depthToRGB8 | def depthToRGB8(float_img_buff, encoding):
'''
Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0
@param float_img_buff: ROS Image to translate
@type img: ros image
@return a Opencv RGB image
'''
gray_image = None
if (encoding[-3:-2]== "U"):
gray_image = float_img_buff
else:
float_img = np.zeros((float_img_buff.shape[0], float_img_buff.shape[1], 1), dtype = "float32")
float_img.data = float_img_buff.data
gray_image=cv2.convertScaleAbs(float_img, alpha=255/MAXRANGE)
cv_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2RGB)
return cv_image | python | def depthToRGB8(float_img_buff, encoding):
'''
Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0
@param float_img_buff: ROS Image to translate
@type img: ros image
@return a Opencv RGB image
'''
gray_image = None
if (encoding[-3:-2]== "U"):
gray_image = float_img_buff
else:
float_img = np.zeros((float_img_buff.shape[0], float_img_buff.shape[1], 1), dtype = "float32")
float_img.data = float_img_buff.data
gray_image=cv2.convertScaleAbs(float_img, alpha=255/MAXRANGE)
cv_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2RGB)
return cv_image | [
"def",
"depthToRGB8",
"(",
"float_img_buff",
",",
"encoding",
")",
":",
"gray_image",
"=",
"None",
"if",
"(",
"encoding",
"[",
"-",
"3",
":",
"-",
"2",
"]",
"==",
"\"U\"",
")",
":",
"gray_image",
"=",
"float_img_buff",
"else",
":",
"float_img",
"=",
"n... | Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0
@param float_img_buff: ROS Image to translate
@type img: ros image
@return a Opencv RGB image | [
"Translates",
"from",
"Distance",
"Image",
"format",
"to",
"RGB",
".",
"Inf",
"values",
"are",
"represented",
"by",
"NaN",
"when",
"converting",
"to",
"RGB",
"NaN",
"passed",
"to",
"0"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/comm_py/comm/ros/listenerCamera.py#L15-L37 | train | 230,161 |
JdeRobot/base | src/libs/comm_py/comm/ros/listenerCamera.py | ListenerCamera.__callback | def __callback (self, img):
'''
Callback function to receive and save Images.
@param img: ROS Image received
@type img: sensor_msgs.msg.Image
'''
image = imageMsg2Image(img, self.bridge)
self.lock.acquire()
self.data = image
self.lock.release() | python | def __callback (self, img):
'''
Callback function to receive and save Images.
@param img: ROS Image received
@type img: sensor_msgs.msg.Image
'''
image = imageMsg2Image(img, self.bridge)
self.lock.acquire()
self.data = image
self.lock.release() | [
"def",
"__callback",
"(",
"self",
",",
"img",
")",
":",
"image",
"=",
"imageMsg2Image",
"(",
"img",
",",
"self",
".",
"bridge",
")",
"self",
".",
"lock",
".",
"acquire",
"(",
")",
"self",
".",
"data",
"=",
"image",
"self",
".",
"lock",
".",
"releas... | Callback function to receive and save Images.
@param img: ROS Image received
@type img: sensor_msgs.msg.Image | [
"Callback",
"function",
"to",
"receive",
"and",
"save",
"Images",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/comm_py/comm/ros/listenerCamera.py#L89-L102 | train | 230,162 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py | noise | def noise():
'''a noise vector'''
from random import gauss
v = Vector3(gauss(0, 1), gauss(0, 1), gauss(0, 1))
v.normalize()
return v * args.noise | python | def noise():
'''a noise vector'''
from random import gauss
v = Vector3(gauss(0, 1), gauss(0, 1), gauss(0, 1))
v.normalize()
return v * args.noise | [
"def",
"noise",
"(",
")",
":",
"from",
"random",
"import",
"gauss",
"v",
"=",
"Vector3",
"(",
"gauss",
"(",
"0",
",",
"1",
")",
",",
"gauss",
"(",
"0",
",",
"1",
")",
",",
"gauss",
"(",
"0",
",",
"1",
")",
")",
"v",
".",
"normalize",
"(",
"... | a noise vector | [
"a",
"noise",
"vector"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py#L30-L35 | train | 230,163 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py | find_offsets | def find_offsets(data, ofs):
'''find mag offsets by applying Bills "offsets revisited" algorithm
on the data
This is an implementation of the algorithm from:
http://gentlenav.googlecode.com/files/MagnetometerOffsetNullingRevisited.pdf
'''
# a limit on the maximum change in each step
max_change = args.max_change
# the gain factor for the algorithm
gain = args.gain
data2 = []
for d in data:
d = d.copy() + noise()
d.x = float(int(d.x + 0.5))
d.y = float(int(d.y + 0.5))
d.z = float(int(d.z + 0.5))
data2.append(d)
data = data2
history_idx = 0
mag_history = data[0:args.history]
for i in range(args.history, len(data)):
B1 = mag_history[history_idx] + ofs
B2 = data[i] + ofs
diff = B2 - B1
diff_length = diff.length()
if diff_length <= args.min_diff:
# the mag vector hasn't changed enough - we don't get any
# information from this
history_idx = (history_idx+1) % args.history
continue
mag_history[history_idx] = data[i]
history_idx = (history_idx+1) % args.history
# equation 6 of Bills paper
delta = diff * (gain * (B2.length() - B1.length()) / diff_length)
# limit the change from any one reading. This is to prevent
# single crazy readings from throwing off the offsets for a long
# time
delta_length = delta.length()
if max_change != 0 and delta_length > max_change:
delta *= max_change / delta_length
# set the new offsets
ofs = ofs - delta
if args.verbose:
print(ofs)
return ofs | python | def find_offsets(data, ofs):
'''find mag offsets by applying Bills "offsets revisited" algorithm
on the data
This is an implementation of the algorithm from:
http://gentlenav.googlecode.com/files/MagnetometerOffsetNullingRevisited.pdf
'''
# a limit on the maximum change in each step
max_change = args.max_change
# the gain factor for the algorithm
gain = args.gain
data2 = []
for d in data:
d = d.copy() + noise()
d.x = float(int(d.x + 0.5))
d.y = float(int(d.y + 0.5))
d.z = float(int(d.z + 0.5))
data2.append(d)
data = data2
history_idx = 0
mag_history = data[0:args.history]
for i in range(args.history, len(data)):
B1 = mag_history[history_idx] + ofs
B2 = data[i] + ofs
diff = B2 - B1
diff_length = diff.length()
if diff_length <= args.min_diff:
# the mag vector hasn't changed enough - we don't get any
# information from this
history_idx = (history_idx+1) % args.history
continue
mag_history[history_idx] = data[i]
history_idx = (history_idx+1) % args.history
# equation 6 of Bills paper
delta = diff * (gain * (B2.length() - B1.length()) / diff_length)
# limit the change from any one reading. This is to prevent
# single crazy readings from throwing off the offsets for a long
# time
delta_length = delta.length()
if max_change != 0 and delta_length > max_change:
delta *= max_change / delta_length
# set the new offsets
ofs = ofs - delta
if args.verbose:
print(ofs)
return ofs | [
"def",
"find_offsets",
"(",
"data",
",",
"ofs",
")",
":",
"# a limit on the maximum change in each step",
"max_change",
"=",
"args",
".",
"max_change",
"# the gain factor for the algorithm",
"gain",
"=",
"args",
".",
"gain",
"data2",
"=",
"[",
"]",
"for",
"d",
"in... | find mag offsets by applying Bills "offsets revisited" algorithm
on the data
This is an implementation of the algorithm from:
http://gentlenav.googlecode.com/files/MagnetometerOffsetNullingRevisited.pdf | [
"find",
"mag",
"offsets",
"by",
"applying",
"Bills",
"offsets",
"revisited",
"algorithm",
"on",
"the",
"data"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py#L37-L93 | train | 230,164 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImage.set_menu | def set_menu(self, menu):
'''set a MPTopMenu on the frame'''
self.menu = menu
self.in_queue.put(MPImageMenu(menu)) | python | def set_menu(self, menu):
'''set a MPTopMenu on the frame'''
self.menu = menu
self.in_queue.put(MPImageMenu(menu)) | [
"def",
"set_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"menu",
"=",
"menu",
"self",
".",
"in_queue",
".",
"put",
"(",
"MPImageMenu",
"(",
"menu",
")",
")"
] | set a MPTopMenu on the frame | [
"set",
"a",
"MPTopMenu",
"on",
"the",
"frame"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L145-L148 | train | 230,165 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImage.set_popup_menu | def set_popup_menu(self, menu):
'''set a popup menu on the frame'''
self.popup_menu = menu
self.in_queue.put(MPImagePopupMenu(menu)) | python | def set_popup_menu(self, menu):
'''set a popup menu on the frame'''
self.popup_menu = menu
self.in_queue.put(MPImagePopupMenu(menu)) | [
"def",
"set_popup_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"popup_menu",
"=",
"menu",
"self",
".",
"in_queue",
".",
"put",
"(",
"MPImagePopupMenu",
"(",
"menu",
")",
")"
] | set a popup menu on the frame | [
"set",
"a",
"popup",
"menu",
"on",
"the",
"frame"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L150-L153 | train | 230,166 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.image_coordinates | def image_coordinates(self, point):
'''given a point in window coordinates, calculate image coordinates'''
# the dragpos is the top left position in image coordinates
ret = wx.Point(int(self.dragpos.x + point.x/self.zoom),
int(self.dragpos.y + point.y/self.zoom))
return ret | python | def image_coordinates(self, point):
'''given a point in window coordinates, calculate image coordinates'''
# the dragpos is the top left position in image coordinates
ret = wx.Point(int(self.dragpos.x + point.x/self.zoom),
int(self.dragpos.y + point.y/self.zoom))
return ret | [
"def",
"image_coordinates",
"(",
"self",
",",
"point",
")",
":",
"# the dragpos is the top left position in image coordinates",
"ret",
"=",
"wx",
".",
"Point",
"(",
"int",
"(",
"self",
".",
"dragpos",
".",
"x",
"+",
"point",
".",
"x",
"/",
"self",
".",
"zoom... | given a point in window coordinates, calculate image coordinates | [
"given",
"a",
"point",
"in",
"window",
"coordinates",
"calculate",
"image",
"coordinates"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L254-L259 | train | 230,167 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.redraw | def redraw(self):
'''redraw the image with current settings'''
state = self.state
if self.img is None:
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
return
# get the current size of the containing window frame
size = self.frame.GetSize()
(width, height) = (self.img.GetWidth(), self.img.GetHeight())
rect = wx.Rect(self.dragpos.x, self.dragpos.y, int(size.x/self.zoom), int(size.y/self.zoom))
#print("redraw", self.zoom, self.dragpos, size, rect);
if rect.x > width-1:
rect.x = width-1
if rect.y > height-1:
rect.y = height-1
if rect.width > width - rect.x:
rect.width = width - rect.x
if rect.height > height - rect.y:
rect.height = height - rect.y
scaled_image = self.img.Copy()
scaled_image = scaled_image.GetSubImage(rect);
scaled_image = scaled_image.Rescale(int(rect.width*self.zoom), int(rect.height*self.zoom))
if state.brightness != 1.0:
try:
from PIL import Image
pimg = mp_util.wxToPIL(scaled_image)
pimg = Image.eval(pimg, lambda x: int(x * state.brightness))
scaled_image = mp_util.PILTowx(pimg)
except Exception:
if not self.done_PIL_warning:
print("Please install PIL for brightness control")
self.done_PIL_warning = True
# ignore lack of PIL library
pass
self.imagePanel.set_image(scaled_image)
self.need_redraw = False
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
'''
from guppy import hpy
h = hpy()
print h.heap()
''' | python | def redraw(self):
'''redraw the image with current settings'''
state = self.state
if self.img is None:
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
return
# get the current size of the containing window frame
size = self.frame.GetSize()
(width, height) = (self.img.GetWidth(), self.img.GetHeight())
rect = wx.Rect(self.dragpos.x, self.dragpos.y, int(size.x/self.zoom), int(size.y/self.zoom))
#print("redraw", self.zoom, self.dragpos, size, rect);
if rect.x > width-1:
rect.x = width-1
if rect.y > height-1:
rect.y = height-1
if rect.width > width - rect.x:
rect.width = width - rect.x
if rect.height > height - rect.y:
rect.height = height - rect.y
scaled_image = self.img.Copy()
scaled_image = scaled_image.GetSubImage(rect);
scaled_image = scaled_image.Rescale(int(rect.width*self.zoom), int(rect.height*self.zoom))
if state.brightness != 1.0:
try:
from PIL import Image
pimg = mp_util.wxToPIL(scaled_image)
pimg = Image.eval(pimg, lambda x: int(x * state.brightness))
scaled_image = mp_util.PILTowx(pimg)
except Exception:
if not self.done_PIL_warning:
print("Please install PIL for brightness control")
self.done_PIL_warning = True
# ignore lack of PIL library
pass
self.imagePanel.set_image(scaled_image)
self.need_redraw = False
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
'''
from guppy import hpy
h = hpy()
print h.heap()
''' | [
"def",
"redraw",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"self",
".",
"img",
"is",
"None",
":",
"self",
".",
"mainSizer",
".",
"Fit",
"(",
"self",
")",
"self",
".",
"Refresh",
"(",
")",
"state",
".",
"frame",
".",
"Refres... | redraw the image with current settings | [
"redraw",
"the",
"image",
"with",
"current",
"settings"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L261-L315 | train | 230,168 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.limit_dragpos | def limit_dragpos(self):
'''limit dragpos to sane values'''
if self.dragpos.x < 0:
self.dragpos.x = 0
if self.dragpos.y < 0:
self.dragpos.y = 0
if self.img is None:
return
if self.dragpos.x >= self.img.GetWidth():
self.dragpos.x = self.img.GetWidth()-1
if self.dragpos.y >= self.img.GetHeight():
self.dragpos.y = self.img.GetHeight()-1 | python | def limit_dragpos(self):
'''limit dragpos to sane values'''
if self.dragpos.x < 0:
self.dragpos.x = 0
if self.dragpos.y < 0:
self.dragpos.y = 0
if self.img is None:
return
if self.dragpos.x >= self.img.GetWidth():
self.dragpos.x = self.img.GetWidth()-1
if self.dragpos.y >= self.img.GetHeight():
self.dragpos.y = self.img.GetHeight()-1 | [
"def",
"limit_dragpos",
"(",
"self",
")",
":",
"if",
"self",
".",
"dragpos",
".",
"x",
"<",
"0",
":",
"self",
".",
"dragpos",
".",
"x",
"=",
"0",
"if",
"self",
".",
"dragpos",
".",
"y",
"<",
"0",
":",
"self",
".",
"dragpos",
".",
"y",
"=",
"0... | limit dragpos to sane values | [
"limit",
"dragpos",
"to",
"sane",
"values"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L362-L373 | train | 230,169 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.on_drag_event | def on_drag_event(self, event):
'''handle mouse drags'''
state = self.state
if not state.can_drag:
return
newpos = self.image_coordinates(event.GetPosition())
dx = -(newpos.x - self.mouse_down.x)
dy = -(newpos.y - self.mouse_down.y)
self.dragpos = wx.Point(self.dragpos.x+dx,self.dragpos.y+dy)
self.limit_dragpos()
self.mouse_down = newpos
self.need_redraw = True
self.redraw() | python | def on_drag_event(self, event):
'''handle mouse drags'''
state = self.state
if not state.can_drag:
return
newpos = self.image_coordinates(event.GetPosition())
dx = -(newpos.x - self.mouse_down.x)
dy = -(newpos.y - self.mouse_down.y)
self.dragpos = wx.Point(self.dragpos.x+dx,self.dragpos.y+dy)
self.limit_dragpos()
self.mouse_down = newpos
self.need_redraw = True
self.redraw() | [
"def",
"on_drag_event",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"not",
"state",
".",
"can_drag",
":",
"return",
"newpos",
"=",
"self",
".",
"image_coordinates",
"(",
"event",
".",
"GetPosition",
"(",
")",
")",
"dx... | handle mouse drags | [
"handle",
"mouse",
"drags"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L401-L413 | train | 230,170 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.show_popup_menu | def show_popup_menu(self, pos):
'''show a popup menu'''
self.popup_pos = self.image_coordinates(pos)
self.frame.PopupMenu(self.wx_popup_menu, pos) | python | def show_popup_menu(self, pos):
'''show a popup menu'''
self.popup_pos = self.image_coordinates(pos)
self.frame.PopupMenu(self.wx_popup_menu, pos) | [
"def",
"show_popup_menu",
"(",
"self",
",",
"pos",
")",
":",
"self",
".",
"popup_pos",
"=",
"self",
".",
"image_coordinates",
"(",
"pos",
")",
"self",
".",
"frame",
".",
"PopupMenu",
"(",
"self",
".",
"wx_popup_menu",
",",
"pos",
")"
] | show a popup menu | [
"show",
"a",
"popup",
"menu"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L415-L418 | train | 230,171 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.on_key_event | def on_key_event(self, event):
'''handle key events'''
keycode = event.GetKeyCode()
if keycode == wx.WXK_HOME:
self.zoom = 1.0
self.dragpos = wx.Point(0, 0)
self.need_redraw = True | python | def on_key_event(self, event):
'''handle key events'''
keycode = event.GetKeyCode()
if keycode == wx.WXK_HOME:
self.zoom = 1.0
self.dragpos = wx.Point(0, 0)
self.need_redraw = True | [
"def",
"on_key_event",
"(",
"self",
",",
"event",
")",
":",
"keycode",
"=",
"event",
".",
"GetKeyCode",
"(",
")",
"if",
"keycode",
"==",
"wx",
".",
"WXK_HOME",
":",
"self",
".",
"zoom",
"=",
"1.0",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"... | handle key events | [
"handle",
"key",
"events"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L436-L442 | train | 230,172 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.on_event | def on_event(self, event):
'''pass events to the parent'''
state = self.state
if isinstance(event, wx.MouseEvent):
self.on_mouse_event(event)
if isinstance(event, wx.KeyEvent):
self.on_key_event(event)
if (isinstance(event, wx.MouseEvent) and
not event.ButtonIsDown(wx.MOUSE_BTN_ANY) and
event.GetWheelRotation() == 0):
# don't flood the queue with mouse movement
return
evt = mp_util.object_container(event)
pt = self.image_coordinates(wx.Point(evt.X,evt.Y))
evt.X = pt.x
evt.Y = pt.y
state.out_queue.put(evt) | python | def on_event(self, event):
'''pass events to the parent'''
state = self.state
if isinstance(event, wx.MouseEvent):
self.on_mouse_event(event)
if isinstance(event, wx.KeyEvent):
self.on_key_event(event)
if (isinstance(event, wx.MouseEvent) and
not event.ButtonIsDown(wx.MOUSE_BTN_ANY) and
event.GetWheelRotation() == 0):
# don't flood the queue with mouse movement
return
evt = mp_util.object_container(event)
pt = self.image_coordinates(wx.Point(evt.X,evt.Y))
evt.X = pt.x
evt.Y = pt.y
state.out_queue.put(evt) | [
"def",
"on_event",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"isinstance",
"(",
"event",
",",
"wx",
".",
"MouseEvent",
")",
":",
"self",
".",
"on_mouse_event",
"(",
"event",
")",
"if",
"isinstance",
"(",
"event",
... | pass events to the parent | [
"pass",
"events",
"to",
"the",
"parent"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L444-L460 | train | 230,173 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.on_menu | def on_menu(self, event):
'''called on menu event'''
state = self.state
if self.popup_menu is not None:
ret = self.popup_menu.find_selected(event)
if ret is not None:
ret.popup_pos = self.popup_pos
if ret.returnkey == 'fitWindow':
self.fit_to_window()
elif ret.returnkey == 'fullSize':
self.full_size()
else:
state.out_queue.put(ret)
return
if self.menu is not None:
ret = self.menu.find_selected(event)
if ret is not None:
state.out_queue.put(ret)
return | python | def on_menu(self, event):
'''called on menu event'''
state = self.state
if self.popup_menu is not None:
ret = self.popup_menu.find_selected(event)
if ret is not None:
ret.popup_pos = self.popup_pos
if ret.returnkey == 'fitWindow':
self.fit_to_window()
elif ret.returnkey == 'fullSize':
self.full_size()
else:
state.out_queue.put(ret)
return
if self.menu is not None:
ret = self.menu.find_selected(event)
if ret is not None:
state.out_queue.put(ret)
return | [
"def",
"on_menu",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"self",
".",
"popup_menu",
"is",
"not",
"None",
":",
"ret",
"=",
"self",
".",
"popup_menu",
".",
"find_selected",
"(",
"event",
")",
"if",
"ret",
"is",
... | called on menu event | [
"called",
"on",
"menu",
"event"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L462-L480 | train | 230,174 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.set_menu | def set_menu(self, menu):
'''add a menu from the parent'''
self.menu = menu
wx_menu = menu.wx_menu()
self.frame.SetMenuBar(wx_menu)
self.frame.Bind(wx.EVT_MENU, self.on_menu) | python | def set_menu(self, menu):
'''add a menu from the parent'''
self.menu = menu
wx_menu = menu.wx_menu()
self.frame.SetMenuBar(wx_menu)
self.frame.Bind(wx.EVT_MENU, self.on_menu) | [
"def",
"set_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"menu",
"=",
"menu",
"wx_menu",
"=",
"menu",
".",
"wx_menu",
"(",
")",
"self",
".",
"frame",
".",
"SetMenuBar",
"(",
"wx_menu",
")",
"self",
".",
"frame",
".",
"Bind",
"(",
"wx",
... | add a menu from the parent | [
"add",
"a",
"menu",
"from",
"the",
"parent"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L482-L487 | train | 230,175 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.set_popup_menu | def set_popup_menu(self, menu):
'''add a popup menu from the parent'''
self.popup_menu = menu
if menu is None:
self.wx_popup_menu = None
else:
self.wx_popup_menu = menu.wx_menu()
self.frame.Bind(wx.EVT_MENU, self.on_menu) | python | def set_popup_menu(self, menu):
'''add a popup menu from the parent'''
self.popup_menu = menu
if menu is None:
self.wx_popup_menu = None
else:
self.wx_popup_menu = menu.wx_menu()
self.frame.Bind(wx.EVT_MENU, self.on_menu) | [
"def",
"set_popup_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"popup_menu",
"=",
"menu",
"if",
"menu",
"is",
"None",
":",
"self",
".",
"wx_popup_menu",
"=",
"None",
"else",
":",
"self",
".",
"wx_popup_menu",
"=",
"menu",
".",
"wx_menu",
"("... | add a popup menu from the parent | [
"add",
"a",
"popup",
"menu",
"from",
"the",
"parent"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L489-L496 | train | 230,176 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.fit_to_window | def fit_to_window(self):
'''fit image to window'''
state = self.state
self.dragpos = wx.Point(0, 0)
client_area = state.frame.GetClientSize()
self.zoom = min(float(client_area.x) / self.img.GetWidth(),
float(client_area.y) / self.img.GetHeight())
self.need_redraw = True | python | def fit_to_window(self):
'''fit image to window'''
state = self.state
self.dragpos = wx.Point(0, 0)
client_area = state.frame.GetClientSize()
self.zoom = min(float(client_area.x) / self.img.GetWidth(),
float(client_area.y) / self.img.GetHeight())
self.need_redraw = True | [
"def",
"fit_to_window",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"state",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"0",
",",
"0",
")",
"client_area",
"=",
"state",
".",
"frame",
".",
"GetClientSize",
"(",
")",
"self",
".",
"zo... | fit image to window | [
"fit",
"image",
"to",
"window"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L498-L505 | train | 230,177 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py | MPImagePanel.full_size | def full_size(self):
'''show image at full size'''
self.dragpos = wx.Point(0, 0)
self.zoom = 1.0
self.need_redraw = True | python | def full_size(self):
'''show image at full size'''
self.dragpos = wx.Point(0, 0)
self.zoom = 1.0
self.need_redraw = True | [
"def",
"full_size",
"(",
"self",
")",
":",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"0",
",",
"0",
")",
"self",
".",
"zoom",
"=",
"1.0",
"self",
".",
"need_redraw",
"=",
"True"
] | show image at full size | [
"show",
"image",
"at",
"full",
"size"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L507-L511 | train | 230,178 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavmission.py | mavmission | def mavmission(logfile):
'''extract mavlink mission'''
mlog = mavutil.mavlink_connection(filename)
wp = mavwp.MAVWPLoader()
while True:
m = mlog.recv_match(type=['MISSION_ITEM','CMD','WAYPOINT'])
if m is None:
break
if m.get_type() == 'CMD':
m = mavutil.mavlink.MAVLink_mission_item_message(0,
0,
m.CNum,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
m.CId,
0, 1,
m.Prm1, m.Prm2, m.Prm3, m.Prm4,
m.Lat, m.Lng, m.Alt)
if m.current >= 2:
continue
while m.seq > wp.count():
print("Adding dummy WP %u" % wp.count())
wp.set(m, wp.count())
wp.set(m, m.seq)
wp.save(args.output)
print("Saved %u waypoints to %s" % (wp.count(), args.output)) | python | def mavmission(logfile):
'''extract mavlink mission'''
mlog = mavutil.mavlink_connection(filename)
wp = mavwp.MAVWPLoader()
while True:
m = mlog.recv_match(type=['MISSION_ITEM','CMD','WAYPOINT'])
if m is None:
break
if m.get_type() == 'CMD':
m = mavutil.mavlink.MAVLink_mission_item_message(0,
0,
m.CNum,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
m.CId,
0, 1,
m.Prm1, m.Prm2, m.Prm3, m.Prm4,
m.Lat, m.Lng, m.Alt)
if m.current >= 2:
continue
while m.seq > wp.count():
print("Adding dummy WP %u" % wp.count())
wp.set(m, wp.count())
wp.set(m, m.seq)
wp.save(args.output)
print("Saved %u waypoints to %s" % (wp.count(), args.output)) | [
"def",
"mavmission",
"(",
"logfile",
")",
":",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
")",
"wp",
"=",
"mavwp",
".",
"MAVWPLoader",
"(",
")",
"while",
"True",
":",
"m",
"=",
"mlog",
".",
"recv_match",
"(",
"type",
"=",
"[",
... | extract mavlink mission | [
"extract",
"mavlink",
"mission"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavmission.py#L20-L47 | train | 230,179 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py | message_checksum | def message_checksum(msg):
'''calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes'''
from .mavcrc import x25crc
crc = x25crc()
crc.accumulate_str(msg.name + ' ')
# in order to allow for extensions the crc does not include
# any field extensions
crc_end = msg.base_fields()
for i in range(crc_end):
f = msg.ordered_fields[i]
crc.accumulate_str(f.type + ' ')
crc.accumulate_str(f.name + ' ')
if f.array_length:
crc.accumulate([f.array_length])
return (crc.crc&0xFF) ^ (crc.crc>>8) | python | def message_checksum(msg):
'''calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes'''
from .mavcrc import x25crc
crc = x25crc()
crc.accumulate_str(msg.name + ' ')
# in order to allow for extensions the crc does not include
# any field extensions
crc_end = msg.base_fields()
for i in range(crc_end):
f = msg.ordered_fields[i]
crc.accumulate_str(f.type + ' ')
crc.accumulate_str(f.name + ' ')
if f.array_length:
crc.accumulate([f.array_length])
return (crc.crc&0xFF) ^ (crc.crc>>8) | [
"def",
"message_checksum",
"(",
"msg",
")",
":",
"from",
".",
"mavcrc",
"import",
"x25crc",
"crc",
"=",
"x25crc",
"(",
")",
"crc",
".",
"accumulate_str",
"(",
"msg",
".",
"name",
"+",
"' '",
")",
"# in order to allow for extensions the crc does not include",
"# ... | calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes | [
"calculate",
"a",
"8",
"-",
"bit",
"checksum",
"of",
"the",
"key",
"fields",
"of",
"a",
"message",
"so",
"we",
"can",
"detect",
"incompatible",
"XML",
"changes"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L379-L394 | train | 230,180 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py | merge_enums | def merge_enums(xml):
'''merge enums between XML files'''
emap = {}
for x in xml:
newenums = []
for enum in x.enum:
if enum.name in emap:
emapitem = emap[enum.name]
# check for possible conflicting auto-assigned values after merge
if (emapitem.start_value <= enum.highest_value and emapitem.highest_value >= enum.start_value):
for entry in emapitem.entry:
# correct the value if necessary, but only if it was auto-assigned to begin with
if entry.value <= enum.highest_value and entry.autovalue == True:
entry.value = enum.highest_value + 1
enum.highest_value = entry.value
# merge the entries
emapitem.entry.extend(enum.entry)
if not emapitem.description:
emapitem.description = enum.description
print("Merged enum %s" % enum.name)
else:
newenums.append(enum)
emap[enum.name] = enum
x.enum = newenums
for e in emap:
# sort by value
emap[e].entry = sorted(emap[e].entry,
key=operator.attrgetter('value'),
reverse=False)
# add a ENUM_END
emap[e].entry.append(MAVEnumEntry("%s_ENUM_END" % emap[e].name,
emap[e].entry[-1].value+1, end_marker=True)) | python | def merge_enums(xml):
'''merge enums between XML files'''
emap = {}
for x in xml:
newenums = []
for enum in x.enum:
if enum.name in emap:
emapitem = emap[enum.name]
# check for possible conflicting auto-assigned values after merge
if (emapitem.start_value <= enum.highest_value and emapitem.highest_value >= enum.start_value):
for entry in emapitem.entry:
# correct the value if necessary, but only if it was auto-assigned to begin with
if entry.value <= enum.highest_value and entry.autovalue == True:
entry.value = enum.highest_value + 1
enum.highest_value = entry.value
# merge the entries
emapitem.entry.extend(enum.entry)
if not emapitem.description:
emapitem.description = enum.description
print("Merged enum %s" % enum.name)
else:
newenums.append(enum)
emap[enum.name] = enum
x.enum = newenums
for e in emap:
# sort by value
emap[e].entry = sorted(emap[e].entry,
key=operator.attrgetter('value'),
reverse=False)
# add a ENUM_END
emap[e].entry.append(MAVEnumEntry("%s_ENUM_END" % emap[e].name,
emap[e].entry[-1].value+1, end_marker=True)) | [
"def",
"merge_enums",
"(",
"xml",
")",
":",
"emap",
"=",
"{",
"}",
"for",
"x",
"in",
"xml",
":",
"newenums",
"=",
"[",
"]",
"for",
"enum",
"in",
"x",
".",
"enum",
":",
"if",
"enum",
".",
"name",
"in",
"emap",
":",
"emapitem",
"=",
"emap",
"[",
... | merge enums between XML files | [
"merge",
"enums",
"between",
"XML",
"files"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L396-L427 | train | 230,181 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py | check_duplicates | def check_duplicates(xml):
'''check for duplicate message IDs'''
merge_enums(xml)
msgmap = {}
enummap = {}
for x in xml:
for m in x.message:
key = m.id
if key in msgmap:
print("ERROR: Duplicate message id %u for %s (%s:%u) also used by %s" % (
m.id,
m.name,
x.filename, m.linenumber,
msgmap[key]))
return True
fieldset = set()
for f in m.fields:
if f.name in fieldset:
print("ERROR: Duplicate field %s in message %s (%s:%u)" % (
f.name, m.name,
x.filename, m.linenumber))
return True
fieldset.add(f.name)
msgmap[key] = '%s (%s:%u)' % (m.name, x.filename, m.linenumber)
for enum in x.enum:
for entry in enum.entry:
if entry.autovalue == True and "common.xml" not in entry.origin_file:
print("Note: An enum value was auto-generated: %s = %u" % (entry.name, entry.value))
s1 = "%s.%s" % (enum.name, entry.name)
s2 = "%s.%s" % (enum.name, entry.value)
if s1 in enummap or s2 in enummap:
print("ERROR: Duplicate enum %s:\n\t%s = %s @ %s:%u\n\t%s" % (
"names" if s1 in enummap else "values",
s1, entry.value, entry.origin_file, entry.origin_line,
enummap.get(s1) or enummap.get(s2)))
return True
enummap[s1] = enummap[s2] = "%s.%s = %s @ %s:%u" % (enum.name, entry.name, entry.value, entry.origin_file, entry.origin_line)
return False | python | def check_duplicates(xml):
'''check for duplicate message IDs'''
merge_enums(xml)
msgmap = {}
enummap = {}
for x in xml:
for m in x.message:
key = m.id
if key in msgmap:
print("ERROR: Duplicate message id %u for %s (%s:%u) also used by %s" % (
m.id,
m.name,
x.filename, m.linenumber,
msgmap[key]))
return True
fieldset = set()
for f in m.fields:
if f.name in fieldset:
print("ERROR: Duplicate field %s in message %s (%s:%u)" % (
f.name, m.name,
x.filename, m.linenumber))
return True
fieldset.add(f.name)
msgmap[key] = '%s (%s:%u)' % (m.name, x.filename, m.linenumber)
for enum in x.enum:
for entry in enum.entry:
if entry.autovalue == True and "common.xml" not in entry.origin_file:
print("Note: An enum value was auto-generated: %s = %u" % (entry.name, entry.value))
s1 = "%s.%s" % (enum.name, entry.name)
s2 = "%s.%s" % (enum.name, entry.value)
if s1 in enummap or s2 in enummap:
print("ERROR: Duplicate enum %s:\n\t%s = %s @ %s:%u\n\t%s" % (
"names" if s1 in enummap else "values",
s1, entry.value, entry.origin_file, entry.origin_line,
enummap.get(s1) or enummap.get(s2)))
return True
enummap[s1] = enummap[s2] = "%s.%s = %s @ %s:%u" % (enum.name, entry.name, entry.value, entry.origin_file, entry.origin_line)
return False | [
"def",
"check_duplicates",
"(",
"xml",
")",
":",
"merge_enums",
"(",
"xml",
")",
"msgmap",
"=",
"{",
"}",
"enummap",
"=",
"{",
"}",
"for",
"x",
"in",
"xml",
":",
"for",
"m",
"in",
"x",
".",
"message",
":",
"key",
"=",
"m",
".",
"id",
"if",
"key... | check for duplicate message IDs | [
"check",
"for",
"duplicate",
"message",
"IDs"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L429-L469 | train | 230,182 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py | total_msgs | def total_msgs(xml):
'''count total number of msgs'''
count = 0
for x in xml:
count += len(x.message)
return count | python | def total_msgs(xml):
'''count total number of msgs'''
count = 0
for x in xml:
count += len(x.message)
return count | [
"def",
"total_msgs",
"(",
"xml",
")",
":",
"count",
"=",
"0",
"for",
"x",
"in",
"xml",
":",
"count",
"+=",
"len",
"(",
"x",
".",
"message",
")",
"return",
"count"
] | count total number of msgs | [
"count",
"total",
"number",
"of",
"msgs"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L473-L478 | train | 230,183 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py | MAVType.base_fields | def base_fields(self):
'''return number of non-extended fields'''
if self.extensions_start is None:
return len(self.fields)
return len(self.fields[:self.extensions_start]) | python | def base_fields(self):
'''return number of non-extended fields'''
if self.extensions_start is None:
return len(self.fields)
return len(self.fields[:self.extensions_start]) | [
"def",
"base_fields",
"(",
"self",
")",
":",
"if",
"self",
".",
"extensions_start",
"is",
"None",
":",
"return",
"len",
"(",
"self",
".",
"fields",
")",
"return",
"len",
"(",
"self",
".",
"fields",
"[",
":",
"self",
".",
"extensions_start",
"]",
")"
] | return number of non-extended fields | [
"return",
"number",
"of",
"non",
"-",
"extended",
"fields"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L125-L129 | train | 230,184 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py | dataflash_logger._dataflash_dir | def _dataflash_dir(self, mpstate):
'''returns directory path to store DF logs in. May be relative'''
if mpstate.settings.state_basedir is None:
ret = 'dataflash'
else:
ret = os.path.join(mpstate.settings.state_basedir,'dataflash')
try:
os.makedirs(ret)
except OSError as e:
if e.errno != errno.EEXIST:
print("DFLogger: OSError making (%s): %s" % (ret, str(e)))
except Exception as e:
print("DFLogger: Unknown exception making (%s): %s" % (ret, str(e)))
return ret | python | def _dataflash_dir(self, mpstate):
'''returns directory path to store DF logs in. May be relative'''
if mpstate.settings.state_basedir is None:
ret = 'dataflash'
else:
ret = os.path.join(mpstate.settings.state_basedir,'dataflash')
try:
os.makedirs(ret)
except OSError as e:
if e.errno != errno.EEXIST:
print("DFLogger: OSError making (%s): %s" % (ret, str(e)))
except Exception as e:
print("DFLogger: Unknown exception making (%s): %s" % (ret, str(e)))
return ret | [
"def",
"_dataflash_dir",
"(",
"self",
",",
"mpstate",
")",
":",
"if",
"mpstate",
".",
"settings",
".",
"state_basedir",
"is",
"None",
":",
"ret",
"=",
"'dataflash'",
"else",
":",
"ret",
"=",
"os",
".",
"path",
".",
"join",
"(",
"mpstate",
".",
"setting... | returns directory path to store DF logs in. May be relative | [
"returns",
"directory",
"path",
"to",
"store",
"DF",
"logs",
"in",
".",
"May",
"be",
"relative"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L65-L80 | train | 230,185 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py | dataflash_logger.new_log_filepath | def new_log_filepath(self):
'''returns a filepath to a log which does not currently exist and is suitable for DF logging'''
lastlog_filename = os.path.join(self.dataflash_dir,'LASTLOG.TXT')
if os.path.exists(lastlog_filename) and os.stat(lastlog_filename).st_size != 0:
fh = open(lastlog_filename,'rb')
log_cnt = int(fh.read()) + 1
fh.close()
else:
log_cnt = 1
self.lastlog_file = open(lastlog_filename,'w+b')
self.lastlog_file.write(log_cnt.__str__())
self.lastlog_file.close()
return os.path.join(self.dataflash_dir, '%u.BIN' % (log_cnt,)); | python | def new_log_filepath(self):
'''returns a filepath to a log which does not currently exist and is suitable for DF logging'''
lastlog_filename = os.path.join(self.dataflash_dir,'LASTLOG.TXT')
if os.path.exists(lastlog_filename) and os.stat(lastlog_filename).st_size != 0:
fh = open(lastlog_filename,'rb')
log_cnt = int(fh.read()) + 1
fh.close()
else:
log_cnt = 1
self.lastlog_file = open(lastlog_filename,'w+b')
self.lastlog_file.write(log_cnt.__str__())
self.lastlog_file.close()
return os.path.join(self.dataflash_dir, '%u.BIN' % (log_cnt,)); | [
"def",
"new_log_filepath",
"(",
"self",
")",
":",
"lastlog_filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"dataflash_dir",
",",
"'LASTLOG.TXT'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"lastlog_filename",
")",
"and",
"os",
".... | returns a filepath to a log which does not currently exist and is suitable for DF logging | [
"returns",
"a",
"filepath",
"to",
"a",
"log",
"which",
"does",
"not",
"currently",
"exist",
"and",
"is",
"suitable",
"for",
"DF",
"logging"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L82-L96 | train | 230,186 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py | dataflash_logger.start_new_log | def start_new_log(self):
'''open a new dataflash log, reset state'''
filename = self.new_log_filepath()
self.block_cnt = 0
self.logfile = open(filename, 'w+b')
print("DFLogger: logging started (%s)" % (filename))
self.prev_cnt = 0
self.download = 0
self.prev_download = 0
self.last_idle_status_printed_time = time.time()
self.last_status_time = time.time()
self.missing_blocks = {}
self.acking_blocks = {}
self.blocks_to_ack_and_nack = []
self.missing_found = 0
self.abandoned = 0 | python | def start_new_log(self):
'''open a new dataflash log, reset state'''
filename = self.new_log_filepath()
self.block_cnt = 0
self.logfile = open(filename, 'w+b')
print("DFLogger: logging started (%s)" % (filename))
self.prev_cnt = 0
self.download = 0
self.prev_download = 0
self.last_idle_status_printed_time = time.time()
self.last_status_time = time.time()
self.missing_blocks = {}
self.acking_blocks = {}
self.blocks_to_ack_and_nack = []
self.missing_found = 0
self.abandoned = 0 | [
"def",
"start_new_log",
"(",
"self",
")",
":",
"filename",
"=",
"self",
".",
"new_log_filepath",
"(",
")",
"self",
".",
"block_cnt",
"=",
"0",
"self",
".",
"logfile",
"=",
"open",
"(",
"filename",
",",
"'w+b'",
")",
"print",
"(",
"\"DFLogger: logging start... | open a new dataflash log, reset state | [
"open",
"a",
"new",
"dataflash",
"log",
"reset",
"state"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L98-L114 | train | 230,187 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py | dataflash_logger.mavlink_packet | def mavlink_packet(self, m):
'''handle REMOTE_LOG_DATA_BLOCK packets'''
now = time.time()
if m.get_type() == 'REMOTE_LOG_DATA_BLOCK':
if self.stopped:
# send a stop packet every second until the other end gets the idea:
if now - self.time_last_stop_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending stop packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_STOP,1)
return
# if random.random() < 0.1: # drop 1 packet in 10
# return
if not self.new_log_started:
if self.log_settings.verbose:
print("DFLogger: Received data packet - starting new log")
self.start_new_log()
self.new_log_started = True
if self.new_log_started == True:
size = m.block_size
data = ''.join(str(chr(x)) for x in m.data[:size])
ofs = size*(m.block_cnt)
self.logfile.seek(ofs)
self.logfile.write(data)
if m.block_cnt in self.missing_blocks:
if self.log_settings.verbose:
print("DFLogger: Received missing block: %d" % (m.block_cnt,))
del self.missing_blocks[m.block_cnt]
self.missing_found += 1
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# print("DFLogger: missing blocks: %s" % (str(self.missing_blocks),))
else:
# ACK the block we just got:
if m.block_cnt in self.acking_blocks:
# already acking this one; we probably sent
# multiple nacks and received this one
# multiple times
pass
else:
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# NACK any blocks we haven't seen and should have:
if(m.block_cnt - self.block_cnt > 1):
for block in range(self.block_cnt+1, m.block_cnt):
if block not in self.missing_blocks and \
block not in self.acking_blocks:
self.missing_blocks[block] = 1
if self.log_settings.verbose:
print ("DFLogger: setting %d for nacking" % (block,))
self.blocks_to_ack_and_nack.append([self.master,block,0,now,None])
#print "\nmissed blocks: ",self.missing_blocks
if self.block_cnt < m.block_cnt:
self.block_cnt = m.block_cnt
self.download += size
elif not self.new_log_started and not self.stopped:
# send a start packet every second until the other end gets the idea:
if now - self.time_last_start_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending start packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_START,1)
self.time_last_start_packet_sent = now | python | def mavlink_packet(self, m):
'''handle REMOTE_LOG_DATA_BLOCK packets'''
now = time.time()
if m.get_type() == 'REMOTE_LOG_DATA_BLOCK':
if self.stopped:
# send a stop packet every second until the other end gets the idea:
if now - self.time_last_stop_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending stop packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_STOP,1)
return
# if random.random() < 0.1: # drop 1 packet in 10
# return
if not self.new_log_started:
if self.log_settings.verbose:
print("DFLogger: Received data packet - starting new log")
self.start_new_log()
self.new_log_started = True
if self.new_log_started == True:
size = m.block_size
data = ''.join(str(chr(x)) for x in m.data[:size])
ofs = size*(m.block_cnt)
self.logfile.seek(ofs)
self.logfile.write(data)
if m.block_cnt in self.missing_blocks:
if self.log_settings.verbose:
print("DFLogger: Received missing block: %d" % (m.block_cnt,))
del self.missing_blocks[m.block_cnt]
self.missing_found += 1
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# print("DFLogger: missing blocks: %s" % (str(self.missing_blocks),))
else:
# ACK the block we just got:
if m.block_cnt in self.acking_blocks:
# already acking this one; we probably sent
# multiple nacks and received this one
# multiple times
pass
else:
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# NACK any blocks we haven't seen and should have:
if(m.block_cnt - self.block_cnt > 1):
for block in range(self.block_cnt+1, m.block_cnt):
if block not in self.missing_blocks and \
block not in self.acking_blocks:
self.missing_blocks[block] = 1
if self.log_settings.verbose:
print ("DFLogger: setting %d for nacking" % (block,))
self.blocks_to_ack_and_nack.append([self.master,block,0,now,None])
#print "\nmissed blocks: ",self.missing_blocks
if self.block_cnt < m.block_cnt:
self.block_cnt = m.block_cnt
self.download += size
elif not self.new_log_started and not self.stopped:
# send a start packet every second until the other end gets the idea:
if now - self.time_last_start_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending start packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_START,1)
self.time_last_start_packet_sent = now | [
"def",
"mavlink_packet",
"(",
"self",
",",
"m",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'REMOTE_LOG_DATA_BLOCK'",
":",
"if",
"self",
".",
"stopped",
":",
"# send a stop packet every second until the o... | handle REMOTE_LOG_DATA_BLOCK packets | [
"handle",
"REMOTE_LOG_DATA_BLOCK",
"packets"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L194-L259 | train | 230,188 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ardupilotmega.py | MAVLink.meminfo_send | def meminfo_send(self, brkval, freemem, force_mavlink1=False):
'''
state of APM memory
brkval : heap top (uint16_t)
freemem : free memory (uint16_t)
'''
return self.send(self.meminfo_encode(brkval, freemem), force_mavlink1=force_mavlink1) | python | def meminfo_send(self, brkval, freemem, force_mavlink1=False):
'''
state of APM memory
brkval : heap top (uint16_t)
freemem : free memory (uint16_t)
'''
return self.send(self.meminfo_encode(brkval, freemem), force_mavlink1=force_mavlink1) | [
"def",
"meminfo_send",
"(",
"self",
",",
"brkval",
",",
"freemem",
",",
"force_mavlink1",
"=",
"False",
")",
":",
"return",
"self",
".",
"send",
"(",
"self",
".",
"meminfo_encode",
"(",
"brkval",
",",
"freemem",
")",
",",
"force_mavlink1",
"=",
"force_mavl... | state of APM memory
brkval : heap top (uint16_t)
freemem : free memory (uint16_t) | [
"state",
"of",
"APM",
"memory"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ardupilotmega.py#L9577-L9585 | train | 230,189 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py | older_message | def older_message(m, lastm):
'''return true if m is older than lastm by timestamp'''
atts = {'time_boot_ms' : 1.0e-3,
'time_unix_usec' : 1.0e-6,
'time_usec' : 1.0e-6}
for a in atts.keys():
if hasattr(m, a):
mul = atts[a]
t1 = m.getattr(a) * mul
t2 = lastm.getattr(a) * mul
if t2 >= t1 and t2 - t1 < 60:
return True
return False | python | def older_message(m, lastm):
'''return true if m is older than lastm by timestamp'''
atts = {'time_boot_ms' : 1.0e-3,
'time_unix_usec' : 1.0e-6,
'time_usec' : 1.0e-6}
for a in atts.keys():
if hasattr(m, a):
mul = atts[a]
t1 = m.getattr(a) * mul
t2 = lastm.getattr(a) * mul
if t2 >= t1 and t2 - t1 < 60:
return True
return False | [
"def",
"older_message",
"(",
"m",
",",
"lastm",
")",
":",
"atts",
"=",
"{",
"'time_boot_ms'",
":",
"1.0e-3",
",",
"'time_unix_usec'",
":",
"1.0e-6",
",",
"'time_usec'",
":",
"1.0e-6",
"}",
"for",
"a",
"in",
"atts",
".",
"keys",
"(",
")",
":",
"if",
"... | return true if m is older than lastm by timestamp | [
"return",
"true",
"if",
"m",
"is",
"older",
"than",
"lastm",
"by",
"timestamp"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py#L22-L34 | train | 230,190 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py | process | def process(filename):
'''process one logfile'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, notimestamps=args.notimestamps,
robust_parsing=args.robust)
ext = os.path.splitext(filename)[1]
isbin = ext in ['.bin', '.BIN']
islog = ext in ['.log', '.LOG']
output = None
count = 1
dirname = os.path.dirname(filename)
if isbin or islog:
extension = "bin"
else:
extension = "tlog"
file_header = ''
messages = []
# we allow a list of modes that map to one mode number. This allows for --mode=AUTO,RTL and consider the RTL as part of AUTO
modes = args.mode.upper().split(',')
flightmode = None
while True:
m = mlog.recv_match()
if m is None:
break
if args.link is not None and m._link != args.link:
continue
mtype = m.get_type()
if mtype in messages:
if older_message(m, messages[mtype]):
continue
# we don't use mlog.flightmode as that can be wrong if we are extracting a single link
if mtype == 'HEARTBEAT' and m.get_srcComponent() != mavutil.mavlink.MAV_COMP_ID_GIMBAL and m.type != mavutil.mavlink.MAV_TYPE_GCS:
flightmode = mavutil.mode_string_v10(m).upper()
if mtype == 'MODE':
flightmode = mlog.flightmode
if (isbin or islog) and m.get_type() in ["FMT", "PARM", "CMD"]:
file_header += m.get_msgbuf()
if (isbin or islog) and m.get_type() == 'MSG' and m.Message.startswith("Ardu"):
file_header += m.get_msgbuf()
if m.get_type() in ['PARAM_VALUE','MISSION_ITEM']:
timestamp = getattr(m, '_timestamp', None)
file_header += struct.pack('>Q', timestamp*1.0e6) + m.get_msgbuf()
if not mavutil.evaluate_condition(args.condition, mlog.messages):
continue
if flightmode in modes:
if output is None:
path = os.path.join(dirname, "%s%u.%s" % (modes[0], count, extension))
count += 1
print("Creating %s" % path)
output = open(path, mode='wb')
output.write(file_header)
else:
if output is not None:
output.close()
output = None
if output and m.get_type() != 'BAD_DATA':
timestamp = getattr(m, '_timestamp', None)
if not isbin:
output.write(struct.pack('>Q', timestamp*1.0e6))
output.write(m.get_msgbuf()) | python | def process(filename):
'''process one logfile'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, notimestamps=args.notimestamps,
robust_parsing=args.robust)
ext = os.path.splitext(filename)[1]
isbin = ext in ['.bin', '.BIN']
islog = ext in ['.log', '.LOG']
output = None
count = 1
dirname = os.path.dirname(filename)
if isbin or islog:
extension = "bin"
else:
extension = "tlog"
file_header = ''
messages = []
# we allow a list of modes that map to one mode number. This allows for --mode=AUTO,RTL and consider the RTL as part of AUTO
modes = args.mode.upper().split(',')
flightmode = None
while True:
m = mlog.recv_match()
if m is None:
break
if args.link is not None and m._link != args.link:
continue
mtype = m.get_type()
if mtype in messages:
if older_message(m, messages[mtype]):
continue
# we don't use mlog.flightmode as that can be wrong if we are extracting a single link
if mtype == 'HEARTBEAT' and m.get_srcComponent() != mavutil.mavlink.MAV_COMP_ID_GIMBAL and m.type != mavutil.mavlink.MAV_TYPE_GCS:
flightmode = mavutil.mode_string_v10(m).upper()
if mtype == 'MODE':
flightmode = mlog.flightmode
if (isbin or islog) and m.get_type() in ["FMT", "PARM", "CMD"]:
file_header += m.get_msgbuf()
if (isbin or islog) and m.get_type() == 'MSG' and m.Message.startswith("Ardu"):
file_header += m.get_msgbuf()
if m.get_type() in ['PARAM_VALUE','MISSION_ITEM']:
timestamp = getattr(m, '_timestamp', None)
file_header += struct.pack('>Q', timestamp*1.0e6) + m.get_msgbuf()
if not mavutil.evaluate_condition(args.condition, mlog.messages):
continue
if flightmode in modes:
if output is None:
path = os.path.join(dirname, "%s%u.%s" % (modes[0], count, extension))
count += 1
print("Creating %s" % path)
output = open(path, mode='wb')
output.write(file_header)
else:
if output is not None:
output.close()
output = None
if output and m.get_type() != 'BAD_DATA':
timestamp = getattr(m, '_timestamp', None)
if not isbin:
output.write(struct.pack('>Q', timestamp*1.0e6))
output.write(m.get_msgbuf()) | [
"def",
"process",
"(",
"filename",
")",
":",
"print",
"(",
"\"Processing %s\"",
"%",
"filename",
")",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
",",
"notimestamps",
"=",
"args",
".",
"notimestamps",
",",
"robust_parsing",
"=",
"args",... | process one logfile | [
"process",
"one",
"logfile"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py#L36-L108 | train | 230,191 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py | LogModule.handle_log_entry | def handle_log_entry(self, m):
'''handling incoming log entry'''
if m.time_utc == 0:
tstring = ''
else:
tstring = time.ctime(m.time_utc)
self.entries[m.id] = m
print("Log %u numLogs %u lastLog %u size %u %s" % (m.id, m.num_logs, m.last_log_num, m.size, tstring)) | python | def handle_log_entry(self, m):
'''handling incoming log entry'''
if m.time_utc == 0:
tstring = ''
else:
tstring = time.ctime(m.time_utc)
self.entries[m.id] = m
print("Log %u numLogs %u lastLog %u size %u %s" % (m.id, m.num_logs, m.last_log_num, m.size, tstring)) | [
"def",
"handle_log_entry",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"time_utc",
"==",
"0",
":",
"tstring",
"=",
"''",
"else",
":",
"tstring",
"=",
"time",
".",
"ctime",
"(",
"m",
".",
"time_utc",
")",
"self",
".",
"entries",
"[",
"m",
"."... | handling incoming log entry | [
"handling",
"incoming",
"log",
"entry"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L32-L39 | train | 230,192 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py | LogModule.handle_log_data_missing | def handle_log_data_missing(self):
'''handling missing incoming log data'''
if len(self.download_set) == 0:
return
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
if len(diff) == 0:
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, (1 + highest) * 90, 0xffffffff)
self.retries += 1
else:
num_requests = 0
while num_requests < 20:
start = min(diff)
diff.remove(start)
end = start
while end + 1 in diff:
end += 1
diff.remove(end)
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, start * 90, (end + 1 - start) * 90)
num_requests += 1
self.retries += 1
if len(diff) == 0:
break | python | def handle_log_data_missing(self):
'''handling missing incoming log data'''
if len(self.download_set) == 0:
return
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
if len(diff) == 0:
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, (1 + highest) * 90, 0xffffffff)
self.retries += 1
else:
num_requests = 0
while num_requests < 20:
start = min(diff)
diff.remove(start)
end = start
while end + 1 in diff:
end += 1
diff.remove(end)
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, start * 90, (end + 1 - start) * 90)
num_requests += 1
self.retries += 1
if len(diff) == 0:
break | [
"def",
"handle_log_data_missing",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"download_set",
")",
"==",
"0",
":",
"return",
"highest",
"=",
"max",
"(",
"self",
".",
"download_set",
")",
"diff",
"=",
"set",
"(",
"range",
"(",
"highest",
")",
... | handling missing incoming log data | [
"handling",
"missing",
"incoming",
"log",
"data"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L75-L101 | train | 230,193 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py | LogModule.log_status | def log_status(self):
'''show download status'''
if self.download_filename is None:
print("No download")
return
dt = time.time() - self.download_start
speed = os.path.getsize(self.download_filename) / (1000.0 * dt)
m = self.entries.get(self.download_lognum, None)
if m is None:
size = 0
else:
size = m.size
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
print("Downloading %s - %u/%u bytes %.1f kbyte/s (%u retries %u missing)" % (self.download_filename,
os.path.getsize(self.download_filename),
size,
speed,
self.retries,
len(diff))) | python | def log_status(self):
'''show download status'''
if self.download_filename is None:
print("No download")
return
dt = time.time() - self.download_start
speed = os.path.getsize(self.download_filename) / (1000.0 * dt)
m = self.entries.get(self.download_lognum, None)
if m is None:
size = 0
else:
size = m.size
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
print("Downloading %s - %u/%u bytes %.1f kbyte/s (%u retries %u missing)" % (self.download_filename,
os.path.getsize(self.download_filename),
size,
speed,
self.retries,
len(diff))) | [
"def",
"log_status",
"(",
"self",
")",
":",
"if",
"self",
".",
"download_filename",
"is",
"None",
":",
"print",
"(",
"\"No download\"",
")",
"return",
"dt",
"=",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"download_start",
"speed",
"=",
"os",
"."... | show download status | [
"show",
"download",
"status"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L104-L123 | train | 230,194 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py | LogModule.log_download | def log_download(self, log_num, filename):
'''download a log file'''
print("Downloading log %u as %s" % (log_num, filename))
self.download_lognum = log_num
self.download_file = open(filename, "wb")
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
log_num, 0, 0xFFFFFFFF)
self.download_filename = filename
self.download_set = set()
self.download_start = time.time()
self.download_last_timestamp = time.time()
self.download_ofs = 0
self.retries = 0 | python | def log_download(self, log_num, filename):
'''download a log file'''
print("Downloading log %u as %s" % (log_num, filename))
self.download_lognum = log_num
self.download_file = open(filename, "wb")
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
log_num, 0, 0xFFFFFFFF)
self.download_filename = filename
self.download_set = set()
self.download_start = time.time()
self.download_last_timestamp = time.time()
self.download_ofs = 0
self.retries = 0 | [
"def",
"log_download",
"(",
"self",
",",
"log_num",
",",
"filename",
")",
":",
"print",
"(",
"\"Downloading log %u as %s\"",
"%",
"(",
"log_num",
",",
"filename",
")",
")",
"self",
".",
"download_lognum",
"=",
"log_num",
"self",
".",
"download_file",
"=",
"o... | download a log file | [
"download",
"a",
"log",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L125-L138 | train | 230,195 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py | LogModule.idle_task | def idle_task(self):
'''handle missing log data'''
if self.download_last_timestamp is not None and time.time() - self.download_last_timestamp > 0.7:
self.download_last_timestamp = time.time()
self.handle_log_data_missing() | python | def idle_task(self):
'''handle missing log data'''
if self.download_last_timestamp is not None and time.time() - self.download_last_timestamp > 0.7:
self.download_last_timestamp = time.time()
self.handle_log_data_missing() | [
"def",
"idle_task",
"(",
"self",
")",
":",
"if",
"self",
".",
"download_last_timestamp",
"is",
"not",
"None",
"and",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"download_last_timestamp",
">",
"0.7",
":",
"self",
".",
"download_last_timestamp",
"=",
"... | handle missing log data | [
"handle",
"missing",
"log",
"data"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L185-L189 | train | 230,196 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py | complete_modules | def complete_modules(text):
'''complete mavproxy module names'''
import MAVProxy.modules, pkgutil
modlist = [x[1] for x in pkgutil.iter_modules(MAVProxy.modules.__path__)]
ret = []
loaded = set(complete_loadedmodules(''))
for m in modlist:
if not m.startswith("mavproxy_"):
continue
name = m[9:]
if not name in loaded:
ret.append(name)
return ret | python | def complete_modules(text):
'''complete mavproxy module names'''
import MAVProxy.modules, pkgutil
modlist = [x[1] for x in pkgutil.iter_modules(MAVProxy.modules.__path__)]
ret = []
loaded = set(complete_loadedmodules(''))
for m in modlist:
if not m.startswith("mavproxy_"):
continue
name = m[9:]
if not name in loaded:
ret.append(name)
return ret | [
"def",
"complete_modules",
"(",
"text",
")",
":",
"import",
"MAVProxy",
".",
"modules",
",",
"pkgutil",
"modlist",
"=",
"[",
"x",
"[",
"1",
"]",
"for",
"x",
"in",
"pkgutil",
".",
"iter_modules",
"(",
"MAVProxy",
".",
"modules",
".",
"__path__",
")",
"]... | complete mavproxy module names | [
"complete",
"mavproxy",
"module",
"names"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L63-L75 | train | 230,197 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py | complete_filename | def complete_filename(text):
'''complete a filename'''
#ensure directories have trailing slashes:
list = glob.glob(text+'*')
for idx, val in enumerate(list):
if os.path.isdir(val):
list[idx] = (val + os.path.sep)
return list | python | def complete_filename(text):
'''complete a filename'''
#ensure directories have trailing slashes:
list = glob.glob(text+'*')
for idx, val in enumerate(list):
if os.path.isdir(val):
list[idx] = (val + os.path.sep)
return list | [
"def",
"complete_filename",
"(",
"text",
")",
":",
"#ensure directories have trailing slashes:",
"list",
"=",
"glob",
".",
"glob",
"(",
"text",
"+",
"'*'",
")",
"for",
"idx",
",",
"val",
"in",
"enumerate",
"(",
"list",
")",
":",
"if",
"os",
".",
"path",
... | complete a filename | [
"complete",
"a",
"filename"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L77-L86 | train | 230,198 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py | complete_variable | def complete_variable(text):
'''complete a MAVLink variable'''
if text.find('.') != -1:
var = text.split('.')[0]
if var in rline_mpstate.status.msgs:
ret = []
for f in rline_mpstate.status.msgs[var].get_fieldnames():
ret.append(var + '.' + f)
return ret
return []
return rline_mpstate.status.msgs.keys() | python | def complete_variable(text):
'''complete a MAVLink variable'''
if text.find('.') != -1:
var = text.split('.')[0]
if var in rline_mpstate.status.msgs:
ret = []
for f in rline_mpstate.status.msgs[var].get_fieldnames():
ret.append(var + '.' + f)
return ret
return []
return rline_mpstate.status.msgs.keys() | [
"def",
"complete_variable",
"(",
"text",
")",
":",
"if",
"text",
".",
"find",
"(",
"'.'",
")",
"!=",
"-",
"1",
":",
"var",
"=",
"text",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"if",
"var",
"in",
"rline_mpstate",
".",
"status",
".",
"msgs",
... | complete a MAVLink variable | [
"complete",
"a",
"MAVLink",
"variable"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L92-L102 | train | 230,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.