hackrf_sweep gain configuration support

This commit is contained in:
Michael Ossmann 2017-02-11 21:45:40 -07:00
parent c060f82c25
commit dc39b44c67
2 changed files with 16 additions and 2 deletions

View File

@ -187,6 +187,8 @@ class QSpectrumAnalyzerMainWindow(QtGui.QMainWindow, Ui_QSpectrumAnalyzerMainWin
if backend == "rtl_power_fftw": if backend == "rtl_power_fftw":
self.rtl_power_thread = RtlPowerFftwThread(self.data_storage) self.rtl_power_thread = RtlPowerFftwThread(self.data_storage)
elif backend == "hackrf_sweep": elif backend == "hackrf_sweep":
self.gainSpinBox.setMaximum(102)
self.gainSpinBox.setValue(40)
self.rtl_power_thread = HackRFSweepThread(self.data_storage) self.rtl_power_thread = HackRFSweepThread(self.data_storage)
print(self.rtl_power_thread) print(self.rtl_power_thread)
else: else:

View File

@ -275,7 +275,7 @@ class RtlPowerFftwThread(RtlPowerBaseThread):
class HackRFSweepThread(RtlPowerBaseThread): class HackRFSweepThread(RtlPowerBaseThread):
"""Thread which runs hackrf_sweep process""" """Thread which runs hackrf_sweep process"""
def setup(self, start_freq=0, stop_freq=6000, bin_size=1000, def setup(self, start_freq=0, stop_freq=6000, bin_size=1000,
interval=0.0, gain=0, ppm=0, crop=0, single_shot=False, interval=0.0, gain=40, ppm=0, crop=0, single_shot=False,
device_index=0, sample_rate=20000000): device_index=0, sample_rate=20000000):
"""Setup hackrf_sweep params""" """Setup hackrf_sweep params"""
# theoretically we can support bins smaller than 40 kHz, but it is # theoretically we can support bins smaller than 40 kHz, but it is
@ -293,6 +293,14 @@ class HackRFSweepThread(RtlPowerBaseThread):
total_bandwidth = step_count * step_bandwidth total_bandwidth = step_count * step_bandwidth
stop_freq = start_freq + total_bandwidth stop_freq = start_freq + total_bandwidth
# distribute gain between two analog gain stages
if gain < 0:
gain = 0
if gain > 102:
gain = 102
lna_gain = 8 * (gain // 18)
vga_gain = 2 * ((gain - lna_gain) // 2)
self.params = { self.params = {
"start_freq": start_freq, # MHz "start_freq": start_freq, # MHz
"stop_freq": stop_freq, # MHz "stop_freq": stop_freq, # MHz
@ -301,7 +309,9 @@ class HackRFSweepThread(RtlPowerBaseThread):
"sample_rate": 20e6, # sps "sample_rate": 20e6, # sps
"bin_size": bin_size, # kHz "bin_size": bin_size, # kHz
"interval": 0, # seconds "interval": 0, # seconds
"gain": 0, "gain": gain,
"lna_gain": lna_gain,
"vga_gain": vga_gain,
"ppm": 0, "ppm": 0,
"crop": 0, "crop": 0,
"single_shot": single_shot "single_shot": single_shot
@ -322,6 +332,8 @@ class HackRFSweepThread(RtlPowerBaseThread):
int(self.params["stop_freq"])), int(self.params["stop_freq"])),
"-B", "-B",
"-w", "{}".format(int(self.params["bin_size"]*1000)), "-w", "{}".format(int(self.params["bin_size"]*1000)),
"-l", "{}".format(int(self.params["lna_gain"])),
"-g", "{}".format(int(self.params["vga_gain"])),
] ]
if self.params["single_shot"]: if self.params["single_shot"]: