Esempio n. 1
0
def genCommandConfigLua(inSchemaPath, outCommandConfigPath):
    schema = xpjsonAstrobee.loadDocument(inSchemaPath)
    specs = sorted(schema.commandSpecs, key=lambda c: c.id)

    categoryMap = {}
    for spec in specs:
        assert '.' in spec.id, 'CommandSpec without category: %s' % spec
        category, baseId = spec.id.split('.', 1)
        specsInCategory = categoryMap.setdefault(category, [])
        specsInCategory.append(getCommandConfig(spec))

    categories = sorted(categoryMap.keys())
    config = {
        'availableSubsystems': [{
            'name': c,
            'subsystemTypeName': c + 'Type'
        } for c in categories],
        'availableSubsystemTypes': [{
            'name': k + 'Type',
            'commands': categoryMap[k]
        } for k in categories]
    }
    # import json; print json.dumps(config, indent=4, sort_keys=True)
    table = luaTable.dumps(config)

    with open(outCommandConfigPath, 'w') as outStream:
        outStream.write(TEMPLATE_MAIN % {'table': table})
    logging.info('wrote command config Lua to %s', outCommandConfigPath)
Esempio n. 2
0
def genCommandNamesMsg(inSchemaPath, outCommandNamesPath):
    schema = xpjsonAstrobee.loadDocument(inSchemaPath)

    paramSpecs = sorted(schema.paramSpecs, key=lambda c: c.id)
    cmdSpecs = sorted(schema.commandSpecs, key=lambda c: c.id)

    seenCategories = {}
    declList = []

    for paramSpec in paramSpecs: 
        if not paramSpec.choices:
            continue
        for choiceCode, choiceLabel in paramSpec.choices:
            declList.append(TEMPLATE_PARAM_DECL % getParamContext(paramSpec, choiceCode, choiceLabel))

    declList.append('');

    for cmdSpec in cmdSpecs:
        category, _ = splitCommandCategory(cmdSpec)
        seenCategories[category] = True
        declList.append(TEMPLATE_DECL % getCommandContext(cmdSpec))

    declList.append('');

    for key in sorted(seenCategories.keys()):
        declList.append(TEMPLATE_SUBSYS_DECL % {
            'categoryAllCaps': xpjsonAstrobee.allCaps(key),
            'category': key,
        })

    decls = '\n'.join(declList)

    with open(outCommandNamesPath, 'w') as outStream:
        outStream.write(TEMPLATE_MAIN % {'decls': decls})
    logging.info('wrote ROS msg file declaring command name constants to %s', outCommandNamesPath)
Esempio n. 3
0
def genCommandTypes(inSchemaPath, commandTypesPath):
    schema = xpjsonAstrobee.loadDocument(inSchemaPath)

    paramSpecs = sorted(schema.paramSpecs, key=lambda spec: spec.id)

    for spec in paramSpecs:
        genParamDecls(spec, commandTypesPath)

    logging.info('wrote command types to %s', commandTypesPath)
Esempio n. 4
0
def genCommandConstants(inSchemaPath, outCommandConstantsPath):
    schema = xpjsonAstrobee.loadDocument(inSchemaPath)

    commandSpecs = sorted(schema.commandSpecs, key=lambda spec: spec.id)
    paramSpecs = sorted(schema.paramSpecs, key=lambda spec: spec.id)

    commandDecls = [genCommandSpecDecls(spec) for spec in commandSpecs]
    paramDecls = [genParamDecls(spec) for spec in paramSpecs]
    body = ''.join(commandDecls + paramDecls)

    with open(outCommandConstantsPath, 'w') as outStream:
        outStream.write(TEMPLATE_MAIN % {'body': body})
    logging.info('wrote command constants to %s', outCommandConstantsPath)
Esempio n. 5
0
def genCommandConstants(inSchemaPath, baseRobotImplPath):
    schema = xpjsonAstrobee.loadDocument(inSchemaPath)

    commandSpecs = sorted(schema.commandSpecs, key=lambda spec: spec.id)

    commandDecls = [genCommandSpecDecls(spec) for spec in commandSpecs]

    body = ''.join(commandDecls)

    filename = baseRobotImplPath + '/internal/BaseRobotImpl.java'

    with open(filename, 'w') as outStream:
        outStream.write(TEMPLATE_MAIN % {'body': body})
    logging.info('wrote base robot implementation to %s', filename)