commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8031 - in grc/branches/grc_reloaded: . scripts src/gr


From: jblum
Subject: [Commit-gnuradio] r8031 - in grc/branches/grc_reloaded: . scripts src/grc src/grc_gnuradio src/grc_gnuradio/blks2 src/grc_gnuradio/data
Date: Sun, 16 Mar 2008 01:41:48 -0600 (MDT)

Author: jblum
Date: 2008-03-16 01:41:46 -0600 (Sun, 16 Mar 2008)
New Revision: 8031

Added:
   grc/branches/grc_reloaded/src/grc_gnuradio/Block.py
   grc/branches/grc_reloaded/src/grc_gnuradio/Connection.py
   grc/branches/grc_reloaded/src/grc_gnuradio/FlowGraph.py
   grc/branches/grc_reloaded/src/grc_gnuradio/Generator.py
   grc/branches/grc_reloaded/src/grc_gnuradio/Param.py
   grc/branches/grc_reloaded/src/grc_gnuradio/Platform.py
   grc/branches/grc_reloaded/src/grc_gnuradio/Port.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blocks/
   grc/branches/grc_reloaded/src/grc_gnuradio/data/
Removed:
   grc/branches/grc_reloaded/src/grc/platforms/
Modified:
   grc/branches/grc_reloaded/scripts/grc
   grc/branches/grc_reloaded/scripts/usrp_diagnostics
   grc/branches/grc_reloaded/setup.py
   grc/branches/grc_reloaded/src/grc/ActionHandler.py
   grc/branches/grc_reloaded/src/grc/Preferences.py
   grc/branches/grc_reloaded/src/grc_gnuradio/__init__.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py
   grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml
Log:
moved gnuradio python platform into grc_gnuradio top level module

Modified: grc/branches/grc_reloaded/scripts/grc
===================================================================
--- grc/branches/grc_reloaded/scripts/grc       2008-03-16 06:05:02 UTC (rev 
8030)
+++ grc/branches/grc_reloaded/scripts/grc       2008-03-16 07:41:46 UTC (rev 
8031)
@@ -47,10 +47,7 @@
                print '\nExiting!\n'            
                exit(-1)
        #end import of modules  
-       from grc.platforms.gnuradio_python.Platform import Platform
-       platform = Platform()
-       from grc.gui.elements.Platform import Platform
-       platform = Platform(platform)
+       from grc_gnuradio.Platform import Platform
        from grc.ActionHandler import ActionHandler
-       ActionHandler(args, platform)
+       ActionHandler(args, Platform())
 

Modified: grc/branches/grc_reloaded/scripts/usrp_diagnostics
===================================================================
--- grc/branches/grc_reloaded/scripts/usrp_diagnostics  2008-03-16 06:05:02 UTC 
(rev 8030)
+++ grc/branches/grc_reloaded/scripts/usrp_diagnostics  2008-03-16 07:41:46 UTC 
(rev 8031)
@@ -29,7 +29,7 @@
 
 from grc.gui.Dialogs import TextDisplay
 
-from grc.platforms.gnuradio_python.Platform import Platform
+from grc_gnuradio.Platform import Platform
 platform = Platform()
 
 from grc.gui.elements.Platform import Platform

Modified: grc/branches/grc_reloaded/setup.py
===================================================================
--- grc/branches/grc_reloaded/setup.py  2008-03-16 06:05:02 UTC (rev 8030)
+++ grc/branches/grc_reloaded/setup.py  2008-03-16 07:41:46 UTC (rev 8031)
@@ -25,13 +25,11 @@
 
 VERSION = __import__('src/grc/Constants').VERSION
 
