Beispiel #1
0
 def test_set_rx(self):
     hackrf.setup()
     hackrf.set_freq(433.92e6)
     print(hackrf.is_streaming())
     hackrf.start_rx_mode(self.callback_fun)
     time.sleep(1)
     hackrf.stop_rx_mode()
Beispiel #2
0
    def process_command(command, ctrl_connection, is_tx: bool):
        is_rx = not is_tx
        if command == "stop":
            return "stop"

        tag, value = command.split(":")
        if tag == "center_freq":
            ret = hackrf.set_freq(int(value))
            ctrl_connection.send("set_center_freq to {0}:{1}".format(value, ret))

        elif tag == "rf_gain":
            ret = hackrf.set_rf_gain(int(value))
            ctrl_connection.send("set_rf_gain to {0}:{1}".format(value, ret))

        elif tag == "if_gain" and is_rx:
            ret = hackrf.set_if_rx_gain(int(value))
            ctrl_connection.send("set_if_gain to {0}:{1}".format(value, ret))

        elif tag == "if_gain" and is_tx:
            ret = hackrf.set_if_tx_gain(int(value))
            ctrl_connection.send("set_if_gain to {0}:{1}".format(value, ret))

        elif tag == "baseband_gain" and is_rx:
            ret = hackrf.set_baseband_gain(int(value))
            ctrl_connection.send("set_baseband_gain to {0}:{1}".format(value, ret))

        elif tag == "sample_rate":
            ret = hackrf.set_sample_rate(int(value))
            ctrl_connection.send("set_sample_rate to {0}:{1}".format(value, ret))

        elif tag == "bandwidth":
            ret = hackrf.set_baseband_filter_bandwidth(int(value))
            ctrl_connection.send("set_bandwidth to {0}:{1}".format(value, ret))
Beispiel #3
0
    def initialize_hackrf(freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, ctrl_conn, is_tx):
        ret = hackrf.setup()
        ctrl_conn.send("setup:" + str(ret))
        if ret != 0:
            return False

        ret = hackrf.set_freq(freq)
        ctrl_conn.send("set_center_freq to {0}:{1}".format(freq, ret))

        ret = hackrf.set_sample_rate(sample_rate)
        ctrl_conn.send("set_sample_rate to {0}:{1}".format(sample_rate, ret))

        ret = hackrf.set_rf_gain(gain)
        ctrl_conn.send("set_rf_gain to {0}:{1}".format(gain, ret))

        if is_tx:
            ret = hackrf.set_if_tx_gain(if_gain)
            ctrl_conn.send("set_if_gain to {0}:{1}".format(if_gain, ret))
        else:
            ret = hackrf.set_if_rx_gain(if_gain)
            ctrl_conn.send("set_if_gain to {0}:{1}".format(if_gain, ret))

            ret = hackrf.set_baseband_gain(baseband_gain)
            ctrl_conn.send("set_baseband_gain to {0}:{1}".format(baseband_gain, ret))

        ret = hackrf.set_baseband_filter_bandwidth(bandwidth)
        ctrl_conn.send("set_bandwidth to {0}:{1}".format(bandwidth, ret))

        return True
Beispiel #4
0
    def initialize_hackrf(freq, sample_rate, gain, bw, ctrl_conn):
        ret = hackrf.setup()
        ctrl_conn.send("setup:" + str(ret))
        if ret != 0:
            return False

        ret = hackrf.set_freq(freq)
        ctrl_conn.send("set_freq:" + str(ret))

        ret = hackrf.set_sample_rate(sample_rate)
        ctrl_conn.send("set_sample_rate:" + str(ret))

        ret = hackrf.set_lna_gain(gain)
        ctrl_conn.send("set_lna_gain:" + str(ret))

        ret = hackrf.set_vga_gain(gain)
        ctrl_conn.send("set_vga_gain:" + str(ret))

        ret = hackrf.set_txvga_gain(gain)
        ctrl_conn.send("set_txvga_gain:" + str(ret))

        ret = hackrf.set_baseband_filter_bandwidth(bw)
        ctrl_conn.send("set_bandwidth:" + str(ret))

        return True
Beispiel #5
0
    def process_command(command):
        logger.debug("HackRF: {}".format(command))
        if command == "stop":
            return "stop"

        tag, value = command.split(":")
        if tag == "center_freq":
            logger.info("HackRF: Set center freq to {0}".format(int(value)))
            return hackrf.set_freq(int(value))

        elif tag == "gain":
            logger.info("HackRF: Set gain to {0}".format(int(value)))
            hackrf.set_lna_gain(int(value))
            hackrf.set_vga_gain(int(value))
            hackrf.set_txvga_gain(int(value))

        elif tag == "sample_rate":
            logger.info("HackRF: Set sample_rate to {0}".format(int(value)))
            return hackrf.set_sample_rate(int(value))

        elif tag == "bandwidth":
            logger.info("HackRF: Set bandwidth to {0}".format(int(value)))
            return hackrf.set_baseband_filter_bandwidth(int(value))
Beispiel #6
0
 def set_device_frequency(self, value):
     if self.is_open:
         retcode = hackrf.set_freq(value)
     else:
         retcode = self.error_not_open
     self.log_retcode(retcode, "set_frequency", value)