# Path: imusim/behaviours/mac.py
# class MAC(object):
#     """
#     Base class for MAC implementations.
# 
#     @ivar radio: The L{Radio} used by the MAC.
#     @ivar timerMux: L{TimerMultiplexer} used by the MAC.
#     """
# 
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, radio, timerMux):
#         """
#         Initialise MAC.
# 
#         @param radio: The L{Radio} to be used by the MAC.
#         @param timerMux: L{TimerMultiplexer} to be used by the MAC.
#         """
#         self.radio = radio
#         self.timerMux = timerMux
# 
#         self.radio.setReceiveHandler(self.handleIncomingPacket)
# 
#     @abstractmethod
#     def queuePacket(self, packet):
#         """
#         Queue a packet for transmission
# 
#         @param packet: The L{RadioPacket} to transmit.
#         """
#         pass
# 
#     @abstractmethod
#     def handleIncomingPacket(self, packet):
#         """
#         Handle a received packet from the radio.
# 
#         @param packet: the received L{RadioPacket}.
#         """
#         pass
# 
# Path: imusim/behaviours/timing.py
# class VirtualTimer(object):
#     """
#     A virtual timer multiplexed to a hardware timer.
# 
#     Implements the same interface as L{Timer}.
# 
#     @ivar callback: Function to be called when timer fires.
#     """
#     def __init__(self, mux, callback=None):
#         """
#         Create virtual timer.
# 
#         @param mux: The L{TimerMultiplexer} implementing this timer.
#         """
#         self._period = None
#         self._mux = mux
#         self.callback = callback
#         self._mux._vtimers.append(self)
# 
#     @prepend_method_doc(Timer)
#     def start(self, period, repeat=False):
#         self._period = period
#         self._repeat = repeat
# 
#         if self._mux._inHandler:
#             # In timer event, handler is iterating through virtual timer list.
#             self._done = True
#             self._remaining = self._period
#         else:
#             self._done = False
#             if self._mux._period is None:
#                 # Timer off, this will become the only active virtual timer.
#                 self._remaining = self._period
#                 self._mux._period = self._period
#                 self._mux._timer.start(self._period, self._mux._timerHandler)
#             elif self._period < self._mux._period:
#                 # This timer will fire before any others.
#                 self._remaining = self._period
#                 elapsed = self._mux._timer.timeElapsed()
#                 for vtimer in self._mux._vtimers:
#                     if vtimer is not self and vtimer._period is not None:
#                         vtimer._remaining -= elapsed
#                 self._mux._period = self._period
#                 self._mux._timer.start(self._mux._period,
#                         self._mux._timerHandler)
#             elif self._period == self._mux._period:
#                 # This timer will fire at the same time as others.
#                 self._remaining = self._period
#             else:
#                 # Other timers will fire before this one.
#                 self._remaining = self._period + self._mux._timer.timeElapsed()
# 
#     @prepend_method_doc(Timer)
#     def clear(self):
#         self._period = None
# 
#     @prepend_method_doc(Timer)
#     def timeElapsed(self):
#         return (self._period - self._remaining) + self.mux._timer.timeElapsed()
# 
# Path: imusim/platforms/radios.py
# class RadioPacket(dict):
#     """
#     Class to represent a radio packet.
# 
#     Payload fields should be added as dictionary items.
# 
#     Metadata relevant to radio simulation should be added as attributes.
#     """
# 
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, *args, **kwargs):
#         dict.__init__(self, *args, **kwargs)
#         """
#         Construct a radio packet.
#         """
#         pass
# 
#     @abstractproperty
#     def bytes(self):
#         pass


from imusim.behaviours.mac import MAC
from imusim.behaviours.timing import VirtualTimer
from imusim.platforms.radios import RadioPacket
from imusim.maths.quaternions import Quaternion
from imusim.utilities.documentation import prepend_method_doc
import numpy as np
            data = self[key]
            if isinstance(data, Quaternion):
                size += array(data.components).nbytes
            elif isinstance(data, numpy.ndarray):
                size += data.nbytes
        return size

class AuxPacket(DataPacket):
    """
    Auxillary packet from slave to slave.

    @ivar source: Source device ID.
    @ivar dest: Destination device ID.
    """
    def __init__(self, source, dest, data):
        """
        Initialise auxillary packet.

        @param source: Source device ID.
        @param dest: Destination device ID.
        @param data: Payload data.
        """
        DataPacket.__init__(self, source, data)
        self.dest = dest

class MasterMAC(MAC):
    """
    Master MAC implementation.
    """


