Exemplo n.º 1
0
 def stream_samps(self, timespec):
     for sel in self.selectors:
         sel.set_output_index(self.gen_msgs.msg_num)
     cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
     cmd.num_samps = self.num_samps
     cmd.time_spec = timespec
     self.uhd_usrp_source_0.issue_stream_cmd(cmd)
Exemplo n.º 2
0
def test_stacked_rx_commands():

    # Crimson TNG Setup.
    channels = range(4)
    sample_rate = 20e6
    sample_count = 4096

    # Crimson TNG acts as a source by providing complex float samples.
    csrc = crimson.get_src_c(channels, sample_rate, 15e6, 1.0)

    # Vector buffer that accepts complex float samples.
    vsnk = [blocks.vector_sink_c() for channel in channels]
    """
    +-----------+
    |           |   +---------+
    |      ch[0]|-->| vsnk[0] |
    |           |   +---------+
    |           |   +---------+
    |      ch[1]|-->| vsnk[1] |
    |           |   +---------+
    |           |
    |           |   +---------+
    |      ch[N]|-->| vsnk[N] |
    | csrc      |   +---------+
    +-----------+
    """
    flowgraph = gr.top_block()
    for channel in channels:
        flowgraph.connect((csrc, channel), vsnk[channel])

    # The flowgraph must be started before commands are sent.
    flowgraph.start()

    # Enqueue one RX command every second starting at <start> and ending at <end> times.
    csrc.set_time_now(uhd.time_spec(0.0))
    start = 3
    end = 8
    for second in range(start, end, 1):
        cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
        cmd.num_samps = sample_count
        cmd.stream_now = False
        cmd.time_spec = uhd.time_spec(second)
        csrc.issue_stream_cmd(cmd)

    # Poll for incoming RX commands and print the length of the vector sink.
    for second in range(end):
        for channel in channels:
            print "%d: %d" % (second, len(vsnk[channel].data()))
        time.sleep(1.0)

    # Cleanup and validate.
    flowgraph.stop()
    flowgraph.wait()
    for channel in channels:
        total_sample_count = sample_count * (end - start)
        assert len(vsnk[channel].data()) == total_sample_count
Exemplo n.º 3
0
def run_rx(csrc, channels, stack, sample_rate, _vsnk):
    """
    +-----------+
    |           |   +---------+
    |      ch[0]|-->| vsnk[0] |
    |           |   +---------+
    |           |   +---------+
    |      ch[1]|-->| vsnk[1] |
    |           |   +---------+
    |           |
    |           |   +---------+
    |      ch[N]|-->| vsnk[N] |
    | csrc      |   +---------+
    +-----------+
    """

    # Connect.
    vsnk = [blocks.vector_sink_c() for ch in channels]

    flowgraph = gr.top_block()
    for ch in channels:
        flowgraph.connect((csrc, ch), vsnk[ch])

    # Run. The flowgraph must be started before stream commands are sent.
    flowgraph.start()

    for frame in stack:  #rx_stack in fund_freq

        cmd = uhd.stream_cmd_t(
            uhd.stream_mode_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
        cmd.num_samps = frame[
            1]  #frame[1]= rx_stack[( , it["sample_count"])] in fund_freq
        cmd.stream_now = False
        #print(frame[0])
        cmd.time_spec = uhd.time_spec(
            frame[0])  #frame[0]=rx_stack[ 10.005, ] in fund_freq
        csrc.issue_stream_cmd(cmd)
        #print("rx stack time is:", cmd.time_spec)

    # Wait for completion.
    total_sample_count = sum([frame[1] for frame in stack])
    #print("total sample count is:", total_sample_count)
    while len(vsnk[0].data()) < total_sample_count:
        time.sleep(0.1)

    flowgraph.stop()
    flowgraph.wait()

    # Cannot return from thread so extend instead.
    _vsnk.extend(vsnk)
Exemplo n.º 4
0
def rx_run(csrc, channels, sample_count, start_time_specs, sample_rate, vsnks):
    """
    +-----------+
    |           |   +---------+
    |      ch[0]|-->| vsnk[0] |
    |           |   +---------+
    |           |   +---------+
    |      ch[1]|-->| vsnk[1] |
    |           |   +---------+
    |           |
    |           |   +---------+
    |      ch[N]|-->| vsnk[N] |
    | csrc      |   +---------+
    +-----------+
    """

    vsnk = [blocks.vector_sink_c() for channel in channels]

    flowgraph = gr.top_block()
    for channel in channels:
        flowgraph.connect((csrc, channel), vsnk[channel])

    # The flowgraph must be started before stream commands are sent.
    flowgraph.start()

    for start_time_spec in start_time_specs:
        cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
        cmd.num_samps = sample_count
        cmd.stream_now = False
        cmd.time_spec = start_time_spec
        csrc.issue_stream_cmd(cmd)

    total_sample_count = len(start_time_specs) * sample_count

    # Wait for completion.
    while len(vsnk[0].data()) < total_sample_count:
        time.sleep(0.1)

    flowgraph.stop()
    flowgraph.wait()

    # Save for later use.
    vsnks.append(vsnk)

    dump(vsnk, total_sample_count, channels)

    test_fullness(vsnk, sample_count, start_time_specs)
Exemplo n.º 5
0
#%%
from gnuradio import uhd

uhd_usrp_source_0 = uhd.usrp_source(
    ",".join(("", "")),
    uhd.stream_args(
        cpu_format="fc32",
        args='',
        channels=list(range(0, 2)),
    ),
)

#streamer restart/align
stop_cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_STOP_CONTINUOUS)
stop_cmd.stream_now = True

