2019-12-27 23:26:45 +00:00
|
|
|
from owrx.command import Option
|
2021-02-20 17:09:24 +00:00
|
|
|
from owrx.source.direct import DirectSource, DirectSourceDeviceDescription
|
2022-12-10 18:50:26 +00:00
|
|
|
from owrx.log import LogPipe
|
2019-12-31 15:20:36 +00:00
|
|
|
from subprocess import Popen
|
2021-09-20 16:36:24 +00:00
|
|
|
from csdr.chain import Chain
|
|
|
|
from pycsdr.modules import Convert, Gain
|
|
|
|
from pycsdr.types import Format
|
2022-09-19 16:46:11 +00:00
|
|
|
from typing import List
|
|
|
|
from owrx.form.input import Input, TextInput
|
2019-12-31 15:20:36 +00:00
|
|
|
import logging
|
|
|
|
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2019-12-27 23:26:45 +00:00
|
|
|
class FifiSdrSource(DirectSource):
|
2019-12-31 18:14:05 +00:00
|
|
|
def getCommandMapper(self):
|
2021-01-20 16:01:46 +00:00
|
|
|
return (
|
|
|
|
super()
|
|
|
|
.getCommandMapper()
|
|
|
|
.setBase("arecord")
|
|
|
|
.setMappings({"device": Option("-D"), "samp_rate": Option("-r")})
|
|
|
|
.setStatic("-t raw -f S16_LE -c2 -")
|
|
|
|
)
|
2019-12-27 23:26:45 +00:00
|
|
|
|
|
|
|
def getEventNames(self):
|
2019-12-28 00:24:07 +00:00
|
|
|
return super().getEventNames() + ["device"]
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2021-09-20 16:36:24 +00:00
|
|
|
def getFormatConversion(self) -> Chain:
|
|
|
|
return Chain([Convert(Format.COMPLEX_SHORT, Format.COMPLEX_FLOAT), Gain(Format.COMPLEX_FLOAT, 5.0)])
|
2019-12-31 15:20:36 +00:00
|
|
|
|
|
|
|
def sendRockProgFrequency(self, frequency):
|
2022-12-10 18:50:26 +00:00
|
|
|
stdoutPipe = LogPipe(logging.DEBUG, self.logger, "STDOUT")
|
|
|
|
stderrPipe = LogPipe(logging.DEBUG, self.logger, "STDERR")
|
|
|
|
process = Popen(
|
|
|
|
["rockprog", "--vco", "-w", "--freq={}".format(frequency / 1e6)],
|
|
|
|
stdout=stdoutPipe,
|
|
|
|
stderr=stderrPipe
|
|
|
|
)
|
2019-12-31 15:20:36 +00:00
|
|
|
process.communicate()
|
|
|
|
rc = process.wait()
|
|
|
|
if rc != 0:
|
2022-12-10 18:50:26 +00:00
|
|
|
self.logger.warning("rockprog failed to set frequency; rc=%i", rc)
|
|
|
|
stdoutPipe.close()
|
|
|
|
stderrPipe.close()
|
2019-12-31 15:20:36 +00:00
|
|
|
|
|
|
|
def preStart(self):
|
|
|
|
values = self.getCommandValues()
|
|
|
|
self.sendRockProgFrequency(values["tuner_freq"])
|
|
|
|
|
2020-12-30 16:18:46 +00:00
|
|
|
def onPropertyChange(self, changes):
|
|
|
|
if "center_freq" in changes:
|
|
|
|
self.sendRockProgFrequency(changes["center_freq"])
|
2021-02-20 17:09:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FifiSdrDeviceDescription(DirectSourceDeviceDescription):
|
2021-04-17 15:42:08 +00:00
|
|
|
def getName(self):
|
|
|
|
return "FiFi SDR"
|
2022-06-09 18:25:29 +00:00
|
|
|
|
|
|
|
def supportsPpm(self):
|
|
|
|
# not currently mapped, and it's unclear how this should be sent to the device
|
|
|
|
return False
|
2022-09-19 16:46:11 +00:00
|
|
|
|
|
|
|
def getInputs(self) -> List[Input]:
|
|
|
|
return super().getInputs() + [
|
|
|
|
TextInput(
|
|
|
|
"device",
|
|
|
|
"Device identifier",
|
|
|
|
infotext="Alsa audio device identifier",
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
def getDeviceOptionalKeys(self):
|
|
|
|
return super().getDeviceOptionalKeys() + ["device"]
|