Any Python programmers on here that can help.

  • Sorry to ask, but I could do with a little bit of help to get me moving.


    I use gnu radio to drive an SDR for DATV, I slightly reworked an existing flowgraph without any GUI, and use the generated .py file from a script in Linux.


    I am wondering if I can pass variables from command line to the python file at run time.


    For example here are the first few lines from the Python script.


    #!/usr/bin/env python2
    # -*- coding: utf-8 -*-
    ##################################################
    # GNU Radio Python Flow Graph
    # Title: Sr250
    # Generated: Sat Aug 3 00:17:48 2019
    ##################################################
                                                                                                                                       
                                                                                                                                       
    from gnuradio import blocks
    from gnuradio import dtv
    from gnuradio import eng_notation
    from gnuradio import filter
    from gnuradio import gr
    from gnuradio.eng_option import eng_option
    from gnuradio.filter import firdes
    from optparse import OptionParser
    import osmosdr
    import time


    class SR250(gr.top_block):

    def __init__(self):
    gr.top_block.__init__(self, "Sr250")

    ##################################################
    # Variables
    ##################################################
    self.symbol_rate = symbol_rate = 250e3
    self.taps = taps = 80
    self.samp_rate = samp_rate = symbol_rate * 2
    self.rolloff = rolloff = 0.35
    self.resample = resample = int(round(5e6/symbol_rate))
    self.center_freq = center_freq = 2408.9e6

    ##################################################
    # Blocks
    ##################################################
    self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
    interpolation=resample,


    So it would be good to add the frequency as an external variable and possibly the symbol rate. I think the answer lies with Import sys, but to date my tries have failed me.


    So if there is a Python Guru out there that could put me in the correct direction it would be appreciated.



    Adrian

  • OK, went a different route to 'import sys' as I found a tutorial on another method which is probably a lot safer.


    I am up to this at present:-



    #!/usr/bin/env python2
    # -*- coding: utf-8 -*-
    ##################################################
    # GNU Radio Python Flow Graph
    # Title: dvbs2
    # Generated: Sat Aug 3 00:17:48 2019
    # Modified for external command line variables G8UGD 26/11/2019
    ##################################################

    from gnuradio import blocks
    from gnuradio import dtv
    from gnuradio import eng_notation
    from gnuradio import filter
    from gnuradio import gr
    from gnuradio.eng_option import eng_option
    from gnuradio.filter import firdes
    from optparse import OptionParser
    import osmosdr
    import time
    import argparse

    parser = argparse.ArgumentParser(description='Frequency, IF gain and Symbol rate')
    parser.add_argument("-cf", default=2409.7, type=float, help="This is the 'cf' centre frequency variable")
    parser.add_argument("-ifg", default=1, type=int, help="This is the 'ifg' TX IF Gain variable")
    parser.add_argument("-ks", default=250, type=int, help="This is the 'ks' Symbol rate variable ie 250, 333 etc.")
    args = parser.parse_args()
    cf = args.cf
    ifg = args.ifg
    ks = args.ks


    class dvbs2(gr.top_block):

    def __init__(self):
    gr.top_block.__init__(self, "dvbs2")

    ##################################################
    # Variables
    ##################################################
    self.symbol_rate = symbol_rate = ks * 1e3
    self.taps = taps = 80
    self.samp_rate = samp_rate = symbol_rate * 2
    self.rolloff = rolloff = 0.35
    self.resample = resample = int(round(5e6/symbol_rate))
    self.center_freq = center_freq = cf * 1e6
    ##################################################
    # Blocks
    etc


    I have never programmed in Python so I am sure there are better ways at doing this, Changing the modulation and FEC seem to be more difficult, but I will continue to try. It keeps the mushy grey matter healthier.


    Adrian