Esempio n. 1
0
 def __init__(self, time_source=the_reactor):
     self.__interesting_objects = CellDict(dynamic=True)
     CollectionState.__init__(self, self.__interesting_objects)
     self.__objects = {}
     self.__expiry_times = {}
     self.__time_source = IReactorTime(time_source)
     self.__flush_call = None
Esempio n. 2
0
 def test_undefined(self):
     """no state_insert method defined"""
     self.object = CollectionState(CellDict(dynamic=True))
     self.object.state_from_json({'foo': {'fail': True}})
     # throws but exception is caught -- TODO: Test logging
     self.assertEqual([], list(self.object.state().keys()))
     self.flushLoggedErrors(ValueError)
Esempio n. 3
0
 def __init__(self, time_source=the_reactor):
     self.__interesting_objects = CellDict(dynamic=True)
     CollectionState.__init__(self, self.__interesting_objects)
     self.__objects = {}
     self.__expiry_times = {}
     self.__time_source = IReactorTime(time_source)
     self.__flush_call = None
Esempio n. 4
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()
Esempio n. 5
0
 def __init__(self, time_source=the_reactor):
     self.__interesting_objects = {}
     CollectionState.__init__(self,
                              self.__interesting_objects,
                              dynamic=True)
     self.__objects = {}
     self.__expiry_times = {}
     self.__time_source = IReactorTime(time_source)
Esempio n. 6
0
 def __init__(self,
         name=None,
         rx_driver=nullExportedState,
         tx_driver=nullExportedState,
         vfo_cell=None,
         components={}):
     # pylint: disable=dangerous-default-value
     """
     rx_driver -- may be nullExportedState
     tx_driver -- may be nullExportedState
     vfo_cell -- may be None
     """
     if vfo_cell is None:
         vfo_cell = _stub_vfo
     assert isinstance(vfo_cell.type(), RangeT)
     # TODO: Consider using an unconditional wrapper around the VFO cell which sets the cell metadata consistently.
     
     self.__name = name
     self.__vfo_cell = vfo_cell
     self.rx_driver = IRXDriver(rx_driver) if rx_driver is not nullExportedState else nullExportedState
     self.tx_driver = ITXDriver(tx_driver) if tx_driver is not nullExportedState else nullExportedState
     coerced_components = {}
     for key, component in components.iteritems():
         coerced_components[key] = IComponent(component)
     self.__components = CellDict(initial_state=coerced_components)
     self.__components_state = CollectionState(self.__components)
     
     self.__transmitting = False
Esempio n. 7
0
 def __init__(self,
         name=None,
         rx_driver=nullExportedState,
         tx_driver=nullExportedState,
         vfo_cell=None,
         components={}):
     # pylint: disable=dangerous-default-value
     """
     rx_driver -- may be nullExportedState
     tx_driver -- may be nullExportedState
     vfo_cell -- may be None
     """
     if vfo_cell is None:
         vfo_cell = _stub_vfo
     assert vfo_cell.key() == 'freq'
     assert isinstance(vfo_cell.type(), Range)
     
     self.__name = name
     self.__vfo_cell = vfo_cell
     self.rx_driver = IRXDriver(rx_driver) if rx_driver is not nullExportedState else nullExportedState
     self.tx_driver = ITXDriver(tx_driver) if tx_driver is not nullExportedState else nullExportedState
     self.__components = {}
     for key, component in components.iteritems():
         self.__components[key] = IComponent(component)
     self.__components_state = CollectionState(self.__components, dynamic=False)
     
     self.__transmitting = False
Esempio n. 8
0
    def __init__(self,
                 name=None,
                 rx_driver=nullExportedState,
                 tx_driver=nullExportedState,
                 vfo_cell=None,
                 components={}):
        '''
        rx_driver -- may be nullExportedState
        tx_driver -- may be nullExportedState
        vfo_cell -- may be None
        '''
        if vfo_cell is None:
            vfo_cell = _stub_vfo
        assert vfo_cell.key() == 'freq'
        assert isinstance(vfo_cell.type(), Range)

        self.__name = name
        self.rx_driver = IRXDriver(
            rx_driver
        ) if rx_driver is not nullExportedState else nullExportedState
        self.tx_driver = ITXDriver(
            tx_driver
        ) if tx_driver is not nullExportedState else nullExportedState
        self.__vfo_cell = vfo_cell
        self.__components = components
        self.components = CollectionState(self.__components, dynamic=False)
