def test_start_time_on_init(self): # initialize the block and get the start time print("starting start time on init") sink_inputs = dict(self.default_inputs) op = envsim.env_sink(**sink_inputs) now = time.time() uhd_time_now = op.get_time_now() self.assertAlmostEqual(uhd_time_now.get_real_secs(), now, places=ACCEPTABLE_TIME_DIGITS_OF_ACCURACY)
def test_set_time_now(self): # initialize the block and set the start time print("starting set time now") sink_inputs = dict(self.default_inputs) int_s = 1503689677 frac_s = 0.5 op = envsim.env_sink(**sink_inputs) op.set_time_now(time_spec_t(int_s, frac_s)) uhd_time_now = op.get_time_now() self.assertEqual(int_s, uhd_time_now.get_full_secs()) self.assertEqual(frac_s, uhd_time_now.get_frac_secs())
def test_sob_bursts_with_tx_time(self): ''' The packet length field is not defined We input a packet len tag that occurs on the first sample of the block. We include a tx_time tag Check that one message is generated including all input samples and appropriate timestamp ''' print("starting test_sob_bursts_with_tx_time") # put in a known (and easy to do math on) start time to make testing doable start_time_int_s = 100 start_time_frac_s = 0.0 tag_start_time_int_s = 200 tag_start_time_frac_s = 0.5 sink_inputs = dict(self.default_inputs) sink_inputs["tx_pkt_len_name"] = "" sample_rate = sink_inputs["sample_rate"] src_data = [ 0 + 1j, 2 + 3j, 4 + 5j, 6 + 7j, 8 + 9j, 10 + 11j, 12 + 13j, 14 + 15j, 16 + 17j, 18 + 19j ] tag_offset = 0 src_tags = [{ "offset": tag_offset, "key": self.tx_sob_name, "value": True }, { "offset": tag_offset, "key": self.tx_time_name, "value": (tag_start_time_int_s, tag_start_time_frac_s) }] # convert src_tags into proper gnuradio stream tags src_tags = [dict_to_tag(st) for st in src_tags] # Note that currently the timestamp for envsim is in units of integer seconds and integer picoseconds expected_list = [ { "meta": { "timestamp_s": (tag_start_time_int_s, int(tag_start_time_frac_s * 1e12)), "packet_len": len(src_data) }, "data": src_data }, ] expected_block_time = tag_start_time_int_s + tag_start_time_frac_s + len( src_data) / sample_rate src = blocks.vector_source_c(src_data, False, 1, src_tags) print("length of source data vector: {}".format(len(src_data))) op = envsim.env_sink(**sink_inputs) # set start time instead of getting from system clock op.set_time_now(time_spec_t(start_time_int_s, start_time_frac_s)) # connect up input and message destination blocks self.tb.connect(src, op) self.tb.msg_connect((op, 'event'), (self.msg_dst, 'store')) self.tb.run() # check data result_list = [ iq_packet_to_dict(self.msg_dst.get_message(i)) for i in range(self.msg_dst.num_messages()) ] self.assertPacketListEqual(expected_list, result_list) self.assertAlmostEqual(expected_block_time, op.get_time_now().get_real_secs())
def test_sob_bursts_no_tags(self): ''' The packet length field is not defined. We input no stream tags. Check that a message is generated including all input samples and appropriate timestamps ''' print("test_sob_bursts_no_tags") # put in a known (and easy to do math on) start time to make testing doable start_time_int_s = 100 start_time_frac_s = 0.0 sink_inputs = dict(self.default_inputs) sink_inputs["tx_pkt_len_name"] = "" sample_rate = sink_inputs["sample_rate"] src_data = [ 0 + 1j, 2 + 3j, 4 + 5j, 6 + 7j, ] expected_list = [ { "meta": { "timestamp_s": (start_time_int_s, int(start_time_frac_s * 1e12)), "packet_len": len(src_data) }, "data": src_data }, ] expected_block_time = start_time_int_s + start_time_frac_s + len( src_data) / sample_rate # note no tags used src = blocks.vector_source_c(src_data) op = envsim.env_sink(**sink_inputs) # set start time instead of getting from system clock op.set_time_now(time_spec_t(start_time_int_s, start_time_frac_s)) # connect up input and message destination blocks self.tb.connect(src, op) self.tb.msg_connect((op, 'event'), (self.msg_dst, 'store')) self.tb.run() # check data result_list = [ iq_packet_to_dict(self.msg_dst.get_message(i)) for i in range(self.msg_dst.num_messages()) ] self.assertPacketListEqual(expected_list, result_list) self.assertAlmostEqual(expected_block_time, op.get_time_now().get_real_secs())