Exemple #1
0
    def test_003(self):
        offsets = (6, 3, 8)
        key = pmt.string_to_symbol('key')
        srcid = pmt.string_to_symbol('qa_tag_utils')
        tags = []

        for k in offsets:
            t = gr.tag_t()
            t.offset = k
            t.key = key
            t.value = pmt.from_long(k)
            t.srcid = srcid
            tags.append(t)

        for k, t in zip(sorted(offsets),
                        sorted(tags, key=gr.tag_t_offset_compare_key())):
            self.assertEqual(t.offset, k)
            self.assertTrue(pmt.equal(t.key, key))
            self.assertTrue(pmt.equal(t.value, pmt.from_long(k)))
            self.assertTrue(pmt.equal(t.srcid, srcid))

        tmin = min(tags, key=gr.tag_t_offset_compare_key())
        self.assertEqual(tmin.offset, min(offsets))
        self.assertTrue(pmt.equal(tmin.key, key))
        self.assertTrue(pmt.equal(tmin.value, pmt.from_long(min(offsets))))
        self.assertTrue(pmt.equal(tmin.srcid, srcid))

        tmax = max(tags, key=gr.tag_t_offset_compare_key())
        self.assertEqual(tmax.offset, max(offsets))
        self.assertTrue(pmt.equal(tmax.key, key))
        self.assertTrue(pmt.equal(tmax.value, pmt.from_long(max(offsets))))
        self.assertTrue(pmt.equal(tmax.srcid, srcid))
Exemple #2
0
 def test14(self):
     const = self.MAXINT32 - 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     self.assertEqual(const,pmt.to_long(deser))
Exemple #3
0
 def test17(self):
     const = self.MININT32 + 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     x_long = pmt.to_long(deser)
     self.assertEqual(const, x_long)
 def test_005_t (self):
     """ Tags """
     X_in = (
         (1, 2, 3, 4),
         (5, 6, 7, 8),
     )
     A = (
         (0, 1), # Flip them round
         (1, 0),
     )
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.intern("in1")
     tag1.value = pmt.PMT_T
     tag2 = gr.tag_t()
     tag2.offset = 0
     tag2.key = pmt.intern("in2")
     tag2.value = pmt.PMT_T
     self.run_once(X_in, A, tpp=gr.TPP_ONE_TO_ONE, tags=(tag1, tag2))
     self.assertTrue(pmt.equal(tag1.key, self.the_tags[0][0].key))
     self.assertTrue(pmt.equal(tag2.key, self.the_tags[1][0].key))
Exemple #5
0
    def test_002(self):
        offset = 10
        key = pmt.string_to_symbol('key')
        value = pmt.from_long(23)
        srcid = pmt.from_bool(False)

        format_dict = {'offset': offset,
                       'key': key,
                       'value': value,
                       'srcid': srcid}
        format_list = [offset, key, value, srcid]
        format_tuple = (offset, key, value, srcid)

        t_dict = gr.python_to_tag(format_dict)
        t_list = gr.python_to_tag(format_list)
        t_tuple = gr.python_to_tag(format_tuple)

        self.assertTrue(pmt.equal(t_dict.key, key))
        self.assertTrue(pmt.equal(t_dict.value, value))
        self.assertEqual(t_dict.offset, offset)

        self.assertTrue(pmt.equal(t_list.key, key))
        self.assertTrue(pmt.equal(t_list.value, value))
        self.assertEqual(t_list.offset, offset)

        self.assertTrue(pmt.equal(t_tuple.key, key))
        self.assertTrue(pmt.equal(t_tuple.value, value))
        self.assertEqual(t_tuple.offset, offset)