self.uhd_usrp_source_0.issue_stream_cmd(stop_cmd)

stream_cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_START_CONTINUOUS)
stream_cmd.stream_now = False
#delay by 5s
stream_cmd.time_spec = self.uhd_usrp_source_0.get_time_now() + uhd.time_spec_t(
    5.0)
self.uhd_usrp_source_0.issue_stream_cmd(stream_cmd)

#freq align - potential phase sync
retune_time = self.uhd_usrp_source_0.get_time_now() + uhd.time_spec_t(5.0)
self.uhd_usrp_source_0.set_command_time(retune_time)

center_freq_tmp = 2.4501e9
tune_req = uhd.tune_request_t(center_freq_tmp)
Exemplo n.º 6
0
    def coreTest(self, rx_gain, tx_amp, centre_freq, sample_rate=20e6):
        """
        |<------------ TX CHAIN ---------->| |<----- RX CHAIN ---->|
                                    +------+ +------+
        +--------+    +--------+    |      | |      |    +---------+
        | sig[0] |--->| c2s[0] |--->|ch0   | |   ch0|--->| vsnk[0] |
        +--------+    +--------+    |      | |      |    +---------+
        +--------+    +--------+    |      | |      |    +---------+
        | sig[1] |--->| c2s[1] |--->|ch1   | |   ch1|--->| vsnk[1] |
        +--------+    +--------+    |      | |      |    +---------+
        +--------+    +--------+    |      | |      |    +---------+
        | sig[2] |--->| c2s[2] |--->|ch2   | |   ch2|--->| vsnk[2] |
        +--------+    +--------+    |      | |      |    +---------+
        +--------+    +--------+    |      | |      |    +---------+
        | sig[3] |--->| c2s[3] |--->|ch3   | |   ch3|--->| vsnk[3] |
        +--------+    +--------+    | csnk | | csrc |    +---------+
                                    +------+ +------+
        """

        # Is above 40 MHz, disable Channels C & D
        if centre_freq > 40e6:
            self.channels = range(2)

        tb = gr.top_block()

        # Variables.
        wave_freq = 1e6

        sc = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
        sc.num_samps = 64

        # Blocks and Connections (TX CHAIN).
        sigs = [
            analog.sig_source_c(sample_rate, analog.GR_SIN_WAVE, wave_freq,
                                tx_amp, 0.0) for channel in self.channels
        ]

        c2ss = [
            blocks.complex_to_interleaved_short(True)
            for channel in self.channels
        ]

        csnk = crimson_sink_s(self.channels, sample_rate, centre_freq, 0.0)

        for channel in self.channels:
            tb.connect(sigs[channel], c2ss[channel])
            tb.connect(c2ss[channel], (csnk, channel))

        # Blocks and Connections (RX CHAIN).
        csrc = crimson_source_c(self.channels, sample_rate, centre_freq,
                                rx_gain)

        vsnk = [blocks.vector_sink_c() for channel in self.channels]

        for channel in self.channels:
            tb.connect((csrc, channel), vsnk[channel])

        # Reset TX and RX times to be roughly in sync.
        csnk.set_time_now(uhd.time_spec_t(0.0))
        csrc.set_time_now(uhd.time_spec_t(0.0))

        # Issue stream command to start RX chain somewhere in the middle of the test.
        sc.stream_now = False
        sc.time_spec = uhd.time_spec_t(self.test_time / 2.0)
        csrc.issue_stream_cmd(sc)

        # Run the test.
        tb.start()
        time.sleep(self.test_time)
        tb.stop()
        tb.wait()

        # Return a vsnk sample for further processing and verification.
        # vsnk are to be processed in individual unit tests, eg. def test_xyz_t(self):
        # Read sigproc.py for further information on signal processing and vsnks.

        return vsnk, csnk, csrc
