Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
super().setUp()
self.form.ui.tabWidget.setCurrentIndex(2)
logger.debug("Preparing Modulation dialog")
self.dialog, _ = self.form.generator_tab_controller.prepare_modulation_dialog()
QApplication.instance().processEvents()
QTest.qWait(self.WAIT_TIMEOUT_BEFORE_NEW)
if self.SHOW:
self.dialog.show()
logger.debug("Initializing Modulation dialog")
self.dialog.initialize("1111")
logger.debug("Preparation success")
endless_sender = EndlessSender(BackendHandler(), "HackRF")
msg = Message([1, 0] * 16 + [1, 1, 0, 0] * 8 + [0, 0, 1, 1] * 8 + [1, 0, 1, 1, 1, 0, 0, 1, 1, 1] * 4, 0,
MessageType("empty_message_type"))
modulator = Modulator("test_modulator")
modulator.samples_per_symbol = 1000
modulator.carrier_freq_hz = 55e3
logger.debug("Starting endless sender")
endless_sender.start()
time.sleep(1)
logger.debug("Pushing data")
endless_sender.push_data(modulator.modulate(msg.encoded_bits))
logger.debug("Pushed data")
time.sleep(5)
logger.debug("Stopping endless sender")
endless_sender.stop()
time.sleep(1)
logger.debug("bye")
"--gain", str(self.gain), "--bandwidth", str(self.bandwidth),
"--port", str(self.gr_port)]
if self.device.upper() == "USRP":
if self.device_args:
options.extend(["--device-args", self.device_args])
if self.device.upper() == "HACKRF":
options.extend(["--if-gain", str(self.if_gain), "--baseband-gain", str(self.baseband_gain)])
if self.device.upper() == "RTL-SDR":
options.extend(["--freq-correction", str(self.freq_correction),
"--direct-sampling", str(self.direct_sampling_mode)])
logger.info("Starting Gnuradio")
logger.debug(" ".join(options))
self.tb_process = Popen(options, stdout=PIPE, stderr=PIPE, stdin=PIPE, bufsize=1)
logger.info("Started Gnuradio")
t = Thread(target=self.enqueue_output, args=(self.tb_process.stderr, self.queue))
t.daemon = True # thread dies with the program
t.start()
def start(self):
self.abort.value = 0
try:
self.process = Process(target=self.modulate_continuously, args=(self.num_repeats, ))
self.process.daemon = True
self.process.start()
except RuntimeError as e:
logger.debug(str(e))
def apply_bandpass_filter(data, f_low, f_high, filter_bw=0.08):
if f_low > f_high:
f_low, f_high = f_high, f_low
f_low = util.clip(f_low, -0.5, 0.5)
f_high = util.clip(f_high, -0.5, 0.5)
h = Filter.design_windowed_sinc_bandpass(f_low, f_high, filter_bw)
# Choose normal or FFT convolution based on heuristic described in
# https://softwareengineering.stackexchange.com/questions/171757/computational-complexity-of-correlation-in-time-vs-multiplication-in-frequency-s/
if len(h) < 8 * math.log(math.sqrt(len(data))):
logger.debug("Use normal convolve")
return np.convolve(data, h, 'same')
else:
logger.debug("Use FFT convolve")
return Filter.fft_convolve_1d(data, h)
def shutdown_device(cls, ctrl_connection, is_tx=False):
logger.debug("AirSpy: closing device")
ret = airspy.stop_rx()
ctrl_connection.send("Stop RX:" + str(ret))
ret = airspy.close()
ctrl_connection.send("EXIT:" + str(ret))
return True
def closeEvent(self, event: QCloseEvent):
if self.device.backend is not Backends.none:
self.emit_editing_finished_signals()
self.timer.stop()
self.device.stop("Dialog closed. Killing recording process.")
logger.debug("Device stopped successfully.")
if not self.testing_mode:
if not self.save_before_close():
event.ignore()
return
time.sleep(0.1)
if self.device.backend not in (Backends.none, Backends.network):
# Backend none is selected, when no device is available
logger.debug("Cleaning up device")
self.device.cleanup()
logger.debug("Successfully cleaned up device")
self.device_settings_widget.emit_device_parameters_changed()
constants.SETTINGS.setValue("{}/geometry".format(self.__class__.__name__), self.saveGeometry())
def shutdown_device(cls, ctrl_connection, is_tx: bool):
logger.debug("SDRPLAY: closing device")
ret = sdrplay.close_stream()
ctrl_connection.send("CLOSE STREAM:" + str(ret))
if cls.sdrplay_device_index is not None:
ret = sdrplay.release_device_index()
ctrl_connection.send("RELEASE DEVICE:" + str(ret))
def run(self):
logger.debug("Spectrum Thread: Init Process")
self.initialize_process()
logger.debug("Spectrum Thread: Process Intialized")
self.init_recv_socket()
logger.debug("Spectrum Thread: Socket initialized")
recv = self.socket.recv
rcvd = b""
try:
logger.debug("Spectrum Thread: Enter main loop")
while not self.isInterruptionRequested():
try:
rcvd += recv(32768) # Receive Buffer = 32768 Byte
except (zmq.error.ContextTerminated, ConnectionResetError):
self.stop("Stopped receiving, because connection was reset")
return
except OSError as e: # https://github.com/jopohl/urh/issues/131
logger.warning("Error occurred", str(e))
if len(rcvd) < 8:
self.stop("Stopped receiving, because no data transmitted anymore")
return
if len(rcvd) % 8 != 0:
continue
def shutdown_device(cls, ctrl_connection, is_tx: bool):
logger.debug("RTLSDR: closing device")
ret = rtlsdr.close()
ctrl_connection.send("CLOSE:" + str(ret))