Beispiel #1
0
    def hackrf_send(ctrl_connection, freq, sample_rate, bandwidth, gain, if_gain, baseband_gain,
                    send_buffer, current_sent_index, current_sending_repeat, sending_repeats):
        def sending_is_finished():
            if sending_repeats == 0:  # 0 = infinity
                return False

            return current_sending_repeat.value >= sending_repeats and current_sent_index.value >= len(send_buffer)

        def callback_send(buffer_length):
            try:
                if sending_is_finished():
                    return b""

                result = send_buffer[current_sent_index.value:current_sent_index.value + buffer_length]
                current_sent_index.value += buffer_length
                if current_sent_index.value >= len(send_buffer) - 1:
                    current_sending_repeat.value += 1
                    if current_sending_repeat.value < sending_repeats or sending_repeats == 0:  # 0 = infinity
                        current_sent_index.value = 0
                    else:
                        current_sent_index.value = len(send_buffer)

                return result
            except (BrokenPipeError, EOFError):
                return b""

        if not HackRF.initialize_hackrf(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, ctrl_connection, is_tx=True):
            return False

        hackrf.start_tx_mode(callback_send)

        exit_requested = False

        while not exit_requested and not sending_is_finished():
            while ctrl_connection.poll():
                result = HackRF.process_command(ctrl_connection.recv(), ctrl_connection, is_tx=True)
                if result == "stop":
                    exit_requested = True
                    break

        if exit_requested:
            logger.debug("HackRF: exit requested. Stopping sending")
        if sending_is_finished():
            logger.debug("HackRF: sending is finished.")

        HackRF.shutdown_hackrf(ctrl_connection)
        ctrl_connection.close()
Beispiel #2
0
    def start_tx_mode(self, samples_to_send: np.ndarray = None, repeats=None, resume=False):
        if self.is_open:
            self.init_send_parameters(samples_to_send, repeats, resume=resume)
            retcode = hackrf.start_tx_mode(self.callback_send)

            if retcode == self.success:
                self.is_transmitting = True
                self._start_sendbuffer_thread()
            else:
                self.is_transmitting = False
        else:
            retcode = self.error_not_open
        self.log_retcode(retcode, "start_tx_mode")
Beispiel #3
0
    def test_c_api(self):
        def callback(n):
            print("called")
            return np.array([1], dtype=np.complex64)

        print("init", hackrf.init())
        print("open", hackrf.open())

        print("start_tx", hackrf.start_tx_mode(callback))
        time.sleep(1)

        print("stop_tx", hackrf.stop_tx_mode())

        print("close", hackrf.close())
        print("exit", hackrf.exit())
Beispiel #4
0
    def test_c_api(self):
        def callback(n):
            print("called")
            return np.array([1], dtype=np.complex64)

        print("init", hackrf.init())
        print("open", hackrf.open())

        print("start_tx", hackrf.start_tx_mode(callback))
        time.sleep(1)

        print("stop_tx", hackrf.stop_tx_mode())

        print("close", hackrf.close())
        print("exit", hackrf.exit())
Beispiel #5
0
 def enter_async_send_mode(cls, callback):
     hackrf.start_tx_mode(callback)
Beispiel #6
0
 def enter_async_send_mode(cls, callback):
     hackrf.start_tx_mode(callback)