Exemple #6
0
 def test19(self):
     max_key = pmt.intern("MAX")
     _max = pmt.from_long(self.MAXINT32)
     min_key = pmt.intern("MIN")
     _min = pmt.from_long(self.MININT32)
     d = pmt.make_dict()
     d = pmt.dict_add(d, max_key, _max)
     d = pmt.dict_add(d, min_key, _min)
     s = pmt.serialize_str(d)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(d, deser))
     p_dict = pmt.to_python(deser)
     self.assertEqual(self.MAXINT32, p_dict["MAX"])
     self.assertEqual(self.MININT32, p_dict["MIN"])
    def test_001_null_dict(self):
        in_data = [0, 0, 0, 0]
        in_meta = pmt.make_dict()
        expected_meta = pmt.dict_add(in_meta, pmt.intern('num'),
                                     pmt.from_long(4))
        in_pdu = pmt.cons(in_meta, pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(expected_meta,
                                pmt.init_u8vector(len(in_data), in_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(pmt.cons(pmt.from_long(0), pmt.PMT_T))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
    def test_000(self):
        num_msgs = 10
        msg_interval = 1000
        msg_list = []
        for i in range(num_msgs):
            msg_list.append(pmt.from_long(i))

        # Create vector source with dummy data to trigger messages
        src_data = []
        for i in range(num_msgs * msg_interval):
            src_data.append(float(i))
        src = blocks.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, msg_interval)
        msg_cons = message_consumer()

        # Connect vector source to message gen
        self.tb.connect(src, msg_gen)

        # Connect message generator to message consumer
        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        # Verify that the messgae port query functions work
        self.assertEqual(
            pmt.to_python(msg_gen.message_ports_out())[0], 'out_port')
        self.assertEqual(
            'in_port' in pmt.to_python(msg_cons.message_ports_in()), True)

        # Run to verify message passing
        self.tb.start()

        # Wait for all messages to be sent
        while msg_gen.msg_ctr < num_msgs:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # Verify that the message consumer got all the messages
        self.assertEqual(num_msgs, len(msg_cons.msg_list))
        for i in range(num_msgs):
            self.assertTrue(pmt.equal(msg_list[i], msg_cons.msg_list[i]))
    def test_001_combo(self):

        self.dut = pdu_utils.pdu_preamble([0, 1, 0, 1], [], 2, 3, True)
        self.connectUp()

        input_data = pmt.init_u8vector(8, [1, 0, 1, 1, 0, 0, 1, 0])
        input_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("KEY"),
                                  pmt.intern("VALUE"))
        input_pdu = pmt.cons(input_dict, input_data)

        expected_data = [
            0, 0, 0, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1,
            -1, -1, -1, 1, 1, -1, -1, 0, 0, 0
        ]
        expected_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("KEY"),
                                     pmt.intern("VALUE"))
        expected_pdu = pmt.cons(
            expected_dict, pmt.init_f32vector(len(expected_data),
                                              expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(input_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

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

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

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Exemple #10
0
    def test_001(self):
        '''
        Input data perfectly matches params to pdu_fine_time_measure
        '''
        self.dut = pdu_utils.pdu_fine_time_measure(0.005, 0.005, 10, 15)
        self.connectUp()

        i_data = [0.1 + 0j] * 5 + [1.0 + 0j] * 990 + [0.1 + 0j] * 5
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("start_time"),
                              pmt.from_double(1.0))
        i_meta = pmt.dict_add(i_meta, pmt.intern("sample_rate"),
                              pmt.from_float(1000.0))
        i_meta = pmt.dict_add(i_meta, pmt.intern("duration"),
                              pmt.from_float(1000.0))
        in_pdu = pmt.cons(i_meta, pmt.init_c32vector(len(i_data), i_data))

        e_data = [1.0 + 0j] * 990 + [0.1 + 0j] * 5
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_float(1000.0))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(1.005))
        e_meta = pmt.dict_add(e_meta, pmt.intern("duration"),
                              pmt.from_float(999.995))
        e_pdu = pmt.cons(e_meta, pmt.init_c32vector(len(e_data), e_data))

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

        #print("test_001:")
        #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

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Exemple #11
0
    def test_006_max_pdu_size(self):
        # two SOB tags exactly max_pdu_size samples apart, with an SOB-to-EOB length that is not divisible by the alignment size
        self.tb = gr.top_block()
        start_time = 0.1
        max_size = 100
        sob_tag = gr.tag_utils.python_to_tag(
            (10, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))
        eob_tag = gr.tag_utils.python_to_tag(
            (91, pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src")))
        sob_tag3 = gr.tag_utils.python_to_tag(
            (11 + max_size, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))
        vs = blocks.vector_source_s(range(1350), False, 1,
                                    [sob_tag, eob_tag, sob_tag3])
        t2p = pdu.tags_to_pdu_s(pmt.intern('SOB'), pmt.intern('EOB'), 1024,
                                512000, ([]), False, 0, start_time)
        t2p.set_eob_parameters(10, 0)
        t2p.set_max_pdu_size(max_size)

        dbg = blocks.message_debug()
        self.tb.connect(vs, t2p)
        self.tb.msg_connect((t2p, 'pdus'), (dbg, 'store'))
        expected_vec = pmt.init_s16vector((9 * 10),
                                          list(range(10, 91)) + [0] * 9)
        expected_time = start_time + (10 / 512000.0)

        self.tb.run()

        # assertions for the first PDU only, second PDU will exist
        self.assertEqual(dbg.num_messages(), 2)
        #print "got ", dbg.get_message(0)
        #print "expected", expected_vec
        #print "len is {}".format(len(pmt.to_python(pmt.cdr(dbg.get_message(0)))))
        self.assertTrue(pmt.equal(pmt.cdr(dbg.get_message(0)), expected_vec))
        time_tuple1 = pmt.dict_ref(pmt.car(dbg.get_message(0)),
                                   pmt.intern("rx_time"), pmt.PMT_NIL)
        self.assertAlmostEqual(
            pmt.to_uint64(pmt.tuple_ref(time_tuple1, 0)) +
            pmt.to_double(pmt.tuple_ref(time_tuple1, 1)), expected_time)

        self.tb = None
Exemple #12
0
    def test_005_u8(self):
        '''
        u8 input data, no decimation, even number of taps
        '''
        self.dut = pdu_utils.pdu_fir_filter(1, [1] * 4)
        self.connectUp()

        i_data = [
            1,
        ] * 10
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(100.0))
        i_meta = pmt.dict_add(i_meta, pmt.intern("start_time"),
                              pmt.from_double(9.9))
        in_pdu = pmt.cons(i_meta, pmt.init_u8vector(len(i_data), i_data))

        e_data = [2, 3] + [
            4,
        ] * 7 + [3, 2]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(100.0))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(9.895))
        e_pdu = pmt.cons(e_meta, pmt.init_u8vector(len(e_data), e_data))

        self.tb.start()
        time.sleep(.01)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        #print("test_005:")
        #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

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
    def test_000(self):
        num_msgs = 10
        msg_interval = 1000
        msg_list = []
        for i in range(num_msgs):
            msg_list.append(pmt.from_long(i))

        # Create vector source with dummy data to trigger messages
        src_data = []
        for i in range(num_msgs*msg_interval):
            src_data.append(float(i))
        src = blocks.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, msg_interval)
        msg_cons = message_consumer()
        
        # Connect vector source to message gen
        self.tb.connect(src, msg_gen)
        
        # Connect message generator to message consumer
        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        # Verify that the messgae port query functions work
        self.assertEqual(pmt.symbol_to_string(pmt.vector_ref(
                    msg_gen.message_ports_out(), 0)), 'out_port')
        self.assertEqual(pmt.symbol_to_string(pmt.vector_ref(
                    msg_cons.message_ports_in(), 0)), 'in_port')
        
        # Run to verify message passing
        self.tb.start()

        # Wait for all messages to be sent
        while msg_gen.msg_ctr < num_msgs:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()               
        
        # Verify that the message consumer got all the messages
        self.assertEqual(num_msgs, len(msg_cons.msg_list))
        for i in range(num_msgs):
            self.assertTrue(pmt.equal(msg_list[i], msg_cons.msg_list[i]))
    def test_001_pack_MSB(self):
        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
        ]
        expected_data = [0, 255, 85]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
    def test_004_match_offsetb(self):

        self.dut = pdu_utils.pdu_align('01010101', 0, -4, pdu_utils.ALIGN_DROP)
        self.connectUp()

        in_data = [0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        expected_data = [0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

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

        self.assertEqual(1, self.debug.num_messages())
        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
    def test_bit_flip(self):
        self.dut = pdu_utils.pdu_binary_tools(0)
        self.connectUp()

        i_vec = pmt.init_u8vector(6, [1, 0, 0, 1, 0, 1])
        e_vec = pmt.init_u8vector(6, [0, 1, 1, 0, 1, 0])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

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

        print("test bit_flip:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0)))))
        print(self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu)))
Exemple #17
0
    def test_004_c32(self):
        '''
        complex input data, no decimation, odd number of taps
        '''
        self.dut = pdu_utils.pdu_fir_filter(1, [.2] * 5)
        self.connectUp()

        i_data = [
            1,
        ] * 10
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(1000.0))
        in_pdu = pmt.cons(i_meta, pmt.init_c32vector(len(i_data), i_data))

        e_data = [
            .6,
            .8,
        ] + [
            1,
        ] * 6 + [.8, .6]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(1000.0))
        e_pdu = pmt.cons(e_meta, pmt.init_c32vector(len(e_data), e_data))

        self.tb.start()
        time.sleep(.01)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        #print("test_004:")
        #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

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Exemple #18
0
    def test_002_short_pass(self):

        self.dut = pdu_utils.pdu_length_filter(8, True)
        self.connectUp()

        in_data = [0, 0, 0, 0, 0, 0]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_data = [0, 0, 0, 0, 0, 0]
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

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

        self.assertEqual(1, self.debug.num_messages())
        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
 def test_007_match_errors2 (self):
     '''
     Ensure specification of the number of errors in an alignment sequence is
     properly checked
     '''
     self.dut = pdu_utils.pdu_align('10101010', 2, 0, pdu_utils.ALIGN_EMPTY)
     self.connectUp()
     
     in_data = [1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1]
     expected_data = [0, 1, 0, 1, 0, 1, 0, 1]
     
     in_pdu = pmt.cons(pmt.make_dict(), pmt.init_u8vector(len(in_data), in_data))
     expected_pdu = pmt.cons(pmt.make_dict(), pmt.init_u8vector(len(expected_data), expected_data))
     
     self.tb.start()
     time.sleep(.001)
     self.emitter.emit(in_pdu)
     time.sleep(.1)
     self.tb.stop()
     self.tb.wait()
     
     self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Exemple #20
