コード例 #1
0
    def test_002_holdoff (self):
        self.tb = gr.top_block ()

        trig_key = pmt.intern("TRIGGER")
        tags = []
        tags.append(gr.tag_utils.python_to_tag((5, trig_key, pmt.PMT_T)))  # should trigger
        tags.append(gr.tag_utils.python_to_tag((6, trig_key, pmt.PMT_T)))
        tags.append(gr.tag_utils.python_to_tag((9, trig_key, pmt.PMT_T)))  # should trigger
        tags.append(gr.tag_utils.python_to_tag((10, trig_key, pmt.PMT_T)))
        tags.append(gr.tag_utils.python_to_tag((11, trig_key, pmt.PMT_T)))
        tags.append(gr.tag_utils.python_to_tag((12, trig_key, pmt.PMT_T)))
        tags.append(gr.tag_utils.python_to_tag((13, trig_key, pmt.PMT_T)))  # should trigger
        msg = pmt.cons(pmt.dict_add(pmt.make_dict(), pmt.intern("K1"), pmt.intern("V1")), pmt.init_u8vector(4,[48,49,50,51,]))
        src = blocks.vector_source_f(range(20), False, 1, tags)
        tmt = pdu_utils.tag_message_trigger_f(trig_key, pmt.PMT_NIL, msg, 3, 0.0, 0.0, 0.0, False)
        debug = blocks.message_debug()
        self.tb.connect(src, tmt)

        self.tb.msg_connect((tmt, 'msg'), (debug, 'store'))
        self.tb.run ()

        self.assertEquals(debug.num_messages(),3)
        self.assertTrue(pmt.eqv(msg, debug.get_message(0)))
        self.assertTrue(pmt.eqv(msg, debug.get_message(1)))

        self.tb = None
コード例 #2
0
    def handle_command(self, msg):
        # incoming message will be a dictionary that should contain the items
        # freq and lo_offset at a minimum - if this is met, issue a command
        # that can be handled by the freq_xlating_fir_filter_ccf block
        try:
            #print "got a message!"
            # we don't care about the frequency since we are CORDIC tuning
            lo_offset = pmt.dict_ref(msg, self.dict_key, pmt.PMT_NIL)
            if not pmt.eqv(lo_offset, pmt.PMT_NIL):
                offset = pmt.to_python(lo_offset)
                #print "lo offset is " + repr(offset*-1.0)
                self.message_port_pub(pmt.intern("freq"),
                    pmt.cons(pmt.intern("freq"), pmt.from_double(-1.0*offset)))
                #print "published msg, offset = " + repr(-1.0*offset)

                # if the dictionary has a time value, use it
                time_tag = pmt.dict_ref(msg, pmt.intern("time"), pmt.PMT_NIL)
                if not pmt.eqv(time_tag, pmt.PMT_NIL):
                    secs = pmt.to_uint64(pmt.car(time_tag)) - self.origin_time['secs']
                    frac = pmt.to_double(pmt.cdr(time_tag)) - self.origin_time['frac']
                    tune_sample = long(secs * self.sample_rate) + long(frac * self.sample_rate)
                else:
                    tune_sample = TAG_IMMEDIATELY

                # we will also set the block to tag the output when it is time
                self.tag_offset = tune_sample
                self.tag_value = pmt.from_double(-1.0*offset)

        except Exception as e:
            print "exception: " + repr(e)
コード例 #3
0
    def test_002_normal(self):

        tnow = time.time()

        in_data = [
            0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1,
            0, 1
        ]
        meta = pmt.dict_add(pmt.make_dict(), pmt.intern('wall_clock_time'),
                            pmt.from_double(tnow - 10))
        in_pdu = pmt.cons(meta, pmt.init_c32vector(len(in_data), in_data))

        e_data = [
            0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1,
            0, 1
        ]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern('wall_clock_time'),
                              pmt.from_double(tnow))
        e_pdu = pmt.cons(e_meta, pmt.init_c32vector(len(e_data), e_data))

        # set up fg
        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()
        # check data

        self.assertEqual(1, self.debug.num_messages())

        #print("test_002_normal2:")
        #print("pdu expected: " + repr(pmt.car(e_pdu)))
        #print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        #print("data expected: " + repr(pmt.to_python(pmt.cdr(e_pdu))))
        #print("data got:      " + repr(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        #print

        a_meta = pmt.car(self.debug.get_message(0))

        time_tag = pmt.dict_ref(a_meta, pmt.intern("wall_clock_time"),
                                pmt.PMT_NIL)
        if not pmt.eqv(time_tag, pmt.PMT_NIL):
            self.assertAlmostEqual(tnow, pmt.to_double(time_tag), delta=60)
        else:
            self.assertTrue(False)

        delta_tag = pmt.dict_ref(a_meta, pmt.intern("time_delta_ms"),
                                 pmt.PMT_NIL)
        if not pmt.eqv(delta_tag, pmt.PMT_NIL):
            self.assertAlmostEqual(10000, pmt.to_double(delta_tag), delta=10)
        else:
            self.assertTrue(False)
