new status controller as json
This commit is contained in:
parent
16b3c11678
commit
eaa98b0d64
@ -11,13 +11,15 @@ from owrx.connection import WebSocketMessageHandler
|
|||||||
from owrx.version import openwebrx_version
|
from owrx.version import openwebrx_version
|
||||||
from owrx.feature import FeatureDetector
|
from owrx.feature import FeatureDetector
|
||||||
from owrx.metrics import Metrics
|
from owrx.metrics import Metrics
|
||||||
|
from owrx.sdr import SdrService
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(ABC):
|
||||||
def __init__(self, handler, request):
|
def __init__(self, handler, request):
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
self.request = request
|
self.request = request
|
||||||
@ -35,6 +37,10 @@ class Controller(object):
|
|||||||
content = content.encode()
|
content = content.encode()
|
||||||
self.handler.wfile.write(content)
|
self.handler.wfile.write(content)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def handle_request(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class StatusController(Controller):
|
class StatusController(Controller):
|
||||||
def handle_request(self):
|
def handle_request(self):
|
||||||
@ -55,6 +61,42 @@ class StatusController(Controller):
|
|||||||
self.send_response("\n".join(["{key}={value}".format(key=key, value=value) for key, value in vars.items()]))
|
self.send_response("\n".join(["{key}={value}".format(key=key, value=value) for key, value in vars.items()]))
|
||||||
|
|
||||||
|
|
||||||
|
class StatusJsonController(Controller):
|
||||||
|
def getProfileStats(self, profile):
|
||||||
|
return {
|
||||||
|
"name": profile["name"],
|
||||||
|
"center_freq": profile["center_freq"],
|
||||||
|
"sample_rate": profile["samp_rate"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def getReceiverStats(self, receiver):
|
||||||
|
stats = {
|
||||||
|
"name": receiver.getName(),
|
||||||
|
# TODO would be better to have types from the config here
|
||||||
|
"type": type(receiver).__name__,
|
||||||
|
"profiles": [self.getProfileStats(p) for p in receiver.getProfiles().values()]
|
||||||
|
}
|
||||||
|
return stats
|
||||||
|
|
||||||
|
def handle_request(self):
|
||||||
|
pm = PropertyManager.getSharedInstance()
|
||||||
|
|
||||||
|
gps = pm["receiver_gps"]
|
||||||
|
status = {
|
||||||
|
"receiver": {
|
||||||
|
"name": pm["receiver_name"],
|
||||||
|
"admin": pm["receiver_admin"],
|
||||||
|
"gps": {"lat": gps[0], "lon": gps[1]},
|
||||||
|
"asl": pm["receiver_asl"],
|
||||||
|
"location": pm["receiver_location"],
|
||||||
|
},
|
||||||
|
"max_clients": pm["max_clients"],
|
||||||
|
"version": openwebrx_version,
|
||||||
|
"sdrs": [self.getReceiverStats(r) for r in SdrService.getSources().values()]
|
||||||
|
}
|
||||||
|
self.send_response(json.dumps(status), content_type="application/json")
|
||||||
|
|
||||||
|
|
||||||
class AssetsController(Controller):
|
class AssetsController(Controller):
|
||||||
def getModified(self, file):
|
def getModified(self, file):
|
||||||
return None
|
return None
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from owrx.controllers import (
|
from owrx.controllers import (
|
||||||
StatusController,
|
StatusController,
|
||||||
|
StatusJsonController,
|
||||||
IndexController,
|
IndexController,
|
||||||
OwrxAssetsController,
|
OwrxAssetsController,
|
||||||
WebSocketController,
|
WebSocketController,
|
||||||
@ -41,6 +42,7 @@ class Router(object):
|
|||||||
mappings = [
|
mappings = [
|
||||||
{"route": "/", "controller": IndexController},
|
{"route": "/", "controller": IndexController},
|
||||||
{"route": "/status", "controller": StatusController},
|
{"route": "/status", "controller": StatusController},
|
||||||
|
{"route": "/status.json", "controller": StatusJsonController},
|
||||||
{"regex": "/static/(.+)", "controller": OwrxAssetsController},
|
{"regex": "/static/(.+)", "controller": OwrxAssetsController},
|
||||||
{"regex": "/aprs-symbols/(.+)", "controller": AprsSymbolsController},
|
{"regex": "/aprs-symbols/(.+)", "controller": AprsSymbolsController},
|
||||||
{"route": "/ws/", "controller": WebSocketController},
|
{"route": "/ws/", "controller": WebSocketController},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user