0
    def test_006_u8(self):
        '''
        u8 input data, complicated input, decimation, and filtering
        '''
        self.dut = pdu_utils.pdu_fir_filter(3, [1, 2, 4, 3] * 4)
        self.connectUp()

        i_data = [4, 4, 4, 0, 0, 0] * 10
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(3.0))
        i_meta = pmt.dict_add(i_meta, pmt.intern("start_time"),
                              pmt.from_double(33))
        in_pdu = pmt.cons(i_meta, pmt.init_u8vector(len(i_data), i_data))

        e_data = [
            48, 60, 72, 88, 72, 88, 72, 88, 72, 88, 72, 88, 72, 88, 72, 88, 72,
            88, 60, 56
        ]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(1.0))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(32.5))
        e_pdu = pmt.cons(e_meta, pmt.init_u8vector(len(e_data), e_data))

        self.tb.start()
        time.sleep(.01)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        #print("test_005:")
        #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

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
    def test_002_u8_scale_offset(self):
        self.add.set_scale(4)
        self.add.set_offset(3)

        in_data = range(8)
        expected_data = range(3, 32, 4)
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.cons(pmt.intern("NONPDU"), pmt.intern("PAIR")))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Exemple #22
0
    def test_001_simple (self):
        self.tb = gr.top_block ()
        start_time = 0.1
        sob_tag = gr.tag_utils.python_to_tag((34, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))
        eob_tag = gr.tag_utils.python_to_tag((34+(8*31), pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src")))
        vs = blocks.vector_source_s(range(350), False, 1, [sob_tag, eob_tag])
        t2p = pdu_utils.tags_to_pdu_s(pmt.intern('SOB'), pmt.intern('EOB'), 1024, 512000, ([]), False, 0, start_time)
        t2p.set_eob_parameters(8, 0)
        dbg = blocks.message_debug()
        self.tb.connect(vs, t2p)
        self.tb.msg_connect((t2p, 'pdu_out'), (dbg, 'store'))
        expected_vec = pmt.init_s16vector((8*31), range(34,34+(8*31)))
        expected_time = start_time + (34 / 512000.0)

        self.tb.run ()

        self.assertEqual(dbg.num_messages(), 1)
        self.assertTrue(pmt.equal(pmt.cdr(dbg.get_message(0)), expected_vec))
        time_tuple1 = pmt.dict_ref(pmt.car(dbg.get_message(0)), pmt.intern("burst_time"), pmt.PMT_NIL)
        self.assertAlmostEqual(pmt.to_uint64(pmt.tuple_ref(time_tuple1,0)) + pmt.to_double(pmt.tuple_ref(time_tuple1,1)), expected_time)

        self.tb = None
    def test_coerce (self):
        self.emitter = pdu_utils.message_emitter()
        self.cf = fhss_utils.cf_estimate(fhss_utils.COERCE, [x*1e6 for x in range(900,930)])
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.cf, 'in'))
        self.tb.msg_connect((self.cf, 'out'), (self.debug, 'store'))
        
        # original data
        in_data = np.exp(1j*np.array(np.linspace(0,10*np.pi*2, 20)))
        i_vec = pmt.init_c32vector(len(in_data), in_data)

        out_data = [(1+0j), (-0.9863691-0.16454819j), (0.9458478+0.32461047j), (-0.8795409-0.47582325j), (0.7892561+0.61406416j), (-0.67745465-0.7355646j), (0.54718447+0.8370121j), (-0.40199703-0.915641j), (0.24585037+0.9693079j), (-0.083001345-0.9965495j), (-0.08211045+0.99662334j), (0.24498378-0.96952736j), (-0.4011784+0.9160001j), (0.5464361-0.83750105j), (-0.6767969+0.73617005j), (0.78870696-0.6147696j), (-0.87911534+0.47660938j), (0.94555736-0.3254559j), (-0.9862217+0.16542989j), (0.9999997-0.00089395075j)]
        e_vec = pmt.init_c32vector(len(out_data), out_data)

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, pmt.intern("sample_rate"), pmt.from_float(1e3))
        meta = pmt.dict_add(meta, pmt.intern("center_frequency"), pmt.from_float(910.6e6))
        in_pdu = pmt.cons(meta, i_vec)
        e_pdu = pmt.cons(meta, e_vec)

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

        # parse output
        #print "got ", list(pmt.to_python(pmt.cdr(self.debug.get_message(0))))
        #print "got ", self.debug.get_message(0)
        rcv = self.debug.get_message(0)
        rcv_meta = pmt.car(rcv)
        rcv_data = pmt.cdr(rcv)
        rcv_cf = pmt.dict_ref(rcv_meta, pmt.intern("center_frequency"), pmt.PMT_NIL)

        # asserts
        self.assertComplexTuplesAlmostEqual(tuple(pmt.c32vector_elements(rcv_data)), tuple(out_data), 2)
        self.assertTrue(pmt.equal(rcv_cf, pmt.from_float(911e6)))