-PACKAGES=[
+PACKAGES = [
        'grc',
        'grc.elements',
        'grc.gui',
        'grc.gui.elements',
-       'grc.platforms',
-       'grc.platforms.gnuradio_python',
 
        'grc_gnuradio',
        'grc_gnuradio.blks2',
@@ -39,20 +37,23 @@
        'grc_gnuradio.wxgui',
 ]
 
-DATA=[
+GRC_DATA = [
        'data/*.*',
-       'platforms/gnuradio_python/data/*.*',   
-       'platforms/gnuradio_python/blocks/*.*',
-       'platforms/gnuradio_python/blocks/sources/*.xml',
-       'platforms/gnuradio_python/blocks/sinks/*.xml',
-       'platforms/gnuradio_python/blocks/graphical_sinks/*.xml',
-       'platforms/gnuradio_python/blocks/operators/*.xml',
-       'platforms/gnuradio_python/blocks/conversions/*.xml',
-       'platforms/gnuradio_python/blocks/variables/*.xml',
-       'platforms/gnuradio_python/blocks/misc/*.xml',
-       'platforms/gnuradio_python/blocks/usrp/*.xml',
 ]
 
+GRC_GNURADIO_DATA = [  
+       'data/*.*',     
+       'blocks/*.*',
+       'blocks/sources/*.xml',
+       'blocks/sinks/*.xml',
+       'blocks/graphical_sinks/*.xml',
+       'blocks/operators/*.xml',
+       'blocks/conversions/*.xml',
+       'blocks/variables/*.xml',
+       'blocks/misc/*.xml',
+       'blocks/usrp/*.xml',
+]
+
 setup(
        name='GRC',
        version=VERSION,
@@ -62,6 +63,6 @@
        url='http://gnuradio.org/trac/wiki/GNURadioCompanion',
        packages=PACKAGES,
        package_dir={'': 'src'},
-       package_data={'grc': DATA},
+       package_data={'grc': GRC_DATA, 'grc_gnuradio': GRC_GNURADIO_DATA},
        scripts=['scripts/grc', 'scripts/usrp_diagnostics'],
 )

Modified: grc/branches/grc_reloaded/src/grc/ActionHandler.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/ActionHandler.py  2008-03-16 06:05:02 UTC 
(rev 8030)
+++ grc/branches/grc_reloaded/src/grc/ActionHandler.py  2008-03-16 07:41:46 UTC 
(rev 8031)
@@ -32,6 +32,7 @@
 import Messages
 import ParseXML
 import random
+from grc.gui.elements.Platform import Platform
 
 class ActionHandler:
        """
@@ -44,8 +45,10 @@
                ActionHandler constructor.
                Create the main window, setup the message handler, import the 
preferences, 
                and connect all of the action handlers. Finally, enter the gtk 
main loop and block.
-               @param file_paths a list of flow graph file passed from command 
line            
-               """                             
+               @param file_paths a list of flow graph file passed from command 
line
+               @param platform platform module
+               """
+               platform = Platform(platform)                   
                if PY_GTK_ICON: 
gtk.window_set_default_icon_from_file(PY_GTK_ICON)
                for action in ACTIONS_LIST: action.connect('activate', 
self._handle_actions)
                #setup the main window

Modified: grc/branches/grc_reloaded/src/grc/Preferences.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/Preferences.py    2008-03-16 06:05:02 UTC 
(rev 8030)
+++ grc/branches/grc_reloaded/src/grc/Preferences.py    2008-03-16 07:41:46 UTC 
(rev 8031)
@@ -24,7 +24,7 @@
 import ParseXML
 import Messages
 
-from grc.platforms.gnuradio_python.Platform import Platform
+from grc_gnuradio.Platform import Platform
 platform = Platform()
 
 from grc.gui.elements.Platform import Platform

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/Block.py (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Block.py                         
(rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Block.py 2008-03-16 07:41:46 UTC 
(rev 8031)
@@ -0,0 +1,100 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.Block
+#Flow graph block.
address@hidden Josh Blum
+
+from grc.elements.Block import Block as _Block
+from grc import Utils
+
+class Block(_Block):
+       
+       ##for make source to keep track of indexes
+       _source_count = 0
+       ##for make sink to keep track of indexes
+       _sink_count = 0
+               
+       def __init__(self, flow_graph, n):
+               """
+               Make a new block from nested data.
+               @param flow graph the parent element
+               @param n the nested odict
+               @return block a new block
+               """
+               #grab the data
+               doc = Utils.exists_or_else(n, 'doc', '')        
+               imports = map(lambda i: i.strip(), Utils.listify(n, 'import'))
+               make = n['make']
+               callbacks = Utils.listify(n, 'callback')                        
+               #build the block
+               _Block.__init__(
+                       self,                   
+                       flow_graph=flow_graph, 
+                       n=n,
+               )
+               self._doc = doc
+               self._imports = imports
+               self._make = make
+               self._callbacks = callbacks     
+               
+       def validate(self):
+               _Block.validate(self)
+               for ports, Port in (
+                       (self._sources, self.get_parent().get_parent().Source), 
+                       (self._sinks, self.get_parent().get_parent().Sink),
+               ):
+                       #how many ports?
+                       num_ports = len(ports)
+                       #do nothing for 0 ports
+                       if not num_ports: continue
+                       #get the nports setting
+                       port0 = ports[str(0)]
+                       nports = port0.get_nports()
+                       #do nothing for no nports
+                       if not nports: continue
+                       #do nothing if nports is already num ports
+                       if nports == num_ports: continue
+                       #remove excess ports and connections
+                       if nports < num_ports:
+                               #remove the connections
+                               for key in map(str, range(nports, num_ports)):
+                                       port = ports[key]
+                                       for connection in 
port.get_connections():
+                                               
self.get_parent().remove_element(connection)
+                               #remove the ports
+                               for key in map(str, range(nports, num_ports)): 
ports.pop(key)
+                               continue
+                       #add more ports
+                       if nports > num_ports:
+                               for key in map(str, range(num_ports, nports)):
+                                       n = port0._n
+                                       n['key'] = key
+                                       port = Port(self, n)
+                                       ports[key] = port
+                               continue
+               
+       def get_doc(self): return self._doc
+       
+       def get_imports(self): return self._imports
+       
+       def get_make(self): return self.resolve_dependencies(self._make)
+       
+       def get_callbacks(self):
+               return map(lambda c: self.get_id() + '.' + 
self.resolve_dependencies(c), self._callbacks)
+       

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/Connection.py (from rev 
8030, grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Connection.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Connection.py                    
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Connection.py    2008-03-16 
07:41:46 UTC (rev 8031)
@@ -0,0 +1,42 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.Connection
+#Flow graph connection.
+#A connection exists between 2 ports.
+#One port must be input, one output.
+#The port decided whether it can have the connection.
address@hidden Josh Blum
+
+from grc.elements.Connection import Connection as _Connection
+
+class Connection(_Connection):
+       
+       def validate(self):
+               """
+               Validate the connections.
+               The ports must match in type and vector length.
+               """
+               _Connection.validate(self) #checks type
+               #check vector length
+               source_vlen = self.get_source().get_vlen()
+               sink_vlen = self.get_sink().get_vlen()
+               try: assert(source_vlen == sink_vlen)
+               except AssertionError: self._add_error_message('Source vector 
length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))
+               
+               

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/FlowGraph.py (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/FlowGraph.py                     
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/FlowGraph.py     2008-03-16 
07:41:46 UTC (rev 8031)
@@ -0,0 +1,49 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.FlowGraph
+#Primative flow graph.
address@hidden Josh Blum
+
+from grc.elements.FlowGraph import FlowGraph as _FlowGraph
+from Block import Block
+from Connection import Connection
+
+class FlowGraph(_FlowGraph):
+       
+       def evaluate(self, expr):
+               """
+               Evaluate the expression.
+               @param expr the string expression
+               @throw Exception bad expression
+               @return the evaluated data
+               """
+               n = dict() #namespace
+               #load imports
+               for block in filter(lambda b: b.get_key() == 'import', 
self.get_blocks()):
+                       try: exec block.get_make() in n
+                       except: pass
+               #load variables
+               for block in filter(lambda b: 
b.get_key().startswith('variable'), self.get_blocks()):
+                       try: 
+                               e = eval(block.get_make(), n, n)
+                               n[block.get_id()] = e
+                       except: pass
+               e = eval(expr, n, n)
+               return e
+               

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/Generator.py (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Generator.py                     
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Generator.py     2008-03-16 
07:41:46 UTC (rev 8031)
@@ -0,0 +1,121 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.Generator
+#Create python based flow graphs.
address@hidden Josh Blum
+
+import os
+import subprocess
+import sys
+from Cheetah.Template import Template
+from grc.Constants import FLOW_GRAPH_FILE_EXTENSION
+
+##The default binary to execute python files.
+PYEXEC = 'python'
+#>>> platform dependency! MacOS requires pythonw to run wx apps        #
+if sys.platform == 'darwin': PYEXEC = 'pythonw'
+
+PATH = os.path.dirname(__file__)
+
+NO_GUI_TEMPLATE = PATH + '/data/no_gui.tmpl'
+
+WX_GUI_TEMPLATE = PATH + '/data/wx_gui.tmpl'
+
+class Generator(object):
+       
+       def __init__(self, flow_graph):
+               self._flow_graph = flow_graph
+               
+       def get_popen(self, file_path):
+               """!
+               Generate and execute this python flow graph.
+               @param file_path the file path of the flow graph
+               @return a popen object
+               """
+               exec_file = file_path.replace(FLOW_GRAPH_FILE_EXTENSION, '') + 
'.py'
+               #generate file
+               open(exec_file, 'w').write(str(self))
+               #execute
+               cmds = [PYEXEC, exec_file]
+               if self._flow_graph.get_option('generate_options') == 'no_gui':
+                       cmds = ['xterm', '-e'] + cmds                   
+               p = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE, shell=False, universal_newlines=True)
+               return p
+                               
+       def __str__(self):
+               """!
+               Convert the flow graph to python code.
+               @return a string of python code
+               """
+               all_blocks = self._flow_graph.get_blocks()
+               #get imports
+               imports = list()
+               imports.append('from gnuradio import gr')
+               for block in all_blocks: imports.extend(block.get_imports())
+               for block in filter(lambda b: b.get_key() == 'import', 
all_blocks):
+                       imports.append(block.get_make())
+               #separate variables
+               variables = filter(lambda b: 
b.get_key().startswith('variable'), all_blocks)
+               variables = sorted(variables, lambda x, y: cmp(x.get_id(), 
y.get_id())) 
+               #separate blocks
+               blocks = filter(lambda b: b not in variables and b.get_key() != 
'import', all_blocks)
+               blocks = sorted(blocks, lambda x, y: cmp(x.get_id(), 
y.get_id())) 
+               if self._flow_graph.get_option('generate_options') == 'no_gui': 
                
+                       imports = sorted(set(imports)) #unique and sorted
+                       #load the namespace
+                       namespace = {
+                               'imports':      imports,
+                               'flow_graph': self._flow_graph,
+                               'variables': variables,
+                               'blocks': blocks,
+                               'connections': 
self._flow_graph.get_connections(),
+                       }
+                       #build the template
+                       t = Template(open(NO_GUI_TEMPLATE, 'r').read(), 
namespace)
+               elif self._flow_graph.get_option('generate_options') == 
'wx_gui':               
+                       imports.append('from grc_gnuradio.wxgui import 
Controls')
+                       imports.append('import wx')
+                       imports = sorted(set(imports)) #unique and sorted
+                       #separate variables with wx controls
+                       sliders = filter(lambda v: v.get_key() == 
'variable_slider', variables)
+                       buttons = filter(lambda v: v.get_key() == 
'variable_button', variables)
+                       choosers = filter(lambda v: v.get_key() == 
'variable_chooser', variables)
+                       #graphical sinks
+                       graphical_sinks = filter(lambda b: 
b.get_key().startswith('wxgui'), blocks)
+                       #all callbacks
+                       callbacks = list()
+                       for block in blocks: 
callbacks.extend(block.get_callbacks())
+                       #load the namespace
+                       namespace = {
+                               'imports':      imports,
+                               'flow_graph': self._flow_graph,
+                               'variables': variables,
+                               'sliders': sliders,
+                               'buttons': buttons,
+                               'choosers': choosers,
+                               'blocks': blocks,
+                               'graphical_sinks': graphical_sinks,
+                               'connections': 
self._flow_graph.get_connections(),
+                               'callbacks': callbacks,
+                       }
+                       #build the template
+                       t = Template(open(WX_GUI_TEMPLATE, 'r').read(), 
namespace)
+               else: print self._flow_graph.get_option('generate_options')
+               return str(t)
+                       

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/Param.py (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Param.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Param.py                         
(rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Param.py 2008-03-16 07:41:46 UTC 
(rev 8031)
@@ -0,0 +1,257 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.Param
+#Flow graph block parameters.
address@hidden Josh Blum
+
+from grc.elements.Param import Param as _Param
+import os
+
+class Param(_Param):
+       
+       ##possible param types
+       TYPES = _Param.TYPES + [
+               'complex', 'real', 'int', 
+               'complex_vector', 'real_vector', 'int_vector',
+               'hex', 'string',
+               'file_open', 'file_save',
+               'id',
+               'source_pad_key', 'sink_pad_key',
+               'grid_pos', 'import',
+       ]
+       
+       def evaluate(self):
+               """
+               Evaluate the value.
+               @return evaluated type
+               """             
+               self._lisitify_flag = False
+               self._stringify_flag = False
+               
+               def eval_string(v):
+                       try: 
+                               e = self.get_parent().get_parent().evaluate(v)
+                               assert(isinstance(e, str))
+                               return e
+                       except: 
+                               self._stringify_flag = True
+                               return v
+               t = self.get_type()
+               v = self.get_value()
+               if self.is_enum():
+                       return self.get_value()
+               elif t in ('raw', 'complex', 'real', 'int', 'complex_vector', 
'real_vector', 'int_vector', 'hex'):
+                       #raise exception if python cannot evaluate this value
+                       try: e = self.get_parent().get_parent().evaluate(v)
+                       except:
+                               self._add_error_message('Value "%s" cannot be 
evaluated.'%v)
+                               raise Exception 
+                       #raise an exception if the data is invalid
+                       if t == 'raw': 
+                               return e
+                       elif t == 'complex':
+                               try: assert(isinstance(e, (complex, float, int, 
long)))
+                               except AssertionError:
+                                       self._add_error_message('Expression 
"%s" is invalid for type complex.'%str(e))
+                                       raise Exception 
+                               return e
+                       elif t == 'real':
+                               try: assert(isinstance(e, (float, int, long)))
+                               except AssertionError:
+                                       self._add_error_message('Expression 
"%s" is invalid for type real.'%str(e))
+                                       raise Exception 
+                               return e
+                       elif t == 'int':
+                               try: assert(isinstance(e, (int, long)))
+                               except AssertionError:
+                                       self._add_error_message('Expression 
"%s" is invalid for type integer.'%str(e))
+                                       raise Exception 
+                               return e
+                       elif t == 'complex_vector':
+                               if not isinstance(e, (tuple, list, set)): 
+                                       self._lisitify_flag = True
+                                       e = [e]
+                               try:
+                                       for ei in e:
+                                               assert(isinstance(ei, (complex, 
float, int, long)))
+                               except AssertionError:
+                                       self._add_error_message('Expression 
"%s" is invalid for type complex vector.'%str(e))
+                                       raise Exception 
+                               return e
+                       elif t == 'real_vector':
+                               if not isinstance(e, (tuple, list, set)): 
+                                       self._lisitify_flag = True
+                                       e = [e]
+                               try:
+                                       for ei in e:
+                                               assert(isinstance(ei, (float, 
int, long)))
+                               except AssertionError:
+                                       self._add_error_message('Expression 
"%s" is invalid for type real vector.'%str(e))
+                                       raise Exception 
+                               return e
+                       elif t == 'int_vector':
+                               if not isinstance(e, (tuple, list, set)): 
+                                       self._lisitify_flag = True
+                                       e = [e]
+                               try:
+                                       for ei in e:
+                                               assert(isinstance(ei, (int, 
long)))
+                               except AssertionError:
+                                       self._add_error_message('Expression 
"%s" is invalid for type integer vector.'%str(e))
+                                       raise Exception 
+                               return e
+                       elif t == 'hex':
+                               return hex(e)
+                       else: raise TypeError, 'Type "%s" not handled'%t
+               elif t == 'string':
+                       e = eval_string(v)
+                       return str(e)
+               elif t == 'file_open': 
+                       e = eval_string(v)
+                       e = str(e)                
+                       assert(os.path.isfile(e))
+                       return e
+               elif t == 'file_save':
+                       e = eval_string(v)
+                       e = str(e)    
+                       assert(os.path.exists(os.path.dirname(e)))
+                       assert(not os.path.isdir(e))
+                       assert(os.path.basename(e))     
+                       return e
+               elif t == 'id':
+                       #can python use this as a variable?
+                       try:
+                               assert(len(v) > 0)
+                               assert(v[0].isalpha())
+                               for c in v: assert(c.isalnum() or c in ('_',))
+                       except AssertionError: 
+                               self._add_error_message('ID "%s" must be 
alpha-numeric or underscored, and begin with a letter.'%v)
+                               raise Exception                 
+                       params = self.get_all_params('id')
+                       keys = [param.get_value() for param in params]
+                       try: assert(len(keys) == len(set(keys)))
+                       except:
+                               self._add_error_message('ID "%s" is not 
unique.'%v)
+                               raise Exception 
+                       return v
+               elif t == 'source_pad_key':
+                       #should be an integer
+                       try: e = int(v)
+                       except:
+                               self._add_error_message('Source Pad Key "%s" is 
not an integer.'%v)
+                               raise Exception                         
+                       params = filter(lambda p: p.is_valid(), 
self.get_all_params('source_pad_key'))
+                       keys = [int(param.get_value()) for param in params]
+                       try: assert(len(keys) == len(set(keys)))
+                       except AssertionError:
+                               self._add_error_message('Source Pad Key "%s" is 
not unique.'%v)
+                               raise Exception
+                       return e
+               elif t == 'sink_pad_key':
+                       #should be an integer
+                       try: e = int(v)
+                       except:
+                               self._add_error_message('Sink Pad Key "%s" is 
not an integer.'%v)
+                               raise Exception 
+                       params = filter(lambda p: p.is_valid(), 
self.get_all_params('sink_pad_key'))
+                       keys = [int(param.get_value()) for param in params]
+                       try: assert(len(keys) == len(set(keys)))
+                       except AssertionError:
+                               self._add_error_message('Sink Pad Key "%s" is 
not unique.'%v)
+                               raise Exception
+                       return e
+               elif t == 'grid_pos':
+                       e = self.get_parent().get_parent().evaluate(v)
+                       try: 
+                               assert(isinstance(e, (list, tuple)) and len(e) 
== 4)
+                               for ei in e: assert(isinstance(ei, int))
+                       except AssertionError:
+                               self._add_error_message('A grid position must 
be a list of 4 integers.')
+                               raise Exception
+                       row, col, row_span, col_span = e
+                       #check row, col
+                       try: assert(row >= 0 and col >= 0)
+                       except AssertionError:
+                               self._add_error_message('Row and column must be 
non-negative.')
+                               raise Exception
+                       #check row span, col span
+                       try: assert(row_span > 0 and col_span > 0)
+                       except AssertionError:
+                               self._add_error_message('Row and column span 
must be greater than zero.')
+                               raise Exception
+                       #calculate hostage cells
+                       self._hostage_cells = list()
+                       for r in range(row_span):
+                               for c in range(col_span):
+                                       self._hostage_cells.append((row+r, 
col+c))
+                       #avoid collisions                               
+                       params = filter(lambda p: p is not self, 
self.get_all_params('grid_pos'))
+                       for param in params:
+                               for cell in param._hostage_cells:
+                                       if cell in self._hostage_cells:
+                                               
self._add_error_message('Another graphical element is using cell 
"%s".'%str(cell))
+                                               raise Exception
+                       return e
+               elif t == 'import':
+                       n = dict() #new namespace
+                       try: exec v in n
+                       except ImportError: 
+                               self._add_error_message('Import "%s" failed.'%v)
+                               raise Exception
+                       except Exception:
+                               self._add_error_message('Bad import syntax: 
"%s".'%v)
+                               raise Exception
+                       return filter(lambda k: str(k) != '__builtins__', 
n.keys())
+               else: raise TypeError, 'Type "%s" not handled'%t
+               
+       def to_code(self):
+               """!
+               Convert the value to code.
+               @return a string representing the code
+               """                                     
+               v = self.get_value()
+               t = self.get_type()
+               if t in ('string', 'file_open', 'file_save'): 
+                       if self._stringify_flag:
+                               return '"%s"'%v.replace('"', '\"')
+                       else:
+                               return v
+               elif t in ('complex_vector', 'real_vector', 'int_vector'): 
+                       if self._lisitify_flag:
+                               return '(%s, )'%v
+                       else:
+                               return '(%s)'%v
+               else:
+                       return v                
+               
+       def get_all_params(self, type):
+               """!
+               Get all the params from the flowgraph that have the given type.
+               @param type the specified type
+               @return a list of params
+               """
+               all_params = list()
+               #get all blocks
+               blocks = self.get_parent().get_parent().get_blocks()
+               for block in blocks:
+                       #filter params of other types
+                       params = filter(lambda p: p.get_type() == type, 
block.get_params())
+                       all_params.extend(params)
+               return all_params
+               

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/Platform.py (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Platform.py                      
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Platform.py      2008-03-16 
07:41:46 UTC (rev 8031)
@@ -0,0 +1,67 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.Platform
+#Gnuradio python specific platform.
address@hidden Josh Blum
+
+import os
+from grc.elements.Platform import Platform as _Platform
+from FlowGraph import FlowGraph as _FlowGraph
+from Connection import Connection as _Connection
+from Block import Block as _Block
+from Port import Source,Sink
+from Param import Param as _Param
+from Generator import Generator
+
+PATH = os.path.dirname(__file__)
+
+BLOCK_TREE = PATH + '/data/block_tree.xml'
+
+DEFAULT_FLOW_GRAPH = PATH + '/data/default_flow_graph.grc.xml'
+
+class Platform(_Platform):
+       
+       def __init__(self):
+               """!
+               Make a platform from the arguments.
+               @param name the platform name
+               @param key the unique platform key
+               @param path the file path to this platform
+               @return a platform object
+               """
+               _Platform.__init__(
+                       self,
+                       name='GNURadio Python', 
+                       key='gnuradio_python',  
+                       path=PATH,
+                       block_tree=BLOCK_TREE,
+                       default_flow_graph=DEFAULT_FLOW_GRAPH,
+                       generator=Generator,
+               )
+               
+       ##############################################
+       # Constructors
+       ##############################################
+       FlowGraph = _FlowGraph
+       Connection = _Connection
+       Block = _Block
+       Source = Source
+       Sink = Sink
+       Param = _Param
+       

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/Port.py (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Port.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Port.py                          
(rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Port.py  2008-03-16 07:41:46 UTC 
(rev 8031)
@@ -0,0 +1,139 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.Port
+#Flow graph block port (source or sink).
address@hidden Josh Blum
+
+from grc.elements.Port import Port as _Port
+from grc import Utils
+from grc.Constants import MAX_NUM_PORTS
+
+class Port(_Port):
+
+       ##possible port types
+       TYPES = ['complex', 'float', 'int', 'short', 'byte']
+
+       def __init__(self, block, n):   
+               """
+               Make a new port from nested data.
+               @param block the parent element
+               @param n the nested odict
+               @return a new port
+               """
+               vlen = Utils.exists_or_else(n, 'vlen', '1')
+               nports = Utils.exists_or_else(n, 'nports', '')
+               optional = Utils.exists_or_else(n, 'optional', '')
+               #build the port
+               _Port.__init__(
+                       self,
+                       block=block, 
+                       n=n,
+               )
+               self._nports = nports
+               self._vlen = vlen
+               self._optional = bool(optional)
+               
+       def test(self):
+               _Port.test(self)
+               #if self.get_nports():
+               #       try: assert(int(self.get_key()) == 0)
+               #       except (AssertionError,ValueError): 
self._exit_with_error('Port key must be "0" when nports is specified.')
+               #       try:
+               #               if self.is_sink(): 
assert(len(self.get_parent().get_sinks()) == 1)
+               #               elif self.is_source(): 
assert(len(self.get_parent().get_sources()) == 1)
+               #       except AssertionError: self._exit_with_error('Other 
ports not allowed when nports is specified.')
+       
+       def get_vlen(self): 
+               """
+               Get the vector length.
+               If the evaluation of vlen cannot be cast to an integer, return 
1.
+               @return the vector length or 1
+               """
+               vlen = self.get_parent().resolve_dependencies(self._vlen)
+               try: return int(self.get_parent().get_parent().evaluate(vlen))
+               except: return 1                 
+       
+       def get_nports(self): 
+               """
+               Get the number of ports.
+               If already blank, return a blank
+               If the evaluation of nports cannot be cast to an integer, 
return 1.
+               @return the number of ports or 1
+               """
+               nports = self.get_parent().resolve_dependencies(self._nports)
+               #return blank if nports is blank
+               if not nports: return ''
+               try: 
+                       nports = 
int(self.get_parent().get_parent().evaluate(nports))
+                       assert(0 < nports <= MAX_NUM_PORTS)
+                       return nports
+               except: return 1        
+       
+       def get_optional(self): return bool(self._optional)
+       
+       def get_color(self): 
+               """
+               Get the color that represents this port's type.
+               Codes differ for ports where the vec length is 1 or greater 
than 1.
+               @return a hex color code.
+               """
+               try:
+                       if self.get_vlen() == 1:
+                               return {#vlen is 1
+                                       'complex': '#3399FF',
+                                       'float': '#FF8C69',
+                                       'int': '#00FF99', 
+                                       'short': '#FFFF66', 
+                                       'byte': '#FF66FF',
+                               }[self.get_type()]      
+                       return {#vlen is non 1
+                               'complex': '#3399AA',
+                               'float': '#CC8C69',
+                               'int': '#00CC99', 
+                               'short': '#CCCC33', 
+                               'byte': '#CC66CC',
+                       }[self.get_type()]
+               except: return _Port.get_color(self)
+               
+       def is_empty(self):
+               """!
+               Is this port empty?
+               An empty port has no connections.
+               Not empty of optional is set.
+               @return true if empty
+               """
+               return not self.get_optional() and not self.get_connections()
+       
+class Source(Port):
+       
+       def __init__(self, block, n):
+               self._n = n #save n
+               #key is port index
+               n['key'] = str(block._source_count)
+               block._source_count = block._source_count + 1
+               Port.__init__(self, block, n)
+       
+class Sink(Port):
+       
+       def __init__(self, block, n):
+               self._n = n #save n
+               #key is port index
+               n['key'] = str(block._sink_count)
+               block._sink_count = block._sink_count + 1
+               Port.__init__(self, block, n)

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/__init__.py      2008-03-16 
06:05:02 UTC (rev 8030)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/__init__.py      2008-03-16 
07:41:46 UTC (rev 8031)
@@ -17,5 +17,5 @@
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 address@hidden grc_gnuradio 
-#Supplemental package for gnuradio.
+#gnuradio overloaded elements and supplemental python modules
 address@hidden Josh Blum

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py        
2008-03-16 06:05:02 UTC (rev 8030)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py        
2008-03-16 07:41:46 UTC (rev 8031)
@@ -0,0 +1,22 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc_gnuradio.blks2
+#Package for external gnuradio blocks.
address@hidden Josh Blum
+

Added: grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py                  
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py  2008-03-16 
07:41:46 UTC (rev 8031)
@@ -0,0 +1,263 @@
+#!/usr/bin/env python
+#
+# Copyright 2003,2004,2006,2007 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from gnuradio import gr, packet_utils
+import gnuradio.gr.gr_threading as _threading
+
+##payload length in bytes
+DEFAULT_PAYLOAD_LEN = 512
+
+##how many messages in a queue
+DEFAULT_MSGQ_LIMIT = 2
+
+##threshold for unmaking packets
+DEFAULT_THRESHOLD = 12
+
+#######################################################################################
+##     Packet Modulation
+#######################################################################################
+
+class packet_mod_thread(_threading.Thread):
+       """
+       Sample the input message queue and call send.           
+       """
+       
+       def __init__(self, msgq, payload_length, send):
+               """!
+               packet_mod_thread contructor.
+               @param msgq the message queue to sample
+               @param payload_length number of bytes in a data-stream slice
+               @param send a function that takes a payload
+               """             
+               self._msgq = msgq
+               self._payload_length = payload_length
+               self._send = send
+               _threading.Thread.__init__(self)
+               self.setDaemon(1)
+               self.keep_running = True
+               self.start()
+               
+       def run(self):
+               """
+               Run this thread by sampling the message queue in and cutting 
out chunks of size payload.
+               """
+               sample = '' #residual sample
+               while self.keep_running:
+                       msg = self._msgq.delete_head() #blocking read of 
message queue
+                       sample = sample + msg.to_string() #get the body of the 
msg as a string  
+                       while len(sample) >= self._payload_length:              
+                               payload = sample[0:self._payload_length]
+                               sample = sample[self._payload_length:]          
        
+                               self._send(payload)     
+
+class packet_mod(gr.hier_block2):
+       """
+       Hierarchical block for wrapping packet-based modulators.
+       """
+       
+       def __init__(self, item_size_in, item_size_out, modulator, 
payload_length=None):
+               """!
+               packet_mod constructor.
+               @param item_size_in the size of the input data stream in bytes
+               @param item_size_out the size of the output data stream in bytes
+               @param modulator the packet-based modulator
+               @param payload_length number of bytes in a data-stream slice
+               """
+               #setup
+               self._item_size_in = item_size_in
+               self._item_size_out = item_size_out
+               if payload_length is None: #get packet length
+                       payload_length = DEFAULT_PAYLOAD_LEN
+               if payload_length%self._item_size_in != 0:      #verify that 
packet length is a multiple of the stream size
+                       raise ValueError, 'The packet length: "%d" is not a 
mutiple of the stream size: "%d".'%(payload_length, self._item_size_in)
+               self._payload_length = payload_length
+               self._modulator = modulator             
+               #create blocks
+               self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
+               msg_sink        = gr.message_sink(self._item_size_in, 
self._msgq_in, False) #False -> blocking          
+               #initialize hier2
+               gr.hier_block2.__init__(
+                       self, 
+                       "packet mod",
+                       gr.io_signature(1, 1, self._item_size_in), # Input 
signature
+                       gr.io_signature(1, 1, self._item_size_out) # Output 
signature
+               )
+               #connect
+               self.connect(self, msg_sink)
+               self.connect(self._modulator, self)
+               #start thread
+               packet_mod_thread(self._msgq_in, self._payload_length, 
self._modulator.send_pkt)                
+
+class mod_pkts(gr.hier_block2):
+       """
+       Hierarchical block for sending packet based data.               
+       """
+       
+       def __init__(self, samples_per_symbol, bits_per_symbol, 
access_code=None, pad_for_usrp=True):
+               """!
+               mod_pkts constructor.
+               @param samples_per_symbol number of samples per symbol
+               @param bits_per_symbol number of bits per symbol
+               @param access_code AKA sync vector
+               @param pad_for_usrp If true, packets are padded such that they 
end up a multiple of 128 samples
+               """
+               #setup parameters
+               self._samples_per_symbol = samples_per_symbol
+               self._bits_per_symbol = bits_per_symbol
+               self._pad_for_usrp = pad_for_usrp
+               if access_code is None: #get access code
+                       access_code = packet_utils.default_access_code
+               if not packet_utils.is_1_0_string(access_code):
+                       raise ValueError, "Invalid access_code %r. Must be 
string of 1's and 0's" % (access_code,)
+               self._access_code = access_code         
+               self._pad_for_usrp = pad_for_usrp               
+               #create blocks
+               msg_source = gr.message_source(gr.sizeof_char, 
DEFAULT_MSGQ_LIMIT)
+               self._msgq_out = msg_source.msgq()              
+               #initialize hier2
+               gr.hier_block2.__init__(
+                       self, 
+                       "mod pkts",
+                       gr.io_signature(0, 0, 0), # Input signature
+                       gr.io_signature(1, 1, gr.sizeof_char) # Output signature
+               )
+               #connect
+               self.connect(msg_source, self)
+               
+       def send_pkt(self, payload='', eof=False):
+               """!
+               Wrap the payload in a packet and push onto the message queue.
+               @param payload string, data to send
+               @param eof boolean, end of file
+               """
+               if eof: 
+                       msg = gr.message(1) # tell self._pkt_input we're not 
sending any more packets
+               else:                   
+                       packet = packet_utils.make_packet(
+                               payload,
+                               self._samples_per_symbol,
+                               self._bits_per_symbol,
+                               self._access_code,
+                               self._pad_for_usrp
+                       )
+                       msg = gr.message_from_string(packet)
+               self._msgq_out.insert_tail(msg)
+       
+#######################################################################################
+##     Packet Demodulation
+#######################################################################################
+
+class packet_demod(gr.hier_block2):
+       """
+       Hierarchical block for wrapping packet-based demodulators.
+       """
+       
+       def __init__(self, item_size_in, item_size_out, demodulator):
+               """!
+               packet_demod constructor.
+               @param item_size_in the size of the input data stream in bytes
+               @param item_size_out the size of the output data stream in bytes
+               @param demodulator the packet-based demodulator
+               """
+               #setup
+               self._item_size_in = item_size_in
+               self._item_size_out = item_size_out
+               self._demodulator = demodulator 
+               #blocks
+               msg_source = gr.message_source(self._item_size_out, 
DEFAULT_MSGQ_LIMIT)
+               self._msgq_out = msg_source.msgq()              
+               #initialize hier2
+               gr.hier_block2.__init__(
+                       self, 
+                       "packet demod",
+                       gr.io_signature(1, 1, self._item_size_in), # Input 
signature
+                       gr.io_signature(1, 1, self._item_size_out) # Output 
signature
+               )
+               #connect
+               self.connect(self, gr.kludge_copy(self._item_size_in), 
self._demodulator)
+               self.connect(msg_source, self)
+               #set callback
+               self._demodulator._watcher.callback = self._recv_packet
+
+       def _recv_packet(self, ok, payload):
+               """!
+               Extract the payload from the packet and push onto message queue.
+               @param ok boolean ok
+               @param payload data received
+               """
+               msg = gr.message_from_string(payload, 0, self._item_size_out, 
len(payload)/self._item_size_out)
+               if ok: self._msgq_out.insert_tail(msg)
+       
+class demod_pkts(gr.hier_block2):
+       """
+       Hierarchical block for demodulating and deframing packets.
+       """
+
+       def __init__(self, access_code=None, callback=None, threshold=-1):
+               """!
+               demod_pkts contructor.   
+               @param access_code AKA sync vector
+               @param callback function of two args: ok, payload
+               @param threshold detect access_code with up to threshold bits 
wrong (-1 -> use default)
+               """
+               #access code
+               if access_code is None: #get access code
+                       access_code = packet_utils.default_access_code
+               if not packet_utils.is_1_0_string(access_code):
+                       raise ValueError, "Invalid access_code %r. Must be 
string of 1's and 0's" % (access_code,)
+               self._access_code = access_code         
+      #threshold
+               if threshold == -1: threshold = DEFAULT_THRESHOLD 
+               self._threshold = threshold  
+               self._callback = callback
+               #initialize hier2
+               gr.hier_block2.__init__(
+                       self,
+                       "demod pkts",
+                       gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+                       gr.io_signature(0, 0, 0), # Output signature
+               ) 
+               #blocks
+               self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT)          # 
holds packets from the PHY
+               correlator = gr.correlate_access_code_bb(self._access_code, 
self._threshold)
+               framer_sink = gr.framer_sink_1(self._msgq_in)           
+               #connect
+               self.connect(self, correlator, framer_sink)
+               #start thread
+               self._watcher = _queue_watcher_thread(self._msgq_in, 
self._callback)
+                       
+class _queue_watcher_thread(_threading.Thread):
+    def __init__(self, rcvd_pktq, callback):
+        _threading.Thread.__init__(self)
+        self.setDaemon(1)
+        self.rcvd_pktq = rcvd_pktq
+        self.callback = callback
+        self.keep_running = True
+        self.start()
+
+    def run(self):
+        while self.keep_running:
+            msg = self.rcvd_pktq.delete_head()
+            ok, payload = packet_utils.unmake_packet(msg.to_string(), 
int(msg.arg1()))
+            if self.callback:
+                self.callback(ok, payload)
+

Added: grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py                
                (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py        
2008-03-16 07:41:46 UTC (rev 8031)
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+#
+# Copyright 2003,2004,2006,2007 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from gnuradio import gr
+
+class selector(gr.hier_block2):
+       """A hier2 block with N inputs and M outputs, where data is only 
forwarded through input n to output m."""
+       def __init__(self, item_size, num_inputs, num_outputs, input_index, 
output_index):      
+               """!
+               SelectorHelper constructor.
+               @param item_size the size of the gr data stream in bytes
+               @param num_inputs the number of inputs (integer)
+               @param num_outputs the number of outputs (integer)
+               @param input_index the index for the source data
+               @param output_index the index for the destination data
+               """     
+               gr.hier_block2.__init__(
+                       self, 'selector', 
+                       gr.io_signature(num_inputs, num_inputs, item_size), 
+                       gr.io_signature(num_outputs, num_outputs, item_size),
+               )
+               #terminator blocks for unused inputs and outputs        
+               self.input_terminators = [gr.null_sink(item_size) for i in 
range(num_inputs)]
+               self.output_terminators = [gr.head(item_size, 0) for i in 
range(num_outputs)]           
+               self.copy = None
+               #connections            
+               for i in range(num_inputs): self.connect((self, i), 
self.input_terminators[i])
+               for i in range(num_outputs): 
self.connect(gr.null_source(item_size), self.output_terminators[i], (self, i))  
   
+               self.item_size = item_size              
+               self.input_index = input_index
+               self.output_index = output_index        
+               self.num_inputs = num_inputs
+               self.num_outputs = num_outputs
+               self._connect_current()
+               
+       def _indexes_valid(self):
+               """!
+               Are the input and output indexes within range of the number of 
inputs and outputs?
+               @return true if input index and output index are in range
+               """
+               return self.input_index in range(self.num_inputs) and 
self.output_index in range(self.num_outputs)
+               
+       def _connect_current(self):
+               """If the input and output indexes are valid: 
+               disconnect the blocks at the input and output index from their 
terminators, 
+               and connect them to one another. Then connect the terminators 
to one another."""
+               if self._indexes_valid():
+                       self.disconnect((self, self.input_index), 
self.input_terminators[self.input_index])                             
+                       
self.disconnect(self.output_terminators[self.output_index], (self, 
self.output_index))
+                       self.copy = gr.skiphead(self.item_size, 0)
+                       self.connect((self, self.input_index), self.copy)
+                       self.connect(self.copy, (self, self.output_index))      
        
+                       
self.connect(self.output_terminators[self.output_index], 
self.input_terminators[self.input_index])      
+               
+       def _disconnect_current(self):
+               """If the input and output indexes are valid: 
+               disconnect the blocks at the input and output index from one 
another, 
+               and the terminators at the input and output index from one 
another.
+               Reconnect the blocks to the terminators."""
+               if self._indexes_valid():
+                       self.disconnect((self, self.input_index), self.copy)
+                       self.disconnect(self.copy, (self, self.output_index))
+                       
self.disconnect(self.output_terminators[self.output_index], 
self.input_terminators[self.input_index])
+                       del self.copy                   
+                       self.copy = None                        
+                       self.connect((self, self.input_index), 
self.input_terminators[self.input_index])
+                       
self.connect(self.output_terminators[self.output_index], (self, 
self.output_index))
+               
+       def set_input_index(self, input_index):
+               """!
+               Change the block to the new input index if the index changed.
+               @param input_index the new input index
+               """
+               if self.input_index != input_index:
+                       self.lock()
+                       self._disconnect_current()
+                       self.input_index = input_index
+                       self._connect_current()
+                       self.unlock()           
+               
+       def set_output_index(self, output_index):
+               """!
+               Change the block to the new output index if the index changed.
+               @param output_index the new output index
+               """             
+               if self.output_index != output_index:   
+                       self.lock()
+                       self._disconnect_current()
+                       self.output_index = output_index
+                       self._connect_current()                 
+                       self.unlock()   
+

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/blocks (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks)

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/data (from rev 8030, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data)

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml 
    2008-03-16 06:05:02 UTC (rev 8030)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml      
2008-03-16 07:41:46 UTC (rev 8031)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!DOCTYPE block_tree SYSTEM "../../../data/block_tree.dtd">
+<!DOCTYPE block_tree SYSTEM "../../grc/data/block_tree.dtd">
 <!-- 
 ###################################################
 ##Block Tree for platform gnuradio python.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]