From 70347d1ef99220700f55c9e974f98151b1de5441 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 31 Dec 2019 15:24:11 +0100 Subject: [PATCH] use automatic ports unless explicitly configured --- config_webrx.py | 7 ------- owrx/sdr.py | 15 +-------------- owrx/source/__init__.py | 8 ++++++-- owrx/source/airspy.py | 4 ++-- owrx/source/connector.py | 4 ++-- owrx/source/fifi_sdr.py | 4 ++-- owrx/source/hackrf.py | 4 ++-- owrx/source/resampler.py | 4 ++-- owrx/source/rtl_sdr.py | 4 ++-- owrx/source/soapy.py | 4 ++-- 10 files changed, 21 insertions(+), 37 deletions(-) diff --git a/config_webrx.py b/config_webrx.py index 96cdd4e..e9466f0 100644 --- a/config_webrx.py +++ b/config_webrx.py @@ -237,13 +237,6 @@ sdrs = { }, } -# ==== Misc settings ==== - -iq_port_range = [ - 4950, - 4960, -] # TCP port for range ncat to listen on. It will send I/Q data over its connections, for internal use in OpenWebRX. It is only accessible from the localhost by default. - # ==== Color themes ==== # A guide is available to help you set these values: https://github.com/simonyiszk/openwebrx/wiki/Calibrating-waterfall-display-levels diff --git a/owrx/sdr.py b/owrx/sdr.py index b63e67e..878b24d 100644 --- a/owrx/sdr.py +++ b/owrx/sdr.py @@ -1,6 +1,5 @@ from owrx.config import PropertyManager from owrx.feature import FeatureDetector, UnknownFeatureException -import sys import logging @@ -12,18 +11,6 @@ class SdrService(object): sources = {} lastPort = None - @staticmethod - def getNextPort(): - pm = PropertyManager.getSharedInstance() - (start, end) = pm["iq_port_range"] - if SdrService.lastPort is None: - SdrService.lastPort = start - else: - SdrService.lastPort += 1 - if SdrService.lastPort > end: - raise IndexError("no more available ports to start more sdrs") - return SdrService.lastPort - @staticmethod def loadProps(): if SdrService.sdrProps is None: @@ -90,5 +77,5 @@ class SdrService(object): className = "".join(x for x in sdrType.title() if x.isalnum()) + "Source" module = __import__("owrx.source.{0}".format(sdrType), fromlist=[className]) cls = getattr(module, className) - SdrService.sources[id] = cls(id, props, SdrService.getNextPort()) + SdrService.sources[id] = cls(id, props) return {key: s for key, s in SdrService.sources.items() if not s.isFailed()} diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index cc78fe3..7b26444 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -8,6 +8,7 @@ import time import signal from abc import ABC, abstractmethod from owrx.command import CommandMapper +from owrx.socket import getAvailablePort import logging @@ -29,7 +30,7 @@ class SdrSource(ABC): CLIENT_BACKGROUND = 1 CLIENT_USER = 2 - def __init__(self, id, props, port): + def __init__(self, id, props): self.id = id self.props = props self.profile_id = None @@ -38,7 +39,10 @@ class SdrSource(ABC): self.wireEvents() self.commandMapper = CommandMapper() - self.port = port + if "port" in props and props["port"] is not None: + self.port = props["port"] + else: + self.port = getAvailablePort() self.monitor = None self.clients = [] self.spectrumClients = [] diff --git a/owrx/source/airspy.py b/owrx/source/airspy.py index 571302b..16878e6 100644 --- a/owrx/source/airspy.py +++ b/owrx/source/airspy.py @@ -3,8 +3,8 @@ from .soapy import SoapyConnectorSource class AirspySource(SoapyConnectorSource): - def __init__(self, id, props, port): - super().__init__(id, props, port) + def __init__(self, id, props): + super().__init__(id, props) self.getCommandMapper().setMappings({"bias_tee": Flag("-t biastee=true")}) def getDriver(self): diff --git a/owrx/source/connector.py b/owrx/source/connector.py index 2a9dd03..9c705e9 100644 --- a/owrx/source/connector.py +++ b/owrx/source/connector.py @@ -9,8 +9,8 @@ logger = logging.getLogger(__name__) class ConnectorSource(SdrSource): - def __init__(self, id, props, port): - super().__init__(id, props, port) + def __init__(self, id, props): + super().__init__(id, props) self.controlSocket = None self.controlPort = getAvailablePort() self.getCommandMapper().setMappings( diff --git a/owrx/source/fifi_sdr.py b/owrx/source/fifi_sdr.py index 7c65d3b..64517a9 100644 --- a/owrx/source/fifi_sdr.py +++ b/owrx/source/fifi_sdr.py @@ -3,8 +3,8 @@ from .direct import DirectSource class FifiSdrSource(DirectSource): - def __init__(self, id, props, port): - super().__init__(id, props, port) + def __init__(self, id, props): + super().__init__(id, props) self.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 f689bbc..cd1ef1f 100644 --- a/owrx/source/hackrf.py +++ b/owrx/source/hackrf.py @@ -3,8 +3,8 @@ from owrx.command import Flag, Option class HackrfSource(DirectSource): - def __init__(self, id, props, port): - super().__init__(id, props, port) + def __init__(self, id, props): + super().__init__(id, props) self.getCommandMapper().setBase("hackrf_transfer").setMappings( { "samp_rate": Option("-s"), diff --git a/owrx/source/resampler.py b/owrx/source/resampler.py index 327144e..6afe50c 100644 --- a/owrx/source/resampler.py +++ b/owrx/source/resampler.py @@ -15,7 +15,7 @@ class Resampler(DirectSource): def onPropertyChange(self, name, value): logger.warning("Resampler is unable to handle property change ({0} changed to {1})".format(name, value)) - def __init__(self, props, port, sdr): + def __init__(self, props, sdr): sdrProps = sdr.getProps() self.shift = (sdrProps["center_freq"] - props["center_freq"]) / sdrProps["samp_rate"] self.decimation = int(float(sdrProps["samp_rate"]) / props["samp_rate"]) @@ -24,7 +24,7 @@ class Resampler(DirectSource): props["samp_rate"] = if_samp_rate self.sdr = sdr - super().__init__(None, props, port) + super().__init__(None, props) def getCommand(self): return [ diff --git a/owrx/source/rtl_sdr.py b/owrx/source/rtl_sdr.py index e7b53da..b30378a 100644 --- a/owrx/source/rtl_sdr.py +++ b/owrx/source/rtl_sdr.py @@ -2,6 +2,6 @@ from .connector import ConnectorSource class RtlSdrSource(ConnectorSource): - def __init__(self, id, props, port): - super().__init__(id, props, port) + def __init__(self, id, props): + super().__init__(id, props) self.getCommandMapper().setBase("rtl_connector") diff --git a/owrx/source/soapy.py b/owrx/source/soapy.py index 40510f6..249dd5e 100644 --- a/owrx/source/soapy.py +++ b/owrx/source/soapy.py @@ -5,8 +5,8 @@ from .connector import ConnectorSource class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta): - def __init__(self, id, props, port): - super().__init__(id, props, port) + def __init__(self, id, props): + super().__init__(id, props) self.getCommandMapper().setBase("soapy_connector").setMappings({"antenna": Option("-a")}) """