Exemple #24
0
    def test_002_1_byte_sync(self):
        orig_array = np.array([1, 0, 1, 0, 1, 0, 1], dtype=np.uint8)
        metadata = {'a': 1, 'b': 2}
        expected_array = np.array(
            [0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1], dtype=np.uint8)
        in_pmt = pmt.cons(pmt.to_pmt(metadata), pmt.to_pmt(orig_array))
        expected_pmt = pmt.cons(pmt.to_pmt(metadata),
                                pmt.to_pmt(expected_array))

        appender = add_sync_pdu(0x23, 1)
        snk = blocks.message_debug()

        self.tb.msg_connect((appender, 'out'), (snk, 'store'))

        self.tb.start()
        appender.to_basic_block()._post(pmt.intern('in'), in_pmt)
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        # check data
        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.equal(snk.get_message(0), expected_pmt))
Exemple #25
0
    def test_003_double_msg(self):
        in_data1 = [0, 0, 0, 0, 0, 0, 0, 0]
        in_data2 = [1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1]
        in_data = in_data1 + in_data1 + in_data2
        tag_time = pmt.make_tuple(pmt.from_uint64(11),
                                  pmt.from_double(0.123456))
        in_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("tx_time"),
                               tag_time)
        in_pdu1 = pmt.cons(in_dict, pmt.init_c32vector(len(in_data1),
                                                       in_data1))
        in_pdu2 = pmt.cons(pmt.make_dict(),
                           pmt.init_c32vector(len(in_data2), in_data2))
        e_tag_0 = gr.tag_utils.python_to_tag(
            (len(in_data1), pmt.intern("tx_sob"), pmt.PMT_T, pmt.PMT_NIL))
        e_tag_1 = gr.tag_utils.python_to_tag(
            (len(in_data1), pmt.intern("tx_time"), tag_time, pmt.PMT_NIL))
        e_tag_2 = gr.tag_utils.python_to_tag(
            (len(in_data) - 1, pmt.intern("tx_eob"), pmt.PMT_T, pmt.PMT_NIL))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu1)
        time.sleep(.005)
        self.emitter.emit(in_pdu1)
        self.emitter.emit(in_pdu2)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        tags = self.vs.tags()
        for tag in tags:
            print tag.offset, tag.key, tag.value
        self.assertEqual(len(tags), 6)
        self.assertEqual(tags[3].offset, e_tag_0.offset)
        self.assertTrue(pmt.equal(tags[3].key, e_tag_0.key))
        self.assertTrue(pmt.equal(tags[3].value, e_tag_0.value))
        self.assertEqual(tags[4].offset, e_tag_1.offset)
        self.assertTrue(pmt.equal(tags[4].key, e_tag_1.key))
        self.assertTrue(pmt.equal(tags[4].value, e_tag_1.value))
        self.assertEqual(tags[5].offset, e_tag_2.offset)
        self.assertTrue(pmt.equal(tags[5].key, e_tag_2.key))
        self.assertTrue(pmt.equal(tags[5].value, e_tag_2.value))
        self.assertTrue((in_data == numpy.real(self.vs.data())).all())
