def set_freq(self, center_freq, keep): self.message_port_pub( pmt.intern('out1'), pmt.cons(pmt.intern('keep'), pmt.from_bool(not keep))) self.message_port_pub( pmt.intern('out2'), pmt.cons(pmt.intern('keep'), pmt.from_bool(keep)))
def onToggleClicked(self, pressed): if pressed: self.state = 1 self.callback(self.pressReleasedDict['Pressed']) else: self.state = 0 self.callback(self.pressReleasedDict['Released']) self.setColor() if pressed: if type(self.pressReleasedDict['Pressed']) == bool: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_bool(self.pressReleasedDict['Pressed']))) elif type(self.pressReleasedDict['Pressed']) == int: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_long(self.pressReleasedDict['Pressed']))) elif type(self.pressReleasedDict['Pressed']) == float: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_float( self.pressReleasedDict['Pressed']))) else: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.intern(self.pressReleasedDict['Pressed']))) else: if type(self.pressReleasedDict['Released']) == bool: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_bool( self.pressReleasedDict['Released']))) elif type(self.pressReleasedDict['Released']) == int: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_long( self.pressReleasedDict['Released']))) elif type(self.pressReleasedDict['Released']) == float: self.message_port_pub( pmt.intern("state"), pmt.cons( pmt.intern(self.outputmsgname), pmt.from_float(self.pressReleasedDict['Released']))) else: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.intern(self.pressReleasedDict['Released'])))
def __init__(self): gr.top_block.__init__(self, "Test_decision") Qt.QWidget.__init__(self) self.setWindowTitle("Test_decision") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "Test_decision") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 320000 self.develop_mode_list = develop_mode_list = [1, 3, 4, 14, 21, 22] ################################################## # Blocks ################################################## self.inets_null_message_source_0 = inets.null_message_source() self.inets_decision_cpp_0 = inets.decision_cpp((develop_mode_list), 14) self.inets_counter_0_0 = inets.counter(1, 22, 1) self.inets_counter_0 = inets.counter(1, 21, 1) self.blocks_message_strobe_random_0_0 = blocks.message_strobe_random( pmt.from_bool(False), blocks.STROBE_POISSON, 2000, 500) self.blocks_message_strobe_random_0 = blocks.message_strobe_random( pmt.from_bool(True), blocks.STROBE_POISSON, 3000, 500) ################################################## # Connections ################################################## self.msg_connect((self.blocks_message_strobe_random_0, 'strobe'), (self.inets_decision_cpp_0, 'spark_in')) self.msg_connect((self.blocks_message_strobe_random_0_0, 'strobe'), (self.inets_decision_cpp_0, 'spark_in')) self.msg_connect((self.inets_decision_cpp_0, 'spark_out_t'), (self.inets_counter_0, 'message_in')) self.msg_connect((self.inets_decision_cpp_0, 'spark_out_f'), (self.inets_counter_0_0, 'message_in')) self.msg_connect( (self.inets_null_message_source_0, 'null_message_out'), (self.inets_decision_cpp_0, 'spark_in'))
def notifyUpdate(self, new_val): if self.callback is not None: if new_val: self.callback(self.pressReleasedDict['Pressed']) else: self.callback(self.pressReleasedDict['Released']) if new_val: if type(self.pressReleasedDict['Pressed']) == bool: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_bool(self.pressReleasedDict['Pressed']))) elif type(self.pressReleasedDict['Pressed']) == int: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_long(self.pressReleasedDict['Pressed']))) elif type(self.pressReleasedDict['Pressed']) == float: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_float( self.pressReleasedDict['Pressed']))) else: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.intern(self.pressReleasedDict['Pressed']))) else: if type(self.pressReleasedDict['Released']) == bool: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_bool( self.pressReleasedDict['Released']))) elif type(self.pressReleasedDict['Released']) == int: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_long( self.pressReleasedDict['Released']))) elif type(self.pressReleasedDict['Released']) == float: self.message_port_pub( pmt.intern("state"), pmt.cons( pmt.intern(self.outputmsgname), pmt.from_float(self.pressReleasedDict['Released']))) else: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.intern(self.pressReleasedDict['Released'])))
def onToggleClicked(self, checked): if self.chkBox.isChecked(): self.callback(self.pressReleasedDict['Pressed']) if type(self.pressReleasedDict['Pressed']) == bool: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_bool(self.pressReleasedDict['Pressed']))) elif type(self.pressReleasedDict['Pressed']) == int: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_long(self.pressReleasedDict['Pressed']))) elif type(self.pressReleasedDict['Pressed']) == float: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_float( self.pressReleasedDict['Pressed']))) else: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.intern(self.pressReleasedDict['Pressed']))) else: self.callback(self.pressReleasedDict['Released']) if type(self.pressReleasedDict['Released']) == bool: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_bool( self.pressReleasedDict['Released']))) elif type(self.pressReleasedDict['Released']) == int: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_long( self.pressReleasedDict['Released']))) elif type(self.pressReleasedDict['Released']) == float: self.message_port_pub( pmt.intern("state"), pmt.cons( pmt.intern(self.outputmsgname), pmt.from_float(self.pressReleasedDict['Released']))) else: self.message_port_pub( pmt.intern("state"), pmt.cons(pmt.intern(self.outputmsgname), pmt.intern(self.pressReleasedDict['Released'])))
def test_002(self): offset = 10 key = pmt.string_to_symbol('key') value = pmt.from_long(23) srcid = pmt.from_bool(False) format_dict = {'offset': offset, 'key': key, 'value': value, 'srcid': srcid} format_list = [offset, key, value, srcid] format_tuple = (offset, key, value, srcid) t_dict = gr.python_to_tag(format_dict) t_list = gr.python_to_tag(format_list) t_tuple = gr.python_to_tag(format_tuple) self.assertTrue(pmt.equal(t_dict.key, key)) self.assertTrue(pmt.equal(t_dict.value, value)) self.assertEqual(t_dict.offset, offset) self.assertTrue(pmt.equal(t_list.key, key)) self.assertTrue(pmt.equal(t_list.value, value)) self.assertEqual(t_list.offset, offset) self.assertTrue(pmt.equal(t_tuple.key, key)) self.assertTrue(pmt.equal(t_tuple.value, value)) self.assertEqual(t_tuple.offset, offset)
def work(self, input_items, output_items): in0 = input_items[0] out = output_items[0] out[:] = in0[:] nread = self.nitems_read(0) #number of items read on port 0 ninput_items = len(in0) eob = pmt.string_to_symbol("tx_eob") sob = pmt.string_to_symbol("tx_sob") pan = pmt.string_to_symbol("pdu_length") value = pmt.from_bool(1) lng = pmt.from_long(8192) source = pmt.string_to_symbol("add_uhd_tag") tags = self.get_tags_in_range(0, nread, nread+ninput_items) print "total input items : " + str(ninput_items) for tag in tags: #print "key : " + str(tag.key) if str(tag.key) == "pdu_length": #print "Found burst start at offset : " + str(tag.offset) + " with value : " + str(tag.value) #print " -> Injecting tag tx_sob @" + str(tag.offset) #print " -> Injecting tag tx_eob @" + str(tag.offset + pmt.to_long(tag.value) -1) self.add_item_tag(0, tag.offset, sob, value, source) self.add_item_tag(0, tag.offset + pmt.to_long(tag.value) -1, eob, value, source) return len(out)
def work(self, input_items, output_items): for ind, sample in enumerate(input_items[0]): if not self._power: if abs(sample) >= self._threshold: self.add_item_tag(0, self.nitems_written(0) + ind, self._key, pmt.from_bool(True)) self._power = True else: if abs(sample) < self._threshold: self.add_item_tag(0, self.nitems_written(0) + ind, self._key, pmt.from_bool(False)) self._power = False output_items[0][:] = input_items[0] return len(output_items[0])
def work(self, input_items, output_items): in0 = input_items[0] out = output_items[0] out[:] = in0[:] nread = self.nitems_read(0) #number of items read on port 0 ninput_items = len(in0) sob_t = pmt.string_to_symbol(self.start_tag) eob_t = pmt.string_to_symbol(self.end_tag) len_t = pmt.string_to_symbol(self.len_tag) value = pmt.from_bool(True) source = pmt.string_to_symbol("uhd_tags") tags = self.get_tags_in_range(0, nread, nread + ninput_items) for tag in tags: #print "key : " + str(tag.key) if str(tag.key) == self.len_tag: if DEBUG: print "Found burst start at offset : " + str( tag.offset) + " with len : " + str(tag.value) print " -> Injecting tag " + self.start_tag + " @" + str( tag.offset) print " -> Injecting tag " + self.end_tag + " @" + str( tag.offset + pmt.to_long(tag.value) - 1) self.add_item_tag(0, tag.offset, sob_t, value, source) self.add_item_tag(0, tag.offset + pmt.to_long(tag.value) - 1, eob_t, value, source) return len(out)
def int_list_to_pmt(self, items): if len(items) == 0: return pmt.from_bool(pmt.PMT_F) else: pmtl = pmt.list1(pmt.from_long(items[0])) for i in range(len(items) - 1): pmtl = pmt.list_add(pmtl, pmt.from_long(items[i + 1])) return pmtl
def test_comparison(self): t = gr.tag_t() t.offset = 10 t.key = pmt.string_to_symbol('key') t.value = pmt.from_long(23) t.srcid = pmt.from_bool(False) t2 = gr.tag_t() t2.offset = 100 t2.key = pmt.string_to_symbol('aaa') t2.value = pmt.from_long(230) t2.srcid = pmt.from_bool(True) self.assertTrue(t < t2) self.assertTrue(t == t) self.assertTrue(t != t2) self.assertFalse(t > t2) self.assertFalse(t < t)
def test_001_all_header_fields(self): with open('/tmp/file.csv', 'w') as f: # write header f.write('field0(string), , field1(bool), field2(float),' + 'field3(long), field4(uint64), field5(double),' + 'field6(complex),field7,field8(time),field9(time_tuple)\n') # add some data f.write( 'field0, empty, True, 1.0,1234567890,987654321, 2.5,1+2j,string,1.0,1.0,1,2,3,4,5\n' ) # start reader/ reader = csv_reader(fname='/tmp/file.csv', has_header=True, period=10, start_delay=0, repeat=False) # expected pdu metadata = pmt.dict_add(pmt.make_dict(), pmt.intern('field0'), pmt.intern('field0')) metadata = pmt.dict_add(metadata, pmt.intern('field1'), pmt.from_bool(True)) metadata = pmt.dict_add(metadata, pmt.intern('field2'), pmt.from_float(1.0)) metadata = pmt.dict_add(metadata, pmt.intern('field3'), pmt.from_long(1234567890)) metadata = pmt.dict_add(metadata, pmt.intern('field4'), pmt.from_uint64(987654321)) metadata = pmt.dict_add(metadata, pmt.intern('field5'), pmt.from_double(2.5)) metadata = pmt.dict_add(metadata, pmt.intern('field6'), pmt.from_complex(1.0 + 2j)) metadata = pmt.dict_add(metadata, pmt.intern('field7'), pmt.intern('string')) metadata = pmt.dict_add( metadata, pmt.intern('field8'), pmt.cons(pmt.from_uint64(1), pmt.from_double(0))) metadata = pmt.dict_add( metadata, pmt.intern('field9'), pmt.make_tuple(pmt.from_uint64(1), pmt.from_double(0))) data = pmt.init_u8vector(5, [1, 2, 3, 4, 5]) expected = pmt.cons(metadata, data) # run self.tb.msg_connect((reader, 'out'), (self.debug, 'store')) self.tb.start() time.sleep(.5) self.tb.stop() self.tb.wait() got = self.debug.get_message(0) self.assertTrue(pmt.equal(expected, got))
def test_001(self): t = gr.tag_t() t.offset = 10 t.key = pmt.string_to_symbol('key') t.value = pmt.from_long(23) t.srcid = pmt.from_bool(False) pt = gr.tag_to_python(t) self.assertEqual(pt.key, 'key') self.assertEqual(pt.value, 23) self.assertEqual(pt.offset, 10)
def test_001_t(self): # Define test params. data_length = 20 repetitions = 5 for n in range(repetitions): vlen = np.random.randint(1, 9) modulation_order = np.random.randint(1, 4) phase_shift = 2.0 * np.pi * np.random.randn() # Generate random input data. data = M_SQRT_2 * np.exp( 1j * (2.0 * np.pi * np.random.randint( 0, 2**modulation_order, size=[data_length * vlen]) / (2.0**modulation_order) + phase_shift)) # Randomly generate normalized channel matrix. channel_gain_dist = np.random.rand() channel_matrix = np.array([ channel_gain_dist * np.exp(2j * np.pi * np.random.rand()), np.sqrt(1 - np.square(np.abs(channel_gain_dist))) * np.exp(2j * np.pi * np.random.rand()) ]) # Set a stream tag to the beginning of the stream. tag_pmt = pmt.from_bool(True) # Append stream tags with CSI to data stream. tags = [(gr.tag_utils.python_to_tag( (0, pmt.string_to_symbol("start"), tag_pmt, pmt.from_long(0)))) ] # Build up the test flowgraph. src = blocks.vector_source_c(data=data, tags=tags) diff_stbc_encoder = digital.diff_stbc_encoder_cc(phase_shift, vlen) # Simulate channel with matrix multiplication. channel = blocks.multiply_matrix_cc_make([channel_matrix]) v2s = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen) diff_stbc_decoder = digital.diff_stbc_decoder_cc(phase_shift, vlen) sink = blocks.vector_sink_c() encoder_sink1 = blocks.vector_sink_c() encoder_sink2 = blocks.vector_sink_c() self.tb.connect(src, diff_stbc_encoder, channel, v2s, diff_stbc_decoder, sink) self.tb.connect((diff_stbc_encoder, 1), (channel, 1)) self.tb.connect((diff_stbc_encoder, 0), encoder_sink1) self.tb.connect((diff_stbc_encoder, 1), encoder_sink2) # Run flowgraph. self.tb.run() ''' Check if the expected result (=the data itself with only missing sequences at the tag positions (differential scheme loses one sample at the beginning of each block) equals the actual result. ''' self.assertComplexTuplesAlmostEqual( data[2 * vlen:data_length * vlen:], sink.data(), 4)
def variable_changed(self, value): if type(value) == float: p = pmt.from_float(value) elif type(value) == int: p = pmt.from_long(value) elif type(value) == bool: p = pmt.from_bool(value) else: p = pmt.intern(value) self.message_port_pub(pmt.intern("msgout"), pmt.cons(pmt.intern(self.pairname), p))
def onBtnClicked(self, pressed): if type(self.msgValue) == int: self.message_port_pub(pmt.intern("pressed"), pmt.cons(pmt.intern(self.msgName), pmt.from_long(self.msgValue))) elif type(self.msgValue) == float: self.message_port_pub(pmt.intern("pressed"), pmt.cons(pmt.intern(self.msgName), pmt.from_double(self.msgValue))) elif type(self.msgValue) == str: self.message_port_pub(pmt.intern("pressed"), pmt.cons(pmt.intern(self.msgName), pmt.intern(self.msgValue))) elif type(self.msgValue) == bool: self.message_port_pub(pmt.intern("pressed"), pmt.cons(pmt.intern(self.msgName), pmt.from_bool(self.msgValue)))
def __init__(self): gr.top_block.__init__(self, "Test Tx buffer function") Qt.QWidget.__init__(self) self.setWindowTitle("Test Tx buffer function") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "Test_tx_buff") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.max_buffer_size = max_buffer_size = 5 self.develop_mode_list = develop_mode_list = [1, 2, 3, 4, 5, 6] ################################################## # Blocks ################################################## self.inets_tx_buffer_0 = inets.tx_buffer((develop_mode_list), max_buffer_size, 1) self.inets_message_tomb_0 = inets.message_tomb() self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", 'localhost', '52001', 10000, False) self.blocks_message_strobe_random_0 = blocks.message_strobe_random( pmt.from_bool(True), blocks.STROBE_POISSON, 2500, 100) ################################################## # Connections ################################################## self.msg_connect((self.blocks_message_strobe_random_0, 'strobe'), (self.inets_tx_buffer_0, 'spark_in')) self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.inets_tx_buffer_0, 'payload_in')) self.msg_connect((self.inets_tx_buffer_0, 'payload_out'), (self.inets_message_tomb_0, 'message_in'))
def work(self, input_items, output_items): """example: multiply with constant""" if self.worker.is_alive(): return len(input_items[0]) if self.drop: self.drop = False self.message_port_pub( pmt.intern('drop'), pmt.from_bool(False), ) if input_items[0].shape[0] == self.nsamples: print(datetime.now()) tags = self.get_tags_in_window(0, 0, self.nsamples) for tag in tags: tag = gr.tag_to_python(tag) if tag.key == 'rx_freq': self.rx_freq = tag.value if tag.key == 'rx_rate': self.rx_rate = tag.value self.worker = Process(target=gen_spectrogram, args=( input_items[0].copy(), self.rx_freq, self.rx_rate, )) # self.worker.setDaemon(True) self.worker.start() self.message_port_pub(pmt.intern('drop'), pmt.from_bool(True)) self.drop = True return self.nsamples return 0
def nmea_parser_core(self, nmea_str): fixobj = pynmea2.parse(nmea_str) nmea_id = fixobj.sentence_type if nmea_id not in ['GGA', 'GLL', 'RMC', 'VTG']: raise AttributeError("Unparsed Sentence") D = pmt.make_dict() D = PMT_ADD(D, PSTR("id"), PSTR(nmea_id)) D = PMT_ADD(D, PSTR("protocol"), PSTR('nmea')) D = PMT_ADD(D, PSTR("host_time"), PSTR(str(self.host_time))) try: self.valid = fixobj.is_valid D = PMT_ADD(D, PSTR("valid"), pmt.from_bool(self.valid)) except AttributeError: pass # not all sentences carry validity try: D = PMT_ADD(D, PSTR("latitude"), PDBL(fixobj.latitude)) D = PMT_ADD(D, PSTR("longitude"), PDBL(fixobj.longitude)) except AttributeError: pass try: if fixobj.altitude is not None: D = PMT_ADD(D, PSTR("altitude"), PDBL(fixobj.altitude)) except AttributeError: pass try: D = PMT_ADD(D, PSTR("track"), PDBL(fixobj.true_track)) except AttributeError: pass try: if fixobj.spd_over_grnd_kmph is not None: D = PMT_ADD(D, PSTR("speed"), PDBL(fixobj.spd_over_grnd_kmph)) except AttributeError: pass try: self.nmea_time = dt.combine(fixobj.datestamp, fixobj.timestamp) D = PMT_ADD(D, PSTR("gps_time"), PSTR(str(self.nmea_time))) except AttributeError: pass # Send the message if D: self.message_port_pub(pmt.intern('gps_msg'), pmt.cons(D, pmt.PMT_NIL))
def __init__(self, tb, plot_vec_len): gr.sync_block.__init__(self, name="plotter_f", in_sig=[(np.float32, plot_vec_len)], out_sig=None) self.tb = tb self.max_bin = tb.cfg.max_plotted_bin # crop plotted data to span self.plot_iface = tb.plot_iface self.plot_iface.redraw_plot.set() self.signal = pmt.from_bool(False) self.port_name = pmt.intern("gui_busy_notifier") self.message_port_register_out(self.port_name)
def variable_changed(self, value): try: if type(value) == float: p = pmt.from_double(value) elif type(value) == int: p = pmt.from_long(value) elif type(value) == bool: p = pmt.from_bool(value) elif type(value) == str: p = pmt.intern(value) else: p = pmt.to_pmt(value) self.message_port_pub(pmt.intern("msgout"), pmt.cons(pmt.intern(self.pairname), p)) except Exception as e: gr.log.error("Unable to convert " + repr(value) + " to PDU, no message will be emitted (reason: %s)" % repr(e))
def phy_tag(offset=0, key='phy', nitems=0, rate=0, flag=0, rx_time=0, payload_sample_index=0): tag = gr.python_to_tag({ 'offset': offset, 'key': pmt.intern(key), 'srcid': pmt.from_bool(False), 'value': phy_tag_create(nitems=nitems, rate=rate, flag=flag, rx_time=rx_time, payload_sample_index=payload_sample_index) }) return tag
def test_005_all_header_fields(self): emitter = pdu_utils.message_emitter() fields = 'field0(string),field1(bool),field2(long),field3(uint64)' + \ ',field4(float),field5(double),field6(complex)' writer = csv_writer('/tmp/file.csv', True, fields, 'uint8') # generate pdu metadata = pmt.dict_add(pmt.make_dict(), pmt.intern('field0'), pmt.intern('field0')) metadata = pmt.dict_add(metadata, pmt.intern('field1'), pmt.from_bool(True)) metadata = pmt.dict_add(metadata, pmt.intern('field2'), pmt.from_long(0)) metadata = pmt.dict_add(metadata, pmt.intern('field3'), pmt.from_uint64(0)) metadata = pmt.dict_add(metadata, pmt.intern('field4'), pmt.from_float(0.0)) metadata = pmt.dict_add(metadata, pmt.intern('field5'), pmt.from_double(0.0)) metadata = pmt.dict_add(metadata, pmt.intern('field6'), pmt.from_complex(1.0 + 1.0j)) data = pmt.init_u8vector(5, [11, 12, 13, 14, 15]) expected = pmt.cons(metadata, data) # run tb = gr.top_block() tb.msg_connect((emitter, 'msg'), (writer, 'in')) tb.start() emitter.emit(expected) time.sleep(.5) tb.stop() tb.wait() # read in csv self.assertTrue( self.check_file('/tmp/file.csv', expected, has_header=True))
def __init__(self): gr.top_block.__init__(self, "Test_idle_sendframe_receiveframe_idle") Qt.QWidget.__init__(self) self.setWindowTitle("Test_idle_sendframe_receiveframe_idle") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "Test_idle_sendframe_receiveframe_idle") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.range_rx_gain = range_rx_gain = 5 self.range_mu = range_mu = 0.6 self.timeout_duration_ms = timeout_duration_ms = 500 self.system_time_granularity_us = system_time_granularity_us = 10000 self.source_address = source_address = 1 self.self_data_info = self_data_info = pmt.to_pmt({'frame_type': 1, 'frame_index': 1, 'destination_address': 2, 'source_address': 1, 'num_resend': 3, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 200}) self.self_ack_info = self_ack_info = pmt.to_pmt({'frame_type': 2, 'frame_index': 1, 'destination_address': 2, 'source_address': 1, 'num_resend': 0, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 0}) self.samp_rate = samp_rate = 1000000 self.rx_gain = rx_gain = range_rx_gain self.rrc = rrc = firdes.root_raised_cosine(1.0, sps, 1, 0.5, 11*sps) self.reserved_field_II = reserved_field_II = 6 self.reserved_field_I = reserved_field_I = 5 self.preamble_detector_threshold = preamble_detector_threshold = 30 self.mu = mu = range_mu self.max_num_retransmission = max_num_retransmission = 5 self.max_buffer_size = max_buffer_size = 10 self.len_source_address = len_source_address = 1 self.len_reserved_field_II = len_reserved_field_II = 2 self.len_reserved_field_I = len_reserved_field_I = 2 self.len_payload_length = len_payload_length = 1 self.len_num_transmission = len_num_transmission = 1 self.len_frame_type = len_frame_type = 1 self.len_frame_index = len_frame_index = 1 self.len_destination_address = len_destination_address = 1 self.increase_index = increase_index = 1 self.frame_type = frame_type = 1 self.frame_index = frame_index = 0 self.experiment_duration_s = experiment_duration_s = 1000 self.diff_preamble_128 = diff_preamble_128 = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0,0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0,0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0][0:128] self.develop_mode_list = develop_mode_list = [0] self.destination_address = destination_address = 3 self.counter_id = counter_id = 20 self.apply_address_check = apply_address_check = 1 self.another_data_info = another_data_info = pmt.to_pmt({'frame_type': 1, 'frame_index': 1, 'destination_address': 1, 'source_address': 2, 'num_resend': 3, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 200}) self.another_ack_info = another_ack_info = pmt.to_pmt({'good_frame' : 1, 'address_check' : 1, 'header_length' : 9, 'payload_length' : 0, 'reserved_field_II' : 6, 'reserved_field_I' : 5, 'num_transmission' : 0, 'source_address' : 1, 'destination_address': 3, 'frame_index' : 22, 'frame_type' : 1}) ################################################## # Blocks ################################################## self.uhd_usrp_source_0_0 = uhd.usrp_source( ",".join(("addr=10.0.0.6", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_0_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0_0.set_center_freq(4e8, 0) self.uhd_usrp_source_0_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("addr=10.0.0.13", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(4e8, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_sink_0_0 = uhd.usrp_sink( ",".join(("addr=10.0.0.13", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), "packet_len", ) self.uhd_usrp_sink_0_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_sink_0_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0_0.set_center_freq(4e8, 0) self.uhd_usrp_sink_0_0.set_gain(0, 0) self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("addr=10.0.0.6", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), "packet_len", ) self.uhd_usrp_sink_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_center_freq(4e8, 0) self.uhd_usrp_sink_0.set_gain(0, 0) self.send_frame_0_0 = send_frame( block_id=102, constellation=gnuradio.digital.constellation_qpsk().base(), destination_address=source_address, develop_mode=1, frame_index=frame_index, frame_type=frame_type, increase_index=increase_index, len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, preamble=diff_preamble_128, reserved_field_I=reserved_field_I, reserved_field_II=reserved_field_II, samp_rate=samp_rate, source_address=destination_address, sps=sps, system_time_granularity_us=system_time_granularity_us, ) self.send_frame_0 = send_frame( block_id=2, constellation=gnuradio.digital.constellation_qpsk().base(), destination_address=destination_address, develop_mode=1, frame_index=frame_index, frame_type=frame_type, increase_index=increase_index, len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, preamble=diff_preamble_128, reserved_field_I=reserved_field_I, reserved_field_II=reserved_field_II, samp_rate=samp_rate, source_address=source_address, sps=sps, system_time_granularity_us=system_time_granularity_us, ) self.receive_frame_0_0 = receive_frame( apply_address_check=apply_address_check, block_id=3, constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode=[11], len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_num_transmission=len_num_transmission, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, matched_filter_coeff=rrc, mu=mu, my_address=source_address, preamble=diff_preamble_128, rx_gain=rx_gain, samp_rate=samp_rate, sps=sps, threshold=preamble_detector_threshold, ) self.receive_frame_0 = receive_frame( apply_address_check=apply_address_check, block_id=103, constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode=[11], len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_num_transmission=len_num_transmission, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, matched_filter_coeff=rrc, mu=mu, my_address=destination_address, preamble=diff_preamble_128, rx_gain=rx_gain, samp_rate=samp_rate, sps=sps, threshold=preamble_detector_threshold, ) self._range_rx_gain_range = Range(0, 60, 1, 5, 200) self._range_rx_gain_win = RangeWidget(self._range_rx_gain_range, self.set_range_rx_gain, "Rx Gain", "counter_slider", float) self.top_grid_layout.addWidget(self._range_rx_gain_win, 1,0,1,1) self._range_mu_range = Range(0, 1, 0.01, 0.6, 200) self._range_mu_win = RangeWidget(self._range_mu_range, self.set_range_mu, "BB Derotation Gain", "counter_slider", float) self.top_grid_layout.addWidget(self._range_mu_win, 2,0,1,1) self.inets_idle_0_0 = inets.idle(1, 100, experiment_duration_s, max_num_retransmission, max_buffer_size, frame_type, len_frame_type, frame_index, len_frame_index, source_address, len_destination_address, destination_address, len_source_address, reserved_field_I, len_reserved_field_I, reserved_field_II, len_reserved_field_II, len_payload_length, increase_index, len_num_transmission) self.inets_idle_0 = inets.idle(2, 1, experiment_duration_s, max_num_retransmission, max_buffer_size, frame_type, len_frame_type, frame_index, len_frame_index, destination_address, len_destination_address, source_address, len_source_address, reserved_field_I, len_reserved_field_I, reserved_field_II, len_reserved_field_II, len_payload_length, increase_index, len_num_transmission) self.inets_frame_info_selector_0 = inets.frame_info_selector() self.frame_info_simulator = blocks.message_strobe_random(pmt.to_pmt({'good_frame' : 1, 'address_check' : 1, 'header_length' : 9, 'payload_length' : 0, 'reserved_field_II' : 6, 'reserved_field_I' : 5, 'num_transmission' : 0, 'source_address' : 1, 'destination_address': 3, 'frame_index' : 22, 'frame_type' : 1}), blocks.STROBE_POISSON, 2000, 1000) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", "localhost", "52001", 10000, False) self.blocks_message_strobe_random_1 = blocks.message_strobe_random(pmt.from_bool(True), blocks.STROBE_POISSON, 2000, 5) ################################################## # Connections ################################################## self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.inets_idle_0, 'data_in')) self.msg_connect((self.inets_frame_info_selector_0, 'data_frame_info_out'), (self.inets_idle_0, 'data_in')) self.msg_connect((self.inets_idle_0, 'data_out'), (self.send_frame_0, 'in')) self.msg_connect((self.inets_idle_0_0, 'data_out'), (self.send_frame_0_0, 'in')) self.msg_connect((self.receive_frame_0, 'rx_frame_info_out'), (self.inets_idle_0_0, 'data_in')) self.msg_connect((self.receive_frame_0_0, 'rx_frame_info_out'), (self.inets_frame_info_selector_0, 'frame_info_in')) self.connect((self.send_frame_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.send_frame_0_0, 0), (self.uhd_usrp_sink_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.receive_frame_0, 0)) self.connect((self.uhd_usrp_source_0_0, 0), (self.receive_frame_0_0, 0))
def trigger_tag_create(state=True, sample_index=0): return pmt.make_tuple(pmt.from_bool(state), pmt.from_long(sample_index))
def make_header(options, filename): extras_present = False if options.freq is not None: extras_present = True # Open the file and make the header hdr_filename = filename + '.hdr' hdr_file = open(hdr_filename, 'wb') header = pmt.make_dict() # Fill in header vals # TODO - Read this from blocks.METADATA_VERSION ver_val = pmt.from_long(long(0)) rate_val = pmt.from_double(options.sample_rate) time_val = pmt.make_tuple(pmt.from_uint64(options.time_sec), pmt.from_double(options.time_fsec)) ft_to_sz = parse_file_metadata.ftype_to_size # Map shortname to properties enum_type = SNAME_TO_ENUM[options.format] type_props = SNAME_DEFS[enum_type] size_val = pmt.from_long(type_props[0]) cplx_val = pmt.from_bool(type_props[1]) type_val = pmt.from_long(type_props[2]) fmt = type_props[2] file_samp_len = long(options.length) seg_size = long(options.seg_size) bytes_val = pmt.from_uint64(long(seg_size*ft_to_sz[fmt])) # Set header vals header = pmt.dict_add(header, pmt.intern("version"), ver_val) header = pmt.dict_add(header, pmt.intern("size"), size_val) header = pmt.dict_add(header, pmt.intern("type"), type_val) header = pmt.dict_add(header, pmt.intern("cplx"), cplx_val) header = pmt.dict_add(header, pmt.intern("rx_time"), time_val) header = pmt.dict_add(header, pmt.intern("rx_rate"), rate_val) header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val) if extras_present: freq_key = pmt.intern("rx_freq") freq_val = pmt.from_double(options.freq) extras = pmt.make_dict() extras = pmt.dict_add(extras, freq_key, freq_val) extras_str = pmt.serialize_str(extras) start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE + len(extras_str)) else: start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE) header = pmt.dict_add(header, pmt.intern("strt"), start_val) num_segments = file_samp_len/seg_size if options.verbose: print "Wrote %d headers to: %s (Version %d)" % (num_segments+1, hdr_filename,pmt.to_long(ver_val)) for x in range(0,num_segments,1): # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) # Update header based on sample rate and segment size header = update_timestamp(header,seg_size) # Last header is special b/c file size is probably not mult. of seg_size header = pmt.dict_delete(header,pmt.intern("bytes")) bytes_remaining = ft_to_sz[fmt]*(file_samp_len - num_segments*long(seg_size)) bytes_val = pmt.from_uint64(bytes_remaining) header = pmt.dict_add(header,pmt.intern("bytes"),bytes_val) # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) hdr_file.close()
def make_header(options, filename): extras_present = False if options.freq is not None: extras_present = True # Open the file and make the header hdr_filename = filename + '.hdr' hdr_file = open(hdr_filename, 'wb') header = pmt.make_dict() # Fill in header vals # TODO - Read this from blocks.METADATA_VERSION ver_val = pmt.from_long(long(0)) rate_val = pmt.from_double(options.sample_rate) time_val = pmt.make_tuple(pmt.from_uint64(options.time_sec), pmt.from_double(options.time_fsec)) ft_to_sz = parse_file_metadata.ftype_to_size # Map shortname to properties enum_type = SNAME_TO_ENUM[options.format] type_props = SNAME_DEFS[enum_type] size_val = pmt.from_long(type_props[0]) cplx_val = pmt.from_bool(type_props[1]) type_val = pmt.from_long(type_props[2]) fmt = type_props[2] file_samp_len = long(options.length) seg_size = long(options.seg_size) bytes_val = pmt.from_uint64(long(seg_size * ft_to_sz[fmt])) # Set header vals header = pmt.dict_add(header, pmt.intern("version"), ver_val) header = pmt.dict_add(header, pmt.intern("size"), size_val) header = pmt.dict_add(header, pmt.intern("type"), type_val) header = pmt.dict_add(header, pmt.intern("cplx"), cplx_val) header = pmt.dict_add(header, pmt.intern("rx_time"), time_val) header = pmt.dict_add(header, pmt.intern("rx_rate"), rate_val) header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val) if extras_present: freq_key = pmt.intern("rx_freq") freq_val = pmt.from_double(options.freq) extras = pmt.make_dict() extras = pmt.dict_add(extras, freq_key, freq_val) extras_str = pmt.serialize_str(extras) start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE + len(extras_str)) else: start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE) header = pmt.dict_add(header, pmt.intern("strt"), start_val) num_segments = file_samp_len / seg_size if options.verbose: print "Wrote %d headers to: %s (Version %d)" % ( num_segments + 1, hdr_filename, pmt.to_long(ver_val)) for x in range(0, num_segments, 1): # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) # Update header based on sample rate and segment size header = update_timestamp(header, seg_size) # Last header is special b/c file size is probably not mult. of seg_size header = pmt.dict_delete(header, pmt.intern("bytes")) bytes_remaining = ft_to_sz[fmt] * (file_samp_len - num_segments * long(seg_size)) bytes_val = pmt.from_uint64(bytes_remaining) header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val) # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) hdr_file.close()
def __init__(self): gr.top_block.__init__(self, "aloha") Qt.QWidget.__init__(self) self.setWindowTitle("aloha") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "aloha") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.range_rx_gain = range_rx_gain = 5 self.range_mu = range_mu = 0.6 self.usrp_device_address = usrp_device_address = "addr=10.0.0.6" self.timeout_duration_ms = timeout_duration_ms = 500 self.system_time_granularity_us = system_time_granularity_us = 1000 self.source_address = source_address = 1 self.self_data_info = self_data_info = pmt.to_pmt({ 'frame_type': 1, 'frame_index': 1, 'destination_address': 2, 'source_address': 1, 'num_resend': 3, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 200 }) self.self_ack_info = self_ack_info = pmt.to_pmt({ 'frame_type': 2, 'frame_index': 1, 'destination_address': 2, 'source_address': 1, 'num_resend': 0, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 0 }) self.samp_rate = samp_rate = 1000000 self.rx_gain = rx_gain = range_rx_gain self.rrc = rrc = firdes.root_raised_cosine(1.0, sps, 1, 0.5, 11 * sps) self.reserved_field_II = reserved_field_II = 6 self.reserved_field_I = reserved_field_I = 5 self.preamble_detector_threshold = preamble_detector_threshold = 30 self.mu = mu = range_mu self.min_backoff_ms = min_backoff_ms = 50 self.max_num_retransmission = max_num_retransmission = 5 self.max_buffer_size = max_buffer_size = 10 self.len_source_address = len_source_address = 1 self.len_reserved_field_II = len_reserved_field_II = 2 self.len_reserved_field_I = len_reserved_field_I = 2 self.len_payload_length = len_payload_length = 1 self.len_num_transmission = len_num_transmission = 1 self.len_frame_type = len_frame_type = 1 self.len_frame_index = len_frame_index = 1 self.len_destination_address = len_destination_address = 1 self.increase_index = increase_index = 1 self.frame_type = frame_type = 1 self.frame_index = frame_index = 0 self.experiment_duration_s = experiment_duration_s = 1000 self.diff_preamble_128 = diff_preamble_128 = [ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 ][0:128] self.develop_mode_list = develop_mode_list = [0] self.destination_address = destination_address = 2 self.cs_threshold = cs_threshold = 0.005 self.cs_duration = cs_duration = 1000 self.counter_id = counter_id = 20 self.backoff_time_unit_ms = backoff_time_unit_ms = 50 self.apply_address_check = apply_address_check = 1 self.another_data_info = another_data_info = pmt.to_pmt({ 'frame_type': 1, 'frame_index': 1, 'destination_address': 1, 'source_address': 2, 'num_resend': 3, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 200 }) self.another_ack_info = another_ack_info = pmt.to_pmt({ 'good_frame': 1, 'address_check': 1, 'header_length': 9, 'payload_length': 0, 'reserved_field_II': 6, 'reserved_field_I': 5, 'num_transmission': 0, 'source_address': 1, 'destination_address': 3, 'frame_index': 22, 'frame_type': 1 }) ################################################## # Blocks ################################################## self.send_frame_0 = send_frame( block_id=2, constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode=1, preamble=diff_preamble_128, samp_rate=samp_rate, sps=sps, system_time_granularity_us=system_time_granularity_us, usrp_device_address=usrp_device_address, ) self.receive_frame_0_0 = receive_frame( apply_address_check=apply_address_check, block_id=3, constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode=[11], len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_num_transmission=len_num_transmission, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, matched_filter_coeff=rrc, mu=mu, my_address=source_address, preamble=diff_preamble_128, rx_gain=rx_gain, samp_rate=samp_rate, sps=sps, threshold=preamble_detector_threshold, usrp_device_address=usrp_device_address, ) self._range_rx_gain_range = Range(0, 60, 1, 5, 200) self._range_rx_gain_win = RangeWidget(self._range_rx_gain_range, self.set_range_rx_gain, 'Rx Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._range_rx_gain_win, 1, 0, 1, 1) self._range_mu_range = Range(0, 1, 0.01, 0.6, 200) self._range_mu_win = RangeWidget(self._range_mu_range, self.set_range_mu, 'BB Derotation Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._range_mu_win, 2, 0, 1, 1) self.inets_timeout_cpp_0 = inets.timeout_cpp( 0, 10, timeout_duration_ms, system_time_granularity_us) self.inets_idle_0 = inets.idle( 0, 1, experiment_duration_s, max_num_retransmission, max_buffer_size, frame_type, len_frame_type, frame_index, len_frame_index, destination_address, len_destination_address, source_address, len_source_address, reserved_field_I, len_reserved_field_I, reserved_field_II, len_reserved_field_II, len_payload_length, increase_index, len_num_transmission) self.inets_frame_info_selector_0_0_0 = inets.frame_info_selector() self.inets_frame_info_selector_0_0 = inets.frame_info_selector() self.inets_frame_info_selector_0 = inets.frame_info_selector() self.inets_exponential_backoff_cpp_0 = inets.exponential_backoff_cpp( 0, 11, backoff_time_unit_ms, max_num_retransmission, min_backoff_ms) self.inets_counter_0_1 = inets.counter(([22]), 22) self.frame_info_simulator = blocks.message_strobe_random( pmt.to_pmt({ 'good_frame': 1, 'address_check': 1, 'header_length': 9, 'payload_length': 0, 'reserved_field_II': 6, 'reserved_field_I': 5, 'num_transmission': 0, 'source_address': 1, 'destination_address': 3, 'frame_index': 22, 'frame_type': 1 }), blocks.STROBE_POISSON, 2000, 1000) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", 'localhost', '52001', 10000, False) self.blocks_message_strobe_random_1 = blocks.message_strobe_random( pmt.from_bool(True), blocks.STROBE_POISSON, 2000, 5) ################################################## # Connections ################################################## self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.inets_idle_0, 'data_in')) self.msg_connect( (self.inets_exponential_backoff_cpp_0, 'frame_info_out'), (self.inets_idle_0, 'data_in')) self.msg_connect( (self.inets_frame_info_selector_0, 'data_frame_info_out'), (self.inets_idle_0, 'data_in')) self.msg_connect( (self.inets_frame_info_selector_0, 'ack_frame_info_out'), (self.inets_timeout_cpp_0, 'ack_frame_info_in')) self.msg_connect( (self.inets_frame_info_selector_0_0, 'data_frame_info_out'), (self.inets_timeout_cpp_0, 'data_frame_info_in')) self.msg_connect( (self.inets_frame_info_selector_0_0_0, 'data_frame_info_out'), (self.inets_exponential_backoff_cpp_0, 'frame_info_trigger_in')) self.msg_connect( (self.inets_frame_info_selector_0_0_0, 'ack_frame_info_out'), (self.inets_idle_0, 'data_in')) self.msg_connect((self.inets_idle_0, 'successful_transmission'), (self.inets_counter_0_1, 'message_in')) self.msg_connect((self.inets_idle_0, 'data_out'), (self.send_frame_0, 'in')) self.msg_connect( (self.inets_timeout_cpp_0, 'frame_info_out'), (self.inets_frame_info_selector_0_0_0, 'frame_info_in')) self.msg_connect((self.receive_frame_0_0, 'rx_frame_info_out'), (self.inets_frame_info_selector_0, 'frame_info_in')) self.msg_connect((self.send_frame_0, 'tx_frame_info_out'), (self.inets_frame_info_selector_0_0, 'frame_info_in'))
def __init__(self, apply_address_check=1, destination_address=3, frame_index=2, frame_type=1, increase_index=1, len_destination_address=1, len_frame_index=1, len_frame_type=1, len_payload_length=1, len_reserved_field_I=2, len_reserved_field_II=2, len_source_address=1, reserved_field_I=5, reserved_field_II=6, source_address=4, system_time_granularity_us=5): gr.top_block.__init__(self, "Test tx rx") Qt.QWidget.__init__(self) self.setWindowTitle("Test tx rx") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "Test_tx_rx") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.apply_address_check = apply_address_check self.destination_address = destination_address self.frame_index = frame_index self.frame_type = frame_type self.increase_index = increase_index self.len_destination_address = len_destination_address self.len_frame_index = len_frame_index self.len_frame_type = len_frame_type self.len_payload_length = len_payload_length self.len_reserved_field_I = len_reserved_field_I self.len_reserved_field_II = len_reserved_field_II self.len_source_address = len_source_address self.reserved_field_I = reserved_field_I self.reserved_field_II = reserved_field_II self.source_address = source_address self.system_time_granularity_us = system_time_granularity_us ################################################## # Variables ################################################## self.sps = sps = 4 self.range_rx_gain = range_rx_gain = 15 self.range_mu = range_mu = 0.6 self.threshold = threshold = 40 self.samp_rate = samp_rate = 4e6 self.rx_gain = rx_gain = range_rx_gain self.rrc = rrc = firdes.root_raised_cosine(1.0, sps, 1, 0.5, 11*sps) self.range_noise = range_noise = 0 self.qpsk_mod = qpsk_mod = gnuradio.digital.constellation_qpsk().base() self.preamble = preamble = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0,0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0,0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0] self.mu = mu = range_mu self.max_num_retransmission = max_num_retransmission = 5 self.max_buffer_size = max_buffer_size = 10 self.len_num_transmission = len_num_transmission = 1 self.experiment_duration_s = experiment_duration_s = 1000 self.diff_preamble_256 = diff_preamble_256 = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0,0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0,0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0] self.diff_preamble_128 = diff_preamble_128 = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0,0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0,0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0][0:128] self.develop_mode_list = develop_mode_list = [0] self.bpsk_mod = bpsk_mod = gnuradio.digital.constellation_bpsk().base() ################################################## # Blocks ################################################## self.tab = Qt.QTabWidget() self.tab_widget_0 = Qt.QWidget() self.tab_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_0) self.tab_grid_layout_0 = Qt.QGridLayout() self.tab_layout_0.addLayout(self.tab_grid_layout_0) self.tab.addTab(self.tab_widget_0, 'TX') self.tab_widget_1 = Qt.QWidget() self.tab_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_1) self.tab_grid_layout_1 = Qt.QGridLayout() self.tab_layout_1.addLayout(self.tab_grid_layout_1) self.tab.addTab(self.tab_widget_1, 'RX') self.tab_widget_2 = Qt.QWidget() self.tab_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_2) self.tab_grid_layout_2 = Qt.QGridLayout() self.tab_layout_2.addLayout(self.tab_grid_layout_2) self.tab.addTab(self.tab_widget_2, 'Demod') self.top_layout.addWidget(self.tab) self.send_frame_0 = send_frame( constellation=gnuradio.digital.constellation_qpsk().base(), destination_address=destination_address, develop_mode_list=develop_mode_list, frame_index=frame_index, frame_type=frame_type, increase_index=increase_index, len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, preamble=diff_preamble_128, reserved_field_I=reserved_field_I, reserved_field_II=reserved_field_II, samp_rate=samp_rate, source_address=source_address, sps=sps, system_time_granularity_us=system_time_granularity_us, ) self.receive_frame_0 = receive_frame( apply_address_check=apply_address_check, constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode_list=[10], len_destination_address=len_destination_address, len_frame_index=len_frame_index, len_frame_type=len_frame_type, len_payload_length=len_payload_length, len_reserved_field_I=len_reserved_field_I, len_reserved_field_II=len_reserved_field_II, len_source_address=len_source_address, matched_filter_coeff=rrc, mu=mu, my_address=destination_address, preamble=diff_preamble_128, rx_gain=rx_gain, samp_rate=samp_rate, sps=sps, threshold=30, ) self._range_rx_gain_range = Range(0, 60, 1, 15, 200) self._range_rx_gain_win = RangeWidget(self._range_rx_gain_range, self.set_range_rx_gain, 'Rx Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._range_rx_gain_win, 1,0,1,1) self._range_noise_range = Range(0, 0.01, 0.00001, 0, 200) self._range_noise_win = RangeWidget(self._range_noise_range, self.set_range_noise, 'noise', "counter_slider", float) self.top_layout.addWidget(self._range_noise_win) self._range_mu_range = Range(0, 1, 0.01, 0.6, 200) self._range_mu_win = RangeWidget(self._range_mu_range, self.set_range_mu, 'BB Derotation Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._range_mu_win, 2,0,1,1) self.inets_null_message_source_0 = inets.null_message_source() self.inets_message_tomb_0 = inets.message_tomb() self.inets_idle_0 = inets.idle((develop_mode_list), experiment_duration_s, max_num_retransmission, max_buffer_size, frame_type, len_frame_type, frame_index, len_frame_index, destination_address, len_destination_address, source_address, len_source_address, reserved_field_I, len_reserved_field_I, reserved_field_II, len_reserved_field_II, len_payload_length, increase_index, len_num_transmission) self.blocks_socket_pdu_0_0 = blocks.socket_pdu("UDP_SERVER", 'localhost', '52001', 10000, False) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", 'localhost', '52001', 10000, False) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_message_strobe_random_0 = blocks.message_strobe_random(pmt.from_bool(True), blocks.STROBE_POISSON, 10000, 5000) self.blocks_message_strobe_0_0 = blocks.message_strobe(pmt.from_bool(True), 1000) self.blocks_message_debug_0_0 = blocks.message_debug() ################################################## # Connections ################################################## self.msg_connect((self.blocks_message_strobe_random_0, 'strobe'), (self.receive_frame_0, 'rx_switch_in')) self.msg_connect((self.blocks_socket_pdu_0_0, 'pdus'), (self.inets_idle_0, 'data_in')) self.msg_connect((self.inets_idle_0, 'successful_transmission'), (self.inets_message_tomb_0, 'message_in')) self.msg_connect((self.inets_idle_0, 'data_out'), (self.send_frame_0, 'in')) self.msg_connect((self.inets_null_message_source_0, 'null_message_out'), (self.inets_idle_0, 'reset_idle')) self.msg_connect((self.receive_frame_0, 'rx_frame_info_out'), (self.blocks_message_debug_0_0, 'print')) self.msg_connect((self.send_frame_0, 'tx_frame_info_out'), (self.inets_message_tomb_0, 'message_in')) self.connect((self.send_frame_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.send_frame_0, 0), (self.receive_frame_0, 0))
def __init__(self): gr.top_block.__init__(self, "Radio Test AP") Qt.QWidget.__init__(self) self.setWindowTitle("Radio Test AP") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "radio_test_ap") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.range_rx_gain = range_rx_gain = 15 self.range_mu = range_mu = 0.6 self.threshold = threshold = 40 self.samp_rate = samp_rate = 4e6 self.rx_gain = rx_gain = range_rx_gain self.rrc = rrc = firdes.root_raised_cosine(1.0, sps, 1, 0.5, 11 * sps) self.range_noise = range_noise = 0 self.qpsk_mod = qpsk_mod = gnuradio.digital.constellation_qpsk().base() self.preamble = preamble = [ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 ] self.mu = mu = range_mu self.max_buffer_size = max_buffer_size = 1 self.diff_preamble_256 = diff_preamble_256 = [ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 ] self.diff_preamble_128 = diff_preamble_128 = [ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 ][0:128] self.develop_mode = develop_mode = 1 self.bpsk_mod = bpsk_mod = gnuradio.digital.constellation_bpsk().base() ################################################## # Blocks ################################################## self.tab = Qt.QTabWidget() self.tab_widget_0 = Qt.QWidget() self.tab_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_0) self.tab_grid_layout_0 = Qt.QGridLayout() self.tab_layout_0.addLayout(self.tab_grid_layout_0) self.tab.addTab(self.tab_widget_0, 'TX') self.tab_widget_1 = Qt.QWidget() self.tab_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_1) self.tab_grid_layout_1 = Qt.QGridLayout() self.tab_layout_1.addLayout(self.tab_grid_layout_1) self.tab.addTab(self.tab_widget_1, 'RX') self.tab_widget_2 = Qt.QWidget() self.tab_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_2) self.tab_grid_layout_2 = Qt.QGridLayout() self.tab_layout_2.addLayout(self.tab_grid_layout_2) self.tab.addTab(self.tab_widget_2, 'Demod') self.top_layout.addWidget(self.tab) self.send_frame_0 = send_frame( constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode=2, preamble=[], samp_rate=4e6, sps=4, system_time_granularity_us=5, ) self.receive_frame_0 = receive_frame( constellation=gnuradio.digital.constellation_qpsk().base(), develop_mode=1, matched_filter_coeff=(), mu=0, preamble=(), rx_gain=25, samp_rate=0, sps=16, threshold=30, ) self._range_rx_gain_range = Range(0, 60, 1, 15, 200) self._range_rx_gain_win = RangeWidget(self._range_rx_gain_range, self.set_range_rx_gain, 'Rx Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._range_rx_gain_win, 1, 0, 1, 1) self._range_noise_range = Range(0, 0.01, 0.00001, 0, 200) self._range_noise_win = RangeWidget(self._range_noise_range, self.set_range_noise, 'noise', "counter_slider", float) self.top_layout.addWidget(self._range_noise_win) self._range_mu_range = Range(0, 1, 0.01, 0.6, 200) self._range_mu_win = RangeWidget(self._range_mu_range, self.set_range_mu, 'BB Derotation Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._range_mu_win, 2, 0, 1, 1) self.inets_tx_buffer_0 = inets.tx_buffer(develop_mode, max_buffer_size, 1) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", 'localhost', '52001', 10000, False) self.blocks_null_sink_0_0_0_1 = blocks.null_sink(gr.sizeof_float * 1) self.blocks_null_sink_0_0_0_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.blocks_null_sink_0_0_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.blocks_null_sink_0_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.blocks_message_strobe_0_0 = blocks.message_strobe( pmt.from_bool(True), 1000) self.blocks_message_strobe_0 = blocks.message_strobe( pmt.from_bool(True), 1000) self.blocks_message_debug_0_0_0 = blocks.message_debug() self.blocks_message_debug_0_0 = blocks.message_debug() self.blocks_message_debug_0 = blocks.message_debug() ################################################## # Connections ################################################## self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.receive_frame_0, 'rx_switch_in')) self.msg_connect((self.blocks_message_strobe_0_0, 'strobe'), (self.inets_tx_buffer_0, 'spark_in')) self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.inets_tx_buffer_0, 'payload_in')) self.msg_connect((self.inets_tx_buffer_0, 'payload_out'), (self.send_frame_0, 'in')) self.msg_connect((self.receive_frame_0, 'out'), (self.blocks_message_debug_0_0, 'print')) self.msg_connect((self.receive_frame_0, 'snr'), (self.blocks_message_debug_0_0_0, 'print')) self.msg_connect((self.send_frame_0, 'message_out'), (self.blocks_message_debug_0, 'print')) self.connect((self.receive_frame_0, 3), (self.blocks_null_sink_0_0, 0)) self.connect((self.receive_frame_0, 1), (self.blocks_null_sink_0_0_0, 0)) self.connect((self.receive_frame_0, 0), (self.blocks_null_sink_0_0_0_0, 0)) self.connect((self.receive_frame_0, 2), (self.blocks_null_sink_0_0_0_1, 0)) self.connect((self.send_frame_0, 0), (self.receive_frame_0, 0))
def __init__(self): gr.top_block.__init__(self, "Test_idle_sendframe") Qt.QWidget.__init__(self) self.setWindowTitle("Test_idle_sendframe") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "Test_idle_sendframe") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.source_address = source_address = 1 self.self_data_info = self_data_info = pmt.to_pmt({ 'frame_type': 1, 'frame_index': 1, 'destination_address': 2, 'source_address': 1, 'num_resend': 3, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 200 }) self.self_ack_info = self_ack_info = pmt.to_pmt({ 'frame_type': 2, 'frame_index': 1, 'destination_address': 2, 'source_address': 1, 'num_resend': 0, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 0 }) self.samp_rate = samp_rate = 1000000 self.reserved_field_II = reserved_field_II = 6 self.reserved_field_I = reserved_field_I = 5 self.max_num_retransmission = max_num_retransmission = 5 self.max_buffer_size = max_buffer_size = 10 self.len_source_address = len_source_address = 1 self.len_reserved_field_II = len_reserved_field_II = 2 self.len_reserved_field_I = len_reserved_field_I = 2 self.len_payload_length = len_payload_length = 1 self.len_num_transmission = len_num_transmission = 1 self.len_frame_type = len_frame_type = 1 self.len_frame_index = len_frame_index = 1 self.len_destination_address = len_destination_address = 1 self.increase_index = increase_index = 0 self.frame_type = frame_type = 1 self.frame_index = frame_index = 1 self.experiment_duration_s = experiment_duration_s = 1000 self.develop_mode_list = develop_mode_list = [0] self.destination_address = destination_address = 3 self.counter_id = counter_id = 20 self.another_data_info = another_data_info = pmt.to_pmt({ 'frame_type': 1, 'frame_index': 1, 'destination_address': 1, 'source_address': 2, 'num_resend': 3, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 200 }) self.another_ack_info = another_ack_info = pmt.to_pmt({ 'frame_type': 2, 'frame_index': 1, 'destination_address': 1, 'source_address': 2, 'num_resend': 0, 'reserved_field_I': 1, 'reserved_field_II': 1, 'pay_load_length': 0 }) ################################################## # Blocks ################################################## self.uhd_usrp_sink_0_0 = uhd.usrp_sink( ",".join(("addr=10.0.0.13", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), "packet_len", ) self.uhd_usrp_sink_0_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_sink_0_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0_0.set_center_freq(4e8, 0) self.uhd_usrp_sink_0_0.set_gain(0, 0) self.send_frame_0 = send_frame( block_id=2, constellation=gnuradio.digital.constellation_qpsk().base(), destination_address=3, develop_mode=1, frame_index=2, frame_type=1, increase_index=1, len_destination_address=1, len_frame_index=1, len_frame_type=1, len_payload_length=1, len_reserved_field_I=2, len_reserved_field_II=2, len_source_address=1, preamble=[], reserved_field_I=5, reserved_field_II=6, samp_rate=4e6, source_address=4, sps=4, system_time_granularity_us=10, ) self.inets_message_tomb_0 = inets.message_tomb() self.inets_idle_0 = inets.idle( 2, 1, experiment_duration_s, max_num_retransmission, max_buffer_size, frame_type, len_frame_type, frame_index, len_frame_index, destination_address, len_destination_address, source_address, len_source_address, reserved_field_I, len_reserved_field_I, reserved_field_II, len_reserved_field_II, len_payload_length, increase_index, len_num_transmission) self.frame_info_simulator = blocks.message_strobe_random( another_ack_info, blocks.STROBE_POISSON, 4000, 2000) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", "localhost", "52001", 10000, False) self.blocks_message_strobe_random_0_0_0 = blocks.message_strobe_random( pmt.from_bool(True), blocks.STROBE_POISSON, 2000, 0) ################################################## # Connections ################################################## self.msg_connect((self.blocks_message_strobe_random_0_0_0, 'strobe'), (self.inets_idle_0, 'reset_idle')) self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.inets_idle_0, 'data_in')) self.msg_connect((self.inets_idle_0, 'successful_transmission'), (self.inets_message_tomb_0, 'message_in')) self.msg_connect((self.inets_idle_0, 'data_out'), (self.send_frame_0, 'in')) self.connect((self.send_frame_0, 0), (self.uhd_usrp_sink_0_0, 0))