示例#1
0
文件: LimeSDR.py 项目: decolnz/urh
    def initialize_limesdr(freq, sample_rate, bandwidth, gain, channel_index, antenna_index, ctrl_conn, is_tx):
        ret = limesdr.open()
        ctrl_conn.send("OPEN:" + str(ret))
        limesdr.disable_all_channels()
        if ret != 0:
            return False

        ret = limesdr.init()
        ctrl_conn.send("INIT:" + str(ret))

        if ret != 0:
            return False

        LimeSDR.process_command((LimeSDR.Command.SET_CHANNEL_INDEX.name, channel_index), ctrl_conn, is_tx)
        limesdr.set_tx(is_tx)
        limesdr.enable_channel(True, is_tx, channel_index)

        # Set Antenna needs to be called before other stuff!!!
        LimeSDR.process_command((LimeSDR.Command.SET_ANTENNA_INDEX.name, antenna_index), ctrl_conn, is_tx)
        LimeSDR.process_command((LimeSDR.Command.SET_FREQUENCY.name, freq), ctrl_conn, is_tx)
        LimeSDR.process_command((LimeSDR.Command.SET_SAMPLE_RATE.name, sample_rate), ctrl_conn, is_tx)
        ctrl_conn.send("Setting bandwidth...")
        LimeSDR.process_command((LimeSDR.Command.SET_BANDWIDTH.name, bandwidth), ctrl_conn, is_tx)
        LimeSDR.process_command((LimeSDR.Command.SET_RF_GAIN.name, gain * 0.01), ctrl_conn, is_tx)

        antennas = limesdr.get_antenna_list()
        ctrl_conn.send("Current normalized gain is {0:.2f}".format(limesdr.get_normalized_gain()))
        ctrl_conn.send("Current antenna is {0}".format(antennas[limesdr.get_antenna()]))
        ctrl_conn.send("Current chip temperature is {0:.2f}°C".format(limesdr.get_chip_temperature()))

        return True
示例#2
0
    def setup_device(cls, ctrl_connection: Connection, device_identifier):
        ret = limesdr.open()
        ctrl_connection.send("OPEN:" + str(ret))
        limesdr.disable_all_channels()
        if ret != 0:
            return False

        ret = limesdr.init()
        ctrl_connection.send("INIT:" + str(ret))

        return ret == 0
示例#3
0
    def setup_device(cls, ctrl_connection: Connection, device_identifier):
        ret = limesdr.open()
        ctrl_connection.send("OPEN:" + str(ret))
        limesdr.disable_all_channels()
        if ret != 0:
            return False

        ret = limesdr.init()
        ctrl_connection.send("INIT:" + str(ret))

        return ret == 0