Exemplo n.º 7
0
def main():

    # Crimson TNG Setup.
    channels = np.array([0, 1, 2, 3])
    sample_rate = 20e6
    sample_count = 4096

    # Crimson TNG acts as a source by providing complex float samples.
    csrc = crimson.get_src_c(channels, sample_rate, 15e6, 1.0)

    # Vector buffer that accepts complex float samples.
    vsnk = [blocks.vector_sink_c() for channel in channels]
    """
    +-----------+
    |           |   +---------+
    |      ch[0]|-->| vsnk[0] |
    |           |   +---------+
    |           |   +---------+
    |      ch[1]|-->| vsnk[1] |
    |           |   +---------+
    |           |
    |           |   +---------+
    |      ch[N]|-->| vsnk[N] |
    | csrc      |   +---------+
    +-----------+
    """
    flowgraph = gr.top_block()
    for channel in channels:
        flowgraph.connect((csrc, channel), vsnk[channel])

    # The flowgraph must be started before commands are sent.
    flowgraph.start()

    # Enqueue one RX command every second starting at <start> and ending at <end> times.
    csrc.set_time_now(uhd.time_spec(0.0))
    start = 3  #Start Time
    end = 8  #End Time
    interval = 1  #Increment time (Wait this long between subsequent Rx commands)

    interval_additional_delay_coefficient = 0.1  # Time at which we poll between Rx commands
    for second in range(start, end, interval):
        cmd = uhd.stream_cmd_t(
            uhd.stream_mode_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
        cmd.num_samps = sample_count
        cmd.stream_now = False
        cmd.time_spec = uhd.time_spec(second)
        csrc.issue_stream_cmd(cmd)

    # Poll for incoming RX commands and print the length of the vector sink.
    for sec in range(end):
        for channel in channels:
            #print(channel)
            print("%d: %d: %d" % (channel, sec, len(vsnk[channel].data())))
            print(len(vsnk[channel].data()))
            #Populate slot 1 of that array with the sample count for that time interval
        time.sleep(interval + interval * interval_additional_delay_coefficient)

    #Poll for incoming RX commands and print the length of the vector sink.

    #make a pass/fail object that defaults true;
    # Cleanup and validate.
    flowgraph.stop()
    flowgraph.wait()

    #Test 1: assure length of all Rx samples received are as expected
    for channel in channels:
        expect_sample_count = sample_count * (end - start)
        actual_sample_count = len((vsnk[channel].data()))

        print("the expected sample count and the actual sample count are:",
              expect_sample_count, actual_sample_count)
        #Assert that both are true (or make a global pass bool)
        assert expect_sample_count == actual_sample_count
Exemplo n.º 8
0
def main():

    # Crimson TNG Setup.
    channels = np.array([0, 1, 2, 3])
    sample_rate = 20e6
    sample_count = 4096

    # Crimson TNG acts as a source by providing complex float samples.
    csrc = crimson.get_src_c(channels, sample_rate, 15e6, 1.0)

    # Vector buffer that accepts complex float samples.
    vsnk = [blocks.vector_sink_c() for channel in channels]
    """
    +-----------+
    |           |   +---------+
    |      ch[0]|-->| vsnk[0] |
    |           |   +---------+
    |           |   +---------+
    |      ch[1]|-->| vsnk[1] |
    |           |   +---------+
    |           |
    |           |   +---------+
    |      ch[N]|-->| vsnk[N] |
    | csrc      |   +---------+
    +-----------+
    """
    flowgraph = gr.top_block()
    for channel in channels:
        flowgraph.connect((csrc, channel), vsnk[channel])

    # The flowgraph must be started before commands are sent.
    flowgraph.start()

    # Enqueue one RX command every second starting at <start> and ending at <end> times.
    csrc.set_time_now(uhd.time_spec(0.0))
    start = 3  #Start Time
    end = 8  #End Time
    interval = 1  #Increment time (Wait this long between subsequent Rx commands)

    #Create an expected Rx sample count array for the amount of samples expected to be received
    sample_count_array = np.arange(sample_count,
                                   int(sample_count * ((end - start) + 1)),
                                   sample_count,
                                   dtype=np.int32)
    zero_count_array = np.zeros(start, dtype=np.int32)
    expect_count_array = np.append(zero_count_array, sample_count_array)
    print("the theoretical expected sample count array is:",
          expect_count_array)

    interval_additional_delay_coefficient = 0.1  # Time at which we poll between Rx commands
    for second in range(start, end, interval):
        cmd = uhd.stream_cmd_t(
            uhd.stream_mode_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
        cmd.num_samps = sample_count
        cmd.stream_now = False
        cmd.time_spec = uhd.time_spec(second)
        csrc.issue_stream_cmd(cmd)

    #Poll for incoming RX commands and print the length of the vector sink.

    ch_1_array = []
    ch_2_array = []
    ch_3_array = []
    ch_4_array = []
    for second in range(end):
        #print(channel)
        print("%d: %d: %d" % (0, second, len(vsnk[0].data())))
        ch_1_array.append(len(vsnk[0].data()))
        print("%d: %d: %d" % (1, second, len(vsnk[1].data())))
        ch_2_array.append(len(vsnk[1].data()))
        print("%d: %d: %d" % (2, second, len(vsnk[2].data())))
        ch_3_array.append(len(vsnk[2].data()))
        print("%d: %d: %d" % (3, second, len(vsnk[3].data())))
        ch_4_array.append(len(vsnk[3].data()))
        #Populate slot 1 of that array with the sample count for that time interval
        time.sleep(interval + interval * interval_additional_delay_coefficient)

    ch_1_actual_array = np.asarray(ch_1_array)
    ch_2_actual_array = np.asarray(ch_2_array)
    ch_3_actual_array = np.asarray(ch_3_array)
    ch_4_actual_array = np.asarray(ch_4_array)
    print("the collected channel 1 sample count array is:", ch_1_actual_array)
    print("the collected channel 2 sample count array is:", ch_2_actual_array)
    print("the collected channel 3 sample count array is:", ch_3_actual_array)
    print("the collected channel 4 sample count array is:", ch_4_actual_array)

    #Test 2: Make sure that slots 0..start = 0, and start..end increment by sample count.
    try:
        assert (np.array_equal((ch_1_actual_array), (expect_count_array)))
        assert (np.array_equal((ch_2_actual_array), (expect_count_array)))
        assert (np.array_equal((ch_3_actual_array), (expect_count_array)))
        assert (np.array_equal((ch_4_actual_array), (expect_count_array)))
    except:
        print('expected and actual array are not equal, fail')
        sys.exit(1)