diff --git a/lib/dependencies.py b/lib/dependencies.py index e3daa1a41fa7cb88e8d90a88ee7ff97c117030a7..eae54035b050d0ebe27e6f9c19a7c01a9510275a 100644 --- a/lib/dependencies.py +++ b/lib/dependencies.py @@ -5,6 +5,7 @@ import os from hardware import Hardware + def check_dependencies(): """ Check for needed external dependencies. @@ -15,6 +16,7 @@ def check_dependencies(): check_connected_hardware() print("… checked.\n") + def check_user(): """ Check for running user. SU should not be run as root. @@ -25,6 +27,7 @@ def check_user(): else: print(" * user id %s" % os.getuid()) + def check_os(): """ We do not support Windows @@ -35,6 +38,7 @@ def check_os(): else: print(" * posix system") + def check_connected_hardware(): """ Output connected and supported rf hardware. diff --git a/lib/disk.py b/lib/disk.py index e3540484d3ddaa60250c16881c61b645467aa7f2..e01aa9b8494dcdffcc72f346d036462dfdb71d7a 100644 --- a/lib/disk.py +++ b/lib/disk.py @@ -2,6 +2,7 @@ import os + class Disk(object): """ Class for disk operations. @@ -21,7 +22,6 @@ class Disk(object): else: return None - @staticmethod def path_writeble(path): """ @@ -39,7 +39,8 @@ class Disk(object): def sizeof_fmt(num, suffix="B"): """ Convert number of bytes into human readable format. - Source: https://web.archive.org/web/20111010015624/http://blogmag.net/blog/read/38/Print_human_readable_file_size + Source: https://web.archive.org/web/20111010015624/ \ + http://blogmag.net/blog/read/38/Print_human_readable_file_size """ for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]: if abs(num) < 1024.0: diff --git a/lib/gr/noise_detect.py b/lib/gr/noise_detect.py index db35549716f98be9100667662f49036c2de466c4..b835b15ee403f5214c685f746f496cd8119f83c4 100644 --- a/lib/gr/noise_detect.py +++ b/lib/gr/noise_detect.py @@ -1,5 +1,5 @@ -import sys -import os +# -*- coding: utf-8 -*- + import tempfile import numpy as np @@ -9,14 +9,14 @@ from gnuradio import blocks from gnuradio import gr import osmosdr + class NoiseFloorDetect(gr.top_block): def __init__(self, samp_rate, freq, capture_time, - device=None - ): + device=None): gr.top_block.__init__(self, "Top Block") self.samp_rate = samp_rate @@ -36,9 +36,6 @@ class NoiseFloorDetect(gr.top_block): samples_count = 0 sample_blocks = [] - minimum = 999999999.9 - maximum = 0.0 - while True: # pull from message queue msg = self.msgq_out.delete_head() @@ -76,18 +73,18 @@ class NoiseFloorDetect(gr.top_block): # 1. split samples into 1s sections and extract max value # 2. threshold is calculated as median + min value max_sections = [] - for i in range(0,int(len(samples)/2e6)-1): - max = np.amax(samples[i*int(samp_rate):(i+1)*int(samp_rate)]) - max_sections.append(max) + for i in range(0, int(len(samples)/2e6)-1): + amax = np.amax(samples[i*int(samp_rate):(i+1)*int(samp_rate)]) + max_sections.append(amax) median = np.median(max_sections) - min = np.amin(max_sections) - result['threshold'] = round(median+min, 6) + amin = np.amin(max_sections) + result['threshold'] = round(median+amin, 6) plt.plot(samples) - plt.plot([0, len(samples)-1], \ - [result['threshold'], result['threshold']], \ - label="threshold " + str(result['threshold']), \ + plt.plot([0, len(samples)-1], + [result['threshold'], result['threshold']], + label="threshold " + str(result['threshold']), linewidth=1.5, linestyle="-", color="red") plt.legend(loc='upper right') @@ -104,7 +101,6 @@ class NoiseFloorDetect(gr.top_block): def _create_image_tmp_file(self): return tempfile.NamedTemporaryFile() - def _extract_statistic_data_from_samples(self, samples): measurements = {} measurements['min'] = np.amin(samples) @@ -117,7 +113,8 @@ class NoiseFloorDetect(gr.top_block): return measurements def _build_blocks(self): - self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "osmosdr=0" ) + self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + + " " + "osmosdr=0" ) self.osmosdr_source_0.set_sample_rate(self.samp_rate) self.osmosdr_source_0.set_center_freq(self.freq, 0) self.osmosdr_source_0.set_freq_corr(0, 0) @@ -130,22 +127,26 @@ class NoiseFloorDetect(gr.top_block): self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) - self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, \ - int(self.samp_rate)*int(self.capture_time)) - self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, \ - 10*self.samp_rate, \ + self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, + int(self.samp_rate)*int(self. + capture_time)) + self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, + 10*self.samp_rate, True) - self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_float*1, \ - self.blocks_message_sink_0_msgq_out, \ - False) + self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_float*1, + self.blocks_message_sink_0_msgq_out, + False) self.blocks_file_source_0 = self.osmosdr_source_0 self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) ################################################## # Connections ################################################## - self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) - self.connect((self.blocks_throttle_0, 0), (self.blocks_head_0, 0)) - self.connect((self.blocks_head_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) - self.connect((self.blocks_complex_to_mag_squared_0, 0), \ + self.connect((self.blocks_file_source_0, 0), + (self.blocks_throttle_0, 0)) + self.connect((self.blocks_throttle_0, 0), + (self.blocks_head_0, 0)) + self.connect((self.blocks_head_0, 0), + (self.blocks_complex_to_mag_squared_0, 0)) + self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_message_sink_0, 0)) \ No newline at end of file diff --git a/lib/gui/gui.py b/lib/gui/gui.py index a7f5684c50678d593b5b81ab089d7bebd6b46b0e..78cae967bf49d03e09d9c04779e6a28ea1de18c7 100644 --- a/lib/gui/gui.py +++ b/lib/gui/gui.py @@ -1,11 +1,9 @@ # -*- coding: utf-8 -*- -import sys import os import logging import datetime import re -import time from PyQt5 import QtCore, QtGui, QtWidgets, uic @@ -20,6 +18,7 @@ from lib.gui.update_progress_bar import UpdateProgressBar from lib.gui.capture import Capture from lib.gui.noise_floor_plot import NoiseFloorPlot + class SuGui(QtWidgets.QMainWindow): """ GUI class used to realise the main window. @@ -104,15 +103,15 @@ class SuGui(QtWidgets.QMainWindow): # Thread stuff # progress_bar thread self.progress_bar_thread.set_measure_time(options['capture_time']) - self.progress_bar_thread.progress.connect(self.update_progress_bar, \ + self.progress_bar_thread.progress.connect(self.update_progress_bar, QtCore.Qt.QueuedConnection) - self.progress_bar_thread.run_time.connect(self.update_run_time, \ + self.progress_bar_thread.run_time.connect(self.update_run_time, QtCore.Qt.QueuedConnection) self.progress_bar_thread.start() self._set_setEnabled(False) # capture thread - self.capture_thread.exit_code.connect(self.update_progress_bar, \ + self.capture_thread.exit_code.connect(self.update_progress_bar, QtCore.Qt.QueuedConnection) self.capture_thread.set_file_sink(file_sink) self.capture_thread.start() @@ -147,7 +146,7 @@ class SuGui(QtWidgets.QMainWindow): self._set_setEnabled(True) # disbale freq buttons if env is selected if self.comboBox_env.currentIndex() != 0: - self._set_setEnabled(False, freq_button_only = True) + self._set_setEnabled(False, freq_button_only=True) # disable stop button again self.button_stop.setEnabled(False) self.button_start.setEnabled(True) @@ -173,22 +172,23 @@ class SuGui(QtWidgets.QMainWindow): """ Show about widget. """ - QtWidgets.QMessageBox.about(self, "About", \ - Su.name_and_version() + "\n\n" \ - "Contact: daniel.meissner@smail.inf.h-brs.de\n" \ - "Source: https://git.fslab.de/dmeiss2s/su") + QtWidgets.QMessageBox.about(self, "About", + Su.name_and_version() + "\n\n" + "Contact: daniel.meissner@smail.inf.h-brs.de\n" + "Source: https://git.fslab.de/dmeiss2s/su") def nf_button(self): if len(Hardware.get_connected_supported_devices()) != 0: options = self._extract_options() - measure_time = 60 + measure_time = 30 nf_detect = NoiseFloorDetect(options['samp_rate'], options['freq'], measure_time) - QtWidgets.QMessageBox.about(self, "Noise floor detection started", \ - "You have to wait " + str(measure_time) + "s after clicking 'Ok'.") + QtWidgets.QMessageBox.about(self, "Noise floor detection started", + "You have to wait " + str(measure_time) + + "s after clicking 'Ok'.") result = nf_detect.detect() # plot results @@ -232,11 +232,10 @@ class SuGui(QtWidgets.QMainWindow): try: nf = float(self.lineEdit_nf.text()) except: - QtWidgets.QMessageBox.about(self, "Error", \ + QtWidgets.QMessageBox.about(self, "Error", "Threshold needs to be from type int or float.") self.lineEdit_nf.setText("0.006") - def configure_env(self): """ Configure envirenment with selected home automatation system. @@ -318,8 +317,8 @@ class SuGui(QtWidgets.QMainWindow): """ Extract device key from combo box. """ - device_id = re.search(r"\w{4}:\w{4}", self.comboBox_hardware. \ - currentText()).group() + device_id = re.search(r"\w{4}:\w{4}", self.comboBox_hardware. + currentText()).group() device_key = '' for key, value in Hardware.SUPPORTED_HARDWARE.items(): @@ -339,18 +338,18 @@ class SuGui(QtWidgets.QMainWindow): It returns True or False. """ if len(self.lineEdit_dump_file.text()) == 0: - QtWidgets.QMessageBox.about(self, "Dumpfile path missing…", \ + QtWidgets.QMessageBox.about(self, "Dumpfile path missing…", "Please add dump file path.") return False elif len(Hardware.get_connected_supported_devices()) == 0: - QtWidgets.QMessageBox.about(self, "No supported RF hardware " \ - "connected…", \ + QtWidgets.QMessageBox.about(self, "No supported RF hardware " + "connected…", "Please connect RF hardware.") self.refresh_hw_button() return False elif len(self.comboBox_hardware.currentText()) == 0: - QtWidgets.QMessageBox.about(self, "No supported RF hardware " \ - "selected…", \ + QtWidgets.QMessageBox.about(self, "No supported RF hardware " + "selected…", "Select RF hardware.") self.refresh_hw_button() return False @@ -363,7 +362,7 @@ class SuGui(QtWidgets.QMainWindow): """ needed_disk_space = Disk.sizeof_fmt(self._calculate_needed_disk_space()) self.label_status. \ - setText("Needed disk space:\n" \ + setText("Needed disk space:\n" "" + needed_disk_space) self.check_dump_file_path() @@ -374,7 +373,8 @@ class SuGui(QtWidgets.QMainWindow): Returned integer value. """ - time, samp_rate = self._get_checked_time_and_samp_rate_radio_buttons().values() + time, samp_rate = \ + self._get_checked_time_and_samp_rate_radio_buttons().values() return int((time*samp_rate) * 8) @@ -414,7 +414,8 @@ class SuGui(QtWidgets.QMainWindow): Buttons """ freq_button = self._get_checked_freq_button() - time_and_samp_rate_buttons = self._get_checked_time_and_samp_rate_radio_buttons() + time_and_samp_rate_buttons = \ + self._get_checked_time_and_samp_rate_radio_buttons() # radio buttons options = {} # diff --git a/lib/gui/noise_floor_plot.py b/lib/gui/noise_floor_plot.py index e77283d38a5722c39fa2153ab43081fd78b3b054..821b46824ecfb7e97f19d6135aecb33a01fb4506 100644 --- a/lib/gui/noise_floor_plot.py +++ b/lib/gui/noise_floor_plot.py @@ -2,6 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets, uic + class NoiseFloorPlot(QtWidgets.QMainWindow): def __init__(self, plot_path): @@ -21,4 +22,4 @@ class NoiseFloorPlot(QtWidgets.QMainWindow): """ Close button action """ - self.close() \ No newline at end of file + self.close() diff --git a/lib/gui/update_progress_bar.py b/lib/gui/update_progress_bar.py index 02a3396de262d5ed0623188a04acfdef6d78473a..8248bf923deab75f17aef603ae1311fccbf60b2e 100644 --- a/lib/gui/update_progress_bar.py +++ b/lib/gui/update_progress_bar.py @@ -3,6 +3,7 @@ import time from PyQt5.QtCore import QThread, pyqtSignal, QObject + class UpdateProgressBar(QThread): progress = pyqtSignal(int) @@ -11,9 +12,6 @@ class UpdateProgressBar(QThread): def __init__(self): """ Make a new thread instance. - - :param measure_time: Time to measure spectrum - :type measure_time: int """ QThread.__init__(self) @@ -54,4 +52,4 @@ class UpdateProgressBar(QThread): """ Set start time of capture. """ - self.start_time = float(time.time()) \ No newline at end of file + self.start_time = float(time.time()) diff --git a/lib/hardware.py b/lib/hardware.py index 0311e51cf66c09bcf0111f2112b0ed1e2355c6b3..2d872af37da7fc76d295e9883934575ed8ef4bb6 100644 --- a/lib/hardware.py +++ b/lib/hardware.py @@ -6,6 +6,7 @@ import sys import os import logging + class Hardware(object): """ Inspect system for supported via USB connected devices. @@ -16,8 +17,8 @@ class Hardware(object): * LTR-SDR DVB-T stick """ SUPPORTED_HARDWARE = { - "hackrfone": "1d50:cc15", # rad1o and hackrf one has the same id :/ - "rtlsdr": "0bda:2838" # Realtek Semiconductor Corp. RTL2838 DVB-T + "hackrfone": "1d50:cc15", # rad1o and hackrf one has the same id :/ + "rtlsdr": "0bda:2838" # Realtek Semiconductor Corp. RTL2838 DVB-T } @staticmethod diff --git a/lib/su.py b/lib/su.py index 1094ee498a2c1d5da0f0a072ee0c033cd0e89deb..276388bc343db929cab8e60c589cc7d1e9fc2d9c 100644 --- a/lib/su.py +++ b/lib/su.py @@ -2,6 +2,7 @@ from lib.version import __version__ + class Su(object): """ Prgramm class to store some information about the programm.