Skip to content

Commit

Permalink
Allow listing, getting and setting SoapySDR device settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xmikos committed Mar 21, 2017
1 parent 74d65a6 commit 3511a83
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion simplesoapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SoapyDevice:
default_buffer_size = 8192

def __init__(self, soapy_args='', sample_rate=0, bandwidth=0, corr=0, gain=0, auto_gain=False,
channel=0, antenna='', force_sample_rate=False, force_bandwidth=False):
channel=0, antenna='', settings=None, force_sample_rate=False, force_bandwidth=False):
self.device = SoapySDR.Device(soapy_args)
self.buffer = None
self.buffer_size = None
Expand Down Expand Up @@ -90,6 +90,10 @@ def __init__(self, soapy_args='', sample_rate=0, bandwidth=0, corr=0, gain=0, au
if antenna:
self.antenna = antenna

if settings:
for setting_name, value in settings.items():
self.set_setting(setting_name, value)

def _fix_hardware_quirks(self):
"""Apply some settings to fix quirks of specific hardware"""
if self.hardware == 'RTLSDR':
Expand Down Expand Up @@ -294,6 +298,14 @@ def list_frequencies(self):
"""List available tunable elements"""
return self.device.listFrequencies(SoapySDR.SOAPY_SDR_RX, self._channel)

def list_settings(self):
"""List available device settings, their default values and description"""
settings = {
s.key: {'value': s.value, 'name': s.name, 'description': s.description}
for s in self.device.getSettingInfo()
}
return settings

def get_gain(self, amp_name):
"""Get gain of given amplification element"""
if amp_name not in self.list_gains():
Expand All @@ -318,6 +330,18 @@ def set_frequency(self, tunable_name, value):
raise ValueError('Unknown tunable element!')
self.device.setFrequency(SoapySDR.SOAPY_SDR_RX, self._channel, tunable_name, value)

def get_setting(self, setting_name):
"""Get value of given device setting"""
if setting_name not in self.list_settings():
raise ValueError('Unknown device setting!')
return self.device.readSetting(setting_name)

def set_setting(self, setting_name, value):
"""Set value of given device setting"""
if setting_name not in self.list_settings():
raise ValueError('Unknown device setting!')
self.device.writeSetting(setting_name, value)

def start_stream(self, buffer_size=0, stream_args=None):
"""Start streaming samples"""
if self.is_streaming:
Expand Down

0 comments on commit 3511a83

Please sign in to comment.