Beispiel #1
0
 def test_receiver_device_default(self):
     """
     Receiver should default to the monitor device, not other receiver's device.
     """
     top = Top(devices={
         's1': SimulatedDeviceForTest(),
         's2': SimulatedDeviceForTest(),
     })
     
     (_key, receiver1) = top.add_receiver('AM', key='a')
     top.set_source_name('s2')
     receiver1.set_device_name('s1')
     (_key, receiver2) = top.add_receiver('AM', key='b')
     self.assertEquals(receiver2.get_device_name(), 's2')
     self.assertEquals(receiver1.get_device_name(), 's1')
Beispiel #2
0
 def test_receiver_device_default(self):
     """
     Receiver should default to the monitor device, not other receiver's device.
     """
     top = Top(devices={
         's1': SimulatedDeviceForTest(),
         's2': SimulatedDeviceForTest(),
     })
     
     (_key, receiver1) = top.add_receiver('AM', key='a')
     top.set_source_name('s2')
     receiver1.set_device_name('s1')
     (_key, receiver2) = top.add_receiver('AM', key='b')
     self.assertEquals(receiver2.get_device_name(), 's2')
     self.assertEquals(receiver1.get_device_name(), 's1')
Beispiel #3
0
 def test_audio_callback_smoke(self):
     def callback(data):
         pass
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)})
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_callback(callback, 48000)
     top.remove_audio_callback(callback)
Beispiel #4
0
 def test_audio_callback_smoke(self):
     def callback(data):
         pass
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)})
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_callback(callback, 48000)
     top.remove_audio_callback(callback)
Beispiel #5
0
class DemodulatorTester(object):
    """
    Set up an environment for testing a demodulator and do some fundamental tests.
    """
    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 close(self):
        if self.__top is not None:
            self.__top.stop()
            self.__top = None
    
    def __enter__(self):
        state_smoke_test(self.__demodulator)
    
    def __exit__(self, exc_type, exc_value, traceback):
        self.close()
Beispiel #6
0
    def test_auto_retune(self):
        # pylint: disable=no-member

        f1 = 50e6  # avoid 100e6 because that's a default a couple of places
        dev = simulate.SimulatedDevice(freq=f1, allow_tuning=True)
        bandwidth = dev.get_rx_driver().get_output_type().get_sample_rate()
        top = Top(devices={'s1': dev})
        (_key, receiver) = top.add_receiver('AM', key='a')

        # initial state check
        receiver.set_rec_freq(f1)
        self.assertEqual(dev.get_freq(), f1)

        # one "page" up
        f2 = f1 + bandwidth * 3 / 4
        receiver.set_rec_freq(f2)
        self.assertEqual(dev.get_freq(), f1 + bandwidth)

        # must wait for tune_delay, which is 0 for simulated source, or it will look still-valid
        yield deferLater(the_reactor, 0.1, lambda: None)

        # one "page" down
        receiver.set_rec_freq(f1)
        self.assertEqual(dev.get_freq(), f1)

        yield deferLater(the_reactor, 0.1, lambda: None)

        # long hop
        receiver.set_rec_freq(200e6)
        self.assertEqual(dev.get_freq(), 200e6)
Beispiel #7
0
 def test_auto_retune(self):
     # pylint: disable=no-member
     
     f1 = 50e6  # avoid 100e6 because that's a default a couple of places
     dev = simulate.SimulatedDevice(freq=f1, allow_tuning=True)
     bandwidth = dev.get_rx_driver().get_output_type().get_sample_rate()
     top = Top(devices={'s1': dev})
     (_key, receiver) = top.add_receiver('AM', key='a')
     
     # initial state check
     receiver.set_rec_freq(f1)
     self.assertEqual(dev.get_freq(), f1)
     
     # one "page" up
     f2 = f1 + bandwidth * 3 / 4
     receiver.set_rec_freq(f2)
     self.assertEqual(dev.get_freq(), f1 + bandwidth)
     
     # must wait for tune_delay, which is 0 for simulated source, or it will look still-valid
     yield deferLater(the_reactor, 0.1, lambda: None)
     
     # one "page" down
     receiver.set_rec_freq(f1)
     self.assertEqual(dev.get_freq(), f1)
     
     yield deferLater(the_reactor, 0.1, lambda: None)
     
     # long hop
     receiver.set_rec_freq(200e6)
     self.assertEqual(dev.get_freq(), 200e6)
