wire data parsing and storage

This commit is contained in:
Jakob Ketterl 2021-02-19 18:45:29 +01:00
parent 039b57d28b
commit 86278ff44d
6 changed files with 26 additions and 11 deletions

View File

@ -80,14 +80,17 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
def processFormData(self): def processFormData(self):
self.processData(self.parseFormData()) self.processData(self.parseFormData())
self.store()
self.send_redirect(self.request.path) self.send_redirect(self.request.path)
def processData(self, data): def processData(self, data):
config = Config.get() config = self.getData()
for k, v in data.items(): for k, v in data.items():
if v is None: if v is None:
if k in config: if k in config:
del config[k] del config[k]
else: else:
config[k] = v config[k] = v
config.store()
def store(self):
Config.get().store()

View File

@ -54,14 +54,18 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController):
class SdrDeviceController(SettingsFormController): class SdrDeviceController(SettingsFormController):
def __init__(self, handler, request, options): def __init__(self, handler, request, options):
super().__init__(handler, request, options) super().__init__(handler, request, options)
self.device = self._get_device() self.device_id, self.device = self._get_device()
def getData(self): def getData(self):
return self.device return self.device
def processData(self, data): def store(self):
# TODO implement storing of data here # need to overwrite the existing key in the config since the layering won't capture the changes otherwise
logger.debug(data) config = Config.get()
sdrs = config["sdrs"]
sdrs[self.device_id] = self.getData()
config["sdrs"] = sdrs
super().store()
def getSections(self): def getSections(self):
try: try:
@ -78,7 +82,7 @@ class SdrDeviceController(SettingsFormController):
device_id = unquote(self.request.matches.group(1)) device_id = unquote(self.request.matches.group(1))
if device_id not in Config.get()["sdrs"]: if device_id not in Config.get()["sdrs"]:
return None return None
return Config.get()["sdrs"][device_id] return device_id, Config.get()["sdrs"][device_id]
def header_variables(self): def header_variables(self):
variables = super().header_variables() variables = super().header_variables()

View File

@ -36,7 +36,7 @@ class OptionalConverter(Converter):
return self.defaultFormValue if value is None else self.sub_converter.convert_to_form(value) return self.defaultFormValue if value is None else self.sub_converter.convert_to_form(value)
def convert_from_form(self, value): def convert_from_form(self, value):
return None if value == self.defaultFormValue else self.sub_converter.convert_to_form(value) return None if value == self.defaultFormValue else self.sub_converter.convert_from_form(value)
class IntConverter(Converter): class IntConverter(Converter):

View File

@ -11,7 +11,7 @@ from owrx.command import CommandMapper
from owrx.socket import getAvailablePort from owrx.socket import getAvailablePort
from owrx.property import PropertyStack, PropertyLayer from owrx.property import PropertyStack, PropertyLayer
from owrx.form import Input, TextInput, NumberInput, CheckboxInput, FloatInput from owrx.form import Input, TextInput, NumberInput, CheckboxInput, FloatInput
from owrx.form.converter import IntConverter, OptionalConverter from owrx.form.converter import IntConverter, OptionalConverter, FloatConverter
from owrx.controllers.settings import Section from owrx.controllers.settings import Section
from typing import List from typing import List
@ -394,7 +394,7 @@ class SdrDeviceDescription(object):
"Run background services on this device", "Run background services on this device",
converter=OptionalConverter(defaultFormValue=True), converter=OptionalConverter(defaultFormValue=True),
), ),
FloatInput("rf_gain", "Device gain"), FloatInput("rf_gain", "Device gain", converter=OptionalConverter(FloatConverter())),
] ]
def mergeInputs(self, *args): def mergeInputs(self, *args):

View File

@ -2,6 +2,7 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
from owrx.command import Flag, Option from owrx.command import Flag, Option
from typing import List from typing import List
from owrx.form import Input, TextInput from owrx.form import Input, TextInput
from owrx.form.converter import OptionalConverter
class RtlSdrSource(ConnectorSource): class RtlSdrSource(ConnectorSource):
@ -19,6 +20,11 @@ class RtlSdrDeviceDescription(ConnectorDeviceDescription):
return self.mergeInputs( return self.mergeInputs(
super().getInputs(), super().getInputs(),
[ [
TextInput("device", "Device identifier", infotext="Device serial number or index"), TextInput(
"device",
"Device identifier",
infotext="Device serial number or index",
converter=OptionalConverter(),
),
], ],
) )

View File

@ -3,6 +3,7 @@ from owrx.command import Option
from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
from typing import List from typing import List
from owrx.form import Input, TextInput from owrx.form import Input, TextInput
from owrx.form.converter import OptionalConverter
from owrx.form.soapy import SoapyGainInput from owrx.form.soapy import SoapyGainInput
@ -108,6 +109,7 @@ class SoapyConnectorDeviceDescription(ConnectorDeviceDescription):
"device", "device",
"Device Identifier", "Device Identifier",
infotext='SoapySDR device identifier string (example: "serial=123456789")', infotext='SoapySDR device identifier string (example: "serial=123456789")',
converter=OptionalConverter()
), ),
SoapyGainInput( SoapyGainInput(
"rf_gain", "rf_gain",