def test_003_double_eob_rej_tt_update (self): self.tb = gr.top_block () start_time = 0.0 sob_tag = gr.tag_utils.python_to_tag((51, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src"))) eob_tag = gr.tag_utils.python_to_tag((51+(8*11), pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src"))) time_tuple = pmt.make_tuple(pmt.from_uint64(4), pmt.from_double(0.125), pmt.from_uint64(10000000), pmt.from_double(4000000.0)) time_tag = gr.tag_utils.python_to_tag((360, pmt.intern("rx_time"), time_tuple, pmt.intern("src"))) sob_tag2 = gr.tag_utils.python_to_tag((400, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src"))) eob_tag2e = gr.tag_utils.python_to_tag((409, pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src"))) eob_tag2 = gr.tag_utils.python_to_tag((416, pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src"))) vs = blocks.vector_source_s(range(500), False, 1, [sob_tag, eob_tag, time_tag, sob_tag2, eob_tag2e, eob_tag2]) t2p = pdu_utils.tags_to_pdu_s(pmt.intern('SOB'), pmt.intern('EOB'), 1024, 1000000, ([]), 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_vec1 = pmt.init_s16vector((8*11), range(51,51+(8*11))) expected_vec2 = pmt.init_s16vector(16, list(range(400,409)) + [0]*7) expected_time1 = start_time + (51 / 1000000.0) expected_time2 = 4.125 + ((400-360) / 1000000.0) self.tb.run () self.assertEqual(dbg.num_messages(), 2) self.assertTrue(pmt.equal(pmt.cdr(dbg.get_message(0)), expected_vec1)) self.assertTrue(pmt.equal(pmt.cdr(dbg.get_message(1)), expected_vec2)) time_tuple1 = pmt.dict_ref(pmt.car(dbg.get_message(0)), pmt.intern("burst_time"), pmt.PMT_NIL) time_tuple2 = pmt.dict_ref(pmt.car(dbg.get_message(1)), 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_time1) self.assertAlmostEqual(pmt.to_uint64(pmt.tuple_ref(time_tuple2,0)) + pmt.to_double(pmt.tuple_ref(time_tuple2,1)), expected_time2) self.tb = None
def test_002_secondSOB(self): self.tb = gr.top_block() start_time = 4.999999999 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( (51, pmt.intern("SOB"), pmt.PMT_T, pmt.intern("src"))) eob_tag = gr.tag_utils.python_to_tag( (51 + (8 * 26), pmt.intern("EOB"), pmt.PMT_T, pmt.intern("src"))) vs = blocks.vector_source_s(range(350), False, 1, [sob_tag, sob_tag2, eob_tag]) t2p = pdu_utils.tags_to_pdu_s(pmt.intern('SOB'), pmt.intern('EOB'), 1024, 460800, ([]), 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 * 26), range(51, 51 + (8 * 26))) expected_time = start_time + (51 / 460800.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_004_boost_time(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.enable_time_debug(True) t2p.set_eob_parameters(8, 0) dbg = blocks.message_debug() #td = pdu_utils.time_delta("TIME CHECKER") #td = timing_utils.time_delta("TIME CHECKER") self.tb.connect(vs, t2p) self.tb.msg_connect((t2p, 'pdu_out'), (dbg, 'store')) #self.tb.msg_connect((t2p, 'pdu_out'), (td, 'pdu_in')) expected_vec = pmt.init_s16vector((8 * 31), range(34, 34 + (8 * 31))) expected_time = start_time + (34 / 512000.0) ts = time.time() 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) #wct = pmt.to_double(pmt.dict_ref(pmt.car(dbg.get_message(0)), pmt.intern("wall_clock_time"), pmt.PMT_NIL)) #self.assertTrue((wct - ts) < 1.0) self.tb = None
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
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
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 test_003_s_2_11_7 (self): self.source = blocks.vector_source_s(range(0,32*3), False, 1, []) self.ts_pdu = pdu_utils.take_skip_to_pdu_s(2, 11) self.debug = blocks.message_debug() self.tb.connect((self.source, 0), (self.ts_pdu, 0)) self.tb.msg_connect((self.ts_pdu, 'pdu_out'), (self.debug, 'store')) dic = pmt.dict_add(pmt.make_dict(), pmt.intern("pdu_num"), pmt.from_uint64(7)) vec = pmt.init_s16vector(2, list(range(91,93))) expected = pmt.cons(dic,vec) self.tb.run () actual = self.debug.get_message(7) self.assertEqualPDU(actual, expected)
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
def test08(self): v = pmt.init_s16vector(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()