Skip to content

Commit e65ae44

Browse files
authored
Merge branch 'ArduPilot:master' into master
2 parents f815c04 + 3192cae commit e65ae44

18 files changed

+433
-146
lines changed

MAVProxy/modules/lib/grapher.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def plotit(self, x, y, fields, colors=[], title=None, interactive=True):
381381
if self.grid:
382382
pylab.grid()
383383

384-
if self.show_flightmode:
384+
if self.show_flightmode != 0:
385385
alpha = 0.3
386386
xlim = self.ax1.get_xlim()
387387
for i in range(len(self.flightmode_list)):
@@ -409,14 +409,14 @@ def plotit(self, x, y, fields, colors=[], title=None, interactive=True):
409409
else:
410410
self.fig.canvas.set_window_title(title)
411411

412-
if self.show_flightmode:
412+
if self.show_flightmode != 0:
413413
mode_patches = []
414414
for mode in self.modes_plotted.keys():
415415
(color, alpha) = self.modes_plotted[mode]
416416
mode_patches.append(matplotlib.patches.Patch(color=color,
417417
label=mode, alpha=alpha*1.5))
418418
labels = [patch.get_label() for patch in mode_patches]
419-
if ax1_labels != []:
419+
if ax1_labels != [] and self.show_flightmode != 2:
420420
patches_legend = matplotlib.pyplot.legend(mode_patches, labels, loc=self.legend_flightmode)
421421
self.fig.gca().add_artist(patches_legend)
422422
else:

MAVProxy/modules/lib/mission_item_protocol.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(self, mpstate, name, description, **args):
5959