Exemple #26
0
    def test_dict(self):
        cs = starcoder.command_source()
        snk = blocks.message_debug()
        self.tb.msg_connect((cs, 'out'), (snk, 'store'))

        msg = starcoder_pb2.BlockMessage()
        pl = msg.dict_value.entry.add()
        pl.key.symbol_value = 'key'
        pl.value.double_value = -2.3

        expected = pmt.make_dict()
        expected = pmt.dict_add(expected, pmt.intern('key'),
                                pmt.from_double(-2.3))

        self.tb.start()
        cs.push(msg.SerializeToString())
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.is_dict(snk.get_message(0)))
        self.assertTrue(pmt.equal(snk.get_message(0), expected))
    def test_manchester_decode_nrz(self):
        self.dut = pdu_utils.pdu_binary_tools(6) #MANCHESTER_DECODE
        self.connectUp()

        i_vec = pmt.init_f32vector(16, [1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1])
        e_vec = pmt.init_f32vector(8, [1, 1, -1, -1, 1, -1, 1, -1])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

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

        print("test manchester decode nrz:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.f32vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))))

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Exemple #28
0
    def test_005_two_sobs_misaligned(self):
        # Two SOB tags and the SOB-to-EOB length is not aligned
        self.tb = gr.top_block()
        start_time = 0.1
        sob_tag = gr.tag_utils.python_to_tag(
            (34, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))
        sob_tag2 = gr.tag_utils.python_to_tag(
            (35, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))
        eob_tag = gr.tag_utils.python_to_tag(
            (34 + (8 * 31), pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src")))
        vs = blocks.vector_source_s(range(1350), False, 1,
                                    [sob_tag, sob_tag2, eob_tag])
        #vs = blocks.vector_source_s(range(350), False, 1, [sob_tag, eob_tag])
        t2p = pdu_utils.tags_to_pdu_s(pmt.intern('SOB'), pmt.intern('EOB'),
                                      1024, 512000, ([]), False, 0, start_time)
        t2p.set_eob_parameters(8, 0)
        dbg = blocks.message_debug()
        self.tb.connect(vs, t2p)
        self.tb.msg_connect((t2p, 'pdu_out'), (dbg, 'store'))
        expected_vec = pmt.init_s16vector((8 * 31),
                                          list(range(35, 34 + (8 * 31))) + [0])
        expected_time = start_time + (35 / 512000.0)

        self.tb.run()

        self.assertEqual(dbg.num_messages(), 1)
        #print "got ", dbg.get_message(0)
        #print "expected", expected_vec
        #print "len is {}".format(len(pmt.to_python(pmt.cdr(dbg.get_message(0)))))
        self.assertTrue(pmt.equal(pmt.cdr(dbg.get_message(0)), expected_vec))
        time_tuple1 = pmt.dict_ref(pmt.car(dbg.get_message(0)),
                                   pmt.intern("burst_time"), pmt.PMT_NIL)
        self.assertAlmostEqual(
            pmt.to_uint64(pmt.tuple_ref(time_tuple1, 0)) +
            pmt.to_double(pmt.tuple_ref(time_tuple1, 1)), expected_time)

        self.tb = None
Exemple #29
0
    def test_001_no_change(self):
        orig_array = np.array([1.1, 2.2, 3.3, 4.4, 5.5])
        metadata = {'a': 1, 'b': 2}
        in_pmt = pmt.cons(pmt.to_pmt(metadata), pmt.to_pmt(orig_array))
        expected_pmt = pmt.cons(pmt.to_pmt(metadata), pmt.to_pmt(orig_array))

        # We just need something connected to the trimmer block for
        # the flowgraph to compile, but we'll post messages to it directly
        src = blocks.message_strobe(pmt.PMT_NIL, 9999999)
        trimmer = pdu_trim_uvector(0, 0)
        snk = blocks.message_debug()

        self.tb.msg_connect((src, 'strobe'), (trimmer, 'in'))
        self.tb.msg_connect((trimmer, 'out'), (snk, 'store'))

        self.tb.start()
        trimmer.to_basic_block()._post(pmt.intern('in'), in_pmt)
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        # check data
        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.equal(snk.get_message(0), expected_pmt))
Exemple #30
0
    def test_tuple(self):
        cs = starcoder.command_source()
        snk = blocks.message_debug()
        self.tb.msg_connect((cs, 'out'), (snk, 'store'))

        msg = starcoder_pb2.BlockMessage()
        v = msg.list_value.value.add()
        v.symbol_value = "testtransmission"
        v = msg.list_value.value.add()
        v.double_value = 23.2
        msg.list_value.type = starcoder_pb2.List.TUPLE

        expected = pmt.make_tuple(pmt.intern("testtransmission"),
                                  pmt.from_double(23.2))

        self.tb.start()
        cs.push(msg.SerializeToString())
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.is_tuple(snk.get_message(0)))
        self.assertTrue(pmt.equal(snk.get_message(0), expected))
    def XX_test_003_time_tag(self):
        fs = 32000

        # tune message at exactly 1.0 second
        tune = pmt.dict_add(pmt.make_dict(), pmt.intern('freq'),
                            pmt.from_double(100))
        tune = pmt.dict_add(tune, pmt.intern('time'),
                            pmt.cons(pmt.from_uint64(1), pmt.from_double(0)))

        # blocks
        src = blocks.null_source(gr.sizeof_gr_complex * 1)
        throttle = blocks.throttle(gr.sizeof_gr_complex * 1, fs, True)
        retuner = timing_utils.timed_tag_retuner(fs, pmt.intern("freq"), 0,
                                                 0.0)
        debug = sandia_utils.sandia_tag_debug(gr.sizeof_gr_complex * 1, '', "",
                                              True)
        emitter = pdu_utils.message_emitter()
        debug.set_display(True)
        self.tb.connect(src, throttle)
        self.tb.connect(throttle, retuner)
        self.tb.connect(retuner, debug)
        self.tb.msg_connect((emitter, 'msg'), (retuner, 'command'))

        self.tb.start()
        time.sleep(.1)
        emitter.emit(tune)
        time.sleep(1.5)
        self.tb.stop()

        # assert
        self.assertEqual(debug.num_tags(), 1)
        tag = debug.get_tag(0)
        self.assertTrue(pmt.equal(tag.key, pmt.intern('set_freq')))
        freq = pmt.to_double(tag.value)
        self.assertAlmostEqual(-100, freq)
        self.assertEqual(tag.offset, 32000)
Exemple #32
0
    def test_float(self):
        self.down = pdu_utils.pdu_downsample(3, 0)
        self.connectUp()

        i_vec = pmt.init_f32vector(9, [0, 1, 2, 3.3, 4, 5, 6, 7, 8])
        e_vec = pmt.init_f32vector(3, [0, 3.3, 6])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

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

        print("test float:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.f32vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Exemple #33
0
    def test_007_max_pdu_size_SOBs(self):
        # two SOB tags exactly max_pdu_size samples apart
        self.tb = gr.top_block()
        start_time = 0.1
        max_size = 100
        sob_tag = gr.tag_utils.python_to_tag(
            (10, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))
        sob_tag3 = gr.tag_utils.python_to_tag(
            (10 + max_size, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src")))

        vs = blocks.vector_source_s(range(1350), False, 1, [sob_tag, sob_tag3])
        t2p = pdu_utils.tags_to_pdu_s(pmt.intern('SOB'), pmt.intern('EOB'),
                                      1024, 512000, ([]), False, 0, start_time)
        t2p.set_eob_parameters(10, 0)
        t2p.set_max_pdu_size(max_size)

        dbg = blocks.message_debug()
        self.tb.connect(vs, t2p)
        self.tb.msg_connect((t2p, 'pdu_out'), (dbg, 'store'))
        expected_vec = pmt.init_s16vector((max_size), range(10, 10 + max_size))
        expected_time = start_time + (10 / 512000.0)

        self.tb.run()

        # assertions for the first PDU only, second PDU will exist
        self.assertEqual(dbg.num_messages(), 2)
        #print "got ", dbg.get_message(0)
        #print "expected", expected_vec
        self.assertTrue(pmt.equal(pmt.cdr(dbg.get_message(0)), expected_vec))
        time_tuple1 = pmt.dict_ref(pmt.car(dbg.get_message(0)),
                                   pmt.intern("burst_time"), pmt.PMT_NIL)
        self.assertAlmostEqual(
            pmt.to_uint64(pmt.tuple_ref(time_tuple1, 0)) +
            pmt.to_double(pmt.tuple_ref(time_tuple1, 1)), expected_time)

        self.tb = None
Exemple #34
0
    def test_002_pass_empty(self):
        split = pdu.pdu_split(True)
        d1 = blocks.message_debug()
        d2 = blocks.message_debug()

        self.tb.msg_connect((split, 'dict'), (d1, 'store'))
        self.tb.msg_connect((split, 'vec'), (d2, 'store'))

        in_meta1 = pmt.dict_add(pmt.make_dict(), pmt.intern('num'),
                                pmt.from_long(4))
        in_meta2 = pmt.dict_add(pmt.make_dict(), pmt.intern('n'),
                                pmt.from_long(99))
        in_pdu = pmt.cons(in_meta1, pmt.init_u8vector(6, range(6)))

        self.tb.start()
        split.to_basic_block()._post(pmt.intern("pdus"),
                                     pmt.intern("MALFORMED PDU"))
        split.to_basic_block()._post(
            pmt.intern("pdus"),
            pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(2, range(2))))
        split.to_basic_block()._post(
            pmt.intern("pdus"), pmt.cons(in_meta2, pmt.init_u8vector(0, [])))
        split.to_basic_block()._post(pmt.intern("pdus"), in_pdu)
        split.to_basic_block()._post(
            pmt.intern("system"), pmt.cons(pmt.intern("done"),
                                           pmt.from_long(1)))
        self.waitFor(lambda: d1.num_messages() == 3,
                     timeout=1.0,
                     poll_interval=0.01)
        self.waitFor(lambda: d2.num_messages() == 3,
                     timeout=1.0,
                     poll_interval=0.01)
        self.tb.wait()

        self.assertTrue(pmt.equal(d1.get_message(0), pmt.PMT_NIL))
        self.assertTrue(pmt.equal(d1.get_message(1), in_meta2))
        self.assertTrue(pmt.equal(d1.get_message(2), in_meta1))
        self.assertTrue(
            pmt.equal(d2.get_message(0), pmt.init_u8vector(2, range(2))))
        self.assertTrue(pmt.equal(d2.get_message(1), pmt.init_u8vector(0, [])))
        self.assertTrue(
            pmt.equal(d2.get_message(2), pmt.init_u8vector(6, range(6))))
Exemple #35
0
    def test_002_timed(self):
        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
        ]
        tag_time = pmt.make_tuple(pmt.from_uint64(11),
                                  pmt.from_double(0.123456))
        in_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("tx_time"),
                               tag_time)
        in_pdu = pmt.cons(in_dict, pmt.init_c32vector(len(in_data), in_data))
        e_tag_0 = gr.tag_utils.python_to_tag(
            (0, pmt.intern("tx_sob"), pmt.PMT_T, pmt.PMT_NIL))
        e_tag_1 = gr.tag_utils.python_to_tag(
            (0, pmt.intern("tx_time"), tag_time, pmt.PMT_NIL))
        e_tag_2 = gr.tag_utils.python_to_tag(
            (len(in_data) - 1, pmt.intern("tx_eob"), pmt.PMT_T, pmt.PMT_NIL))

        self.tb.start()
        self.p2s.to_basic_block()._post(pmt.intern("pdus"),
                                        pmt.intern("MALFORMED PDU"))
        self.p2s.to_basic_block()._post(pmt.intern("pdus"), in_pdu)
        self.waitFor(lambda: len(self.vs.tags()) == 3,
                     timeout=1.0,
                     poll_interval=0.01)
        self.tb.stop()
        self.tb.wait()

        tags = self.vs.tags()
        self.assertEqual(len(tags), 3)
        self.assertEqual(tags[0].offset, e_tag_0.offset)
        self.assertTrue(pmt.equal(tags[0].key, e_tag_0.key))
        self.assertTrue(pmt.equal(tags[0].value, e_tag_0.value))
        self.assertEqual(tags[1].offset, e_tag_1.offset)
        self.assertTrue(pmt.equal(tags[1].key, e_tag_1.key))
        self.assertTrue(pmt.equal(tags[1].value, e_tag_1.value))
        self.assertEqual(tags[2].offset, e_tag_2.offset)
        self.assertTrue(pmt.equal(tags[2].key, e_tag_2.key))
        self.assertTrue(pmt.equal(tags[2].value, e_tag_2.value))
        self.assertTrue((in_data == np.real(self.vs.data())).all())
Exemple #36
0
    def test_002_timed(self):
        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
        ]
        tag_time = pmt.make_tuple(pmt.from_uint64(11),
                                  pmt.from_double(0.123456))
        in_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("tx_time"),
                               tag_time)
        in_pdu = pmt.cons(in_dict, pmt.init_c32vector(len(in_data), in_data))
        e_tag_0 = gr.tag_utils.python_to_tag(
            (0, pmt.intern("tx_sob"), pmt.PMT_T, pmt.PMT_NIL))
        e_tag_1 = gr.tag_utils.python_to_tag(
            (0, pmt.intern("tx_time"), tag_time, pmt.PMT_NIL))
        e_tag_2 = gr.tag_utils.python_to_tag(
            (len(in_data) - 1, pmt.intern("tx_eob"), pmt.PMT_T, pmt.PMT_NIL))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        tags = self.vs.tags()
        self.assertEqual(len(tags), 3)
        self.assertEqual(tags[0].offset, e_tag_0.offset)
        self.assertTrue(pmt.equal(tags[0].key, e_tag_0.key))
        self.assertTrue(pmt.equal(tags[0].value, e_tag_0.value))
        self.assertEqual(tags[1].offset, e_tag_1.offset)
        self.assertTrue(pmt.equal(tags[1].key, e_tag_1.key))
        self.assertTrue(pmt.equal(tags[1].value, e_tag_1.value))
        self.assertEqual(tags[2].offset, e_tag_2.offset)
        self.assertTrue(pmt.equal(tags[2].key, e_tag_2.key))
        self.assertTrue(pmt.equal(tags[2].value, e_tag_2.value))
        self.assertTrue((in_data == numpy.real(self.vs.data())).all())