Beispiel #8
0
 def test_add_unknown_mode(self):
     """
     Specifying an unknown mode should not _fail_.
     """
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)})
     (_key, receiver) = top.add_receiver('NONSENSE', key='a')
     self.assertEqual(receiver.get_mode(), 'AM')
Beispiel #9
0
 def test_add_unknown_mode(self):
     """
     Specifying an unknown mode should not _fail_.
     """
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)})
     (_key, receiver) = top.add_receiver('NONSENSE', key='a')
     self.assertEqual(receiver.get_mode(), 'AM')
Beispiel #10
0
class DemodulatorTester(object):
    """
    Set up an environment for testing a demodulator and do some fundamental tests.
    """
    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 close(self):
        if self.__top is not None:
            self.__top.stop()
            self.__top = None

    def __enter__(self):
        state_smoke_test(self.__demodulator)

    def __exit__(self, exc_type, exc_value, traceback):
        self.close()
Beispiel #11
0
 def test_mono(self):
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)},
               features={'stereo': False})
     queue = gr.msg_queue()
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_queue(queue, 48000)
     top.remove_audio_queue(queue)
Beispiel #12
0
 def test_mono(self):
     top = Top(
         devices={'s1': SimulatedDeviceForTest(freq=0)},
         features={'stereo': False})
     queue = gr.msg_queue()
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_queue(queue, 48000)
     top.remove_audio_queue(queue)
Beispiel #13
0
 def test_mono(self):
     def callback(data):
         pass
     top = Top(
         devices={'s1': SimulatedDeviceForTest(freq=0)},
         features={'stereo': False})
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_callback(callback, 48000)
     top.remove_audio_callback(callback)
Beispiel #14
0
    def test_mono(self):
        def callback(data):
            pass

        top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)},
                  features={'stereo': False})
        (_key, _receiver) = top.add_receiver('AM', key='a')
        top.add_audio_callback(callback, 48000)
        top.remove_audio_callback(callback)
Beispiel #15
0
    def setUp(self):
        f1 = self.f1 = 50e6  # avoid 100e6 because that's a default a couple of places
        self.devs = {
            'clean': _RetuningTestDevice(f1, -1.0),
            'offset_small': _RetuningTestDevice(f1, self.__OFFSET_SMALL),
            'offset_large': _RetuningTestDevice(f1, self.__OFFSET_LARGE),
        }
        self.bandwidth = self.devs['clean'].get_rx_driver().get_output_type().get_sample_rate()
        top = Top(devices=self.devs)
        (_key, self.receiver) = top.add_receiver('AM', key='a')

        # initial state sanity check
        for d in self.devs.itervalues():
            self.assertEqual(d.get_freq(), f1)
Beispiel #16
0
    def setUp(self):
        f1 = self.f1 = 50e6  # avoid 100e6 because that's a default a couple of places
        self.devs = {
            'clean': _RetuningTestDevice(f1, -1.0),
            'offset_small': _RetuningTestDevice(f1, self.__OFFSET_SMALL),
            'offset_large': _RetuningTestDevice(f1, self.__OFFSET_LARGE),
        }
        self.bandwidth = self.devs['clean'].get_rx_driver().get_output_type().get_sample_rate()
        top = Top(devices=self.devs)
        (_key, self.receiver) = top.add_receiver('AM', key='a')

        # initial state sanity check
        for d in self.devs.itervalues():
            self.assertEqual(d.get_freq(), f1)
