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)
def test06(self): v = pmt.init_s8vector(3, [11, -22, 33]) s = pmt.serialize_str(v) d = pmt.deserialize_str(s) self.assertTrue(pmt.equal(v, d))
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()