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