def test_get_receive_buffer_size(self): SettingsProxy.OVERWRITE_RECEIVE_BUFFER_SIZE = None ns = SettingsProxy.get_receive_buffer_size( resume_on_full_receive_buffer=True, spectrum_mode=True) self.assertEqual(ns, constants.SPECTRUM_BUFFER_SIZE) ns = SettingsProxy.get_receive_buffer_size( resume_on_full_receive_buffer=True, spectrum_mode=False) self.assertEqual(ns, constants.SNIFF_BUFFER_SIZE) ns1 = SettingsProxy.get_receive_buffer_size( resume_on_full_receive_buffer=False, spectrum_mode=True) ns2 = SettingsProxy.get_receive_buffer_size( resume_on_full_receive_buffer=False, spectrum_mode=False) self.assertEqual(len(str(ns1)), len(str(ns2)))
def init_recv_buffer(self): if self.receive_buffer is None: num_samples = SettingsProxy.get_receive_buffer_size( self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) self.receive_buffer = IQArray(None, dtype=self.DATA_TYPE, n=int(num_samples))
def change_acess_to_iq_record(self): self.__dev.my_acess_record_iq = True if self.__dev.my_acess_record_iq == False else False if self.__dev.my_acess_record_iq == False: self.__dev.my_receive_buffer = IQArray(None, dtype=np.float32, n=int(SettingsProxy.get_receive_buffer_size(False, False))) self.__dev.my_current_recv_index = 0
def init_recv_buffer(self): if self.receive_buffer is None: num_samples = SettingsProxy.get_receive_buffer_size( self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) self.receive_buffer = np.zeros(int(num_samples), dtype=np.complex64, order='C')
def read_receiving_queue(self): my_num_samples = SettingsProxy.get_receive_buffer_size(False, False) self.my_receive_buffer = IQArray(None, dtype=self.DATA_TYPE, n=int(my_num_samples)) self.my_current_recv_index = 0 while self.is_receiving: try: byte_buffer = self.parent_data_conn.recv_bytes() samples = self.bytes_to_iq(byte_buffer) n_samples = len(samples) if n_samples == 0: continue if self.apply_dc_correction: samples = samples - np.mean(samples, axis=0) except OSError as e: logger.exception(e) continue except EOFError: logger.info("EOF Error: Ending receive thread") break if self.current_recv_index + n_samples >= len(self.receive_buffer): if self.resume_on_full_receive_buffer: self.current_recv_index = 0 if n_samples >= len(self.receive_buffer): n_samples = len(self.receive_buffer) - 1 else: self.stop_rx_mode( "Receiving buffer is full {0}/{1}".format( self.current_recv_index + n_samples, len(self.receive_buffer))) return self.receive_buffer[self. current_recv_index:self.current_recv_index + n_samples] = samples[:n_samples] self.current_recv_index += n_samples if self.my_acess_record_iq: self.my_receive_buffer[self.my_current_recv_index:self. my_current_recv_index + n_samples] = samples[:n_samples] self.my_current_recv_index += n_samples logger.debug("Exiting read_receive_queue thread.")
def __init__(self, raw_mode=False, resume_on_full_receive_buffer=False, spectrum=False, sending=False): """ :param raw_mode: If true, sending and receiving raw samples if false bits are received/sent """ super().__init__(name="NetworkSDRInterface") self.client_ip = self.qsettings.value("client_ip", defaultValue="127.0.0.1", type=str) self.server_ip = "" self.samples_to_send = None # set in virtual device constructor self.client_port = self.qsettings.value("client_port", defaultValue=2222, type=int) self.server_port = self.qsettings.value("server_port", defaultValue=4444, type=int) self.receive_check_timer = QTimer() self.receive_check_timer.setInterval(250) # need to make the connect for the time in constructor, as create connects is called elsewhere in base class self.receive_check_timer.timeout.connect(self.__emit_rcv_index_changed) self.is_in_spectrum_mode = spectrum self.resume_on_full_receive_buffer = resume_on_full_receive_buffer self.__is_sending = False self.__sending_interrupt_requested = False self.sending_repeats = 1 # only used in raw mode self.current_sent_sample = 0 self.current_sending_repeat = 0 self.sending_is_continuous = False self.continuous_send_ring_buffer = None self.num_samples_to_send = None # Only used for continuous send mode self.raw_mode = raw_mode if not sending: if self.raw_mode: num_samples = SettingsProxy.get_receive_buffer_size(self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) try: self.receive_buffer = np.zeros(num_samples, dtype=np.complex64, order='C') except MemoryError: logger.warning("Could not allocate buffer with {0:d} samples, trying less...") i = 0 while True: try: i += 2 self.receive_buffer = np.zeros(num_samples // i, dtype=np.complex64, order='C') logger.debug("Using buffer with {0:d} samples instead.".format(num_samples // i)) break except MemoryError: continue else: self.received_bits = []
def __init__(self, raw_mode=False, resume_on_full_receive_buffer=False, spectrum=False, sending=False): """ :param raw_mode: If true, sending and receiving raw samples if false bits are received/sent """ super().__init__(name="NetworkSDRInterface") self.client_ip = self.qsettings.value("client_ip", defaultValue="127.0.0.1", type=str) self.server_ip = "" self.samples_to_send = None # set in virtual device constructor self.client_port = self.qsettings.value("client_port", defaultValue=2222, type=int) self.server_port = self.qsettings.value("server_port", defaultValue=4444, type=int) self.is_in_spectrum_mode = spectrum self.resume_on_full_receive_buffer = resume_on_full_receive_buffer self.__is_sending = False self.__sending_interrupt_requested = False self.sending_repeats = 1 # only used in raw mode self.current_sent_sample = 0 self.current_sending_repeat = 0 self.sending_is_continuous = False self.continuous_send_ring_buffer = None self.num_samples_to_send = None # Only used for continuous send mode self.raw_mode = raw_mode if not sending: if self.raw_mode: num_samples = SettingsProxy.get_receive_buffer_size(self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) try: self.receive_buffer = np.zeros(num_samples, dtype=np.complex64, order='C') except MemoryError: logger.warning("Could not allocate buffer with {0:d} samples, trying less...") i = 0 while True: try: i += 2 self.receive_buffer = np.zeros(num_samples // i, dtype=np.complex64, order='C') logger.debug("Using buffer with {0:d} samples instead.".format(num_samples // i)) break except MemoryError: continue else: self.received_bits = []
def init_recv_buffer(self): n_samples = SettingsProxy.get_receive_buffer_size(self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) self.data = np.zeros(n_samples, dtype=np.complex64)
def __init__(self, raw_mode=False, resume_on_full_receive_buffer=False, spectrum=False, sending=False): """ :param raw_mode: If true, sending and receiving raw samples if false bits are received/sent """ super().__init__(name="NetworkSDRInterface") self.client_ip = self.qsettings.value("client_ip", defaultValue="127.0.0.1", type=str) self.server_ip = "" self.samples_to_send = None # set in virtual device constructor self.client_port = self.qsettings.value("client_port", defaultValue=2222, type=int) self.server_port = self.qsettings.value("server_port", defaultValue=4444, type=int) self.is_in_spectrum_mode = spectrum self.resume_on_full_receive_buffer = resume_on_full_receive_buffer self.__is_sending = False self.__sending_interrupt_requested = False self.sending_repeats = 1 # only used in raw mode self.current_sent_sample = 0 self.current_sending_repeat = 0 self.sending_is_continuous = False self.continuous_send_ring_buffer = None self.num_samples_to_send = None # Only used for continuous send mode self.raw_mode = raw_mode if not sending: if self.raw_mode: num_samples = SettingsProxy.get_receive_buffer_size( self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) try: self.receive_buffer = IQArray(None, dtype=self.DATA_TYPE, n=num_samples) except MemoryError: logger.warning( "Could not allocate buffer with {0:d} samples, trying less..." ) i = 0 while True: try: i += 2 self.receive_buffer = IQArray(None, dtype=self.DATA_TYPE, n=num_samples // i) logger.debug( "Using buffer with {0:d} samples instead.". format(num_samples // i)) break except MemoryError: continue else: self.received_bits = []
def init_recv_buffer(self): if self.receive_buffer is None: num_samples = SettingsProxy.get_receive_buffer_size(self.resume_on_full_receive_buffer, self.is_in_spectrum_mode) self.receive_buffer = np.zeros(int(num_samples), dtype=np.complex64, order='C')