Пример #1
0
    def test_002_update(self):
        start_time = 0.1
        self.duration = 125000
        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1, [])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, 250000)
        self.utag = timing_utils.add_usrp_tags_c(1090e6, 250000, 0, start_time)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")

        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tag_dbg, 0))

        self.tb.start()
        time.sleep(.01)
        #print("Dumping tags")
        for t in self.tag_dbg.current_tags():
            #print( 'Tag:' , t.key, ' ', t.value )
            if pmt.eq(t.key, pmt.intern("rx_freq")):
                self.assertAlmostEqual(1090e6, pmt.to_double(t.value))
            if pmt.eq(t.key, pmt.intern("rx_rate")):
                self.assertAlmostEqual(250000, pmt.to_double(t.value))

        self.utag.update_tags(self.makeDict(freq=1091e6, rate=260000, epoch_int=0, epoch_frac=start_time + .3))
        time.sleep(.01)
        #print("Dumping tags")
        for t in self.tag_dbg.current_tags():
            #print( 'Tag:' , t.key, ' ', t.value )
            if pmt.eq(t.key, pmt.intern("rx_freq")):
                self.assertAlmostEqual(1091e6, pmt.to_double(t.value))
            if pmt.eq(t.key, pmt.intern("rx_rate")):
                self.assertAlmostEqual(260000, pmt.to_double(t.value))

        time.sleep(.1)
        self.tb.stop()
    def setUp(self):
        self.rate = 250000

        self.duration = int(self.rate * 4)
        self.start_time = .098765
        self.skey = pmt.intern("trigger_sample")
        self.tkey = pmt.intern("trigger_time")

        self.tb = gr.top_block()

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, self.rate)

        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.start_time = .098765
        self.utag = timing_utils.add_usrp_tags_c(1090e6, self.rate, 0,
                                                 self.start_time)
        #self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex*1, '', "");
        self.msg_dbg = blocks.message_debug()
        self.timer = timing_utils.interrupt_emitter_c(self.rate, True)

        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.utag, 0))
        #self.tb.connect((self.utag, 0), (self.tag_dbg, 0))
        self.tb.connect((self.utag, 0), (self.timer, 0))
        self.tb.msg_connect((self.emitter, "msg"), (self.timer, "set"))
        self.tb.msg_connect((self.timer, "trig"), (self.msg_dbg, "store"))
    def test_004_onlyusrp(self):
        self.tb = gr.top_block()
        self.rate = 250000
        self.interval = 0
        self.duration = 4532

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [])
        self.utag = timing_utils.add_usrp_tags_c(1090e6, self.rate, 0, .98765)
        self.tags = timing_utils.tag_uhd_offset_c(self.rate, self.interval)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, "", "")
        self.tag_dbg.set_display(False)
        self.tb.connect((self.src, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tags, 0))
        self.tb.connect((self.tags, 0), (self.tag_dbg, 0))
        e_n_tags = 4

        self.tb.run()
        self.assertEqual(self.tag_dbg.num_tags(), e_n_tags)
        self.tb = None
    def test_002_alt(self):
        self.tb = gr.top_block()
        self.rate = 1
        self.interval = 133
        self.duration = 4532

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [])
        self.utag = timing_utils.add_usrp_tags_c(1090e6, self.rate, 0, .98765)
        self.tags = timing_utils.tag_uhd_offset_c(self.rate, self.interval)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, "", "")
        self.tag_dbg.set_display(False)
        self.tb.connect((self.src, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tags, 0))
        self.tb.connect((self.tags, 0), (self.tag_dbg, 0))
        e_n_tags = int(ceil(1.0 * self.duration / self.interval)) + 3

        self.tb.run()

        tags = self.tag_dbg.current_tags()
        tprev = None
        for t in tags:
            if pmt.eq(t.key, pmt.intern("rx_time_offset")):
                self.assertAlmostEqual(
                    self.rate, pmt.to_double(pmt.tuple_ref(t.value, 3)))
                self.assertEqual(t.offset,
                                 pmt.to_uint64(pmt.tuple_ref(t.value, 2)))
                self.assertTrue((pmt.to_uint64(pmt.tuple_ref(t.value, 2)) /
                                 (1.0 * self.interval)).is_integer())
                if tprev is not None:
                    tcur = pmt.to_uint64(pmt.tuple_ref(
                        t.value, 0)) + pmt.to_double(pmt.tuple_ref(t.value, 1))
                    self.assertAlmostEqual(tcur - tprev,
                                           1.0 * self.interval / self.rate)
                    tprev = tcur
                else:
                    tprev = pmt.to_uint64(pmt.tuple_ref(
                        t.value, 0)) + pmt.to_double(pmt.tuple_ref(t.value, 1))
        self.assertEqual(self.tag_dbg.num_tags(), e_n_tags)
        self.tb = None
