Evening all,

I am working on a project to realise some form of cognitive radio.

I am new to GNURadio so please bear with me.

I have so far successfully enabled a spectrum scan and can set a local
variable based on this for the optimum channel.  Additionally, I have been
able to transmit that frequency (using a file) to the receiver for an over
the air reconfiguration (OTAR).

What I am struggling with now, and hopefully it is a simple solution, Once
I have sent the file for the OTAR I wish that python file generated by
GNURadio to automatically close after a time period, say 30 secs.  This
should trigger the quitting rule, within this is the command to open my
second transmission file which will send the data file.

Is there a simple way to get the GNURadio file to automatically quit after
a given time period?

Attached is my .py file which has been slightly tweaked but commented on at
the top
#!/usr/bin/env python2
# 
-*- coding: utf-8 -*-

##################################################
#GNU Radio Python Flow Graph
# Title: Gmsk Tx

# Generated: Mon Jul 31 16:38:52 2017

#Edited for Project (import os and os.system("python ./Basic_SigGen.py") in def 
quitting():
#################################################



if __name__ == '__main__':
    
        import ctypes
    
        import sys
    
        if sys.platform.startswith('linux'):
        
                try:
            
                        x11 = ctypes.cdll.LoadLibrary('libX11.so')
            
                        x11.XInitThreads()
        
                except:
            
                        print "Warning:failed to XInitThreads()"



from PyQt4 import Qt

from gnuradio import blocks

from gnuradio import digital

from gnuradio import eng_notation

from gnuradio import gr

from gnuradio import uhd

from gnuradio.eng_option import eng_option

from gnuradio.filter import firdes

from grc_gnuradio import blks2 as grc_blks2

from optparse import OptionParser

import sys

import time

import os




class GMSK_TX(gr.top_block, Qt.QWidget):


    def __init__(self):
        
        gr.top_block.__init__(self, "Gmsk Tx")
        
        Qt.QWidget.__init__(self)
        
        self.setWindowTitle("Gmsk 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", "GMSK_TX")

        self.restoreGeometry(self.settings.value("geometry").toByteArray())



##################################################
        
# Variables
        
##################################################
        

        self.samp_rate = samp_rate = 1e6

        self.freq = freq = 2e9
        
        self.code1 = code1 = 
'010110011011101100010101011111101001001110001011010001101010001'



##################################################
        
# Blocks
        
##################################################
        

        self.uhd_usrp_sink_0_0 = uhd.usrp_sink(

                ",".join(("", "")),

                uhd.stream_args(

                        cpu_format="fc32",
                        
                        channels=range(1),
                
                ),
        
        )
        
        self.uhd_usrp_sink_0_0.set_samp_rate(samp_rate)
        
        self.uhd_usrp_sink_0_0.set_center_freq(freq, 0)
        
        self.uhd_usrp_sink_0_0.set_gain(30, 0)
        
        self.uhd_usrp_sink_0_0.set_antenna('TX/RX', 0)
        
        self.digital_gmsk_mod_0 = digital.gmsk_mod(
                
                samples_per_symbol=2,
                
                bt=0.35,
                
                verbose=False,
                
                log=False,
        
        )
        
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((1, ))
        
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, 
'/root/optimum_freq.csv', False)
        
        self.blks2_packet_encoder_0 = 
grc_blks2.packet_mod_b(grc_blks2.packet_encoder(

                        samples_per_symbol=2,

                        bits_per_symbol=1,
                        
                        preamble='',
                        
                        access_code=code1,
                        
                        pad_for_usrp=True,
                
                ),
                
                payload_length=1,
        
        )

        

##################################################
        
# Connections
        
##################################################
        

        self.connect((self.blks2_packet_encoder_0, 0), 
(self.digital_gmsk_mod_0, 0))
    
    self.connect((self.blocks_file_source_0, 0), (self.blks2_packet_encoder_0, 
0))
    
    self.connect((self.blocks_multiply_const_vxx_0, 0), 
(self.uhd_usrp_sink_0_0, 0))    
        
        self.connect((self.digital_gmsk_mod_0, 0), 
(self.blocks_multiply_const_vxx_0, 0))    

    

    def closeEvent(self, event):

        self.settings = Qt.QSettings("GNU Radio", "GMSK_TX")

        self.settings.setValue("geometry", self.saveGeometry())

        event.accept()


    
    def get_samp_rate(self):

        return self.samp_rate


    
    def set_samp_rate(self, samp_rate):

        self.samp_rate = samp_rate

        self.uhd_usrp_sink_0_0.set_samp_rate(self.samp_rate)


    
    def get_freq(self):

        return self.freq
    
    def set_freq(self, freq):

        self.freq = freq

        self.uhd_usrp_sink_0_0.set_center_freq(self.freq, 0)


    
    def get_code1(self):

        return self.code1


    
    def set_code1(self, code1):

        self.code1 = code1




def main(top_block_cls=GMSK_TX, options=None):


    from distutils.version import StrictVersion

    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):

        style = gr.prefs().get_string('qtgui', 'style', 'raster')

        Qt.QApplication.setGraphicsSystem(style)
    
    qapp = Qt.QApplication(sys.argv)

    tb = top_block_cls()
    
    tb.start()
    
    tb.show()
    
    def quitting():
        
        tb.stop()
        
        tb.wait()
        
        os.system("python ./Basic_SigGen.py")
    
    qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
    
    qapp.exec_()




if __name__ == '__main__':
    
    main()
_______________________________________________
Discuss-gnuradio mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to