Пример #1
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.emitter2 = pdu_utils.message_emitter()
     self.pre = pdu_utils.pdu_preamble([], [], 8, 20, True)
     self.gmsk = pdu_utils.pdu_gmsk_fc(0.5, firdes.gaussian(1, 4, 0.35, 9))
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.pre, 'pdu_in'))
     self.tb.msg_connect((self.emitter2, 'msg'), (self.gmsk, 'pdu_in'))
     self.tb.msg_connect((self.pre, 'pdu_out'), (self.gmsk, 'pdu_in'))
     self.tb.msg_connect((self.gmsk, 'pdu_out'), (self.debug, 'store'))
Пример #2
0
    def test_from_pam(self):
        self.emitter = pdu_utils.message_emitter()
        #self.flip = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.FROM_PAM)
        self.flip = pdu_utils.pdu_binary_tools(2)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.flip, 'pdu_in'))
        self.tb.msg_connect((self.flip, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_f32vector(6, [1, -1, -1, 1, -1, 1])
        e_vec = pmt.init_u8vector(6, [1, 0, 0, 1, 0, 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 from_pam:"
        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))
Пример #3
0
    def test_endian(self):
        self.emitter = pdu_utils.message_emitter()
        #self.endi = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.ENDIAN_SWAP8)
        self.endi = pdu_utils.pdu_binary_tools(4)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.endi, 'pdu_in'))
        self.tb.msg_connect((self.endi, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_u8vector(
            16, [1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0])
        e_vec = pmt.init_u8vector(
            16, [1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 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 endian_swap8:"
        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))
Пример #4
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.combiner = pdu_utils.pdu_burst_combiner()
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.combiner, 'pdu_in'))
     self.tb.msg_connect((self.combiner, 'pdu_out'), (self.debug, 'store'))
Пример #5
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.upsample = pdu_utils.upsample(4, False)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.upsample, 'pdu_in'))
     self.tb.msg_connect((self.upsample, 'pdu_out'), (self.debug, 'store'))
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.add = pdu_utils.pdu_add_noise(0, 0, 1)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.add, 'pdu_in'))
     self.tb.msg_connect((self.add, 'pdu_out'), (self.debug, 'store'))
Пример #7
0
    def test_001_basic_nrz_test(self):
        emitter = pdu_utils.message_emitter()
        preamble = pdu_utils.pdu_preamble([0, 1, 0, 1], [], 2, 3, True)
        debug = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (preamble, 'pdu_in'))
        self.tb.msg_connect((preamble, 'pdu_out'), (debug, 'store'))

        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"))
        expected_data = pmt.init_f32vector((8 + 4 + 0) * 2 + 3 * 2, [
            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
        ])
        self.tb.start()
        time.sleep(.001)
        emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        emitter.emit(pmt.cons(input_dict, input_data))
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()
        output_data = pmt.cdr(debug.get_message(0))

        self.assertEquals(1, debug.num_messages())
        self.assertTrue((pmt.f32vector_elements(expected_data) ==
                         pmt.f32vector_elements(output_data)))
Пример #8
0
    def test_001_split(self):
        emitter = pdu_utils.message_emitter()
        split = pdu_utils.pdu_split()
        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), in_meta2))
        self.assertTrue(pmt.equal(d1.get_message(1), 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(6, range(6))))
Пример #9
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.set = pdu_utils.pdu_set_m(pmt.intern('num'), pmt.from_long(4))
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.set, 'pdu_in'))
     self.tb.msg_connect((self.set, 'pdu_out'), (self.debug, 'store'))
Пример #10
0
    def test_simple(self):
        self.emitter = pdu_utils.message_emitter()
        self.ctm2 = pdu_utils.pdu_complex_to_mag2()
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.ctm2, 'cpdus'))
        self.tb.msg_connect((self.ctm2, 'fpdus'), (self.debug, 'store'))

        # gnuradio uses single-precision floats by default
        i_vec = pmt.init_c32vector(3, [3 + 4j, 1 + 0j, 0 + 1j])
        e_vec = pmt.init_f32vector(3, [25, 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 ctm2:")
        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))
Пример #11
0
    def test_float(self):
        self.emitter = pdu_utils.message_emitter()
        self.down = pdu_utils.pdu_downsample(3, 0)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.down, 'pdu_in'))
        self.tb.msg_connect((self.down, 'pdu_out'), (self.debug, 'store'))

        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))
