wire data parsing and storage
This commit is contained in:
parent
039b57d28b
commit
86278ff44d
@ -80,14 +80,17 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
|
||||
|
||||
def processFormData(self):
|
||||
self.processData(self.parseFormData())
|
||||
self.store()
|
||||
self.send_redirect(self.request.path)
|
||||
|
||||
def processData(self, data):
|
||||
config = Config.get()
|
||||
config = self.getData()
|
||||
for k, v in data.items():
|
||||
if v is None:
|
||||
if k in config:
|
||||
del config[k]
|
||||
else:
|
||||
config[k] = v
|
||||
config.store()
|
||||
|
||||
def store(self):
|
||||
Config.get().store()
|
||||
|
@ -54,14 +54,18 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController):
|
||||
class SdrDeviceController(SettingsFormController):
|
||||
def __init__(self, handler, request, options):
|
||||
super().__init__(handler, request, options)
|
||||
self.device = self._get_device()
|
||||
self.device_id, self.device = self._get_device()
|
||||
|
||||
def getData(self):
|
||||
return self.device
|
||||
|
||||
def processData(self, data):
|
||||
# TODO implement storing of data here
|
||||
logger.debug(data)
|
||||
def store(self):
|
||||
# need to overwrite the existing key in the config since the layering won't capture the changes otherwise
|
||||
config = Config.get()
|
||||
sdrs = config["sdrs"]
|
||||
sdrs[self.device_id] = self.getData()
|
||||
config["sdrs"] = sdrs
|
||||
super().store()
|
||||
|
||||
def getSections(self):
|
||||
try:
|
||||
@ -78,7 +82,7 @@ class SdrDeviceController(SettingsFormController):
|
||||
device_id = unquote(self.request.matches.group(1))
|
||||
if device_id not in Config.get()["sdrs"]:
|
||||
return None
|
||||
return Config.get()["sdrs"][device_id]
|
||||
return device_id, Config.get()["sdrs"][device_id]
|
||||
|
||||
def header_variables(self):
|
||||
variables = super().header_variables()
|
||||
|
@ -36,7 +36,7 @@ class OptionalConverter(Converter):
|
||||
return self.defaultFormValue if value is None else self.sub_converter.convert_to_form(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):
|
||||
|
@ -11,7 +11,7 @@ from owrx.command import CommandMapper
|
||||
from owrx.socket import getAvailablePort
|
||||
from owrx.property import PropertyStack, PropertyLayer
|
||||
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 typing import List
|
||||
|
||||
@ -394,7 +394,7 @@ class SdrDeviceDescription(object):
|
||||
"Run background services on this device",
|
||||
converter=OptionalConverter(defaultFormValue=True),
|
||||
),
|
||||
FloatInput("rf_gain", "Device gain"),
|
||||
FloatInput("rf_gain", "Device gain", converter=OptionalConverter(FloatConverter())),
|
||||
]
|
||||
|
||||
def mergeInputs(self, *args):
|
||||
|
@ -2,6 +2,7 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
|
||||
from owrx.command import Flag, Option
|
||||
from typing import List
|
||||
from owrx.form import Input, TextInput
|
||||
from owrx.form.converter import OptionalConverter
|
||||
|
||||
|
||||
class RtlSdrSource(ConnectorSource):
|
||||
@ -19,6 +20,11 @@ class RtlSdrDeviceDescription(ConnectorDeviceDescription):
|
||||
return self.mergeInputs(
|
||||
super().getInputs(),
|
||||
[
|
||||
TextInput("device", "Device identifier", infotext="Device serial number or index"),
|
||||
TextInput(
|
||||
"device",
|
||||
"Device identifier",
|
||||
infotext="Device serial number or index",
|
||||
converter=OptionalConverter(),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ from owrx.command import Option
|
||||
from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription
|
||||
from typing import List
|
||||
from owrx.form import Input, TextInput
|
||||
from owrx.form.converter import OptionalConverter
|
||||
from owrx.form.soapy import SoapyGainInput
|
||||
|
||||
|
||||
@ -108,6 +109,7 @@ class SoapyConnectorDeviceDescription(ConnectorDeviceDescription):
|
||||
"device",
|
||||
"Device Identifier",
|
||||
infotext='SoapySDR device identifier string (example: "serial=123456789")',
|
||||
converter=OptionalConverter()
|
||||
),
|
||||
SoapyGainInput(
|
||||
"rf_gain",
|
||||
|
Loading…
Reference in New Issue
Block a user