diff --git a/qspectrumanalyzer/__main__.py b/qspectrumanalyzer/__main__.py index 0a2d33a..a61562f 100755 --- a/qspectrumanalyzer/__main__.py +++ b/qspectrumanalyzer/__main__.py @@ -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)) diff --git a/qspectrumanalyzer/backend.py b/qspectrumanalyzer/backend.py index 1fa6556..5345629 100644 --- a/qspectrumanalyzer/backend.py +++ b/qspectrumanalyzer/backend.py @@ -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"]: diff --git a/qspectrumanalyzer/qspectrumanalyzer.ui b/qspectrumanalyzer/qspectrumanalyzer.ui index 2562645..63467ba 100644 --- a/qspectrumanalyzer/qspectrumanalyzer.ui +++ b/qspectrumanalyzer/qspectrumanalyzer.ui @@ -189,13 +189,13 @@ 3 - 0.000000000000000 + 24.000000000000000 - 6000.000000000000000 + 1766.000000000000000 - 88.000000000000000 + 87.000000000000000 @@ -227,10 +227,10 @@ 3 - 0.000000000000000 + 24.000000000000000 - 6000.000000000000000 + 1766.000000000000000 108.000000000000000 @@ -265,10 +265,10 @@ 3 - 5000.000000000000000 + 2800.000000000000000 - 100.000000000000000 + 10.000000000000000 diff --git a/qspectrumanalyzer/ui_qspectrumanalyzer.py b/qspectrumanalyzer/ui_qspectrumanalyzer.py index 115af1d..db0ed27 100644 --- a/qspectrumanalyzer/ui_qspectrumanalyzer.py +++ b/qspectrumanalyzer/ui_qspectrumanalyzer.py @@ -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)