Beispiel #1
0
 def test_name(self):
     self.assertEqual(
         'a',
         merge_devices([Device(), Device(name='a')]).get_name())
     self.assertEqual(
         'a',
         merge_devices([Device(name='a'), Device()]).get_name())
     self.assertEqual(
         'a+b',
         merge_devices([Device(name='a'),
                        Device(name='b')]).get_name())
Beispiel #2
0
 def test_components_disjoint(self):
     d = merge_devices([
         Device(components={'a': ExportedState()}),
         Device(components={'b': ExportedState()})
     ])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components().keys()), ['a', 'b'])
Beispiel #3
0
 def test_components_conflict(self):
     d = merge_devices([
         Device(components={'a': ExportedState()}),
         Device(components={'a': ExportedState()})
     ])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components().keys()), ['0-a', '1-a'])
Beispiel #4
0
 def test_components_conflict(self):
     d = merge_devices([
         Device(components={'a': StubComponent()}),
         Device(components={'a': StubComponent()})
     ])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components_dict().iterkeys()), ['0-a', '1-a'])
Beispiel #5
0
 def test_vfos(self):
     d = merge_devices([
         Device(vfo_cell=_ConstantVFOCell(1)),
         Device(vfo_cell=LooseCell(
             value=0, type=RangeT([(10, 20)]), writable=True))
     ])
     self.assertTrue(d.get_vfo_cell().isWritable())
Beispiel #6
0
 def test_components_conflict(self):
     d = merge_devices([
         Device(components={'a': StubComponent()}),
         Device(components={'a': StubComponent()})
     ])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components_dict().iterkeys()), ['0-a', '1-a'])
Beispiel #7
0
 def test_components_conflict(self):
     d = merge_devices([
         Device(components={'a': ExportedState()}),
         Device(components={'a': ExportedState()})
     ])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components().keys()), ['0-a', '1-a'])
Beispiel #8
0
 def test_components_disjoint(self):
     d = merge_devices([
         Device(components={'a': ExportedState()}),
         Device(components={'b': ExportedState()})
     ])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components().keys()), ['a', 'b'])
Beispiel #9
0
def OsmoSDRDevice(
		osmo_device,
		name=None,
		profile=OsmoSDRProfile(),
		sample_rate=None,
		external_freq_shift=0.0,  # deprecated
		correction_ppm=0.0):
	'''
	osmo_device: gr-osmosdr device string
	name: block name (usually not specified)
	profile: an OsmoSDRProfile (see docs)
	sample_rate: desired sample rate, or None == guess a good rate
	external_freq_shift: external (down|up)converter frequency (Hz) -- DEPRECATED, use shinysdr.devices.FrequencyShift
	correction_ppm: oscillator frequency calibration (parts-per-million)
	'''
	# The existence of the correction_ppm parameter is a workaround for the current inability to dynamically change an exported field's type (the frequency range), allowing them to be initialized early enough, in the configuration, to take effect. (Well, it's also nice to hardcode them in the config if you want to.)
	if name is None:
		name = 'OsmoSDR %s' % osmo_device
	
	source = osmosdr.source('numchan=1 ' + osmo_device)
	if source.get_num_channels() < 1:
		# osmosdr.source doesn't throw an exception, allegedly because gnuradio can't handle it in a hier_block2 initializer. But we want to fail understandably, so recover by detecting it (sample rate = 0, which is otherwise nonsense)
		raise LookupError('OsmoSDR device not found (device string = %r)' % osmo_device)
	elif source.get_num_channels() > 1:
		raise LookupError('Too many devices/channels; need exactly one (device string = %r)' % osmo_device)
	
	tuning = _OsmoSDRTuning(profile, correction_ppm, source)
	vfo_cell = tuning.get_vfo_cell()
	
	if sample_rate is None:
		# If sample_rate is unspecified, we pick the closest available rate to a reasonable value. (Reasonable in that it's within the data handling capabilities of this software and of USB 2.0 connections.) Previously, we chose the maximum sample rate, but that may be too high for the connection the RF hardware, or too high for the CPU to FFT/demodulate.
		source.set_sample_rate(convert_osmosdr_range(source.get_sample_rates())(2.4e6))
	else:
		source.set_sample_rate(sample_rate)
	
	rx_driver = _OsmoSDRRXDriver(
		source=source,
		name=name,
		sample_rate=sample_rate,
		tuning=tuning)
	
	hw_initial_freq = source.get_center_freq()
	if hw_initial_freq == 0.0:
		# If the hardware/driver isn't providing a reasonable default (RTLs don't), do it ourselves; go to the middle of the FM broadcast band (rounded up or down to what the hardware reports it supports).
		vfo_cell.set(100e6)
	else:
		print hw_initial_freq
		vfo_cell.set(tuning.from_hardware_freq(hw_initial_freq))
	
	self = Device(
		name=name,
		vfo_cell=vfo_cell,
		rx_driver=rx_driver)
	
	# implement legacy option in terms of new devices
	if external_freq_shift == 0.0:
		return self
	else:
		return merge_devices([self, FrequencyShift(-external_freq_shift)])
