Example #1
0
    def __init__(self):
        gr.sync_block.__init__(
            self, name="blockchain_source",
            in_sig=None, out_sig=None)

        self.message_port_register_out(pmt.intern("utx"))
        self.message_port_register_out(pmt.intern("block"))
Example #2
0
 def handle_msg(self, msg_pmt):
     msg = pmt.cdr(msg_pmt)
     if not pmt.is_u8vector(msg):
         print "[ERROR] Received invalid message type. Expected u8vector"
         return
     packet = array.array("B", pmt.u8vector_elements(msg))
     try:
         header = csp_header.CSP(packet[:4])
     except ValueError as e:
         if self.verbose:
             print e
         return
     if not self.force and not header.crc:
         if self.verbose:
             print "CRC not used"
         self.message_port_pub(pmt.intern('ok'), msg_pmt)
     else:
         if len(packet) < 8: # bytes CSP header, 4 bytes CRC-32C
             if self.verbose:
                 print "Malformed CSP packet (too short)"
             return
         crc = crc32c.crc(packet[:-4] if self.include_header else packet[4:-4])
         packet_crc = struct.unpack(">I", packet[-4:])[0]
         if crc == packet_crc:
             if self.verbose:
                 print "CRC OK"
             self.message_port_pub(pmt.intern('ok'), msg_pmt)
         else:
             if self.verbose:
                 print "CRC failed"
             self.message_port_pub(pmt.intern('fail'), msg_pmt)
Example #3
0
 def __init__(self, blkname="set_title", prefix="Title: ", parent=None):
     gr.sync_block.__init__(self,blkname,[],[])
     self.message_port_register_in(pmt.intern("name"));
     self.set_msg_handler(pmt.intern("name"), self.handler)
     self.prefix = prefix
     self.parent = parent
     self.n = ""
Example #4
0
    def test_tag_propagation(self):
        N = 10 # Block length
        stream_sizes = [1,2,3]

        expected_result     = N*(stream_sizes[0]*[1,]
                                 +stream_sizes[1]*[2,]
                                 +stream_sizes[2]*[3,])
        # check the data
        (result, tags) = self.help_stream_tag_propagation(N, stream_sizes)
        self.assertFloatTuplesAlmostEqual(expected_result, result, places=6)

        # check the tags
        expected_tag_offsets_src1 = [sum(stream_sizes)*i for i in range(N)]
        expected_tag_offsets_src2 = [stream_sizes[0]
                                     +sum(stream_sizes)*i for i in range(N)]
        expected_tag_offsets_src3 = [stream_sizes[0]+stream_sizes[1]
                                     +sum(stream_sizes)*i for i in range(N)]
        tags_src1 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src1'))]
        tags_src2 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src2'))]
        tags_src3 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src3'))]

        for i in range(len(expected_tag_offsets_src1)):
            self.assertTrue(expected_tag_offsets_src1[i] == tags_src1[i].offset)
        for i in range(len(expected_tag_offsets_src2)):
            self.assertTrue(expected_tag_offsets_src2[i] == tags_src2[i].offset)
        for i in range(len(expected_tag_offsets_src3)):
            self.assertTrue(expected_tag_offsets_src3[i] == tags_src3[i].offset)
Example #5
0
 def __init__(self):
     gr.sync_block.__init__(self,
         name="gns430_parser",
         in_sig=None,
         out_sig=None)
         
     self.count = 0
     self.message_port_register_out(pmt.intern('out'))
     self.buf = ''
     self.message_port_register_in(pmt.intern('in'))
     self.set_msg_handler(pmt.intern('in'),self.handle_msg)
     
     self.dict2 = {}
     
     self.lat = 0
     self.lon = 0
     self.alt = 0
     self.nav_status = ''
     self.track = 0
     self.track_error = 0
     self.ground_speed = 0
     self.distance_to_wpt = 0
     self.bearing_to_wpt = 0
     self.destination_id = ''
     self.desired_track = 0
Example #6
0
 def __init__(self):
   gr.basic_block.__init__(self, name="packetizer_python", in_sig=[], out_sig=[])
   self.message_port_register_in(pmt.intern('in'))
   self.message_port_register_out(pmt.intern('out'))
   self.set_msg_handler(pmt.intern('in'), self.handle_message)
   #Max MTU size in bytes the PHY is able to handle
   self.max_mtu_size = 250
 def handle_msg(self, msg):
     if pmt.dict_has_key(msg, pmt.intern(self.len_tag_key)):
         packet_len = pmt.to_python(msg)[self.len_tag_key]
         msg = pmt.dict_delete(msg, pmt.intern(self.len_tag_key))
         msg = pmt.dict_add(msg, pmt.intern(self.len_tag_key), pmt.from_long(packet_len * 8))
         
     self.message_port_pub(self.msg_buf_out, msg)
Example #8
0
    def test_001_t(self):
        tkey = 'packet_len'
        tsrc = 'testsrc'
        ptkey = pmt.intern(tkey)
        ptsrc = pmt.intern(tsrc)
        pre_padding = 17
        post_padding = 23
        tag = gr.tag_utils.python_to_tag((0, ptkey, pmt.from_long(128), ptsrc))

        data = np.arange(128) + 1
        data = data.astype(np.complex)

        ref = np.concatenate((np.zeros(pre_padding, dtype=data.dtype),
                              data, np.zeros(post_padding, dtype=data.dtype)))

        src = blocks.vector_source_c(data, tags=(tag, ))
        uut = gfdm.short_burst_shaper(pre_padding, post_padding, tkey)
        snk = blocks.vector_sink_c()
        # set up fg
        self.tb.connect(src, uut, snk)
        self.tb.run()
        # check data
        res = np.array(snk.data())

        self.assertComplexTuplesAlmostEqual(ref, res)
Example #9
0
    def __init__(self, blkname="text_input", label="", *args):
        gr.sync_block.__init__(self,blkname,[],[])
        QtGui.QGroupBox.__init__(self, *args)
        self.filemax = 0;
        self.message_port_register_in(pmt.intern("file_range"));
        self.message_port_register_out(pmt.intern("range"));

        self.lay = QtGui.QGridLayout()
        self.setLayout(self.lay)
        self.scroll = QtGui.QScrollBar(Qt.Qt.Horizontal)
        self.laStart = QtGui.QLabel("Start Sample:")
        self.leStart = QtGui.QLineEdit("0")
        self.laLen = QtGui.QLabel("Sample Length:")
        self.leLen   = QtGui.QLineEdit("4096")

        self.lay.addWidget(self.scroll, 0, 0, 1, 4)
        self.lay.addWidget(self.laStart, 1, 0)
        self.lay.addWidget(self.leStart, 1, 1)
        self.lay.addWidget(self.laLen, 1, 2)
        self.lay.addWidget(self.leLen, 1, 3)

        self.leStart.returnPressed.connect(self.box_changed)
        self.leLen.returnPressed.connect(self.box_changed)
        self.scroll.sliderMoved.connect(self.slider_changed)
        self.set_msg_handler(pmt.intern("file_range"), self.set_file_range)
 
        self.box_changed()
        self.scroll.setFocusPolicy(QtCore.Qt.StrongFocus)
 def __init__(self, channel_count, channel_map):
     gr.basic_block.__init__(self,
         name="virtual_channel_encoder",
         in_sig=None,
         out_sig=None)
     
     if len(channel_map) > channel_count:
         channel_map = channel_map[:channel_count]
     elif channel_count > len(channel_map):
         channel_count = len(channel_map) + 1
     
     self.frags = {}
     self.frag_age = 128
     
     self.channel_count = channel_count
     self.channel_map = {}
     
     for i in range(channel_count):
         out_name = 'out%d' % (i)
         if i < len(channel_map):
             self.channel_map[channel_map[i]] = out_name
         #print "[%s] Registered '%s'" % (self.name, out_name)
         self.message_port_register_out(pmt.intern(out_name))
     
     self.message_port_register_in(pmt.intern('in'))
     self.set_msg_handler(pmt.intern('in'), self.demux)
