Exemplo n.º 1
0
def gen(ast):
    msgs = []
    msgtogen = collect(ast)
    #Generate the needed message files
    for (struct_t, file) in msgtogen.items():
        msgs.append(file)
        filecontent = ros_msgdef(struct_t)
        write_file(file, filecontent)
    return msgs
Exemplo n.º 2
0
def gen(ast):
    msgs= []
    msgtogen = collect(ast)
    #Generate the needed message files
    for (struct_t, file) in msgtogen.items():
        msgs.append(file)
        filecontent = ros_msgdef(struct_t)
        write_file(file, filecontent)
    return msgs
Exemplo n.º 3
0
def machine(visitor, m, d):
    clear(d, node_templates_machine_sublevel)
    clear(d, machine_templates)
    d['machine_qname'] = str(m._qname)

    visitor.node_bf(m, d)

    app(d, machine_templates)
    filename = 'launch/' + d['machine_qname'] + '.launch'
    d['launch_files'].append(filename)
    file = d['package_path'] / filename
    write_file(file, d['machine_launchfile'])
Exemplo n.º 4
0
def generate_msg_files(msgtogen):
    """ The msgtogen is a mapping (dict) from the data StructType to the msg
    filename. The required extra msg fields (radl__flags, instrumentation, etc)
    are automatically added.
    @Returns the list of message files generated.
    """
    msgs = []
    #Generate the needed message files
    for (struct_t, file) in msgtogen.items():
        msgs.append(file)
        filecontent = ros_msgdef(struct_t)
        write_file(file, filecontent)
    return msgs
Exemplo n.º 5
0
def gen(msg_list, gened_cpp_files, ast):
    #The Cmakefile waits for msg files relative to the msg dir
    msg_dir = filepath(qn_msgfile(QualifiedName(ast._qname, '', True)))
    msg_files = (str(m.relative_to(msg_dir)) for m in msg_list)
    localroot = qn_dir(ast._qname)
    d = {'namespace'       : ast._qname.name(),
         'msg_files'       : '\n  '.join(msg_files),
         'gened_cpp_files' : gened_cpp_files,
         'localroot'       : localroot}
    for t in nt: d[t] = ''
    for t in lt: d[t] = ''
    for t in sl: d[t] = ''
    _visitor.visit(ast, d)
    app(d, 'cmakeliststxt')
    write_file(filepath(localroot / "CMakeLists.txt"), d['cmakeliststxt'])
Exemplo n.º 6
0
def gen(package_folder, package_name, build_dependencies, run_dependencies):
    d = {'source'  : str(infos.source_file),
         'package' : package_name}

    build_deps = ''
    for p in build_dependencies:
        build_deps += build_dep_template.format(package_dep=p)
    d['build_deps'] = build_deps

    run_deps = ''
    for p in run_dependencies:
        run_deps += run_dep_template.format(package_dep=p)
    d['run_deps'] = run_deps

    package_xml = package_xml_template.format(**d)
    write_file(package_folder / "package.xml", package_xml)
Exemplo n.º 7
0
def gen_srosfile(plantinfo, package_name, package_folder):
    """ Generate SROS config file from a plant description.
    @return: the config file handle
    """
    ## we create the correct structure for the sros yaml configuration file and dump it
    cfg = dict()
    topics = list()
    cfg['topics'] = topics

    warned_systems = set()

    def getIP(system):
        try:
            return system['IP']._val
        except AttributeError:
            if not (system._qname in warned_systems):
                warning(
                    "No IP given, so SROS generation assumes IP 127.0.0.1 for system "
                    + str(system._qname), system._location)
                warned_systems.add(system._qname)
            return '127.0.0.1'

    for t in plantinfo.topics:

        publisherIP = getIP(
            plantinfo[plantinfo[t]['publisher_node']]['system'])
        subscriberIPs = [
            getIP(plantinfo[s]['system'])
            for s in plantinfo[t]['subscriber_nodes']
        ]

        topic_info = {
            'name': qn_topic(t._qname),
            'publishers': [publisherIP],
            'subscribers': subscriberIPs
        }
        topics.append(topic_info)

    sros_cfg_file = 'sros_cfg.yaml'
    write_file(package_folder / sros_cfg_file, yaml.dump(cfg))

    return sros_cfg_file
