class UdpNmeaProtocol(asyncio.DatagramProtocol):
    def __init__(self, component_id: int) -> None:
        self.mavlink2rest = MavlinkMessenger()
        self.mavlink2rest.set_component_id(component_id)

    def connection_made(self, transport: asyncio.BaseTransport) -> None:
        """Behavior when a new connection is stablished."""
        logger.debug(
            f"New UDP connection with {transport.get_extra_info('peername')}.")
        self.transport = transport

    def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None:
        """What happens when data is received from a client socket."""
        message = data.decode()
        logger.info(
            f"Message received for component {self.mavlink2rest.component_id}: {message}"
        )
        mavlink_package = TrafficController.parse_mavlink_package(message)
        asyncio.create_task(
            TrafficController.forward_message(mavlink_package,
                                              self.mavlink2rest))
        logger.info("Successfully forwarded mavlink coordinates package.")
 def forward_message(message: MavlinkGpsInput, component_id: int) -> None:
     """Forward Mavlink message package to Mavlink2Rest, on the specified component ID."""
     mavlink2rest = MavlinkMessenger()
     mavlink2rest.set_component_id(component_id)
     mavlink2rest.send_mavlink_message(message.dict())