make sdrs configurable by type; move format_conversion forward

This commit is contained in:
Jakob Ketterl 2019-05-07 17:09:29 +02:00
parent cb187fd3c2
commit 7eaada4726
5 changed files with 77 additions and 17 deletions

View File

@ -103,9 +103,12 @@ Note: if you experience audio underruns while CPU usage is 100%, you can:
# You can use other SDR hardware as well, by giving your own command that outputs the I/Q samples... Some examples of configuration are available here (default is RTL-SDR):
# valid: "rtl_sdr", "sdrplay", "hackrf"
rtl_type = "rtl_sdr"
# >> RTL-SDR via rtl_sdr
start_rtl_command="rtl_sdr -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -".format(rf_gain=rf_gain, center_freq=center_freq, samp_rate=samp_rate, ppm=ppm)
format_conversion="csdr convert_u8_f"
#start_rtl_command="rtl_sdr -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -".format(rf_gain=rf_gain, center_freq=center_freq, samp_rate=samp_rate, ppm=ppm)
#format_conversion="csdr convert_u8_f"
#lna_gain=8
#rf_amp=1

View File

@ -45,7 +45,6 @@ class dsp:
self.fft_compression = "none"
self.demodulator = "nfm"
self.name = "csdr"
self.format_conversion = "csdr convert_u8_f"
self.base_bufsize = 512
self.nc_port = 4951
self.csdr_dynamic_bufsize = False
@ -67,7 +66,6 @@ class dsp:
any_chain_base="nc -v 127.0.0.1 {nc_port} | "
if self.csdr_dynamic_bufsize: any_chain_base+="csdr setbuf {start_bufsize} | "
if self.csdr_through: any_chain_base+="csdr through | "
any_chain_base+=self.format_conversion+(" | " if self.format_conversion!="" else "") ##"csdr flowcontrol {flowcontrol} auto 1.5 10 | "
if which == "fft":
fft_chain_base = any_chain_base+"csdr fft_cc {fft_size} {fft_block_size} | " + \
("csdr logpower_cf -70 | " if self.fft_averages == 0 else "csdr logaveragepower_cf -70 {fft_size} {fft_averages} | ") + \
@ -255,9 +253,6 @@ class dsp:
if self.fft_averages == 0: return self.samp_rate/self.fft_fps
else: return self.samp_rate/self.fft_fps/self.fft_averages
def set_format_conversion(self,format_conversion):
self.format_conversion=format_conversion
def set_offset_freq(self,offset_freq):
self.offset_freq=offset_freq
if self.running:

View File

@ -29,12 +29,18 @@ class PropertyManager(object):
def __init__(self, properties = None):
self.properties = {}
self.callbacks = []
if properties is not None:
for (name, prop) in properties.items():
self.add(name, prop)
def add(self, name, prop):
self.properties[name] = prop
def fireCallbacks(value):
for c in self.callbacks:
c(name, value)
prop.wire(fireCallbacks)
return self
def __getitem__(self, name):
return self.getPropertyValue(name)
@ -50,6 +56,10 @@ class PropertyManager(object):
def getPropertyValue(self, name):
return self.getProperty(name).getValue()
def wire(self, callback):
self.callbacks.append(callback)
return self
class RequirementMissingException(Exception):
pass
@ -58,7 +68,7 @@ class FeatureDetector(object):
"core": [ "csdr", "nmux" ],
"rtl_sdr": [ "rtl_sdr" ],
"sdrplay": [ "rx_tools" ],
"hackrf": [ "rx_tools" ]
"hackrf": [ "hackrf_transfer" ]
}
def is_available(self, feature):
@ -88,3 +98,8 @@ class FeatureDetector(object):
def has_rx_tools(self):
return os.system("rx_sdr --help 2> /dev/null") != 32512
def has_hackrf_transfer(self):
# TODO i don't have a hackrf, so somebody doublecheck this.
# TODO also check if it has the stdout feature
return os.system("hackrf_transfer --help 2> /dev/null") != 32512

View File

