commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8140 - in grc/branches/grc_reloaded/src: grc grc_gnur


From: jblum
Subject: [Commit-gnuradio] r8140 - in grc/branches/grc_reloaded/src: grc grc_gnuradio grc_gnuradio/blocks/modulators grc_gnuradio/data
Date: Sat, 29 Mar 2008 16:42:01 -0600 (MDT)

Author: jblum
Date: 2008-03-29 16:42:01 -0600 (Sat, 29 Mar 2008)
New Revision: 8140

Added:
   
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_demod.xml
   
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_mod.xml
   grc/branches/grc_reloaded/src/grc_gnuradio/extract_docs.py
Removed:
   
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qam_demod.xml
   
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qam_mod.xml
Modified:
   grc/branches/grc_reloaded/src/grc/ParseXML.py
   grc/branches/grc_reloaded/src/grc_gnuradio/Block.py
   grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml
Log:
blks2 docs supported

Modified: grc/branches/grc_reloaded/src/grc/ParseXML.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/ParseXML.py       2008-03-29 20:06:12 UTC 
(rev 8139)
+++ grc/branches/grc_reloaded/src/grc/ParseXML.py       2008-03-29 22:42:01 UTC 
(rev 8140)
@@ -50,9 +50,6 @@
        
        def fatal(self, msg):
                raise ValidationError('Fatal', msg, self.location())
