2016-01-02 07:22:36 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# (c) Siddharth Bharat Purohit, 3DRobotics Inc.
|
|
|
|
|
|
|
|
"""
|
|
|
|
The **mavgen.py** program is a code generator which creates mavlink header files.
|
|
|
|
"""
|
|
|
|
|
2016-05-09 22:14:30 -03:00
|
|
|
from waflib import Logs, Task, Utils, Node
|
2016-01-02 07:22:36 -04:00
|
|
|
from waflib.TaskGen import feature, before_method, extension
|
2018-11-18 17:08:31 -04:00
|
|
|
import os, sys
|
2016-05-19 15:18:17 -03:00
|
|
|
import os.path
|
|
|
|
from xml.etree import ElementTree as et
|
2016-01-02 07:22:36 -04:00
|
|
|
|
|
|
|
class mavgen(Task.Task):
|
2016-01-13 10:39:32 -04:00
|
|
|
"""generate mavlink header files"""
|
2016-05-05 19:43:54 -03:00
|
|
|
color = 'BLUE'
|
2016-01-13 14:50:06 -04:00
|
|
|
before = 'cxx c'
|
2016-01-02 07:22:36 -04:00
|
|
|
|
2016-05-19 15:18:17 -03:00
|
|
|
def scan(self):
|
|
|
|
nodes = []
|
|
|
|
names = []
|
|
|
|
|
|
|
|
entry_point = self.inputs[0]
|
|
|
|
queue = [entry_point]
|
|
|
|
head = 0
|
|
|
|
|
|
|
|
while head < len(queue):
|
|
|
|
node = queue[head]
|
|
|
|
head += 1
|
|
|
|
|
|
|
|
tree = et.parse(node.abspath())
|
|
|
|
root = tree.getroot()
|
|
|
|
includes = root.findall('include')
|
|
|
|
for i in includes:
|
|
|
|
path = i.text.strip()
|
|
|
|
n = node.parent.find_node(path)
|
|
|
|
if n:
|
|
|
|
nodes.append(n)
|
|
|
|
if n not in queue:
|
|
|
|
queue.append(n)
|
|
|
|
continue
|
|
|
|
|
|
|
|
path = os.path.join(
|
|
|
|
node.parent.path_from(entry_point.parent),
|
|
|
|
path
|
|
|
|
)
|
|
|
|
if not path in names:
|
|
|
|
names.append(path)
|
|
|
|
|
|
|
|
return nodes, names
|
|
|
|
|
2016-05-09 22:14:30 -03:00
|
|
|
def run(self):
|
2018-11-18 17:08:31 -04:00
|
|
|
sys.path.insert(0,self.env.get_flat('MAVLINK_DIR'))
|
2018-11-14 04:27:42 -04:00
|
|
|
from pymavlink.generator import mavgen
|
|
|
|
class mavgen_options:
|
|
|
|
language = 'C'
|
|
|
|
wire_protocol = '2.0'
|
|
|
|
validate = False
|
|
|
|
output = self.env.get_flat('OUTPUT_DIR')
|
|
|
|
xml = self.inputs[0].abspath()
|
|
|
|
if mavgen.mavgen(mavgen_options(), [xml]):
|
|
|
|
return 0
|
|
|
|
return 1
|
2016-05-09 22:14:30 -03:00
|
|
|
|
2016-01-13 14:28:26 -04:00
|
|
|
def post_run(self):
|
|
|
|
super(mavgen, self).post_run()
|
|
|
|
for header in self.generator.output_dir.ant_glob("*.h **/*.h", remove=False):
|
|
|
|
header.sig = header.cache_sig = self.cache_sig
|
|
|
|
|
2016-01-02 07:22:36 -04:00
|
|
|
def options(opt):
|
2016-01-13 10:39:32 -04:00
|
|
|
opt.load('python')
|
2016-01-02 07:22:36 -04:00
|
|
|
|
|
|
|
@feature('mavgen')
|
|
|
|
@before_method('process_source')
|
|
|
|
def process_mavgen(self):
|
2016-01-14 12:32:26 -04:00
|
|
|
if not hasattr(self, 'output_dir'):
|
|
|
|
self.bld.fatal('mavgen: missing option output_dir')
|
|
|
|
|
2021-12-06 00:52:46 -04:00
|
|
|
inputs = self.to_nodes(self.bld.srcnode.find_node(self.source))
|
2016-01-02 07:22:36 -04:00
|
|
|
outputs = []
|
|
|
|
|
|
|
|
self.source = []
|
2016-01-13 15:05:48 -04:00
|
|
|
|
2016-01-14 12:32:26 -04:00
|
|
|
if not isinstance(self.output_dir, Node.Node):
|
|
|
|
self.output_dir = self.bld.bldnode.find_or_declare(self.output_dir)
|
|
|
|
|
2016-01-13 15:05:48 -04:00
|
|
|
task = self.create_task('mavgen', inputs, outputs)
|
2016-01-14 12:32:26 -04:00
|
|
|
task.env['OUTPUT_DIR'] = self.output_dir.abspath()
|
2016-01-13 15:05:48 -04:00
|
|
|
|
|
|
|
task.env.env = dict(os.environ)
|
|
|
|
task.env.env['PYTHONPATH'] = task.env.MAVLINK_DIR
|
2016-01-02 07:22:36 -04:00
|
|
|
|
|
|
|
def configure(cfg):
|
2016-01-13 10:39:32 -04:00
|
|
|
"""
|
|
|
|
setup environment for mavlink header generator
|
|
|
|
"""
|
|
|
|
cfg.load('python')
|
|
|
|
cfg.check_python_version(minver=(2,7,0))
|
2016-01-02 07:22:36 -04:00
|
|
|
|
2016-01-13 10:39:32 -04:00
|
|
|
env = cfg.env
|
2016-02-05 12:09:21 -04:00
|
|
|
env.MAVLINK_DIR = cfg.srcnode.make_node('modules/mavlink/').abspath()
|