Example #11
0
    def tx_work(self,x):
		
		pygame.init()
		screen = pygame.display.set_mode((640, 480))
		pygame.display.set_caption('Pygame Caption')
		pygame.mouse.set_visible(0)
		 
		done = False
		while not done:
		   time.sleep(0.1)
		   for event in pygame.event.get():
			  if (event.type == KEYUP) or (event.type == KEYDOWN):
				 print event
				 if (event.key == K_ESCAPE and event.type == KEYDOWN):
					dict2 = { "id" : "joystick",
					"buttons" : [1,0,0]}
					#pmt_dict = pmt.to_pmt(dict2)
					self.message_port_pub(pmt.intern('out'),pmt.to_pmt(dict2))
				 if (event.key == K_ESCAPE and event.type == KEYUP):
					dict2 = { "id" : "joystick",
					"buttons" : [0,0,0]}
					#pmt_dict = pmt.to_pmt(dict2)
					self.message_port_pub(pmt.intern('out'),pmt.to_pmt(dict2))
					print 'here'

					 
				
		'''
Example #12
0
    def handle_queue(self):
        if self.state == self.STATE_IDLE:
          if self.app_queue.empty() == False:
            self.last_tx_packet = self.app_queue.get()

            msg_str = "".join([chr(x) for x in pmt.u8vector_elements(pmt.cdr(self.last_tx_packet))])
            self.curr_packet_len = len(msg_str[3:])
            self.curr_packet_seq = ord(msg_str[0])

            self.last_tx_time = time.time()
            print '[stop_and_wait] :: Sending packet. Payload len: '+ str(self.curr_packet_len) +' Queue fill level = ', self.app_queue.qsize()

            if self.use_ack:
                self.state = self.STATE_WAIT_FOR_ACK

            self.num_data_packets_send += 1
            self.log_packet("TX", 0, self.curr_packet_len, self.curr_packet_seq, self.last_snr)
            self.message_port_pub(pmt.intern('to_phy'), self.last_tx_packet)

        elif self.state == self.STATE_WAIT_FOR_ACK:
          if (time.time() - self.last_tx_time) > self.ack_timeout:
            #retransmit
            print '[stop_and_wait] :: ACK timeout. Retransmitting'
            self.last_tx_time = time.time()
            self.num_ack_timeouts += 1
            self.num_data_packets_send += 1
            self.log_packet("TX", 0, self.curr_packet_len, self.curr_packet_seq, self.last_snr)
            self.message_port_pub(pmt.intern('to_phy'), self.last_tx_packet)
    def test_sc_tag(self):
        constA = [-3.0+1j, -1.0-1j, 1.0+1j, 3-1j]
        constB = [12.0+1j, -12.0-1j, 6.0+1j, -6-1j]
        src_data = (0, 1, 2, 3, 3, 2, 1, 0)
        expected_result = (-3+1j, -1-1j, 1+1j, 3-1j,
                            -6-1j, 6+1j, -12-1j, 12+1j)
        first_tag = gr.tag_t()
        first_tag.key = pmt.intern("set_symbol_table")
        first_tag.value = pmt.init_c32vector(len(constA), constA)
        first_tag.offset = 0
        second_tag = gr.tag_t()
        second_tag.key = pmt.intern("set_symbol_table")
        second_tag.value = pmt.init_c32vector(len(constB), constB)
        second_tag.offset = 4

        src = blocks.vector_source_s(src_data, False, 1, [first_tag, second_tag])
        op = digital.chunks_to_symbols_sc(constB)

        dst = blocks.vector_sink_c()
        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        actual_result = dst.data()
        self.assertEqual(expected_result, actual_result)
Example #14
0
 def __init__(self, key):
     gr.sync_block.__init__(self,"pdu_meta_extract",[],[])
     self.key = key;
     self.outport = pmt.intern("values");
     self.message_port_register_in(pmt.intern("pdus"));
     self.message_port_register_out(self.outport);
     self.set_msg_handler(pmt.intern("pdus"), self.handler);
Example #15
0
    def write_data(self, msg):
        snr = pmt.to_double(pmt.dict_ref(msg, pmt.intern("snr"), pmt.from_double(0)))
        encoding = pmt.to_long(pmt.dict_ref(msg, pmt.intern("encoding"), pmt.from_long(0)))

        time_now = time() * 1000
        delay = str(time_now - self.last_time)
        self.last_time = time_now


        if self.snr_file != "":
            f_snr = open(self.snr_file, 'a')
            f_snr.write(str(snr) + '\n')
            f_snr.close()

        if self.enc_file != "":
            f_enc = open(self.enc_file, 'a')    
            f_enc.write(str(encoding) + '\n')
            f_enc.close()

        if self.delay_file != "":
            f_delay = open(self.delay_file, 'a')
            f_delay.write(delay + '\n')
            f_delay.close()

        if self.debug:
            print("SNR:" + str(snr))
            print("Encoding:" + str(encoding))
            print("Delay in millis: " + delay)
Example #16
0
	def __init__(self, tune_freq=1, sample_rate=1, fft_len=1, channel_space=1, search_bw=1, log=False, verbose=False):
		gr.sync_block.__init__(self,
			name="spectrum_logger",
			in_sig=None,
			out_sig=[np.float32])
		self.sample_rate = sample_rate
		self.channel_space = channel_space
		self.search_bw = search_bw
		self.tune_freq = tune_freq
		self.log = log
		self.verbose = verbose
		self.constraints = []
		self.statistic = {}
		self.settings = {'date':time.strftime("%y%m%d"), 'time':time.strftime("%H%M%S"), 'tune_freq':tune_freq, 'sample_rate':sample_rate, 'fft_len':fft_len,'channel_space':channel_space, 'search_bw':search_bw}
		if self.log:
			self.log_file = open('/tmp/ss_log'+'-'+ time.strftime("%y%m%d") + '-' + time.strftime("%H%M%S"),'w')
			self.log_file.write('Time,'+time.strftime("%H%M%S") + ',sample_rate,' + str(sample_rate) +
			 ',channel_space,' + str(channel_space) + ',search_bw,' + str(search_bw) +
			  ',tune_freq,' + str(tune_freq) + '\n')
			self.log_file.write('settings ' + str(self.settings) + '\n')
			self.log_file.write('statistics ' + str(self.statistic) + '\n')
			print 'successfully created log file'
			print self.log_file
		else:
			print 'printing results'

		#message ports
		#self.message_port_register_out(pmt.intern('PDU spect_msg'))
		self.message_port_register_in(pmt.intern('PDU from_ss'))
		self.set_msg_handler(pmt.intern('PDU from_ss'), self.ss_rx_callback)
Example #17
0
    def __init__(self, snr_file, enc_file, delay_file, debug):
        gr.sync_block.__init__(self,
            "sink",
            None,
            None)

        self.snr_file = snr_file
        self.enc_file = enc_file
        self.delay_file = delay_file
        self.debug = debug

        # Time in millis
        self.last_time = time() * 1000

        # Check if files have been provided and reset them
        if self.snr_file != "":
            open(self.snr_file, 'w').close()
        else:
            print("No file for SNR information provided.")
        if self.enc_file != "":
            open(self.enc_file, 'w').close()
        else:
            print("No file for Encoding information provided.")
        if self.delay_file != "":
            open(self.delay_file, 'w').close()
        else:
            print("No file for Frame Delay information provided.")

        self.message_port_register_in(pmt.intern("frame data"))
        self.set_msg_handler(pmt.intern("frame data"), self.write_data)
Example #18
0
 def __init__(self,f,fs):
     gr.sync_block.__init__(self,"pcap_range_source",[],[])
     self.message_port_register_in(pmt.intern("pdus"));
     self.message_port_register_out(pmt.intern("pdus"));
     self.set_msg_handler(pmt.intern("pdus"), self.handler);
     self.f = f
     self.fs = fs
Example #19
0
 def start(self):
     self.count = self.count_init
     self.thread.start()
     reg = pmt.cons(pmt.intern("timer_event"), self.message_subscribers(pmt.intern("timer_event")))
     reg_msg = pmt.cons(pmt.intern("ES_REGISTER_HANDLER"), reg)
     print "subscribers: %s" % (str(self.message_subscribers(pmt.intern("timer_event"))))
     print "registration message: %s" % (str(reg_msg))
     self.message_port_pub(pmt.intern("which_stream"), reg_msg)
Example #20
0
 def __init__(self, PanId, SrcAddM):
     # Variables externas Parametros
     self.SrcAddM = SrcAddM
     self.PanId = PanId
     gr.sync_block.__init__(self, name="tx_mac_802_15_4", in_sig=[], out_sig=[])
     self.message_port_register_in(pmt.intern("in"))
     self.message_port_register_out(pmt.intern("out"))
     self.set_msg_handler(pmt.intern("in"), self.make_MPDU)  # Funcion
Example #21
0
 def __init__(self):
     gr.sync_block.__init__(self,
         name="tx_app_xbee",
         in_sig=[],
         out_sig=[])
     self.message_port_register_in(pmt.intern("in"))
     self.message_port_register_out(pmt.intern("out"))
     self.set_msg_handler(pmt.intern("in"), self.make_APDU)  #Funcion make_APDU
Example #22
0
    def __init__(self):
        gr.basic_block.__init__(self,
            name="print_header",
            in_sig=[],
            out_sig=[])

        self.message_port_register_in(pmt.intern('in'))
        self.set_msg_handler(pmt.intern('in'), self.handle_msg)
Example #23
0
 def __init__(self):
     gr.sync_block.__init__(self, "burst_deframer", [], [])
     self.message_port_register_in(pmt.intern("pdus"))
     self.message_port_register_out(pmt.intern("pdus"))
     self.set_msg_handler(pmt.intern("pdus"), self.handler)
     self.npkt = 0
     self.npkt_ok = 0
     self.npkt_hok = 0
Example #24
0
 def __init__(self):
     gr.basic_block.__init__(self,
         name="chat_receiver",
         in_sig=[], # No streaming ports!
         out_sig=[])
     # Register the message port
     self.message_port_register_in(pmt.intern('in'))
     self.set_msg_handler(pmt.intern('in'), self.handle_msg)
Example #25
0
    def __init__(self):
        gr.basic_block.__init__(self,
            name="beacon_parser",
            in_sig=None,
            out_sig=None)

        self.message_port_register_in(pmt.intern('in'))
        self.set_msg_handler(pmt.intern('in'), self.handle_msg)
Example #26
0
    def __init__(self, blkname="pyqt_raster", label="", *args):
        gr.sync_block.__init__(self,blkname,[],[])
        Qwt.QwtPlot.__init__(self, *args)
        self.enabled = True

        # set up message port
        self.message_port_register_in(pmt.intern("pdus"))
        self.set_msg_handler(pmt.intern("pdus"), self.handler);
        
        # QwtPlot set up
        self.setMinimumWidth(100)
        self.setMinimumHeight(100)

        self._lock = threading.Lock();

        # set up label if desired
        if not label == "":
            ttl = Qwt.QwtText(label)
            ttl.setFont(Qt.QFont("Helvetica",10))
            self.setTitle(ttl)

        # wedge everything as close as possible
        self.plotLayout().setMargin(0)
        self.plotLayout().setCanvasMargin(0)
        self.plotLayout().setSpacing(0)

        # set up background etc
        self.setCanvasBackground(Qt.Qt.black)
        self.alignScales()

        # set up image raster
        dim = (100,100)
        self.__data = PlotImage('Image', dim[0], dim[1])
        self.__data.attach(self)
        self.__data.setData( numpy.random.normal(0,1e-9,dim) )
        self.replot()

        # connect the plot callback signal
        QtCore.QObject.connect(self,
                       QtCore.SIGNAL("updatePlot(int)"),
                       self.do_plot)

        # set up zoomer
        self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom,
                                        Qwt.QwtPlot.yLeft,
                                        Qwt.QwtPicker.DragSelection,
                                        Qwt.QwtPicker.AlwaysOff,
                                        self.canvas())
        self.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.black))

        # Set up menu actions
        actions = [("Start/Stop", self.toggle_enabled),
                  ]
        self.actions = [];
        for a in actions:
            action = QtGui.QAction(a[0], self)
            action.triggered.connect(a[1])
            self.actions.append(action)
Example #27
0
 def __init__(self, data_to_concat=[0xff]):
     gr.basic_block.__init__(self,
         name="data-concatenator",
         in_sig=[],
         out_sig=[])
     self.message_port_register_out(pmt.intern('out'))
     self.message_port_register_in(pmt.intern('in'))
     self.set_msg_handler(pmt.intern('in'), self.handle_msg)
     self.data_to_concat = data_to_concat
 def __init__(self, k=0):
     gr.sync_block.__init__(self, 
             name = "cpdu_average_power",
             in_sig = [],
             out_sig = []);
     self.k = k
     self.message_port_register_in(pmt.intern("cpdus"));
     self.message_port_register_out(pmt.intern("cpdus"));
     self.set_msg_handler(pmt.intern("cpdus"), self.handler);  
Example #29
0
    def __init__(self):
        gr.sync_block.__init__(
            self, name="blockchain_source",
            in_sig=None, out_sig=None)

        self.header = "SATOSHIWIRELESS";
        self.message_port_register_in(pmt.intern("msg_string"));
        self.message_port_register_out(pmt.intern("pdu"))
        self.set_msg_handler(pmt.intern("msg_string"), self.handle_msg);
Example #30
0
    def __init__(self):
        gr.basic_block.__init__(self,
            name="swap_crc",
            in_sig=[],
            out_sig=[])

        self.message_port_register_in(pmt.intern('in'))
        self.set_msg_handler(pmt.intern('in'), self.handle_msg)
        self.message_port_register_out(pmt.intern('out'))
Example #31
0
 def send_packet_msg(self):
     print(f'Passing packet to nic interface')
     message = pmt.cons(pmt.intern('pkt'), pmt.to_pmt(self.current_packet.tobytes()))
Example #32
0
 def set_pdu_length(self, pdu_length):
     self.pdu_length = pdu_length
     self.blocks_message_strobe_0_0.set_msg(
         pmt.intern("".join("b" for i in range(self.pdu_length))))
Example #33
0
    def __init__(self):
        gr.top_block.__init__(self, "Wifi Transceiver 2")

        ##################################################
        # Variables
        ##################################################
        self.tx_gain = tx_gain = 1000e-3
        self.samp_rate = samp_rate = 5e6
        self.rx_gain = rx_gain = 500e-3
        self.pdu_length = pdu_length = 500
        self.mac_dst = mac_dst = [0x13, 0x13, 0x13, 0x13, 0x13, 0x13]
        self.mac_addr = mac_addr = [0x12, 0x12, 0x12, 0x12, 0x12, 0x12]
        self.lo_offset = lo_offset = 0
        self.interval = interval = 1e3
        self.freq = freq = 2.52e9
        self.encoding = encoding = 0
        self.chan_est = chan_est = 0

        ##################################################
        # Blocks
        ##################################################
        self.wifi_phy_hier_0 = wifi_phy_hier(
            bandwidth=samp_rate,
            chan_est=chan_est,
            encoding=encoding,
            frequency=freq,
            sensitivity=0.56,
        )
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("", "")),
            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(
            uhd.tune_request(freq,
                             rf_freq=freq - lo_offset,
                             rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0)
        self.uhd_usrp_source_0.set_normalized_gain(rx_gain, 0)
        self.uhd_usrp_sink_0_0 = uhd.usrp_sink(
            ",".join(("", "")),
            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(
            uhd.tune_request(freq,
                             rf_freq=freq - lo_offset,
                             rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0)
        self.uhd_usrp_sink_0_0.set_normalized_gain(tx_gain, 0)
        self.toolkit_cs_0 = toolkit.cs()
        self.macprotocols_frame_buffer_0 = macprotocols.frame_buffer(
            256, False, 0, True)
        self.macprotocols_csma_ca_0 = macprotocols.csma_ca((mac_addr), 9, 16,
                                                           34, 1000, -60, True)
        self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(
            sample_rate=samp_rate,
            fft_size=64,
            ref_scale=2,
            frame_rate=30,
            avg_alpha=1.0,
            average=False,
        )
        self.ieee802_11_parse_mac_0 = ieee802_11.parse_mac(False, False)
        self.ieee802_11_mac_0_0 = ieee802_11.mac(
            (mac_addr), (mac_dst), ([0xff, 0xff, 0xff, 0xff, 0xff, 255]))
        (self.ieee802_11_mac_0_0).set_min_output_buffer(256)
        (self.ieee802_11_mac_0_0).set_max_output_buffer(4096)
        self.foo_wireshark_connector_0_0 = foo.wireshark_connector(127, False)
        self.foo_wireshark_connector_0 = foo.wireshark_connector(127, False)
        self.foo_packet_pad2_0 = foo.packet_pad2(False, False, 0.001, 10000,
                                                 10000)
        (self.foo_packet_pad2_0).set_min_output_buffer(100000)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(
            gr.sizeof_float * 1, 64)
        self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", "", "52000",
                                                     10000, False)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.6, ))
        (self.blocks_multiply_const_vxx_0).set_min_output_buffer(100000)
        self.blocks_message_strobe_0_0 = blocks.message_strobe(
            pmt.intern("".join("b" for i in range(pdu_length))), interval)
        self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                     "/tmp/wifi_rx.pcap",
                                                     False)
        self.blocks_file_sink_0_0.set_unbuffered(True)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                   "/tmp/wifi_rx_all.pcap",
                                                   False)
        self.blocks_file_sink_0.set_unbuffered(True)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0_0, 'strobe'),
                         (self.ieee802_11_mac_0_0, 'app in'))
        self.msg_connect((self.blocks_socket_pdu_0, 'pdus'),
                         (self.ieee802_11_mac_0_0, 'app in'))
        self.msg_connect((self.ieee802_11_mac_0_0, 'app out'),
                         (self.foo_wireshark_connector_0_0, 'in'))
        self.msg_connect((self.ieee802_11_mac_0_0, 'phy out'),
                         (self.macprotocols_frame_buffer_0, 'app in'))
        self.msg_connect((self.macprotocols_csma_ca_0, 'frame to app'),
                         (self.ieee802_11_mac_0_0, 'phy in'))
        self.msg_connect((self.macprotocols_csma_ca_0, 'frame request'),
                         (self.macprotocols_frame_buffer_0, 'req in 0'))
        self.msg_connect((self.macprotocols_csma_ca_0, 'request to cs'),
                         (self.toolkit_cs_0, 'in_msg'))
        self.msg_connect((self.macprotocols_csma_ca_0, 'frame to phy'),
                         (self.wifi_phy_hier_0, 'mac_in'))
        self.msg_connect((self.macprotocols_frame_buffer_0, 'frame out 0'),
                         (self.macprotocols_csma_ca_0, 'frame from buffer'))
        self.msg_connect((self.toolkit_cs_0, 'out_msg'),
                         (self.macprotocols_csma_ca_0, 'cs in'))
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'),
                         (self.foo_wireshark_connector_0, 'in'))
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'),
                         (self.ieee802_11_parse_mac_0, 'in'))
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'),
                         (self.macprotocols_csma_ca_0, 'frame from phy'))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.foo_packet_pad2_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0),
                     (self.toolkit_cs_0, 0))
        self.connect((self.foo_packet_pad2_0, 0), (self.uhd_usrp_sink_0_0, 0))
        self.connect((self.foo_wireshark_connector_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.foo_wireshark_connector_0_0, 0),
                     (self.blocks_file_sink_0_0, 0))
        self.connect((self.logpwrfft_x_0, 0),
                     (self.blocks_vector_to_stream_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.logpwrfft_x_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.wifi_phy_hier_0, 0))
        self.connect((self.wifi_phy_hier_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
Example #34
0
    def test_98(self):
        """
        Test case generated by test-case generator
        """
        ##################################################
        # Variables
        ##################################################
        # Input data into the system
        src_data = "PKdhtXMmr18n2L9K88eMlGn7CcctT9RwKSB1FebW397VI5uG1yhc3uavuaOb9vyJ"
        self.bw = bw = 250000
        self.sf = sf = 11
        self.samp_rate = samp_rate = 250000
        self.pay_len = pay_len = 64
        self.n_frame = n_frame = 2
        self.impl_head = impl_head = False
        self.has_crc = has_crc = True
        self.frame_period = frame_period = 200
        self.cr = cr = 6

        ##################################################
        # Blocks
        ##################################################
        # Tx side
        self.lora_sdr_whitening_0 = lora_sdr.whitening()
        self.lora_sdr_modulate_0 = lora_sdr.modulate(sf, samp_rate, bw)
        self.lora_sdr_modulate_0.set_min_output_buffer(10000000)
        self.lora_sdr_interleaver_0 = lora_sdr.interleaver(cr, sf)
        self.lora_sdr_header_0 = lora_sdr.header(impl_head, has_crc, cr)
        self.lora_sdr_hamming_enc_0 = lora_sdr.hamming_enc(cr, sf)
        self.lora_sdr_gray_decode_0 = lora_sdr.gray_decode(sf)
        self.lora_sdr_data_source_0_1_0 = lora_sdr.data_source(
            pay_len, n_frame, src_data)
        self.lora_sdr_add_crc_0 = lora_sdr.add_crc(has_crc)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex * 1)
        self.blocks_message_strobe_random_0_1_0 = blocks.message_strobe_random(
            pmt.intern(''), blocks.STROBE_UNIFORM, frame_period, 5)
        # Rx side
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
            interpolation=4, decimation=1, taps=None, fractional_bw=None)
        self.lora_sdr_header_decoder_0 = lora_sdr.header_decoder(
            impl_head, cr, pay_len, has_crc)
        self.lora_sdr_hamming_dec_0 = lora_sdr.hamming_dec()
        self.lora_sdr_gray_enc_0 = lora_sdr.gray_enc()
        self.lora_sdr_frame_sync_0 = lora_sdr.frame_sync(
            samp_rate, bw, sf, impl_head)
        self.lora_sdr_fft_demod_0 = lora_sdr.fft_demod(samp_rate, bw, sf,
                                                       impl_head)
        self.lora_sdr_dewhitening_0 = lora_sdr.dewhitening()
        self.lora_sdr_deinterleaver_0 = lora_sdr.deinterleaver(sf)
        self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif()
        self.blocks_message_debug_0 = blocks.message_debug()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)

        ##################################################
        # Connections
        ##################################################
        # Tx side
        self.tb.msg_connect(
            (self.blocks_message_strobe_random_0_1_0, 'strobe'),
            (self.lora_sdr_data_source_0_1_0, 'trigg'))
        self.tb.msg_connect((self.lora_sdr_data_source_0_1_0, 'msg'),
                            (self.lora_sdr_add_crc_0, 'msg'))
        self.tb.msg_connect((self.lora_sdr_data_source_0_1_0, 'msg'),
                            (self.lora_sdr_header_0, 'msg'))
        self.tb.msg_connect((self.lora_sdr_data_source_0_1_0, 'msg'),
                            (self.lora_sdr_interleaver_0, 'msg'))
        self.tb.msg_connect((self.lora_sdr_data_source_0_1_0, 'msg'),
                            (self.lora_sdr_modulate_0, 'msg'))
        self.tb.msg_connect((self.lora_sdr_data_source_0_1_0, 'msg'),
                            (self.lora_sdr_whitening_0, 'msg'))
        self.tb.connect((self.lora_sdr_add_crc_0, 0),
                        (self.lora_sdr_hamming_enc_0, 0))
        self.tb.connect((self.lora_sdr_gray_decode_0, 0),
                        (self.lora_sdr_modulate_0, 0))
        self.tb.connect((self.lora_sdr_hamming_enc_0, 0),
                        (self.lora_sdr_interleaver_0, 0))
        self.tb.connect((self.lora_sdr_header_0, 0),
                        (self.lora_sdr_add_crc_0, 0))
        self.tb.connect((self.lora_sdr_interleaver_0, 0),
                        (self.lora_sdr_gray_decode_0, 0))
        self.tb.connect((self.lora_sdr_whitening_0, 0),
                        (self.lora_sdr_header_0, 0))
        self.tb.connect((self.lora_sdr_modulate_0, 0),
                        (self.blocks_throttle_0, 0))
        # Rx side

        self.tb.connect((self.blocks_throttle_0, 0),
                        (self.rational_resampler_xxx_0, 0))
        self.tb.msg_connect((self.lora_sdr_crc_verif_0, 'msg'),
                            (self.blocks_message_debug_0, 'store'))
        self.tb.msg_connect((self.lora_sdr_frame_sync_0, 'new_frame'),
                            (self.lora_sdr_deinterleaver_0, 'new_frame'))
        self.tb.msg_connect((self.lora_sdr_frame_sync_0, 'new_frame'),
                            (self.lora_sdr_dewhitening_0, 'new_frame'))
        self.tb.msg_connect((self.lora_sdr_frame_sync_0, 'new_frame'),
                            (self.lora_sdr_fft_demod_0, 'new_frame'))
        self.tb.msg_connect((self.lora_sdr_frame_sync_0, 'new_frame'),
                            (self.lora_sdr_hamming_dec_0, 'new_frame'))
        self.tb.msg_connect((self.lora_sdr_frame_sync_0, 'new_frame'),
                            (self.lora_sdr_header_decoder_0, 'new_frame'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'pay_len'),
                            (self.lora_sdr_crc_verif_0, 'pay_len'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CRC'),
                            (self.lora_sdr_crc_verif_0, 'CRC'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CR'),
                            (self.lora_sdr_deinterleaver_0, 'CR'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'pay_len'),
                            (self.lora_sdr_dewhitening_0, 'pay_len'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CRC'),
                            (self.lora_sdr_dewhitening_0, 'CRC'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CR'),
                            (self.lora_sdr_fft_demod_0, 'CR'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CR'),
                            (self.lora_sdr_frame_sync_0, 'CR'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'err'),
                            (self.lora_sdr_frame_sync_0, 'err'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CRC'),
                            (self.lora_sdr_frame_sync_0, 'crc'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'pay_len'),
                            (self.lora_sdr_frame_sync_0, 'pay_len'))
        self.tb.msg_connect((self.lora_sdr_header_decoder_0, 'CR'),
                            (self.lora_sdr_hamming_dec_0, 'CR'))
        self.tb.connect((self.lora_sdr_deinterleaver_0, 0),
                        (self.lora_sdr_hamming_dec_0, 0))
        self.tb.connect((self.lora_sdr_dewhitening_0, 0),
                        (self.lora_sdr_crc_verif_0, 0))
        self.tb.connect((self.lora_sdr_fft_demod_0, 0),
                        (self.lora_sdr_gray_enc_0, 0))
        self.tb.connect((self.lora_sdr_frame_sync_0, 0),
                        (self.lora_sdr_fft_demod_0, 0))
        self.tb.connect((self.lora_sdr_gray_enc_0, 0),
                        (self.lora_sdr_deinterleaver_0, 0))
        self.tb.connect((self.lora_sdr_hamming_dec_0, 0),
                        (self.lora_sdr_header_decoder_0, 0))
        self.tb.connect((self.lora_sdr_header_decoder_0, 0),
                        (self.lora_sdr_dewhitening_0, 0))
        self.tb.connect((self.rational_resampler_xxx_0, 0),
                        (self.lora_sdr_frame_sync_0, 0))

        # run the flowgraph, since we use a message strobe we have to run and stop the flowgraph with some computation time inbetween
        self.tb.start()
        time.sleep(10)
        self.tb.stop()
        self.tb.wait()
        # try to get get the message from the store port of the message debug printer and convert to string from pmt message
        try:
            msg = pmt.symbol_to_string(
                self.blocks_message_debug_0.get_message(0))
        except:
            # if not possible set message to be None
            msg = None

        # check if message received is the same as the message decoded
        self.assertMultiLineEqual(
            src_data,
            msg,
            msg="Error decoded data {0} is not the same as input data {1}".
            format(msg, src_data))
 def test_001_headerpadding_payload_offset (self):
     """ Like test 1, but with header padding + payload offset. """
     n_zeros = 3
     header = (1, 2, 3)
     header_padding = 1
     payload_offset = -1
     payload = tuple(range(5, 20))
     data_signal = (0,) * n_zeros + header + payload + (0,) * 100
     trigger_signal = [0,] * len(data_signal)
     trigger_signal[n_zeros] = 1
     # This goes on output 1, item 3 + 1 (for payload offset)
     testtag4 = make_tag('tag4', 314, n_zeros + len(header) + 3)
     data_src = blocks.vector_source_f(
             data_signal,
             False,
             tags=(testtag4,)
     )
     trigger_src = blocks.vector_source_b(trigger_signal, False)
     hpd = digital.header_payload_demux(
         len(header),
         1, # Items per symbol
         0, # Guard interval
         "frame_len", # TSB tag key
         "detect", # Trigger tag key
         False, # No symbols please
         gr.sizeof_float, # Item size
         "", # Timing tag key
         1.0, # Samp rate
         (), # No special tags
         header_padding
     )
     self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you
     header_sink = blocks.vector_sink_f()
     payload_sink = blocks.vector_sink_f()
     self.tb.connect(data_src,    (hpd, 0))
     self.tb.connect(trigger_src, (hpd, 1))
     self.tb.connect((hpd, 0), header_sink)
     self.tb.connect((hpd, 1), payload_sink)
     self.tb.start()
     time.sleep(.2) # Need this, otherwise, the next message is ignored
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.to_pmt({'frame_len': len(payload), 'payload_offset': payload_offset})
     )
     while len(payload_sink.data()) < len(payload):
         time.sleep(.2)
     self.tb.stop()
     self.tb.wait()
     # Header is now padded:
     self.assertEqual(header_sink.data(),  (0,) + header + (payload[0],))
     # Payload is now offset:
     self.assertEqual(
             payload_sink.data(),
             data_signal[n_zeros + len(header) + payload_offset:n_zeros + len(header) + payload_offset + len(payload)]
     )
     ptags_payload = {}
     for tag in payload_sink.tags():
         ptag = gr.tag_to_python(tag)
         ptags_payload[ptag.key] = ptag.offset
     expected_tags_payload = {
             'frame_len': 0,
             'payload_offset': 0,
             'tag4': 3 - payload_offset,
     }
     self.assertEqual(expected_tags_payload, ptags_payload)
Example #36
0
    def __init__(self, username, mode):
        gr.basic_block.__init__(self,
                                name="ATA Control",
                                in_sig=None,
                                out_sig=None)

        self.hat_creek = EarthLocation(lat='40d49.05m',
                                       lon='-121d28.40m',
                                       height=986.0 * u.meter)
        self.pos = ap.ATAPositions()
        self.mode = mode
        self.obs_info = {}
        self.ant_list = []
        self.my_ants = []
        self.is_configured = False

        #run the flowgraph either online or offline
        if mode == 'online':

            try_ping = subprocess.Popen(['ping', '-c', '1', 'control'],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
            stdout, stderr = try_ping.communicate()
            ping_output = stdout.decode('utf-8')

            ping_success = "1 packets transmitted, 1 received"

            if ping_success in ping_output:
                try:
                    alarm = ac.get_alarm()

                    if alarm['user'] == username:
                        self.is_user = True
                        print(
                            "You are the primary user. You have full permissions."
                        )

                    else:
                        self.is_user = False
                        raise Exception(
                            "Another user, {0}, has the array locked out. \n"
                            "You do not have permission to observe.".format(
                                alarm['user']))
                except KeyError:
                    self.is_user = False
                    raise Exception(
                        "The array is not locked out under your username.\n"
                        "You do not have permission to observe.")

                self.message_port_register_in(pmt.intern("command"))
                self.set_msg_handler(pmt.intern("command"), self.handle_msg)

            else:
                exception_msg = "Sorry, you must be able to connect to the ATA\n"\
                                "machine. if you want to observe. If you want to test\n"\
                                "the code on your local computer without observing, \n"\
                                "switch to Offline Mode."
                raise Exception(exception_msg)

        elif mode == 'offline':
            self.message_port_register_in(pmt.intern("command"))
            self.set_msg_handler(pmt.intern("command"),
                                 self.handle_msg_offline)
        else:
            print(
                "Error: No Control Block Mode specified! Select mode and try again."
            )
 def test_003_t (self):
     """
     Like test 1, but twice, plus one fail
     """
     ### Tx Data
     n_zeros = 5
     header = (1, 2, 3)
     header_fail = (-1, -2, -4) # Contents don't really matter
     payload1 = tuple(range(5, 20))
     payload2 = (42,)
     sampling_rate = 2
     data_signal = (0,) * n_zeros + header + payload1
     trigger_signal = [0,] * len(data_signal) * 2
     trigger_signal[n_zeros] = 1
     trigger_signal[len(data_signal)] = 1
     trigger_signal[len(data_signal)+len(header_fail)+n_zeros] = 1
     print("Triggers at: {0} {1} {2}".format(
         n_zeros,
         len(data_signal),
         len(data_signal)+len(header_fail)+n_zeros)
     )
     tx_signal = data_signal + \
             header_fail + (0,) * n_zeros + \
             header + payload2 + (0,) * 1000
     # Timing tag: This is preserved and updated:
     timing_tag = make_tag('rx_time', (0, 0), 0)
     # Rx freq tags:
     rx_freq_tag1 = make_tag('rx_freq', 1.0, 0)
     rx_freq_tag2 = make_tag('rx_freq', 1.5, 29)
     rx_freq_tag3 = make_tag('rx_freq', 2.0, 30)
     ### Flow graph
     data_src = blocks.vector_source_f(
         tx_signal, False,
         tags=(timing_tag, rx_freq_tag1, rx_freq_tag2, rx_freq_tag3)
     )
     trigger_src = blocks.vector_source_b(trigger_signal, False)
     hpd = digital.header_payload_demux(
         header_len=len(header),
         items_per_symbol=1,
         guard_interval=0,
         length_tag_key="frame_len",
         trigger_tag_key="detect",
         output_symbols=False,
         itemsize=gr.sizeof_float,
         timing_tag_key='rx_time',
         samp_rate=sampling_rate,
         special_tags=('rx_freq',),
     )
     self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you
     header_sink = blocks.vector_sink_f()
     payload_sink = blocks.vector_sink_f()
     self.tb.connect(data_src,    (hpd, 0))
     self.tb.connect(trigger_src, (hpd, 1))
     self.tb.connect((hpd, 0), header_sink)
     self.tb.connect((hpd, 1), payload_sink)
     self.tb.start()
     time.sleep(.2) # Need this, otherwise, the next message is ignored
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.from_long(len(payload1))
     )
     while len(payload_sink.data()) < len(payload1):
         time.sleep(.2)
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.PMT_F
     )
     # This next command is a bit of a showstopper, but there's no condition to check upon
     # to see if the previous msg handling is finished
     time.sleep(.7)
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.from_long(len(payload2))
     )
     while len(payload_sink.data()) < len(payload1) + len(payload2):
         time.sleep(.2)
     self.tb.stop()
     self.tb.wait()
     # Signal description:
     # 0:  5 zeros
     # 5:  header 1
     # 8:  payload 1 (length: 15)
     # 23: header 2 (fail)
     # 26: 5 zeros
     # 31: header 3
     # 34: payload 2 (length 1)
     # 35: 1000 zeros
     self.assertEqual(header_sink.data(),  header + header_fail + header)
     self.assertEqual(payload_sink.data(), payload1 + payload2)
     tags_payload = [gr.tag_to_python(x) for x in payload_sink.tags()]
     tags_payload = sorted([(x.offset, x.key, x.value) for x in tags_payload])
     tags_expected_payload = [
         (0,             'frame_len', len(payload1)),
         (len(payload1), 'frame_len', len(payload2)),
     ]
     tags_header = [gr.tag_to_python(x) for x in header_sink.tags()]
     tags_header = sorted([(x.offset, x.key, x.value) for x in tags_header])
     tags_expected_header = [
         (0,             'rx_freq', 1.0),
         (0,             'rx_time', (2, 0.5)), # Hard coded time value :( Is n_zeros/sampling_rate
         (len(header),   'rx_freq', 1.0),
         (len(header),   'rx_time', (11, .5)), # Hard coded time value :(. See above.
         (2*len(header), 'rx_freq', 2.0),
         (2*len(header), 'rx_time', (15, .5)), # Hard coded time value :(. See above.
     ]
     self.assertEqual(tags_header, tags_expected_header)
     self.assertEqual(tags_payload, tags_expected_payload)
Example #38
0
 def __init__(self, blkname="text_input", label="", *args):
     gr.sync_block.__init__(self, blkname, [], [])
     QtGui.QLineEdit.__init__(self, *args)
     self.returnPressed.connect(self.text_changed)
     self.message_port_register_out(pmt.intern("pdus"))
Example #39
0
 def __init__(self, fn):
     gr.sync_block.__init__(self, "pdu_lambda", [], [])
     self.set_fn(fn)
     self.message_port_register_in(pmt.intern("pdus"))
     self.message_port_register_out(pmt.intern("pdus"))
     self.set_msg_handler(pmt.intern("pdus"), self.handler)
Example #40
0
    def __init__(self,
                 pre_bits=[
                     0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1,
                     1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
                     0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
                     1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0,
                     0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0
                 ]):
        gr.top_block.__init__(self, "Psk Burst Tx")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Psk Burst Tx")
        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", "psk_burst_tx")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.pre_bits = pre_bits

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 100e3

        self.ldpc_enc = ldpc_enc = fec.ldpc_encoder_make(
            '/home/abraxas3d/goodies/share/gnuradio/fec/ldpc/271.127.3.112')

        ##################################################
        # Blocks
        ##################################################
        self.root_raised_cosine_filter_0 = filter.interp_fir_filter_ccf(
            2, firdes.root_raised_cosine(1, 2.0, 1, 0.35, 41))
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
            8192,  #size
            samp_rate,  #samp_rate
            "",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)

        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_FREE,
                                                  qtgui.TRIG_SLOPE_POS, 0.0, 0,
                                                  0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(True)
        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 True:
            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 * 1):
            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.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 1,
                                       0)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
            8192,  #size
            "",  #name
            1  #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                   qtgui.TRIG_SLOPE_POS, 0.0,
                                                   0, "")
        self.qtgui_const_sink_x_0.enable_autoscale(False)
        self.qtgui_const_sink_x_0.enable_grid(False)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)

        if not True:
            self.qtgui_const_sink_x_0.disable_legend()

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "red", "red", "red", "red", "red", "red", "red",
            "red"
        ]
        styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        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_const_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_const_sink_x_0_win = sip.wrapinstance(
            self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 1, 1)
        self.pyqt_meta_text_output_0 = pyqt.meta_text_output()
        self._pyqt_meta_text_output_0_win = self.pyqt_meta_text_output_0
        self.top_layout.addWidget(self._pyqt_meta_text_output_0_win)
        self.pyqt_ctime_plot_0 = pyqt.ctime_plot('')
        self._pyqt_ctime_plot_0_win = self.pyqt_ctime_plot_0
        self.top_grid_layout.addWidget(self._pyqt_ctime_plot_0_win, 1, 0)
        self.mapper_mapper_msg_0 = mapper.mapper_msg(mapper.QPSK,
                                                     ([0, 1, 3, 2]))
        self.fec_async_encoder_0 = fec.async_encoder(ldpc_enc, False, True,
                                                     True, 1500)
        self.es_source_0 = es.source(1 * [gr.sizeof_gr_complex], 1, 2)
        self.channels_channel_model_0_0 = channels.channel_model(
            noise_voltage=0.05,
            frequency_offset=random.random() * 1e-4,
            epsilon=1.0 + random.random() * 1e-4,
            taps=(1.0 + 1.0j, ),
            noise_seed=0,
            block_tags=False)
        self.burst_scheduler_0 = burst.burst_scheduler()
        self.burst_randomizer_0 = burst.randomizer(
            ([0, 14, 15]), ([1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0]),
            100000)
        self.burst_preamble_insert_0 = burst.preamble_insert((pre_bits))
        self.burst_padder_0 = burst.padder(144)
        self.burst_framer_0 = burst.framer(144)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_random_pdu_0 = blocks.random_pdu(50, 256 / 2, chr(0xFF), 2)
        self.blocks_message_strobe_0 = blocks.message_strobe(
            pmt.intern("TEST"), 1000)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1,
                                                   '/tmp/psk_ldpc_xmit.dat',
                                                   False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'),
                         (self.blocks_random_pdu_0, 'generate'))
        self.msg_connect((self.blocks_random_pdu_0, 'pdus'),
                         (self.burst_framer_0, 'packed_pdus'))
        self.msg_connect((self.burst_framer_0, 'unpacked_pdus'),
                         (self.burst_padder_0, 'pdus'))
        self.msg_connect((self.burst_padder_0, 'pdus'),
                         (self.burst_randomizer_0, 'pdus'))
        self.msg_connect((self.burst_preamble_insert_0, 'pdus'),
                         (self.mapper_mapper_msg_0, 'pdus'))
        self.msg_connect((self.burst_randomizer_0, 'pdus'),
                         (self.fec_async_encoder_0, 'in'))
        self.msg_connect((self.burst_scheduler_0, 'sched_pdu'),
                         (self.es_source_0, 'schedule_event'))
        self.msg_connect((self.burst_scheduler_0, 'sched_pdu'),
                         (self.pyqt_meta_text_output_0, 'pdus'))
        self.msg_connect((self.es_source_0, 'nproduced'),
                         (self.burst_scheduler_0, 'nproduced'))
        self.msg_connect((self.fec_async_encoder_0, 'out'),
                         (self.burst_preamble_insert_0, 'pdus'))
        self.msg_connect((self.mapper_mapper_msg_0, 'cpdus'),
                         (self.burst_scheduler_0, 'sched_pdu'))
        self.msg_connect((self.mapper_mapper_msg_0, 'cpdus'),
                         (self.pyqt_ctime_plot_0, 'cpdus'))
        self.connect((self.blocks_throttle_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.channels_channel_model_0_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.channels_channel_model_0_0, 0),
                     (self.qtgui_const_sink_x_0, 0))
        self.connect((self.channels_channel_model_0_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.es_source_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.channels_channel_model_0_0, 0))
Example #41
0
    def test_002_callbacks(self):
        in_data = [0, 0, 0, 0]
        in_meta = pmt.make_dict()
        expected_meta1 = pmt.dict_add(in_meta, pmt.intern('num'),
                                      pmt.from_long(4))
        expected_meta2 = pmt.dict_add(
            pmt.dict_add(in_meta, pmt.intern('num'), pmt.from_long(4)),
            pmt.intern('name'), pmt.intern('param1'))
        expected_meta3 = pmt.dict_add(
            pmt.dict_add(in_meta, pmt.intern('name'), pmt.intern('param1')),
            pmt.intern('num'), pmt.from_long(1))
        in_pdu = pmt.cons(in_meta, pmt.init_u8vector(len(in_data), in_data))
        expected_pdu1 = pmt.cons(expected_meta1,
                                 pmt.init_u8vector(len(in_data), in_data))
        expected_pdu2 = pmt.cons(expected_meta2,
                                 pmt.init_u8vector(len(in_data), in_data))
        expected_pdu3 = pmt.cons(expected_meta3,
                                 pmt.init_u8vector(len(in_data), in_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.set.set_key(pmt.intern('name'))
        self.set.set_val(pmt.intern('param1'))
        time.sleep(.001)
        self.emitter.emit(self.debug.get_message(0))
        time.sleep(.001)
        self.set.set_kv(pmt.intern('num'), pmt.from_long(1))
        time.sleep(.001)
        self.emitter.emit(self.debug.get_message(1))
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu1))
        self.assertTrue(pmt.equal(self.debug.get_message(1), expected_pdu2))
        self.assertTrue(pmt.equal(self.debug.get_message(2), expected_pdu3))
Example #42
0
    def __init__(self):
        gr.top_block.__init__(self, "Tag Test")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Tag Test")
        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", "tag_test")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
        	1024, #size
        	samp_rate, #samp_rate
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)
        
        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_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        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_control_panel(False)
        
        if not True:
          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*1):
            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.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_tags_strobe_0 = blocks.tags_strobe(gr.sizeof_gr_complex*1, pmt.intern("TEST"), 1000, pmt.intern("strobe"))
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_tags_strobe_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.blocks_throttle_0, 0), (self.qtgui_time_sink_x_0, 0))    
Example #43
0
 def handler(self, pdu):
     meta = pmt.car(pdu)
     vec = pmt.to_python(pmt.cdr(pdu))
     vec = self.fn(vec)
     self.message_port_pub(pmt.intern("pdus"),
                           pmt.cons(meta, pmt.to_pmt(vec)))
 def test_002_symbols (self):
     """
     Same as before, but operate on symbols
     """
     n_zeros = 1
     items_per_symbol = 3
     gi = 1
     n_symbols = 4
     header = (1, 2, 3)
     payload = (1, 2, 3)
     data_signal = (0,) * n_zeros + (0,) + header + ((0,) + payload) * n_symbols
     trigger_signal = [0,] * len(data_signal)
     trigger_signal[n_zeros] = 1
     # This is dropped:
     testtag1 = make_tag('tag1', 0, 0)
     # This goes on output 0, item 0 (from the GI)
     testtag2 = make_tag('tag2', 23, n_zeros)
     # This goes on output 0, item 0 (middle of the header symbol)
     testtag3 = make_tag('tag3', 42, n_zeros + gi + 1)
     # This goes on output 1, item 1 (middle of the first payload symbol)
     testtag4 = make_tag('tag4', 314, n_zeros + (gi + items_per_symbol) * 2 + 1)
     data_src = blocks.vector_source_f(data_signal, False, tags=(testtag1, testtag2, testtag3, testtag4))
     trigger_src = blocks.vector_source_b(trigger_signal, False)
     hpd = digital.header_payload_demux(
         len(header) / items_per_symbol, # Header length (in symbols)
         items_per_symbol,               # Items per symbols
         gi,                             # Items per guard time
         "frame_len",                    # Frame length tag key
         "detect",                       # Trigger tag key
         True,                           # Output symbols (not items)
         gr.sizeof_float                 # Bytes per item
     )
     self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you
     header_sink = blocks.vector_sink_f(items_per_symbol)
     payload_sink = blocks.vector_sink_f(items_per_symbol)
     self.tb.connect(data_src,    (hpd, 0))
     self.tb.connect(trigger_src, (hpd, 1))
     self.tb.connect((hpd, 0), header_sink)
     self.tb.connect((hpd, 1), payload_sink)
     self.tb.start()
     time.sleep(.2) # Need this, otherwise, the next message is ignored
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.from_long(n_symbols)
     )
     while len(payload_sink.data()) < len(payload) * n_symbols:
         time.sleep(.2)
     self.tb.stop()
     self.tb.wait()
     self.assertEqual(header_sink.data(),  header)
     self.assertEqual(payload_sink.data(), payload * n_symbols)
     ptags_header = []
     for tag in header_sink.tags():
         ptag = gr.tag_to_python(tag)
         ptags_header.append({'key': ptag.key, 'offset': ptag.offset})
     expected_tags_header = [
             {'key': 'tag2', 'offset': 0},
             {'key': 'tag3', 'offset': 0},
     ]
     self.assertEqual(expected_tags_header, ptags_header)
     ptags_payload = []
     for tag in payload_sink.tags():
         ptag = gr.tag_to_python(tag)
         ptags_payload.append({'key': ptag.key, 'offset': ptag.offset})
     expected_tags_payload = [
             {'key': 'frame_len', 'offset': 0},
             {'key': 'tag4', 'offset': 1},
     ]
     self.assertEqual(expected_tags_payload, ptags_payload)
Example #45
0
    def __init__(self,
                 constellation=gnuradio.digital.constellation_qpsk().base()):
        gr.top_block.__init__(self, "Test_slide_window")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Test_slide_window")
        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_slide_window")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.constellation = constellation

        ##################################################
        # Variables
        ##################################################
        self.sps = sps = 4
        self.range_rx_gain = range_rx_gain = 0
        self.range_mu = range_mu = 0.6
        self.usrp_device_address = usrp_device_address = "addr=10.0.0.6"
        self.tx_center_frequency = tx_center_frequency = 3.8e8
        self.system_time_granularity_us = system_time_granularity_us = 1000
        self.source_address = source_address = 1
        self.samp_rate = samp_rate = 1000000
        self.rx_gain = rx_gain = range_rx_gain
        self.rx_center_frequency = rx_center_frequency = 3.9e8

        self.rrc = rrc = firdes.root_raised_cosine(1.0, sps, 1, 0.5, 11 * sps)

        self.mu = mu = range_mu
        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.destination_address = destination_address = 2
        self.cs_threshold = cs_threshold = 0.005

        ##################################################
        # Blocks
        ##################################################
        self._range_rx_gain_range = Range(0, 1, 1, 0, 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_0 = inets.timeout(0, 10, 1000, 1000, 1)
        self.inets_slide_window_0 = inets.slide_window(
            1, 22, 5, 1,
            constellation.bits_per_symbol() * (samp_rate / sps), 200, 1)
        self.inets_sending_0 = inets.sending(
            develop_mode=0,
            block_id=11,
            constellation=gnuradio.digital.constellation_qpsk().base(),
            preamble=diff_preamble_128,
            samp_rate=samp_rate,
            sps=sps,
            system_time_granularity_us=system_time_granularity_us,
            usrp_device_address=usrp_device_address,
            center_frequency=tx_center_frequency)
        self.inets_receiving_0 = inets.receiving(
            1, 21,
            gnuradio.digital.constellation_qpsk().base(), rrc, mu,
            diff_preamble_128, rx_gain, samp_rate, sps, 30,
            usrp_device_address, rx_center_frequency)
        self.inets_framing_1 = inets.framing(0, 17, 2, 1, 0, 1,
                                             destination_address, 1,
                                             source_address, 1, 318, 2, 524, 2,
                                             2, 1, 1, 0)
        self.inets_framing_0 = inets.framing(0, 17, 1, 1, 0, 1,
                                             destination_address, 1,
                                             source_address, 1, 318, 2, 524, 2,
                                             2, 1, 1, 0)
        self.inets_frame_type_check_0 = inets.frame_type_check(
            0, 25, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1)
        self.inets_frame_probe_0 = inets.frame_probe(1, 100, 0)
        self.inets_frame_index_check_0 = inets.frame_index_check(
            1, 28, 1, 1, 1, 1, 1)
        self.inets_frame_filter_1 = inets.frame_filter(0, 26, 0, 0, 0, 0, 8, 0,
                                                       0, 1)
        self.inets_frame_buffer_0 = inets.frame_buffer(0, 16, 10, 1, 1)
        self.inets_frame_analysis_0 = inets.frame_analysis(
            0, 7, 1, 1, 1, 1, 1, 2, 2, 2, 1, source_address)
        self.inets_dummy_source_0 = inets.dummy_source(0, 23, 100, 2, 20)
        self.inets_address_check_0 = inets.address_check(0, 17, source_address)
        self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", 'localhost',
                                                     '52001', 10000, False)
        self.blocks_message_strobe_0 = blocks.message_strobe(
            pmt.intern("TEST"), 1000)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'),
                         (self.inets_dummy_source_0, 'trigger'))
        self.msg_connect(
            (self.inets_address_check_0, 'address_check_pass_out'),
            (self.inets_frame_type_check_0, 'frame_info_in'))
        self.msg_connect((self.inets_dummy_source_0, 'output'),
                         (self.inets_frame_buffer_0, 'enqueue'))
        self.msg_connect((self.inets_frame_analysis_0, 'frame_info_out'),
                         (self.inets_address_check_0, 'frame_info_in'))
        self.msg_connect((self.inets_frame_buffer_0, 'dequeue_element'),
                         (self.inets_framing_0, 'data_in'))
        self.msg_connect((self.inets_frame_filter_1, 'frame_info_out'),
                         (self.inets_sending_0, 'in'))
        self.msg_connect((self.inets_frame_index_check_0, 'frame_info_out'),
                         (self.inets_sending_0, 'in'))
        self.msg_connect(
            (self.inets_frame_type_check_0, 'data_frame_info_out'),
            (self.inets_framing_1, 'data_in'))
        self.msg_connect((self.inets_frame_type_check_0, 'ack_frame_info_out'),
                         (self.inets_timeout_0, 'ack_frame_info_in'))
        self.msg_connect((self.inets_framing_0, 'frame_out'),
                         (self.inets_slide_window_0, 'frame_info_in'))
        self.msg_connect((self.inets_framing_1, 'frame_out'),
                         (self.inets_frame_index_check_0, 'frame_in'))
        self.msg_connect((self.inets_receiving_0, 'rx_frame_out'),
                         (self.inets_frame_analysis_0, 'frame_in'))
        self.msg_connect((self.inets_slide_window_0, 'reload_request'),
                         (self.inets_frame_buffer_0, 'dequeue'))
        self.msg_connect((self.inets_slide_window_0, 'frame_info_out'),
                         (self.inets_frame_filter_1, 'frame_info_in'))
        self.msg_connect((self.inets_slide_window_0, 'frame_info_out'),
                         (self.inets_timeout_0, 'data_frame_info_in'))
        self.msg_connect((self.inets_timeout_0, 'frame_info_out'),
                         (self.inets_slide_window_0, 'ack_info_in'))
Example #46
0
 def __init__(self,
              n_bursts,
              n_channels,
              freq_delta,
              base_freq,
              dsp_tuning,
              burst_length,
              base_time,
              hop_time,
              post_tuning=False,
              tx_gain=0,
              verbose=False):
     gr.hier_block2.__init__(
         self,
         "FrequencyHopperSrc",
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
     )
     n_samples_total = n_bursts * burst_length
     lowest_frequency = base_freq - numpy.floor(n_channels / 2) * freq_delta
     self.hop_sequence = [
         lowest_frequency + n * freq_delta for n in range(n_channels)
     ]
     numpy.random.shuffle(self.hop_sequence)
     # Repeat that:
     self.hop_sequence = [
         self.hop_sequence[x % n_channels] for x in range(n_bursts)
     ]
     if verbose:
         print("Hop Frequencies  | Hop Pattern")
         print("=================|================================")
         for f in self.hop_sequence:
             print("{:6.3f} MHz      |  ".format(f / 1e6), end='')
             if n_channels < 50:
                 print(" " * int((f - base_freq) / freq_delta) + "#")
             else:
                 print("\n")
         print("=================|================================")
     # There's no real point in setting the gain via tag for this application,
     # but this is an example to show you how to do it.
     gain_tag = gr.tag_t()
     gain_tag.offset = 0
     gain_tag.key = pmt.string_to_symbol('tx_command')
     gain_tag.value = pmt.to_pmt({'gain': tx_gain})
     tag_list = [
         gain_tag,
     ]
     for i in range(len(self.hop_sequence)):
         time = pmt.cons(
             pmt.from_uint64(int(base_time + i * hop_time + 0.01)),
             pmt.from_double((base_time + i * hop_time + 0.01) % 1),
         )
         tune_tag = gr.tag_t()
         tune_tag.offset = i * burst_length
         # TODO dsp_tuning should also be able to do post_tuning
         if i > 0 and post_tuning and not dsp_tuning:
             tune_tag.offset -= 1  # Move it to last sample of previous burst
         if dsp_tuning:
             tune_tag.key = pmt.string_to_symbol('tx_command')
             tune_tag.value = pmt.to_pmt({
                 'lo_freq':
                 base_freq,
                 'dsp_freq':
                 base_freq - self.hop_sequence[i]
             })
             tune_tag.value = pmt.dict_add(tune_tag.value,
                                           pmt.intern("time"), time)
         else:
             tune_tag.key = pmt.string_to_symbol('tx_command')
             tune_tag.value = pmt.to_pmt({'freq': self.hop_sequence[i]})
             tune_tag.value = pmt.dict_add(tune_tag.value,
                                           pmt.intern('time'), time)
         tag_list.append(tune_tag)
         length_tag = gr.tag_t()
         length_tag.offset = i * burst_length
         length_tag.key = pmt.string_to_symbol('packet_len')
         length_tag.value = pmt.from_long(burst_length)
         tag_list.append(length_tag)
         time_tag = gr.tag_t()
         time_tag.offset = i * burst_length
         time_tag.key = pmt.string_to_symbol('tx_time')
         time_tag.value = pmt.make_tuple(pmt.car(time), pmt.cdr(time))
         tag_list.append(time_tag)
     tag_source = blocks.vector_source_c((1.0, ) * n_samples_total,
                                         repeat=False,
                                         tags=tag_list)
     mult = blocks.multiply_cc()
     self.connect(self, mult, self)
     self.connect(tag_source, (mult, 1))
Example #47
0
    def __init__(self):
        gr.top_block.__init__(self, "Wifi Tx")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Wifi Tx")
        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", "wifi_tx")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.tx_gain = tx_gain = 0.75
        self.samp_rate = samp_rate = 10e6
        self.pdu_length = pdu_length = 500
        self.out_buf_size = out_buf_size = 96000
        self.lo_offset = lo_offset = 0
        self.interval = interval = 300
        self.freq = freq = 5890000000
        self.encoding = encoding = 0

        ##################################################
        # Blocks
        ##################################################
        self._tx_gain_range = Range(0, 1, 0.01, 0.75, 200)
        self._tx_gain_win = RangeWidget(self._tx_gain_range, self.set_tx_gain,
                                        "tx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._tx_gain_win)
        self._samp_rate_options = [5e6, 10e6, 20e6]
        self._samp_rate_labels = ["5 MHz", "10 MHz", "20 MHz"]
        self._samp_rate_tool_bar = Qt.QToolBar(self)
        self._samp_rate_tool_bar.addWidget(Qt.QLabel("samp_rate" + ": "))
        self._samp_rate_combo_box = Qt.QComboBox()
        self._samp_rate_tool_bar.addWidget(self._samp_rate_combo_box)
        for label in self._samp_rate_labels:
            self._samp_rate_combo_box.addItem(label)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._samp_rate_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_combo_box.currentIndexChanged.connect(
            lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_tool_bar)
        self._pdu_length_range = Range(0, 1500, 1, 500, 200)
        self._pdu_length_win = RangeWidget(self._pdu_length_range,
                                           self.set_pdu_length, "pdu_length",
                                           "counter_slider", int)
        self.top_layout.addWidget(self._pdu_length_win)
        self._lo_offset_options = (
            0,
            6e6,
            11e6,
        )
        self._lo_offset_labels = (
            str(self._lo_offset_options[0]),
            str(self._lo_offset_options[1]),
            str(self._lo_offset_options[2]),
        )
        self._lo_offset_tool_bar = Qt.QToolBar(self)
        self._lo_offset_tool_bar.addWidget(Qt.QLabel("lo_offset" + ": "))
        self._lo_offset_combo_box = Qt.QComboBox()
        self._lo_offset_tool_bar.addWidget(self._lo_offset_combo_box)
        for label in self._lo_offset_labels:
            self._lo_offset_combo_box.addItem(label)
        self._lo_offset_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._lo_offset_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._lo_offset_options.index(i)))
        self._lo_offset_callback(self.lo_offset)
        self._lo_offset_combo_box.currentIndexChanged.connect(
            lambda i: self.set_lo_offset(self._lo_offset_options[i]))
        self.top_layout.addWidget(self._lo_offset_tool_bar)
        self._interval_range = Range(10, 1000, 1, 300, 200)
        self._interval_win = RangeWidget(self._interval_range,
                                         self.set_interval, "interval",
                                         "counter_slider", int)
        self.top_layout.addWidget(self._interval_win)
        self._freq_options = [
            2412000000.0, 2417000000.0, 2422000000.0, 2427000000.0,
            2432000000.0, 2437000000.0, 2442000000.0, 2447000000.0,
            2452000000.0, 2457000000.0, 2462000000.0, 2467000000.0,
            2472000000.0, 2484000000.0, 5170000000.0, 5180000000.0,
            5190000000.0, 5200000000.0, 5210000000.0, 5220000000.0,
            5230000000.0, 5240000000.0, 5250000000.0, 5260000000.0,
            5270000000.0, 5280000000.0, 5290000000.0, 5300000000.0,
            5310000000.0, 5320000000.0, 5500000000.0, 5510000000.0,
            5520000000.0, 5530000000.0, 5540000000.0, 5550000000.0,
            5560000000.0, 5570000000.0, 5580000000.0, 5590000000.0,
            5600000000.0, 5610000000.0, 5620000000.0, 5630000000.0,
            5640000000.0, 5660000000.0, 5670000000.0, 5680000000.0,
            5690000000.0, 5700000000.0, 5710000000.0, 5720000000.0,
            5745000000.0, 5755000000.0, 5765000000.0, 5775000000.0,
            5785000000.0, 5795000000.0, 5805000000.0, 5825000000.0,
            5860000000.0, 5870000000.0, 5880000000.0, 5890000000.0,
            5900000000.0, 5910000000.0, 5920000000.0
        ]
        self._freq_labels = [
            '  1 | 2412.0 | 11g', '  2 | 2417.0 | 11g', '  3 | 2422.0 | 11g',
            '  4 | 2427.0 | 11g', '  5 | 2432.0 | 11g', '  6 | 2437.0 | 11g',
            '  7 | 2442.0 | 11g', '  8 | 2447.0 | 11g', '  9 | 2452.0 | 11g',
            ' 10 | 2457.0 | 11g', ' 11 | 2462.0 | 11g', ' 12 | 2467.0 | 11g',
            ' 13 | 2472.0 | 11g', ' 14 | 2484.0 | 11g', ' 34 | 5170.0 | 11a',
            ' 36 | 5180.0 | 11a', ' 38 | 5190.0 | 11a', ' 40 | 5200.0 | 11a',
            ' 42 | 5210.0 | 11a', ' 44 | 5220.0 | 11a', ' 46 | 5230.0 | 11a',
            ' 48 | 5240.0 | 11a', ' 50 | 5250.0 | 11a', ' 52 | 5260.0 | 11a',
            ' 54 | 5270.0 | 11a', ' 56 | 5280.0 | 11a', ' 58 | 5290.0 | 11a',
            ' 60 | 5300.0 | 11a', ' 62 | 5310.0 | 11a', ' 64 | 5320.0 | 11a',
            '100 | 5500.0 | 11a', '102 | 5510.0 | 11a', '104 | 5520.0 | 11a',
            '106 | 5530.0 | 11a', '108 | 5540.0 | 11a', '110 | 5550.0 | 11a',
            '112 | 5560.0 | 11a', '114 | 5570.0 | 11a', '116 | 5580.0 | 11a',
            '118 | 5590.0 | 11a', '120 | 5600.0 | 11a', '122 | 5610.0 | 11a',
            '124 | 5620.0 | 11a', '126 | 5630.0 | 11a', '128 | 5640.0 | 11a',
            '132 | 5660.0 | 11a', '134 | 5670.0 | 11a', '136 | 5680.0 | 11a',
            '138 | 5690.0 | 11a', '140 | 5700.0 | 11a', '142 | 5710.0 | 11a',
            '144 | 5720.0 | 11a', '149 | 5745.0 | 11a (SRD)',
            '151 | 5755.0 | 11a (SRD)', '153 | 5765.0 | 11a (SRD)',
            '155 | 5775.0 | 11a (SRD)', '157 | 5785.0 | 11a (SRD)',
            '159 | 5795.0 | 11a (SRD)', '161 | 5805.0 | 11a (SRD)',
            '165 | 5825.0 | 11a (SRD)', '172 | 5860.0 | 11p',
            '174 | 5870.0 | 11p', '176 | 5880.0 | 11p', '178 | 5890.0 | 11p',
            '180 | 5900.0 | 11p', '182 | 5910.0 | 11p', '184 | 5920.0 | 11p'
        ]
        self._freq_tool_bar = Qt.QToolBar(self)
        self._freq_tool_bar.addWidget(Qt.QLabel("freq" + ": "))
        self._freq_combo_box = Qt.QComboBox()
        self._freq_tool_bar.addWidget(self._freq_combo_box)
        for label in self._freq_labels:
            self._freq_combo_box.addItem(label)
        self._freq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._freq_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._freq_options.index(i)))
        self._freq_callback(self.freq)
        self._freq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_freq(self._freq_options[i]))
        self.top_layout.addWidget(self._freq_tool_bar)
        self._encoding_options = [0, 1, 2, 3, 4, 5, 6, 7]
        self._encoding_labels = [
            "BPSK 1/2", "BPSK 3/4", "QPSK 1/2", "QPSK 3/4", "16QAM 1/2",
            "16QAM 3/4", "64QAM 2/3", "64QAM 3/4"
        ]
        self._encoding_group_box = Qt.QGroupBox("encoding")
        self._encoding_box = Qt.QHBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._encoding_button_group = variable_chooser_button_group()
        self._encoding_group_box.setLayout(self._encoding_box)
        for i, label in enumerate(self._encoding_labels):
            radio_button = Qt.QRadioButton(label)
            self._encoding_box.addWidget(radio_button)
            self._encoding_button_group.addButton(radio_button, i)
        self._encoding_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._encoding_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._encoding_options.index(i)))
        self._encoding_callback(self.encoding)
        self._encoding_button_group.buttonClicked[int].connect(
            lambda i: self.set_encoding(self._encoding_options[i]))
        self.top_layout.addWidget(self._encoding_group_box)
        self.wifi_phy_hier_0 = wifi_phy_hier(
            bandwidth=10e6,
            chan_est=0,
            encoding=encoding,
            frequency=5.89e9,
            sensitivity=0.56,
        )
        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_subdev_spec('A:B', 0)
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_time_now(uhd.time_spec(time.time()),
                                          uhd.ALL_MBOARDS)
        self.uhd_usrp_sink_0.set_center_freq(
            uhd.tune_request(freq,
                             rf_freq=freq - lo_offset,
                             rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0)
        self.uhd_usrp_sink_0.set_normalized_gain(tx_gain, 0)
        self.ieee802_11_mac_0 = ieee802_11.mac(
            ([0x23, 0x23, 0x23, 0x23, 0x23, 0x23]),
            ([0x42, 0x42, 0x42, 0x42, 0x42, 0x42]),
            ([0xff, 0xff, 0xff, 0xff, 0xff, 255]))
        self.foo_packet_pad2_0 = foo.packet_pad2(False, False, 0.01, 100, 1000)
        (self.foo_packet_pad2_0).set_min_output_buffer(96000)
        self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_SERVER", '', '52001',
                                                     10000, False)
        self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex *
                                                       1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.6, ))
        (self.blocks_multiply_const_vxx_0).set_min_output_buffer(100000)
        self.blocks_message_strobe_0_0 = blocks.message_strobe(
            pmt.intern("".join("x" for i in range(pdu_length))), interval)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0_0, 'strobe'),
                         (self.ieee802_11_mac_0, 'app in'))
        self.msg_connect((self.blocks_socket_pdu_0, 'pdus'),
                         (self.ieee802_11_mac_0, 'app in'))
        self.msg_connect((self.ieee802_11_mac_0, 'phy out'),
                         (self.wifi_phy_hier_0, 'mac_in'))
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'),
                         (self.ieee802_11_mac_0, 'phy in'))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.foo_packet_pad2_0, 0))
        self.connect((self.blocks_null_source_0, 0), (self.wifi_phy_hier_0, 0))
        self.connect((self.foo_packet_pad2_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.wifi_phy_hier_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
Example #48
0
 def text_changed(self):
     s = self.text().toUtf8()
     nvec = numpy.fromstring((s), dtype=numpy.uint8, count=len(s))
     vec = pmt.to_pmt(nvec)
     self.message_port_pub(pmt.intern("pdus"), pmt.cons(pmt.PMT_NIL, vec))
     self.clear()