def test_packet_format_async_counter(self): bps = 2 ac = packet_utils.default_access_code hdr_format = digital.header_format_counter(ac, 0, 2) formatter = digital.protocol_formatter_async(hdr_format) snk_hdr = blocks.message_debug() snk_pld = blocks.message_debug() self.tb.msg_connect(formatter, 'header', snk_hdr, 'store') self.tb.msg_connect(formatter, 'payload', snk_pld, 'store') send_str = "Hello World" + 1000 * "xxx" send_pmt = pmt.make_u8vector(len(send_str), ord(' ')) for i in range(len(send_str)): pmt.u8vector_set(send_pmt, i, ord(send_str[i])) msg = pmt.cons(pmt.PMT_NIL, send_pmt) port = pmt.intern("in") formatter.to_basic_block()._post(port, msg) self.tb.start() while (snk_hdr.num_messages() < 1) or (snk_pld.num_messages() < 1): time.sleep(0.1) self.tb.stop() self.tb.wait() result_hdr_pmt = pmt.cdr(snk_hdr.get_message(0)) result_pld_pmt = pmt.cdr(snk_pld.get_message(0)) result_hdr = pmt.u8vector_elements(result_hdr_pmt) result_pld = pmt.u8vector_elements(result_pld_pmt) header = "".join(chr(r) for r in result_hdr) payload = "".join(chr(r) for r in result_pld) access_code = packet_utils.conv_1_0_string_to_packed_binary_string( packet_utils.default_access_code)[0] rx_access_code = header[0:len(access_code)] length = len(send_str) rx_length = struct.unpack_from(b"!H", six.b(header), len(access_code))[0] rx_bps = struct.unpack_from(b"!H", six.b(header), len(access_code) + 4)[0] rx_counter = struct.unpack_from(b"!H", six.b(header), len(access_code) + 6)[0] self.assertEqual(access_code, rx_access_code) self.assertEqual(length, rx_length) self.assertEqual(bps, rx_bps) self.assertEqual(0, rx_counter) self.assertEqual(length, len(payload)) self.assertEqual(send_str, payload[0:length])
def test_packet_format_async_counter(self): bps = 2 ac = packet_utils.default_access_code hdr_format = digital.header_format_counter(ac, 0, 2) formatter = digital.protocol_formatter_async(hdr_format) snk_hdr = blocks.message_debug() snk_pld = blocks.message_debug() self.tb.msg_connect(formatter, 'header', snk_hdr, 'store') self.tb.msg_connect(formatter, 'payload', snk_pld, 'store') send_str = "Hello World" + 1000*"xxx" send_pmt = pmt.make_u8vector(len(send_str), ord(' ')) for i in range(len(send_str)): pmt.u8vector_set(send_pmt, i, ord(send_str[i])) msg = pmt.cons(pmt.PMT_NIL, send_pmt) port = pmt.intern("in") formatter.to_basic_block()._post(port, msg) self.tb.start() while (snk_hdr.num_messages() < 1) and (snk_pld.num_messages() < 1): time.sleep(0.1) self.tb.stop() self.tb.wait() result_hdr_pmt = pmt.cdr(snk_hdr.get_message(0)) result_pld_pmt = pmt.cdr(snk_pld.get_message(0)) result_hdr = pmt.u8vector_elements(result_hdr_pmt) result_pld = pmt.u8vector_elements(result_pld_pmt) header = "".join([chr(r) for r in result_hdr]) payload = "".join([chr(r) for r in result_pld]) access_code = packet_utils.conv_1_0_string_to_packed_binary_string(packet_utils.default_access_code)[0] rx_access_code = header[0:len(access_code)] length = len(send_str) rx_length = struct.unpack_from("!H", header, len(access_code))[0] rx_bps = struct.unpack_from("!H", header, len(access_code)+4)[0] rx_counter = struct.unpack_from("!H", header, len(access_code)+6)[0] self.assertEqual(access_code, rx_access_code) self.assertEqual(length, rx_length) self.assertEqual(bps, rx_bps) self.assertEqual(0, rx_counter) self.assertEqual(length, len(payload)) self.assertEqual(send_str, payload[0:length])
def test_packet_format_async_default(self): ac = packet_utils.default_access_code hdr_format = digital.header_format_default(ac, 0) formatter = digital.protocol_formatter_async(hdr_format) snk_hdr = blocks.message_debug() snk_pld = blocks.message_debug() self.tb.msg_connect(formatter, 'header', snk_hdr, 'store') self.tb.msg_connect(formatter, 'payload', snk_pld, 'store') send_str = b"Hello World" send_pmt = pmt.make_u8vector(len(send_str), 0) for i in range(len(send_str)): pmt.u8vector_set(send_pmt, i, send_str[i]) msg = pmt.cons(pmt.PMT_NIL, send_pmt) port = pmt.intern("in") formatter.to_basic_block()._post(port, msg) self.tb.start() while (snk_hdr.num_messages() < 1) or (snk_pld.num_messages() < 1): time.sleep(0.1) self.tb.stop() self.tb.wait() result_hdr_pmt = pmt.cdr(snk_hdr.get_message(0)) result_pld_pmt = pmt.cdr(snk_pld.get_message(0)) result_hdr = pmt.u8vector_elements(result_hdr_pmt) result_pld = pmt.u8vector_elements(result_pld_pmt) header = bytes(result_hdr) payload = bytes(result_pld) access_code = packet_utils.default_access_code_binary rx_access_code = header[0:len(access_code)] length = len(send_str) rx_length = struct.unpack_from(b"!H", header, len(access_code))[0] self.assertEqual(access_code, rx_access_code) self.assertEqual(length, rx_length) self.assertEqual(length, len(payload)) self.assertEqual(send_str, payload[0:length])
def __init__(self): gr.top_block.__init__(self, "Tx Stage6") Qt.QWidget.__init__(self) self.setWindowTitle("Tx Stage6") 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", "tx_stage6") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.nfilts = nfilts = 32 self.eb = eb = 0.22 self.psf_taps = psf_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0, eb, 15*sps*nfilts) self.thresh = thresh = 3 self.taps_per_filt = taps_per_filt = len(psf_taps)/nfilts self.pld_const = pld_const = digital.constellation_calcdist((digital.psk_2()[0]), (digital.psk_2()[1]), 2, 1).base() self.pld_const.gen_soft_dec_lut(8) self.hdr_format = hdr_format = digital.header_format_default(digital.packet_utils.default_access_code, thresh) self.hdr_const = hdr_const = digital.constellation_calcdist((digital.psk_2()[0]), (digital.psk_2()[1]), 2, 1).base() self.hdr_const.gen_soft_dec_lut(8) self.filt_delay = filt_delay = 1+(taps_per_filt-1)/2 self.bps = bps = pld_const.bits_per_symbol() ################################################## # 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, 'Time') 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, 'Freq') self.top_layout.addWidget(self.tab) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 400*sps, #size sps, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.01) self.qtgui_time_sink_x_0.set_y_axis(-2, 2) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_TAG, qtgui.TRIG_SLOPE_POS, 0.0, 15, 0, 'packet_len') self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) if not False: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.tab_layout_0.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc sps, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.tab_layout_1.addWidget(self._qtgui_freq_sink_x_0_win) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf( sps, taps=(psf_taps), flt_size=nfilts) self.pfb_arb_resampler_xxx_0.declare_sample_delay(filt_delay) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + 'hackrf=0' ) self.osmosdr_sink_0.set_sample_rate(32) self.osmosdr_sink_0.set_center_freq(144e6, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(10, 0) self.osmosdr_sink_0.set_if_gain(20, 0) self.osmosdr_sink_0.set_bb_gain(20, 0) self.osmosdr_sink_0.set_antenna('ant0', 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.digital_protocol_formatter_async_0 = digital.protocol_formatter_async(hdr_format) self.digital_map_bb_1_0 = digital.map_bb((pld_const.pre_diff_code())) self.digital_map_bb_1 = digital.map_bb((hdr_const.pre_diff_code())) self.digital_crc32_async_bb_1 = digital.crc32_async_bb(False) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc((pld_const.points()), 1) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((hdr_const.points()), 1) self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, 'packet_len', 0) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", '127.0.0.1', '52001', 10, False) self.blocks_repack_bits_bb_0_0 = blocks.repack_bits_bb(8, pld_const.bits_per_symbol(), 'packet_len', False, gr.GR_MSB_FIRST) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, hdr_const.bits_per_symbol(), 'packet_len', False, gr.GR_MSB_FIRST) self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len') self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len') self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((.5, )) ################################################## # Connections ################################################## self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.digital_crc32_async_bb_1, 'in')) self.msg_connect((self.digital_crc32_async_bb_1, 'out'), (self.digital_protocol_formatter_async_0, 'in')) self.msg_connect((self.digital_protocol_formatter_async_0, 'payload'), (self.blocks_pdu_to_tagged_stream_0, 'pdus')) self.msg_connect((self.digital_protocol_formatter_async_0, 'header'), (self.blocks_pdu_to_tagged_stream_0_0, 'pdus')) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.blocks_repack_bits_bb_0_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_map_bb_1, 0)) self.connect((self.blocks_repack_bits_bb_0_0, 0), (self.digital_map_bb_1_0, 0)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.blocks_tagged_stream_mux_0, 1)) self.connect((self.digital_map_bb_1, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_map_bb_1_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.qtgui_time_sink_x_0, 0))
def __init__(self, freq): gr.top_block.__init__(self, "Burst Transmitter") ################################################## # Variables ################################################## self.tsh = tsh = 0 self.sps = sps = 4 self.nfilts = nfilts = 64 self.eb = eb = .700 self.usrp_rate = usrp_rate = 500e3 self.psf_taps = psf_taps = firdes.root_raised_cosine( nfilts / 1.5, nfilts, 1.0, eb, 5 * sps * nfilts) self.pld_cons = pld_cons = digital.constellation_calcdist( ([-1, 1]), ([0, 1]), 4, 1).base() self.hdr_cons = hdr_cons = digital.constellation_calcdist( ([-1, 1]), ([0, 1]), 2, 1).base() self.freq = freq self.format_0 = format_0 = digital.header_format_default( digital.packet_utils.default_access_code, tsh) self.b_ntaps = b_ntaps = 50 ################################################## # Blocks ################################################## self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), "packet_len", ) self.uhd_usrp_sink_0.set_samp_rate(usrp_rate) self.uhd_usrp_sink_0.set_center_freq(freq, 0) self.uhd_usrp_sink_0.set_gain(0, 0) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(sps, taps=(psf_taps), flt_size=nfilts) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, usrp_rate, usrp_rate / sps * 1.4, 10e3, firdes.WIN_KAISER, 6.76)) self.digital_protocol_formatter_async_0 = digital.protocol_formatter_async( format_0) self.digital_map_bb_0_0 = digital.map_bb((pld_cons.pre_diff_code())) self.digital_map_bb_0 = digital.map_bb((hdr_cons.pre_diff_code())) self.digital_diff_encoder_bb_0_0 = digital.diff_encoder_bb( pld_cons.arity()) self.digital_crc32_async_bb_0 = digital.crc32_async_bb(False) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc( (pld_cons.points()), pld_cons.dimensionality()) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (hdr_cons.points()), hdr_cons.dimensionality()) self.digital_burst_shaper_xx_0 = digital.burst_shaper_cc( (firdes.window(firdes.WIN_HANN, b_ntaps, 0)), 10, 20, True, "packet_len") self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux( gr.sizeof_gr_complex * 1, "packet_len", 0) self.blocks_tagged_stream_multiply_length_0 = blocks.tagged_stream_multiply_length( gr.sizeof_gr_complex * 1, "packet_len", sps) self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", '127.0.0.1', '52001', 10000, False) self.blocks_repack_bits_bb_2 = blocks.repack_bits_bb( 8, 1, "packet_len", False, gr.GR_MSB_FIRST) self.blocks_repack_bits_bb_1 = blocks.repack_bits_bb( 8, 1, "packet_len", False, gr.GR_MSB_FIRST) self.blocks_pdu_to_tagged_stream_1_0 = blocks.pdu_to_tagged_stream( blocks.byte_t, "packet_len") self.blocks_pdu_to_tagged_stream_1 = blocks.pdu_to_tagged_stream( blocks.byte_t, "packet_len") ################################################## # Connections ################################################## self.msg_connect((self.blocks_socket_pdu_0, 'pdus'), (self.digital_crc32_async_bb_0, 'in')) self.msg_connect((self.digital_crc32_async_bb_0, 'out'), (self.digital_protocol_formatter_async_0, 'in')) self.msg_connect((self.digital_protocol_formatter_async_0, 'payload'), (self.blocks_pdu_to_tagged_stream_1, 'pdus')) self.msg_connect((self.digital_protocol_formatter_async_0, 'header'), (self.blocks_pdu_to_tagged_stream_1_0, 'pdus')) self.connect((self.blocks_pdu_to_tagged_stream_1, 0), (self.blocks_repack_bits_bb_2, 0)) self.connect((self.blocks_pdu_to_tagged_stream_1_0, 0), (self.blocks_repack_bits_bb_1, 0)) self.connect((self.blocks_repack_bits_bb_1, 0), (self.digital_map_bb_0, 0)) self.connect((self.blocks_repack_bits_bb_2, 0), (self.digital_map_bb_0_0, 0)) self.connect((self.blocks_tagged_stream_multiply_length_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self.digital_burst_shaper_xx_0, 0)) self.connect((self.digital_burst_shaper_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.blocks_tagged_stream_mux_0, 1)) self.connect((self.digital_diff_encoder_bb_0_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.digital_map_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_map_bb_0_0, 0), (self.digital_diff_encoder_bb_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_tagged_stream_multiply_length_0, 0))
def __init__(self, hdr_const=digital.constellation_calcdist( (digital.psk_2()[0]), (digital.psk_2()[1]), 2, 1).base(), hdr_enc=fec.dummy_encoder_make(8000), hdr_format=digital.header_format_default( digital.packet_utils.default_access_code, 0), pld_const=digital.constellation_calcdist( (digital.psk_2()[0]), (digital.psk_2()[1]), 2, 1).base(), pld_enc=fec.dummy_encoder_make(8000), psf_taps=[ 0, ], sps=2): gr.hier_block2.__init__( self, "Packet Tx", gr.io_signature(0, 0, 0), gr.io_signaturev(3, 3, [ gr.sizeof_gr_complex * 1, gr.sizeof_gr_complex * 1, gr.sizeof_gr_complex * 1 ]), ) self.message_port_register_hier_in("in") self.message_port_register_hier_out("postcrc") ################################################## # Parameters ################################################## self.hdr_const = hdr_const self.hdr_enc = hdr_enc self.hdr_format = hdr_format self.pld_const = pld_const self.pld_enc = pld_enc self.psf_taps = psf_taps self.sps = sps ################################################## # Variables ################################################## self.nfilts = nfilts = 32 self.taps_per_filt = taps_per_filt = len(psf_taps) / nfilts self.filt_delay = filt_delay = int(1 + (taps_per_filt - 1) // 2) ################################################## # Blocks ################################################## self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(sps, taps=psf_taps, flt_size=nfilts) self.pfb_arb_resampler_xxx_0.declare_sample_delay(filt_delay) self.fec_async_encoder_0_0 = fec.async_encoder(hdr_enc, True, False, False, 1500) self.fec_async_encoder_0 = fec.async_encoder(pld_enc, True, False, False, 1500) self.digital_protocol_formatter_async_0 = digital.protocol_formatter_async( hdr_format) self.digital_map_bb_1_0 = digital.map_bb(pld_const.pre_diff_code()) self.digital_map_bb_1 = digital.map_bb(hdr_const.pre_diff_code()) self.digital_crc32_async_bb_1 = digital.crc32_async_bb(False) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc( pld_const.points(), 1) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( hdr_const.points(), 1) self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux( gr.sizeof_gr_complex * 1, 'packet_len', 0) self.blocks_tagged_stream_multiply_length_0 = blocks.tagged_stream_multiply_length( gr.sizeof_gr_complex * 1, 'packet_len', sps) self.blocks_repack_bits_bb_0_0 = blocks.repack_bits_bb( 8, pld_const.bits_per_symbol(), 'packet_len', False, gr.GR_MSB_FIRST) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb( 8, hdr_const.bits_per_symbol(), 'packet_len', False, gr.GR_MSB_FIRST) self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream( blocks.byte_t, 'packet_len') self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream( blocks.byte_t, 'packet_len') ################################################## # Connections ################################################## self.msg_connect((self.digital_crc32_async_bb_1, 'out'), (self.fec_async_encoder_0, 'in')) self.msg_connect((self.digital_crc32_async_bb_1, 'out'), (self, 'postcrc')) self.msg_connect((self.digital_protocol_formatter_async_0, 'payload'), (self.blocks_pdu_to_tagged_stream_0, 'pdus')) self.msg_connect((self.digital_protocol_formatter_async_0, 'header'), (self.fec_async_encoder_0_0, 'in')) self.msg_connect((self.fec_async_encoder_0, 'out'), (self.digital_protocol_formatter_async_0, 'in')) self.msg_connect((self.fec_async_encoder_0_0, 'out'), (self.blocks_pdu_to_tagged_stream_0_0, 'pdus')) self.msg_connect((self, 'in'), (self.digital_crc32_async_bb_1, 'in')) self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.blocks_repack_bits_bb_0_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_map_bb_1, 0)) self.connect((self.blocks_repack_bits_bb_0_0, 0), (self.digital_map_bb_1_0, 0)) self.connect((self.blocks_tagged_stream_multiply_length_0, 0), (self, 0)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self, 1)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self, 2)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.blocks_tagged_stream_mux_0, 1)) self.connect((self.digital_map_bb_1, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_map_bb_1_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_tagged_stream_multiply_length_0, 0))
def __init__(self): gr.top_block.__init__(self, "Evolucao") Qt.QWidget.__init__(self) self.setWindowTitle("Evolucao") 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", "evolucao") self.restoreGeometry(self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Variables ################################################## self.pld_const = pld_const = digital.constellation_calcdist((digital.psk_4()[0]), (digital.psk_4()[1]), 4, 1).base() self.pld_const.gen_soft_dec_lut(8) self.sps = sps = 2 self.rep = rep = 3 self.preamble_rep = preamble_rep = [0xe3, 0x8f, 0xc0, 0xfc, 0x7f, 0xc7, 0xe3, 0x81, 0xc0, 0xff, 0x80, 0x38, 0xff, 0xf0, 0x38, 0xe0, 0x0f, 0xc0, 0x03, 0x80, 0x00, 0xff, 0xff, 0xc0] self.preamble_dummy = preamble_dummy = [0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc] self.nfilts = nfilts = 32 self.hdr_format = hdr_format = digital.header_format_counter(digital.packet_utils.default_access_code, 3, pld_const.bits_per_symbol()) self.eb = eb = 0.22 self.tx_rrc_taps = tx_rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0, eb, 5*sps*nfilts) self.rate = rate = 2 self.preamble_select = preamble_select = {1: preamble_dummy, 3: preamble_rep} self.hdr_const = hdr_const = digital.constellation_calcdist((digital.psk_2()[0]), (digital.psk_2()[1]), 2, 1).base() self.hdr_const.gen_soft_dec_lut(8) self.dec_hdr = dec_hdr = fec.repetition_decoder.make(hdr_format.header_nbits(), rep, 0.5) self.taps_per_filt = taps_per_filt = len(tx_rrc_taps)/nfilts self.rxmod = rxmod = digital.generic_mod(hdr_const, False, sps, True, eb, False, False) self.preamble = preamble = preamble_select[int(1.0/dec_hdr.rate())] self.polys = polys = [109, 79] self.mark_delays = mark_delays = [0, 0, 34, 56, 87, 119] self.k = k = 7 self.time_offset = time_offset = 1.0 self.sps_0 = sps_0 = 2 self.samp_rate = samp_rate = 32000 self.rx_rrc_taps = rx_rrc_taps = firdes.root_raised_cosine(nfilts, nfilts*sps, 1.0, eb, 11*sps*nfilts) self.noise = noise = 0.0 self.modulated_sync_word = modulated_sync_word = digital.modulate_vector_bc(rxmod .to_basic_block(), (preamble), ([1])) self.mark_delay = mark_delay = mark_delays[sps] self.freq_offset = freq_offset = 0 self.filt_delay = filt_delay = 1+(taps_per_filt-1)/2 self.enc_hdr = enc_hdr = fec.repetition_encoder_make(8000, rep) self.enc = enc = fec.cc_encoder_make(8000, k, rate, (polys), 0, fec.CC_TERMINATED, False) self.dec = dec = fec.cc_decoder.make(8000, k, rate, (polys), 0, -1, fec.CC_TERMINATED, False) self.amp = amp = 1.0 ################################################## # Blocks ################################################## self._time_offset_range = Range(0.99, 1.01, 0.00001, 1.0, 200) self._time_offset_win = RangeWidget(self._time_offset_range, self.set_time_offset, 'Time Offset', "counter_slider", float) self.top_grid_layout.addWidget(self._time_offset_win, 0, 2, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._noise_range = Range(0, 5, 0.01, 0.0, 200) self._noise_win = RangeWidget(self._noise_range, self.set_noise, 'Noise Amp', "counter_slider", float) self.top_grid_layout.addWidget(self._noise_win, 0, 0, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._freq_offset_range = Range(-0.5, 0.5, 0.0001, 0, 200) self._freq_offset_win = RangeWidget(self._freq_offset_range, self.set_freq_offset, 'Freq. Offset', "counter_slider", float) self.top_grid_layout.addWidget(self._freq_offset_win, 0, 1, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._amp_range = Range(0, 2, 0.01, 1.0, 200) self._amp_win = RangeWidget(self._amp_range, self.set_amp, 'Amplitude', "counter_slider", float) self.top_grid_layout.addWidget(self._amp_win) self.tab1 = Qt.QTabWidget() self.tab1_widget_0 = Qt.QWidget() self.tab1_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab1_widget_0) self.tab1_grid_layout_0 = Qt.QGridLayout() self.tab1_layout_0.addLayout(self.tab1_grid_layout_0) self.tab1.addTab(self.tab1_widget_0, 'Time') self.tab1_widget_1 = Qt.QWidget() self.tab1_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab1_widget_1) self.tab1_grid_layout_1 = Qt.QGridLayout() self.tab1_layout_1.addLayout(self.tab1_grid_layout_1) self.tab1.addTab(self.tab1_widget_1, 'Freq.') self.tab1_widget_2 = Qt.QWidget() self.tab1_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab1_widget_2) self.tab1_grid_layout_2 = Qt.QGridLayout() self.tab1_layout_2.addLayout(self.tab1_grid_layout_2) self.tab1.addTab(self.tab1_widget_2, 'Const.') self.top_grid_layout.addWidget(self.tab1, 1, 2, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf( sps, taps=(tx_rrc_taps), flt_size=nfilts) self.pfb_arb_resampler_xxx_0.declare_sample_delay(filt_delay) self.fec_generic_decoder_0 = fec.decoder(dec_hdr, gr.sizeof_float, gr.sizeof_char) self.fec_async_encoder_0_0 = fec.async_encoder(enc, True, False, False, 1500) self.fec_async_encoder_0 = fec.async_encoder(enc, True, False, False, 1500) self.fec_async_decoder_0 = fec.async_decoder(dec_hdr, True, False, 1500*8) self.digital_protocol_parser_b_0 = digital.protocol_parser_b(hdr_format) self.digital_protocol_formatter_async_0 = digital.protocol_formatter_async(hdr_format) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, 6.28/400.0, (rx_rrc_taps), nfilts, nfilts/2, 1.5, 1) self.digital_map_bb_1_0 = digital.map_bb((pld_const.pre_diff_code())) self.digital_map_bb_1 = digital.map_bb((hdr_const.pre_diff_code())) self.digital_header_payload_demux_0 = digital.header_payload_demux( (hdr_format.header_nbits() * int(1.0/dec_hdr.rate())) / hdr_const.bits_per_symbol(), 1, 0, "payload symbols", "time_est", True, gr.sizeof_gr_complex, "rx_time", 1, "", 0, ) self.digital_crc32_async_bb_1 = digital.crc32_async_bb(False) self.digital_crc32_async_bb_0 = digital.crc32_async_bb(True) self.digital_costas_loop_cc_0_0_0 = digital.costas_loop_cc(6.28/200.0, pld_const.arity(), False) self.digital_costas_loop_cc_0_0 = digital.costas_loop_cc(6.28/200.0, hdr_const.arity(), False) self.digital_corr_est_cc_0 = digital.corr_est_cc((modulated_sync_word), sps, mark_delay, 0.999) self.digital_constellation_soft_decoder_cf_0_0 = digital.constellation_soft_decoder_cf(hdr_const) self.digital_constellation_soft_decoder_cf_0 = digital.constellation_soft_decoder_cf(pld_const) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc((pld_const.points()), 1) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((hdr_const.points()), 1) self.digital_burst_shaper_xx_0 = digital.burst_shaper_cc((firdes.window(firdes.WIN_HANN, 20, 0)), 0, filt_delay, True, 'packet_len') (self.digital_burst_shaper_xx_0).set_block_alias("burst_shaper0") self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise, frequency_offset=freq_offset, epsilon=time_offset, taps=(1.0, ), noise_seed=0, block_tags=True ) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True) self.blocks_tagged_stream_to_pdu_0_0 = blocks.tagged_stream_to_pdu(blocks.float_t, "payload symbols") self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, 'pacote') self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, 'packet_len', 0) self.blocks_tagged_stream_multiply_length_0_0 = blocks.tagged_stream_multiply_length(gr.sizeof_float*1, "payload symbols", pld_const.bits_per_symbol()) self.blocks_tagged_stream_multiply_length_0 = blocks.tagged_stream_multiply_length(gr.sizeof_gr_complex*1, 'packet_len', sps) self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, 100, 'pacote') self.blocks_repack_bits_bb_0_0 = blocks.repack_bits_bb(8, pld_const.bits_per_symbol(), 'packet_len', False, gr.GR_MSB_FIRST) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, hdr_const.bits_per_symbol(), 'packet_len', False, gr.GR_MSB_FIRST) self.blocks_pdu_to_tagged_stream_1 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len') self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len') self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len') self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((amp, )) self.blocks_multiply_by_tag_value_cc_0 = blocks.multiply_by_tag_value_cc("amp_est", 1) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, '/home/andre/Desktop/transmit_maior.txt', True) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_sink_0_0_0 = blocks.file_sink(gr.sizeof_char*1, '/home/andre/Desktop/transmitido/depois.txt', False) self.blocks_file_sink_0_0_0.set_unbuffered(False) ################################################## # Connections ################################################## self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'), (self.digital_crc32_async_bb_1, 'in')) self.msg_connect((self.blocks_tagged_stream_to_pdu_0_0, 'pdus'), (self.fec_async_decoder_0, 'in')) self.msg_connect((self.digital_crc32_async_bb_0, 'out'), (self.blocks_pdu_to_tagged_stream_1, 'pdus')) self.msg_connect((self.digital_crc32_async_bb_1, 'out'), (self.fec_async_encoder_0, 'in')) self.msg_connect((self.digital_protocol_formatter_async_0, 'payload'), (self.blocks_pdu_to_tagged_stream_0, 'pdus')) self.msg_connect((self.digital_protocol_formatter_async_0, 'header'), (self.fec_async_encoder_0_0, 'in')) self.msg_connect((self.digital_protocol_parser_b_0, 'info'), (self.digital_header_payload_demux_0, 'header_data')) self.msg_connect((self.fec_async_decoder_0, 'out'), (self.digital_crc32_async_bb_0, 'in')) self.msg_connect((self.fec_async_encoder_0, 'out'), (self.digital_protocol_formatter_async_0, 'in')) self.msg_connect((self.fec_async_encoder_0_0, 'out'), (self.blocks_pdu_to_tagged_stream_0_0, 'pdus')) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_multiply_by_tag_value_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.digital_corr_est_cc_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.blocks_repack_bits_bb_0_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_1, 0), (self.blocks_file_sink_0_0_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_map_bb_1, 0)) self.connect((self.blocks_repack_bits_bb_0_0, 0), (self.digital_map_bb_1_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.blocks_tagged_stream_to_pdu_0, 0)) self.connect((self.blocks_tagged_stream_multiply_length_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_tagged_stream_multiply_length_0_0, 0), (self.blocks_tagged_stream_to_pdu_0_0, 0)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self.digital_burst_shaper_xx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_tagged_stream_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.digital_burst_shaper_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.blocks_tagged_stream_mux_0, 1)) self.connect((self.digital_constellation_soft_decoder_cf_0, 0), (self.blocks_tagged_stream_multiply_length_0_0, 0)) self.connect((self.digital_constellation_soft_decoder_cf_0_0, 0), (self.fec_generic_decoder_0, 0)) self.connect((self.digital_corr_est_cc_0, 0), (self.blocks_multiply_by_tag_value_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0_0, 0), (self.digital_constellation_soft_decoder_cf_0_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.digital_constellation_soft_decoder_cf_0, 0)) self.connect((self.digital_header_payload_demux_0, 0), (self.digital_costas_loop_cc_0_0, 0)) self.connect((self.digital_header_payload_demux_0, 1), (self.digital_costas_loop_cc_0_0_0, 0)) self.connect((self.digital_map_bb_1, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_map_bb_1_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_header_payload_demux_0, 0)) self.connect((self.fec_generic_decoder_0, 0), (self.digital_protocol_parser_b_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_tagged_stream_multiply_length_0, 0))