def int_list_to_pmt(self, items): if len(items) == 0: return pmt.pmt_from_bool(pmt.PMT_F) else: pmtl = pmt.pmt_list1(pmt.pmt_from_long(items[0])) for i in range(len(items)-1): pmtl = pmt.pmt_list_add(pmtl, pmt.pmt_from_long(items[i+1])) return pmtl
def test_001_t (self): """ more advanced: - 6 symbols per carrier - 2 pilots per carrier - have enough data for nearly 3 OFDM symbols """ tx_symbols = range(1, 16); pilot_symbols = ((1j, 2j), (3j, 4j)) occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) pilot_carriers = ((2, 13), (3, 12)) expected_result = (0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0, 7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0) fft_len = 16 mtu = 4096 tag_name = "len" tag = gr.gr_tag_t() tag.offset = 0 tag.key = pmt.pmt_string_to_symbol(tag_name) tag.value = pmt.pmt_from_long(len(tx_symbols)) src = gr.vector_source_c(tx_symbols, (tag,), False, 1) alloc = ofdm.carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, tag_name) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run () self.assertEqual(sink.data(), expected_result)
def test_001_t (self): """ pretty simple """ fft_len = 6 tx_symbols = (1, 2, 3) pilot_symbols = ((1j,),) occupied_carriers = ((0, 1, 2),) pilot_carriers = ((3,),) expected_result = (1, 2, 3, 1j, 0, 0) mtu = 128 tag_name = "len" tag = gr.gr_tag_t() tag.offset = 0 tag.key = pmt.pmt_string_to_symbol(tag_name) tag.value = pmt.pmt_from_long(len(tx_symbols)) src = gr.vector_source_c(tx_symbols, (tag,), False, 1) alloc = ofdm.carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, tag_name) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run () self.assertEqual(sink.data(), expected_result)
def generate_tag(self, tag_key, srcid, value, offset): tag = gr.gr_tag_t() tag.key = pmt.pmt_string_to_symbol(tag_key) tag.srcid = pmt.pmt_string_to_symbol(srcid) tag.value = pmt.pmt_from_long(value) tag.offset = offset return tag
def get_tag_list(data_len, tag_key, N_ofdm_symbols): tag_list = [] for i in range(data_len): tag = gr.gr_tag_t() tag.key = pmt.pmt_string_to_symbol(tag_key) tag.srcid = pmt.pmt_string_to_symbol("test_src") tag.value = pmt.pmt_from_long(i%N_ofdm_symbols) tag.offset = i tag_list.append(tag) return tag_list
def make_lengthtags(lengths, offsets, tagname='length', vlen=1): tags = [] assert(len(offsets) == len(lengths)) for offset, length in zip(offsets, lengths): tag = gr.gr_tag_t() tag.offset = offset/vlen tag.key = pmt.pmt_string_to_symbol(tagname) tag.value = pmt.pmt_from_long(length/vlen) tags.append(tag) return tags
def packets_to_vectors(packets, lengthtagname, vlen=1): tags = [] data = [] offset = 0 for packet in packets: data.extend(packet) tag = gr.gr_tag_t() tag.offset = offset/vlen tag.key = pmt.pmt_string_to_symbol(lengthtagname) tag.value = pmt.pmt_from_long(len(packet)/vlen) tags.append(tag) offset = offset + len(packet) return data, tags
def test_crc_len(self): data = range(16) tag_name = "len" tag = gr.gr_tag_t() tag.offset = 0 tag.key = pmt.pmt_string_to_symbol(tag_name) tag.value = pmt.pmt_from_long(len(data)) src = gr.vector_source_b(data, (tag,), False, 1) mtu = 64 crc = ofdm.crc32_bb(False, mtu, tag_name) sink = gr.vector_sink_b() self.tb.connect(src, crc, sink) self.tb.run() # Check that the packets before crc_check are 4 bytes longer that the input. self.assertEqual(len(data) + 4, len(sink.data()))
def test_crc_equal(self): data = (0, 1, 2, 3, 4, 5, 6, 7, 8) tag_name = "len" tag = gr.gr_tag_t() tag.offset = 0 tag.key = pmt.pmt_string_to_symbol(tag_name) tag.value = pmt.pmt_from_long(len(data)) src = gr.vector_source_b(data, (tag,), False, 1) mtu = 64 crc = ofdm.crc32_bb(False, mtu, tag_name) crc_check = ofdm.crc32_bb(True, mtu, tag_name) sink = gr.vector_sink_b() sink2 = gr.vector_sink_b() self.tb.connect(src, crc, crc_check, sink) self.tb.run() # Check that the packets after crc_check are the same as input. self.assertEqual(data, sink.data())
def setUp (self): self.tb = gr.top_block () # These are block parameters msg_buf_name_in = "cell_id" msg_buf_name_out = "pilots" N_rb_dl = 6 ant_port = 0 # These parameters are regarded as "data" cell_id = 124 # Set up msg inputs and outputs msg = pmt.pmt_from_long(cell_id) self.strobe = blocks.message_strobe(msg, 1000) self.dbg = blocks.message_debug() # UUT self.param = estimator_parameterizer_msg(msg_buf_name_in, msg_buf_name_out, N_rb_dl, ant_port) # Set up connections self.tb.msg_connect(self.strobe, "strobe", self.param, msg_buf_name_in) self.tb.msg_connect(self.param, msg_buf_name_out, self.dbg, "store")
def test_001_t (self): cell_id = 220 N_ant = 2 style= "tx_diversity" N_rb_dl = self.N_rb_dl self.demux.set_cell_id(cell_id) mib = pack_mib(50,0,1.0, 511) bch = encode_bch(mib, N_ant) pbch = encode_pbch(bch, cell_id, N_ant, style) stream = [] for i in range(4): frame = generate_frame(pbch, N_rb_dl, cell_id, i+20, N_ant) stream.extend(frame[0].flatten()) print len(stream) tag_name = "symbol" tag_list = [] for i in range(len(stream)/(12*N_rb_dl)): if i%7 == 0: tag = gr.gr_tag_t() tag.key = pmt.pmt_string_to_symbol(tag_name) tag.value = pmt.pmt_from_long(i%140) tag.offset = i*12*N_rb_dl tag_list.append(tag) print len (tag_list) self.src1.set_data(stream, tuple(tag_list)) self.src2.set_data(np.ones(len(stream), dtype=np.complex)) self.src3.set_data(np.ones(len(stream), dtype=np.complex)) # set up fg self.tb.run () # check data res1 = self.snk1.data() res2 = self.snk2.data() res3 = self.snk3.data() print len(res1) compare = res1[0:len(pbch[0])] ''' partl = 10 for i in range(len(res1)/partl): partres = compare[partl*i:partl*(i+1)] partcom = pbch[0][partl*i:partl*(i+1)] try: self.assertComplexTuplesAlmostEqual(partcom,partres) print str(i*partl) + "\tsuccess" except: #print "\n\n\n\n\n\n" print str(i*partl) + "\t" + str(partres) ''' self.assertComplexTuplesAlmostEqual(compare,tuple(pbch[0])) self.assertComplexTuplesAlmostEqual(res2,tuple(np.ones(len(res2), dtype=np.complex))) self.assertComplexTuplesAlmostEqual(res3,tuple(np.ones(len(res3), dtype=np.complex)))
def run(self): while(self.count == -1 or self.count > 0): time.sleep(self.delay); timer_evt = es.event_create(self.d_type, 0, self.evt_length); timer_evt = es.event_args_add( timer_evt, pmt.pmt_intern("timer_counter"), pmt.pmt_from_long(self.count)); self.queue.add_event( timer_evt ); if(self.count > 0): self.count = self.count - 1;