improved property system
This commit is contained in:
parent
df9646aaf9
commit
cb187fd3c2
@ -24,12 +24,27 @@ class PropertyManager(object):
|
||||
PropertyManager.sharedInstance = PropertyManager()
|
||||
return PropertyManager.sharedInstance
|
||||
|
||||
def __init__(self):
|
||||
def collect(self, *props):
|
||||
return PropertyManager(dict((name, self.getProperty(name)) for name in props))
|
||||
|
||||
def __init__(self, properties = None):
|
||||
self.properties = {}
|
||||
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 __getitem__(self, name):
|
||||
return self.getPropertyValue(name)
|
||||
|
||||
def __setitem__(self, name, value):
|
||||
self.getProperty(name).setValue(value)
|
||||
|
||||
def getProperty(self, name):
|
||||
if not name in self.properties:
|
||||
self.properties[name] = Property()
|
||||
self.add(name, Property())
|
||||
return self.properties[name]
|
||||
|
||||
def getPropertyValue(self, name):
|
||||
|
@ -6,16 +6,16 @@ import time
|
||||
|
||||
class RtlNmuxSource(threading.Thread):
|
||||
def run(self):
|
||||
pm = PropertyManager.getSharedInstance()
|
||||
props = PropertyManager.getSharedInstance().collect("samp_rate", "nmux_memory", "start_rtl_command", "iq_server_port")
|
||||
|
||||
nmux_bufcnt = nmux_bufsize = 0
|
||||
while nmux_bufsize < pm.getPropertyValue("samp_rate")/4: nmux_bufsize += 4096
|
||||
while nmux_bufsize * nmux_bufcnt < pm.getPropertyValue("nmux_memory") * 1e6: nmux_bufcnt += 1
|
||||
while nmux_bufsize < props["samp_rate"]/4: nmux_bufsize += 4096
|
||||
while nmux_bufsize * nmux_bufcnt < props["nmux_memory"] * 1e6: nmux_bufcnt += 1
|
||||
if nmux_bufcnt == 0 or nmux_bufsize == 0:
|
||||
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 = pm.getPropertyValue("start_rtl_command") + "| nmux --bufsize %d --bufcnt %d --port %d --address 127.0.0.1" % (nmux_bufsize, nmux_bufcnt, pm.getPropertyValue("iq_server_port"))
|
||||
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"])
|
||||
self.process = subprocess.Popen(cmd, shell=True)
|
||||
print("[RtlNmuxSource] Started rtl source: " + cmd)
|
||||
self.process.wait()
|
||||
@ -36,31 +36,31 @@ class SpectrumThread(threading.Thread):
|
||||
super().__init__()
|
||||
|
||||
def run(self):
|
||||
pm = PropertyManager.getSharedInstance()
|
||||
props = PropertyManager.getSharedInstance().collect(
|
||||
"samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor", "fft_compression", "format_conversion",
|
||||
"csdr_dynamic_bufsize", "csdr_print_bufsizes", "csdr_through", "iq_server_port"
|
||||
)
|
||||
|
||||
samp_rate = pm.getPropertyValue("samp_rate")
|
||||
fft_size = pm.getPropertyValue("fft_size")
|
||||
fft_fps = pm.getPropertyValue("fft_fps")
|
||||
fft_voverlap_factor = pm.getPropertyValue("fft_voverlap_factor")
|
||||
fft_compression = pm.getPropertyValue("fft_compression")
|
||||
format_conversion = pm.getPropertyValue("format_conversion")
|
||||
samp_rate = props["samp_rate"]
|
||||
fft_size = props["fft_size"]
|
||||
fft_fps = props["fft_fps"]
|
||||
fft_voverlap_factor = props["fft_voverlap_factor"]
|
||||
|
||||
spectrum_dsp=dsp=csdr.dsp()
|
||||
dsp.nc_port = pm.getPropertyValue("iq_server_port")
|
||||
dsp = csdr.dsp()
|
||||
dsp.nc_port = props["iq_server_port"]
|
||||
dsp.set_demodulator("fft")
|
||||
dsp.set_samp_rate(samp_rate)
|
||||
dsp.set_fft_size(fft_size)
|
||||
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(fft_compression)
|
||||
dsp.set_format_conversion(format_conversion)
|
||||
dsp.csdr_dynamic_bufsize = pm.getPropertyValue("csdr_dynamic_bufsize")
|
||||
dsp.csdr_print_bufsizes = pm.getPropertyValue("csdr_print_bufsizes")
|
||||
dsp.csdr_through = pm.getPropertyValue("csdr_through")
|
||||
sleep_sec=0.87/fft_fps
|
||||
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"]
|
||||
print("[openwebrx-spectrum] Spectrum thread initialized successfully.")
|
||||
dsp.start()
|
||||
if pm.getPropertyValue("csdr_dynamic_bufsize"):
|
||||
if props["csdr_dynamic_bufsize"]:
|
||||
dsp.read(8) #dummy read to skip bufsize & preamble
|
||||
print("[openwebrx-spectrum] Note: CSDR_DYNAMIC_BUFSIZE_ON = 1")
|
||||
print("[openwebrx-spectrum] Spectrum thread started.")
|
||||
@ -93,26 +93,28 @@ class DspManager(object):
|
||||
self.doRun = True
|
||||
self.handler = handler
|
||||
|
||||
pm = PropertyManager.getSharedInstance()
|
||||
self.localProps = PropertyManager.getSharedInstance().collect(
|
||||
"audio_compression", "fft_compression", "format_conversion", "digimodes_fft_size", "csdr_dynamic_bufsize",
|
||||
"csdr_print_bufsizes", "csdr_through", "iq_server_port", "digimodes_enable", "samp_rate"
|
||||
)
|
||||
|
||||
self.dsp = csdr.dsp()
|
||||
#dsp_initialized=False
|
||||
pm.getProperty("audio_compression").wire(self.dsp.set_audio_compression)
|
||||
pm.getProperty("fft_compression").wire(self.dsp.set_fft_compression)
|
||||
pm.getProperty("format_conversion").wire(self.dsp.set_format_conversion)
|
||||
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)
|
||||
pm.getProperty("digimodes_fft_size").wire(self.dsp.set_secondary_fft_size)
|
||||
self.localProps.getProperty("digimodes_fft_size").wire(self.dsp.set_secondary_fft_size)
|
||||
|
||||
self.dsp.nc_port=pm.getPropertyValue("iq_server_port")
|
||||
self.dsp.csdr_dynamic_bufsize = pm.getPropertyValue("csdr_dynamic_bufsize")
|
||||
self.dsp.csdr_print_bufsizes = pm.getPropertyValue("csdr_print_bufsizes")
|
||||
self.dsp.csdr_through = pm.getPropertyValue("csdr_through")
|
||||
self.dsp.nc_port = self.localProps["iq_server_port"]
|
||||
self.dsp.csdr_dynamic_bufsize = self.localProps["csdr_dynamic_bufsize"]
|
||||
self.dsp.csdr_print_bufsizes = self.localProps["csdr_print_bufsizes"]
|
||||
self.dsp.csdr_through = self.localProps["csdr_through"]
|
||||
|
||||
pm.getProperty("samp_rate").wire(self.dsp.set_samp_rate)
|
||||
self.localProps.getProperty("samp_rate").wire(self.dsp.set_samp_rate)
|
||||
#do_secondary_demod=False
|
||||
|
||||
self.localProps = PropertyManager()
|
||||
self.localProps.getProperty("output_rate").wire(self.dsp.set_output_rate)
|
||||
self.localProps.getProperty("offset_freq").wire(self.dsp.set_offset_freq)
|
||||
self.localProps.getProperty("squelch_level").wire(self.dsp.set_squelch_level)
|
||||
@ -136,7 +138,7 @@ class DspManager(object):
|
||||
self.dsp.start()
|
||||
self.localProps.getProperty("mod").wire(set_mod)
|
||||
|
||||
if (pm.getPropertyValue("digimodes_enable")):
|
||||
if (self.localProps["digimodes_enable"]):
|
||||
def set_secondary_mod(mod):
|
||||
if mod == False: mod = None
|
||||
if self.dsp.get_secondary_demodulator() == mod: return
|
||||
@ -147,7 +149,7 @@ class DspManager(object):
|
||||
else:
|
||||
self.dsp.set_secondary_demodulator(mod)
|
||||
self.handler.write_secondary_dsp_config({
|
||||
"secondary_fft_size":pm.getPropertyValue("digimodes_fft_size"),
|
||||
"secondary_fft_size":self.localProps["digimodes_fft_size"],
|
||||
"if_samp_rate":self.dsp.if_samp_rate(),
|
||||
"secondary_bw":self.dsp.secondary_bw()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user