From 3aa238727e2f130ed0674a7c719d5c3c20854b71 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 19 Feb 2021 15:29:17 +0100 Subject: [PATCH] start building device forms --- owrx/controllers/settings/device.py | 30 -------------------------- owrx/controllers/settings/sdr.py | 2 +- owrx/source/__init__.py | 33 +++++++++++++++++++++++++++++ owrx/source/connector.py | 8 +++++-- owrx/source/rtl_sdr.py | 7 +++--- owrx/source/sdrplay.py | 6 +++++- owrx/source/soapy.py | 18 +++++++++++++++- 7 files changed, 65 insertions(+), 39 deletions(-) delete mode 100644 owrx/controllers/settings/device.py diff --git a/owrx/controllers/settings/device.py b/owrx/controllers/settings/device.py deleted file mode 100644 index edf6348..0000000 --- a/owrx/controllers/settings/device.py +++ /dev/null @@ -1,30 +0,0 @@ -from owrx.form import Input -from owrx.controllers.settings import Section -from typing import List - - -class SdrDeviceDescriptionMissing(Exception): - pass - - -class SdrDeviceDescription(object): - @staticmethod - def getByType(sdr_type: str) -> "SdrDeviceDescription": - try: - className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceDescription" - module = __import__("owrx.source.{0}".format(sdr_type), fromlist=[className]) - cls = getattr(module, className) - return cls() - except (ModuleNotFoundError, AttributeError): - raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type)) - - def getInputs(self) -> List[Input]: - return [] - - def mergeInputs(self, *args): - # build a dictionary indexed by the input id to make sure every id only exists once - inputs = {input.id: input for input_list in args for input in input_list} - return inputs.values() - - def getSection(self): - return Section("Device settings", *self.getInputs()) diff --git a/owrx/controllers/settings/sdr.py b/owrx/controllers/settings/sdr.py index 4a45b2e..f490ef8 100644 --- a/owrx/controllers/settings/sdr.py +++ b/owrx/controllers/settings/sdr.py @@ -1,7 +1,7 @@ from owrx.controllers.admin import AuthorizationMixin from owrx.controllers.template import WebpageController from owrx.controllers.settings import SettingsFormController -from owrx.controllers.settings.device import SdrDeviceDescription, SdrDeviceDescriptionMissing +from owrx.source import SdrDeviceDescription, SdrDeviceDescriptionMissing from owrx.config import Config from urllib.parse import quote, unquote diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index 540b7f4..9b84b67 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -10,6 +10,9 @@ from abc import ABC, abstractmethod from owrx.command import CommandMapper from owrx.socket import getAvailablePort from owrx.property import PropertyStack, PropertyLayer +from owrx.form import Input, TextInput, NumberInput +from owrx.controllers.settings import Section +from typing import List import logging @@ -352,3 +355,33 @@ class SdrSource(ABC): self.busyState = state for c in self.clients: c.onBusyStateChange(state) + + +class SdrDeviceDescriptionMissing(Exception): + pass + + +class SdrDeviceDescription(object): + @staticmethod + def getByType(sdr_type: str) -> "SdrDeviceDescription": + try: + className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceDescription" + module = __import__("owrx.source.{0}".format(sdr_type), fromlist=[className]) + cls = getattr(module, className) + return cls() + except (ModuleNotFoundError, AttributeError): + raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type)) + + def getInputs(self) -> List[Input]: + return [ + TextInput("name", "Device name"), + NumberInput("ppm", "Frequency correction", append="ppm"), + ] + + def mergeInputs(self, *args): + # build a dictionary indexed by the input id to make sure every id only exists once + inputs = {input.id: input for input_list in args for input in input_list} + return inputs.values() + + def getSection(self): + return Section("Device settings", *self.getInputs()) diff --git a/owrx/source/connector.py b/owrx/source/connector.py index 8789cbe..dd055c2 100644 --- a/owrx/source/connector.py +++ b/owrx/source/connector.py @@ -1,7 +1,7 @@ -from . import SdrSource +from owrx.source import SdrSource, SdrDeviceDescription from owrx.socket import getAvailablePort import socket -from owrx.command import CommandMapper, Flag, Option +from owrx.command import Flag, Option import logging @@ -69,3 +69,7 @@ class ConnectorSource(SdrSource): values["port"] = self.getPort() values["controlPort"] = self.getControlPort() return values + + +class ConnectorDeviceDescription(SdrDeviceDescription): + pass diff --git a/owrx/source/rtl_sdr.py b/owrx/source/rtl_sdr.py index 7fe899b..6a65daa 100644 --- a/owrx/source/rtl_sdr.py +++ b/owrx/source/rtl_sdr.py @@ -1,6 +1,5 @@ -from .connector import ConnectorSource +from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.command import Flag, Option -from owrx.controllers.settings.device import SdrDeviceDescription from typing import List from owrx.form import Input, TextInput @@ -15,11 +14,11 @@ class RtlSdrSource(ConnectorSource): ) -class RtlSdrDeviceDescription(SdrDeviceDescription): +class RtlSdrDeviceDescription(ConnectorDeviceDescription): def getInputs(self) -> List[Input]: return self.mergeInputs( super().getInputs(), [ - TextInput("test", "This is a drill"), + TextInput("device", "Device identifier", infotext="Device serial number or index"), ], ) diff --git a/owrx/source/sdrplay.py b/owrx/source/sdrplay.py index 5fb2f4c..5b3ef23 100644 --- a/owrx/source/sdrplay.py +++ b/owrx/source/sdrplay.py @@ -1,4 +1,4 @@ -from .soapy import SoapyConnectorSource +from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription class SdrplaySource(SoapyConnectorSource): @@ -17,3 +17,7 @@ class SdrplaySource(SoapyConnectorSource): def getDriver(self): return "sdrplay" + + +class SdrplayDeviceDescription(SoapyConnectorDeviceDescription): + pass diff --git a/owrx/source/soapy.py b/owrx/source/soapy.py index 64c0713..d9c4b2e 100644 --- a/owrx/source/soapy.py +++ b/owrx/source/soapy.py @@ -1,6 +1,8 @@ from abc import ABCMeta, abstractmethod from owrx.command import Option -from .connector import ConnectorSource +from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription +from typing import List +from owrx.form import Input, TextInput class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta): @@ -94,3 +96,17 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta): if settings: changes["settings"] = ",".join("{0}={1}".format(k, v) for k, v in settings.items()) super().onPropertyChange(changes) + + +class SoapyConnectorDeviceDescription(ConnectorDeviceDescription): + def getInputs(self) -> List[Input]: + return self.mergeInputs( + super().getInputs(), + [ + TextInput( + "device", + "Device Identifier", + infotext='SoapySDR device identifier string (example: "serial=123456789")', + ), + ], + )