2019-12-21 19:58:28 +00:00
|
|
|
from owrx.meta import MetaParser
|
|
|
|
from owrx.wsjt import WsjtParser
|
2020-04-12 11:10:23 +00:00
|
|
|
from owrx.js8 import Js8Parser
|
2019-12-21 19:58:28 +00:00
|
|
|
from owrx.aprs import AprsParser
|
2020-01-09 14:11:53 +00:00
|
|
|
from owrx.pocsag import PocsagParser
|
2019-12-21 19:58:28 +00:00
|
|
|
from owrx.source import SdrSource
|
2020-03-24 21:13:42 +00:00
|
|
|
from owrx.property import PropertyStack, PropertyLayer
|
2020-04-26 20:46:30 +00:00
|
|
|
from owrx.modes import Modes
|
2019-12-21 19:58:28 +00:00
|
|
|
from csdr import csdr
|
|
|
|
import threading
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class DspManager(csdr.output):
|
|
|
|
def __init__(self, handler, sdrSource):
|
|
|
|
self.handler = handler
|
|
|
|
self.sdrSource = sdrSource
|
2020-01-09 14:11:53 +00:00
|
|
|
self.parsers = {
|
|
|
|
"meta": MetaParser(self.handler),
|
|
|
|
"wsjt_demod": WsjtParser(self.handler),
|
|
|
|
"packet_demod": AprsParser(self.handler),
|
|
|
|
"pocsag_demod": PocsagParser(self.handler),
|
2020-04-12 11:10:23 +00:00
|
|
|
"js8_demod": Js8Parser(self.handler),
|
2020-01-09 14:11:53 +00:00
|
|
|
}
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2020-03-24 21:13:42 +00:00
|
|
|
self.props = PropertyStack()
|
|
|
|
# local demodulator properties not forwarded to the sdr
|
2020-03-24 21:16:11 +00:00
|
|
|
self.props.addLayer(0, PropertyLayer().filter(
|
2020-03-24 21:13:42 +00:00
|
|
|
"output_rate",
|
|
|
|
"squelch_level",
|
|
|
|
"secondary_mod",
|
|
|
|
"low_cut",
|
|
|
|
"high_cut",
|
|
|
|
"offset_freq",
|
|
|
|
"mod",
|
|
|
|
"secondary_offset_freq",
|
2020-04-14 11:43:26 +00:00
|
|
|
"dmr_filter",
|
2020-03-24 21:13:42 +00:00
|
|
|
))
|
|
|
|
# properties that we inherit from the sdr
|
2020-03-24 21:16:11 +00:00
|
|
|
self.props.addLayer(1, self.sdrSource.getProps().filter(
|
2020-03-23 22:56:05 +00:00
|
|
|
"audio_compression",
|
|
|
|
"fft_compression",
|
|
|
|
"digimodes_fft_size",
|
|
|
|
"csdr_dynamic_bufsize",
|
|
|
|
"csdr_print_bufsizes",
|
|
|
|
"csdr_through",
|
|
|
|
"digimodes_enable",
|
|
|
|
"samp_rate",
|
|
|
|
"digital_voice_unvoiced_quality",
|
|
|
|
"temporary_directory",
|
|
|
|
"center_freq",
|
2020-04-26 20:46:30 +00:00
|
|
|
"start_mod",
|
|
|
|
"start_freq",
|
2020-03-24 21:13:42 +00:00
|
|
|
))
|
2019-12-21 19:58:28 +00:00
|
|
|
|
|
|
|
self.dsp = csdr.dsp(self)
|
|
|
|
self.dsp.nc_port = self.sdrSource.getPort()
|
|
|
|
|
|
|
|
def set_low_cut(cut):
|
|
|
|
bpf = self.dsp.get_bpf()
|
|
|
|
bpf[0] = cut
|
|
|
|
self.dsp.set_bpf(*bpf)
|
|
|
|
|
|
|
|
def set_high_cut(cut):
|
|
|
|
bpf = self.dsp.get_bpf()
|
|
|
|
bpf[1] = cut
|
|
|
|
self.dsp.set_bpf(*bpf)
|
|
|
|
|
|
|
|
def set_dial_freq(key, value):
|
2020-03-24 21:13:42 +00:00
|
|
|
freq = self.props["center_freq"] + self.props["offset_freq"]
|
2020-01-09 14:11:53 +00:00
|
|
|
for parser in self.parsers.values():
|
|
|
|
parser.setDialFrequency(freq)
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2020-04-26 20:46:30 +00:00
|
|
|
if "start_mod" in self.props:
|
|
|
|
self.dsp.set_demodulator(self.props["start_mod"])
|
|
|
|
mode = Modes.findByModulation(self.props["start_mod"])
|
|
|
|
|
|
|
|
if mode and mode.bandpass:
|
|
|
|
self.dsp.set_bpf(mode.bandpass.low_cut, mode.bandpass.high_cut)
|
|
|
|
else:
|
|
|
|
self.dsp.set_bpf(-4000, 4000)
|
|
|
|
|
|
|
|
if "start_freq" in self.props and "center_freq" in self.props:
|
|
|
|
self.dsp.set_offset_freq(self.props["start_freq"] - self.props["center_freq"])
|
|
|
|
else:
|
|
|
|
self.dsp.set_offset_freq(0)
|
|
|
|
|
2019-12-21 19:58:28 +00:00
|
|
|
self.subscriptions = [
|
2020-03-24 21:13:42 +00:00
|
|
|
self.props.wireProperty("audio_compression", self.dsp.set_audio_compression),
|
|
|
|
self.props.wireProperty("fft_compression", self.dsp.set_fft_compression),
|
|
|
|
self.props.wireProperty("digimodes_fft_size", self.dsp.set_secondary_fft_size),
|
|
|
|
self.props.wireProperty("samp_rate", self.dsp.set_samp_rate),
|
|
|
|
self.props.wireProperty("output_rate", self.dsp.set_output_rate),
|
|
|
|
self.props.wireProperty("offset_freq", self.dsp.set_offset_freq),
|
2020-04-05 14:35:46 +00:00
|
|
|
self.props.wireProperty("center_freq", self.dsp.set_center_freq),
|
2020-03-24 21:13:42 +00:00
|
|
|
self.props.wireProperty("squelch_level", self.dsp.set_squelch_level),
|
|
|
|
self.props.wireProperty("low_cut", set_low_cut),
|
|
|
|
self.props.wireProperty("high_cut", set_high_cut),
|
|
|
|
self.props.wireProperty("mod", self.dsp.set_demodulator),
|
|
|
|
self.props.wireProperty("digital_voice_unvoiced_quality", self.dsp.set_unvoiced_quality),
|
|
|
|
self.props.wireProperty("dmr_filter", self.dsp.set_dmr_filter),
|
|
|
|
self.props.wireProperty("temporary_directory", self.dsp.set_temporary_directory),
|
2020-03-24 21:16:11 +00:00
|
|
|
self.props.filter("center_freq", "offset_freq").wire(set_dial_freq),
|
2019-12-21 19:58:28 +00:00
|
|
|
]
|
|
|
|
|
2020-03-24 21:13:42 +00:00
|
|
|
self.dsp.csdr_dynamic_bufsize = self.props["csdr_dynamic_bufsize"]
|
|
|
|
self.dsp.csdr_print_bufsizes = self.props["csdr_print_bufsizes"]
|
|
|
|
self.dsp.csdr_through = self.props["csdr_through"]
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2020-03-24 21:13:42 +00:00
|
|
|
if self.props["digimodes_enable"]:
|
2019-12-21 19:58:28 +00:00
|
|
|
|
|
|
|
def set_secondary_mod(mod):
|
|
|
|
if mod == False:
|
|
|
|
mod = None
|
|
|
|
self.dsp.set_secondary_demodulator(mod)
|
|
|
|
if mod is not None:
|
|
|
|
self.handler.write_secondary_dsp_config(
|
|
|
|
{
|
2020-03-24 21:13:42 +00:00
|
|
|
"secondary_fft_size": self.props["digimodes_fft_size"],
|
2019-12-21 19:58:28 +00:00
|
|
|
"if_samp_rate": self.dsp.if_samp_rate(),
|
|
|
|
"secondary_bw": self.dsp.secondary_bw(),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.subscriptions += [
|
2020-03-24 21:13:42 +00:00
|
|
|
self.props.wireProperty("secondary_mod", set_secondary_mod),
|
|
|
|
self.props.wireProperty("secondary_offset_freq", self.dsp.set_secondary_offset_freq),
|
2019-12-21 19:58:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
self.sdrSource.addClient(self)
|
|
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
if self.sdrSource.isAvailable():
|
|
|
|
self.dsp.start()
|
|
|
|
|
|
|
|
def receive_output(self, t, read_fn):
|
|
|
|
logger.debug("adding new output of type %s", t)
|
|
|
|
writers = {
|
|
|
|
"audio": self.handler.write_dsp_data,
|
|
|
|
"smeter": self.handler.write_s_meter_level,
|
|
|
|
"secondary_fft": self.handler.write_secondary_fft,
|
|
|
|
"secondary_demod": self.handler.write_secondary_demod,
|
|
|
|
}
|
2020-01-09 14:11:53 +00:00
|
|
|
for demod, parser in self.parsers.items():
|
|
|
|
writers[demod] = parser.parse
|
|
|
|
|
2019-12-21 19:58:28 +00:00
|
|
|
write = writers[t]
|
|
|
|
|
|
|
|
threading.Thread(target=self.pump(read_fn, write)).start()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self.dsp.stop()
|
|
|
|
self.sdrSource.removeClient(self)
|
|
|
|
for sub in self.subscriptions:
|
|
|
|
sub.cancel()
|
|
|
|
self.subscriptions = []
|
|
|
|
|
|
|
|
def setProperty(self, prop, value):
|
2020-03-24 21:13:42 +00:00
|
|
|
self.props[prop] = value
|
2019-12-21 19:58:28 +00:00
|
|
|
|
|
|
|
def getClientClass(self):
|
|
|
|
return SdrSource.CLIENT_USER
|
|
|
|
|
|
|
|
def onStateChange(self, state):
|
|
|
|
if state == SdrSource.STATE_RUNNING:
|
|
|
|
logger.debug("received STATE_RUNNING, attempting DspSource restart")
|
|
|
|
self.dsp.start()
|
|
|
|
elif state == SdrSource.STATE_STOPPING:
|
|
|
|
logger.debug("received STATE_STOPPING, shutting down DspSource")
|
|
|
|
self.dsp.stop()
|
|
|
|
elif state == SdrSource.STATE_FAILED:
|
|
|
|
logger.debug("received STATE_FAILED, shutting down DspSource")
|
|
|
|
self.dsp.stop()
|
|
|
|
|
|
|
|
def onBusyStateChange(self, state):
|
|
|
|
pass
|