Esempio n. 9
0
    def test_collection_delete(self):
        d = CellDict({'a': ExportedState()}, dynamic=True)
        self.setUpForObject(CollectionState(d))

        self.assertEqual(
            self.getUpdates(),
            transform_for_json([
                ['register_block', 1, 'urlroot', []],
                [
                    'register_cell', 2, 'urlroot/a',
                    self.object.state()['a'].description()
                ],
                ['register_block', 3, 'urlroot/a', []],
                ['value', 3, {}],
                ['value', 2, 3],
                ['value', 1, {
                    'a': 2
                }],
                ['value', 0, 1],
            ]))
        self.assertEqual(self.getUpdates(), [])
        del d['a']
        self.assertEqual(self.getUpdates(), [
            ['value', 1, {}],
            ['delete', 2],
            ['delete', 3],
        ])
Esempio n. 10
0
class TestStateInsert(unittest.TestCase):
    object = None
    
    def test_success(self):
        self.object = InsertFailSpecimen()
        self.object.state_from_json({'foo': {'fail': False}})
        self.assertEqual(['foo'], self.object.state().keys())
    
    def test_failure(self):
        self.object = InsertFailSpecimen()
        self.object.state_from_json({'foo': {'fail': True}})
        # throws but exception is caught
        self.assertEqual([], self.object.state().keys())
    
    def test_undefined(self):
        '''no state_insert method defined'''
        self.object = CollectionState({}, dynamic=True)
        self.object.state_from_json({'foo': {'fail': True}})
        # throws but exception is caught
        self.assertEqual([], self.object.state().keys())
Esempio n. 11
0
class TestStateInsert(unittest.TestCase):
    object = None

    def test_success(self):
        self.object = InsertFailSpecimen()
        self.object.state_from_json({'foo': {'fail': False}})
        self.assertEqual(['foo'], self.object.state().keys())

    def test_failure(self):
        self.object = InsertFailSpecimen()
        self.object.state_from_json({'foo': {'fail': True}})
        # throws but exception is caught
        self.assertEqual([], self.object.state().keys())

    def test_undefined(self):
        """no state_insert method defined"""
        self.object = CollectionState(CellDict(dynamic=True))
        self.object.state_from_json({'foo': {'fail': True}})
        # throws but exception is caught
        self.assertEqual([], self.object.state().keys())
Esempio n. 12
0
class TestStateInsert(unittest.TestCase):
    object = None
    
    def test_success(self):
        self.object = InsertFailSpecimen()
        self.object.state_from_json({'foo': {'fail': False}})
        self.assertEqual(['foo'], list(self.object.state().keys()))
    
    def test_failure(self):
        self.object = InsertFailSpecimen()
        self.object.state_from_json({'foo': {'fail': True}})
        # throws but exception is caught -- TODO: Test logging
        self.assertEqual([], list(self.object.state().keys()))
        self.flushLoggedErrors(ValueError)
    
    def test_undefined(self):
        """no state_insert method defined"""
        self.object = CollectionState(CellDict(dynamic=True))
        self.object.state_from_json({'foo': {'fail': True}})
        # throws but exception is caught -- TODO: Test logging
        self.assertEqual([], list(self.object.state().keys()))
        self.flushLoggedErrors(ValueError)
Esempio n. 13
0
class TestCollectionStream(StateStreamTestCase):
	def setUp(self):
		self.d = {'a': ExportedState()}
		self.object = CollectionState(self.d, dynamic=True)
		StateStreamTestCase.setUp(self)
	
	def test_delete(self):
		self.assertEqual(self.getUpdates(), [
			['register_block', 1, 'urlroot'],
			['register_cell', 2, 'urlroot/a', self.object.state()['a'].description()],
			['register_block', 3, 'urlroot/a'],
			['value', 3, {}],
			['value', 2, 3],
			['value', 1, {'a': 2}],
			['value', 0, 1],
		])
		self.assertEqual(self.getUpdates(), [])
		del self.d['a']
		self.assertEqual(self.getUpdates(), [
			['value', 1, {}],
			['delete', 2],
			['delete', 3],
		])
Esempio n. 14
0
 def test_failure(self):
     self.object = InsertFailSpecimen()
     self.object.state_from_json({'foo': {'fail': True}})
     # throws but exception is caught -- TODO: Test logging
     self.assertEqual([], list(self.object.state().keys()))
     self.flushLoggedErrors(ValueError)
Esempio n. 15
0
	def setUp(self):
		self.d = {'a': ExportedState()}
		self.object = CollectionState(self.d, dynamic=True)
		StateStreamTestCase.setUp(self)
Esempio n. 16
0
 def __init__(self, table, top):
     CollectionState.__init__(self, table)
     self.__top = top
