예제 #1
0
def handle_node_event(node_data: NodeData) -> core_pb2.Event:
    """
    Handle node event when there is a node event

    :param node_data: node data
    :return: node event that contains node id, name, model, position, and services
    """
    node = node_data.node
    x, y, _ = node.position.get()
    position = core_pb2.Position(x=x, y=y)
    lon, lat, alt = node.position.get_geo()
    geo = core_pb2.Geo(lon=lon, lat=lat, alt=alt)
    services = [x.name for x in node.services]
    node_proto = core_pb2.Node(
        id=node.id,
        name=node.name,
        model=node.type,
        icon=node.icon,
        position=position,
        geo=geo,
        services=services,
    )
    message_type = node_data.message_type.value
    node_event = core_pb2.NodeEvent(message_type=message_type, node=node_proto)
    return core_pb2.Event(node_event=node_event, source=node_data.source)
예제 #2
0
파일: server.py 프로젝트: yanhc519/core
 def _handle_node_event(self, event):
     position = core_pb2.Position(x=event.x_position, y=event.y_position)
     services = event.services or ""
     services = services.split("|")
     node_proto = core_pb2.Node(id=event.id,
                                name=event.name,
                                model=event.model,
                                position=position,
                                services=services)
     return core_pb2.NodeEvent(node=node_proto)
예제 #3
0
def handle_node_event(event: NodeData) -> core_pb2.NodeEvent:
    """
    Handle node event when there is a node event

    :param event: node data
    :return: node event that contains node id, name, model, position, and services
    """
    position = core_pb2.Position(x=event.x_position, y=event.y_position)
    node_proto = core_pb2.Node(
        id=event.id,
        name=event.name,
        model=event.model,
        position=position,
        services=event.services,
    )
    return core_pb2.NodeEvent(node=node_proto, source=event.source)
예제 #4
0
def handle_node_event(event):
    """
    Handle node event when there is a node event

    :param core.emulator.data.NodeData event: node data
    :return: node event that contains node id, name, model, position, and services
    :rtype: core.api.grpc.core_pb2.NodeEvent
    """
    position = core_pb2.Position(x=event.x_position, y=event.y_position)
    services = event.services or ""
    services = services.split("|")
    node_proto = core_pb2.Node(
        id=event.id,
        name=event.name,
        model=event.model,
        position=position,
        services=services,
    )
    return core_pb2.NodeEvent(node=node_proto, source=event.source)