def __init__(self, arguments, thread_manager, location_callback, receive_callback, valid_callback): """ Initialize the RF sensor. The `arguments` parameter is used to load settings for a specific RF sensor type. The sensor has a `thread_manager`, which is a `Thread_Manager` object for registering its own thread loop. Additionally, it requires certian callbacks. The `location_callback` is called whenever the sensor needs to know its own location for the "rssi_broadcast" and the "rssi_ground_station" private packets. The `receive_callback` is called whenever non-private packets are received and has the `Packet` object as an argument. Finally, the `valid_callback` is called shortly after the `location_callback` is called. It may be given a boolean argument indicating whether another RF sensor has a valid location, but only when creating the "rssi_ground_station" private packet. This is used by the callback to determine if measurements at a certain location are finished. Classes that inherit this base class may extend this method. """ super(RF_Sensor, self).__init__("rf_sensor", thread_manager) # Make sure that the provided callbacks are callable. for callback in [location_callback, receive_callback, valid_callback]: if not hasattr(callback, "__call__"): raise TypeError("Provided RF sensor callback is not callable") # Load settings for a specific RF sensor type. if isinstance(arguments, Arguments): self._settings = arguments.get_settings(self.type) else: raise ValueError("'arguments' must be an instance of Arguments") # Initialize common member variables. self._id = self._settings.get("rf_sensor_id") self._number_of_sensors = self._settings.get("number_of_sensors") self._address = None self._connection = None self._buffer = None self._scheduler = TDMA_Scheduler(self._id, arguments) self._packets = [] self._queue = Queue.Queue() self._joined = False self._activated = False self._started = False self._loop_delay = self._settings.get("loop_delay") self._location_callback = location_callback self._receive_callback = receive_callback self._valid_callback = valid_callback