示例#4
0
    def test_cython_wrapper(self):
        print("Devices:", limesdr.get_device_list())
        # print("Open:", limesdr.open("LimeSDR-USB, media=USB 3.0, module=STREAM, addr=1d50:6108, serial=0009060B0049180A"))
        print("Open:", limesdr.open())
        print("-" * 20)

        print("Is Open 0:", limesdr.is_open(0))
        print("Is Open 1:", limesdr.is_open(1))
        print("Init", limesdr.init())
        limesdr.set_tx(True)
        self.assertTrue(limesdr.get_tx())
        #print(limesdr.IS_TX)
        print("Num Channels TX:", limesdr.get_num_channels())
        print("TX antennas", limesdr.get_antenna_list())
        limesdr.set_tx(False)
        self.assertFalse(limesdr.get_tx())

        print("Num Channels RX:", limesdr.get_num_channels())
        limesdr.CHANNEL = 0
        print("Enable RX Channel 0:", limesdr.enable_channel(True, False, 0))

        #path = os.path.realpath(os.path.join(__file__, "..", "..", "src", "urh", "dev", "native", "lime.ini"))
        #print(path)
        #limesdr.load_config(path)
        #limesdr.save_config("/tmp/lime_test.ini")

        clocks = ["LMS_CLOCK_REF", "LMS_CLOCK_SXR", "LMS_CLOCK_SXT", "LMS_CLOCK_CGEN", "LMS_CLOCK_RXTSP", "LMS_CLOCK_TXTSP"]

        for i, clock in enumerate(clocks):
            print(clock, limesdr.get_clock_freq(i))

        limesdr.print_last_error()
        print("RX Sample Rate Range:", limesdr.get_sample_rate_range())
        print("RX Channel 0 Sample Rate:", limesdr.get_sample_rate())
        print("Set Sample Rate:", limesdr.set_sample_rate(2e6))
        print("RX Channel 0 Sample Rate:", limesdr.get_sample_rate())

        limesdr.print_last_error()
        print("RX Frequency Range:", limesdr.get_center_frequency_range())
        print("RX 0 center freq:", limesdr.get_center_frequency())
        print("RX 0 set center freq:", limesdr.set_center_frequency(433.92e6))
        print("RX 0 center freq:", limesdr.get_center_frequency())

        limesdr.print_last_error()
        print("RX 0 gain", limesdr.get_normalized_gain())
        print("RX 0 set gain", limesdr.set_normalized_gain(0.5))
        print("RX 0 gain", limesdr.get_normalized_gain())

        limesdr.print_last_error()
        print("RX Bandwidth Range", limesdr.get_lpf_bandwidth_range())
        print("RX 0 Bandwidth", limesdr.get_lpf_bandwidth())
        print("RX 0 set Bandwidth", limesdr.set_lpf_bandwidth(20e6))
        print("RX 0 Bandwidth", limesdr.get_lpf_bandwidth())

        limesdr.print_last_error()
        print("RX 0 calibrate:", limesdr.calibrate(20e6))

        limesdr.print_last_error()
        antenna_list = limesdr.get_antenna_list()
        print("RX 0 antenna list", antenna_list)
        print("RX 0 current antenna", limesdr.get_antenna(), antenna_list[limesdr.get_antenna()])
        print("RX 0 current antenna BW", limesdr.get_antenna_bw(limesdr.get_antenna()))

        print("Chip Temperature", limesdr.get_chip_temperature())

        parent_conn, child_conn = Pipe()

        for _ in range(2):
            limesdr.print_last_error()
            print("Setup stream", limesdr.setup_stream(1000))
            print("Start stream", limesdr.start_stream())
            limesdr.recv_stream(child_conn, 1000, 100)
            print("Stop stream", limesdr.stop_stream())
            print("Destroy stream", limesdr.destroy_stream())

            print(parent_conn.recv_bytes())

        limesdr.set_tx(True)
        self.assertTrue(limesdr.get_tx())
        samples_to_send = np.ones(32768, dtype=np.complex64)
        for _ in range(2):
            limesdr.print_last_error()
            print("Setup stream", limesdr.setup_stream(4000000000))
            print("Start stream", limesdr.start_stream())
            print("Send samples", limesdr.send_stream(samples_to_send, 100))
            print("Stop stream", limesdr.stop_stream())
            print("Destroy stream", limesdr.destroy_stream())

        print("-" * 20)
        print("Close:", limesdr.close())
        print("Is Open 0:", limesdr.is_open(0))
        print("Is Open 1:", limesdr.is_open(1))