Exemplo n.º 8
0
def gen(msg_list, gened_cpp_files, ast):
    #The Cmakefile waits for msg files relative to the msg dir
    msg_dir = filepath(qn_msgfile(QualifiedName(ast._qname, '', True)))
    msg_files = (str(m.relative_to(msg_dir)) for m in msg_list)
    localroot = qn_dir(ast._qname)
    d = {
        'namespace': ast._qname.name(),
        'msg_files': '\n  '.join(msg_files),
        'gened_cpp_files': gened_cpp_files,
        'localroot': localroot
    }
    for t in nt:
        d[t] = ''
    for t in lt:
        d[t] = ''
    for t in sl:
        d[t] = ''
    _visitor.visit(ast, d)
    app(d, 'cmakeliststxt')
    write_file(filepath(localroot / "CMakeLists.txt"), d['cmakeliststxt'])
Exemplo n.º 9
0
def gen(localroot, msg_list, msg_dir, ast, extra_files=None):

    onleaf = AstVisitor.leaf_bf  # @UndefinedVariable

    visitor = AstVisitor({'node' : _from_node}, kind='bf', onleaf=onleaf)

    d = {'module'     : ast._name,
         'module_lib' : qn.cmake_ast(ast._qname.rootmodule()),
         'ast_fun'    : qn.c_astfun(ast),
         '_localroot' : localroot
         }

    clear(d, cmake_templates)
    clear(d, cmake_msgs_templates)
    clear(d, node_templates_cmake_sublevel)

    visitor.visit(ast, d)

    toload = infos.loaded_modules
    loaded_modules = ' '.join(qn.cmake_ast(n) for n in toload)
    d['find_modules'] = d['module_lib'] + ' radl_lib roscpp ' + loaded_modules
    d['run_modules'] = ' roscpp'
    d['ros_modules'] = ' '.join(n.name() for n in toload)

# Trying to be smart make dependencies hard since otherwise we can't blindly
# add any ros package as a message dependency.
#     if len(msg_list) > 0:

    msg_files = (str(relative_path(m, msg_dir)) for m in msg_list)
    d['msg_files'] = listjoin(' ', msg_files)
    d['extra_files'] = listjoin(' ', extra_files) if extra_files else ''
    d['find_modules'] += ' message_generation'
    d['run_modules'] += ' message_runtime'

    app(d, cmake_msgs_templates)

    app(d, cmake_templates)

    write_file(localroot / "CMakeLists.txt", d['cmakeliststxt'])
Exemplo n.º 10
0
def do_pass(ast):

    d = {
        'namespace': ast._name,
        'package_name': qn.package_ast(ast),
        'ast': qn.cmake_ast(ast),
        'ast_fun': qn.c_astfun(ast),
        'user_src_folder': user_src_path,
        'module_sources': '',
        'module_includes': '',
        'module_libs': '',
        'module_find_libs': ''
    }

    # Generate the package file
    build_deps = ['radl_lib']
    for p in infos.loaded_modules:
        build_deps.append(qn.package_ast(p))

    d['ast_deps'] = ' '.join(build_deps)

    astfolder = ws_path(d['package_name'])

    # Generate the ast files
    c_filename, c_file, h_filename, h_file = ASTdump.gen(ast)
    d['ast_c_filename'] = c_filename
    d['ast_h_filename'] = h_filename
    write_file(astfolder / c_filename, c_file)
    write_file(astfolder / 'include' / h_filename, h_file)

    clear(d, cmake_templates)
    clear(d, lib_static_templates_cmake_sublevel)
    clear(d, lib_cmake_templates_cmake_sublevel)

    visitor = AstVisitor(
        fun_dict_of((module_settings, static_library, cmake_library)),
        onleaf=follow_modlocal_links(AstVisitor.leaf_bf),  # @UndefinedVariable
        kind='bf')
    # We follow links to have correct dependencies, but we need unicity
    d['_seen'] = set()

    visitor.node_bf(ast, d)  #visitor follow links and unique passage

    app(d, cmake_templates)

    # Generate the cmake file
    cmake = d['cmakelists']
    cmake_file = astfolder / 'CMakeLists.txt'
    write_file(cmake_file, cmake)

    catkin_pkg.gen(astfolder, d['package_name'], build_deps, [])

    user_src = astfolder / d['user_src_folder']
    link_path(user_src, infos.module_base_path, relative=infos.relative_links)