Пример #5
0
    def __init__(self, filename, loop, decimation, samp_rate, f0, short,
                 start_time):
        gr.hier_block2.__init__(self, "uhd_timed_cordic_emulator",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # variables
        taps = filter.firdes.low_pass_2(1, samp_rate,
                                        (samp_rate * 0.4) / decimation,
                                        (samp_rate * 0.4) / decimation, 60)
        print "freq xlating filter created with " + repr(len(taps)) + " taps"
        fc_start = f0

        # message inputs / outputs
        self.message_port_register_hier_in("command")

        # blocks
        if short:
            self.file = blocks.file_source(gr.sizeof_short * 1, filename, loop)
        else:
            self.file = blocks.file_source(gr.sizeof_gr_complex * 1, filename,
                                           loop)
        self.scale = blocks.multiply_const_vcc((1.0 / pow(2, 15), ))
        self.deint = blocks.interleaved_short_to_complex(False, False)
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate,
                                        True)
        self.tagger = timing_utils.add_usrp_tags_c(
            fc_start, samp_rate, int(start_time),
            (start_time - int(start_time)))
        self.tuner = timing_utils.retune_uhd_to_timed_tag(
            int(samp_rate), pmt.intern('dsp_freq'), int(start_time),
            (start_time - int(start_time)))
        if DECIMATE_IN_FREQ_XLATING_FILTER:
            self.filt = timing_utils.timed_freq_xlating_fir_ccf(
                decimation, (taps), fc_start, samp_rate)
        else:
            self.filt = timing_utils.timed_freq_xlating_fir_ccf(
                1, [1], fc_start, samp_rate)
            self.fir = filter.fir_filter_ccf(decimation, (taps))
            self.fir.declare_sample_delay(0)

        # connections
        if short:
            self.connect(self.file, self.deint)
            self.connect(self.deint, self.throttle)
            self.connect(self.throttle, self.scale)
            self.connect(self.scale, self.tagger)
        else:
            self.connect(self.file, self.throttle)
            self.connect(self.throttle, self.tagger)

        self.connect(self.tagger, self.tuner)
        self.connect(self.tuner, self.filt)

        if DECIMATE_IN_FREQ_XLATING_FILTER:
            self.connect(self.filt, self)
        else:
            self.connect(self.filt, self.fir)
            self.connect(self.fir, self)

        self.msg_connect(self, "command", self.tuner, "command")
    def __init__(self, filename, loop, decimation, samp_rate, f0, short,
                 start_time):
        gr.hier_block2.__init__(self, "uhd_timed_cordic_emulator",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # setup logger
        logger_name = 'gr_log.' + self.to_basic_block().alias()
        if logger_name in gr.logger_get_names():
            self.log = gr.logger(logger_name)
        else:
            self.log = gr.logger('log')

        # variables
        taps = filter.firdes.low_pass_2(1, samp_rate,
                                        (samp_rate * 0.4) / decimation,
                                        (samp_rate * 0.4) / decimation, 60)
        self.log.debug("freq xlating filter created with " + repr(len(taps)) +
                       " taps")
        fc_start = f0

        # message inputs / outputs
        self.message_port_register_hier_in("command")

        # blocks
        if short:
            self.file = blocks.file_source(gr.sizeof_short * 1, filename, loop)
        else:
            self.file = blocks.file_source(gr.sizeof_gr_complex * 1, filename,
                                           loop)
        self.deint = sandia_utils.interleaved_short_to_complex(
            False, False, 1.0 / pow(2, 15))
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate,
                                        True)
        self.tagger = timing_utils.add_usrp_tags_c(
            fc_start, samp_rate, int(start_time),
            (start_time - int(start_time)))
        self.tuner = timing_utils.retune_uhd_to_timed_tag(
            int(samp_rate), timing_utils.PMTCONSTSTR__dsp_freq(),
            int(start_time), (start_time - int(start_time)))
        if DECIMATE_IN_FREQ_XLATING_FILTER:
            self.filt = timing_utils.timed_freq_xlating_fir_ccf(
                decimation, (taps), fc_start, samp_rate)
        else:
            self.filt = timing_utils.timed_freq_xlating_fir_ccf(
                1, [1], fc_start, samp_rate)
            self.fir = filter.fir_filter_ccf(decimation, (taps))
            self.fir.declare_sample_delay(0)

        # connections
        if short:
            self.connect(self.file, self.deint)
            self.connect(self.deint, self.throttle)
            self.connect(self.throttle, self.tagger)
        else:
            self.connect(self.file, self.throttle)
            self.connect(self.throttle, self.tagger)

        self.connect(self.tagger, self.tuner)
        self.connect(self.tuner, self.filt)

        if DECIMATE_IN_FREQ_XLATING_FILTER:
            self.connect(self.filt, self)
        else:
            self.connect(self.filt, self.fir)
            self.connect(self.fir, self)

        self.msg_connect(self, "command", self.tuner, "command")