Beispiel #17
0
class TestReceiver(unittest.TestCase):
    def setUp(self):
        self.top = Top(devices={'s1': SimulatedDevice()})
        (_key, self.receiver) = self.top.add_receiver('AM', key='a')
    
    def tearDown(self):
        self.top.close_all_devices()

    def test_smoke(self):
        state_smoke_test(self.receiver)

    def test_no_audio_demodulator(self):
        """Smoke test for demodulator with no audio output."""
        # TODO: Allow parameterizing with a different mode table so that we can use a test stub mode rather than a real one
        self.receiver.set_mode('MODE-S')
Beispiel #18
0
 def test_receiver_source_switch(self):
     """
     Regression test: Switching sources was not updating receiver input frequency.
     """
     freq1 = 1e6
     freq2 = 2e6
     top = Top(devices={
         's1': SimulatedDeviceForTest(freq=freq1),
         's2': SimulatedDeviceForTest(freq=freq2),
     })
     
     (_key, receiver) = top.add_receiver('AM', key='a')
     receiver.set_rec_freq(freq2)
     receiver.set_device_name('s1')
     self.assertFalse(receiver.get_is_valid(), 'receiver initially invalid')
     receiver.set_device_name('s2')
     self.assertTrue(receiver.get_is_valid(), 'receiver now valid')
Beispiel #19
0
 def test_receiver_source_switch(self):
     """
     Regression test: Switching sources was not updating receiver input frequency.
     """
     freq1 = 1e6
     freq2 = 2e6
     top = Top(devices={
         's1': SimulatedDeviceForTest(freq=freq1),
         's2': SimulatedDeviceForTest(freq=freq2),
     })
     
     (_key, receiver) = top.add_receiver('AM', key='a')
     receiver.set_rec_freq(freq2)
     receiver.set_device_name('s1')
     self.assertFalse(receiver.get_is_valid(), 'receiver initially invalid')
     receiver.set_device_name('s2')
     self.assertTrue(receiver.get_is_valid(), 'receiver now valid')
Beispiel #20
0
class TestReceiver(unittest.TestCase):
    def setUp(self):
        self.top = Top(devices={'s1': SimulatedDevice()})
        (_key, self.receiver) = self.top.add_receiver('AM', key='a')

    def tearDown(self):
        self.top.close_all_devices()

    def test_smoke(self):
        state_smoke_test(self.receiver)

    def test_no_audio_demodulator(self):
        """Smoke test for demodulator with no audio output."""
        # TODO: Allow parameterizing with a different mode table so that we can use a test stub mode rather than a real one. Also fix rtl_433 leaving unclean reactor.
        for mode in ['MODE-S']:
            if lookup_mode(mode):
                self.receiver.set_mode(mode)
                break
        else:
            raise unittest.SkipTest('No no-audio mode available.')
Beispiel #21
0
class TestReceiver(unittest.TestCase):
    def setUp(self):
        self.top = Top(devices={'s1': SimulatedDevice()})
        (_key, self.receiver) = self.top.add_receiver('AM', key='a')
    
    def tearDown(self):
        self.top.close_all_devices()

    def test_smoke(self):
        state_smoke_test(self.receiver)

    def test_no_audio_demodulator(self):
        """Smoke test for demodulator with no audio output."""
        # TODO: Allow parameterizing with a different mode table so that we can use a test stub mode rather than a real one. Also fix rtl_433 leaving unclean reactor.
        for mode in ['MODE-S']:
            if lookup_mode(mode):
                self.receiver.set_mode(mode)
                break
        else:
            raise unittest.SkipTest('No no-audio mode available.')
Beispiel #22
0
 def test_audio_queue_smoke(self):
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)})
     queue = gr.msg_queue()
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_queue(queue, 48000)
     top.remove_audio_queue(queue)
Beispiel #23
0
 def test_audio_queue_smoke(self):
     top = Top(devices={'s1': SimulatedDeviceForTest(freq=0)})
     queue = gr.msg_queue()
     (_key, _receiver) = top.add_receiver('AM', key='a')
     top.add_audio_queue(queue, 48000)
     top.remove_audio_queue(queue)