6060
def gui_menu_items(self):
6161
return [
62+
MPMenuItem('FTP', 'FTP', '# %s ftp' % self.command_name()),
6263
MPMenuItem('Clear', 'Clear', '# %s clear' % self.command_name()),
6364
MPMenuItem('List', 'List', '# %s list' % self.command_name()),
6465
MPMenuItem(
@@ -863,6 +864,8 @@ def commands(self):
863864
print("%s module not available; use old compat modules" % str(self.itemtype()))
864865
return
865866
return {
867+
"ftp": self.wp_ftp_download,
868+
"ftpload": self.wp_ftp_upload,
866869
"clear": self.cmd_clear,
867870
"list": self.cmd_list,
868871
"load": (self.cmd_load, ["(FILENAME)"]),
@@ -962,7 +965,7 @@ def request_list_send(self):
962965
mission_type=self.mav_mission_type())
963966

964967
def wp_ftp_download(self, args):
965-
'''Download wpts from vehicle with ftp'''
968+
'''Download items from vehicle with ftp'''
966969
ftp = self.mpstate.module('ftp')
967970
if ftp is None:
968971
print("Need ftp module")
@@ -971,7 +974,7 @@ def wp_ftp_download(self, args):
971974
ftp.cmd_get([self.mission_ftp_name()], callback=self.ftp_callback, callback_progress=self.ftp_callback_progress)
972975

973976
def ftp_callback_progress(self, fh, total_size):
974-
'''progress callback from ftp fetch of mission'''
977+
'''progress callback from ftp fetch of mission items'''
975978
if self.ftp_count is None and total_size >= 10:
976979
ofs = fh.tell()
977980
fh.seek(0)
@@ -987,18 +990,18 @@ def ftp_callback_progress(self, fh, total_size):
987990
self.mpstate.console.set_status('Mission', 'Mission %u/%u' % (done, self.ftp_count))
988991

989992
def ftp_callback(self, fh):
990-
'''callback from ftp fetch of mission'''
993+
'''callback from ftp fetch of mission items'''
991994
if fh is None:
992995
print("mission: failed ftp download")
993996
return
994997
magic = 0x763d
995998
data = fh.read()
996999
magic2, dtype, options, start, num_items = struct.unpack("<HHHHH", data[0:10])
9971000
if magic != magic2:
998-
print("mission: bad magic 0x%x expected 0x%x" % (magic2, magic))
1001+
print("%s: bad magic 0x%x expected 0x%x" % (self.itemtype(), magic2, magic))
9991002
return
1000-
if dtype != mavutil.mavlink.MAV_MISSION_TYPE_MISSION:
1001-
print("mission: bad data type %u" % dtype)
1003+
if dtype != self.mav_mission_type():
1004+
print("%s: bad data type %u" % (self.itemtype(), dtype))
10021005
return
10031006

10041007
self.wploader.clear()
@@ -1051,11 +1054,11 @@ def wp_ftp_upload(self, args):
10511054
except Exception as msg:
10521055
print("Unable to load %s - %s" % (filename, msg))
10531056
return
1054-
print("Loaded %u waypoints from %s" % (self.wploader.count(), filename))
1055-
print("Sending mission with ftp")
1057+
print("Loaded %u %s from %s" % (self.wploader.count(), self.itemstype(), filename))
1058+
print("Sending %s with ftp" % self.itemstype())
10561059

10571060
fh = SIO()
1058-
fh.write(struct.pack("<HHHHH", 0x763d, mavutil.mavlink.MAV_MISSION_TYPE_MISSION, 0, 0, self.wploader.count()))
1061+
fh.write(struct.pack("<HHHHH", 0x763d, self.mav_mission_type(), 0, 0, self.wploader.count()))
10591062
mavmsg = mavutil.mavlink.MAVLink_mission_item_int_message
10601063
for i in range(self.wploader.count()):
10611064
w = self.wploader.wp(i)
@@ -1074,18 +1077,18 @@ def wp_ftp_upload(self, args):
10741077
fh=fh, callback=self.ftp_upload_callback, progress_callback=self.ftp_upload_progress)
10751078

10761079
def ftp_upload_progress(self, proportion):
1077-
'''callback from ftp put of mission'''
1080+
'''callback from ftp put of items'''
10781081
if proportion is None:
10791082
self.mpstate.console.set_status('Mission', 'Mission ERR')
10801083
else:
10811084
count = self.wploader.count()
10821085
self.mpstate.console.set_status('Mission', 'Mission %u/%u' % (int(proportion*count), count))
10831086

10841087
def ftp_upload_callback(self, dlen):
1085-
'''callback from ftp put of mission'''
1088+
'''callback from ftp put of items'''
10861089
if dlen is None:
1087-
print("Failed to send waypoints")
1090+
print("Failed to send %s" % self.itemstype())
10881091
else:
10891092
mavmsg = mavutil.mavlink.MAVLink_mission_item_int_message
10901093
item_size = mavmsg.unpacker.size
1091-
print("Sent mission of length %u in %.2fs" % ((dlen - 10) // item_size, time.time() - self.upload_start))
1094+
print("Sent %s of length %u in %.2fs" % (self.itemtype(), (dlen - 10) // item_size, time.time() - self.upload_start))

MAVProxy/modules/lib/mp_module.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,11 @@ def link_label(link):
205205
label = str(link.linknum+1)
206206
return label
207207

208-
def is_primary_vehicle(self, msg):
208+
def message_is_from_primary_vehicle(self, msg):
209209
'''see if a msg is from our primary vehicle'''
210210
sysid = msg.get_srcSystem()
211-
if self.target_system == 0 or self.target_system == sysid:
211+
compid = msg.get_srcComponent()
212+
if ((self.target_system == 0 or self.target_system == sysid) and
213+
(self.target_component == 0 or self.target_component == compid)):
212214
return True
213215
return False

MAVProxy/modules/lib/msgstats.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,52 @@ def child_task(self):
4242

4343
def show_stats(mlog):
4444
'''show stats on a file'''
45-
if not hasattr(mlog, 'formats'):
46-
print("Must be DF log")
47-
return
4845
sizes = {}
4946
total_size = 0
5047
names = mlog.name_to_id.keys()
5148
pairs = []
49+
maxnamelen = 4
5250

5351
for name in names:
5452
sizes[name] = 0
5553

5654
for name in names:
5755
mid = mlog.name_to_id[name]
58-
count = mlog.counts[mid]
59-
mlen = mlog.formats[mid].len
60-
size = count * mlen
61-
total_size += size
62-
sizes[name] += size
63-
pairs.append((name, count*mlen))
56+
# DFReader_text logs use the name directly as the index to the dictionaries
57+
if hasattr(mlog, 'formats') and mid not in mlog.formats:
58+
mid = name
59+
# In DFReader_text logs count is a dictionary, which is not set for
60+
# messages that are never seen in the log.
61+
if isinstance(mlog.counts,dict) and mid not in mlog.counts:
62+
count = 0
63+
else:
64+
count = mlog.counts[mid]
65+
# mavmmaplog class (tlogs) does not contain formats attribute, so instead of
66+
# counting size in bytes, we count the number of messages
67+
if hasattr(mlog, 'formats'):
68+
mlen = mlog.formats[mid].len
69+
size = count * mlen
70+
total_size += size
71+
sizes[name] += size
72+
pairs.append((name, count*mlen))
73+
else:
74+
total_size += count
75+
pairs.append((name, count))
76+
if count>0 and len(name)>maxnamelen:
77+
maxnamelen = len(name)
78+
79+
# mavmmaplog class (tlogs) does not contain formats attribute, so instead of
80+
# counting size in bytes, we count the number of messages
81+
if not hasattr(mlog, 'formats'):
82+
print("Total number of messages: %u" % total_size)
83+
else:
84+
print("Total size: %u" % total_size)
6485

86+
# Print out the percentage for each message, from lowest to highest
6587
pairs = sorted(pairs, key = lambda p : p[1])
66-
print("Total size: %u" % total_size)
6788
for (name,size) in pairs:
6889
if size > 0:
69-
print("%-4s %.2f%%" % (name, 100.0 * size / total_size))
90+
print("%-*s %.2f%%" % (maxnamelen, name, 100.0 * size / total_size))
7091

7192
print("")
7293
category_total = 0

MAVProxy/modules/lib/multiproc_util.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def __init__(self, *args, **kwargs):
269269
'''
270270
Parameters
271271
----------
272-
mlog : DFReader
272+
mlog : DFReader / mavmmaplog
273273
A dataflash or telemetry log
274274
'''
275275
super(MPDataLogChildTask, self).__init__(*args, **kwargs)
@@ -282,22 +282,31 @@ def wrap(self):
282282
'''Apply custom pickle wrappers to non-pickleable attributes'''
283283

284284
# wrap filehandle and mmap in mlog for pickling
285-
filehandle = self._mlog.filehandle
285+
if hasattr(self._mlog,'filehandle'):
286+
filehandle = self._mlog.filehandle
287+
elif hasattr(self._mlog,'f'):
288+
filehandle = self._mlog.f
286289
data_map = self._mlog.data_map
287290
data_len = self._mlog.data_len
288-
self._mlog.filehandle = WrapFileHandle(filehandle)
291+
if hasattr(self._mlog,'filehandle'):
292+
self._mlog.filehandle = WrapFileHandle(filehandle)
293+
elif hasattr(self._mlog,'f'):
294+
self._mlog.f = WrapFileHandle(filehandle)
289295
self._mlog.data_map = WrapMMap(data_map, filehandle, data_len)
290296

291297
# @override
292298
def unwrap(self):
293299
'''Unwrap custom pickle wrappers of non-pickleable attributes'''
294300

295301
# restore the state of mlog
296-
self._mlog.filehandle = self._mlog.filehandle.unwrap()
302+
if hasattr(self._mlog,'filehandle'):
303+
self._mlog.filehandle = self._mlog.filehandle.unwrap()
304+
elif hasattr(self._mlog,'f'):
305+
self._mlog.f = self._mlog.f.unwrap()
297306
self._mlog.data_map = self._mlog.data_map.unwrap()
298307

299308
@property
300309
def mlog(self):
301-
'''The dataflash log (DFReader)'''
310+
'''The dataflash or telemetry log (DFReader / mavmmaplog)'''
302311

303312
return self._mlog

MAVProxy/modules/lib/ntrip.py

+27-36
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
from MAVProxy.modules.lib import rtcm3
1515
import ssl
1616
from optparse import OptionParser
17+
from pynmeagps import NMEAMessage, GET
1718

18-
version = 0.1
19+
version = 0.2
1920
useragent = "NTRIP MAVProxy/%.1f" % version
2021

2122

@@ -70,26 +71,8 @@ def __init__(self,
7071
self.ssl = True
7172

7273
def setPosition(self, lat, lon):
73-
self.flagN = "N"
74-
self.flagE = "E"
75-
if lon > 180:
76-
lon = (lon-360)*-1
77-
self.flagE = "W"
78-
elif lon < 0 and lon >= -180:
79-
lon = lon*-1
80-
self.flagE = "W"
81-
elif lon < -180:
82-
lon = lon+360
83-
self.flagE = "E"
84-
else:
85-
self.lon = lon
86-
if lat < 0:
87-
lat = lat*-1
88-
self.flagN = "S"
89-
self.lonDeg = int(lon)
90-
self.latDeg = int(lat)
91-
self.lonMin = (lon-self.lonDeg)*60
92-
self.latMin = (lat-self.latDeg)*60
74+
self.lon = lon
75+
self.lat = lat
9376

9477
def getMountPointString(self):
9578
userstr = self.user
@@ -105,19 +88,28 @@ def getMountPointString(self):
10588
mountPointString += "\r\n"
10689
return mountPointString
10790

108-
def getGGAString(self):
109-
now = datetime.datetime.utcnow()
110-
ggaString = "GPGGA,%02d%02d%04.2f,%02d%011.8f,%1s,%03d%011.8f,%1s,1,05,0.19,+00400,M,%5.3f,M,," % (
111-
now.hour, now.minute, now.second, self.latDeg, self.latMin, self.flagN,
112-
self.lonDeg, self.lonMin, self.flagE, self.height)
113-
checksum = self.calculateCheckSum(ggaString)
114-
return "$%s*%s\r\n" % (ggaString, checksum)
91+
def getGGAByteString(self):
92+
gga_msg = NMEAMessage(
93+
"GP",
94+
"GGA",
95+
GET, # msgmode is expected by this lib
96+
lat=self.lat,
97+
NS="S" if self.lat < 0 else "N",
98+
lon=self.lon,
99+
EW="W" if self.lon < 0 else "E",
100+
quality=1,
101+
numSV=15,
102+
HDOP=0,
103+
alt=self.height,
104+
altUnit="M",
105+
sep=0,
106+
sepUnit="M",
107+
diffAge="",
108+
diffStation=0,
109+
)
115110

116-
def calculateCheckSum(self, stringToCheck):
117-
xsum_calc = 0
118-
for char in stringToCheck:
119-
xsum_calc = xsum_calc ^ ord(char)
120-
return "%02X" % xsum_calc
111+
raw_gga: bytes = gga_msg.serialize()
112+
return raw_gga
121113

122114
def get_ID(self):
123115
'''get ID of last packet'''
@@ -248,9 +240,8 @@ def readLoop(self):
248240
print("got: ", len(data))
249241

250242
def send_gga(self):
251-
gga = self.getGGAString()
252-
if sys.version_info.major >= 3:
253-
gga = bytearray(gga, "ascii")
243+
gga = self.getGGAByteString()
244+
254245
try:
255246
self.socket.sendall(gga)
256247
self.dt_last_gga_sent = time.time()

MAVProxy/modules/mavproxy_console.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def mavlink_packet(self, msg):
336336
if type == 'SYS_STATUS':
337337
self.check_critical_error(msg)
338338

339-
if not self.is_primary_vehicle(msg):
339+
if not self.message_is_from_primary_vehicle(msg):
340340
# don't process msgs from other than primary vehicle, other than
341341
# updating vehicle list
342342
return
@@ -540,13 +540,6 @@ def mavlink_packet(self, msg):
540540
self.console.set_status('PWR', status, fg=fg)
541541
self.console.set_status('Srv', 'Srv %.2f' % (msg.Vservo*0.001), fg='green')
542542
elif type in ['HEARTBEAT', 'HIGH_LATENCY2']:
543-
if msg.get_srcComponent() in [mavutil.mavlink.MAV_COMP_ID_ADSB,
544-
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_1,
545-
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_2,
546-
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_3]:
547-
# ignore these
548-
return
549-
550543
fmode = master.flightmode
551544
if self.settings.vehicle_name:
552545
fmode = self.settings.vehicle_name + ':' + fmode

0 commit comments

Comments
 (0)