openwebrx/owrx/source/afedri.py

112 lines
3.7 KiB
Python
Raw Normal View History

2023-10-15 12:31:59 +02:00
from owrx.source.soapy import SoapyConnectorSource, SoapyConnectorDeviceDescription
2023-10-21 05:07:50 +02:00
from owrx.form.input import Input, CheckboxInput, NumberInput
from owrx.form.input.device import RemoteInput, TextInput
2023-10-15 12:31:59 +02:00
from owrx.form.input.validator import RangeValidator
from owrx.form.input.converter import OptionalConverter
from owrx.form.input.validator import RequiredValidator
2023-10-15 12:31:59 +02:00
from typing import List
AFEDRI_DEVICE_KEYS = ["rx_mode", "map_ch0"]
2023-10-21 05:07:50 +02:00
AFEDRI_PROFILE_KEYS = ["r820t_lna_agc", "r820t_mixer_agc"]
2023-10-15 12:31:59 +02:00
class AfedriAddressPortInput(TextInput):
def __init__(self):
super().__init__(
"afedri_adress_port",
"Afedri IP and Port",
infotext="Afedri IP and port to connect to. Format = IP:Port",
converter=OptionalConverter(),
validator=RequiredValidator(),
)
2023-10-15 12:31:59 +02:00
class AfedriSource(SoapyConnectorSource):
def getSoapySettingsMappings(self):
mappings = super().getSoapySettingsMappings()
2023-10-21 05:07:50 +02:00
mappings.update({x: x for x in AFEDRI_PROFILE_KEYS})
2023-10-15 12:31:59 +02:00
return mappings
def getEventNames(self):
return super().getEventNames() + ["remote", "afedri_adress_port"] + AFEDRI_DEVICE_KEYS
2023-10-15 12:31:59 +02:00
def getDriver(self):
return "afedri"
def buildSoapyDeviceParameters(self, parsed, values):
params = super().buildSoapyDeviceParameters(parsed, values)
# replace driver with sopayRemote
if "remote" in values:
params = [v for v in params if "driver" not in v] # remove present driver
params += [{"driver": "remote", "remote:driver": self.getDriver(), "remote": values["remote"]}]
address, port = values["afedri_adress_port"].split(":")
2023-10-15 12:31:59 +02:00
params += [{"address": address, "port": port}]
can_be_set_at_start = AFEDRI_DEVICE_KEYS
for elm in can_be_set_at_start:
if elm in values:
params += [{elm: values[elm]}]
return params
class AfedriDeviceDescription(SoapyConnectorDeviceDescription):
def getName(self):
return "Afedri device"
def supportsPpm(self):
# not currently mapped, and it's unclear how this should be sent to the device
return False
def hasAgc(self):
# not currently mapped
return False
def getInputs(self) -> List[Input]:
return super().getInputs() + [
RemoteInput(),
AfedriAddressPortInput(),
2023-10-21 05:07:50 +02:00
CheckboxInput(
"r820t_lna_agc",
"Enable R820T LNA AGC",
),
CheckboxInput(
"r820t_mixer_agc",
"Enable R820T Mixer AGC",
),
NumberInput(
"map_ch0",
"Substitute channel 0",
infotext="Number in range [0,3]. Substitute SoapySDR channel 0 with a specific Afedri channel",
2023-10-21 05:07:50 +02:00
validator=RangeValidator(0, 3),
),
NumberInput(
"rx_mode",
"RX Mode (Single/Dual/Quad Channel)",
infotext="Number in range [0,5]. Switch the device to a specific RX mode. <br />"
+ "(0-Single 1-DualDiversity 2-Dual 3-DiversityInternal 4-QuadDiversity 5-Quad)",
2023-10-21 05:07:50 +02:00
validator=RangeValidator(0, 5),
),
2023-10-15 12:31:59 +02:00
]
def getDeviceMandatoryKeys(self):
return super().getDeviceMandatoryKeys() + ["afedri_adress_port"]
2023-10-15 12:31:59 +02:00
def getDeviceOptionalKeys(self):
return super().getDeviceOptionalKeys() + ["remote"] + AFEDRI_DEVICE_KEYS
2023-10-15 12:31:59 +02:00
def getProfileOptionalKeys(self):
2023-10-21 05:07:50 +02:00
return super().getProfileOptionalKeys() + AFEDRI_PROFILE_KEYS
2023-10-15 12:31:59 +02:00
def getGainStages(self):
2023-10-21 05:07:50 +02:00
return [
"RF",
"FE",
"R820T_LNA_GAIN",
"R820T_MIXER_GAIN",
"R820T_VGA_GAIN",
]