# Path: houston/connection.py
# class Message(object):
#     """
#     Base class used by all messages.
#     """
# 
# class Connection(Generic[T]):
#     """
#     Provides a connection to the system under test using a given protocol.
#     """
#     def __init__(self, hooks: Dict[str, Callable[[T], None]]) -> None:
#         """
#         Establishes a new connection.
# 
#         Parameters:
#             hooks: A dictionary of string (name of the hook) to callables
#                 that should be callednupon receiving a message via this
#                 connection.
#         """
#         self.__lock = threading.Lock()
#         self.__hooks = hooks if hooks else {}
# 
#     def receive(self, message: T) -> None:
#         """
#         Forwards any received messages using the hooks attached to this
#         connection.
#         """
#         with self.__lock:
#             for hook in self.__hooks.values():
#                 hook(message)
# 
#     def send(self, message: T) -> None:
#         """
#         Attempts to send a given message to the system under test.
#         """
#         raise NotImplementedError
# 
#     def close(self) -> None:
#         """
#         Closes the connection if open.
#         """
#         raise NotImplementedError
# 
#     def add_hooks(self, hooks: Dict[str, Callable[[T], None]]) -> None:
#         """
#         Adds a dictionary of hooks to the set of hooks to be called
#         when messages are received.
#         """
#         with self.__lock:
#             self.__hooks.update(hooks)
# 
#     def remove_hook(self, hook_name: str) -> None:
#         """
#         Removes a hook from hooks based on its name.
#         """
#         with self.__lock:
#             if hook_name in self.__hooks:
#                 self.__hooks.pop(hook_name)


import logging
import pymavlink
import attr
import dronekit
from typing import Any, List, Callable, Dict
from pymavlink.mavutil import mavlink
from ..connection import Message, Connection

    def to_dronekit_command(self,
                            frame: int = mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
                            ) -> dronekit.Command:
        cmd = dronekit.Command(self.target_system,
                               self.target_component,
                               0,  # Sequence number automatically saved
                               frame,
                               self.cmd_id,
                               0,  # current (not supported)
                               0,  # autocontinue (not supported)
                               self.param_1,
                               self.param_2,
                               self.param_3,
                               self.param_4,
                               self.param_5,
                               self.param_6,
                               self.param_7)
        return cmd


@attr.s(frozen=True)
class MAVLinkMessage(MAVLinkGeneralMessage):
    name = attr.ib(type=str)
    message = attr.ib(type=Any)  # FIXME MAVLink message type


HOOK_TYPE = Dict[str, Callable[[MAVLinkGeneralMessage], None]]



# Path: houston/connection.py
# class Message(object):
#     """
#     Base class used by all messages.
#     """
# 
# class Connection(Generic[T]):
#     """
#     Provides a connection to the system under test using a given protocol.
#     """
#     def __init__(self, hooks: Dict[str, Callable[[T], None]]) -> None:
#         """
#         Establishes a new connection.
# 
#         Parameters:
#             hooks: A dictionary of string (name of the hook) to callables
#                 that should be callednupon receiving a message via this
#                 connection.
#         """
#         self.__lock = threading.Lock()
#         self.__hooks = hooks if hooks else {}
# 
#     def receive(self, message: T) -> None:
#         """
#         Forwards any received messages using the hooks attached to this
#         connection.
#         """
#         with self.__lock:
#             for hook in self.__hooks.values():
#                 hook(message)
# 
#     def send(self, message: T) -> None:
#         """
#         Attempts to send a given message to the system under test.
#         """
#         raise NotImplementedError
# 
#     def close(self) -> None:
#         """
#         Closes the connection if open.
#         """
#         raise NotImplementedError
# 
#     def add_hooks(self, hooks: Dict[str, Callable[[T], None]]) -> None:
#         """
#         Adds a dictionary of hooks to the set of hooks to be called
#         when messages are received.
#         """
#         with self.__lock:
#             self.__hooks.update(hooks)
# 
#     def remove_hook(self, hook_name: str) -> None:
#         """
#         Removes a hook from hooks based on its name.
#         """
#         with self.__lock:
#             if hook_name in self.__hooks:
#                 self.__hooks.pop(hook_name)


# Path: houston/ardu/connection.py
import logging
import pymavlink
import attr
import dronekit
from typing import Any, List, Callable, Dict
from pymavlink.mavutil import mavlink
from ..connection import Message, Connection


    def to_dronekit_command(self,
                            frame: int = mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
                            ) -> dronekit.Command:
        cmd = dronekit.Command(self.target_system,
                               self.target_component,
                               0,  # Sequence number automatically saved
                               frame,
                               self.cmd_id,
                               0,  # current (not supported)
                               0,  # autocontinue (not supported)
                               self.param_1,
                               self.param_2,
                               self.param_3,
                               self.param_4,
                               self.param_5,
                               self.param_6,
                               self.param_7)
        return cmd


@attr.s(frozen=True)
class MAVLinkMessage(MAVLinkGeneralMessage):
    name = attr.ib(type=str)
    message = attr.ib(type=Any)  # FIXME MAVLink message type


HOOK_TYPE = Dict[str, Callable[[MAVLinkGeneralMessage], None]]



class MAVLinkConnection(Connection[MAVLinkGeneralMessage]):