Merge pull request #3 from mossmann/master

hackrf_sweep gain configuration support
This commit is contained in:
Mike Walters 2017-02-12 11:51:19 +00:00 committed by GitHub
commit aba4f40bff
4 changed files with 101 additions and 18 deletions

View File

@ -53,6 +53,14 @@ class QSpectrumAnalyzerSettings(QtGui.QDialog, Ui_QSpectrumAnalyzerSettings):
def on_backendComboBox_currentIndexChanged(self, text):
"""Change executable when backend is changed"""
self.executableEdit.setText(text)
if text == "hackrf_sweep":
self.sampleRateSpinBox.setMinimum(20000000)
self.sampleRateSpinBox.setMaximum(20000000)
self.sampleRateSpinBox.setValue(20000000)
else:
self.sampleRateSpinBox.setMinimum(0)
self.sampleRateSpinBox.setMaximum(25000000)
self.sampleRateSpinBox.setValue(2560000)
def accept(self):
"""Save settings when dialog is accepted"""
@ -185,11 +193,74 @@ class QSpectrumAnalyzerMainWindow(QtGui.QMainWindow, Ui_QSpectrumAnalyzerMainWin
backend = settings.value("backend", "rtl_power")
if backend == "rtl_power_fftw":
self.gainSpinBox.setMinimum(-1)
self.gainSpinBox.setMaximum(49)
self.gainSpinBox.setValue(-1)
self.startFreqSpinBox.setMinimum(24)
self.startFreqSpinBox.setMaximum(1766)
self.startFreqSpinBox.setValue(87)
self.stopFreqSpinBox.setMinimum(24)
self.stopFreqSpinBox.setMaximum(1766)
self.stopFreqSpinBox.setValue(108)
self.binSizeSpinBox.setMinimum(0)
self.binSizeSpinBox.setMaximum(2800)
self.binSizeSpinBox.setValue(10)
self.intervalSpinBox.setMinimum(0)
self.intervalSpinBox.setMaximum(999)
self.intervalSpinBox.setValue(10)
self.ppmSpinBox.setMinimum(-999)
self.ppmSpinBox.setMaximum(999)
self.ppmSpinBox.setValue(0)
self.cropSpinBox.setMinimum(0)
self.cropSpinBox.setMaximum(99)
self.cropSpinBox.setValue(0)
self.rtl_power_thread = RtlPowerFftwThread(self.data_storage)
elif backend == "hackrf_sweep":
self.gainSpinBox.setMinimum(0)
self.gainSpinBox.setMaximum(102)
self.gainSpinBox.setValue(40)
self.startFreqSpinBox.setMinimum(0)
self.startFreqSpinBox.setMaximum(7230)
self.startFreqSpinBox.setValue(0)
self.stopFreqSpinBox.setMinimum(0)
self.stopFreqSpinBox.setMaximum(7250)
self.stopFreqSpinBox.setValue(6000)
self.binSizeSpinBox.setMinimum(40)
self.binSizeSpinBox.setMaximum(5000)
self.binSizeSpinBox.setValue(1000)
self.intervalSpinBox.setMinimum(0)
self.intervalSpinBox.setMaximum(0)
self.intervalSpinBox.setValue(0)
self.ppmSpinBox.setMinimum(0)
self.ppmSpinBox.setMaximum(0)
self.ppmSpinBox.setValue(0)
self.cropSpinBox.setMinimum(0)
self.cropSpinBox.setMaximum(0)
self.cropSpinBox.setValue(0)
self.rtl_power_thread = HackRFSweepThread(self.data_storage)
print(self.rtl_power_thread)
else:
self.gainSpinBox.setMinimum(-1)
self.gainSpinBox.setMaximum(49)
self.gainSpinBox.setValue(-1)
self.startFreqSpinBox.setMinimum(24)
self.startFreqSpinBox.setMaximum(1766)
self.startFreqSpinBox.setValue(87)
self.stopFreqSpinBox.setMinimum(24)
self.stopFreqSpinBox.setMaximum(1766)
self.stopFreqSpinBox.setValue(108)
self.binSizeSpinBox.setMinimum(0)
self.binSizeSpinBox.setMaximum(2800)
self.binSizeSpinBox.setValue(10)
self.intervalSpinBox.setMinimum(0)
self.intervalSpinBox.setMaximum(999)
self.intervalSpinBox.setValue(10)
self.ppmSpinBox.setMinimum(-999)
self.ppmSpinBox.setMaximum(999)
self.ppmSpinBox.setValue(0)
self.cropSpinBox.setMinimum(0)
self.cropSpinBox.setMaximum(99)
self.cropSpinBox.setValue(0)
self.rtl_power_thread = RtlPowerThread(self.data_storage)
self.rtl_power_thread.rtlPowerStarted.connect(self.update_buttons)
@ -223,9 +294,9 @@ class QSpectrumAnalyzerMainWindow(QtGui.QMainWindow, Ui_QSpectrumAnalyzerMainWin
def load_settings(self):
"""Restore spectrum analyzer settings and window geometry"""
settings = QtCore.QSettings()
self.startFreqSpinBox.setValue(settings.value("start_freq", 88.0, float))
self.startFreqSpinBox.setValue(settings.value("start_freq", 87.0, float))
self.stopFreqSpinBox.setValue(settings.value("stop_freq", 108.0, float))
self.binSizeSpinBox.setValue(settings.value("bin_size", 100.0, float))
self.binSizeSpinBox.setValue(settings.value("bin_size", 10.0, float))
self.intervalSpinBox.setValue(settings.value("interval", 10.0, float))
self.gainSpinBox.setValue(settings.value("gain", 0, int))
self.ppmSpinBox.setValue(settings.value("ppm", 0, int))

View File

@ -275,7 +275,7 @@ class RtlPowerFftwThread(RtlPowerBaseThread):
class HackRFSweepThread(RtlPowerBaseThread):
"""Thread which runs hackrf_sweep process"""
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):
"""Setup hackrf_sweep params"""
# 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
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 = {
"start_freq": start_freq, # MHz
"stop_freq": stop_freq, # MHz
@ -301,7 +309,9 @@ class HackRFSweepThread(RtlPowerBaseThread):
"sample_rate": 20e6, # sps
"bin_size": bin_size, # kHz
"interval": 0, # seconds
"gain": 0,
"gain": gain,
"lna_gain": lna_gain,
"vga_gain": vga_gain,
"ppm": 0,
"crop": 0,
"single_shot": single_shot
@ -322,6 +332,8 @@ class HackRFSweepThread(RtlPowerBaseThread):
int(self.params["stop_freq"])),
"-B",
"-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"]:

