introduce a generic mapping from sdr properties to soapy settings

This commit is contained in:
Jakob Ketterl 2020-03-14 01:04:52 +01:00
parent fb82daf936
commit 5da2047935
2 changed files with 31 additions and 15 deletions

View File

@ -1,19 +1,11 @@
from .soapy import SoapyConnectorSource from .soapy import SoapyConnectorSource
from owrx.command import Option
class RtlSdrSoapySource(SoapyConnectorSource): class RtlSdrSoapySource(SoapyConnectorSource):
def getCommandMapper(self): def getSoapySettingsMappings(self):
return super().getCommandMapper().setMappings({"direct_sampling": Option("-t direct_samp").setSpacer("=")}) mappings = super().getSoapySettingsMappings()
mappings.update({"direct_sampling": "direct_samp"})
return mappings
def getDriver(self): def getDriver(self):
return "rtlsdr" return "rtlsdr"
def getEventNames(self):
return super().getEventNames() + ["direct_sampling"]
def onPropertyChange(self, prop, value):
if prop == "direct_sampling":
prop = "settings"
value = "direct_samp={0}".format(value)
super().onPropertyChange(prop, value)

View File

@ -1,12 +1,16 @@
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from owrx.command import Option from owrx.command import Option
from .connector import ConnectorSource from .connector import ConnectorSource
class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta): class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
def getCommandMapper(self): def getCommandMapper(self):
return super().getCommandMapper().setBase("soapy_connector").setMappings({"antenna": Option("-a")}) return super().getCommandMapper().setBase("soapy_connector").setMappings(
{
"antenna": Option("-a"),
"soapy_settings": Option("-t"),
}
)
""" """
must be implemented by child classes to be able to build a driver-based device selector by default. must be implemented by child classes to be able to build a driver-based device selector by default.
@ -20,7 +24,7 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
def getEventNames(self): def getEventNames(self):
return super().getEventNames() + [ return super().getEventNames() + [
"antenna", "antenna",
] ] + list(self.getSoapySettingsMappings().keys())
def parseDeviceString(self, dstr): def parseDeviceString(self, dstr):
def decodeComponent(c): def decodeComponent(c):
@ -50,6 +54,16 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
parsed += [{"driver": self.getDriver()}] parsed += [{"driver": self.getDriver()}]
return parsed return parsed
def getSoapySettingsMappings(self):
return {}
def buildSoapySettings(self, values):
settings = {}
for k, v in self.getSoapySettingsMappings().items():
if k in values:
settings[v] = values[k]
return settings
def getCommandValues(self): def getCommandValues(self):
values = super().getCommandValues() values = super().getCommandValues()
if "device" in values and values["device"] is not None: if "device" in values and values["device"] is not None:
@ -58,4 +72,14 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
parsed = [] parsed = []
modified = self.buildSoapyDeviceParameters(parsed, values) modified = self.buildSoapyDeviceParameters(parsed, values)
values["device"] = self.encodeDeviceString(modified) values["device"] = self.encodeDeviceString(modified)
settings = ",".join(["{0}={1}".format(k, v) for k, v in self.buildSoapySettings(values).items()])
if len(settings):
values["soapy_settings"] = settings
return values return values
def onPropertyChange(self, prop, value):
mappings = self.getSoapySettingsMappings()
if prop in mappings.keys():
value = "{0}={1}".format(mappings[prop], value)
prop = "settings"
super().onPropertyChange(prop, value)