def set_dialect(dialect): '''set the MAVLink dialect to work with. For example, set_dialect("ardupilotmega") ''' global mavlink, current_dialect from generator import mavparse if mavlink is None or mavlink.WIRE_PROTOCOL_VERSION == "1.0" or not 'MAVLINK09' in os.environ: wire_protocol = mavparse.PROTOCOL_1_0 modname = "pymavlink.dialects.v10." + dialect else: wire_protocol = mavparse.PROTOCOL_0_9 modname = "pymavlink.dialects.v09." + dialect try: mod = __import__(modname) except Exception: # auto-generate the dialect module from generator.mavgen import mavgen_python_dialect mavgen_python_dialect(dialect, wire_protocol) mod = __import__(modname) components = modname.split('.') for comp in components[1:]: mod = getattr(mod, comp) current_dialect = dialect mavlink = mod
def generate_content(): # generate the file content... from generator import mavgen, mavparse # path to message_definitions directory if os.getenv("MDEF",None) is not None: mdef_paths = [os.getenv("MDEF")] else: mdef_paths = [os.path.join('..', 'message_definitions'), os.path.join('mavlink', 'message_definitions'), os.path.join('..', 'mavlink', 'message_definitions'), os.path.join('message_definitions'), ] for path in mdef_paths: mdef_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), path) if os.path.exists(mdef_path): print("Using message definitions from %s" % mdef_path) break dialects_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'dialects') v10_dialects = glob.glob(os.path.join(mdef_path, 'v1.0', '*.xml')) # for now v2.0 uses same XML files as v1.0 v20_dialects = glob.glob(os.path.join(mdef_path, 'v1.0', '*.xml')) should_generate = not "NOGEN" in os.environ if should_generate: if len(v10_dialects) == 0: print("No XML message definitions found") sys.exit(1) for xml in v10_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v10')) for xml in v20_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v20')) for xml in v10_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT",'*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s for protocol 1.0" % xml) if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_1_0): print("Building failed %s for protocol 1.0" % xml) sys.exit(1) for xml in v20_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT",'*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s for protocol 2.0" % xml) if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_2_0): print("Building failed %s for protocol 2.0" % xml) sys.exit(1)
v09_dialects if not "NOGEN" in os.environ: for xml in v09_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v09')) for xml in v10_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v10')) for xml in v09_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT",'*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s" % xml) mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_0_9) for xml in v10_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT",'*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s" % xml) mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_1_0) extensions = [] # Assume we might be unable to build native code if platform.system() != 'Windows': extensions = [ Extension('mavnative', sources = ['mavnative/mavnative.c'], include_dirs = [ 'generator/C/include_v1.0',
v09_dialects if not "NOGEN" in os.environ: for xml in v09_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v09')) for xml in v10_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v10')) for xml in v09_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT", '*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s" % xml) mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_0_9) for xml in v10_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT", '*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s" % xml) mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_1_0) extensions = [] # Assume we might be unable to build native code if platform.system() != 'Windows': extensions = [ Extension('mavnative', sources=['mavnative/mavnative.c'], include_dirs=['generator/C/include_v1.0', 'mavnative'])
print("No XML message definitions found") sys.exit(1) if not "NOGEN" in os.environ: for xml in v10_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v10')) for xml in v20_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v20')) for xml in v10_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT",'*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s for protocol 1.0" % xml) if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_1_0): print("Building failed %s for protocol 1.0" % xml) sys.exit(1) for xml in v20_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT",'*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s for protocol 2.0" % xml) if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_2_0): print("Building failed %s for protocol 2.0" % xml) sys.exit(1) extensions = [] # Assume we might be unable to build native code if platform.system() != 'Windows':
print("No XML message definitions found") sys.exit(1) if not "NOGEN" in os.environ: for xml in v10_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v10')) for xml in v20_dialects: shutil.copy(xml, os.path.join(dialects_path, 'v20')) for xml in v10_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT", '*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s for protocol 1.0" % xml) if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_1_0): print("Building failed %s for protocol 1.0" % xml) sys.exit(1) for xml in v20_dialects: dialect = os.path.basename(xml)[:-4] wildcard = os.getenv("MAVLINK_DIALECT", '*') if not fnmatch.fnmatch(dialect, wildcard): continue print("Building %s for protocol 2.0" % xml) if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_2_0): print("Building failed %s for protocol 2.0" % xml) sys.exit(1) extensions = [] # Assume we might be unable to build native code if platform.system() != 'Windows':