예제 #1
0
    def test_004_n512_s32(self):
        self.upsample.set_n(512)
        self.upsample.set_repeat(True)

        in_data = [99, 44]
        expected_data = [
            99,
        ] * 512 + [
            44,
        ] * 512
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_s32vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_s32vector(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(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.05)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
        self.assertTrue(pmt.equal(self.debug.get_message(1), expected_pdu))
예제 #2
0
파일: qa_pmt.py 프로젝트: vowstar/gnuradio
    def test22_absolute_serialization_int_uvecs(self):
        # u8_vector SERDES
        in_vec = [1, 3, 128, 255]
        in_str = b'\n\x00\x00\x00\x00\x04\x01\x00\x01\x03\x80\xff'
        out_str = pmt.serialize_str(pmt.init_u8vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x00\x00\x00\x00\x07\x01\x00\x02\x03\x04\t\n\x19@'
        in_vec = [2, 3, 4, 9, 10, 25, 64]
        out_vec = pmt.u8vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # s8_vector SERDES
        in_vec = [1, 3, 127, -128]
        in_str = b'\n\x01\x00\x00\x00\x04\x01\x00\x01\x03\x7f\x80'
        out_str = pmt.serialize_str(pmt.init_s8vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x01\x00\x00\x00\x07\x01\x00\x02\x00\x04\xf7\n\x19\xc0'
        in_vec = [2, 0, 4, -9, 10, 25, -64]
        out_vec = pmt.s8vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # u16_vector SERDES
        in_vec = [0xfffe, 0, 256, 0xffff]
        in_str = b'\n\x02\x00\x00\x00\x04\x01\x00\xff\xfe\x00\x00\x01\x00\xff\xff'
        out_str = pmt.serialize_str(pmt.init_u16vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x02\x00\x00\x00\x04\x01\x00\xff\xff\x00\x00\x00\x01\x00\x02'
        in_vec = [0xffff, 0, 1, 2]
        out_vec = pmt.u16vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # s16_vector SERDES
        in_vec = [0x7fff, 0, -256, -0x8000]
        in_str = b'\n\x03\x00\x00\x00\x04\x01\x00\x7f\xff\x00\x00\xff\x00\x80\x00'
        out_str = pmt.serialize_str(pmt.init_s16vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x03\x00\x00\x00\x05\x01\x00\x00\x01\x00\x02\x00\x03\x00\x04\xff\xfb'
        in_vec = [1, 2, 3, 4, -5]
        out_vec = pmt.s16vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # u32_vector SERDES
        in_vec = [0x01020304, 0x05060708, 0, 100000000]
        in_str = b'\n\x04\x00\x00\x00\x04\x01\x00\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00\x00\x00\x05\xf5\xe1\x00'
        out_str = pmt.serialize_str(pmt.init_u32vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x04\x00\x00\x00\x06\x01\x00\x00\x00\x000\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x0c\x00\x00\x10\x00'
        in_vec = [48, 0xffffffff, 0, 9, 12, 4096]
        out_vec = pmt.u32vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # s32_vector SERDES
        in_vec = [-0x0, -0x8000000, 1, 0x7ffffff]
        in_str = b'\n\x05\x00\x00\x00\x04\x01\x00\x00\x00\x00\x00\xf8\x00\x00\x00\x00\x00\x00\x01\x07\xff\xff\xff'
        out_str = pmt.serialize_str(pmt.init_s32vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x05\x00\x00\x00\x05\x01\x00\x00\x00\x000\x7f\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xf7\xff\xff\xff\xf3'
        in_vec = [48, 0x7fffffff, 0, -9, -13]
        out_vec = pmt.s32vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)
예제 #3
0
    def send_taps(self, fft_size):

        self.fft_size = fft_size
        self.taps_set = True
        taps = self.tap_equation(fft_size)
        taps_fi = self.gen_fixed_filter(taps, fft_size)
        taps_vec = self.gen_tap_vec(taps_fi, fft_size)
        data_rfnoc = pmt.init_s32vector(len(taps_vec), taps_vec.tolist())
        msg = pmt.cons(pmt.get_PMT_NIL(), data_rfnoc)
        # print(msg)
        self.message_port_pub(pmt.intern('to_rfnoc'), msg)
        print("done sending")
예제 #4
0
    def test_i32_vector(self):
        cs = starcoder.command_source()
        snk = blocks.message_debug()
        self.tb.msg_connect((cs, 'out'), (snk, 'store'))

        msg = starcoder_pb2.BlockMessage()
        msg.uniform_vector_value.i_value.value.extend([12, -65500, 3])
        msg.uniform_vector_value.i_value.size = starcoder_pb2.Size32

        expected = pmt.init_s32vector(3, [12, -65500, 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_s32vector(snk.get_message(0)))
        self.assertTrue(pmt.equal(snk.get_message(0), expected))
예제 #5
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))
예제 #6
0
파일: qa_pmt.py 프로젝트: 232675/gnuradio
 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))
예제 #7
0
    def __init__(self,
                 fname='',
                 has_header=True,
                 data_type='uint8',
                 period=1000,
                 start_delay=0,
                 repeat=True):
        gr.sync_block.__init__(self, "CSV Reader", in_sig=None, out_sig=None)
        self.file = fname
        self.has_header = has_header
        self.data_type = data_type
        self.period = period
        self.repeat = repeat
        self.start_delay = start_delay

        # 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')

        # metadata field mappings
        self.metadata_mappings = {
            'string':
            lambda x: pmt.intern(x),
            'bool':
            lambda x: pmt.from_bool(bool(x)),
            'long':
            lambda x: pmt.from_long(int(x)),
            'uint64':
            lambda x: pmt.from_uint64(int(x)),
            'float':
            lambda x: pmt.from_float(float(x)),
            'double':
            lambda x: pmt.from_double(float(x)),
            'complex':
            lambda x: pmt.from_complex(complex(x)),
            'time':
            lambda x: pmt.cons(pmt.from_uint64(int(math.modf(float(x))[1])),
                               pmt.from_double(math.modf(float(x))[0])),
            'time_tuple':
            lambda x: pmt.make_tuple(
                pmt.from_uint64(int(math.modf(float(x))[1])),
                pmt.from_double(math.modf(float(x))[0]))
        }

        self.data_type_mappings = {
            'uint8':
            lambda x: pmt.init_u8vector(len(x), [int(y) for y in x]),
            'int8':
            lambda x: pmt.init_s8vector(len(x), [int(y) for y in x]),
            'uint16':
            lambda x: pmt.init_u16vector(len(x), [int(y) for y in x]),
            'int16':
            lambda x: pmt.init_s16vector(len(x), [int(y) for y in x]),
            'uint32':
            lambda x: pmt.init_u32vector(len(x), [int(y) for y in x]),
            'int32':
            lambda x: pmt.init_s32vector(len(x), [int(y) for y in x]),
            'float':
            lambda x: pmt.init_f32vector(len(x), [float(y) for y in x]),
            'complex float':
            lambda x: pmt.init_c32vector(len(x), [complex(y) for y in x]),
            'double':
            lambda x: pmt.init_f64vector(len(x), [float(y) for y in x]),
            'complex double':
            lambda x: pmt.init_c64vector(len(x), [complex(y) for y in x])
        }

        # ensure valid data type
        if self.data_type not in self.data_type_mappings.keys():
            raise ValueError('Invalid data type {}'.format(data_type))

        # set file name
        self.set_fname(self.file)

        self.message_port_name = pmt.intern('out')
        self.message_port_register_out(self.message_port_name)

        # flag for when to stop
        self.stop_signal_called = False

        # no timer yet
        self.timer = None

        # file lock
        self.lock = threading.Lock()