Пример #1
0
    def __init__(self, devices={}, audio_config=None, features=_stub_features):
        if len(devices) <= 0:
            raise ValueError('Must have at least one RF device')
        
        gr.top_block.__init__(self, "SDR top block")
        self.__running = False  # duplicate of GR state we can't reach, see __start_or_stop
        self.__has_a_useful_receiver = False

        # Configuration
        # TODO: device refactoring: Remove vestigial 'accessories'
        self._sources = {k: d for k, d in devices.iteritems() if d.can_receive()}
        self._accessories = accessories = {k: d for k, d in devices.iteritems() if not d.can_receive()}
        self.source_name = self._sources.keys()[0]  # arbitrary valid initial value
        self.__rx_device_type = Enum({k: v.get_name() or k for (k, v) in self._sources.iteritems()})
        
        # Audio early setup
        self.__audio_manager = AudioManager(  # must be before contexts
            graph=self,
            audio_config=audio_config,
            stereo=features['stereo'])

        # Blocks etc.
        # TODO: device refactoring: remove 'source' concept (which is currently a device)
        # TODO: remove legacy no-underscore names, maybe get rid of self.source
        self.source = None
        self.__monitor_rx_driver = None
        self.monitor = MonitorSink(
            signal_type=SignalType(sample_rate=10000, kind='IQ'),  # dummy value will be updated in _do_connect
            context=Context(self))
        self.monitor.get_interested_cell().subscribe(self.__start_or_stop_later)
        self.__clip_probe = MaxProbe()
        
        # Receiver blocks (multiple, eventually)
        self._receivers = {}
        self._receiver_valid = {}
        
        # collections
        # TODO: No longer necessary to have these non-underscore names
        self.sources = CollectionState(self._sources)
        self.receivers = ReceiverCollection(self._receivers, self)
        self.accessories = CollectionState(accessories)
        self.__telemetry_store = TelemetryStore()
        
        # Flags, other state
        self.__needs_reconnect = [u'initialization']
        self.__in_reconnect = False
        self.receiver_key_counter = 0
        self.receiver_default_state = {}
        self.__cpu_calculator = LazyRateCalculator(lambda: time.clock())
        
        # Initialization
        
        def hookup_vfo_callback(k, d):  # function so as to not close over loop variable
            d.get_vfo_cell().subscribe(lambda: self.__device_vfo_callback(k))
        
        for k, d in devices.iteritems():
            hookup_vfo_callback(k, d)
        
        self._do_connect()
Пример #2
0
    def __init__(self, devices={}, audio_config=None, stereo=True):
        if not len(devices) > 0:
            raise ValueError('Must have at least one RF device')
        #for key, audio_device in audio_devices.iteritems():
        #    if key == CLIENT_AUDIO_DEVICE:
        #        raise ValueError('The name %r for an audio device is reserved' % (key,))
        #    if not audio_device.can_transmit():
        #        raise ValueError('Audio device %r is not an output' % (key,))
        if audio_config is not None:
            # quick kludge placeholder -- currently a Device-device can't be stereo so we have a placeholder thing
            audio_device_name, audio_sample_rate = audio_config
            audio_devices = {
                'server': (audio_sample_rate,
                           audio.sink(audio_sample_rate, audio_device_name,
                                      False))
            }
        else:
            audio_devices = {}

        gr.top_block.__init__(self, "SDR top block")
        self.__unpaused = True  # user state
        self.__running = False  # actually started

        # Configuration
        # TODO: device refactoring: Remove vestigial 'accessories'
        self._sources = {
            k: d
            for k, d in devices.iteritems() if d.can_receive()
        }
        accessories = {
            k: d
            for k, d in devices.iteritems() if not d.can_receive()
        }
        self.source_name = self._sources.keys()[
            0]  # arbitrary valid initial value

        # Audio early setup
        self.__audio_devices = audio_devices  # must be before contexts

        # Blocks etc.
        # TODO: device refactoring: remove 'source' concept (which is currently a device)
        self.source = None
        self.__rx_driver = None
        self.__source_tune_subscription = None
        self.monitor = MonitorSink(
            signal_type=SignalType(
                sample_rate=10000,
                kind='IQ'),  # dummy value will be updated in _do_connect
            context=Context(self))
        self.__clip_probe = MaxProbe()

        # Receiver blocks (multiple, eventually)
        self._receivers = {}
        self._receiver_valid = {}

        self.__shared_objects = {}

        # kludge for using collection like block - TODO: better architecture
        self.sources = CollectionState(self._sources)
        self.receivers = ReceiverCollection(self._receivers, self)
        self.accessories = CollectionState(accessories)
        # TODO: better name than "shared objects"
        self.shared_objects = CollectionState(self.__shared_objects,
                                              dynamic=True)

        # Audio stream bits
        audio_destination_dict = {
            key: 'Server' or key
            for key, device in audio_devices.iteritems()
        }  # temp name till we have proper device objects
        audio_destination_dict[
            CLIENT_AUDIO_DEVICE] = 'Client'  # TODO reconsider name
        self.__audio_destination_type = Enum(audio_destination_dict,
                                             strict=True)
        self.__audio_channels = 2 if stereo else 1
        self.audio_queue_sinks = {}
        self.__audio_buses = {
            key: BusPlumber(self, self.__audio_channels)
            for key in audio_destination_dict
        }

        # Flags, other state
        self.__needs_reconnect = True
        self.input_rate = None
        self.input_freq = None
        self.receiver_key_counter = 0
        self.receiver_default_state = {}
        self.last_wall_time = time.time()
        self.last_cpu_time = time.clock()
        self.last_cpu_use = 0

        self._do_connect()