Esempio n. 17
0
 def test_success(self):
     self.object = InsertFailSpecimen()
     self.object.state_from_json({'foo': {'fail': False}})
     self.assertEqual(['foo'], self.object.state().keys())
Esempio n. 18
0
 def __init__(self, table, top):
     CollectionState.__init__(self, table, dynamic=True)
     self.__top = top
Esempio n. 19
0
	def __init__(self, table, top):
		CollectionState.__init__(self, table, dynamic=True)
		self.__top = top
Esempio n. 20
0
 def __init__(self, time_source=the_reactor):
     self.__interesting_objects = {}
     CollectionState.__init__(self, self.__interesting_objects, dynamic=True)
     self.__objects = {}
     self.__expiry_times = {}
     self.__time_source = IReactorTime(time_source)
Esempio n. 21
0
 def test_undefined(self):
     """no state_insert method defined"""
     self.object = CollectionState(CellDict(dynamic=True))
     self.object.state_from_json({'foo': {'fail': True}})
     # throws but exception is caught
     self.assertEqual([], self.object.state().keys())
Esempio n. 22
0
 def __init__(self):
     self.__stations = {}
     CollectionState.__init__(self, self.__stations, dynamic=True)
Esempio n. 23
0
 def __init__(self):
     self.__aircraft = {}
     self.__interesting_aircraft = {}
     CollectionState.__init__(self,
                              self.__interesting_aircraft,
                              dynamic=True)
Esempio n. 24
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()
Esempio n. 25
0
 def __init__(self):
     self.table = CellDict(dynamic=True)
     CollectionState.__init__(self, self.table)
Esempio n. 26
0
 def __init__(self):
     self.table = {}
     CollectionState.__init__(self, self.table, dynamic=True)
Esempio n. 27
0
 def __init__(self, cap_table, unserializer):
     self.__cap_table = cap_table
     self.__unserializer = unserializer
     CollectionState.__init__(self, cap_table._get_cap_dict())
Esempio n. 28
0
 def __init__(self, table, top):
     CollectionState.__init__(self, table)
     self.__top = top
Esempio n. 29
0
    def __init__(self, devices={}, audio_config=None, features=_STUB_FEATURES):
        # pylint: disable=dangerous-default-value
        if len(devices) <= 0:
            raise ValueError(
                'Must be configured with at least one RF device! (This should normally be caught by the configuration validator.)'
            )

        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 six.iteritems(devices) if d.can_receive()})
        self._accessories = accessories = {
            k: d
            for k, d in six.iteritems(devices) 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 six.iteritems(self._sources)})

        # 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 six.iteritems(devices):
            hookup_vfo_callback(k, d)

        device_context = DeviceContext(self.__telemetry_store.receive)
        for device in six.itervalues(devices):
            device.attach_context(device_context)

        self._do_connect()
Esempio n. 30
0
    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)])
Esempio n. 31
0
 def test_undefined(self):
     '''no state_insert method defined'''
     self.object = CollectionState({}, dynamic=True)
     self.object.state_from_json({'foo': {'fail': True}})
     # throws but exception is caught
     self.assertEqual([], self.object.state().keys())
Esempio n. 32
0
 def __init__(self):
     self.table = {}
     CollectionState.__init__(self, self.table, dynamic=True)
Esempio n. 33
0
 def __init__(self):
     self.__aircraft = {}
     self.__interesting_aircraft = {}
     CollectionState.__init__(self, self.__interesting_aircraft, dynamic=True)
Esempio n. 34
0
 def test_failure(self):
     self.object = InsertFailSpecimen()
     self.object.state_from_json({'foo': {'fail': True}})
     # throws but exception is caught
     self.assertEqual([], self.object.state().keys())
Esempio n. 35
0
 def __init__(self, cap_table, unserializer):
     self.__cap_table = cap_table
     self.__unserializer = unserializer
     CollectionState.__init__(self, cap_table._get_cap_dict())
Esempio n. 36
0
 def __init__(self):
     self.table = CellDict(dynamic=True)
     CollectionState.__init__(self, self.table)
Esempio n. 37
0
 def test_success(self):
     self.object = InsertFailSpecimen()
     self.object.state_from_json({'foo': {'fail': False}})
     self.assertEqual(['foo'], self.object.state().keys())
Esempio n. 38
0
 def test_failure(self):
     self.object = InsertFailSpecimen()
     self.object.state_from_json({'foo': {'fail': True}})
     # throws but exception is caught
     self.assertEqual([], self.object.state().keys())
Esempio n. 39
0
 def __init__(self):
     self.__stations = {}
     CollectionState.__init__(self, self.__stations, dynamic=True)