Exemple #37
0
    def test_002_pass_empty(self):
        emitter = pdu_utils.message_emitter()
        split = pdu_utils.pdu_split(True)
        d1 = blocks.message_debug()
        d2 = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (split, 'pdu_in'))
        self.tb.msg_connect((split, 'dict'), (d1, 'store'))
        self.tb.msg_connect((split, 'data'), (d2, 'store'))

        in_meta1 = pmt.dict_add(pmt.make_dict(), pmt.intern('num'),
                                pmt.from_long(4))
        in_meta2 = pmt.dict_add(pmt.make_dict(), pmt.intern('n'),
                                pmt.from_long(99))
        in_pdu = pmt.cons(in_meta1, pmt.init_u8vector(6, range(6)))

        self.tb.start()
        time.sleep(.001)
        emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        emitter.emit(pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(2, range(2))))
        time.sleep(.001)
        emitter.emit(pmt.cons(in_meta2, pmt.init_u8vector(0, [])))
        time.sleep(.001)
        emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(d1.get_message(0), pmt.PMT_NIL))
        self.assertTrue(pmt.equal(d1.get_message(1), in_meta2))
        self.assertTrue(pmt.equal(d1.get_message(2), in_meta1))
        self.assertTrue(
            pmt.equal(d2.get_message(0), pmt.init_u8vector(2, range(2))))
        self.assertTrue(pmt.equal(d2.get_message(1), pmt.init_u8vector(0, [])))
        self.assertTrue(
            pmt.equal(d2.get_message(2), pmt.init_u8vector(6, range(6))))
Exemple #38
0
 def test10(self):
     v = pmt.init_s32vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
def compare_tags(a, b):
    return (
        a.offset == b.offset and pmt.equal(a.key, b.key) and pmt.equal(a.value, b.value) and pmt.equal(a.srcid, b.srcid)
    )
Exemple #40
0
def compare_tags(a, b):
    return a.offset == b.offset and pmt.equal(a.key, b.key) and \
           pmt.equal(a.value, b.value)
Exemple #41
0
 def test11(self):
     v = pmt.init_c32vector(3, [11 + -101j, -22 + 202j, 33 + -303j])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
     self.assertEqual(pmt.uniform_vector_itemsize(v), 8)
Exemple #42
0
 def test03(self):
     v = pmt.init_f32vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
     self.assertEqual(pmt.uniform_vector_itemsize(v), 4)
Exemple #43
0
 def test16(self):
     const = self.MININT32
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
Exemple #44
0
 def test07(self):
     v = pmt.init_u16vector(3, [11, 22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
Exemple #45
0
 def test12(self):
     v = pmt.init_c64vector(3, [11 + -101j, -22 + 202j, 33 + -303j])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))