make wsprnet and pskreporter settings work from the web config
This commit is contained in:
parent
ebd4d93908
commit
5487861da1
@ -1,58 +0,0 @@
|
||||
import threading
|
||||
from abc import ABC, abstractmethod
|
||||
from owrx.config import Config
|
||||
|
||||
|
||||
class Reporter(ABC):
|
||||
@abstractmethod
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def spot(self, spot):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def getSupportedModes(self):
|
||||
return []
|
||||
|
||||
|
||||
class ReportingEngine(object):
|
||||
creationLock = threading.Lock()
|
||||
sharedInstance = None
|
||||
|
||||
@staticmethod
|
||||
def getSharedInstance():
|
||||
with ReportingEngine.creationLock:
|
||||
if ReportingEngine.sharedInstance is None:
|
||||
ReportingEngine.sharedInstance = ReportingEngine()
|
||||
return ReportingEngine.sharedInstance
|
||||
|
||||
@staticmethod
|
||||
def stopAll():
|
||||
with ReportingEngine.creationLock:
|
||||
if ReportingEngine.sharedInstance is not None:
|
||||
ReportingEngine.sharedInstance.stop()
|
||||
|
||||
def __init__(self):
|
||||
self.reporters = []
|
||||
config = Config.get()
|
||||
if "pskreporter_enabled" in config and config["pskreporter_enabled"]:
|
||||
# inline import due to circular dependencies
|
||||
from owrx.pskreporter import PskReporter
|
||||
|
||||
self.reporters += [PskReporter()]
|
||||
if "wsprnet_enabled" in config and config["wsprnet_enabled"]:
|
||||
# inline import due to circular dependencies
|
||||
from owrx.wsprnet import WsprnetReporter
|
||||
|
||||
self.reporters += [WsprnetReporter()]
|
||||
|
||||
def stop(self):
|
||||
for r in self.reporters:
|
||||
r.stop()
|
||||
|
||||
def spot(self, spot):
|
||||
for r in self.reporters:
|
||||
if spot["mode"] in r.getSupportedModes():
|
||||
r.spot(spot)
|
57
owrx/reporting/__init__.py
Normal file
57
owrx/reporting/__init__.py
Normal file
@ -0,0 +1,57 @@
|
||||
import threading
|
||||
from owrx.config import Config
|
||||
from owrx.reporting.reporter import Reporter
|
||||
from owrx.reporting.pskreporter import PskReporter
|
||||
from owrx.reporting.wsprnet import WsprnetReporter
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReportingEngine(object):
|
||||
creationLock = threading.Lock()
|
||||
sharedInstance = None
|
||||
|
||||
reporterClasses = {
|
||||
"pskreporter_enabled": PskReporter,
|
||||
"wsprnet_enabled": WsprnetReporter,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def getSharedInstance():
|
||||
with ReportingEngine.creationLock:
|
||||
if ReportingEngine.sharedInstance is None:
|
||||
ReportingEngine.sharedInstance = ReportingEngine()
|
||||
return ReportingEngine.sharedInstance
|
||||
|
||||
@staticmethod
|
||||
def stopAll():
|
||||
with ReportingEngine.creationLock:
|
||||
if ReportingEngine.sharedInstance is not None:
|
||||
ReportingEngine.sharedInstance.stop()
|
||||
|
||||
def __init__(self):
|
||||
self.reporters = []
|
||||
self.configSub = Config.get().filter(*ReportingEngine.reporterClasses.keys()).wire(self.setupReporters)
|
||||
self.setupReporters()
|
||||
|
||||
def setupReporters(self, *args):
|
||||
config = Config.get()
|
||||
for configKey, reporterClass in ReportingEngine.reporterClasses.items():
|
||||
if configKey in config and config[configKey]:
|
||||
if not any(isinstance(r, reporterClass) for r in self.reporters):
|
||||
self.reporters += [reporterClass()]
|
||||
else:
|
||||
for reporter in [r for r in self.reporters if isinstance(r, reporterClass)]:
|
||||
reporter.stop()
|
||||
self.reporters.remove(reporter)
|
||||
|
||||
def stop(self):
|
||||
for r in self.reporters:
|
||||
r.stop()
|
||||
self.configSub.cancel()
|
||||
|
||||
def spot(self, spot):
|
||||
for r in self.reporters:
|
||||
if spot["mode"] in r.getSupportedModes():
|
||||
r.spot(spot)
|
@ -9,7 +9,7 @@ from owrx.config import Config
|
||||
from owrx.version import openwebrx_version
|
||||
from owrx.locator import Locator
|
||||
from owrx.metrics import Metrics, CounterMetric
|
||||
from owrx.reporting import Reporter
|
||||
from owrx.reporting.reporter import Reporter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -22,6 +22,8 @@ class PskReporter(Reporter):
|
||||
|
||||
def stop(self):
|
||||
self.cancelTimer()
|
||||
with self.spotLock:
|
||||
self.spots = []
|
||||
|
||||
def __init__(self):
|
||||
self.spots = []
|
15
owrx/reporting/reporter.py
Normal file
15
owrx/reporting/reporter.py
Normal file
@ -0,0 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class Reporter(ABC):
|
||||
@abstractmethod
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def spot(self, spot):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def getSupportedModes(self):
|
||||
return []
|
@ -1,4 +1,4 @@
|
||||
from owrx.reporting import Reporter
|
||||
from owrx.reporting.reporter import Reporter
|
||||
from owrx.version import openwebrx_version
|
||||
from owrx.config import Config
|
||||
from owrx.locator import Locator
|
||||
@ -12,14 +12,13 @@ from datetime import datetime, timezone
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
PoisonPill = object()
|
||||
|
||||
|
||||
class Worker(threading.Thread):
|
||||
def __init__(self, queue: Queue):
|
||||
self.queue = queue
|
||||
self.doRun = True
|
||||
# some constants that we don't expect to change
|
||||
config = Config.get()
|
||||
self.callsign = config["wsprnet_callsign"]
|
||||
self.locator = Locator.fromCoordinates(config["receiver_gps"])
|
||||
|
||||
super().__init__(daemon=True)
|
||||
|
||||
@ -27,6 +26,9 @@ class Worker(threading.Thread):
|
||||
while self.doRun:
|
||||
try:
|
||||
spot = self.queue.get()
|
||||
if spot is PoisonPill:
|
||||
self.doRun = False
|
||||
else:
|
||||
self.uploadSpot(spot)
|
||||
self.queue.task_done()
|
||||
except Exception:
|
||||
@ -40,6 +42,7 @@ class Worker(threading.Thread):
|
||||
return interval
|
||||
|
||||
def uploadSpot(self, spot):
|
||||
config = Config.get()
|
||||
# function=wspr&date=210114&time=1732&sig=-15&dt=0.5&drift=0&tqrg=7.040019&tcall=DF2UU&tgrid=JN48&dbm=37&version=2.3.0-rc3&rcall=DD5JFK&rgrid=JN58SC&rqrg=7.040047&mode=2
|
||||
# {'timestamp': 1610655960000, 'db': -23.0, 'dt': 0.3, 'freq': 7040048, 'drift': -1, 'msg': 'LA3JJ JO59 37', 'callsign': 'LA3JJ', 'locator': 'JO59', 'mode': 'WSPR'}
|
||||
date = datetime.fromtimestamp(spot["timestamp"] / 1000, tz=timezone.utc)
|
||||
@ -57,9 +60,8 @@ class Worker(threading.Thread):
|
||||
"tgrid": spot["locator"],
|
||||
"dbm": spot["dbm"],
|
||||
"version": openwebrx_version,
|
||||
"rcall": self.callsign,
|
||||
"rgrid": self.locator,
|
||||
# mode 2 = WSPR 2 minutes
|
||||
"rcall": config["wsprnet_callsign"],
|
||||
"rgrid": Locator.fromCoordinates(config["receiver_gps"]),
|
||||
"mode": self._getMode(spot),
|
||||
}
|
||||
).encode()
|
||||
@ -79,7 +81,10 @@ class WsprnetReporter(Reporter):
|
||||
metrics.addMetric("wsprnet.spots", self.spotCounter)
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
while not self.queue.empty():
|
||||
self.queue.get(timeout=1)
|
||||
self.queue.task_done()
|
||||
self.queue.put(PoisonPill)
|
||||
|
||||
def spot(self, spot):
|
||||
try:
|
Loading…
Reference in New Issue
Block a user