Beispiel #10
0
def OsmoSDRDevice(
        osmo_device,
        name=None,
        profile=OsmoSDRProfile(),
        sample_rate=None,
        external_freq_shift=0.0,  # deprecated
        correction_ppm=0.0):
    '''
    osmo_device: gr-osmosdr device string
    name: block name (usually not specified)
    profile: an OsmoSDRProfile (see docs)
    sample_rate: desired sample rate, or None == guess a good rate
    external_freq_shift: external (down|up)converter frequency (Hz) -- DEPRECATED, use shinysdr.devices.FrequencyShift
    correction_ppm: oscillator frequency calibration (parts-per-million)
    '''
    # The existence of the correction_ppm parameter is a workaround for the current inability to dynamically change an exported field's type (the frequency range), allowing them to be initialized early enough, in the configuration, to take effect. (Well, it's also nice to hardcode them in the config if you want to.)
    if name is None:
        name = 'OsmoSDR %s' % osmo_device

    source = osmosdr.source('numchan=1 ' + osmo_device)
    if source.get_num_channels() < 1:
        # osmosdr.source doesn't throw an exception, allegedly because gnuradio can't handle it in a hier_block2 initializer. But we want to fail understandably, so recover by detecting it (sample rate = 0, which is otherwise nonsense)
        raise LookupError('OsmoSDR device not found (device string = %r)' %
                          osmo_device)
    elif source.get_num_channels() > 1:
        raise LookupError(
            'Too many devices/channels; need exactly one (device string = %r)'
            % osmo_device)

    tuning = _OsmoSDRTuning(profile, correction_ppm, source)
    vfo_cell = tuning.get_vfo_cell()

    if sample_rate is None:
        # If sample_rate is unspecified, we pick the closest available rate to a reasonable value. (Reasonable in that it's within the data handling capabilities of this software and of USB 2.0 connections.) Previously, we chose the maximum sample rate, but that may be too high for the connection the RF hardware, or too high for the CPU to FFT/demodulate.
        source.set_sample_rate(
            convert_osmosdr_range(source.get_sample_rates())(2.4e6))
    else:
        source.set_sample_rate(sample_rate)

    rx_driver = _OsmoSDRRXDriver(source=source,
                                 name=name,
                                 sample_rate=sample_rate,
                                 tuning=tuning)

    hw_initial_freq = source.get_center_freq()
    if hw_initial_freq == 0.0:
        # If the hardware/driver isn't providing a reasonable default (RTLs don't), do it ourselves; go to the middle of the FM broadcast band (rounded up or down to what the hardware reports it supports).
        vfo_cell.set(100e6)
    else:
        print hw_initial_freq
        vfo_cell.set(tuning.from_hardware_freq(hw_initial_freq))

    self = Device(name=name, vfo_cell=vfo_cell, rx_driver=rx_driver)

    # implement legacy option in terms of new devices
    if external_freq_shift == 0.0:
        return self
    else:
        return merge_devices([self, FrequencyShift(-external_freq_shift)])
Beispiel #11
0
 def test_close(self):
     log = []
     top = Top(devices={'m':
         merge_devices([
             SimulatedDeviceForTest(),
             Device(components={'c': _DeviceShutdownDetector(log)})])})
     top.close_all_devices()
     self.assertEqual(log, ['close'])
Beispiel #12
0
 def test_vfos(self):
     d = merge_devices(
         [
             Device(vfo_cell=_ConstantVFOCell(1)),
             Device(vfo_cell=LooseCell(key="freq", value=0, type=Range([(10, 20)]), writable=True)),
         ]
     )
     self.assertTrue(d.get_vfo_cell().isWritable())
Beispiel #13
0
 def test_close(self):
     log = []
     top = Top(devices={'m':
         merge_devices([
             SimulatedDeviceForTest(),
             Device(components={'c': _DeviceShutdownDetector(log)})])})
     top.close_all_devices()
     self.assertEqual(log, ['close'])
Beispiel #14
0
 def add(self, key, *devices):
     from shinysdr.devices import merge_devices
     super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #15
0
 def add(self, key, *devices):
     if not len(devices) > 0:
         raise ValueError('config.devices: no device(s) specified')
     from shinysdr.devices import merge_devices
     super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #16
0
 def test_components_conflict(self):
     d = merge_devices([Device(components={"a": ExportedState()}), Device(components={"a": ExportedState()})])
     self.assertEqual(d, IDevice(d))
     self.assertEqual(sorted(d.get_components_dict().keys()), ["0-a", "1-a"])
Beispiel #17
0
 def add(self, key, *devices):
     if len(devices) <= 0:
         raise ConfigException('config.devices: no device(s) specified')
     from shinysdr.devices import merge_devices
     super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #18
0
 def add(self, key, *devices):
     # pylint: disable=arguments-differ
     if len(devices) <= 0:
         raise ConfigException('config.devices: no device(s) specified')
     from shinysdr.devices import merge_devices
     super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #19
0
 def add(self, key, *devices):
     if len(devices) <= 0:
         raise ValueError('config.devices: no device(s) specified')
     from shinysdr.devices import merge_devices
     super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #20
0
 def test_name(self):
     self.assertEqual('a', merge_devices([Device(), Device(name='a')]).get_name())
     self.assertEqual('a', merge_devices([Device(name='a'), Device()]).get_name())
     self.assertEqual('a+b', merge_devices([Device(name='a'), Device(name='b')]).get_name())
Beispiel #21
0
	def add(self, key, *devices):
		from shinysdr.devices import merge_devices
		super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #22
0
 def add(self, key, *devices):
     # pylint: disable=arguments-differ
     if len(devices) <= 0:
         raise ConfigException('config.devices: no device(s) specified')
     from shinysdr.devices import merge_devices
     super(_ConfigDevices, self).add(key, merge_devices(devices))
Beispiel #23
0
 def test_name(self):
     self.assertEqual("a", merge_devices([Device(), Device(name="a")]).get_name())
     self.assertEqual("a", merge_devices([Device(name="a"), Device()]).get_name())
     self.assertEqual("a+b", merge_devices([Device(name="a"), Device(name="b")]).get_name())