From eb758685a1e624cc46d3b8fb777ecd47f42ad394 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 19 May 2019 13:17:36 +0200 Subject: [PATCH 1/4] add antenna switching support for sdrplay --- config_webrx.py | 12 ++++++++---- owrx/config.py | 2 +- owrx/source.py | 11 +++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/config_webrx.py b/config_webrx.py index 3bd92c6..d16b948 100644 --- a/config_webrx.py +++ b/config_webrx.py @@ -133,7 +133,8 @@ sdrs = { "rf_gain": 40, "samp_rate": 500000, "start_freq": 14070000, - "start_mod": "usb" + "start_mod": "usb", + "antenna": "Antenna A" }, "40m": { "name":"40m", @@ -141,7 +142,8 @@ sdrs = { "rf_gain": 40, "samp_rate": 500000, "start_freq": 7070000, - "start_mod": "usb" + "start_mod": "usb", + "antenna": "Antenna A" }, "80m": { "name":"80m", @@ -149,7 +151,8 @@ sdrs = { "rf_gain": 40, "samp_rate": 500000, "start_freq": 3570000, - "start_mod": "usb" + "start_mod": "usb", + "antenna": "Antenna A" }, "49m": { "name": "49m Broadcast", @@ -157,7 +160,8 @@ sdrs = { "rf_gain": 40, "samp_rate": 500000, "start_freq": 6070000, - "start_mod": "am" + "start_mod": "am", + "antenna": "Antenna A" } } }, diff --git a/owrx/config.py b/owrx/config.py index 8fb6513..558e343 100644 --- a/owrx/config.py +++ b/owrx/config.py @@ -32,7 +32,7 @@ class PropertyManager(object): return PropertyManager.sharedInstance def collect(self, *props): - return PropertyManager(dict((name, self.getProperty(name) if self.hasProperty(name) else Property()) for name in props)) + return PropertyManager({name: self.getProperty(name) if self.hasProperty(name) else Property() for name in props}) def __init__(self, properties = None): self.properties = {} diff --git a/owrx/source.py b/owrx/source.py index 3efc7d4..9c41318 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -76,7 +76,7 @@ class SdrSource(object): self.props = props self.activateProfile() self.rtlProps = self.props.collect( - "type", "samp_rate", "nmux_memory", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp" + "samp_rate", "nmux_memory", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna" ).defaults(PropertyManager.getSharedInstance()) def restart(name, value): @@ -128,12 +128,7 @@ class SdrSource(object): props = self.rtlProps start_sdr_command = self.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"] + **props.collect("samp_rate", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna").__dict__() ) if self.format_conversion is not None: @@ -243,7 +238,7 @@ class HackrfSource(SdrSource): class SdrplaySource(SdrSource): def __init__(self, props, port): super().__init__(props, port) - self.command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -" + self.command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -a \"{antenna}\" -" self.format_conversion = None def sleepOnRestart(self): From 92abef71723298cf3546b19a35caf44aaea0b7fe Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 19 May 2019 13:36:05 +0200 Subject: [PATCH 2/4] pass antenna parameter only if set --- owrx/source.py | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/owrx/source.py b/owrx/source.py index 9c41318..f5a0f5f 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -92,9 +92,13 @@ class SdrSource(object): self.process = None self.modificationLock = threading.Lock() - # override these in subclasses as necessary - self.command = None - self.format_conversion = None + # override this in subclasses + def getCommand(self): + pass + + # override this in subclasses, if necessary + def getFormatConversion(self): + return None def activateProfile(self, id = None): profiles = self.props["profiles"] @@ -127,12 +131,13 @@ class SdrSource(object): props = self.rtlProps - start_sdr_command = self.command.format( + start_sdr_command = self.getCommand().format( **props.collect("samp_rate", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna").__dict__() ) - if self.format_conversion is not None: - start_sdr_command += " | " + self.format_conversion + format_conversion = self.getFormatConversion() + if format_conversion is not None: + start_sdr_command += " | " + format_conversion nmux_bufcnt = nmux_bufsize = 0 while nmux_bufsize < props["samp_rate"]/4: nmux_bufsize += 4096 @@ -224,22 +229,26 @@ class SdrSource(object): class RtlSdrSource(SdrSource): - def __init__(self, props, port): - super().__init__(props, port) - self.command = "rtl_sdr -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -" - self.format_conversion = "csdr convert_u8_f" + def getCommand(self): + return "rtl_sdr -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -" + + def getFormatConversion(self): + return "csdr convert_u8_f" class HackrfSource(SdrSource): - def __init__(self, props, port): - super().__init__(props, port) - self.command = "hackrf_transfer -s {samp_rate} -f {center_freq} -g {rf_gain} -l{lna_gain} -a{rf_amp} -r-" - self.format_conversion = "csdr convert_s8_f" + def getCommand(self): + return "hackrf_transfer -s {samp_rate} -f {center_freq} -g {rf_gain} -l{lna_gain} -a{rf_amp} -r-" + + def getFormatConversion(self): + return "csdr convert_s8_f" class SdrplaySource(SdrSource): - def __init__(self, props, port): - super().__init__(props, port) - self.command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -a \"{antenna}\" -" - self.format_conversion = None + def getCommand(self): + command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain}" + if self.rtlProps["antenna"] is not None: + command += " -a \"{antenna}\"" + command += " -" + return command def sleepOnRestart(self): time.sleep(1) From 8091831b1f1a3400da1241a720fe3f646fb79b9e Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 19 May 2019 22:10:11 +0200 Subject: [PATCH 3/4] make both gains available for sdrplay --- config_webrx.py | 12 ++++++++---- owrx/connection.py | 2 +- owrx/source.py | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config_webrx.py b/config_webrx.py index d16b948..25053eb 100644 --- a/config_webrx.py +++ b/config_webrx.py @@ -130,7 +130,8 @@ sdrs = { "20m": { "name":"20m", "center_freq": 14150000, - "rf_gain": 40, + "rf_gain": 4, + "if_gain": 40, "samp_rate": 500000, "start_freq": 14070000, "start_mod": "usb", @@ -139,7 +140,8 @@ sdrs = { "40m": { "name":"40m", "center_freq": 7100000, - "rf_gain": 40, + "rf_gain": 4, + "if_gain": 40, "samp_rate": 500000, "start_freq": 7070000, "start_mod": "usb", @@ -148,7 +150,8 @@ sdrs = { "80m": { "name":"80m", "center_freq": 3650000, - "rf_gain": 40, + "rf_gain": 4, + "if_gain": 40, "samp_rate": 500000, "start_freq": 3570000, "start_mod": "usb", @@ -157,7 +160,8 @@ sdrs = { "49m": { "name": "49m Broadcast", "center_freq": 6000000, - "rf_gain": 40, + "rf_gain": 4, + "if_gain": 40, "samp_rate": 500000, "start_freq": 6070000, "start_mod": "am", diff --git a/owrx/connection.py b/owrx/connection.py index 95ce84f..029b8d4 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -81,7 +81,7 @@ class OpenWebRxClient(object): def setParams(self, params): # only the keys in the protected property manager can be overridden from the web - protected = self.sdr.getProps().collect("samp_rate", "center_freq", "rf_gain", "type") \ + protected = self.sdr.getProps().collect("samp_rate", "center_freq", "rf_gain", "type", "if_gain") \ .defaults(PropertyManager.getSharedInstance()) for key, value in params.items(): protected[key] = value diff --git a/owrx/source.py b/owrx/source.py index f5a0f5f..2820abc 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -76,7 +76,7 @@ class SdrSource(object): self.props = props self.activateProfile() self.rtlProps = self.props.collect( - "samp_rate", "nmux_memory", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna" + "samp_rate", "nmux_memory", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna", "if_gain" ).defaults(PropertyManager.getSharedInstance()) def restart(name, value): @@ -132,7 +132,7 @@ class SdrSource(object): props = self.rtlProps start_sdr_command = self.getCommand().format( - **props.collect("samp_rate", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna").__dict__() + **props.collect("samp_rate", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp", "antenna", "if_gain").__dict__() ) format_conversion = self.getFormatConversion() @@ -244,7 +244,11 @@ class HackrfSource(SdrSource): class SdrplaySource(SdrSource): def getCommand(self): - command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain}" + command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm}" + gainMap = { "rf_gain" : "RFGR", "if_gain" : "IFGR"} + gains = [ "{0}={{{1}}}".format(gainMap[name], name) for name in self.rtlProps.collect("rf_gain", "if_gain").__dict__() ] + if gains: + command += " -g {gains}".format(gains = ",".join(gains)) if self.rtlProps["antenna"] is not None: command += " -a \"{antenna}\"" command += " -" From 8a7aeca6b9c1358cc6612b30fd1e0b9637594da2 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 19 May 2019 22:23:35 +0200 Subject: [PATCH 4/4] if_gain is optional, default is agc --- config_webrx.py | 12 ++++++++---- owrx/source.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config_webrx.py b/config_webrx.py index 25053eb..e97ed63 100644 --- a/config_webrx.py +++ b/config_webrx.py @@ -131,17 +131,23 @@ sdrs = { "name":"20m", "center_freq": 14150000, "rf_gain": 4, - "if_gain": 40, "samp_rate": 500000, "start_freq": 14070000, "start_mod": "usb", "antenna": "Antenna A" }, + "30m": { + "name":"30m", + "center_freq": 10125000, + "rf_gain": 4, + "samp_rate": 250000, + "start_freq": 10142000, + "start_mod": "usb" + }, "40m": { "name":"40m", "center_freq": 7100000, "rf_gain": 4, - "if_gain": 40, "samp_rate": 500000, "start_freq": 7070000, "start_mod": "usb", @@ -151,7 +157,6 @@ sdrs = { "name":"80m", "center_freq": 3650000, "rf_gain": 4, - "if_gain": 40, "samp_rate": 500000, "start_freq": 3570000, "start_mod": "usb", @@ -161,7 +166,6 @@ sdrs = { "name": "49m Broadcast", "center_freq": 6000000, "rf_gain": 4, - "if_gain": 40, "samp_rate": 500000, "start_freq": 6070000, "start_mod": "am", diff --git a/owrx/source.py b/owrx/source.py index 2820abc..eeed1a7 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -246,7 +246,7 @@ class SdrplaySource(SdrSource): def getCommand(self): command = "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm}" gainMap = { "rf_gain" : "RFGR", "if_gain" : "IFGR"} - gains = [ "{0}={{{1}}}".format(gainMap[name], name) for name in self.rtlProps.collect("rf_gain", "if_gain").__dict__() ] + gains = [ "{0}={{{1}}}".format(gainMap[name], name) for (name, value) in self.rtlProps.collect("rf_gain", "if_gain").__dict__().items() if value is not None ] if gains: command += " -g {gains}".format(gains = ",".join(gains)) if self.rtlProps["antenna"] is not None: