Esempio n. 1
0
def main(args=None):
    args = args or argument_parser().parse_args()

    platform = Platform(
        name="GNU Radio Companion Compiler",
        prefs=gr.prefs(),
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
    )
    platform.build_library()

    out_dir = (
        args.output if not args.user_lib_dir else platform.config.hier_block_lib_dir
    )
    if os.path.exists(out_dir):
        pass  # all is well
    elif args.save_to_lib:
        os.mkdir(out_dir)  # create missing hier_block lib directory
    else:
        exit("Error: Invalid output directory")

    Messages.send_init(platform)
    flow_graph = file_path = None
    for grc_file in args.grc_files:
        os.path.exists(grc_file) or exit("Error: missing " + grc_file)
        Messages.send("\n")

        flow_graph, file_path = platform.load_and_generate_flow_graph(
            os.path.abspath(grc_file), os.path.abspath(out_dir)
        )
        if not file_path:
            exit("Compilation error")
    if file_path and args.run:
        run_command_args = flow_graph.get_run_command(file_path, split=True)
        subprocess.call(run_command_args)
Esempio n. 2
0
    def __init__(self, ip=None, port=None, options=None):
        gr.hier_block2.__init__(self, 'codec2_udp_sink',
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))
        options_block.__init__(self, options)
        self.message_port_register_hier_in('in')

        if ip is None:
            ip = self.options.codec2_ip
        if port is None:
            port = self.options.codec2_port

        self.pdu2tag = blocks.pdu_to_tagged_stream(byte_t, 'packet_len')
        payload_bytes = 7
        # The UDP sink has been moved in GNU Radio 3.10
        if gr.api_version() == '9':
            self.udp = udp_sink(gr.sizeof_char * 1, ip, port, payload_bytes,
                                False)
        else:
            udp_header = 0  # no header
            # The new UDP sink requires at least 8 bytes of payload.
            # We use 14 bytes, which is 2 codec2 frames.
            payload_bytes = 14
            self.udp = network.udp_sink(gr.sizeof_char, 1, ip, port,
                                        udp_header, payload_bytes, False)
        self.msg_connect((self, 'in'), (self.pdu2tag, 'pdus'))
        self.connect(self.pdu2tag, self.udp)
Esempio n. 3
0
def main(args=None):
    args = args or argument_parser().parse_args()

    platform = Platform(name='GNU Radio Companion Compiler',
                        prefs=gr.prefs(),
                        version=gr.version(),
                        version_parts=(gr.major_version(), gr.api_version(),
                                       gr.minor_version()))
    platform.build_library()

    output_dir = args.output if not args.user_lib_dir else platform.config.hier_block_lib_dir
    try:
        # recursive mkdir: os.makedirs doesn't work with .. paths, resolve with realpath
        os.makedirs(os.path.realpath(output_dir), exist_ok=True)
    except Exception as e:
        exit(str(e))

    Messages.send_init(platform)
    flow_graph = file_path = None
    for grc_file in args.grc_files:
        os.path.exists(grc_file) or exit('Error: missing ' + grc_file)
        Messages.send('\n')

        flow_graph, file_path = platform.load_and_generate_flow_graph(
            os.path.abspath(grc_file), os.path.abspath(output_dir))
        if not file_path:
            exit('Compilation error')
    if file_path and args.run:
        run_command_args = flow_graph.get_run_command(file_path, split=True)
        subprocess.call(run_command_args)
Esempio n. 4
0
def main(args=None):
    args = args or argument_parser().parse_args()

    platform = Platform(
        name='GNU Radio Companion Compiler',
        prefs=gr.prefs(),
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version())
    )
    platform.build_library()

    out_dir = args.output if not args.user_lib_dir else platform.config.hier_block_lib_dir
    if os.path.exists(out_dir):
        pass  # all is well
    elif args.save_to_lib:
        os.mkdir(out_dir)  # create missing hier_block lib directory
    else:
        exit('Error: Invalid output directory')

    Messages.send_init(platform)
    flow_graph = file_path = None
    for grc_file in args.grc_files:
        os.path.exists(grc_file) or exit('Error: missing ' + grc_file)
        Messages.send('\n')

        flow_graph, file_path = platform.load_and_generate_flow_graph(
            os.path.abspath(grc_file), os.path.abspath(out_dir))
        if not file_path:
            exit('Compilation error')
    if file_path and args.run:
        run_command_args = flow_graph.get_run_command(file_path, split=True)
        subprocess.call(run_command_args)
