def test_receive(self): rtlsdr_class = RTLSDR(0, 0, 0, device_number=0) rtlsdr_class.open() self.assertEqual(rtlsdr_class.current_recv_index, 0) rtlsdr_class.start_rx_mode() time.sleep(2) rtlsdr_class.stop_rx_mode("Finished") index = rtlsdr_class.current_recv_index print(rtlsdr_class.current_recv_index) self.assertGreater(rtlsdr_class.current_recv_index, 0) time.sleep(2) self.assertEqual(index, rtlsdr_class.current_recv_index) rtlsdr_class.start_rx_mode() time.sleep(1) self.assertGreater(rtlsdr_class.current_recv_index, index)
def test_pack_unpack_complex(self): arr = np.array([0, 0, 127.5, 127.5, 255, 255], dtype=np.uint8) self.assertEqual(arr[0], 0) self.assertEqual(arr[1], 0) self.assertEqual(arr[-1], 255) received = arr.tostring() self.assertEqual(len(received), len(arr)) self.assertEqual(np.int8(received[0]), 0) self.assertEqual(np.int8(received[1]), 0) unpacked = RTLSDR.unpack_complex(received, len(received) // 2) self.assertEqual(unpacked[0], complex(-1, -1)) self.assertAlmostEqual(unpacked[1], complex(0, 0), places=1) self.assertEqual(unpacked[2], complex(1, 1)) packed = RTLSDR.pack_complex(unpacked) self.assertEqual(received, packed)
def test_receive(self): rtlsdr_class = RTLSDR(433.92e6, 20, 2e6, device_number=0) self.assertEqual(rtlsdr_class.current_recv_index, 0) rtlsdr_class.start_rx_mode() time.sleep(2) rtlsdr_class.stop_rx_mode("Finished") index = rtlsdr_class.current_recv_index print(rtlsdr_class.current_recv_index) self.assertGreater(rtlsdr_class.current_recv_index, 0) time.sleep(2) self.assertEqual(index, rtlsdr_class.current_recv_index) rtlsdr_class.start_rx_mode() time.sleep(1) self.assertGreater(rtlsdr_class.current_recv_index, index)
def __init__(self, backend_handler, name: str, mode: Mode, freq=None, sample_rate=None, bandwidth=None, gain=None, if_gain=None, baseband_gain=None, samples_to_send=None, device_ip=None, sending_repeats=1, parent=None, resume_on_full_receive_buffer=False, raw_mode=True, portnumber=1234): super().__init__(parent) self.name = name self.mode = mode self.backend_handler = backend_handler freq = config.DEFAULT_FREQUENCY if freq is None else freq sample_rate = config.DEFAULT_SAMPLE_RATE if sample_rate is None else sample_rate bandwidth = config.DEFAULT_BANDWIDTH if bandwidth is None else bandwidth gain = config.DEFAULT_GAIN if gain is None else gain if_gain = config.DEFAULT_IF_GAIN if if_gain is None else if_gain baseband_gain = config.DEFAULT_BB_GAIN if baseband_gain is None else baseband_gain resume_on_full_receive_buffer = self.mode == Mode.spectrum or resume_on_full_receive_buffer if self.name == NetworkSDRInterfacePlugin.NETWORK_SDR_NAME: self.backend = Backends.network else: try: self.backend = self.backend_handler.device_backends[ name.lower()].selected_backend except KeyError: logger.warning("Invalid device name: {0}".format(name)) self.backend = Backends.none self.__dev = None return if self.backend == Backends.grc: if mode == Mode.receive: from urh.dev.gr.ReceiverThread import ReceiverThread self.__dev = ReceiverThread( freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, parent=parent, resume_on_full_receive_buffer=resume_on_full_receive_buffer ) elif mode == Mode.send: from urh.dev.gr.SenderThread import SenderThread self.__dev = SenderThread(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, parent=parent) self.__dev.data = samples_to_send self.__dev.samples_per_transmission = len( samples_to_send) if samples_to_send is not None else 2**15 elif mode == Mode.spectrum: from urh.dev.gr.SpectrumThread import SpectrumThread self.__dev = SpectrumThread(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, parent=parent) else: raise ValueError("Unknown mode") self.__dev.device = name self.__dev.started.connect(self.emit_started_signal) self.__dev.stopped.connect(self.emit_stopped_signal) self.__dev.sender_needs_restart.connect( self.emit_sender_needs_restart) elif self.backend == Backends.native: name = self.name.lower() if name in map(str.lower, BackendHandler.DEVICE_NAMES): if name == "hackrf": from urh.dev.native.HackRF import HackRF self.__dev = HackRF(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, resume_on_full_receive_buffer) elif name.replace("-", "") == "rtlsdr": from urh.dev.native.RTLSDR import RTLSDR self.__dev = RTLSDR(freq, gain, sample_rate, device_number=0, resume_on_full_receive_buffer= resume_on_full_receive_buffer) elif name.replace("-", "") == "rtltcp": from urh.dev.native.RTLSDRTCP import RTLSDRTCP self.__dev = RTLSDRTCP(freq, gain, sample_rate, bandwidth, device_number=0, resume_on_full_receive_buffer= resume_on_full_receive_buffer) elif name == "limesdr": from urh.dev.native.LimeSDR import LimeSDR self.__dev = LimeSDR(freq, gain, sample_rate, bandwidth, gain, resume_on_full_receive_buffer= resume_on_full_receive_buffer) elif name.startswith("airspy"): from urh.dev.native.AirSpy import AirSpy self.__dev = AirSpy(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, resume_on_full_receive_buffer= resume_on_full_receive_buffer) elif name.startswith("usrp"): from urh.dev.native.USRP import USRP self.__dev = USRP(freq, gain, sample_rate, bandwidth, gain, resume_on_full_receive_buffer= resume_on_full_receive_buffer) elif name.startswith("sdrplay"): from urh.dev.native.SDRPlay import SDRPlay self.__dev = SDRPlay(freq, gain, bandwidth, gain, if_gain=if_gain, resume_on_full_receive_buffer= resume_on_full_receive_buffer) elif name == "soundcard": from urh.dev.native.SoundCard import SoundCard self.__dev = SoundCard(sample_rate, resume_on_full_receive_buffer= resume_on_full_receive_buffer) else: raise NotImplementedError( "Native Backend for {0} not yet implemented".format( name)) elif name == "test": # For Unittests Only self.__dev = Device(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, resume_on_full_receive_buffer) else: raise ValueError("Unknown device name {0}".format(name)) self.__dev.portnumber = portnumber self.__dev.device_ip = device_ip if mode == Mode.send: self.__dev.init_send_parameters(samples_to_send, sending_repeats) elif self.backend == Backends.network: self.__dev = NetworkSDRInterfacePlugin( raw_mode=raw_mode, resume_on_full_receive_buffer=resume_on_full_receive_buffer, spectrum=self.mode == Mode.spectrum, sending=self.mode == Mode.send) self.__dev.send_connection_established.connect( self.emit_ready_for_action) self.__dev.receive_server_started.connect( self.emit_ready_for_action) self.__dev.error_occurred.connect(self.emit_fatal_error_occurred) self.__dev.samples_to_send = samples_to_send elif self.backend == Backends.none: self.__dev = None else: raise ValueError("Unsupported Backend") if hasattr(self.__dev, "data_received"): self.__dev.data_received.connect(self.data_received.emit) if mode == Mode.spectrum: self.__dev.is_in_spectrum_mode = True
def __init__(self, backend_handler, name: str, mode: Mode, bw, freq, gain, samp_rate, samples_to_send=None, device_ip=None, sending_repeats=1, parent=None, is_ringbuffer=False, raw_mode=True, portnumber=1234): super().__init__(parent) self.name = name self.mode = mode self.backend_handler = backend_handler if self.name == NetworkSDRInterfacePlugin.NETWORK_SDR_NAME: self.backend = Backends.network else: try: self.backend = self.backend_handler.device_backends[ name.lower()].selected_backend except KeyError: logger.warning("Invalid device name: {0}".format(name)) self.backend = Backends.none self.__dev = None return if self.backend == Backends.grc: if mode == Mode.receive: self.__dev = ReceiverThread(samp_rate, freq, gain, bw, parent=parent, is_ringbuffer=is_ringbuffer) self.__dev.index_changed.connect(self.emit_index_changed) elif mode == Mode.send: self.__dev = SenderThread(samp_rate, freq, gain, bw, parent=parent) self.__dev.data = samples_to_send self.__dev.samples_per_transmission = len(samples_to_send) elif mode == Mode.spectrum: self.__dev = SpectrumThread(samp_rate, freq, gain, bw, parent=parent) else: raise ValueError("Unknown mode") self.__dev.usrp_ip = device_ip self.__dev.device = name self.__dev.started.connect(self.emit_started_signal) self.__dev.stopped.connect(self.emit_stopped_signal) self.__dev.sender_needs_restart.connect( self.emit_sender_needs_restart) elif self.backend == Backends.native: name = self.name.lower() if name in map(str.lower, BackendHandler.DEVICE_NAMES): is_ringbuffer = self.mode == Mode.spectrum or is_ringbuffer if name == "hackrf": from urh.dev.native.HackRF import HackRF self.__dev = HackRF(bw, freq, gain, samp_rate, is_ringbuffer=is_ringbuffer) elif name.replace("-", "") == "rtlsdr": from urh.dev.native.RTLSDR import RTLSDR self.__dev = RTLSDR(freq, gain, samp_rate, device_number=0, is_ringbuffer=is_ringbuffer) elif name.replace("-", "") == "rtltcp": from urh.dev.native.RTLSDRTCP import RTLSDRTCP self.__dev = RTLSDRTCP(freq, gain, samp_rate, device_number=0, is_ringbuffer=is_ringbuffer) else: raise NotImplementedError( "Native Backend for {0} not yet implemented".format( name)) else: raise ValueError("Unknown device name {0}".format(name)) self.__dev.portnumber = portnumber self.__dev.device_ip = device_ip self.__dev.rcv_index_changed.connect(self.emit_index_changed) if mode == Mode.send: self.__dev.init_send_parameters(samples_to_send, sending_repeats, skip_device_parameters=True) elif self.backend == Backends.network: self.__dev = NetworkSDRInterfacePlugin(raw_mode=raw_mode) self.__dev.rcv_index_changed.connect(self.emit_index_changed) self.__dev.samples_to_send = samples_to_send elif self.backend == Backends.none: self.__dev = None else: raise ValueError("Unsupported Backend")
from urh.dev.native.HackRF import HackRF from urh.dev.native.RTLSDR import RTLSDR hfc = HackRF(433.92e6, 1e6, 1e6, 20) hfc.start_rx_mode() rtlsdr = RTLSDR(433.92e6, 20, 2e6, device_number=0) rtlsdr.start_rx_mode()
def __init__(self, backend_handler, name: str, mode: Mode, freq=None, sample_rate=None, bandwidth=None, gain=None, if_gain=None, baseband_gain=None, samples_to_send=None, device_ip=None, sending_repeats=1, parent=None, is_ringbuffer=False, raw_mode=True, portnumber=1234): super().__init__(parent) self.name = name self.mode = mode self.backend_handler = backend_handler freq = config.DEFAULT_FREQUENCY if freq is None else freq sample_rate = config.DEFAULT_SAMPLE_RATE if sample_rate is None else sample_rate bandwidth = config.DEFAULT_BANDWIDTH if bandwidth is None else bandwidth gain = config.DEFAULT_GAIN if gain is None else gain if_gain = config.DEFAULT_IF_GAIN if if_gain is None else if_gain baseband_gain = config.DEFAULT_BB_GAIN if baseband_gain is None else baseband_gain if self.name == NetworkSDRInterfacePlugin.NETWORK_SDR_NAME: self.backend = Backends.network else: try: self.backend = self.backend_handler.device_backends[name.lower()].selected_backend except KeyError: logger.warning("Invalid device name: {0}".format(name)) self.backend = Backends.none self.__dev = None return if self.backend == Backends.grc: if mode == Mode.receive: from urh.dev.gr.ReceiverThread import ReceiverThread self.__dev = ReceiverThread(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, parent=parent, is_ringbuffer=is_ringbuffer) self.__dev.index_changed.connect(self.emit_index_changed) elif mode == Mode.send: from urh.dev.gr.SenderThread import SenderThread self.__dev = SenderThread(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, parent=parent) self.__dev.data = samples_to_send self.__dev.samples_per_transmission = len(samples_to_send) elif mode == Mode.spectrum: from urh.dev.gr.SpectrumThread import SpectrumThread self.__dev = SpectrumThread(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, parent=parent) else: raise ValueError("Unknown mode") self.__dev.device = name self.__dev.started.connect(self.emit_started_signal) self.__dev.stopped.connect(self.emit_stopped_signal) self.__dev.sender_needs_restart.connect(self.emit_sender_needs_restart) elif self.backend == Backends.native: name = self.name.lower() if name in map(str.lower, BackendHandler.DEVICE_NAMES): is_ringbuffer = self.mode == Mode.spectrum or is_ringbuffer if name == "hackrf": from urh.dev.native.HackRF import HackRF self.__dev = HackRF(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, is_ringbuffer) elif name.replace("-", "") == "rtlsdr": from urh.dev.native.RTLSDR import RTLSDR self.__dev = RTLSDR(freq, gain, sample_rate, device_number=0, is_ringbuffer=is_ringbuffer) elif name.replace("-", "") == "rtltcp": from urh.dev.native.RTLSDRTCP import RTLSDRTCP self.__dev = RTLSDRTCP(freq, gain, sample_rate, device_number=0, is_ringbuffer=is_ringbuffer) else: raise NotImplementedError("Native Backend for {0} not yet implemented".format(name)) elif name == "test": # For Unittests Only self.__dev = Device(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, is_ringbuffer) self.__dev.BYTES_PER_SAMPLE = 4 else: raise ValueError("Unknown device name {0}".format(name)) self.__dev.portnumber = portnumber self.__dev.device_ip = device_ip self.__dev.rcv_index_changed.connect(self.emit_index_changed) if mode == Mode.send: self.__dev.init_send_parameters(samples_to_send, sending_repeats, skip_device_parameters=True) elif self.backend == Backends.network: self.__dev = NetworkSDRInterfacePlugin(raw_mode=raw_mode, spectrum=self.mode == Mode.spectrum) self.__dev.rcv_index_changed.connect(self.emit_index_changed) self.__dev.samples_to_send = samples_to_send elif self.backend == Backends.none: self.__dev = None else: raise ValueError("Unsupported Backend")