View File

@ -189,13 +189,13 @@
<number>3</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
<double>24.000000000000000</double>
</property>
<property name="maximum">
<double>6000.000000000000000</double>
<double>1766.000000000000000</double>
</property>
<property name="value">
<double>88.000000000000000</double>
<double>87.000000000000000</double>
</property>
</widget>
</item>
@ -227,10 +227,10 @@
<number>3</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
<double>24.000000000000000</double>
</property>
<property name="maximum">
<double>6000.000000000000000</double>
<double>1766.000000000000000</double>
</property>
<property name="value">
<double>108.000000000000000</double>
@ -265,10 +265,10 @@
<number>3</number>
</property>
<property name="maximum">
<double>5000.000000000000000</double>
<double>2800.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
<double>10.000000000000000</double>
</property>
</widget>
</item>

View File

@ -116,9 +116,9 @@ class Ui_QSpectrumAnalyzerMainWindow(object):
self.startFreqSpinBox.setSizePolicy(sizePolicy)
self.startFreqSpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.startFreqSpinBox.setDecimals(3)
self.startFreqSpinBox.setMinimum(0.0)
self.startFreqSpinBox.setMaximum(6000.0)
self.startFreqSpinBox.setProperty("value", 88.0)
self.startFreqSpinBox.setMinimum(24.0)
self.startFreqSpinBox.setMaximum(1766.0)
self.startFreqSpinBox.setProperty("value", 87.0)
self.startFreqSpinBox.setObjectName(_fromUtf8("startFreqSpinBox"))
self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.startFreqSpinBox)
self.label_3 = QtGui.QLabel(self.frequencyDockWidgetContents)
@ -132,8 +132,8 @@ class Ui_QSpectrumAnalyzerMainWindow(object):
self.stopFreqSpinBox.setSizePolicy(sizePolicy)
self.stopFreqSpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.stopFreqSpinBox.setDecimals(3)
self.stopFreqSpinBox.setMinimum(0.0)
self.stopFreqSpinBox.setMaximum(6000.0)
self.stopFreqSpinBox.setMinimum(24.0)
self.stopFreqSpinBox.setMaximum(1766.0)
self.stopFreqSpinBox.setProperty("value", 108.0)
self.stopFreqSpinBox.setObjectName(_fromUtf8("stopFreqSpinBox"))
self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.stopFreqSpinBox)
@ -148,8 +148,8 @@ class Ui_QSpectrumAnalyzerMainWindow(object):
self.binSizeSpinBox.setSizePolicy(sizePolicy)
self.binSizeSpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.binSizeSpinBox.setDecimals(3)
self.binSizeSpinBox.setMaximum(5000.0)
self.binSizeSpinBox.setProperty("value", 100.0)
self.binSizeSpinBox.setMaximum(2800.0)
self.binSizeSpinBox.setProperty("value", 10.0)
self.binSizeSpinBox.setObjectName(_fromUtf8("binSizeSpinBox"))
self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.binSizeSpinBox)
spacerItem1 = QtGui.QSpacerItem(20, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)