Пример #12
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.emitter = pdu_utils.message_emitter()
     self.pack = pdu_utils.pack_unpack(pdu_utils.MODE_PACK_BYTE, pdu_utils.BIT_ORDER_MSB_FIRST)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.pack, 'pdu_in'))
     self.tb.msg_connect((self.pack, 'pdu_out'), (self.debug, 'store'))
Пример #13
0
    def test_001_t(self):
        self.emitter = pdu_utils.message_emitter()
        self.qd = pdu_utils.pdu_quadrature_demod_cf(1)
        self.debug = blocks.message_debug()

        self.tb.msg_connect((self.emitter, 'msg'), (self.qd, 'cpdus'))
        self.tb.msg_connect((self.qd, 'fpdus'), (self.debug, 'store'))

        in_data1 = [1., 1.j, -1., -1.j, 1.]
        in_data2 = [7. + 7.j, -7. + 7.j, -7. - 7.j, 7. - 7.j, 7. + 7.j]
        expected_data = [PI / 2, PI / 2, PI / 2, PI / 2]
        in_pdu1 = pmt.cons(pmt.make_dict(),
                           pmt.init_c32vector(len(in_data1), in_data1))
        in_pdu2 = pmt.cons(pmt.make_dict(),
                           pmt.init_c32vector(len(in_data2), in_data2))

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

        out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))
        self.assertFloatTuplesAlmostEqual(out_data, expected_data, 4)
        out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(1)))
        self.assertFloatTuplesAlmostEqual(out_data, expected_data, 4)
Пример #14
0
    def test_monte_carlo(self):
        emitter = pdu_utils.message_emitter()
        clock_rec = pdu_utils.pdu_clock_recovery(True)
        msg_debug = blocks.message_debug()

        # make connections
        self.tb.msg_connect((emitter, 'msg'), (clock_rec, 'pdu_in'))
        self.tb.msg_connect((clock_rec, 'pdu_out'), (msg_debug, 'store'))

        # run
        self.tb.start()
        time.sleep(.05)

        # generate and emit
        for i in range(100):
            n_symbols = 100
            sps = 8
            noise_power = 0.02 * i
            original_bits = np.random.randint(0, 2, n_symbols)
            original_samples = original_bits * 2 - 1
            sample_rate = 1e6
            symbol_rate = sample_rate / sps
            data = np.repeat(original_samples, sps) + (
                np.random.rand(n_symbols * sps) * np.sqrt(noise_power))

            meta = pmt.make_dict()
            meta = pmt.dict_add(meta, self.pmt_sample_rate,
                                pmt.from_double(1e6))
            vector = pmt.init_f32vector(len(data), data)

            emitter.emit(pmt.cons(meta, vector))

            time.sleep(.05)

            result = msg_debug.get_message(i)
            result_meta = pmt.car(result)
            result_vector = pmt.to_python(pmt.cdr(result))
            n_errors = sum(original_bits[:len(result_vector)]
                           ^ result_vector[:len(original_bits)])
            result_rate = pmt.to_double(
                pmt.dict_ref(result_meta, self.pmt_symbol_rate, pmt.PMT_NIL))

            #print("result is ", result_rate)
            #print("we expected ", symbol_rate)
            #print("result vector is", result_vector)
            #print("we expected ", original_bits)
            #print("num errors", n_errors)

            # assert some stuff
            if n_errors != 0:
                print("got bad data", i)
            if (result_rate - symbol_rate) > 100:
                print("got bad rate", i)

        # shut down
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(True)
Пример #15
0
    def setUp(self):
        self.tb = gr.top_block()

        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.time = pdu_utils.time_delta("TIME CHECKER")
        self.ctr = pdu_utils.message_counter(pmt.intern("counter"))

        self.tb.msg_connect((self.emitter, 'msg'), (self.time, 'pdu_in'))
        self.tb.msg_connect((self.emitter, 'msg'), (self.ctr, 'msg'))
    def setUp(self):
        self.tb = gr.top_block()
        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.p2b = pdu_utils.pdu_to_bursts_c(
            pdu_utils.EARLY_BURST_BEHAVIOR__APPEND, 64)
        self.vs = blocks.vector_sink_c(1)

        self.tb.msg_connect((self.emitter, 'msg'), (self.p2b, 'bursts'))
        self.tb.connect((self.p2b, 0), (self.vs, 0))
