def __make_demodulator(self, mode, state): '''Returns the demodulator.''' t0 = time.time() mode_def = lookup_mode(mode) if mode_def is None: # TODO: Better handling, like maybe a dummy demod raise ValueError('Unknown mode: ' + mode) clas = mode_def.demod_class state = state.copy() # don't modify arg if 'mode' in state: del state['mode'] # don't switch back to the mode we just switched from facet = ContextForDemodulator(self) init_kwargs = dict( mode=mode, input_rate=self.__get_device().get_rx_driver().get_output_type().get_sample_rate(), context=facet) demodulator = unserialize_exported_state( ctor=clas, state=state, kwargs=init_kwargs) # until _enabled, ignore any callbacks resulting from unserialization calling setters facet._enabled = True log.msg('Constructed %s demodulator: %i ms.' % (mode, (time.time() - t0) * 1000)) return demodulator
def __make_demodulator(self, mode, state): """Returns the demodulator.""" t0 = time.time() mode_def = lookup_mode(mode) if mode_def is None: # TODO: Better handling, like maybe a dummy demod raise ValueError('Unknown mode: ' + mode) clas = mode_def.demod_class state = state.copy() # don't modify arg if 'mode' in state: del state[ 'mode'] # don't switch back to the mode we just switched from facet = ContextForDemodulator(self) init_kwargs = dict(mode=mode, input_rate=self.__get_device().get_rx_driver(). get_output_type().get_sample_rate(), context=facet) demodulator = unserialize_exported_state(ctor=clas, state=state, kwargs=init_kwargs) # until _enabled, ignore any callbacks resulting from unserialization calling setters facet._enabled = True log.msg('Constructed %s demodulator: %i ms.' % (mode, (time.time() - t0) * 1000)) return demodulator
def __make_demodulator(self, mode, state): '''Returns the demodulator.''' mode_def = lookup_mode(mode) if mode_def is None: # TODO: Better handling, like maybe a dummy demod raise ValueError('Unknown mode: ' + mode) clas = mode_def.demod_class state = state.copy() # don't modify arg if 'mode' in state: del state[ 'mode'] # don't switch back to the mode we just switched from facet = ContextForDemodulator(self) init_kwargs = dict(mode=mode, input_rate=self.input_rate, context=facet) for sh_key, sh_ctor in mode_def.shared_objects.iteritems(): init_kwargs[sh_key] = self.context.get_shared_object(sh_ctor) demodulator = unserialize_exported_state(ctor=clas, state=state, kwargs=init_kwargs) # until _enabled, ignore any callbacks resulting from unserialization calling setters facet._enabled = True return demodulator
def __make_demodulator(self, mode, state): """Returns the demodulator.""" t0 = time.time() mode_def = lookup_mode(mode) if mode_def is None: # TODO: Better handling, like maybe a dummy demod raise ValueError("Unknown mode: " + mode) clas = mode_def.demod_class state = state.copy() # don't modify arg if "mode" in state: del state["mode"] # don't switch back to the mode we just switched from facet = ContextForDemodulator(self) init_kwargs = dict( mode=mode, input_rate=self.__get_device().get_rx_driver().get_output_type().get_sample_rate(), context=facet ) for sh_key, sh_ctor in mode_def.shared_objects.iteritems(): init_kwargs[sh_key] = self.context.get_shared_object(sh_ctor) demodulator = unserialize_exported_state(ctor=clas, state=state, kwargs=init_kwargs) # until _enabled, ignore any callbacks resulting from unserialization calling setters facet._enabled = True log.msg("Constructed %s demodulator: %i ms." % (mode, (time.time() - t0) * 1000)) return demodulator
def __make_demodulator(self, mode, state): '''Returns the demodulator.''' mode_def = lookup_mode(mode) if mode_def is None: # TODO: Better handling, like maybe a dummy demod raise ValueError('Unknown mode: ' + mode) clas = mode_def.demod_class state = state.copy() # don't modify arg if 'mode' in state: del state['mode'] # don't switch back to the mode we just switched from facet = ContextForDemodulator(self) init_kwargs = dict( mode=mode, input_rate=self.input_rate, context=facet) for sh_key, sh_ctor in mode_def.shared_objects.iteritems(): init_kwargs[sh_key] = self.context.get_shared_object(sh_ctor) demodulator = unserialize_exported_state( ctor=clas, state=state, kwargs=init_kwargs) # until _enabled, ignore any callbacks resulting from unserialization calling setters facet._enabled = True return demodulator
def __init__(self, mode, input_rate=0, input_center_freq=0, rec_freq=100.0, audio_destination=None, audio_gain=-6, audio_pan=0, audio_channels=0, context=None): assert input_rate > 0 assert audio_channels == 1 or audio_channels == 2 assert audio_destination is not None gr.hier_block2.__init__( # str() because insists on non-unicode self, str('%s receiver' % (mode, )), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(audio_channels, audio_channels, gr.sizeof_float * 1), ) if lookup_mode(mode) is None: # TODO: communicate back to client if applicable log.msg('Unknown mode %r in Receiver(); using AM' % (mode, )) mode = 'AM' # Provided by caller self.context = context self.input_rate = input_rate self.input_center_freq = input_center_freq self.__audio_channels = audio_channels # Simple state self.mode = mode self.rec_freq = rec_freq self.audio_gain = audio_gain self.audio_pan = min(1, max(-1, audio_pan)) self.__audio_destination = audio_destination # Blocks self.__rotator = blocks.rotator_cc() self.demodulator = self.__make_demodulator(mode, {}) self.__update_demodulator_info() self.__audio_gain_blocks = [ blocks.multiply_const_ff(0.0) for _ in xrange(self.__audio_channels) ] self.probe_audio = analog.probe_avg_mag_sqrd_f( 0, alpha=10.0 / 44100) # TODO adapt to output audio rate # Other internals self.__last_output_type = None self.__update_rotator( ) # initialize rotator, also in case of __demod_tunable self.__update_audio_gain() self.__do_connect()
def add_modulator(freq, key, mode, **kwargs): mode_def = lookup_mode(mode) if mode_def is None: # missing plugin, say return modulator = mode_def.mod_class(**kwargs) tx = _SimulatedTransmitter(modulator, audio_rate, rf_rate, freq) self.connect(audio_signal, tx) signals.append(tx) self._transmitters[key] = tx
def __init__( self, mode, rec_freq=100.0, audio_destination=None, device_name=None, audio_gain=-6, audio_pan=0, audio_channels=0, context=None, ): assert audio_channels == 1 or audio_channels == 2 assert audio_destination is not None assert device_name is not None gr.hier_block2.__init__( # str() because insists on non-unicode self, str("%s receiver" % (mode,)), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(audio_channels, audio_channels, gr.sizeof_float * 1), ) if lookup_mode(mode) is None: # TODO: communicate back to client if applicable log.msg("Unknown mode %r in Receiver(); using AM" % (mode,)) mode = "AM" # Provided by caller self.context = context self.__audio_channels = audio_channels # cached info from device self.__device_name = device_name # Simple state self.mode = mode self.rec_freq = rec_freq self.audio_gain = audio_gain self.audio_pan = min(1, max(-1, audio_pan)) self.__audio_destination = audio_destination # Blocks self.__rotator = blocks.rotator_cc() self.__demodulator = self.__make_demodulator(mode, {}) self.__update_demodulator_info() self.__audio_gain_blocks = [blocks.multiply_const_ff(0.0) for _ in xrange(self.__audio_channels)] self.probe_audio = analog.probe_avg_mag_sqrd_f(0, alpha=10.0 / 44100) # TODO adapt to output audio rate # Other internals self.__last_output_type = None self.__update_rotator() # initialize rotator, also in case of __demod_tunable self.__update_audio_gain() self.__do_connect(reason=u"initialization")
def __init__(self, mode, state=None): # TODO: Refactor things so that we can take the demod ctor rather than a mode string if state is None: state = {} mode_def = lookup_mode(mode) if mode_def is None: raise Exception('No such mode is registered: ' + repr(mode)) # TODO: Tell the simulated device to have no modulators, or have a simpler dummy source for testing, so we don't waste time on setup self.__top = Top(devices={'s1': SimulatedDevice()}) (_, receiver) = self.__top.add_receiver(mode, key='a', state=state) self.__demodulator = receiver.get_demodulator() if not isinstance(self.__demodulator, mode_def.demod_class): raise Exception('Demodulator not of expected class: ' + repr(self.__demodulator)) self.__top.start() # TODO overriding internals
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
def __init__(self, mode, freq_absolute=100.0, freq_relative=None, freq_linked_to_device=False, audio_destination=None, device_name=None, audio_gain=-6, audio_pan=0, audio_channels=0, context=None): assert audio_channels == 1 or audio_channels == 2 assert audio_destination is not None assert device_name is not None gr.hier_block2.__init__( # str() because insists on non-unicode self, str('%s receiver' % (mode, )), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(audio_channels, audio_channels, gr.sizeof_float * 1), ) if lookup_mode(mode) is None: # TODO: communicate back to client if applicable log.msg('Unknown mode %r in Receiver(); using AM' % (mode, )) mode = 'AM' # Provided by caller self.context = context self.__audio_channels = audio_channels # cached info from device self.__device_name = device_name # Simple state self.mode = mode self.audio_gain = audio_gain self.audio_pan = min(1, max(-1, audio_pan)) self.__audio_destination = audio_destination # Receive frequency. self.__freq_linked_to_device = bool(freq_linked_to_device) if self.__freq_linked_to_device and freq_relative is not None: self.__freq_relative = float(freq_relative) self.__freq_absolute = self.__freq_relative + self.__get_device( ).get_freq() else: self.__freq_absolute = float(freq_absolute) self.__freq_relative = self.__freq_absolute - self.__get_device( ).get_freq() # Blocks self.__rotator = blocks.rotator_cc() self.__demodulator = self.__make_demodulator(mode, {}) self.__update_demodulator_info() self.__audio_gain_blocks = [ blocks.multiply_const_ff(0.0) for _ in xrange(self.__audio_channels) ] self.probe_audio = analog.probe_avg_mag_sqrd_f( 0, alpha=10.0 / 44100) # TODO adapt to output audio rate # Other internals self.__last_output_type = None self.__update_rotator( ) # initialize rotator, also in case of __demod_tunable self.__update_audio_gain() self.__do_connect(reason=u'initialization')