Skip to content

Commit d42086e

Browse files
authored
Merge branch 'master' into feat/faster-cast-in-generated-python
2 parents a183613 + a4e3325 commit d42086e

File tree

9 files changed

+55
-26
lines changed

9 files changed

+55
-26
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These flake8 settings apply only to auto-generated Python code and are
2+
# different than this repo's .flake8 file settings that apply to handwritten code.
3+
# E203 whitespace before ':'
4+
# E302 expected 2 blank lines, found 1
5+
# E305 expected 2 blank lines after class or function definition, found 1
6+
# E501 line too long (5519 > 79 characters)
7+
# E741 ambiguous variable name 'I'
8+
# F401 'sys' imported but unused
9+
[flake8]
10+
ignore = E203,E302,E305,E741,F401
11+
max-complexity = 37
12+
max-line-length = 5519

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
shell: bash
8585
run: echo "CIBW_BUILD=cp${PYTHON_VERSION/./}-*" >> $GITHUB_ENV
8686
- name: Build wheels
87-
uses: pypa/[email protected].0
87+
uses: pypa/[email protected].1
8888
env:
8989
PYMAVLINK_FAST_INDEX: "1"
9090
CIBW_BUILD: ${{ matrix.cibw_build }}

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ jobs:
4141
# NOTE: we must do all testing on the installed python package, not
4242
# on the build tree. Otherwise the testing is invalid and may not
4343
# indicate the code actually works
44-
#
45-
# Set pythonpath
46-
47-
# install
4844
- name: Install mavlink message
4945
run: |
5046
git clone https://github.com/ArduPilot/mavlink.git
@@ -56,7 +52,7 @@ jobs:
5652
5753
- name: Lint generated python code
5854
run: |
59-
flake8 --ignore='W503,E203,E501,E741' --statistics dialects/
55+
flake8 --config=.github/workflows/flake8-generated.cfg --statistics dialects/
6056
6157
- name: Type check generated python code
6258
if: matrix.python-version != '3.7'

DFReader.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,27 +1385,34 @@ def init_arrays_fast(self, progress_callback=None):
13851385
if 'MultIds' in fmt.colhash:
13861386
fmt2.set_mult_ids(null_term(elements[fmt.colhash['MultIds']]), self.mult_lookup)
13871387

1388-
# Parse the first 100 messages of each type to try to build the
1389-
# messages dictionary. 100 was chosen as a reasonable heuristic to
1390-
# catch every index value that might be in that message.
1388+
# Parse the messages of each type to try to build the messages
1389+
# dictionary.
13911390
for mtype in range(256):
13921391
if mtype not in self.formats:
13931392
continue
13941393
fmt = self.formats[mtype]
1395-
NMSG = 100 if fmt.instance_field is not None else 1
1394+
omtype = offsets[mtype]
1395+
num_offsets = len(omtype)
1396+
if fmt.instance_field:
1397+
NMSG = num_offsets
1398+
if not mtype in type_instances:
1399+
type_instances[mtype] = set()
1400+
if fmt.instance_len == 1:
1401+
# hack to reduce load cost, only scan first 100 messages
1402+
# for single byte instance values. This works nearly all the time, and allows
1403+
# for full indexing for things like NVF which is string indexed, while not taking a huge amount of CPU
1404+
# on IMU and other bulk data
1405+
NMSG = min(NMSG, 100)
1406+
else:
1407+
NMSG = min(1, num_offsets)
13961408
for i in range(NMSG):
1397-
if i >= len(offsets[mtype]):
1398-
break
1399-
ofs = offsets[mtype][i]
1400-
if self.formats[mtype].name not in self.messages:
1409+
ofs = omtype[i]
1410+
if fmt.name not in self.messages:
14011411
self.offset = ofs
14021412
self._parse_next()
1403-
if self.formats[mtype].instance_field is not None:
1404-
fmt = self.formats[mtype]
1405-
# see if we've has this instance value before
1413+
if fmt.instance_field is not None:
1414+
# see if we've had this instance value before
14061415
idata = data[ofs+3+fmt.instance_ofs:ofs+3+fmt.instance_ofs+fmt.instance_len]
1407-
if not mtype in type_instances:
1408-
type_instances[mtype] = set()
14091416
if not idata in type_instances[mtype]:
14101417
# its a new one, need to parse it so we have the complete set of instances
14111418
type_instances[mtype].add(idata)

generator/mavgen.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
# Set defaults for generating MAVLink code
3434
DEFAULT_WIRE_PROTOCOL = mavparse.PROTOCOL_1_0
3535
DEFAULT_LANGUAGE = 'Python'
36-
DEFAULT_ERROR_LIMIT = 200
3736
DEFAULT_VALIDATE = True
3837
DEFAULT_STRICT_UNITS = False
3938

