From e37bc0573df434fe95ba4929f9e65f3d17500e4f Mon Sep 17 00:00:00 2001 From: Jim Ancona Date: Mon, 10 May 2021 20:35:49 -0400 Subject: [PATCH 1/2] Set proper config options for HPSDR connector --- owrx/source/hpsdr.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/owrx/source/hpsdr.py b/owrx/source/hpsdr.py index b0ee66c..8c317dc 100644 --- a/owrx/source/hpsdr.py +++ b/owrx/source/hpsdr.py @@ -1,5 +1,7 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.command import Option +from owrx.form.input import Input, NumberInput, TextInput +from typing import List # In order to use an HPSDR radio, you must install hpsdrconnector from https://github.com/jancona/hpsdrconnector # These are the command line options available: @@ -34,7 +36,25 @@ class HpsdrSource(ConnectorSource): ) ) +class RemoteInput(TextInput): + def __init__(self): + super().__init__( + "remote", "Remote IP", infotext="Remote IP address to connect to." + ) class HpsdrDeviceDescription(ConnectorDeviceDescription): def getName(self): return "HPSDR devices (Hermes / Hermes Lite 2 / Red Pitaya)" + + def getInputs(self) -> List[Input]: + return list(filter(lambda x : x.id != "rf_gain", super().getInputs())) + [ + RemoteInput(), NumberInput("rf_gain", "LNA Gain", + "LNA gain between 0 (-12dB) and 60 (48dB)"), + ] + + def getDeviceOptionalKeys(self): + return list(filter(lambda x : x not in ["rtltcp_compat", "iqswap"], super().getDeviceOptionalKeys())) + ["remote"] + + def getProfileOptionalKeys(self): + return list(filter(lambda x : x != "iqswap", super().getProfileOptionalKeys())) + From 87b9a52fcb10db2a394599ab80925ec35758106e Mon Sep 17 00:00:00 2001 From: Jim Ancona Date: Tue, 11 May 2021 11:21:52 -0400 Subject: [PATCH 2/2] Don't filter inputs, add a validator for RF Gain --- owrx/form/input/__init__.py | 4 ++-- owrx/form/input/validator.py | 12 ++++++++++++ owrx/source/hpsdr.py | 8 +++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/owrx/form/input/__init__.py b/owrx/form/input/__init__.py index 840985a..e45390e 100644 --- a/owrx/form/input/__init__.py +++ b/owrx/form/input/__init__.py @@ -107,8 +107,8 @@ class TextInput(Input): class NumberInput(Input): - def __init__(self, id, label, infotext=None, append="", converter: Converter = None): - super().__init__(id, label, infotext, converter=converter) + def __init__(self, id, label, infotext=None, append="", converter: Converter = None, validator: Validator = None): + super().__init__(id, label, infotext, converter=converter, validator=validator) self.step = None self.append = append diff --git a/owrx/form/input/validator.py b/owrx/form/input/validator.py index 165471f..b9b87d1 100644 --- a/owrx/form/input/validator.py +++ b/owrx/form/input/validator.py @@ -12,3 +12,15 @@ class RequiredValidator(Validator): def validate(self, key, value): if value is None or value == "": raise ValidationError(key, "Field is required") + +class RangeValidator(Validator): + def __init__(self, minValue, maxValue): + self.minValue = minValue + self.maxValue = maxValue + + def validate(self, key, value): + if value is None or value == "": + return # Ignore empty values + n = float(value) + if n < self.minValue or n > self.maxValue: + raise ValidationError(key, 'Value must be between %s and %s'%(self.minValue, self.maxValue)) diff --git a/owrx/source/hpsdr.py b/owrx/source/hpsdr.py index 8c317dc..71cb691 100644 --- a/owrx/source/hpsdr.py +++ b/owrx/source/hpsdr.py @@ -1,6 +1,8 @@ from owrx.source.connector import ConnectorSource, ConnectorDeviceDescription from owrx.command import Option +from owrx.form.error import ValidationError from owrx.form.input import Input, NumberInput, TextInput +from owrx.form.input.validator import RangeValidator from typing import List # In order to use an HPSDR radio, you must install hpsdrconnector from https://github.com/jancona/hpsdrconnector @@ -47,9 +49,9 @@ class HpsdrDeviceDescription(ConnectorDeviceDescription): return "HPSDR devices (Hermes / Hermes Lite 2 / Red Pitaya)" def getInputs(self) -> List[Input]: - return list(filter(lambda x : x.id != "rf_gain", super().getInputs())) + [ - RemoteInput(), NumberInput("rf_gain", "LNA Gain", - "LNA gain between 0 (-12dB) and 60 (48dB)"), + return super().getInputs() + [ + RemoteInput(), + NumberInput("rf_gain", "LNA Gain", "LNA gain between 0 (-12dB) and 60 (48dB)", validator=RangeValidator(0, 60)), ] def getDeviceOptionalKeys(self):