@ -74,14 +74,14 @@ class WebSocketMessageHandler(object):
self.client = None
def handleTextMessage(self, conn, message):
pm = PropertyManager.getSharedInstance()
if (message[:16] == "SERVER DE CLIENT"):
# maybe put some more info in there? nothing to store yet.
self.handshake = "completed"
self.client = OpenWebRxClient(conn)
pm = PropertyManager.getSharedInstance()
config_keys = ["waterfall_colors", "waterfall_min_level", "waterfall_max_level",
"waterfall_auto_level_margin", "shown_center_freq", "samp_rate", "fft_size", "fft_fps",
"audio_compression", "fft_compression", "max_clients", "start_mod",
@ -117,6 +117,13 @@ class WebSocketMessageHandler(object):
if "action" in message and message["action"] == "start":
self.dsp.start()
if message["type"] == "config":
for key, value in message["params"].items():
# only the keys in the protected property manager can be overridden from the web
protected = pm.collect("samp_rate")
protected[key] = value
except json.JSONDecodeError:
print("message is not json: {0}".format(message))

View File

@ -1,12 +1,54 @@
import subprocess
from owrx.config import PropertyManager
from owrx.config import PropertyManager, FeatureDetector
import threading
import csdr
import time
class RtlNmuxSource(threading.Thread):
def run(self):
props = PropertyManager.getSharedInstance().collect("samp_rate", "nmux_memory", "start_rtl_command", "iq_server_port")
props = PropertyManager.getSharedInstance().collect(
"rtl_type", "samp_rate", "nmux_memory", "iq_server_port", "center_freq", "ppm",
"rf_gain", "lna_gain", "rf_amp"
)
def restart(name, value):
print("would now restart rtl source due to property change: {0} changed to {1}".format(name, value))
# TODO not sure how to implement an actual restart... help
props.wire(restart)
featureDetector = FeatureDetector()
if not featureDetector.is_available(props["rtl_type"]):
print("The RTL source type {0} is not available. please check requirements.".format(props["rtl_type"]))
return
types = {
"rtl_sdr": {
"command": "rtl_sdr -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -",
"format_conversion": "csdr convert_u8_f",
},
"hackrf": {
"command": "hackrf_transfer -s {samp_rate} -f {center_freq} -g {rf_gain} -l{lna_gain} -a{rf_amp} -r-",
"format_conversion": "csdr convert_s8_f"
},
"sdrplay": {
"command": "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -",
"format_conversion": None
}
}
params = types[props["rtl_type"]]
start_sdr_command = params["command"].format(
samp_rate = props["samp_rate"],
center_freq = props["center_freq"],
ppm = props["ppm"],
rf_gain = props["rf_gain"],
lna_gain = props["lna_gain"],
rf_amp = props["rf_amp"]
)
if params["format_conversion"] is not None:
start_sdr_command += " | " + params["format_conversion"]
nmux_bufcnt = nmux_bufsize = 0
while nmux_bufsize < props["samp_rate"]/4: nmux_bufsize += 4096
@ -15,7 +57,7 @@ class RtlNmuxSource(threading.Thread):
print("[RtlNmuxSource] Error: nmux_bufsize or nmux_bufcnt is zero. These depend on nmux_memory and samp_rate options in config_webrx.py")
return
print("[RtlNmuxSource] nmux_bufsize = %d, nmux_bufcnt = %d" % (nmux_bufsize, nmux_bufcnt))
cmd = props["start_rtl_command"] + "| nmux --bufsize %d --bufcnt %d --port %d --address 127.0.0.1" % (nmux_bufsize, nmux_bufcnt, props["iq_server_port"])
cmd = start_sdr_command + " | nmux --bufsize %d --bufcnt %d --port %d --address 127.0.0.1" % (nmux_bufsize, nmux_bufcnt, props["iq_server_port"])
self.process = subprocess.Popen(cmd, shell=True)
print("[RtlNmuxSource] Started rtl source: " + cmd)
self.process.wait()
@ -37,7 +79,7 @@ class SpectrumThread(threading.Thread):
def run(self):
props = PropertyManager.getSharedInstance().collect(
"samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor", "fft_compression", "format_conversion",
"samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor", "fft_compression",
"csdr_dynamic_bufsize", "csdr_print_bufsizes", "csdr_through", "iq_server_port"
)
@ -54,7 +96,6 @@ class SpectrumThread(threading.Thread):
dsp.set_fft_fps(fft_fps)
dsp.set_fft_averages(int(round(1.0 * samp_rate / fft_size / fft_fps / (1.0 - fft_voverlap_factor))) if fft_voverlap_factor>0 else 0)
dsp.set_fft_compression(props["fft_compression"])
dsp.set_format_conversion(props["format_conversion"])
dsp.csdr_dynamic_bufsize = props["csdr_dynamic_bufsize"]
dsp.csdr_print_bufsizes = props["csdr_print_bufsizes"]
dsp.csdr_through = props["csdr_through"]
@ -94,7 +135,7 @@ class DspManager(object):
self.handler = handler
self.localProps = PropertyManager.getSharedInstance().collect(
"audio_compression", "fft_compression", "format_conversion", "digimodes_fft_size", "csdr_dynamic_bufsize",
"audio_compression", "fft_compression", "digimodes_fft_size", "csdr_dynamic_bufsize",
"csdr_print_bufsizes", "csdr_through", "iq_server_port", "digimodes_enable", "samp_rate"
)
@ -102,7 +143,6 @@ class DspManager(object):
#dsp_initialized=False
self.localProps.getProperty("audio_compression").wire(self.dsp.set_audio_compression)
self.localProps.getProperty("fft_compression").wire(self.dsp.set_fft_compression)
self.localProps.getProperty("format_conversion").wire(self.dsp.set_format_conversion)
self.dsp.set_offset_freq(0)
self.dsp.set_bpf(-4000,4000)
self.localProps.getProperty("digimodes_fft_size").wire(self.dsp.set_secondary_fft_size)