split config into global and device config

* less config properties sent to the client
This commit is contained in:
Jakob Ketterl 2020-12-31 23:03:36 +01:00
parent 9674af10ce
commit 90f319ebda
2 changed files with 34 additions and 18 deletions

View File

@ -736,7 +736,9 @@ function on_ws_recv(evt) {
if ('max_clients' in config) if ('max_clients' in config)
$('#openwebrx-bar-clients').progressbar().setMaxClients(config['max_clients']); $('#openwebrx-bar-clients').progressbar().setMaxClients(config['max_clients']);
if (typeof(bandwidth) != 'undefined')
waterfall_init(); waterfall_init();
var demodulatorPanel = $('#openwebrx-panel-receiver').demodulatorPanel(); var demodulatorPanel = $('#openwebrx-panel-receiver').demodulatorPanel();
demodulatorPanel.setCenterFrequency(center_freq); demodulatorPanel.setCenterFrequency(center_freq);
demodulatorPanel.setInitialParams(initial_demodulator_params); demodulatorPanel.setInitialParams(initial_demodulator_params);
@ -744,13 +746,14 @@ function on_ws_recv(evt) {
demodulatorPanel.setSquelchMargin(config['squelch_auto_margin']); demodulatorPanel.setSquelchMargin(config['squelch_auto_margin']);
bookmarks.loadLocalBookmarks(); bookmarks.loadLocalBookmarks();
waterfall_clear();
if ('sdr_id' in config && 'profile_id' in config) { if ('sdr_id' in config && 'profile_id' in config) {
currentprofile = config['sdr_id'] + '|' + config['profile_id']; currentprofile = config['sdr_id'] + '|' + config['profile_id'];
$('#openwebrx-sdr-profiles-listbox').val(currentprofile); $('#openwebrx-sdr-profiles-listbox').val(currentprofile);
} }
if (typeof(bandwidth) != 'undefined')
waterfall_clear();
if ('frequency_display_precision' in config) if ('frequency_display_precision' in config)
$('#openwebrx-panel-receiver').demodulatorPanel().setFrequencyPrecision(config['frequency_display_precision']); $('#openwebrx-panel-receiver').demodulatorPanel().setFrequencyPrecision(config['frequency_display_precision']);

View File

@ -12,6 +12,7 @@ from owrx.bookmarks import Bookmarks
from owrx.map import Map from owrx.map import Map
from owrx.property import PropertyStack from owrx.property import PropertyStack
from owrx.modes import Modes, DigitalMode from owrx.modes import Modes, DigitalMode
from owrx.config import Config
from queue import Queue, Full, Empty from queue import Queue, Full, Empty
from js8py import Js8Frame from js8py import Js8Frame
from abc import ABC, ABCMeta, abstractmethod from abc import ABC, ABCMeta, abstractmethod
@ -108,22 +109,26 @@ class OpenWebRxClient(Client, metaclass=ABCMeta):
class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient): class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
config_keys = [ sdr_config_keys = [
"waterfall_colors", "waterfall_min_level",
"waterfall_min_level", "waterfall_min_level",
"waterfall_max_level", "waterfall_max_level",
"waterfall_auto_level_margin",
"samp_rate", "samp_rate",
"fft_size",
"audio_compression",
"fft_compression",
"max_clients",
"start_mod", "start_mod",
"start_freq", "start_freq",
"center_freq", "center_freq",
"initial_squelch_level", "initial_squelch_level",
"profile_id", "profile_id",
"squelch_auto_margin", "squelch_auto_margin",
]
global_config_keys = [
"waterfall_colors",
"waterfall_auto_level_margin",
"fft_size",
"audio_compression",
"fft_compression",
"max_clients",
"frequency_display_precision", "frequency_display_precision",
] ]
@ -132,7 +137,7 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
self.dsp = None self.dsp = None
self.sdr = None self.sdr = None
self.configSubs = [] self.sdrConfigSubs = []
self.connectionProperties = {} self.connectionProperties = {}
try: try:
@ -142,6 +147,10 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
self.close() self.close()
raise raise
globalConfig = Config.get().filter(*OpenWebRxReceiverClient.global_config_keys)
self.globalConfigSub = globalConfig.wire(self.write_config)
self.write_config(globalConfig.__dict__())
self.setSdr() self.setSdr()
features = FeatureDetector().feature_availability() features = FeatureDetector().feature_availability()
@ -154,6 +163,10 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
CpuUsageThread.getSharedInstance().add_client(self) CpuUsageThread.getSharedInstance().add_client(self)
def __del__(self):
if hasattr(self, "globalConfigSub"):
self.globalConfigSub.cancel()
def onStateChange(self, state): def onStateChange(self, state):
if state == SdrSource.STATE_RUNNING: if state == SdrSource.STATE_RUNNING:
self.handleSdrAvailable() self.handleSdrAvailable()
@ -231,8 +244,8 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
self.stopDsp() self.stopDsp()
while self.configSubs: while self.sdrConfigSubs:
self.configSubs.pop().cancel() self.sdrConfigSubs.pop().cancel()
if self.sdr is not None: if self.sdr is not None:
self.sdr.removeClient(self) self.sdr.removeClient(self)
@ -252,7 +265,7 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
stack = PropertyStack() stack = PropertyStack()
stack.addLayer(0, self.sdr.getProps()) stack.addLayer(0, self.sdr.getProps())
stack.addLayer(1, Config.get()) stack.addLayer(1, Config.get())
configProps = stack.filter(*OpenWebRxReceiverClient.config_keys) configProps = stack.filter(*OpenWebRxReceiverClient.sdr_config_keys)
def sendConfig(changes=None): def sendConfig(changes=None):
if changes is None: if changes is None:
@ -273,8 +286,8 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
bookmarks = [b.__dict__() for b in Bookmarks.getSharedInstance().getBookmarks(frequencyRange)] bookmarks = [b.__dict__() for b in Bookmarks.getSharedInstance().getBookmarks(frequencyRange)]
self.write_bookmarks(bookmarks) self.write_bookmarks(bookmarks)
self.configSubs.append(configProps.wire(sendConfig)) self.sdrConfigSubs.append(configProps.wire(sendConfig))
self.configSubs.append(stack.filter("center_freq", "samp_rate").wire(sendBookmarks)) self.sdrConfigSubs.append(stack.filter("center_freq", "samp_rate").wire(sendBookmarks))
# send initial config # send initial config
sendConfig() sendConfig()
@ -295,8 +308,8 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
self.stopDsp() self.stopDsp()
CpuUsageThread.getSharedInstance().remove_client(self) CpuUsageThread.getSharedInstance().remove_client(self)
ClientRegistry.getSharedInstance().removeClient(self) ClientRegistry.getSharedInstance().removeClient(self)
while self.configSubs: while self.sdrConfigSubs:
self.configSubs.pop().cancel() self.sdrConfigSubs.pop().cancel()
super().close() super().close()
def stopDsp(self): def stopDsp(self):