fix problems with sdr device failover detection
This commit is contained in:
parent
efa9771ad7
commit
eab3bf780e
@ -15,6 +15,7 @@ from owrx.modes import Modes, DigitalMode
|
|||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from queue import Full
|
from queue import Full
|
||||||
from js8py import Js8Frame
|
from js8py import Js8Frame
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ import logging
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Client(object):
|
class Client(ABC):
|
||||||
def __init__(self, conn):
|
def __init__(self, conn):
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
self.multiprocessingPipe = Queue(100)
|
self.multiprocessingPipe = Queue(100)
|
||||||
@ -52,6 +53,7 @@ class Client(object):
|
|||||||
except Full:
|
except Full:
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def handleTextMessage(self, conn, message):
|
def handleTextMessage(self, conn, message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -145,8 +147,12 @@ class OpenWebRxReceiverClient(Client):
|
|||||||
self.startDsp()
|
self.startDsp()
|
||||||
|
|
||||||
if "params" in message:
|
if "params" in message:
|
||||||
params = message["params"]
|
dsp = self.getDsp()
|
||||||
self.getDsp().setProperties(params)
|
if dsp is None:
|
||||||
|
logger.warning("DSP not available; discarding client data")
|
||||||
|
else:
|
||||||
|
params = message["params"]
|
||||||
|
dsp.setProperties(params)
|
||||||
|
|
||||||
elif message["type"] == "config":
|
elif message["type"] == "config":
|
||||||
if "params" in message:
|
if "params" in message:
|
||||||
@ -172,27 +178,38 @@ class OpenWebRxReceiverClient(Client):
|
|||||||
logger.warning("message is not json: {0}".format(message))
|
logger.warning("message is not json: {0}".format(message))
|
||||||
|
|
||||||
def setSdr(self, id=None):
|
def setSdr(self, id=None):
|
||||||
next = None
|
while True:
|
||||||
if id is not None:
|
next = None
|
||||||
next = SdrService.getSource(id)
|
if id is not None:
|
||||||
if next is None:
|
next = SdrService.getSource(id)
|
||||||
next = SdrService.getFirstSource()
|
if next is None:
|
||||||
if next is None:
|
next = SdrService.getFirstSource()
|
||||||
# exit condition: no sdrs available
|
if next is None:
|
||||||
self.handleNoSdrsAvailable()
|
# exit condition: no sdrs available
|
||||||
return
|
logger.warning("no more SDR devices available")
|
||||||
|
self.handleNoSdrsAvailable()
|
||||||
|
return
|
||||||
|
|
||||||
# exit condition: no change
|
# exit condition: no change
|
||||||
if next == self.sdr:
|
if next == self.sdr:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.stopDsp()
|
self.stopDsp()
|
||||||
|
|
||||||
if self.configSub is not None:
|
if self.configSub is not None:
|
||||||
self.configSub.cancel()
|
self.configSub.cancel()
|
||||||
self.configSub = None
|
self.configSub = None
|
||||||
|
|
||||||
self.sdr = next
|
self.sdr = next
|
||||||
|
|
||||||
|
self.getDsp()
|
||||||
|
|
||||||
|
# found a working sdr, exit the loop
|
||||||
|
if self.sdr.getState() != SdrSource.STATE_FAILED:
|
||||||
|
break
|
||||||
|
|
||||||
|
logger.warning('SDR device "%s" has failed, selecing new device', self.sdr.getName())
|
||||||
|
self.write_log_message('SDR device "{0}" has failed, selecting new device'.format(self.sdr.getName()))
|
||||||
|
|
||||||
# send initial config
|
# send initial config
|
||||||
self.getDsp().setProperties(self.connectionProperties)
|
self.getDsp().setProperties(self.connectionProperties)
|
||||||
@ -227,13 +244,7 @@ class OpenWebRxReceiverClient(Client):
|
|||||||
self.write_sdr_error("No SDR Devices available")
|
self.write_sdr_error("No SDR Devices available")
|
||||||
|
|
||||||
def startDsp(self):
|
def startDsp(self):
|
||||||
while True:
|
self.getDsp().start()
|
||||||
self.getDsp().start()
|
|
||||||
if self.sdr.getState() == SdrSource.STATE_FAILED:
|
|
||||||
self.write_log_message('SDR device "{0}" has failed, selecting new device'.format(self.sdr.getName()))
|
|
||||||
self.setSdr()
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.stopDsp()
|
self.stopDsp()
|
||||||
@ -271,7 +282,7 @@ class OpenWebRxReceiverClient(Client):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def getDsp(self):
|
def getDsp(self):
|
||||||
if self.dsp is None:
|
if self.dsp is None and self.sdr is not None:
|
||||||
self.dsp = DspManager(self, self.sdr)
|
self.dsp = DspManager(self, self.sdr)
|
||||||
return self.dsp
|
return self.dsp
|
||||||
|
|
||||||
|
@ -199,9 +199,15 @@ class WebSocketConnection(object):
|
|||||||
data = bytes([b ^ masking_key[index % 4] for (index, b) in enumerate(data)])
|
data = bytes([b ^ masking_key[index % 4] for (index, b) in enumerate(data)])
|
||||||
if opcode == OPCODE_TEXT_MESSAGE:
|
if opcode == OPCODE_TEXT_MESSAGE:
|
||||||
message = data.decode("utf-8")
|
message = data.decode("utf-8")
|
||||||
self.messageHandler.handleTextMessage(self, message)
|
try:
|
||||||
|
self.messageHandler.handleTextMessage(self, message)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Exception in websocket handler handleTextMessage()")
|
||||||
elif opcode == OPCODE_BINARY_MESSAGE:
|
elif opcode == OPCODE_BINARY_MESSAGE:
|
||||||
self.messageHandler.handleBinaryMessage(self, data)
|
try:
|
||||||
|
self.messageHandler.handleBinaryMessage(self, data)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Exception in websocket handler handleBinaryMessage()")
|
||||||
elif opcode == OPCODE_PING:
|
elif opcode == OPCODE_PING:
|
||||||
self.sendPong()
|
self.sendPong()
|
||||||
elif opcode == OPCODE_PONG:
|
elif opcode == OPCODE_PONG:
|
||||||
|
Loading…
Reference in New Issue
Block a user