def __init__(self, device_name, sample_rate, channel_mapping): self.__device_name = device_name self.__sample_rate = sample_rate self.__signal_type = SignalType( # TODO: type should be able to be LSB kind='IQ' if len(channel_mapping) == 2 else 'USB', sample_rate=self.__sample_rate) gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(0, 0, 0), ) sink = audio.sink(self.__sample_rate, device_name=self.__device_name, ok_to_block=True) # TODO: ignoring channel_mapping parameter, shouldn't be split = blocks.complex_to_float(1) self.connect(self, split, (sink, 0)) self.connect((split, 1), (sink, 1))
def get_output_type(self): return SignalType(kind='IQ', sample_rate=self.__rf_rate)
def get_input_type(self): return SignalType(kind='MONO', sample_rate=self.__audio_rate)
def get_output_type(self): return SignalType(kind='MONO', sample_rate=pipe_rate)
def get_output_type(self): """implement IDemodulator""" return SignalType(kind='MONO', sample_rate=self.__demod_rate)
def __init__(self, name): gr.hier_block2.__init__( self, name, gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) rf_rate = self.rf_rate audio_rate = self.audio_rate self.__noise_level = -22 self.__transmitters = CellDict(dynamic=True) self.__transmitters_cs = CollectionState(self.__transmitters) self.__bus = blocks.add_vcc(1) self.__channel_model = channels.channel_model( noise_voltage=dB(self.__noise_level), frequency_offset=0, epsilon=1.01, # TODO: expose this parameter # taps=..., # TODO: apply something here? ) self.__rotator = blocks.rotator_cc() self.__throttle = blocks.throttle(gr.sizeof_gr_complex, rf_rate) self.connect(self.__bus, self.__throttle, self.__channel_model, self.__rotator, self) signals = [] def add_modulator(freq, key, mode_or_modulator_ctor, **kwargs): if isinstance(mode_or_modulator_ctor, type): mode = None ctor = mode_or_modulator_ctor else: mode = mode_or_modulator_ctor mode_def = lookup_mode(mode) if mode_def is None: # missing plugin, say return ctor = mode_def.mod_class context = None # TODO implement context modulator = ctor(context=context, mode=mode, **kwargs) tx = _SimulatedTransmitter(modulator, audio_rate, rf_rate, freq) self.connect(audio_signal, tx) signals.append(tx) self.__transmitters[key] = tx # Audio input signal pitch = analog.sig_source_f(audio_rate, analog.GR_SAW_WAVE, -1, 2000, 1000) audio_signal = vco = blocks.vco_f(audio_rate, 1, 1) self.connect(pitch, vco) # Channels add_modulator(0.0, 'usb', 'USB') add_modulator(10e3, 'am', 'AM') add_modulator(30e3, 'fm', 'NFM') add_modulator(-30e3, 'vor1', 'VOR', angle=0) add_modulator(-60e3, 'vor2', 'VOR', angle=math.pi / 2) add_modulator( 50e3, 'rtty', 'RTTY', message='The quick brown fox jumped over the lazy dog.\n') add_modulator(80e3, 'chirp', ChirpModulator) bus_input = 0 for signal in signals: self.connect(signal, (self.__bus, bus_input)) bus_input = bus_input + 1 self.__signal_type = SignalType(kind='IQ', sample_rate=rf_rate) self.__usable_bandwidth = RangeT([(-rf_rate / 2, rf_rate / 2)])
def __init__(self, devices={}, audio_config=None, features=_STUB_FEATURES): # pylint: disable=dangerous-default-value if len(devices) <= 0: raise ValueError('Must have at least one RF device') gr.top_block.__init__(self, type(self).__name__) 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 = CellDict({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()} for key in self._sources: # arbitrary valid initial value self.source_name = key break self.__rx_device_type = EnumT({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().subscribe2(self.__start_or_stop_later, the_subscription_context) self.__clip_probe = MaxProbe() # Receiver blocks (multiple, eventually) self._receivers = CellDict(dynamic=True) self._receiver_valid = {} # collections # TODO: No longer necessary to have these non-underscore names self.sources = CollectionState(CellDict(self._sources)) self.receivers = ReceiverCollection(self._receivers, self) self.accessories = CollectionState(CellDict(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 = {} # Initialization def hookup_vfo_callback(k, d): # function so as to not close over loop variable d.get_vfo_cell().subscribe2(lambda value: self.__device_vfo_callback(k), the_subscription_context) for k, d in devices.iteritems(): hookup_vfo_callback(k, d) self._do_connect()
def test_sample_rate(self): self.assertIsInstance(SignalType(kind='IQ', sample_rate=1).get_sample_rate(), float) self.assertIsInstance(no_signal.get_sample_rate(), float) self.assertEqual(123, SignalType(kind='IQ', sample_rate=123).get_sample_rate()) self.assertEqual(0, no_signal.get_sample_rate())
def test_constants(self): self.assertEqual( no_signal, SignalType(kind='NONE', sample_rate=0))
def test_validation(self): self.assertRaises(TypeError, lambda: SignalType(kind='NONE', sample_rate=None)) self.assertRaises(ValueError, lambda: SignalType(kind='NONE', sample_rate=0.1)) self.assertRaises(ValueError, lambda: SignalType(kind='FOO', sample_rate=1.0)) self.assertRaises(ValueError, lambda: SignalType(kind='IQ', sample_rate=-1.0)) self.assertRaises(ValueError, lambda: SignalType(kind='IQ', sample_rate=0.0))
def make(self, kind='IQ'): signal_type = SignalType(kind=kind, sample_rate=1000) m = MonitorSink(context=self.context, signal_type=signal_type) self.tb.connect(blocks.null_source(signal_type.get_itemsize()), m) return m
def get_input_type(self): return SignalType(kind='IQ', sample_rate=10000)
def get_input_type(self): return SignalType('IQ', 1)
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()