コード例 #4
0
    def work(self, input_items, output_items):
        in0 = input_items[0]
        start = self.nitems_read(0)
        end = start + len(in0)

        tags = self.get_tags_in_range(0, start, end)
        for tag in tags:
            if pmt.eqv(tag.key, self.st):
                self.start_idx = tag.offset
            elif pmt.eqv(tag.key, self.et):
                if self.start_idx:
                    print(
                        repr(
                            round((tag.offset - self.start_idx) * 1000.0 /
                                  self.rate, 3)) + ", ")
                self.start_idx = 0

        return len(in0)
コード例 #5
0
    def test_002_emit2(self):
        emitter = pdu_utils.message_emitter()
        debug = blocks.message_debug()
        msg = pmt.cons(pmt.intern("TEST MESSAGE"),
                       pmt.init_u8vector(4, range(4)))
        self.tb.msg_connect((emitter, 'msg'), (debug, 'store'))

        self.tb.start()
        time.sleep(.001)
        emitter.emit()
        time.sleep(.001)
        emitter.emit(msg)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print(emitter.get_n_msgs())
        self.assertEquals(2, debug.num_messages())
        self.assertTrue(pmt.eqv(pmt.PMT_NIL, debug.get_message(0)))
        self.assertTrue(pmt.eqv(msg, debug.get_message(1)))
コード例 #6
0
    def handle_command(self, msg):
        with self.lock:
            # incoming message will be a dictionary that should contain the items
            # freq and lo_offset at a minimum - if this is met, issue a command
            # that can be handled by the freq_xlating_fir_filter_ccf block
            try:
                # print "got a message!"
                # we don't care about the frequency since we are CORDIC tuning
                lo_offset = pmt.dict_ref(msg, self.dict_key, pmt.PMT_NIL)
                if not pmt.eqv(lo_offset, pmt.PMT_NIL):
                    offset = pmt.to_python(lo_offset)
                    # print "lo offset is " + repr(offset*-1.0)
                    self.message_port_pub(
                        timing_utils.PMTCONSTSTR__freq(),
                        pmt.cons(timing_utils.PMTCONSTSTR__freq(),
                                 pmt.from_double(-1.0 * offset)))
                    # print "published msg, offset = " + repr(-1.0*offset)

                    # if the dictionary has a time value, use it
                    time_tag = pmt.dict_ref(msg,
                                            timing_utils.PMTCONSTSTR__time(),
                                            pmt.PMT_NIL)
                    if not pmt.eqv(time_tag, pmt.PMT_NIL):
                        secs = pmt.to_uint64(
                            pmt.car(time_tag)) - self.ref_time['secs']
                        frac = pmt.to_double(
                            pmt.cdr(time_tag)) - self.ref_time['frac']
                        tune_sample = int(secs * self.sample_rate) + int(
                            frac * self.sample_rate) + self.ref_time['offset']
                    else:
                        tune_sample = TAG_IMMEDIATELY

                    # we will also set the block to tag the output when it is time
                    if len(self.tune_commands) < self.tune_commands.maxlen:
                        self.tune_commands.append(
                            (tune_sample, pmt.from_double(-1.0 * offset)))

            except Exception as e:
                print("exception: " + repr(e))
コード例 #7
0
ファイル: qa_message.py プロジェクト: bsheaffer/gnuradio-old
    def test_debug_401(self):
        msg = pmt.intern("TESTING")
        src = blocks.message_strobe(msg, 500)
        snk = blocks.message_debug()

        tb = gr.top_block()
        tb.msg_connect(src, "strobe", snk, "store")
        tb.start()
        time.sleep(1)
        tb.stop()
        tb.wait()

        rec_msg = snk.get_message(0)
        self.assertTrue(pmt.eqv(rec_msg, msg))
コード例 #8
0
ファイル: qa_message.py プロジェクト: Gabotero/GNURadioNext
    def test_debug_401(self):
        msg = pmt.intern("TESTING")
        src = blocks.message_strobe(msg, 500)
        snk = blocks.message_debug()

	tb = gr.top_block()
        tb.msg_connect(src, "strobe", snk, "store")
        tb.start()
        time.sleep(1)
        tb.stop()
        tb.wait()

        rec_msg = snk.get_message(0)
        self.assertTrue(pmt.eqv(rec_msg, msg))
コード例 #9
0
    def test_002_tags(self):
        self.duration = 125000
        tnow = time.time()

        src_tag = gr.tag_utils.python_to_tag([
            0,
            pmt.intern("wall_clock_time"),
            pmt.from_double(tnow - 10000),
            pmt.intern("test_002_tags")
        ])
        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [src_tag])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, 250000)
        self.dut = timing_utils.system_time_diff_c(True, False)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        self.nullf = blocks.null_sink(gr.sizeof_float * 1)

        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.dut, 0))
        self.tb.connect((self.dut, 0), (self.tag_dbg, 0))
        self.tb.connect((self.dut, 1), (self.nullf, 0))

        self.tb.start()
        time.sleep(.02)

        tags = self.tag_dbg.current_tags()
        time_tag = None
        print("Dumping tags")
        for t in tags:
            print('Tag:', t.key, ' ', t.value)
            if pmt.eqv(t.key, pmt.intern("wall_clock_time")):
                time_tag = t

        if time_tag:
            self.assertAlmostEqual(tnow,
                                   pmt.to_double(time_tag.value),
                                   delta=60)
        else:
            self.assertTrue(False)

        time.sleep(.1)
        self.tb.stop()