# Path: imusim/behaviours/mac.py
# class MAC(object):
#     """
#     Base class for MAC implementations.
# 
#     @ivar radio: The L{Radio} used by the MAC.
#     @ivar timerMux: L{TimerMultiplexer} used by the MAC.
#     """
# 
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, radio, timerMux):
#         """
#         Initialise MAC.
# 
#         @param radio: The L{Radio} to be used by the MAC.
#         @param timerMux: L{TimerMultiplexer} to be used by the MAC.
#         """
#         self.radio = radio
#         self.timerMux = timerMux
# 
#         self.radio.setReceiveHandler(self.handleIncomingPacket)
# 
#     @abstractmethod
#     def queuePacket(self, packet):
#         """
#         Queue a packet for transmission
# 
#         @param packet: The L{RadioPacket} to transmit.
#         """
#         pass
# 
#     @abstractmethod
#     def handleIncomingPacket(self, packet):
#         """
#         Handle a received packet from the radio.
# 
#         @param packet: the received L{RadioPacket}.
#         """
#         pass
# 
# Path: imusim/behaviours/timing.py
# class VirtualTimer(object):
#     """
#     A virtual timer multiplexed to a hardware timer.
# 
#     Implements the same interface as L{Timer}.
# 
#     @ivar callback: Function to be called when timer fires.
#     """
#     def __init__(self, mux, callback=None):
#         """
#         Create virtual timer.
# 
#         @param mux: The L{TimerMultiplexer} implementing this timer.
#         """
#         self._period = None
#         self._mux = mux
#         self.callback = callback
#         self._mux._vtimers.append(self)
# 
#     @prepend_method_doc(Timer)
#     def start(self, period, repeat=False):
#         self._period = period
#         self._repeat = repeat
# 
#         if self._mux._inHandler:
#             # In timer event, handler is iterating through virtual timer list.
#             self._done = True
#             self._remaining = self._period
#         else:
#             self._done = False
#             if self._mux._period is None:
#                 # Timer off, this will become the only active virtual timer.
#                 self._remaining = self._period
#                 self._mux._period = self._period
#                 self._mux._timer.start(self._period, self._mux._timerHandler)
#             elif self._period < self._mux._period:
#                 # This timer will fire before any others.
#                 self._remaining = self._period
#                 elapsed = self._mux._timer.timeElapsed()
#                 for vtimer in self._mux._vtimers:
#                     if vtimer is not self and vtimer._period is not None:
#                         vtimer._remaining -= elapsed
#                 self._mux._period = self._period
#                 self._mux._timer.start(self._mux._period,
#                         self._mux._timerHandler)
#             elif self._period == self._mux._period:
#                 # This timer will fire at the same time as others.
#                 self._remaining = self._period
#             else:
#                 # Other timers will fire before this one.
#                 self._remaining = self._period + self._mux._timer.timeElapsed()
# 
#     @prepend_method_doc(Timer)
#     def clear(self):
#         self._period = None
# 
#     @prepend_method_doc(Timer)
#     def timeElapsed(self):
#         return (self._period - self._remaining) + self.mux._timer.timeElapsed()
# 
# Path: imusim/platforms/radios.py
# class RadioPacket(dict):
#     """
#     Class to represent a radio packet.
# 
#     Payload fields should be added as dictionary items.
# 
#     Metadata relevant to radio simulation should be added as attributes.
#     """
# 
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, *args, **kwargs):
#         dict.__init__(self, *args, **kwargs)
#         """
#         Construct a radio packet.
#         """
#         pass
# 
#     @abstractproperty
#     def bytes(self):
#         pass


# Path: imusim/behaviours/orient_tdma.py
from imusim.behaviours.mac import MAC
from imusim.behaviours.timing import VirtualTimer
from imusim.platforms.radios import RadioPacket
from imusim.maths.quaternions import Quaternion
from imusim.utilities.documentation import prepend_method_doc
import numpy as np

            data = self[key]
            if isinstance(data, Quaternion):
                size += array(data.components).nbytes
            elif isinstance(data, numpy.ndarray):
                size += data.nbytes
        return size

class AuxPacket(DataPacket):
    """
    Auxillary packet from slave to slave.

    @ivar source: Source device ID.
    @ivar dest: Destination device ID.
    """
    def __init__(self, source, dest, data):
        """
        Initialise auxillary packet.

        @param source: Source device ID.
        @param dest: Destination device ID.
        @param data: Payload data.
        """
        DataPacket.__init__(self, source, data)
        self.dest = dest

class MasterMAC(MAC):
    """
    Master MAC implementation.
    """


    @prepend_method_doc(MAC)