Пример #17
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.emitter = pdu_utils.message_emitter()
     self.ht = pdu_utils.pdu_head_tail(pdu_utils.INPUTTYPE_UNPACKED_BYTE, 16, 1)
     self.d_head = blocks.message_debug()
     self.d_tail = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.ht, 'pdu_in'))
     self.tb.msg_connect((self.ht, 'head'), (self.d_head, 'store'))
     self.tb.msg_connect((self.ht, 'tail'), (self.d_tail, 'store'))
Пример #18
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.drop = pdu_utils.msg_drop_random(0.5, 1)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.drop, 'pdu_in'))
     self.tb.msg_connect((self.drop, 'pdu_out'), (self.debug, 'store'))
     self.in_msg = pmt.PMT_T
     self.n_msgs = 10000
     self.tolerance = self.n_msgs * 0.01
Пример #19
0
    def setUp(self):
        self.tb = gr.top_block()
        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.p2b = pdu_utils.pdu_to_bursts_c(
            pdu_utils.EARLY_BURST_BEHAVIOR__APPEND, 64)
        self.vs = blocks.vector_sink_c(1)
        self.tag_debug = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        self.tag_debug.set_display(True)

        self.tb.msg_connect((self.emitter, 'msg'), (self.p2b, 'bursts'))
        self.tb.connect((self.p2b, 0), (self.vs, 0))
        self.tb.connect((self.p2b, 0), (self.tag_debug, 0))
Пример #20
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.emitter = pdu_utils.message_emitter()
     self.emd = pdu_utils.extract_metadata(pmt.intern("test_key"), 1, 0)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.emd, 'dict'))
     self.tb.msg_connect((self.emd, 'msg'), (self.debug, 'store'))
     self.base_dict = pmt.make_dict()
     self.base_dict = pmt.dict_add(self.base_dict, pmt.intern("key1"), pmt.intern("value1"))
     self.base_dict = pmt.dict_add(self.base_dict, pmt.intern("key2"), pmt.intern("value2"))
     self.base_dict = pmt.dict_add(self.base_dict, pmt.intern("uint64_key"), pmt.from_uint64(1234567))
     self.base_dict = pmt.dict_add(self.base_dict, pmt.intern("double_key"), pmt.from_double(1.234567))
Пример #21
0
    def setUp (self):
        self.tb = gr.top_block ()
        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.num_paths = 3
        self.pdu_round_robin = pdu_utils.pdu_round_robin(self.num_paths)
        self.debug = []
        for i in range(self.num_paths):
          self.debug.append(blocks.message_debug())

        self.tb.msg_connect((self.emitter, "msg"), (self.pdu_round_robin, "pdu_in"))
        for i in range(self.num_paths):
          self.tb.msg_connect((self.pdu_round_robin, "pdu_out_{}".format(i)), (self.debug[i], "store"))
Пример #22
0
    def test_003_instantiation_fff(self):
        self.emitter = pdu_utils.message_emitter()
        self.resamp = pdu_utils.pdu_pfb_resamp_ccc([1], 1, 1.0)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.resamp, 'pdu_in'))
        self.tb.msg_connect((self.resamp, 'pdu_out'), (self.debug, 'store'))

        self.tb.start()
        time.sleep(.5)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(True)
Пример #23
0
    def test_001(self):
        self.emitter = pdu_utils.message_emitter()
        self.debug = pdu_utils.sandia_message_debug()

        # make connections
        self.tb.msg_connect((self.emitter, 'msg'), (self.debug, 'print'))

        self.tb.start()
        self.emitter.emit(pmt.intern("TEST"))
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(True)
    def test_002_send8_keep4(self):
        emitter = pdu_utils.message_emitter()
        keep = pdu_utils.message_keep_1_in_n(2)
        debug = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (keep, 'in'))
        self.tb.msg_connect((keep, 'out'), (debug, 'store'))

        self.tb.start()
        for x in range(8):
            time.sleep(.001)
            emitter.emit()
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertEquals(4, debug.num_messages())
Пример #25
0
    def test_001_emit3(self):
        emitter = pdu_utils.message_emitter()
        debug = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (debug, 'store'))

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

        self.assertEquals(3, debug.num_messages())
Пример #26
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)))
Пример #27
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.dut = pdu_utils.pdu_logger('/dev/null')
     self.tb.msg_connect((self.emitter, 'msg'), (self.dut, 'pdu_in'))
Пример #28
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.debug = blocks.message_debug()
Пример #29
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.ctr = pdu_utils.message_counter("counter")
     self.tb.msg_connect((self.emitter, 'msg'), (self.ctr, 'msg'))