示例#1
0
def getParamContext(param, code, label):
    assert '.' in param.id, 'ParamSpec without category: %s' % param
    category, baseId = param.id.split('.', 1)
    return {
        'baseIdAllCaps': xpjsonAstrobee.allCaps(baseId),
        'choiceLabelAllCaps': xpjsonAstrobee.allCaps(label),
        'choiceCode': code,
    }
示例#2
0
def getCommandContext(cmd):
    category, baseId = splitCommandCategory(cmd)
    return {
        'categoryAllCaps': xpjsonAstrobee.allCaps(category),
        'baseId': baseId,
        'baseIdAllCaps': xpjsonAstrobee.allCaps(baseId),
        'fullId': cmd.id,
    }
示例#3
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)
示例#4
0
def getParamContext(param):
    if '.' in param.id:
        category, baseId = param.id.split('.', 1)
    else:
        category, baseId = None, param.id
    result = {
        'paramId':
        xpjsonAstrobee.fixName(baseId),
        'paramIdAllCaps':
        xpjsonAstrobee.allCaps(xpjsonAstrobee.fixName(baseId)),
        'paramValueTypeRapid':
        xpjsonAstrobee.XPJSON_PARAM_VALUE_TYPE_MAPPINGS[param.valueType],
    }
    if category is not None:
        result['paramCategoryAllCaps'] = xpjsonAstrobee.allCaps(category)
    return result
示例#5
0
def getCommandContext(cmd):
    assert '.' in cmd.id, 'CommandSpec without category: %s' % cmd
    category, baseId = cmd.id.split('.', 1)
    return {
        'commandId': baseId,
        'commandIdAllCaps': xpjsonAstrobee.allCaps(baseId),
        'commandCategoryUpper': category.upper(),
    }
示例#6
0
def getChoiceContext(choiceCode):
    capChoiceCode = choiceCode
    if choiceCode[0] >= '0' and choiceCode[0] <= '9':
        capChoiceCode = 'r' + choiceCode
    return {
        'choiceCode': choiceCode,
        'choiceCodeAllCaps': xpjsonAstrobee.allCaps(capChoiceCode),
    }
示例#7
0
def getChoiceContext(choiceCode, choiceLabel):
    return {
        'choiceCode': choiceCode,
        'choiceLabelAllCaps': xpjsonAstrobee.allCaps(choiceLabel),
    }