From 6cf269470835403b4aab65d57cadd1084da684eb Mon Sep 17 00:00:00 2001 From: "Michal Krenek (Mikos)" Date: Thu, 19 May 2016 22:28:44 +0200 Subject: [PATCH] Add support for multiple RTL-SDR devices (select device index in settings) --- qspectrumanalyzer/__main__.py | 3 ++ qspectrumanalyzer/backend.py | 10 +++-- .../languages/qspectrumanalyzer_cs.ts | 31 ++++++++------- .../qspectrumanalyzer_settings.ui | 39 +++++++++++++++---- .../ui_qspectrumanalyzer_settings.py | 21 ++++++++-- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/qspectrumanalyzer/__main__.py b/qspectrumanalyzer/__main__.py index 5423f6f..a160e99 100755 --- a/qspectrumanalyzer/__main__.py +++ b/qspectrumanalyzer/__main__.py @@ -32,6 +32,7 @@ class QSpectrumAnalyzerSettings(QtGui.QDialog, Ui_QSpectrumAnalyzerSettings): settings = QtCore.QSettings() self.executableEdit.setText(settings.value("rtl_power_executable", "rtl_power")) self.waterfallHistorySizeSpinBox.setValue(settings.value("waterfall_history_size", 100, int)) + self.deviceIndexSpinBox.setValue(settings.value("device_index", 0, int)) self.sampleRateSpinBox.setValue(settings.value("sample_rate", 2560000, int)) backend = settings.value("backend", "rtl_power") @@ -58,6 +59,7 @@ class QSpectrumAnalyzerSettings(QtGui.QDialog, Ui_QSpectrumAnalyzerSettings): settings = QtCore.QSettings() settings.setValue("rtl_power_executable", self.executableEdit.text()) settings.setValue("waterfall_history_size", self.waterfallHistorySizeSpinBox.value()) + settings.setValue("device_index", self.deviceIndexSpinBox.value()) settings.setValue("sample_rate", self.sampleRateSpinBox.value()) settings.setValue("backend", self.backendComboBox.currentText()) QtGui.QDialog.accept(self) @@ -345,6 +347,7 @@ class QSpectrumAnalyzerMainWindow(QtGui.QMainWindow, Ui_QSpectrumAnalyzerMainWin ppm=int(self.ppmSpinBox.value()), crop=int(self.cropSpinBox.value()) / 100.0, single_shot=single_shot, + device_index=settings.value("device_index", 0, int), sample_rate=settings.value("sample_rate", 2560000, int)) self.rtl_power_thread.start() diff --git a/qspectrumanalyzer/backend.py b/qspectrumanalyzer/backend.py index 7a8492b..206c910 100644 --- a/qspectrumanalyzer/backend.py +++ b/qspectrumanalyzer/backend.py @@ -22,7 +22,7 @@ class RtlPowerBaseThread(QtCore.QThread): self.wait() def setup(self, start_freq, stop_freq, bin_size, interval=10.0, gain=-1, - ppm=0, crop=0, single_shot=False, sample_rate=2560000): + ppm=0, crop=0, single_shot=False, device_index=0, sample_rate=2560000): """Setup rtl_power params""" raise NotImplementedError @@ -63,13 +63,14 @@ class RtlPowerBaseThread(QtCore.QThread): class RtlPowerThread(RtlPowerBaseThread): """Thread which runs rtl_power process""" def setup(self, start_freq, stop_freq, bin_size, interval=10.0, gain=-1, - ppm=0, crop=0, single_shot=False, sample_rate=2560000): + ppm=0, crop=0, single_shot=False, device_index=0, sample_rate=2560000): """Setup rtl_power params""" self.params = { "start_freq": start_freq, "stop_freq": stop_freq, "bin_size": bin_size, "interval": interval, + "device_index": device_index, "hops": 0, "gain": gain, "ppm": ppm, @@ -93,6 +94,7 @@ class RtlPowerThread(RtlPowerBaseThread): self.params["stop_freq"], self.params["bin_size"]), "-i", "{}".format(self.params["interval"]), + "-d", "{}".format(self.params["device_index"]), "-p", "{}".format(self.params["ppm"]), "-c", "{}".format(self.params["crop"]) ] @@ -143,7 +145,7 @@ class RtlPowerThread(RtlPowerBaseThread): class RtlPowerFftwThread(RtlPowerBaseThread): """Thread which runs rtl_power_fftw process""" def setup(self, start_freq, stop_freq, bin_size, interval=10.0, gain=-1, - ppm=0, crop=0, single_shot=False, sample_rate=2560000): + ppm=0, crop=0, single_shot=False, device_index=0, sample_rate=2560000): """Setup rtl_power_fftw params""" crop = crop * 100 overlap = crop * 2 @@ -158,6 +160,7 @@ class RtlPowerFftwThread(RtlPowerBaseThread): "start_freq": start_freq, "stop_freq": stop_freq, "freq_range": freq_range, + "device_index": device_index, "sample_rate": sample_rate, "bin_size": bin_size, "bins": bins, @@ -199,6 +202,7 @@ class RtlPowerFftwThread(RtlPowerBaseThread): self.params["stop_freq"]), "-b", "{}".format(self.params["bins"]), "-t", "{}".format(self.params["time"]), + "-d", "{}".format(self.params["device_index"]), "-r", "{}".format(self.params["sample_rate"]), "-p", "{}".format(self.params["ppm"]), ] diff --git a/qspectrumanalyzer/languages/qspectrumanalyzer_cs.ts b/qspectrumanalyzer/languages/qspectrumanalyzer_cs.ts index 642818a..a647333 100644 --- a/qspectrumanalyzer/languages/qspectrumanalyzer_cs.ts +++ b/qspectrumanalyzer/languages/qspectrumanalyzer_cs.ts @@ -81,7 +81,7 @@ - + QSpectrumAnalyzer {} @@ -176,12 +176,12 @@ - + N/A - + About - QSpectrumAnalyzer @@ -206,7 +206,7 @@ - + Frequency hops: {} | Sweep time: {:.2f} s | FPS: {:.2f} @@ -252,50 +252,55 @@ QSpectrumAnalyzerSettings - + rtl_power - + ... - + rtl_power_fftw - + &Backend: - + E&xecutable: - + &Waterfall history size: - + Sa&mple rate: - + Select executable - QSpectrumAnalyzer - + Settings - QSpectrumAnalyzer + + + &Device index: + + QSpectrumAnalyzerSmooth diff --git a/qspectrumanalyzer/qspectrumanalyzer_settings.ui b/qspectrumanalyzer/qspectrumanalyzer_settings.ui index 87398e4..2f00976 100644 --- a/qspectrumanalyzer/qspectrumanalyzer_settings.ui +++ b/qspectrumanalyzer/qspectrumanalyzer_settings.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 210 + 325 + 259 @@ -92,6 +92,29 @@ + + + &Device index: + + + deviceIndexSpinBox + + + + + + + 0 + + + 99 + + + 0 + + + + Sa&mple rate: @@ -101,7 +124,7 @@ - + 0 @@ -149,7 +172,9 @@ executableEdit executableButton waterfallHistorySizeSpinBox + deviceIndexSpinBox sampleRateSpinBox + buttonBox @@ -160,8 +185,8 @@ accept() - 230 - 203 + 236 + 252 157 @@ -176,8 +201,8 @@ reject() - 298 - 203 + 304 + 252 286 diff --git a/qspectrumanalyzer/ui_qspectrumanalyzer_settings.py b/qspectrumanalyzer/ui_qspectrumanalyzer_settings.py index dd6bf7e..2c34180 100644 --- a/qspectrumanalyzer/ui_qspectrumanalyzer_settings.py +++ b/qspectrumanalyzer/ui_qspectrumanalyzer_settings.py @@ -25,7 +25,7 @@ except AttributeError: class Ui_QSpectrumAnalyzerSettings(object): def setupUi(self, QSpectrumAnalyzerSettings): QSpectrumAnalyzerSettings.setObjectName(_fromUtf8("QSpectrumAnalyzerSettings")) - QSpectrumAnalyzerSettings.resize(400, 210) + QSpectrumAnalyzerSettings.resize(325, 259) self.verticalLayout = QtGui.QVBoxLayout(QSpectrumAnalyzerSettings) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.formLayout = QtGui.QFormLayout() @@ -59,16 +59,25 @@ class Ui_QSpectrumAnalyzerSettings(object): self.waterfallHistorySizeSpinBox.setProperty("value", 100) self.waterfallHistorySizeSpinBox.setObjectName(_fromUtf8("waterfallHistorySizeSpinBox")) self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.waterfallHistorySizeSpinBox) + self.label_5 = QtGui.QLabel(QSpectrumAnalyzerSettings) + self.label_5.setObjectName(_fromUtf8("label_5")) + self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_5) + self.deviceIndexSpinBox = QtGui.QSpinBox(QSpectrumAnalyzerSettings) + self.deviceIndexSpinBox.setMinimum(0) + self.deviceIndexSpinBox.setMaximum(99) + self.deviceIndexSpinBox.setProperty("value", 0) + self.deviceIndexSpinBox.setObjectName(_fromUtf8("deviceIndexSpinBox")) + self.formLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.deviceIndexSpinBox) self.label_4 = QtGui.QLabel(QSpectrumAnalyzerSettings) self.label_4.setObjectName(_fromUtf8("label_4")) - self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_4) + self.formLayout.setWidget(4, QtGui.QFormLayout.LabelRole, self.label_4) self.sampleRateSpinBox = QtGui.QSpinBox(QSpectrumAnalyzerSettings) self.sampleRateSpinBox.setMinimum(0) self.sampleRateSpinBox.setMaximum(25000000) self.sampleRateSpinBox.setSingleStep(10000) self.sampleRateSpinBox.setProperty("value", 2560000) self.sampleRateSpinBox.setObjectName(_fromUtf8("sampleRateSpinBox")) - self.formLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.sampleRateSpinBox) + self.formLayout.setWidget(4, QtGui.QFormLayout.FieldRole, self.sampleRateSpinBox) self.verticalLayout.addLayout(self.formLayout) spacerItem = QtGui.QSpacerItem(20, 21, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout.addItem(spacerItem) @@ -80,6 +89,7 @@ class Ui_QSpectrumAnalyzerSettings(object): self.label_3.setBuddy(self.backendComboBox) self.label.setBuddy(self.executableEdit) self.label_2.setBuddy(self.waterfallHistorySizeSpinBox) + self.label_5.setBuddy(self.deviceIndexSpinBox) self.label_4.setBuddy(self.sampleRateSpinBox) self.retranslateUi(QSpectrumAnalyzerSettings) @@ -89,7 +99,9 @@ class Ui_QSpectrumAnalyzerSettings(object): QSpectrumAnalyzerSettings.setTabOrder(self.backendComboBox, self.executableEdit) QSpectrumAnalyzerSettings.setTabOrder(self.executableEdit, self.executableButton) QSpectrumAnalyzerSettings.setTabOrder(self.executableButton, self.waterfallHistorySizeSpinBox) - QSpectrumAnalyzerSettings.setTabOrder(self.waterfallHistorySizeSpinBox, self.sampleRateSpinBox) + QSpectrumAnalyzerSettings.setTabOrder(self.waterfallHistorySizeSpinBox, self.deviceIndexSpinBox) + QSpectrumAnalyzerSettings.setTabOrder(self.deviceIndexSpinBox, self.sampleRateSpinBox) + QSpectrumAnalyzerSettings.setTabOrder(self.sampleRateSpinBox, self.buttonBox) def retranslateUi(self, QSpectrumAnalyzerSettings): QSpectrumAnalyzerSettings.setWindowTitle(_translate("QSpectrumAnalyzerSettings", "Settings - QSpectrumAnalyzer", None)) @@ -100,5 +112,6 @@ class Ui_QSpectrumAnalyzerSettings(object): self.executableEdit.setText(_translate("QSpectrumAnalyzerSettings", "rtl_power", None)) self.executableButton.setText(_translate("QSpectrumAnalyzerSettings", "...", None)) self.label_2.setText(_translate("QSpectrumAnalyzerSettings", "&Waterfall history size:", None)) + self.label_5.setText(_translate("QSpectrumAnalyzerSettings", "&Device index:", None)) self.label_4.setText(_translate("QSpectrumAnalyzerSettings", "Sa&mple rate:", None))