@@ -298,9 +297,8 @@ def mavgen_validate(xmlfile):
298297

299298
# build all the dialects in the dialects subpackage
300299
class Opts(object):
301-
def __init__(self, output, wire_protocol=DEFAULT_WIRE_PROTOCOL, language=DEFAULT_LANGUAGE, validate=DEFAULT_VALIDATE, error_limit=DEFAULT_ERROR_LIMIT, strict_units=DEFAULT_STRICT_UNITS):
300+
def __init__(self, output, wire_protocol=DEFAULT_WIRE_PROTOCOL, language=DEFAULT_LANGUAGE, validate=DEFAULT_VALIDATE, strict_units=DEFAULT_STRICT_UNITS):
302301
self.wire_protocol = wire_protocol
303-
self.error_limit = error_limit
304302
self.language = language
305303
self.output = output
306304
self.validate = validate

mavextra.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,10 @@ def ekf1_pos(EKF1):
10811081
from . import mavutil
10821082
self = mavutil.mavfile_global
10831083
if ekf_origin is None:
1084-
if not 'ORGN' in self.messages:
1084+
# Look for the ORGN[0] message explicitly
1085+
if not 'ORGN[0]' in self.messages:
10851086
return None
1086-
ekf_origin = self.messages['ORGN']
1087+
ekf_origin = self.messages['ORGN[0]']
10871088
(ekf_origin.Lat, ekf_origin.Lng) = (ekf_origin.Lat, ekf_origin.Lng)
10881089
(lat,lon) = gps_offset(ekf_origin.Lat, ekf_origin.Lng, EKF1.PE, EKF1.PN)
10891090
alt = ekf_origin.Alt - EKF1.PD

mavutil.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,20 @@ def dump_message_verbose(f, m):
27182718
timestamp = "%s.%02u: " % (
27192719
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)),
27202720
int(timestamp*100.0)%100)
2721-
f.write("%s%s (id=%u) (link=%s) (signed=%s) (seq=%u) (src=%u/%u)\n" % (timestamp, m.get_type(), m.get_msgId(), str(m.get_link_id()), str(m.get_signed()), m.get_seq(), m.get_srcSystem(), m.get_srcComponent()))
2721+
if m.get_signed():
2722+
signed = f"Yes; out-link={str(m.get_link_id())}"
2723+
else:
2724+
signed = "No"
2725+
2726+
inbound_link = getattr(m, '_link', None)
2727+
f.write(
2728+
f"{timestamp}{m.get_type()} (id={m.get_msgId()}) "
2729+
f"(seq={m.get_seq()}) "
2730+
f"(src={m.get_srcSystem()}/{m.get_srcComponent()}) "
2731+
f"(in-link={inbound_link}) "
2732+
f"(signed={signed})\n"
2733+
)
2734+
27222735
for fieldname in m.get_fieldnames():
27232736

27242737
# format in those most boring way possible:

tools/mavgen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
parser.add_argument("--lang", dest="language", choices=mavgen.supportedLanguages, default=mavgen.DEFAULT_LANGUAGE, help="language of generated code [default: %(default)s]")
2424
parser.add_argument("--wire-protocol", choices=[mavparse.PROTOCOL_0_9, mavparse.PROTOCOL_1_0, mavparse.PROTOCOL_2_0], default=mavgen.DEFAULT_WIRE_PROTOCOL, help="MAVLink protocol version. [default: %(default)s]")
2525
parser.add_argument("--no-validate", action="store_false", dest="validate", default=mavgen.DEFAULT_VALIDATE, help="Do not perform XML validation. Can speed up code generation if XML files are known to be correct.")
26-
parser.add_argument("--error-limit", default=mavgen.DEFAULT_ERROR_LIMIT, help="maximum number of validation errors to display")
2726
parser.add_argument("--strict-units", action="store_true", dest="strict_units", default=mavgen.DEFAULT_STRICT_UNITS, help="Perform validation of units attributes.")
2827
parser.add_argument("definitions", metavar="XML", nargs="+", help="MAVLink definitions")
2928
args = parser.parse_args()

tools/mavlogdump.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ def match_type(mtype, patterns):
238238
if (isbin or islog) and m_type == "FMT":
239239
output.write(m.get_msgbuf())
240240
continue
241+
if (isbin or islog) and m_type in ["FMTU", "MULT", "UNIT"]:
242+
output.write(m.get_msgbuf())
243+
continue
241244
if (isbin or islog) and (m_type == "PARM" and args.parms):
242245
output.write(m.get_msgbuf())
243246
continue

0 commit comments

Comments
 (0)