api.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:openag_brain 作者: OpenAgInitiative 项目源码 文件源码
def get_topic_data(topic_name):
    """
    GET /api/<version>/topic_data/<topic_name>

    Get a single data point from a topic over HTTP.
    """
    topic_name = "/" + topic_name
    try:
        msg_class, real_topic, _ = rostopic.get_topic_class(topic_name)
    except rostopic.ROSTopicIOException as e:
        raise e
    if not real_topic:
        return error("Topic does not exist", 404)
    msg = rospy.wait_for_message(real_topic, msg_class)
    data = getattr(msg, "data", None)
    if data is None:
        json = '{"status": ['
        for x in msg.status:
            if x == msg.status[-1]:
                json += '{"name": \"%s\", "level": %d, "message": \"%s\", "hardware_id": \"%s\", "values": %s}]}' % \
                        (x.name if x.name else "null", x.level, \
                         x.message if x.message else "null", x.hardware_id if x.hardware_id else "null", \
                         x.values)
            else:
                json += '{"name": \"%s\", "level": %d, "message": \"%s\", "hardware_id": \"%s\", "values": %s},' % \
                        (x.name if x.name else "null", x.level, \
                         x.message if x.message else "null", x.hardware_id if x.hardware_id else "null", \
                         x.values)
        return Response(json, mimetype = 'application/json')
    else:
    return jsonify({"result": data})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号