Пример #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'))
    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))
Пример #3
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))
Пример #4
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))
Пример #5
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))
Пример #6
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.tb.msg_connect((self.emitter, 'msg'), (self.p2b, 'bursts'))
        self.tb.connect((self.p2b, 0), (self.vs, 0))
Пример #7
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())
Пример #8
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)))