示例#5
0
    def test_cython_wrapper(self):
        print("Devices:", limesdr.get_device_list())
        # print("Open:", limesdr.open("LimeSDR-USB, media=USB 3.0, module=STREAM, addr=1d50:6108, serial=0009060B0049180A"))
        print("Open:", limesdr.open())
        print("-" * 20)

        print("Is Open 0:", limesdr.is_open(0))
        print("Is Open 1:", limesdr.is_open(1))
        print("Init", limesdr.init())
        limesdr.set_tx(True)
        self.assertTrue(limesdr.get_tx())
        #print(limesdr.IS_TX)
        print("Num Channels TX:", limesdr.get_num_channels())
        print("TX antennas", limesdr.get_antenna_list())
        limesdr.set_tx(False)
        self.assertFalse(limesdr.get_tx())

        print("Num Channels RX:", limesdr.get_num_channels())
        limesdr.CHANNEL = 0
        print("Enable RX Channel 0:", limesdr.enable_channel(True, False, 0))

        #path = os.path.realpath(os.path.join(__file__, "..", "..", "src", "urh", "dev", "native", "lime.ini"))
        #print(path)
        #limesdr.load_config(path)
        #limesdr.save_config("/tmp/lime_test.ini")

        clocks = [
            "LMS_CLOCK_REF", "LMS_CLOCK_SXR", "LMS_CLOCK_SXT",
            "LMS_CLOCK_CGEN", "LMS_CLOCK_RXTSP", "LMS_CLOCK_TXTSP"
        ]

        for i, clock in enumerate(clocks):
            print(clock, limesdr.get_clock_freq(i))

        limesdr.print_last_error()
        print("RX Sample Rate Range:", limesdr.get_sample_rate_range())
        print("RX Channel 0 Sample Rate:", limesdr.get_sample_rate())
        print("Set Sample Rate:", limesdr.set_sample_rate(2e6))
        print("RX Channel 0 Sample Rate:", limesdr.get_sample_rate())

        limesdr.print_last_error()
        print("RX Frequency Range:", limesdr.get_center_frequency_range())
        print("RX 0 center freq:", limesdr.get_center_frequency())
        print("RX 0 set center freq:", limesdr.set_center_frequency(433.92e6))
        print("RX 0 center freq:", limesdr.get_center_frequency())

        limesdr.print_last_error()
        print("RX 0 gain", limesdr.get_normalized_gain())
        print("RX 0 set gain", limesdr.set_normalized_gain(0.5))
        print("RX 0 gain", limesdr.get_normalized_gain())

        limesdr.print_last_error()
        print("RX Bandwidth Range", limesdr.get_lpf_bandwidth_range())
        print("RX 0 Bandwidth", limesdr.get_lpf_bandwidth())
        print("RX 0 set Bandwidth", limesdr.set_lpf_bandwidth(20e6))
        print("RX 0 Bandwidth", limesdr.get_lpf_bandwidth())

        limesdr.print_last_error()
        print("RX 0 calibrate:", limesdr.calibrate(20e6))

        limesdr.print_last_error()
        antenna_list = limesdr.get_antenna_list()
        print("RX 0 antenna list", antenna_list)
        print("RX 0 current antenna", limesdr.get_antenna(),
              antenna_list[limesdr.get_antenna()])
        print("RX 0 current antenna BW",
              limesdr.get_antenna_bw(limesdr.get_antenna()))

        print("Chip Temperature", limesdr.get_chip_temperature())

        parent_conn, child_conn = Pipe()

        for _ in range(2):
            limesdr.print_last_error()
            print("Setup stream", limesdr.setup_stream(1000))
            print("Start stream", limesdr.start_stream())
            limesdr.recv_stream(child_conn, 1000, 100)
            print("Stop stream", limesdr.stop_stream())
            print("Destroy stream", limesdr.destroy_stream())

            print(parent_conn.recv_bytes())

        limesdr.set_tx(True)
        self.assertTrue(limesdr.get_tx())
        samples_to_send = np.ones(32768, dtype=np.complex64)
        for _ in range(2):
            limesdr.print_last_error()
            print("Setup stream", limesdr.setup_stream(4000000000))
            print("Start stream", limesdr.start_stream())
            print("Send samples", limesdr.send_stream(samples_to_send, 100))
            print("Stop stream", limesdr.stop_stream())
            print("Destroy stream", limesdr.destroy_stream())

        print("-" * 20)
        print("Close:", limesdr.close())
        print("Is Open 0:", limesdr.is_open(0))
        print("Is Open 1:", limesdr.is_open(1))