summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2014-07-11 10:03:27 -0400
committerTom Rondeau <tom@trondeau.com>2014-07-11 10:03:27 -0400
commit62831422ae4b2a817a997153468008db38e06598 (patch)
tree4aca7097fbfae8bf1890194c90ad43e44b572db5
parent2bb2b31476cb33e9c1bbb196fffba3a857b4f75a (diff)
parent6d9dfac64806ad2d1eb77a9ae909e4b9d66ea7fd (diff)
Merge remote-tracking branch 'gnuradio-wg-grc/grc_variable_blocks'
-rw-r--r--gr-digital/grc/digital_constellation.xml90
-rw-r--r--gr-digital/grc/digital_constellation_rect.xml102
-rw-r--r--grc/base/Block.py7
-rw-r--r--grc/python/Block.py10
-rw-r--r--grc/python/FlowGraph.py2
-rw-r--r--grc/python/block.dtd3
6 files changed, 106 insertions, 108 deletions
diff --git a/gr-digital/grc/digital_constellation.xml b/gr-digital/grc/digital_constellation.xml
index 8d2a34f1fa..4ca78984a7 100644
--- a/gr-digital/grc/digital_constellation.xml
+++ b/gr-digital/grc/digital_constellation.xml
@@ -7,65 +7,57 @@
###################################################
-->
<block>
- <name>Constellation Object</name>
- <key>variable_constellation</key>
- <category>Modulators</category>
- <import>from gnuradio import digital</import>
- <var_make>self.$(id) = $(id) = digital.constellation_calcdist($const_points, $sym_map, $rot_sym, $dims).base()
+ <name>Constellation Object</name>
+ <key>variable_constellation</key>
+ <category>Modulators</category>
+ <import>from gnuradio import digital</import>
+ <var_make>self.$(id) = $(id) = digital.constellation_calcdist($const_points, $sym_map, $rot_sym, $dims).base()
#if str($soft_dec_lut).lower() == '"auto"' or str($soft_dec_lut).lower() == "'auto'"
self.$(id).gen_soft_dec_lut($precision)
#else if str($soft_dec_lut) != 'None'
self.$(id).set_soft_dec_lut($soft_dec_lut, $precision)
#end if
</var_make>
- <make></make>
- <!--<callback></callback>-->
+ <var_value>digital.constellation_calcdist($const_points, $sym_map, $rot_sym, $dims)</var_value>
+ <make></make>
+ <!--<callback></callback>-->
- <!-- Required to 'trick' GRC into using this as a proper variable-->
- <param>
- <name>Ignore Me</name>
- <key>value</key>
- <value>"ok"</value>
- <type>raw</type>
- <hide>all</hide>
- </param>
-
- <param>
- <name>Symbol Map</name>
- <key>sym_map</key>
- <value>[0, 1, 3, 2]</value>
- <type>int_vector</type>
- </param>
- <param>
- <name>Constellation Points</name>
- <key>const_points</key>
- <value>[-1-1j, -1+1j, 1+1j, 1-1j]</value>
- <type>complex_vector</type>
+ <param>
+ <name>Symbol Map</name>
+ <key>sym_map</key>
+ <value>[0, 1, 3, 2]</value>
+ <type>int_vector</type>
+ </param>
+ <param>
+ <name>Constellation Points</name>
+ <key>const_points</key>
+ <value>[-1-1j, -1+1j, 1+1j, 1-1j]</value>
+ <type>complex_vector</type>
</param>
<param>
- <name>Rotational Symmetry</name>
- <key>rot_sym</key>
- <value>4</value>
- <type>int</type>
+ <name>Rotational Symmetry</name>
+ <key>rot_sym</key>
+ <value>4</value>
+ <type>int</type>
</param>
<param>
- <name>Dimensionality</name>
- <key>dims</key>
- <value>1</value>
- <type>int</type>
+ <name>Dimensionality</name>
+ <key>dims</key>
+ <value>1</value>
+ <type>int</type>
</param>
- <param>
- <name>Soft Decisions Precision</name>
- <key>precision</key>
- <value>8</value>
- <type>int</type>
- <hide>part</hide>
- </param>
- <param>
- <name>Soft Decisions LUT</name>
- <key>soft_dec_lut</key>
- <value>None</value>
- <type>raw</type>
- <hide>#if str($soft_dec_lut) == 'None' then 'part' else 'none'#</hide>
- </param>
+ <param>
+ <name>Soft Decisions Precision</name>
+ <key>precision</key>
+ <value>8</value>
+ <type>int</type>
+ <hide>part</hide>
+ </param>
+ <param>
+ <name>Soft Decisions LUT</name>
+ <key>soft_dec_lut</key>
+ <value>None</value>
+ <type>raw</type>
+ <hide>#if str($soft_dec_lut) == 'None' then 'part' else 'none'#</hide>
+ </param>
</block>
diff --git a/gr-digital/grc/digital_constellation_rect.xml b/gr-digital/grc/digital_constellation_rect.xml
index e6acc14bc4..fee750ac1f 100644
--- a/gr-digital/grc/digital_constellation_rect.xml
+++ b/gr-digital/grc/digital_constellation_rect.xml
@@ -9,79 +9,71 @@
<block>
<name>Constellation Rect. Object</name>
<key>variable_constellation_rect</key>
- <category>Modulators</category>
+ <category>Modulators</category>
<import>from gnuradio import digital</import>
- <var_make>self.$(id) = $(id) = digital.constellation_rect($const_points, $sym_map, $rot_sym, $real_sect, $imag_sect, $w_real_sect, $w_imag_sect).base()
+ <var_make>self.$(id) = $(id) = digital.constellation_rect($const_points, $sym_map, $rot_sym, $real_sect, $imag_sect, $w_real_sect, $w_imag_sect).base()
#if str($softbits_lut) != 'None'
self.$(id).set_softbits($softbits_lut, $precision)
#end if
</var_make>
- <make></make>
- <!--<callback>set_softbits($softbits_lut, $precision)</callback>-->
-
- <!-- Required to 'trick' GRC into using this as a proper variable-->
- <param>
- <name>Ignore Me</name>
- <key>value</key>
- <value>"ok"</value>
- <type>raw</type>
- <hide>all</hide>
- </param>
+ <var_value>digital.constellation_rect($const_points, $sym_map, $rot_sym, $real_sect, $imag_sect, $w_real_sect, $w_imag_sect)</var_value>
+ <make></make>
+ <!--<callback>set_softbits($softbits_lut, $precision)</callback>-->
<param>
- <name>Symbol Map</name>
- <key>sym_map</key>
- <value>[0, 1, 3, 2]</value>
- <type>int_vector</type>
+ <name>Symbol Map</name>
+ <key>sym_map</key>
+ <value>[0, 1, 3, 2]</value>
+ <type>int_vector</type>
</param>
<param>
- <name>Constellation Points</name>
- <key>const_points</key>
- <value>[-1-1j, -1+1j, 1+1j, 1-1j]</value>
- <type>complex_vector</type>
+ <name>Constellation Points</name>
+ <key>const_points</key>
+ <value>[-1-1j, -1+1j, 1+1j, 1-1j]</value>
+ <type>complex_vector</type>
</param>
<param>
- <name>Rotational Symmetry</name>
- <key>rot_sym</key>
- <value>4</value>
- <type>int</type>
+ <name>Rotational Symmetry</name>
+ <key>rot_sym</key>
+ <value>4</value>
+ <type>int</type>
</param>
<param>
- <name>Real Sectors</name>
- <key>real_sect</key>
- <value>2</value>
- <type>int</type>
+ <name>Real Sectors</name>
+ <key>real_sect</key>
+ <value>2</value>
+ <type>int</type>
</param>
<param>
- <name>Imaginary Sectors</name>
- <key>imag_sect</key>
- <value>2</value>
- <type>int</type>
+ <name>Imaginary Sectors</name>
+ <key>imag_sect</key>
+ <value>2</value>
+ <type>int</type>
</param>
<param>
- <name>Width Real Sectors</name>
- <key>w_real_sect</key>
- <value>1</value>
- <type>int</type>
+ <name>Width Real Sectors</name>
+ <key>w_real_sect</key>
+ <value>1</value>
+ <type>int</type>
</param>
<param>
- <name>Width Imaginary Sectors</name>
- <key>w_imag_sect</key>
- <value>1</value>
- <type>int</type>
+ <name>Width Imaginary Sectors</name>
+ <key>w_imag_sect</key>
+ <value>1</value>
+ <type>int</type>
</param>
- <param>
- <name>Soft bits precision</name>
- <key>precision</key>
- <value>8</value>
- <type>int</type>
- <hide>part</hide>
- </param>
- <param>
- <name>Soft bits LUT</name>
- <key>softbits_lut</key>
- <value>None</value>
- <type>raw</type>
- <hide>#if str($softbits_lut) == 'None' then 'part' else 'none'#</hide>
- </param>
+ <param>
+ <name>Soft bits precision</name>
+ <key>precision</key>
+ <value>8</value>
+ <type>int</type>
+ <hide>part</hide>
+ </param>
+ <param>
+ <name>Soft bits LUT</name>
+ <key>softbits_lut</key>
+ <value>None</value>
+ <type>raw</type>
+ <hide>#if str($softbits_lut) == 'None' then 'part' else 'none'#</hide>
+ </param>
</block>
diff --git a/grc/base/Block.py b/grc/base/Block.py
index a14ffd92fc..a8a699f29d 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -77,6 +77,7 @@ class Block(Element):
self._block_wrapper_path = n.find('block_wrapper_path')
self._bussify_sink = n.find('bus_sink')
self._bussify_source = n.find('bus_source')
+ self._var_value = n.find('var_value') or '$value'
# get list of param tabs
n_tabs = n.find('param_tab_order') or None
@@ -275,8 +276,10 @@ class Block(Element):
tmpl = str(tmpl)
if '$' not in tmpl: return tmpl
n = dict((p.get_key(), TemplateArg(p)) for p in self.get_params())
- try: return str(Template(tmpl, n))
- except Exception, e: return "-------->\n%s: %s\n<--------"%(e, tmpl)
+ try:
+ return str(Template(tmpl, n))
+ except Exception as err:
+ return "Template error: %s\n %s" % (tmpl, err)
##############################################
# Controller Modify
diff --git a/grc/python/Block.py b/grc/python/Block.py
index 7a1c3a254f..9556e8f061 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from .. base.Block import Block as _Block
from .. gui.Block import Block as _GUIBlock
+from . FlowGraph import _variable_matcher
import extract_docs
class Block(_Block, _GUIBlock):
@@ -90,6 +91,14 @@ class Block(_Block, _GUIBlock):
if not self.get_parent().evaluate(check_res):
self.add_error_message('Check "%s" failed.'%check)
except: self.add_error_message('Check "%s" did not evaluate.'%check)
+ # for variables check the value (only if var_value is used
+ if _variable_matcher.match(self.get_key()) and self._var_value != '$value':
+ value = self._var_value
+ try:
+ value = self.get_var_value()
+ self.get_parent().evaluate(value)
+ except Exception as err:
+ self.add_error_message('Value "%s" cannot be evaluated:\n%s' % (value, err))
def rewrite(self):
"""
@@ -169,6 +178,7 @@ class Block(_Block, _GUIBlock):
def get_make(self): return self.resolve_dependencies(self._make)
def get_var_make(self): return self.resolve_dependencies(self._var_make)
+ def get_var_value(self): return self.resolve_dependencies(self._var_value)
def get_callbacks(self):
"""
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py
index 114f708cb2..daec2d4310 100644
--- a/grc/python/FlowGraph.py
+++ b/grc/python/FlowGraph.py
@@ -262,7 +262,7 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
#load variables
for variable in self.get_variables():
try:
- e = eval(variable.get_param('value').to_code(), n, n)
+ e = eval(variable.get_var_value(), n, n)
n[variable.get_id()] = e
except: pass
#make namespace public
diff --git a/grc/python/block.dtd b/grc/python/block.dtd
index 18e53fda2a..602339ba7c 100644
--- a/grc/python/block.dtd
+++ b/grc/python/block.dtd
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Top level element.
A block contains a name, ...parameters list, and list of IO ports.
-->
-<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, make, callback*, param_tab_order?, param*, bus_sink?, bus_source?, check*, sink*, source*, bus_structure_sink?, bus_structure_source?, doc?, grc_source?)>
+<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, var_value?, make, callback*, param_tab_order?, param*, bus_sink?, bus_source?, check*, sink*, source*, bus_structure_sink?, bus_structure_source?, doc?, grc_source?)>
<!--
Sub level elements.
-->
@@ -57,6 +57,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
<!ELEMENT bus_structure_sink (#PCDATA)>
<!ELEMENT bus_structure_source (#PCDATA)>
<!ELEMENT var_make (#PCDATA)>
+<!ELEMENT var_value (#PCDATA)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT value (#PCDATA)>
<!ELEMENT callback (#PCDATA)>