-               
-def getChildrenByTagName(doc, tag_name):
-       return filter(lambda c: str(c.localName) == str(tag_name), 
doc.childNodes)
        
 def validate_dtd(xml_file, dtd_file=None):
        """!

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/Block.py 2008-03-29 20:06:12 UTC 
(rev 8139)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/Block.py 2008-03-29 22:42:01 UTC 
(rev 8140)
@@ -22,61 +22,8 @@
 
 from grc.elements.Block import Block as _Block
 from grc import Utils
+import extract_docs
 
-DOCS_DIR = '/usr/local/share/doc/grc_gnuradio_docs/'
-from grc import ParseXML
-import os
-
-def extract_txt(doc):
-       """!
-       Recursivly pull the text out of an xml document.
-       @param doc the xml document
-       @return a string
-       """
-       if len(doc.childNodes) == 0: return str(doc.nodeValue)
-       return ''.join(map(extract_txt, doc.childNodes))
-       
-def is_match(key, file):
-       """!
-       Is the block key a match for the given file name?
-       @param key block key
-       @param file the xml file name
-       @return true if matches
-       """
-       file = file.replace('.xml', '') #remove file ext        
-       file = file.replace('class', '') #remove the class
-       file = file.replace('__', '_') #doxygen xml files have 2 underscores
-       if len(file) != len(key): return False
-       for i,k in enumerate(key):
-               if file[i] != k and k != 'x': return False      
-       return True
-
-def extract_docs(key):
-       """!
-       Extract the documentation from the doxygen generated xml files.
-       If multiple files match, combine the docs.
-       @param key the block key
-       @return a string with documentation
-       """             
-       #get potential xml file matches for the key
-       if os.path.exists(DOCS_DIR) and os.path.isdir(DOCS_DIR):
-               matches = filter(lambda f: is_match(key, f), 
os.listdir(DOCS_DIR))
-       else: matches = list()
-       #combine all matches
-       doc_strs = list()
-       for match in matches:
-               doc = ParseXML.from_file(DOCS_DIR + '/' + match)
-               doc = ParseXML.getChildrenByTagName(doc, 'doxygen')[0]
-               doc = ParseXML.getChildrenByTagName(doc, 'compounddef')[0]
-               #extract descriptions
-               comp_name = extract_txt(ParseXML.getChildrenByTagName(doc, 
'compoundname')[0]).strip('\n')
-               comp_name = '   ---   ' + comp_name + '   ---   '
-               brief_desc = extract_txt(ParseXML.getChildrenByTagName(doc, 
'briefdescription')[0]).strip('\n')
-               detailed_desc = extract_txt(ParseXML.getChildrenByTagName(doc, 
'detaileddescription')[0]).strip('\n')
-               #combine
-               doc_strs.append('\n'.join([comp_name, brief_desc, 
detailed_desc]).strip('\n'))  
-       return '\n\n'.join(doc_strs)
-       
 class Block(_Block):
        
        ##for make source to keep track of indexes
@@ -146,7 +93,7 @@
        def get_doc(self): 
                doc = self._doc.strip('\n').replace('\\\n', '')
                #merge custom doc with doxygen docs 
-               return '\n'.join([doc, 
extract_docs(self.get_key())]).strip('\n')
+               return '\n'.join([doc, 
extract_docs.extract(self.get_key())]).strip('\n')
        
        def get_imports(self): return self._imports
        

Deleted: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qam_demod.xml

Deleted: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qam_mod.xml

Copied: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_demod.xml
 (from rev 8124, 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qam_demod.xml)
===================================================================
--- 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_demod.xml
                           (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_demod.xml
   2008-03-29 22:42:01 UTC (rev 8140)
@@ -0,0 +1,100 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##QAM Demod - 8, 16, 64, 256
+###################################################
+ -->
+<block>
+       <name>QAM Demod</name>
+       <key>blks2_qamx_demod</key>
+       <import>from gnuradio import blks2</import>
+       <make>blks2.$(type)_demod(
+       samples_per_symbol=$samples_per_symbol,
+       excess_bw=$excess_bw,
+       costas_alpha=$costas_alpha,
+       gain_mu=$gain_mu,
+       mu=$mu,
+       omega_relative_limit=$omega_relative_limit,
+       gray_code=$gray_code,
+)</make>
+       <param>
+               <name>Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>QAM8</name>
+                       <key>qam8</key>
+               </option>
+               <option>
+                       <name>QAM16</name>
+                       <key>qam16</key>
+               </option>
+               <option>
+                       <name>QAM64</name>
+                       <key>qam64</key>
+               </option>
+               <option>
+                       <name>QAM256</name>
+                       <key>qam256</key>
+               </option>
+       </param>
+       <param>
+               <name>Samples per Symbol</name>
+               <key>samples_per_symbol</key>
+               <value>2</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Excess BW</name>
+               <key>excess_bw</key>
+               <value>0.35</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Costas Alpha</name>
+               <key>costas_alpha</key>
+               <value>0.175</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Gain Mu</name>
+               <key>gain_mu</key>
+               <value>0.03</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Mu</name>
+               <key>mu</key>
+               <value>0.05</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Omega Relative Limit</name>
+               <key>omega_relative_limit</key>
+               <value>0.005</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Gray Code</name>
+               <key>gray_code</key>
+               <value>True</value>
+               <type>enum</type>
+               <option>
+                       <name>Yes</name>
+                       <key>True</key>
+               </option>
+               <option>
+                       <name>No</name>
+                       <key>False</key>
+               </option>
+       </param>
+       <sink>
+               <name>in</name>
+               <type>complex</type>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>byte</type>
+       </source>
+</block>

Copied: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_mod.xml 
(from rev 8124, 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qam_mod.xml)
===================================================================
--- 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_mod.xml 
                            (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/modulators/blks2_qamx_mod.xml 
    2008-03-29 22:42:01 UTC (rev 8140)
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##QAM Mod - 8, 16, 64, 256
+###################################################
+ -->
+<block>
+       <name>QAM Mod</name>
+       <key>blks2_qamx_mod</key>
+       <import>from gnuradio import blks2</import>
+       <make>blks2.$(type)_mod(
+       samples_per_symbol=$samples_per_symbol,
+       excess_bw=$excess_bw,
+       gray_code=$gray_code,
+)</make>
+       <param>
+               <name>Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>QAM8</name>
+                       <key>qam8</key>
+               </option>
+               <option>
+                       <name>QAM16</name>
+                       <key>qam16</key>
+               </option>
+               <option>
+                       <name>QAM64</name>
+                       <key>qam64</key>
+               </option>
+               <option>
+                       <name>QAM256</name>
+                       <key>qam256</key>
+               </option>
+       </param>
+       <param>
+               <name>Samples per Symbol</name>
+               <key>samples_per_symbol</key>
+               <value>2</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Excess BW</name>
+               <key>excess_bw</key>
+               <value>0.35</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Gray Code</name>
+               <key>gray_code</key>
+               <value>True</value>
+               <type>enum</type>
+               <option>
+                       <name>Yes</name>
+                       <key>True</key>
+               </option>
+               <option>
+                       <name>No</name>
+                       <key>False</key>
+               </option>
+       </param>
+       <sink>
+               <name>in</name>
+               <type>byte</type>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>complex</type>
+       </source>
+</block>

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml      
2008-03-29 20:06:12 UTC (rev 8139)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml      
2008-03-29 22:42:01 UTC (rev 8140)
@@ -175,8 +175,8 @@
                <block>blks2_gmsk_mod</block>
                <block>blks2_gmsk_demod</block>
                
-               <block>blks2_qam_mod</block>
-               <block>blks2_qam_demod</block>
+               <block>blks2_qamx_mod</block>
+               <block>blks2_qamx_demod</block>
                
                <block>packet_modulator</block>
                <block>packet_demodulator</block>

Added: grc/branches/grc_reloaded/src/grc_gnuradio/extract_docs.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/extract_docs.py                  
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/extract_docs.py  2008-03-29 
22:42:01 UTC (rev 8140)
@@ -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.extract_docs
+#Extract documentation from the gnuradio doxygen files.
address@hidden Josh Blum
+
+from grc import ParseXML
+import os
+
+DOCS_DIR = '/usr/local/share/doc/grc_gnuradio_docs/'
+DOXYGEN_NAME_INST = ('doxygen', 'compounddef', 'compoundname')
+DOXYGEN_BRIEFDESC_GR_INST = ('doxygen', 'compounddef', 'briefdescription')
+DOXYGEN_DETAILDESC_GR_INST = ('doxygen', 'compounddef', 'detaileddescription')
+DOXYGEN_BRIEFDESC_BLKS2_INST = ('doxygen', 'compounddef', ('sectiondef', 
{'kind': 'public-func'}), 'memberdef', 'briefdescription')
+DOXYGEN_DETAILDESC_BLKS2_INST = ('doxygen', 'compounddef', ('sectiondef', 
{'kind': 'public-func'}), 'memberdef', 'detaileddescription')
+
+def get_xml_entity(xml_file, instructions):
+       """!
+       Get an xml entity from the file by following the given path.
+       @param xml_file the path to the xml file
+       @param instructions the specification to search the xml doc
+       @return the xml entity or None if not found
+       """
+       doc = ParseXML.from_file(xml_file)
+       for inst in instructions:
+               #split up the intruction if it is a tuple or list
+               if isinstance(inst, (tuple, list)): tag, attrs = inst
+               else: tag, attrs = inst, {}
+               #look through each child node
+               childMatch = None
+               for childNode in doc.childNodes:
+                       if str(childNode.localName) == str(tag):
+                               #if child node has no attributes, attrs must be 
empty
+                               if not childNode.hasAttributes():
+                                       if attrs: continue
+                                       childMatch = childNode
+                                       break
+                               if all(str(childNode.getAttribute(k)) == str(v) 
for k,v in attrs.iteritems()): 
+                                       childMatch = childNode
+                                       break           
+               if not childMatch: return None
+               doc = childMatch        
+       return doc              
+
+def extract_txt(doc):
+       """!
+       Recursivly pull the text out of an xml document.
+       @param doc the xml document
+       @return a string
+       """
+       if len(doc.childNodes) == 0: return str(doc.nodeValue)
+       return ''.join(map(extract_txt, doc.childNodes)).strip('\n')
+       
+def is_match(key, file):
+       """!
+       Is the block key a match for the given file name?
+       @param key block key
+       @param file the xml file name
+       @return true if matches
+       """
+       file = file.replace('.xml', '') #remove file ext
+       file = file.replace('__', '_') #doxygen xml files have 2 underscores
+       file = file.replace('_1_1', '_') #weird blks2 doxygen syntax
+       if key.startswith('gr_'): key = key.replace('gr_', '')
+       elif key.startswith('blks2_'): key = key.replace('blks2_', '')
+       else: return False
+       for k, f in zip(*map(reversed, map(lambda x: x.split('_'), [key, 
file]))):
+               if k == f: continue
+               ks = k.split('x')
+               if len(ks) == 2 and f.startswith(ks[0]) and f.endswith(ks[1]): 
continue
+               if len(ks) > 2 and all(ki in ('x', fi) for ki, fi in zip(k, 
f)): continue
+               return False
+       return True     
+
+def extract(key):
+       """!
+       Extract the documentation from the doxygen generated xml files.
+       If multiple files match, combine the docs.
+       @param key the block key
+       @return a string with documentation
+       """             
+       #get potential xml file matches for the key
+       if os.path.exists(DOCS_DIR) and os.path.isdir(DOCS_DIR):
+               matches = filter(lambda f: is_match(key, f), 
os.listdir(DOCS_DIR))
+       else: matches = list()
+       #combine all matches
+       doc_strs = list()
+       for match in matches:
+               xml_file = DOCS_DIR + '/' + match
+               #extract descriptions
+               comp_name = extract_txt(get_xml_entity(xml_file, 
DOXYGEN_NAME_INST))
+               comp_name = '   ---   ' + comp_name + '   ---   '
+               if key.startswith('gr_'):
+                       brief_desc = extract_txt(get_xml_entity(xml_file, 
DOXYGEN_BRIEFDESC_GR_INST))
+                       detailed_desc = extract_txt(get_xml_entity(xml_file, 
DOXYGEN_DETAILDESC_GR_INST))
+               elif key.startswith('blks2_'):
+                       brief_desc = extract_txt(get_xml_entity(xml_file, 
DOXYGEN_BRIEFDESC_BLKS2_INST))
+                       detailed_desc = extract_txt(get_xml_entity(xml_file, 
DOXYGEN_DETAILDESC_BLKS2_INST))
+               else:
+                       brief_desc = ''
+                       detailed_desc = ''
+               #combine
+               doc_strs.append('\n'.join([comp_name, brief_desc, 
detailed_desc]).strip('\n'))  
+       return '\n\n'.join(doc_strs)
+





reply via email to

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