Esempio n. 5
0
    def __init__(self):
        """
        Make a platform for gnuradio.
        """
        # ensure hier and conf directories
        if not os.path.exists(HIER_BLOCKS_LIB_DIR):
            os.mkdir(HIER_BLOCKS_LIB_DIR)
        if not os.path.exists(os.path.dirname(PREFS_FILE)):
            os.mkdir(os.path.dirname(PREFS_FILE))

        self.block_docstrings = {}
        self.block_docstrings_loaded_callback = lambda: None  # dummy to be replaced by BlockTreeWindow

        self._docstring_extractor = extract_docs.SubprocessLoader(
            callback_query_result=self._save_docstring_extraction_result,
            callback_finished=lambda: self.block_docstrings_loaded_callback())

        # init
        _Platform.__init__(
            self,
            name='GNU Radio Companion',
            version=(gr.version(), gr.major_version(), gr.api_version(),
                     gr.minor_version()),
            key='grc',
            license=__doc__.strip(),
            website='http://gnuradio.org/',
            block_paths=BLOCKS_DIRS,
            block_dtd=BLOCK_DTD,
            default_flow_graph=DEFAULT_FLOW_GRAPH,
            generator=Generator,
            colors=[(name, color) for name, key, sizeof, color in CORE_TYPES],
        )
        self._move_old_pref_file()
        _GUIPlatform.__init__(self, prefs_file=PREFS_FILE)
        self._auto_hier_block_generate_chain = set()
Esempio n. 6
0
    def __init__(self):
        """
        Make a platform for gnuradio.
        """
        #ensure hier dir
        if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR)
        #init
        _Platform.__init__(
            self,
            name='GNU Radio Companion',
            version=(gr.version(), gr.major_version(), gr.api_version(), gr.minor_version()),
            key='grc',
            license=__doc__.strip(),
            website='http://gnuradio.org/',
            block_paths=BLOCKS_DIRS,
            block_dtd=BLOCK_DTD,
            default_flow_graph=DEFAULT_FLOW_GRAPH,
            generator=Generator,
            colors=COLORS,
        )

        _GUIPlatform.__init__(
            self,
            prefs_file=PREFS_FILE
        )
Esempio n. 7
0
def grc_to_py(grcfile, outdir):
    platform = Platform(prefs_file=gr.prefs(),
                        version=gr.version(),
                        version_parts=(gr.major_version(), gr.api_version(),
                                       gr.minor_version()))
    data = platform.parse_flow_graph(grcfile)

    # Clean out the QT GUI, etc.
    blocks = data['flow_graph']['block']
    for b in blocks:
        if b['key'] == 'options':
            for opt in b['param']:
                if opt['key'] == 'generate_options' and opt[
                        'value'] != 'no_gui':
                    opt['value'] = 'no_gui'
                elif opt['key'] == 'run_options' and opt['value'] != 'run':
                    opt['value'] = 'run'
                elif opt['key'] == 'run' and opt['value'] != 'False':
                    opt['value'] = 'False'

    fg = platform.get_new_flow_graph()
    fg.import_data(data)
    fg.grc_file_path = os.path.abspath(grcfile)
    fg.validate()

    if not fg.is_valid():
        raise StandardError("\n\n".join(["Validation failed:"] +
                                        fg.get_error_messages()))

    if outdir[-1] != '/':
        outdir += '/'
    gen = platform.Generator(fg, outdir)
    gen.write()
