2018-09-25 12:56:47 +00:00
|
|
|
"""
|
|
|
|
OpenWebRX csdr plugin: do the signal processing with csdr
|
|
|
|
|
|
|
|
This file is part of OpenWebRX,
|
|
|
|
an open-source SDR receiver software with a web UI.
|
|
|
|
Copyright (c) 2013-2015 by Andras Retzler <randras@sdr.hu>
|
2020-01-09 21:24:39 +00:00
|
|
|
Copyright (c) 2019-2020 by Jakob Ketterl <dd5jfk@darc.de>
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import signal
|
2019-05-07 16:19:53 +00:00
|
|
|
import threading
|
2019-11-23 15:56:29 +00:00
|
|
|
import math
|
2019-05-14 21:30:03 +00:00
|
|
|
from functools import partial
|
2019-08-11 14:37:30 +00:00
|
|
|
|
2019-08-17 22:15:07 +00:00
|
|
|
from owrx.kiss import KissClient, DirewolfConfig
|
2019-07-20 11:38:25 +00:00
|
|
|
from owrx.wsjt import Ft8Chopper, WsprChopper, Jt9Chopper, Jt65Chopper, Ft4Chopper
|
2016-06-07 18:51:04 +00:00
|
|
|
|
2019-05-10 20:07:26 +00:00
|
|
|
import logging
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-05-10 20:07:26 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-05-14 21:30:03 +00:00
|
|
|
class output(object):
|
2019-08-04 12:55:56 +00:00
|
|
|
def send_output(self, t, read_fn):
|
|
|
|
if not self.supports_type(t):
|
|
|
|
# TODO rewrite the output mechanism in a way that avoids producing unnecessary data
|
2019-08-11 09:37:45 +00:00
|
|
|
logger.warning("dumping output of type %s since it is not supported.", t)
|
2019-08-04 12:55:56 +00:00
|
|
|
threading.Thread(target=self.pump(read_fn, lambda x: None)).start()
|
|
|
|
return
|
|
|
|
self.receive_output(t, read_fn)
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-08-04 12:55:56 +00:00
|
|
|
def receive_output(self, t, read_fn):
|
2019-05-14 21:30:03 +00:00
|
|
|
pass
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-28 09:40:58 +00:00
|
|
|
def pump(self, read, write):
|
|
|
|
def copy():
|
|
|
|
run = True
|
|
|
|
while run:
|
|
|
|
data = read()
|
|
|
|
if data is None or (isinstance(data, bytes) and len(data) == 0):
|
|
|
|
run = False
|
|
|
|
else:
|
|
|
|
write(data)
|
|
|
|
|
|
|
|
return copy
|
|
|
|
|
2019-08-04 12:55:56 +00:00
|
|
|
def supports_type(self, t):
|
|
|
|
return True
|
2019-05-14 21:30:03 +00:00
|
|
|
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
class dsp(object):
|
2019-05-14 21:30:03 +00:00
|
|
|
def __init__(self, output):
|
2018-09-25 12:56:47 +00:00
|
|
|
self.samp_rate = 250000
|
2019-09-13 20:28:17 +00:00
|
|
|
self.output_rate = 11025
|
2018-09-25 12:56:47 +00:00
|
|
|
self.fft_size = 1024
|
|
|
|
self.fft_fps = 5
|
|
|
|
self.offset_freq = 0
|
|
|
|
self.low_cut = -4000
|
|
|
|
self.high_cut = 4000
|
2019-07-21 17:40:28 +00:00
|
|
|
self.bpf_transition_bw = 320 # Hz, and this is a constant
|
|
|
|
self.ddc_transition_bw_rate = 0.15 # of the IF sample rate
|
2018-09-25 12:56:47 +00:00
|
|
|
self.running = False
|
|
|
|
self.secondary_processes_running = False
|
|
|
|
self.audio_compression = "none"
|
|
|
|
self.fft_compression = "none"
|
|
|
|
self.demodulator = "nfm"
|
|
|
|
self.name = "csdr"
|
|
|
|
self.base_bufsize = 512
|
2019-09-13 20:28:17 +00:00
|
|
|
self.nc_port = None
|
2018-09-25 12:56:47 +00:00
|
|
|
self.csdr_dynamic_bufsize = False
|
|
|
|
self.csdr_print_bufsizes = False
|
|
|
|
self.csdr_through = False
|
2019-11-23 15:56:29 +00:00
|
|
|
self.squelch_level = -150
|
2018-09-25 12:56:47 +00:00
|
|
|
self.fft_averages = 50
|
|
|
|
self.iqtee = False
|
|
|
|
self.iqtee2 = False
|
|
|
|
self.secondary_demodulator = None
|
|
|
|
self.secondary_fft_size = 1024
|
|
|
|
self.secondary_process_fft = None
|
|
|
|
self.secondary_process_demod = None
|
2019-07-21 17:40:28 +00:00
|
|
|
self.pipe_names = [
|
|
|
|
"bpf_pipe",
|
|
|
|
"shift_pipe",
|
|
|
|
"squelch_pipe",
|
|
|
|
"smeter_pipe",
|
|
|
|
"meta_pipe",
|
|
|
|
"iqtee_pipe",
|
|
|
|
"iqtee2_pipe",
|
|
|
|
"dmr_control_pipe",
|
|
|
|
]
|
|
|
|
self.secondary_pipe_names = ["secondary_shift_pipe"]
|
2018-09-25 12:56:47 +00:00
|
|
|
self.secondary_offset_freq = 1000
|
2019-05-18 20:10:43 +00:00
|
|
|
self.unvoiced_quality = 1
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock = threading.Lock()
|
2019-05-14 21:30:03 +00:00
|
|
|
self.output = output
|
2019-07-13 15:16:38 +00:00
|
|
|
self.temporary_directory = "/tmp"
|
2019-09-13 20:28:17 +00:00
|
|
|
self.is_service = False
|
2019-08-17 20:38:09 +00:00
|
|
|
self.direwolf_config = None
|
|
|
|
self.direwolf_port = None
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-09-13 20:28:17 +00:00
|
|
|
def set_service(self, flag=True):
|
|
|
|
self.is_service = flag
|
|
|
|
|
2019-07-13 15:16:38 +00:00
|
|
|
def set_temporary_directory(self, what):
|
|
|
|
self.temporary_directory = what
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def chain(self, which):
|
2019-06-30 14:24:56 +00:00
|
|
|
chain = ["nc -v 127.0.0.1 {nc_port}"]
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.csdr_dynamic_bufsize:
|
|
|
|
chain += ["csdr setbuf {start_bufsize}"]
|
|
|
|
if self.csdr_through:
|
|
|
|
chain += ["csdr through"]
|
2018-09-25 12:56:47 +00:00
|
|
|
if which == "fft":
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += [
|
|
|
|
"csdr fft_cc {fft_size} {fft_block_size}",
|
2019-07-21 17:40:28 +00:00
|
|
|
"csdr logpower_cf -70"
|
|
|
|
if self.fft_averages == 0
|
|
|
|
else "csdr logaveragepower_cf -70 {fft_size} {fft_averages}",
|
|
|
|
"csdr fft_exchange_sides_ff {fft_size}",
|
2019-06-30 14:24:56 +00:00
|
|
|
]
|
|
|
|
if self.fft_compression == "adpcm":
|
|
|
|
chain += ["csdr compress_fft_adpcm_f_u8 {fft_size}"]
|
2019-05-15 21:08:55 +00:00
|
|
|
return chain
|
2019-09-10 22:27:49 +00:00
|
|
|
chain += ["csdr shift_addition_cc --fifo {shift_pipe}"]
|
|
|
|
if self.decimation > 1:
|
|
|
|
chain += ["csdr fir_decimate_cc {decimation} {ddc_transition_bw} HAMMING"]
|
|
|
|
chain += ["csdr bandpass_fir_fft_cc --fifo {bpf_pipe} {bpf_transition_bw} HAMMING"]
|
2019-08-11 09:37:45 +00:00
|
|
|
if self.output.supports_type("smeter"):
|
2019-08-04 12:55:56 +00:00
|
|
|
chain += [
|
2019-08-11 09:37:45 +00:00
|
|
|
"csdr squelch_and_smeter_cc --fifo {squelch_pipe} --outfifo {smeter_pipe} 5 {smeter_report_every}"
|
2019-08-04 12:55:56 +00:00
|
|
|
]
|
2018-09-25 12:56:47 +00:00
|
|
|
if self.secondary_demodulator:
|
2019-08-11 09:37:45 +00:00
|
|
|
if self.output.supports_type("secondary_fft"):
|
2019-08-04 12:55:56 +00:00
|
|
|
chain += ["csdr tee {iqtee_pipe}"]
|
|
|
|
chain += ["csdr tee {iqtee2_pipe}"]
|
|
|
|
# early exit if we don't want audio
|
2019-08-11 09:37:45 +00:00
|
|
|
if not self.output.supports_type("audio"):
|
2019-08-04 12:55:56 +00:00
|
|
|
return chain
|
2019-05-16 19:26:31 +00:00
|
|
|
# safe some cpu cycles... no need to decimate if decimation factor is 1
|
2019-07-21 17:40:28 +00:00
|
|
|
last_decimation_block = (
|
|
|
|
["csdr fractional_decimator_ff {last_decimation}"] if self.last_decimation != 1.0 else []
|
|
|
|
)
|
2019-05-15 21:08:55 +00:00
|
|
|
if which == "nfm":
|
2019-07-21 17:40:28 +00:00
|
|
|
chain += ["csdr fmdemod_quadri_cf", "csdr limit_ff"]
|
2019-05-16 19:26:31 +00:00
|
|
|
chain += last_decimation_block
|
2019-08-11 14:36:53 +00:00
|
|
|
chain += ["csdr deemphasis_nfm_ff {audio_rate}"]
|
2019-08-11 11:52:19 +00:00
|
|
|
if self.get_audio_rate() != self.get_output_rate():
|
|
|
|
chain += [
|
|
|
|
"sox -t raw -r {audio_rate} -e floating-point -b 32 -c 1 --buffer 32 - -t raw -r {output_rate} -e signed-integer -b 16 -c 1 - "
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
chain += ["csdr convert_f_s16"]
|
2019-05-16 19:26:31 +00:00
|
|
|
elif self.isDigitalVoice(which):
|
2019-07-21 17:40:28 +00:00
|
|
|
chain += ["csdr fmdemod_quadri_cf", "dc_block "]
|
2019-05-16 19:26:31 +00:00
|
|
|
chain += last_decimation_block
|
2019-05-24 23:46:16 +00:00
|
|
|
# dsd modes
|
2019-07-21 17:40:28 +00:00
|
|
|
if which in ["dstar", "nxdn"]:
|
|
|
|
chain += ["csdr limit_ff", "csdr convert_f_s16"]
|
2019-05-16 19:26:31 +00:00
|
|
|
if which == "dstar":
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += ["dsd -fd -i - -o - -u {unvoiced_quality} -g -1 "]
|
2019-05-16 19:26:31 +00:00
|
|
|
elif which == "nxdn":
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += ["dsd -fi -i - -o - -u {unvoiced_quality} -g -1 "]
|
|
|
|
chain += ["CSDR_FIXED_BUFSIZE=32 csdr convert_s16_f"]
|
2019-06-08 07:23:39 +00:00
|
|
|
max_gain = 5
|
2019-05-24 23:46:16 +00:00
|
|
|
# digiham modes
|
|
|
|
else:
|
2019-07-21 17:40:28 +00:00
|
|
|
chain += ["rrc_filter", "gfsk_demodulator"]
|
2019-05-24 23:46:16 +00:00
|
|
|
if which == "dmr":
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += [
|
|
|
|
"dmr_decoder --fifo {meta_pipe} --control-fifo {dmr_control_pipe}",
|
2019-07-21 17:40:28 +00:00
|
|
|
"mbe_synthesizer -f -u {unvoiced_quality}",
|
2019-06-30 14:24:56 +00:00
|
|
|
]
|
2019-05-24 23:46:16 +00:00
|
|
|
elif which == "ysf":
|
2019-07-21 17:40:28 +00:00
|
|
|
chain += ["ysf_decoder --fifo {meta_pipe}", "mbe_synthesizer -y -f -u {unvoiced_quality}"]
|
2019-06-08 07:23:39 +00:00
|
|
|
max_gain = 0.0005
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += [
|
|
|
|
"digitalvoice_filter -f",
|
|
|
|
"CSDR_FIXED_BUFSIZE=32 csdr agc_ff 160000 0.8 1 0.0000001 {max_gain}".format(max_gain=max_gain),
|
2019-07-21 17:40:28 +00:00
|
|
|
"sox -t raw -r 8000 -e floating-point -b 32 -c 1 --buffer 32 - -t raw -r {output_rate} -e signed-integer -b 16 -c 1 - ",
|
2019-06-30 14:24:56 +00:00
|
|
|
]
|
2019-05-15 21:08:55 +00:00
|
|
|
elif which == "am":
|
2019-07-21 17:40:28 +00:00
|
|
|
chain += ["csdr amdemod_cf", "csdr fastdcblock_ff"]
|
2019-05-16 19:26:31 +00:00
|
|
|
chain += last_decimation_block
|
2020-01-24 10:42:20 +00:00
|
|
|
chain += [
|
|
|
|
"csdr agc_ff 160000 0.8 0.001 0.0000001 50",
|
|
|
|
"csdr limit_ff",
|
|
|
|
"csdr convert_f_s16",
|
|
|
|
]
|
2019-05-15 21:08:55 +00:00
|
|
|
elif which == "ssb":
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += ["csdr realpart_cf"]
|
2019-05-16 19:26:31 +00:00
|
|
|
chain += last_decimation_block
|
2019-07-21 17:40:28 +00:00
|
|
|
chain += ["csdr agc_ff", "csdr limit_ff"]
|
2019-07-10 20:31:06 +00:00
|
|
|
# fixed sample rate necessary for the wsjt-x tools. fix with sox...
|
2019-08-11 11:52:19 +00:00
|
|
|
if self.get_audio_rate() != self.get_output_rate():
|
2019-07-10 20:31:06 +00:00
|
|
|
chain += [
|
|
|
|
"sox -t raw -r {audio_rate} -e floating-point -b 32 -c 1 --buffer 32 - -t raw -r {output_rate} -e signed-integer -b 16 -c 1 - "
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
chain += ["csdr convert_f_s16"]
|
2019-05-15 21:08:55 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.audio_compression == "adpcm":
|
2019-06-30 14:24:56 +00:00
|
|
|
chain += ["csdr encode_ima_adpcm_i16_u8"]
|
2019-05-15 21:08:55 +00:00
|
|
|
return chain
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def secondary_chain(self, which):
|
2019-11-22 14:00:36 +00:00
|
|
|
chain = ["cat {input_pipe}"]
|
2018-09-25 12:56:47 +00:00
|
|
|
if which == "fft":
|
2019-11-22 14:00:36 +00:00
|
|
|
chain += [
|
|
|
|
"csdr realpart_cf",
|
|
|
|
"csdr fft_fc {secondary_fft_input_size} {secondary_fft_block_size}",
|
|
|
|
"csdr logpower_cf -70",
|
|
|
|
]
|
|
|
|
if self.fft_compression == "adpcm":
|
|
|
|
chain += ["csdr compress_fft_adpcm_f_u8 {secondary_fft_size}"]
|
|
|
|
return chain
|
2020-01-13 19:10:14 +00:00
|
|
|
elif which == "bpsk31" or which == "bpsk63":
|
2019-11-22 14:00:36 +00:00
|
|
|
return chain + [
|
|
|
|
"csdr shift_addition_cc --fifo {secondary_shift_pipe}",
|
|
|
|
"csdr bandpass_fir_fft_cc -{secondary_bpf_cutoff} {secondary_bpf_cutoff} {secondary_bpf_cutoff}",
|
|
|
|
"csdr simple_agc_cc 0.001 0.5",
|
|
|
|
"csdr timing_recovery_cc GARDNER {secondary_samples_per_bits} 0.5 2 --add_q",
|
|
|
|
"CSDR_FIXED_BUFSIZE=1 csdr dbpsk_decoder_c_u8",
|
|
|
|
"CSDR_FIXED_BUFSIZE=1 csdr psk31_varicode_decoder_u8_u8",
|
|
|
|
]
|
2019-07-13 21:16:25 +00:00
|
|
|
elif self.isWsjtMode(which):
|
2019-11-22 14:00:36 +00:00
|
|
|
chain += ["csdr realpart_cf"]
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.last_decimation != 1.0:
|
2019-11-22 14:00:36 +00:00
|
|
|
chain += ["csdr fractional_decimator_ff {last_decimation}"]
|
2019-11-22 23:34:41 +00:00
|
|
|
return chain + ["csdr limit_ff", "csdr convert_f_s16"]
|
2019-08-11 11:52:19 +00:00
|
|
|
elif which == "packet":
|
2019-11-22 14:00:36 +00:00
|
|
|
chain += ["csdr fmdemod_quadri_cf"]
|
2019-08-11 11:52:19 +00:00
|
|
|
if self.last_decimation != 1.0:
|
2019-11-22 14:00:36 +00:00
|
|
|
chain += ["csdr fractional_decimator_ff {last_decimation}"]
|
|
|
|
return chain + ["csdr convert_f_s16", "direwolf -c {direwolf_config} -r {audio_rate} -t 0 -q d -q h - 1>&2"]
|
2020-01-06 21:08:17 +00:00
|
|
|
elif which == "pocsag":
|
|
|
|
chain += ["csdr fmdemod_quadri_cf"]
|
|
|
|
if self.last_decimation != 1.0:
|
|
|
|
chain += ["csdr fractional_decimator_ff {last_decimation}"]
|
2020-01-07 06:30:19 +00:00
|
|
|
return chain + ["fsk_demodulator -i", "pocsag_decoder"]
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def set_secondary_demodulator(self, what):
|
2019-05-18 19:38:15 +00:00
|
|
|
if self.get_secondary_demodulator() == what:
|
|
|
|
return
|
2018-09-25 12:56:47 +00:00
|
|
|
self.secondary_demodulator = what
|
2019-07-12 17:28:40 +00:00
|
|
|
self.calculate_decimation()
|
2019-05-18 19:38:15 +00:00
|
|
|
self.restart()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def secondary_fft_block_size(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
return (self.samp_rate / self.decimation) / (
|
|
|
|
self.fft_fps * 2
|
|
|
|
) # *2 is there because we do FFT on real signal here
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def secondary_decimation(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
return 1 # currently unused
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def secondary_bpf_cutoff(self):
|
|
|
|
if self.secondary_demodulator == "bpsk31":
|
2019-07-21 17:40:28 +00:00
|
|
|
return 31.25 / self.if_samp_rate()
|
2020-01-13 19:10:14 +00:00
|
|
|
elif self.secondary_demodulator == "bpsk63":
|
|
|
|
return 62.5 / self.if_samp_rate()
|
2018-09-25 12:56:47 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def secondary_bpf_transition_bw(self):
|
|
|
|
if self.secondary_demodulator == "bpsk31":
|
2019-05-05 20:09:48 +00:00
|
|
|
return 31.25 / self.if_samp_rate()
|
2020-01-13 19:10:14 +00:00
|
|
|
elif self.secondary_demodulator == "bpsk63":
|
|
|
|
return 62.5 / self.if_samp_rate()
|
2018-09-25 12:56:47 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def secondary_samples_per_bits(self):
|
|
|
|
if self.secondary_demodulator == "bpsk31":
|
2019-07-21 17:40:28 +00:00
|
|
|
return int(round(self.if_samp_rate() / 31.25)) & ~3
|
2020-01-13 19:10:14 +00:00
|
|
|
elif self.secondary_demodulator == "bpsk63":
|
|
|
|
return int(round(self.if_samp_rate() / 62.5)) & ~3
|
2018-09-25 12:56:47 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def secondary_bw(self):
|
|
|
|
if self.secondary_demodulator == "bpsk31":
|
|
|
|
return 31.25
|
2020-01-13 19:10:14 +00:00
|
|
|
elif self.secondary_demodulator == "bpsk63":
|
|
|
|
return 62.5
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def start_secondary_demodulator(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
if not self.secondary_demodulator:
|
|
|
|
return
|
2019-07-28 09:40:58 +00:00
|
|
|
logger.debug("starting secondary demodulator from IF input sampled at %d" % self.if_samp_rate())
|
2019-11-22 14:00:36 +00:00
|
|
|
secondary_command_demod = " | ".join(self.secondary_chain(self.secondary_demodulator))
|
2019-08-04 12:55:56 +00:00
|
|
|
self.try_create_pipes(self.secondary_pipe_names, secondary_command_demod)
|
2019-08-15 23:27:03 +00:00
|
|
|
self.try_create_configs(secondary_command_demod)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
secondary_command_demod = secondary_command_demod.format(
|
2019-05-10 19:29:05 +00:00
|
|
|
input_pipe=self.iqtee2_pipe,
|
|
|
|
secondary_shift_pipe=self.secondary_shift_pipe,
|
|
|
|
secondary_decimation=self.secondary_decimation(),
|
|
|
|
secondary_samples_per_bits=self.secondary_samples_per_bits(),
|
|
|
|
secondary_bpf_cutoff=self.secondary_bpf_cutoff(),
|
|
|
|
secondary_bpf_transition_bw=self.secondary_bpf_transition_bw(),
|
2019-07-06 16:21:43 +00:00
|
|
|
if_samp_rate=self.if_samp_rate(),
|
2019-07-21 17:40:28 +00:00
|
|
|
last_decimation=self.last_decimation,
|
2019-08-11 11:52:19 +00:00
|
|
|
audio_rate=self.get_audio_rate(),
|
2019-08-15 23:27:03 +00:00
|
|
|
direwolf_config=self.direwolf_config,
|
2019-07-21 17:40:28 +00:00
|
|
|
)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-28 09:40:58 +00:00
|
|
|
logger.debug("secondary command (demod) = %s", secondary_command_demod)
|
2019-07-21 17:40:28 +00:00
|
|
|
my_env = os.environ.copy()
|
|
|
|
# if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"]="1";
|
|
|
|
if self.csdr_print_bufsizes:
|
|
|
|
my_env["CSDR_PRINT_BUFSIZES"] = "1"
|
2019-08-11 09:37:45 +00:00
|
|
|
if self.output.supports_type("secondary_fft"):
|
2019-11-22 14:00:36 +00:00
|
|
|
secondary_command_fft = " | ".join(self.secondary_chain("fft"))
|
2019-08-04 12:55:56 +00:00
|
|
|
secondary_command_fft = secondary_command_fft.format(
|
|
|
|
input_pipe=self.iqtee_pipe,
|
|
|
|
secondary_fft_input_size=self.secondary_fft_size,
|
|
|
|
secondary_fft_size=self.secondary_fft_size,
|
|
|
|
secondary_fft_block_size=self.secondary_fft_block_size(),
|
2018-09-25 12:56:47 +00:00
|
|
|
)
|
2019-08-04 12:55:56 +00:00
|
|
|
logger.debug("secondary command (fft) = %s", secondary_command_fft)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-08-04 12:55:56 +00:00
|
|
|
self.secondary_process_fft = subprocess.Popen(
|
2020-01-17 20:18:02 +00:00
|
|
|
secondary_command_fft, stdout=subprocess.PIPE, shell=True, start_new_session=True, env=my_env
|
2019-08-04 12:55:56 +00:00
|
|
|
)
|
|
|
|
self.output.send_output(
|
|
|
|
"secondary_fft",
|
|
|
|
partial(self.secondary_process_fft.stdout.read, int(self.get_secondary_fft_bytes_to_read())),
|
|
|
|
)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-08-17 17:59:58 +00:00
|
|
|
# direwolf does not provide any meaningful data on stdout
|
|
|
|
# more specifically, it doesn't provide any data. if however, for any strange reason, it would start to do so,
|
|
|
|
# it would block if not read. by piping it to devnull, we avoid a potential pitfall here.
|
|
|
|
secondary_output = subprocess.DEVNULL if self.isPacket() else subprocess.PIPE
|
2019-07-21 17:40:28 +00:00
|
|
|
self.secondary_process_demod = subprocess.Popen(
|
2020-01-17 20:18:02 +00:00
|
|
|
secondary_command_demod, stdout=secondary_output, shell=True, start_new_session=True, env=my_env
|
2019-07-28 09:40:58 +00:00
|
|
|
)
|
2018-09-25 12:56:47 +00:00
|
|
|
self.secondary_processes_running = True
|
2019-05-14 21:30:03 +00:00
|
|
|
|
2019-07-13 21:16:25 +00:00
|
|
|
if self.isWsjtMode():
|
|
|
|
smd = self.get_secondary_demodulator()
|
|
|
|
if smd == "ft8":
|
|
|
|
chopper = Ft8Chopper(self.secondary_process_demod.stdout)
|
|
|
|
elif smd == "wspr":
|
|
|
|
chopper = WsprChopper(self.secondary_process_demod.stdout)
|
2019-07-14 15:09:34 +00:00
|
|
|
elif smd == "jt65":
|
|
|
|
chopper = Jt65Chopper(self.secondary_process_demod.stdout)
|
|
|
|
elif smd == "jt9":
|
|
|
|
chopper = Jt9Chopper(self.secondary_process_demod.stdout)
|
2019-07-20 11:38:25 +00:00
|
|
|
elif smd == "ft4":
|
|
|
|
chopper = Ft4Chopper(self.secondary_process_demod.stdout)
|
2019-07-06 16:21:43 +00:00
|
|
|
chopper.start()
|
2019-08-04 12:55:56 +00:00
|
|
|
self.output.send_output("wsjt_demod", chopper.read)
|
2019-08-17 17:59:58 +00:00
|
|
|
elif self.isPacket():
|
|
|
|
# we best get the ax25 packets from the kiss socket
|
2019-08-15 23:27:03 +00:00
|
|
|
kiss = KissClient(self.direwolf_port)
|
2019-08-11 14:37:30 +00:00
|
|
|
self.output.send_output("packet_demod", kiss.read)
|
2020-01-09 14:12:51 +00:00
|
|
|
elif self.isPocsag():
|
|
|
|
self.output.send_output("pocsag_demod", self.secondary_process_demod.stdout.readline)
|
2019-08-17 17:59:58 +00:00
|
|
|
else:
|
|
|
|
self.output.send_output("secondary_demod", partial(self.secondary_process_demod.stdout.read, 1))
|
2019-08-11 14:37:30 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
# open control pipes for csdr and send initialization data
|
|
|
|
if self.secondary_shift_pipe != None: # TODO digimodes
|
|
|
|
self.secondary_shift_pipe_file = open(self.secondary_shift_pipe, "w") # TODO digimodes
|
|
|
|
self.set_secondary_offset_freq(self.secondary_offset_freq) # TODO digimodes
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def set_secondary_offset_freq(self, value):
|
2019-07-21 17:40:28 +00:00
|
|
|
self.secondary_offset_freq = value
|
2019-07-06 16:21:43 +00:00
|
|
|
if self.secondary_processes_running and hasattr(self, "secondary_shift_pipe_file"):
|
2019-07-21 17:40:28 +00:00
|
|
|
self.secondary_shift_pipe_file.write("%g\n" % (-float(self.secondary_offset_freq) / self.if_samp_rate()))
|
2018-09-25 12:56:47 +00:00
|
|
|
self.secondary_shift_pipe_file.flush()
|
|
|
|
|
|
|
|
def stop_secondary_demodulator(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.secondary_processes_running == False:
|
|
|
|
return
|
2018-09-25 12:56:47 +00:00
|
|
|
self.try_delete_pipes(self.secondary_pipe_names)
|
2019-08-17 20:38:09 +00:00
|
|
|
self.try_delete_configs()
|
2019-05-08 14:31:52 +00:00
|
|
|
if self.secondary_process_fft:
|
|
|
|
try:
|
|
|
|
os.killpg(os.getpgid(self.secondary_process_fft.pid), signal.SIGTERM)
|
|
|
|
except ProcessLookupError:
|
|
|
|
# been killed by something else, ignore
|
|
|
|
pass
|
|
|
|
if self.secondary_process_demod:
|
|
|
|
try:
|
|
|
|
os.killpg(os.getpgid(self.secondary_process_demod.pid), signal.SIGTERM)
|
|
|
|
except ProcessLookupError:
|
|
|
|
# been killed by something else, ignore
|
|
|
|
pass
|
2018-09-25 12:56:47 +00:00
|
|
|
self.secondary_processes_running = False
|
|
|
|
|
|
|
|
def get_secondary_demodulator(self):
|
|
|
|
return self.secondary_demodulator
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_secondary_fft_size(self, secondary_fft_size):
|
|
|
|
# to change this, restart is required
|
|
|
|
self.secondary_fft_size = secondary_fft_size
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_audio_compression(self, what):
|
2018-09-25 12:56:47 +00:00
|
|
|
self.audio_compression = what
|
|
|
|
|
2019-10-15 17:50:24 +00:00
|
|
|
def get_audio_bytes_to_read(self):
|
|
|
|
# desired latency: 5ms
|
|
|
|
# uncompressed audio has 16 bits = 2 bytes per sample
|
|
|
|
base = self.output_rate * 0.005 * 2
|
|
|
|
# adpcm compresses the bitstream by 4
|
|
|
|
if self.audio_compression == "adpcm":
|
|
|
|
base = base / 4
|
|
|
|
return int(base)
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_fft_compression(self, what):
|
2018-09-25 12:56:47 +00:00
|
|
|
self.fft_compression = what
|
|
|
|
|
|
|
|
def get_fft_bytes_to_read(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.fft_compression == "none":
|
|
|
|
return self.fft_size * 4
|
|
|
|
if self.fft_compression == "adpcm":
|
2019-10-15 17:50:24 +00:00
|
|
|
return int((self.fft_size / 2) + (10 / 2))
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def get_secondary_fft_bytes_to_read(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.fft_compression == "none":
|
|
|
|
return self.secondary_fft_size * 4
|
|
|
|
if self.fft_compression == "adpcm":
|
|
|
|
return (self.secondary_fft_size / 2) + (10 / 2)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_samp_rate(self, samp_rate):
|
|
|
|
self.samp_rate = samp_rate
|
2019-05-07 18:06:06 +00:00
|
|
|
self.calculate_decimation()
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.running:
|
|
|
|
self.restart()
|
2019-05-07 18:06:06 +00:00
|
|
|
|
|
|
|
def calculate_decimation(self):
|
2019-05-16 19:26:31 +00:00
|
|
|
(self.decimation, self.last_decimation, _) = self.get_decimation(self.samp_rate, self.get_audio_rate())
|
2019-05-15 21:08:55 +00:00
|
|
|
|
2019-05-16 19:26:31 +00:00
|
|
|
def get_decimation(self, input_rate, output_rate):
|
2019-07-21 17:40:28 +00:00
|
|
|
decimation = 1
|
|
|
|
while input_rate / (decimation + 1) >= output_rate:
|
2019-05-15 21:08:55 +00:00
|
|
|
decimation += 1
|
2019-05-16 19:26:31 +00:00
|
|
|
fraction = float(input_rate / decimation) / output_rate
|
|
|
|
intermediate_rate = input_rate / decimation
|
|
|
|
return (decimation, fraction, intermediate_rate)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def if_samp_rate(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
return self.samp_rate / self.decimation
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_output_rate(self):
|
|
|
|
return self.output_rate
|
|
|
|
|
2019-05-16 19:26:31 +00:00
|
|
|
def get_audio_rate(self):
|
2020-01-09 12:47:47 +00:00
|
|
|
if self.isDigitalVoice() or self.isPacket() or self.isPocsag():
|
2019-05-16 19:26:31 +00:00
|
|
|
return 48000
|
2019-07-13 21:16:25 +00:00
|
|
|
elif self.isWsjtMode():
|
2019-07-06 16:21:43 +00:00
|
|
|
return 12000
|
2019-05-16 19:26:31 +00:00
|
|
|
return self.get_output_rate()
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def isDigitalVoice(self, demodulator=None):
|
2019-05-16 19:26:31 +00:00
|
|
|
if demodulator is None:
|
|
|
|
demodulator = self.get_demodulator()
|
|
|
|
return demodulator in ["dmr", "dstar", "nxdn", "ysf"]
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def isWsjtMode(self, demodulator=None):
|
2019-07-13 21:16:25 +00:00
|
|
|
if demodulator is None:
|
|
|
|
demodulator = self.get_secondary_demodulator()
|
2019-07-20 11:38:25 +00:00
|
|
|
return demodulator in ["ft8", "wspr", "jt65", "jt9", "ft4"]
|
2019-07-13 21:16:25 +00:00
|
|
|
|
2019-08-15 17:56:59 +00:00
|
|
|
def isPacket(self, demodulator=None):
|
2019-06-07 13:11:04 +00:00
|
|
|
if demodulator is None:
|
2019-08-11 14:36:53 +00:00
|
|
|
demodulator = self.get_secondary_demodulator()
|
2019-06-07 13:11:04 +00:00
|
|
|
return demodulator == "packet"
|
|
|
|
|
2020-01-06 21:08:17 +00:00
|
|
|
def isPocsag(self, demodulator=None):
|
|
|
|
if demodulator is None:
|
|
|
|
demodulator = self.get_secondary_demodulator()
|
|
|
|
return demodulator == "pocsag"
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_output_rate(self, output_rate):
|
2019-10-02 22:14:05 +00:00
|
|
|
if self.output_rate == output_rate:
|
|
|
|
return
|
2019-07-21 17:40:28 +00:00
|
|
|
self.output_rate = output_rate
|
2019-05-07 18:06:06 +00:00
|
|
|
self.calculate_decimation()
|
2019-10-02 22:14:05 +00:00
|
|
|
self.restart()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_demodulator(self, demodulator):
|
|
|
|
if self.demodulator == demodulator:
|
|
|
|
return
|
|
|
|
self.demodulator = demodulator
|
2019-05-16 19:26:31 +00:00
|
|
|
self.calculate_decimation()
|
2019-05-08 14:31:52 +00:00
|
|
|
self.restart()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def get_demodulator(self):
|
|
|
|
return self.demodulator
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_fft_size(self, fft_size):
|
|
|
|
self.fft_size = fft_size
|
2019-05-09 14:52:42 +00:00
|
|
|
self.restart()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_fft_fps(self, fft_fps):
|
|
|
|
self.fft_fps = fft_fps
|
2019-05-09 14:52:42 +00:00
|
|
|
self.restart()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_fft_averages(self, fft_averages):
|
|
|
|
self.fft_averages = fft_averages
|
2019-05-09 14:52:42 +00:00
|
|
|
self.restart()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def fft_block_size(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.fft_averages == 0:
|
|
|
|
return self.samp_rate / self.fft_fps
|
|
|
|
else:
|
|
|
|
return self.samp_rate / self.fft_fps / self.fft_averages
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_offset_freq(self, offset_freq):
|
|
|
|
self.offset_freq = offset_freq
|
2018-09-25 12:56:47 +00:00
|
|
|
if self.running:
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.acquire()
|
2019-07-21 17:40:28 +00:00
|
|
|
self.shift_pipe_file.write("%g\n" % (-float(self.offset_freq) / self.samp_rate))
|
2018-09-25 12:56:47 +00:00
|
|
|
self.shift_pipe_file.flush()
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.release()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def set_bpf(self, low_cut, high_cut):
|
|
|
|
self.low_cut = low_cut
|
|
|
|
self.high_cut = high_cut
|
2018-09-25 12:56:47 +00:00
|
|
|
if self.running:
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.acquire()
|
2019-07-21 17:40:28 +00:00
|
|
|
self.bpf_pipe_file.write(
|
|
|
|
"%g %g\n" % (float(self.low_cut) / self.if_samp_rate(), float(self.high_cut) / self.if_samp_rate())
|
|
|
|
)
|
2018-09-25 12:56:47 +00:00
|
|
|
self.bpf_pipe_file.flush()
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.release()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def get_bpf(self):
|
|
|
|
return [self.low_cut, self.high_cut]
|
|
|
|
|
2019-11-23 15:56:29 +00:00
|
|
|
def convertToLinear(self, db):
|
|
|
|
return float(math.pow(10, db / 10))
|
|
|
|
|
2018-09-25 12:56:47 +00:00
|
|
|
def set_squelch_level(self, squelch_level):
|
2019-07-21 17:40:28 +00:00
|
|
|
self.squelch_level = squelch_level
|
|
|
|
# no squelch required on digital voice modes
|
2020-01-06 21:08:17 +00:00
|
|
|
actual_squelch = -150 if self.isDigitalVoice() or self.isPacket() or self.isPocsag() else self.squelch_level
|
2018-09-25 12:56:47 +00:00
|
|
|
if self.running:
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.acquire()
|
2019-11-23 15:56:29 +00:00
|
|
|
self.squelch_pipe_file.write("%g\n" % (self.convertToLinear(actual_squelch)))
|
2018-09-25 12:56:47 +00:00
|
|
|
self.squelch_pipe_file.flush()
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.release()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-05-18 20:10:43 +00:00
|
|
|
def set_unvoiced_quality(self, q):
|
|
|
|
self.unvoiced_quality = q
|
|
|
|
self.restart()
|
|
|
|
|
|
|
|
def get_unvoiced_quality(self):
|
|
|
|
return self.unvoiced_quality
|
|
|
|
|
2019-06-15 17:10:33 +00:00
|
|
|
def set_dmr_filter(self, filter):
|
|
|
|
if self.dmr_control_pipe_file:
|
|
|
|
self.dmr_control_pipe_file.write("{0}\n".format(filter))
|
|
|
|
self.dmr_control_pipe_file.flush()
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def mkfifo(self, path):
|
2018-09-25 12:56:47 +00:00
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
os.mkfifo(path)
|
|
|
|
|
|
|
|
def ddc_transition_bw(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
return self.ddc_transition_bw_rate * (self.if_samp_rate() / float(self.samp_rate))
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def try_create_pipes(self, pipe_names, command_base):
|
|
|
|
for pipe_name in pipe_names:
|
2019-07-21 17:40:28 +00:00
|
|
|
if "{" + pipe_name + "}" in command_base:
|
|
|
|
setattr(self, pipe_name, self.pipe_base_path + pipe_name)
|
2018-09-25 12:56:47 +00:00
|
|
|
self.mkfifo(getattr(self, pipe_name))
|
|
|
|
else:
|
|
|
|
setattr(self, pipe_name, None)
|
|
|
|
|
|
|
|
def try_delete_pipes(self, pipe_names):
|
|
|
|
for pipe_name in pipe_names:
|
2019-07-21 17:40:28 +00:00
|
|
|
pipe_path = getattr(self, pipe_name, None)
|
2018-09-25 12:56:47 +00:00
|
|
|
if pipe_path:
|
2019-07-21 17:40:28 +00:00
|
|
|
try:
|
|
|
|
os.unlink(pipe_path)
|
2019-07-28 10:11:22 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
# it seems like we keep calling this twice. no idea why, but we don't need the resulting error.
|
|
|
|
pass
|
2019-05-10 20:47:07 +00:00
|
|
|
except Exception:
|
|
|
|
logger.exception("try_delete_pipes()")
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-08-15 23:27:03 +00:00
|
|
|
def try_create_configs(self, command):
|
|
|
|
if "{direwolf_config}" in command:
|
2019-08-17 22:16:08 +00:00
|
|
|
self.direwolf_config = "{tmp_dir}/openwebrx_direwolf_{myid}.conf".format(
|
|
|
|
tmp_dir=self.temporary_directory, myid=id(self)
|
|
|
|
)
|
2019-08-15 23:27:03 +00:00
|
|
|
self.direwolf_port = KissClient.getFreePort()
|
|
|
|
file = open(self.direwolf_config, "w")
|
2019-09-13 20:28:17 +00:00
|
|
|
file.write(DirewolfConfig().getConfig(self.direwolf_port, self.is_service))
|
2019-08-15 23:27:03 +00:00
|
|
|
file.close()
|
|
|
|
else:
|
|
|
|
self.direwolf_config = None
|
2019-08-17 20:38:09 +00:00
|
|
|
self.direwolf_port = None
|
|
|
|
|
|
|
|
def try_delete_configs(self):
|
|
|
|
if self.direwolf_config:
|
|
|
|
try:
|
|
|
|
os.unlink(self.direwolf_config)
|
|
|
|
except FileNotFoundError:
|
|
|
|
# result suits our expectations. fine :)
|
|
|
|
pass
|
|
|
|
except Exception:
|
|
|
|
logger.exception("try_delete_configs()")
|
|
|
|
self.direwolf_config = None
|
2019-08-15 23:27:03 +00:00
|
|
|
|
2018-09-25 12:56:47 +00:00
|
|
|
def start(self):
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.acquire()
|
2019-07-21 17:40:28 +00:00
|
|
|
if self.running:
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.release()
|
|
|
|
return
|
2019-05-07 18:06:06 +00:00
|
|
|
self.running = True
|
|
|
|
|
2019-06-30 14:24:56 +00:00
|
|
|
command_base = " | ".join(self.chain(self.demodulator))
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
# create control pipes for csdr
|
2019-07-13 15:16:38 +00:00
|
|
|
self.pipe_base_path = "{tmp_dir}/openwebrx_pipe_{myid}_".format(tmp_dir=self.temporary_directory, myid=id(self))
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
self.try_create_pipes(self.pipe_names, command_base)
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
# run the command
|
|
|
|
command = command_base.format(
|
|
|
|
bpf_pipe=self.bpf_pipe,
|
|
|
|
shift_pipe=self.shift_pipe,
|
|
|
|
decimation=self.decimation,
|
|
|
|
last_decimation=self.last_decimation,
|
|
|
|
fft_size=self.fft_size,
|
|
|
|
fft_block_size=self.fft_block_size(),
|
|
|
|
fft_averages=self.fft_averages,
|
|
|
|
bpf_transition_bw=float(self.bpf_transition_bw) / self.if_samp_rate(),
|
|
|
|
ddc_transition_bw=self.ddc_transition_bw(),
|
|
|
|
flowcontrol=int(self.samp_rate * 2),
|
|
|
|
start_bufsize=self.base_bufsize * self.decimation,
|
|
|
|
nc_port=self.nc_port,
|
|
|
|
squelch_pipe=self.squelch_pipe,
|
|
|
|
smeter_pipe=self.smeter_pipe,
|
|
|
|
meta_pipe=self.meta_pipe,
|
|
|
|
iqtee_pipe=self.iqtee_pipe,
|
|
|
|
iqtee2_pipe=self.iqtee2_pipe,
|
|
|
|
output_rate=self.get_output_rate(),
|
|
|
|
smeter_report_every=int(self.if_samp_rate() / 6000),
|
|
|
|
unvoiced_quality=self.get_unvoiced_quality(),
|
|
|
|
dmr_control_pipe=self.dmr_control_pipe,
|
|
|
|
audio_rate=self.get_audio_rate(),
|
|
|
|
)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-07-28 09:40:58 +00:00
|
|
|
logger.debug("Command = %s", command)
|
2019-07-21 17:40:28 +00:00
|
|
|
my_env = os.environ.copy()
|
|
|
|
if self.csdr_dynamic_bufsize:
|
|
|
|
my_env["CSDR_DYNAMIC_BUFSIZE_ON"] = "1"
|
|
|
|
if self.csdr_print_bufsizes:
|
|
|
|
my_env["CSDR_PRINT_BUFSIZES"] = "1"
|
2019-08-04 12:55:56 +00:00
|
|
|
|
2019-08-11 09:37:45 +00:00
|
|
|
out = subprocess.PIPE if self.output.supports_type("audio") else subprocess.DEVNULL
|
2020-01-17 20:18:02 +00:00
|
|
|
self.process = subprocess.Popen(command, stdout=out, shell=True, start_new_session=True, env=my_env)
|
2018-09-25 21:15:23 +00:00
|
|
|
|
2019-05-07 16:19:53 +00:00
|
|
|
def watch_thread():
|
|
|
|
rc = self.process.wait()
|
2019-05-10 22:38:22 +00:00
|
|
|
logger.debug("dsp thread ended with rc=%d", rc)
|
2019-07-21 17:40:28 +00:00
|
|
|
if rc == 0 and self.running and not self.modification_lock.locked():
|
2019-05-10 22:38:22 +00:00
|
|
|
logger.debug("restarting since rc = 0, self.running = true, and no modification")
|
2019-05-07 16:19:53 +00:00
|
|
|
self.restart()
|
2018-09-25 21:15:23 +00:00
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
threading.Thread(target=watch_thread).start()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-08-11 09:37:45 +00:00
|
|
|
if self.output.supports_type("audio"):
|
2019-08-04 12:55:56 +00:00
|
|
|
self.output.send_output(
|
|
|
|
"audio",
|
2019-08-11 09:37:45 +00:00
|
|
|
partial(
|
2019-10-15 17:50:24 +00:00
|
|
|
self.process.stdout.read,
|
|
|
|
self.get_fft_bytes_to_read() if self.demodulator == "fft" else self.get_audio_bytes_to_read(),
|
2019-08-11 09:37:45 +00:00
|
|
|
),
|
2019-08-04 12:55:56 +00:00
|
|
|
)
|
2019-05-14 21:30:03 +00:00
|
|
|
|
2019-05-08 14:31:52 +00:00
|
|
|
# open control pipes for csdr
|
2019-06-15 17:10:33 +00:00
|
|
|
if self.bpf_pipe:
|
|
|
|
self.bpf_pipe_file = open(self.bpf_pipe, "w")
|
2019-05-08 14:31:52 +00:00
|
|
|
if self.shift_pipe:
|
2019-06-15 17:10:33 +00:00
|
|
|
self.shift_pipe_file = open(self.shift_pipe, "w")
|
2019-05-08 14:31:52 +00:00
|
|
|
if self.squelch_pipe:
|
2019-06-15 17:10:33 +00:00
|
|
|
self.squelch_pipe_file = open(self.squelch_pipe, "w")
|
2017-05-02 13:12:14 +00:00
|
|
|
self.start_secondary_demodulator()
|
|
|
|
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.release()
|
|
|
|
|
|
|
|
# send initial config through the pipes
|
|
|
|
if self.squelch_pipe:
|
2018-09-25 12:56:47 +00:00
|
|
|
self.set_squelch_level(self.squelch_level)
|
2019-05-08 14:31:52 +00:00
|
|
|
if self.shift_pipe:
|
|
|
|
self.set_offset_freq(self.offset_freq)
|
|
|
|
if self.bpf_pipe:
|
|
|
|
self.set_bpf(self.low_cut, self.high_cut)
|
|
|
|
if self.smeter_pipe:
|
2019-07-21 17:40:28 +00:00
|
|
|
self.smeter_pipe_file = open(self.smeter_pipe, "r")
|
|
|
|
|
2019-05-14 21:30:03 +00:00
|
|
|
def read_smeter():
|
|
|
|
raw = self.smeter_pipe_file.readline()
|
|
|
|
if len(raw) == 0:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return float(raw.rstrip("\n"))
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-08-04 12:55:56 +00:00
|
|
|
self.output.send_output("smeter", read_smeter)
|
2018-09-25 13:28:53 +00:00
|
|
|
if self.meta_pipe != None:
|
2019-05-18 20:27:19 +00:00
|
|
|
# TODO make digiham output unicode and then change this here
|
2019-07-21 17:40:28 +00:00
|
|
|
self.meta_pipe_file = open(self.meta_pipe, "r", encoding="cp437")
|
|
|
|
|
2019-05-14 21:30:03 +00:00
|
|
|
def read_meta():
|
|
|
|
raw = self.meta_pipe_file.readline()
|
|
|
|
if len(raw) == 0:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return raw.rstrip("\n")
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-08-04 12:55:56 +00:00
|
|
|
self.output.send_output("meta", read_meta)
|
2018-09-25 12:56:47 +00:00
|
|
|
|
2019-06-15 17:10:33 +00:00
|
|
|
if self.dmr_control_pipe:
|
|
|
|
self.dmr_control_pipe_file = open(self.dmr_control_pipe, "w")
|
|
|
|
|
2018-09-25 12:56:47 +00:00
|
|
|
def stop(self):
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.acquire()
|
2019-05-07 16:19:53 +00:00
|
|
|
self.running = False
|
|
|
|
if hasattr(self, "process"):
|
|
|
|
try:
|
|
|
|
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
|
|
|
|
except ProcessLookupError:
|
|
|
|
# been killed by something else, ignore
|
|
|
|
pass
|
2018-09-25 12:56:47 +00:00
|
|
|
self.stop_secondary_demodulator()
|
|
|
|
|
|
|
|
self.try_delete_pipes(self.pipe_names)
|
|
|
|
|
2019-05-08 14:31:52 +00:00
|
|
|
self.modification_lock.release()
|
2018-09-25 12:56:47 +00:00
|
|
|
|
|
|
|
def restart(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
if not self.running:
|
|
|
|
return
|
2018-09-25 12:56:47 +00:00
|
|
|
self.stop()
|
|
|
|
self.start()
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.stop()
|
2019-07-21 17:40:28 +00:00
|
|
|
del self.process
|