2020-02-23 16:22:13 +00:00
|
|
|
from . import Controller
|
|
|
|
from owrx.client import ClientRegistry
|
|
|
|
from owrx.version import openwebrx_version
|
|
|
|
from owrx.sdr import SdrService
|
2020-03-21 21:40:39 +00:00
|
|
|
from owrx.config import Config
|
2020-02-23 16:22:13 +00:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
class StatusController(Controller):
|
2020-02-23 17:32:37 +00:00
|
|
|
def indexAction(self):
|
2020-03-21 21:40:39 +00:00
|
|
|
pm = Config.get()
|
2020-03-29 16:08:26 +00:00
|
|
|
# convert to old format
|
|
|
|
gps = (pm["receiver_gps"]["lat"], pm["receiver_gps"]["lon"])
|
2020-02-23 16:22:13 +00:00
|
|
|
# TODO keys that have been left out since they are no longer simple strings: sdr_hw, bands, antenna
|
|
|
|
vars = {
|
|
|
|
"status": "active",
|
|
|
|
"name": pm["receiver_name"],
|
|
|
|
"op_email": pm["receiver_admin"],
|
|
|
|
"users": ClientRegistry.getSharedInstance().clientCount(),
|
|
|
|
"users_max": pm["max_clients"],
|
2020-03-29 16:08:26 +00:00
|
|
|
"gps": gps,
|
2020-02-23 16:22:13 +00:00
|
|
|
"asl": pm["receiver_asl"],
|
|
|
|
"loc": pm["receiver_location"],
|
|
|
|
"sw_version": openwebrx_version,
|
|
|
|
"avatar_ctime": os.path.getctime("htdocs/gfx/openwebrx-avatar.png"),
|
|
|
|
}
|
|
|
|
self.send_response("\n".join(["{key}={value}".format(key=key, value=value) for key, value in vars.items()]))
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-02-23 17:32:37 +00:00
|
|
|
def jsonAction(self):
|
2020-03-21 21:40:39 +00:00
|
|
|
pm = Config.get()
|
2020-02-23 16:22:13 +00:00
|
|
|
|
|
|
|
status = {
|
|
|
|
"receiver": {
|
|
|
|
"name": pm["receiver_name"],
|
|
|
|
"admin": pm["receiver_admin"],
|
2020-03-29 16:08:26 +00:00
|
|
|
"gps": pm["receiver_gps"],
|
2020-02-23 16:22:13 +00:00
|
|
|
"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")
|