attempt to select new sdr on failure

This commit is contained in:
Jakob Ketterl 2019-12-23 21:12:28 +01:00
parent 7793609fa4
commit 46b5e9034f
4 changed files with 49 additions and 25 deletions

View File

@ -2,6 +2,7 @@ from owrx.config import PropertyManager
from owrx.dsp import DspManager
from owrx.cpu import CpuUsageThread
from owrx.sdr import SdrService
from owrx.source import SdrSource
from owrx.client import ClientRegistry
from owrx.feature import FeatureDetector
from owrx.version import openwebrx_version
@ -107,6 +108,14 @@ class OpenWebRxReceiverClient(Client):
receiver_details["locator"] = Locator.fromCoordinates(receiver_details["receiver_gps"])
self.write_receiver_details(receiver_details)
self.__sendProfiles()
features = FeatureDetector().feature_availability()
self.write_features(features)
CpuUsageThread.getSharedInstance().add_client(self)
def __sendProfiles(self):
profiles = [
{"name": s.getName() + " " + p["name"], "id": sid + "|" + pid}
for (sid, s) in SdrService.getSources().items()
@ -114,11 +123,6 @@ class OpenWebRxReceiverClient(Client):
]
self.write_profiles(profiles)
features = FeatureDetector().feature_availability()
self.write_features(features)
CpuUsageThread.getSharedInstance().add_client(self)
def handleTextMessage(self, conn, message):
try:
message = json.loads(message)
@ -155,12 +159,18 @@ class OpenWebRxReceiverClient(Client):
logger.warning("message is not json: {0}".format(message))
def setSdr(self, id=None):
while True:
next = None
if id is not None:
next = SdrService.getSource(id)
if next is None:
self.handleSdrFailure("sdr device unavailable")
next = SdrService.getFirstSource()
if next is None:
# exit condition: no sdrs available
self.handleNoSdrsAvailable()
return
# exit condition: no change
if next == self.sdr:
return
@ -174,6 +184,10 @@ class OpenWebRxReceiverClient(Client):
self.startDsp()
# keep trying until we find a suitable SDR
if self.sdr.getState() != SdrSource.STATE_FAILED:
break
# send initial config
self.setDspProperties(self.connectionProperties)
@ -200,11 +214,12 @@ class OpenWebRxReceiverClient(Client):
self.configSub = configProps.wire(sendConfig)
sendConfig(None, None)
self.__sendProfiles()
self.sdr.addSpectrumClient(self)
def handleSdrFailure(self, message):
self.write_sdr_error(message)
def handleNoSdrsAvailable(self):
self.write_sdr_error("No SDR Devices available")
def startDsp(self):
if self.dsp is None and self.sdr is not None:

View File

@ -146,7 +146,6 @@ class DspManager(csdr.output):
elif state == SdrSource.STATE_FAILED:
logger.debug("received STATE_FAILED, shutting down DspSource")
self.dsp.stop()
self.handler.handleSdrFailure("sdr device failed")
def onBusyStateChange(self, state):
pass

View File

@ -63,15 +63,19 @@ class SdrService(object):
)
@staticmethod
def getSource(id=None):
def getFirstSource():
sources = SdrService.getSources()
if not sources:
return None
# TODO: configure default sdr in config? right now it will pick the first one off the list.
return sources[list(sources.keys())[0]]
@staticmethod
def getSource(id):
SdrService.loadProps()
sources = SdrService.getSources()
if not sources:
return None
if id is None:
# TODO: configure default sdr in config? right now it will pick the first one off the list.
id = list(sources.keys())[0]
if not id in sources:
return None
return sources[id]

View File

@ -80,6 +80,9 @@ class SdrSource(object):
profiles = self.props["profiles"]
if profile_id is None:
profile_id = list(profiles.keys())[0]
if profile_id not in profiles:
logger.warning("invalid profile %s for sdr %s. ignoring", profile_id, self.id)
return
if profile_id == self.profile_id:
return
logger.debug("activating profile {0}".format(profile_id))
@ -275,6 +278,9 @@ class SdrSource(object):
for c in self.spectrumClients:
c.write_spectrum_data(data)
def getState(self):
return self.state
def setState(self, state):
if state == self.state:
return