Esempio n. 8
0
def main():
    from gnuradio import gr
    parser = argparse.ArgumentParser(
        description=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
    parser.add_argument('flow_graphs', nargs='*')
    parser.add_argument(
        '--log',
        choices=['debug', 'info', 'warning', 'error', 'critical'],
        default='warning')
    args = parser.parse_args()

    # Enable logging
    # Note: All other modules need to use the 'grc.<module>' convention
    log = logging.getLogger('grc')
    # NOTE: This sets the log level to what was requested for the logger on the
    # command line, but this may not be the correct approach if multiple handlers
    # are intended to be used. The logger level shown here indicates all the log
    # messages that are captured and the handler levels indicate messages each
    # handler will output. A better approach may be resetting this to logging.DEBUG
    # to catch everything and making sure the handlers have the correct levels set.
    # This would be useful for a future GUI logging window that can filter messages
    # independently of the console output. In this case, this should be DEBUG.
    log.setLevel(LOG_LEVELS[args.log])

    # Console formatting
    console = logging.StreamHandler()
    console.setLevel(LOG_LEVELS[args.log])

    #msg_format = '[%(asctime)s - %(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)'
    msg_format = '[%(levelname)s] %(message)s (%(filename)s:%(lineno)s)'
    date_format = '%I:%M'
    formatter = logging.Formatter(msg_format, datefmt=date_format)

    #formatter = utils.log.ConsoleFormatter()
    console.setFormatter(formatter)
    log.addHandler(console)

    py_version = sys.version.split()[0]
    log.debug("Starting GNU Radio Companion ({})".format(py_version))

    # Delay importing until the logging is setup
    from .gui.Platform import Platform
    from .gui.Application import Application

    log.debug("Loading platform")
    platform = Platform(version=gr.version(),
                        version_parts=(gr.major_version(), gr.api_version(),
                                       gr.minor_version()),
                        prefs=gr.prefs(),
                        install_prefix=gr.prefix())
    platform.build_library()

    log.debug("Loading application")
    app = Application(args.flow_graphs, platform)
    log.debug("Running")
    sys.exit(app.run())
Esempio n. 9
0
def main():
    from gnuradio import gr
    parser = argparse.ArgumentParser(
        description=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
    parser.add_argument('flow_graphs', nargs='*')
    parser.add_argument(
        '--log',
        choices=['debug', 'info', 'warning', 'error', 'critical'],
        default='warning')
    args = parser.parse_args()

    try:
        Gtk.window_set_default_icon(Gtk.IconTheme().load_icon(
            'gnuradio-grc', 256, 0))
    except:
        pass

    # Enable logging
    # Note: All other modules need to use the 'grc.<module>' convention
    log = logging.getLogger('grc')
    log.setLevel(logging.DEBUG)

    # Console formatting
    console = logging.StreamHandler()
    console.setLevel(LOG_LEVELS[args.log])

    #msg_format = '[%(asctime)s - %(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)'
    msg_format = '[%(levelname)s] %(message)s (%(filename)s:%(lineno)s)'
    date_format = '%I:%M'
    formatter = logging.Formatter(msg_format, datefmt=date_format)

    #formatter = utils.log.ConsoleFormatter()
    console.setFormatter(formatter)
    log.addHandler(console)

    py_version = sys.version.split()[0]
    log.debug("Starting GNU Radio Companion ({})".format(py_version))

    # Delay importing until the logging is setup
    from .gui.Platform import Platform
    from .gui.Application import Application

    log.debug("Loading platform")
    platform = Platform(version=gr.version(),
                        version_parts=(gr.major_version(), gr.api_version(),
                                       gr.minor_version()),
                        prefs=gr.prefs(),
                        install_prefix=gr.prefix())
    platform.build_library()

    log.debug("Loading application")
    app = Application(args.flow_graphs, platform)
    log.debug("Running")
    sys.exit(app.run())
Esempio n. 10
0
def main():
    from gnuradio import gr

    parser = argparse.ArgumentParser(
        description=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
    parser.add_argument("flow_graphs", nargs="*")
    parser.add_argument(
        "--log",
        choices=["debug", "info", "warning", "error", "critical"],
        default="warning",
    )
    args = parser.parse_args()

    # Enable logging
    # Note: All other modules need to use the 'grc.<module>' convention
    log = logging.getLogger("grc")
    log.setLevel(logging.INFO)

    # Console formatting
    console = logging.StreamHandler()
    console.setLevel(LOG_LEVELS[args.log])

    # msg_format = '[%(asctime)s - %(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)'
    msg_format = "[%(levelname)s] %(message)s (%(filename)s:%(lineno)s)"
    date_format = "%I:%M"
    formatter = logging.Formatter(msg_format, datefmt=date_format)

    # formatter = utils.log.ConsoleFormatter()
    console.setFormatter(formatter)
    log.addHandler(console)

    py_version = sys.version.split()[0]
    log.debug("Starting GNU Radio Companion ({})".format(py_version))

    # Delay importing until the logging is setup
    from .gui.Platform import Platform
    from .gui.Application import Application

    log.debug("Loading platform")
    platform = Platform(
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(),
                       gr.minor_version()),
        prefs=gr.prefs(),
        install_prefix=gr.prefix(),
    )
    platform.build_library()

    log.debug("Loading application")
    app = Application(args.flow_graphs, platform)
    log.debug("Running")
    sys.exit(app.run())
Esempio n. 11
0
def main():
    from gnuradio import gr
    parser = argparse.ArgumentParser(
        description=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
    parser.add_argument('flow_graphs', nargs='*')
    parser.add_argument('--log', choices=['debug', 'info', 'warning', 'error', 'critical'], default='warning')
    args = parser.parse_args()

    # Enable logging
    # Note: All other modules need to use the 'grc.<module>' convention
    log = logging.getLogger('grc')
    log.setLevel(logging.DEBUG)

    # Console formatting
    console = logging.StreamHandler()
    console.setLevel(LOG_LEVELS[args.log])

    #msg_format = '[%(asctime)s - %(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)'
    msg_format = '[%(levelname)s] %(message)s (%(filename)s:%(lineno)s)'
    date_format = '%I:%M'
    formatter = logging.Formatter(msg_format, datefmt=date_format)

    #formatter = utils.log.ConsoleFormatter()
    console.setFormatter(formatter)
    log.addHandler(console)

    py_version = sys.version.split()[0]
    log.debug("Starting GNU Radio Companion ({})".format(py_version))

    # Delay importing until the logging is setup
    from .gui.Platform import Platform
    from .gui.Application import Application

    log.debug("Loading platform")
    platform = Platform(
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
        prefs=gr.prefs(),
        install_prefix=gr.prefix()
    )
    platform.build_library()

    log.debug("Loading application")
    app = Application(args.flow_graphs, platform)
    log.debug("Running")
    sys.exit(app.run())
Esempio n. 12
0
    def __init__(self):
        """
        Make a platform for gnuradio.
        """
        # ensure hier and conf directories
        if not os.path.exists(HIER_BLOCKS_LIB_DIR):
            os.mkdir(HIER_BLOCKS_LIB_DIR)
        if not os.path.exists(os.path.dirname(PREFS_FILE)):
            os.mkdir(os.path.dirname(PREFS_FILE))

        self.block_docstrings = block_docstrings = dict()
        self.block_docstrings_loaded_callback = lambda: None

        def setter(key, docs):
            block_docstrings[key] = '\n\n'.join(
                '--- {0} ---\n{1}\n'.format(b, d.replace('\n\n', '\n'))
                for b, d in docs.iteritems() if d is not None
            )

        self._docstring_extractor = extract_docs.SubprocessLoader(
            callback_query_result=setter,
            callback_finished=lambda: self.block_docstrings_loaded_callback()
        )

        # init
        _Platform.__init__(
            self,
            name='GNU Radio Companion',
            version=(gr.version(), gr.major_version(), gr.api_version(), gr.minor_version()),
            key='grc',
            license=__doc__.strip(),
            website='http://gnuradio.org/',
            block_paths=BLOCKS_DIRS,
            block_dtd=BLOCK_DTD,
            default_flow_graph=DEFAULT_FLOW_GRAPH,
            generator=Generator,
            colors=COLORS,
        )
        self._move_old_pref_file()
        _GUIPlatform.__init__(
            self,
            prefs_file=PREFS_FILE
        )
        self._auto_hier_block_generate_chain = set()
Esempio n. 13
0
def main():
    parser = optparse.OptionParser(
        usage='usage: %prog [options] [saved flow graphs]',
        version=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
    options, args = parser.parse_args()

    try:
        gtk.window_set_default_icon(gtk.IconTheme().load_icon('gnuradio-grc', 256, 0))
    except:
        pass

    platform = Platform(
        prefs_file=gr.prefs(),
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
        install_prefix=gr.prefix()
    )
    ActionHandler(args, platform)
    gtk.main()
Esempio n. 14
0
def main():
    parser = optparse.OptionParser(
        usage='usage: %prog [options] [saved flow graphs]',
        version=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
    options, args = parser.parse_args()

    try:
        gtk.window_set_default_icon(gtk.IconTheme().load_icon('gnuradio-grc', 256, 0))
    except:
        pass

    platform = Platform(
        prefs_file=gr.prefs(),
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
        install_prefix=gr.prefix()
    )
    ActionHandler(args, platform)
    gtk.main()
Esempio n. 15
0
    def __init__(self):
        """
        Make a platform for gnuradio.
        """
        # ensure hier and conf directories
        if not os.path.exists(HIER_BLOCKS_LIB_DIR):
            os.mkdir(HIER_BLOCKS_LIB_DIR)
        if not os.path.exists(os.path.dirname(PREFS_FILE)):
            os.mkdir(os.path.dirname(PREFS_FILE))

        self.block_docstrings = block_docstrings = dict()
        self.block_docstrings_loaded_callback = lambda: None

        def setter(key, docs):
            block_docstrings[key] = '\n\n'.join(
                '--- {0} ---\n{1}\n'.format(b, d.replace('\n\n', '\n'))
                for b, d in docs.iteritems() if d is not None)

        self._docstring_extractor = extract_docs.SubprocessLoader(
            callback_query_result=setter,
            callback_finished=lambda: self.block_docstrings_loaded_callback())

        # init
        _Platform.__init__(
            self,
            name='GNU Radio Companion',
            version=(gr.version(), gr.major_version(), gr.api_version(),
                     gr.minor_version()),
            key='grc',
            license=__doc__.strip(),
            website='http://gnuradio.org/',
            block_paths=BLOCKS_DIRS,
            block_dtd=BLOCK_DTD,
            default_flow_graph=DEFAULT_FLOW_GRAPH,
            generator=Generator,
            colors=COLORS,
        )
        self._move_old_pref_file()
        _GUIPlatform.__init__(self, prefs_file=PREFS_FILE)
        self._auto_hier_block_generate_chain = set()
Esempio n. 16
0
    def __init__(self):
        """
        Make a platform for gnuradio.
        """
        # ensure hier and conf directories
        if not os.path.exists(HIER_BLOCKS_LIB_DIR):
            os.mkdir(HIER_BLOCKS_LIB_DIR)
        if not os.path.exists(os.path.dirname(PREFS_FILE)):
            os.mkdir(os.path.dirname(PREFS_FILE))

        self.block_docstrings = {}
        self.block_docstrings_loaded_callback = lambda: None  # dummy to be replaced by BlockTreeWindow

        self._docstring_extractor = extract_docs.SubprocessLoader(
            callback_query_result=self._save_docstring_extraction_result,
            callback_finished=lambda: self.block_docstrings_loaded_callback()
        )

        # init
        _Platform.__init__(
            self,
            name='GNU Radio Companion',
            version=(gr.version(), gr.major_version(), gr.api_version(), gr.minor_version()),
            key='grc',
            license=__doc__.strip(),
            website='http://gnuradio.org/',
            block_paths=BLOCKS_DIRS,
            block_dtd=BLOCK_DTD,
            default_flow_graph=DEFAULT_FLOW_GRAPH,
            generator=Generator,
            colors=[(name, color) for name, key, sizeof, color in CORE_TYPES],
        )
        self._move_old_pref_file()
        _GUIPlatform.__init__(
            self,
            prefs_file=PREFS_FILE
        )
        self._auto_hier_block_generate_chain = set()
    import tempfile
    import threading

    import gi

    gi.require_version("Gtk", "3.0")
    gi.require_version("PangoCairo", "1.0")
    from gi.repository import GLib
    from gnuradio import gr
    from gnuradio.grc.gui.Platform import Platform
    from gnuradio.grc.gui.Application import Actions, Application

    # include the necessary boilerplate from grc's main function to create the app
    platform = Platform(
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(),
                       gr.minor_version()),
        prefs=gr.prefs(),
        install_prefix=gr.prefix(),
    )
    platform.build_library()

    # pick an example that runs a bunch of qt-gui sinks
    example_grc_path = (pathlib.Path(gr.prefix()) / "share" / "gnuradio" /
                        "examples" / "qt-gui" / "qtgui_multi_input.grc")
    app = Application((example_grc_path, ), platform)

    # script what we want to try out with the app
    def script(app):
        # ensure the app is initialized before proceeding
        while not app.init:
Esempio n. 18
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2019 Daniel Estevez <*****@*****.**>
#
# This file is part of gr-satellites
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from gnuradio import gr, blocks

if gr.api_version() != '9':
    from gnuradio import network

from ...utils.options_block import options_block
from ...grtypes import byte_t


class codec2_udp_sink(gr.hier_block2, options_block):
    """
    Hierarchical block for Codec2 UDP output

    The input are PDUs with Codec2 data

    The Codec2 data is sent to by PDU, a single frame (7 bytes)
    per packet for lowest latency.

    Args:
      ip: Detination IP (string)
      port: Destination UDP port (int)
Esempio n. 19
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2022 Daniel Estevez <*****@*****.**>
#
# This file is part of gr-satellites
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

# This gives a wrapper around gnuradio.gr.types.*_t (GNU Radio 3.10)
# and gnuradio.blocks.*_t (GNU Radio 3.9), so that the same gr-satellites
# code base can work with both versions of GNU Radio

from gnuradio import gr

api_version = int(gr.api_version())
if api_version == 9:
    from gnuradio.blocks import byte_t, complex_t, float_t
elif api_version >= 10:
    from gnuradio.gr.gr_python.types import byte_t, complex_t, float_t
else:
    raise ValueError('unsupported GNU Radio API version', api_version)