add the ability to disable devices

This commit is contained in:
Jakob Ketterl 2021-02-21 18:11:08 +01:00
parent 7f3d421b25
commit bd31fa5149
2 changed files with 22 additions and 14 deletions

View File

@ -1,6 +1,7 @@
from owrx.config import Config from owrx.config import Config
from owrx.property import PropertyLayer from owrx.property import PropertyLayer
from owrx.feature import FeatureDetector, UnknownFeatureException from owrx.feature import FeatureDetector, UnknownFeatureException
from owrx.source import SdrSourceState
import logging import logging
@ -78,4 +79,8 @@ class SdrService(object):
module = __import__("owrx.source.{0}".format(sdrType), fromlist=[className]) module = __import__("owrx.source.{0}".format(sdrType), fromlist=[className])
cls = getattr(module, className) cls = getattr(module, className)
SdrService.sources[id] = cls(id, props) SdrService.sources[id] = cls(id, props)
return {key: s for key, s in SdrService.sources.items() if not s.isFailed()} return {
key: s
for key, s in SdrService.sources.items()
if s.getState() not in [SdrSourceState.FAILED, SdrSourceState.DISABLED]
}

View File

@ -29,6 +29,7 @@ class SdrSourceState(Enum):
STOPPING = "Stopping" STOPPING = "Stopping"
TUNING = "Tuning" TUNING = "Tuning"
FAILED = "Failed" FAILED = "Failed"
DISABLED = "Disabled"
def __str__(self): def __str__(self):
return self.value return self.value
@ -87,13 +88,12 @@ class SdrSource(ABC):
self.spectrumLock = threading.Lock() self.spectrumLock = threading.Lock()
self.process = None self.process = None
self.modificationLock = threading.Lock() self.modificationLock = threading.Lock()
self.failed = False self.state = SdrSourceState.STOPPED if "enabled" not in props or props["enabled"] else SdrSourceState.DISABLED
self.state = SdrSourceState.STOPPED
self.busyState = SdrBusyState.IDLE self.busyState = SdrBusyState.IDLE
self.validateProfiles() self.validateProfiles()
if self.isAlwaysOn(): if self.isAlwaysOn() and self.state is not SdrSourceState.DISABLED:
self.start() self.start()
def validateProfiles(self): def validateProfiles(self):
@ -198,7 +198,7 @@ class SdrSource(ABC):
if self.monitor: if self.monitor:
return return
if self.isFailed(): if self.getState() is SdrSourceState.FAILED:
return return
try: try:
@ -223,13 +223,15 @@ class SdrSource(ABC):
logger.info("Started sdr source: " + cmd) logger.info("Started sdr source: " + cmd)
available = False available = False
failed = False
def wait_for_process_to_end(): def wait_for_process_to_end():
nonlocal failed
rc = self.process.wait() rc = self.process.wait()
logger.debug("shut down with RC={0}".format(rc)) logger.debug("shut down with RC={0}".format(rc))
self.monitor = None self.monitor = None
if self.getState() is SdrSourceState.RUNNING: if self.getState() is SdrSourceState.RUNNING:
self.failed = True failed = True
self.setState(SdrSourceState.FAILED) self.setState(SdrSourceState.FAILED)
else: else:
self.setState(SdrSourceState.STOPPED) self.setState(SdrSourceState.STOPPED)
@ -238,7 +240,7 @@ class SdrSource(ABC):
self.monitor.start() self.monitor.start()
retries = 1000 retries = 1000
while retries > 0 and not self.isFailed(): while retries > 0 and not failed:
retries -= 1 retries -= 1
if self.monitor is None: if self.monitor is None:
break break
@ -252,15 +254,15 @@ class SdrSource(ABC):
time.sleep(0.1) time.sleep(0.1)
if not available: if not available:
self.failed = True failed = True
try: try:
self.postStart() self.postStart()
except Exception: except Exception:
logger.exception("Exception during postStart()") logger.exception("Exception during postStart()")
self.failed = True failed = True
self.setState(SdrSourceState.FAILED if self.failed else SdrSourceState.RUNNING) self.setState(SdrSourceState.FAILED if failed else SdrSourceState.RUNNING)
def preStart(self): def preStart(self):
""" """
@ -277,11 +279,11 @@ class SdrSource(ABC):
def isAvailable(self): def isAvailable(self):
return self.monitor is not None return self.monitor is not None
def isFailed(self):
return self.failed
def stop(self): def stop(self):
self.setState(SdrSourceState.STOPPING) # don't overwrite failed flag
# TODO introduce a better solution?
if self.getState() is not SdrSourceState.FAILED:
self.setState(SdrSourceState.STOPPING)
with self.modificationLock: with self.modificationLock:
@ -387,6 +389,7 @@ class SdrDeviceDescription(object):
def getInputs(self) -> List[Input]: def getInputs(self) -> List[Input]:
return [ return [
TextInput("name", "Device name"), TextInput("name", "Device name"),
CheckboxInput("enabled", "", "Enable this device", converter=OptionalConverter(defaultFormValue=True)),
NumberInput( NumberInput(
"ppm", "ppm",
"Frequency correction", "Frequency correction",