From 42828dbf65ab1aecca6d968bfd9f1928f774ec85 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 31 Dec 2019 19:14:05 +0100 Subject: [PATCH] add always-on feature --- owrx/source/__init__.py | 14 +++++++++++++- owrx/source/airspy.py | 5 ++--- owrx/source/connector.py | 6 ++++-- owrx/source/fifi_sdr.py | 5 ++--- owrx/source/hackrf.py | 5 ++--- owrx/source/rtl_sdr.py | 5 ++--- owrx/source/soapy.py | 5 ++--- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index 0fb6c91..77e56e0 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -37,7 +37,7 @@ class SdrSource(ABC): self.activateProfile() self.rtlProps = self.props.collect(*self.getEventNames()).defaults(PropertyManager.getSharedInstance()) self.wireEvents() - self.commandMapper = CommandMapper() + self.commandMapper = None if "port" in props and props["port"] is not None: self.port = props["port"] @@ -53,6 +53,12 @@ class SdrSource(ABC): self.state = SdrSource.STATE_STOPPED self.busyState = SdrSource.BUSYSTATE_IDLE + if self.isAlwaysOn(): + self.start() + + def isAlwaysOn(self): + return "always-on" in self.props and self.props["always-on"] + def getEventNames(self): return [ "samp_rate", @@ -63,6 +69,8 @@ class SdrSource(ABC): ] def getCommandMapper(self): + if self.commandMapper is None: + self.commandMapper = CommandMapper() return self.commandMapper @abstractmethod @@ -233,6 +241,10 @@ class SdrSource(ABC): except ValueError: pass + # no need to check for users if we are always-on + if self.isAlwaysOn(): + return + hasUsers = self.hasClients(SdrSource.CLIENT_USER) hasBackgroundTasks = self.hasClients(SdrSource.CLIENT_BACKGROUND) self.setBusyState(SdrSource.BUSYSTATE_BUSY if hasUsers else SdrSource.BUSYSTATE_IDLE) diff --git a/owrx/source/airspy.py b/owrx/source/airspy.py index 16878e6..4453da9 100644 --- a/owrx/source/airspy.py +++ b/owrx/source/airspy.py @@ -3,9 +3,8 @@ from .soapy import SoapyConnectorSource class AirspySource(SoapyConnectorSource): - def __init__(self, id, props): - super().__init__(id, props) - self.getCommandMapper().setMappings({"bias_tee": Flag("-t biastee=true")}) + def getCommandMapper(self): + return super().getCommandMapper().setMappings({"bias_tee": Flag("-t biastee=true")}) def getDriver(self): return "airspy" diff --git a/owrx/source/connector.py b/owrx/source/connector.py index 9c705e9..c626506 100644 --- a/owrx/source/connector.py +++ b/owrx/source/connector.py @@ -10,10 +10,12 @@ logger = logging.getLogger(__name__) class ConnectorSource(SdrSource): def __init__(self, id, props): - super().__init__(id, props) self.controlSocket = None self.controlPort = getAvailablePort() - self.getCommandMapper().setMappings( + super().__init__(id, props) + + def getCommandMapper(self): + return super().getCommandMapper().setMappings( { "samp_rate": Option("-s"), "tuner_freq": Option("-f"), diff --git a/owrx/source/fifi_sdr.py b/owrx/source/fifi_sdr.py index 283e7a2..f591b52 100644 --- a/owrx/source/fifi_sdr.py +++ b/owrx/source/fifi_sdr.py @@ -8,9 +8,8 @@ logger = logging.getLogger(__name__) class FifiSdrSource(DirectSource): - def __init__(self, id, props): - super().__init__(id, props) - self.getCommandMapper().setBase("arecord").setMappings( + def getCommandMapper(self): + return super().getCommandMapper().setBase("arecord").setMappings( {"device": Option("-D"), "samp_rate": Option("-r")} ).setStatic("-f S16_LE -c2 -") diff --git a/owrx/source/hackrf.py b/owrx/source/hackrf.py index cd1ef1f..50001ae 100644 --- a/owrx/source/hackrf.py +++ b/owrx/source/hackrf.py @@ -3,9 +3,8 @@ from owrx.command import Flag, Option class HackrfSource(DirectSource): - def __init__(self, id, props): - super().__init__(id, props) - self.getCommandMapper().setBase("hackrf_transfer").setMappings( + def getCommandMapper(self): + return super().getCommandMapper().setBase("hackrf_transfer").setMappings( { "samp_rate": Option("-s"), "tuner_freq": Option("-f"), diff --git a/owrx/source/rtl_sdr.py b/owrx/source/rtl_sdr.py index b30378a..64badf1 100644 --- a/owrx/source/rtl_sdr.py +++ b/owrx/source/rtl_sdr.py @@ -2,6 +2,5 @@ from .connector import ConnectorSource class RtlSdrSource(ConnectorSource): - def __init__(self, id, props): - super().__init__(id, props) - self.getCommandMapper().setBase("rtl_connector") + def getCommandMapper(self): + return super().getCommandMapper().setBase("rtl_connector") diff --git a/owrx/source/soapy.py b/owrx/source/soapy.py index 249dd5e..0810884 100644 --- a/owrx/source/soapy.py +++ b/owrx/source/soapy.py @@ -5,9 +5,8 @@ from .connector import ConnectorSource class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta): - def __init__(self, id, props): - super().__init__(id, props) - self.getCommandMapper().setBase("soapy_connector").setMappings({"antenna": Option("-a")}) + def getCommandMapper(self): + return super().getCommandMapper().setBase("soapy_connector").setMappings({"antenna": Option("-a")}) """ must be implemented by child classes to be able to build a driver-based device selector by default.