Exemplo n.º 11
0
def gennode(visitor, node, cpps):
    """ Nodes are not recursive for now """

    d = {'in_struct'       : '_in_t',
         'out_struct'      : '_out_t',
         'in_flags_struct' : '_in_flags_t',
         'out_flags_struct': '_out_flags_t',
         'cxx_includes'    : getincludes(node),
         'period'          : to_rate(node['PERIOD'])}    #TODO: 5 correct when ros is fixed and allow a duration as rate constructor argument 

    #Over publications and subscriptions
    pubsub_templates = ['msg_include']
    for pt in pubsub_templates: d[pt] = ''
    #Over the publications
    pubmon_templates = ['pub_call', 'out_fill' , 'set_pub', 'out_flags_struct_def',
                     'out_struct_def', 'pub_flags_fill', 'set_counter', 'pub_report', 'report_fill']
    pub_templates = ['pub_call', 'out_fill' , 'set_pub', 'out_flags_struct_def',
                     'out_struct_def', 'pub_flags_fill']
    mon_templates = ['pub_report', 'report_fill' , 'set_pub', 'set_counter']
    for pt in pubmon_templates: d[pt] = ''
    for pub in node['PUBLISHES']:
        d.update({'pubname'     : pub._qname.name(),
                  'topic_name'  : qn_topic(pub['TOPIC']._qname),
                  'actionname'  : '_' + pub._qname.name() + '_pub',
                  'actionclass' : pub['PUBLISHER']['CXX']['CLASS']._val,
                  'topic_file'  : pub['TOPIC']._ros_msgtype_header,
                  'topic_t'     : pub['TOPIC']._ros_msgtype_name,
                  'initmsg'     : '_init_' + pub._qname.name()})
        d['init_msg_fill'] = ros_val_def(d['initmsg'], pub['TOPIC'],
                                         separators['init_msg_fill'])
        d['report_msg_fill'] = ros_val_def('_report', pub['TOPIC'],
                                         separators['report_msg_fill'])
        if pub['MONITOR'] is None:
            for f in pub_templates: app(d, f)
        else:
            if(pub['MONITOR']._val == 'true'):
                d.update({'times' : to_times(node['PERIOD'])})
                for f in mon_templates: app(d, f)
            else:
                for f in pub_templates: app(d, f)
        for f in pubsub_templates: app(d, f)

    #Over the subscriptions
    sub_templates = ['in_fill', 'set_sub', 'in_struct_def', 'in_flags_struct_def',
                     'sub_flags_fill', 'gathered_flags']
    for st in sub_templates: d[st] = ''
    d['gathered_flags'] = '0'
    for sub in node['SUBSCRIBES']:
        d.update({'subname'     : sub._qname.name(),
                  'topic_name'  : qn_topic(sub['TOPIC']._qname),
                  'actionname'  : '_' + sub._qname.name() + '_sub',
                  'actionclass' : sub['SUBSCRIBER']['CXX']['CLASS']._val,
                  'topic_file'  : sub['TOPIC']._ros_msgtype_header,
                  'topic_t'     : sub['TOPIC']._ros_msgtype_name,
                  'initmsg'     : '_init_' + sub._qname.name(),
                  'maxlatency'  : to_ros_duration(sub['MAXLATENCY'])})
        try:
            d['pubperiod'] = to_ros_duration(sub['TOPIC']._publisher['PERIOD'])
        except AttributeError: #no publisher
            warning("By lack of known publisher, subscription {} will "
                    "compute timeout assuming the publisher period is 10s."
                    "".format(str(sub._qname)), sub._location)
            d['pubperiod'] = "ros::Duration().fromNSec(10000000000)"
        d['init_msg_fill'] = ros_val_def(d['initmsg'], sub['TOPIC'],
                                         separators['init_msg_fill'])
        for f in sub_templates: app(d, f)
        for f in pubsub_templates: app(d, f)
    #generate the header file
    qname = node._qname
    #TODO: 4 namespace nodes... use the nodehandler? or the remaping args?
    d['name'] = qname.name()
    node_h_name = Path(qn_srcfile(node._qname, 'radl__', '.h'))
    node_h = templates['node_h'].format(**d)
    write_file(filepath(node_h_name), node_h)
    #generate the cpp file
    node_cpp_name = Path(qn_srcfile(node._qname, 'radl__', '.cpp'))
    node_cpp = templates['node_cpp'].format(
        node_h_name=node_h_name.name, rate=node['PERIOD']._val, node=node, **d)
    write_file(filepath(node_cpp_name), node_cpp)
    #register the cpp file
    cpps[qname] = node_cpp_name
    return (), cpps
Exemplo n.º 12
0
def gen(ast):
    package_xml = _template_package_xml.format(namespace=ast._qname,
                                               source=str(infos.source_file))
    write_file(filepath(qn_dir(ast._qname) / "package.xml"), package_xml)