commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5794 - in grc/branches/jblum_work: examples src/Graph


From: jblum
Subject: [Commit-gnuradio] r5794 - in grc/branches/jblum_work: examples src/Graphics src/SignalBlockDefs
Date: Mon, 18 Jun 2007 21:35:43 -0600 (MDT)

Author: jblum
Date: 2007-06-18 21:35:42 -0600 (Mon, 18 Jun 2007)
New Revision: 5794

Added:
   grc/branches/jblum_work/examples/valve.grc.xml
Modified:
   grc/branches/jblum_work/examples/channel_distortion.grc.xml
   grc/branches/jblum_work/examples/packet_mod_demod.grc.xml
   grc/branches/jblum_work/examples/variable_sink.grc.xml
   grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py
   grc/branches/jblum_work/src/SignalBlockDefs/Filters.py
   grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py
   grc/branches/jblum_work/src/SignalBlockDefs/Misc.py
   grc/branches/jblum_work/src/SignalBlockDefs/Packet.py
   grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py
   grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py
   grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py
Log:
added valve block and valve example, created throttle helper for various blocks

Modified: grc/branches/jblum_work/examples/channel_distortion.grc.xml
===================================================================
--- grc/branches/jblum_work/examples/channel_distortion.grc.xml 2007-06-18 
18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/examples/channel_distortion.grc.xml 2007-06-19 
03:35:42 UTC (rev 5794)
@@ -1,6 +1,6 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <flow_graph>
-  <timestamp>1182068680.68</timestamp>
+  <timestamp>1182222914.4</timestamp>
   <hostname>tiggle</hostname>
   <version>0.70 alpha</version>
   <valid>True</valid>

Modified: grc/branches/jblum_work/examples/packet_mod_demod.grc.xml
===================================================================
--- grc/branches/jblum_work/examples/packet_mod_demod.grc.xml   2007-06-18 
18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/examples/packet_mod_demod.grc.xml   2007-06-19 
03:35:42 UTC (rev 5794)
@@ -1,6 +1,6 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <flow_graph>
-  <timestamp>1182064037.15</timestamp>
+  <timestamp>1182223827.52</timestamp>
   <hostname>tiggle</hostname>
   <version>0.70 alpha</version>
   <valid>True</valid>
@@ -9,11 +9,32 @@
   <vars>
     <var>
       <key>samp_rate</key>
-      <value>100e3</value>
+      <value>200e3</value>
       <min/>
       <max/>
       <step/>
     </var>
+    <var>
+      <key>freq</key>
+      <value>2500</value>
+      <min>0</min>
+      <max>5000</max>
+      <step>50.0</step>
+    </var>
+    <var>
+      <key>amp</key>
+      <value>1</value>
+      <min>0</min>
+      <max>2</max>
+      <step>0.02</step>
+    </var>
+    <var>
+      <key>off</key>
+      <value>0</value>
+      <min>-1</min>
+      <max>1</max>
+      <step>0.02</step>
+    </var>
   </vars>
   <signal_blocks>
     <signal_block>
@@ -28,66 +49,6 @@
       </params>
     </signal_block>
     <signal_block>
-      <tag>Signal Source</tag>
-      <id>Signal Source0</id>
-      <x_coordinate>47</x_coordinate>
-      <y_coordinate>350</y_coordinate>
-      <rotation>90</rotation>
-      <params>
-        <param>1</param>
-        <param>$samp_rate</param>
-        <param>1</param>
-        <param>1000</param>
-        <param>1</param>
-        <param>0</param>
-      </params>
-    </signal_block>
-    <signal_block>
-      <tag>Packet Demodulator</tag>
-      <id>Packet Demodulator0</id>
-      <x_coordinate>647</x_coordinate>
-      <y_coordinate>414</y_coordinate>
-      <rotation>180</rotation>
-      <params>
-        <param>1</param>
-        <param>$samp_rate</param>
-        <param/>
-        <param>-1</param>
-        <param>2</param>
-      </params>
-    </signal_block>
-    <signal_block>
-      <tag>Packet Modulator</tag>
-      <id>Packet Modulator0</id>
-      <x_coordinate>278</x_coordinate>
-      <y_coordinate>37</y_coordinate>
-      <rotation>0</rotation>
-      <params>
-        <param>1</param>
-        <param>1</param>
-        <param>$samp_rate</param>
-        <param>2</param>
-        <param>100</param>
-        <param/>
-        <param>2</param>
-        <param>0</param>
-        <param>1</param>
-      </params>
-    </signal_block>
-    <signal_block>
-      <tag>PSK Modulator</tag>
-      <id>PSK Modulator0</id>
-      <x_coordinate>548</x_coordinate>
-      <y_coordinate>31</y_coordinate>
-      <rotation>0</rotation>
-      <params>
-        <param>0</param>
-        <param>2</param>
-        <param>0.35</param>
-        <param>0</param>
-      </params>
-    </signal_block>
-    <signal_block>
       <tag>PSK Demodulator</tag>
       <id>PSK Demodulator0</id>
       <x_coordinate>774</x_coordinate>
@@ -129,36 +90,94 @@
         <param>A demonstration of the packet framework.</param>
       </params>
     </signal_block>
+    <signal_block>
+      <tag>Signal Source</tag>
+      <id>Signal Source0</id>
+      <x_coordinate>47</x_coordinate>
+      <y_coordinate>350</y_coordinate>
+      <rotation>90</rotation>
+      <params>
+        <param>1</param>
+        <param>$samp_rate</param>
+        <param>1</param>
+        <param>$freq</param>
+        <param>$amp</param>
+        <param>$off</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>Packet Demodulator</tag>
+      <id>Packet Demodulator0</id>
+      <x_coordinate>637</x_coordinate>
+      <y_coordinate>422</y_coordinate>
+      <rotation>180</rotation>
+      <params>
+        <param>1</param>
+        <param>$samp_rate</param>
+        <param/>
+        <param>-1</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>PSK Modulator</tag>
+      <id>PSK Modulator0</id>
+      <x_coordinate>546</x_coordinate>
+      <y_coordinate>30</y_coordinate>
+      <rotation>0</rotation>
+      <params>
+        <param>0</param>
+        <param>2</param>
+        <param>0.35</param>
+        <param>0</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>Packet Modulator</tag>
+      <id>Packet Modulator0</id>
+      <x_coordinate>263</x_coordinate>
+      <y_coordinate>55</y_coordinate>
+      <rotation>0</rotation>
+      <params>
+        <param>1</param>
+        <param>1</param>
+        <param>$samp_rate</param>
+        <param>2</param>
+        <param>256</param>
+        <param/>
+        <param>0</param>
+        <param>1</param>
+      </params>
+    </signal_block>
   </signal_blocks>
   <connections>
     <connection>
-      <input_signal_block_id>Packet Modulator0</input_signal_block_id>
+      <input_signal_block_id>Scope Sink0</input_signal_block_id>
       <input_socket_index>0</input_socket_index>
-      <output_signal_block_id>Signal Source0</output_signal_block_id>
+      <output_signal_block_id>Packet Demodulator0</output_signal_block_id>
       <output_socket_index>0</output_socket_index>
     </connection>
     <connection>
-      <input_signal_block_id>Scope Sink0</input_signal_block_id>
+      <input_signal_block_id>Packet Demodulator0</input_signal_block_id>
       <input_socket_index>0</input_socket_index>
-      <output_signal_block_id>Packet Demodulator0</output_signal_block_id>
+      <output_signal_block_id>PSK Demodulator0</output_signal_block_id>
       <output_socket_index>0</output_socket_index>
     </connection>
     <connection>
-      <input_signal_block_id>PSK Modulator0</input_signal_block_id>
+      <input_signal_block_id>PSK Demodulator0</input_signal_block_id>
       <input_socket_index>0</input_socket_index>
-      <output_signal_block_id>Packet Modulator0</output_signal_block_id>
+      <output_signal_block_id>PSK Modulator0</output_signal_block_id>
       <output_socket_index>0</output_socket_index>
     </connection>
     <connection>
-      <input_signal_block_id>Packet Demodulator0</input_signal_block_id>
+      <input_signal_block_id>PSK Modulator0</input_signal_block_id>
       <input_socket_index>0</input_socket_index>
-      <output_signal_block_id>PSK Demodulator0</output_signal_block_id>
+      <output_signal_block_id>Packet Modulator0</output_signal_block_id>
       <output_socket_index>0</output_socket_index>
     </connection>
     <connection>
-      <input_signal_block_id>PSK Demodulator0</input_signal_block_id>
+      <input_signal_block_id>Packet Modulator0</input_signal_block_id>
       <input_socket_index>0</input_socket_index>
-      <output_signal_block_id>PSK Modulator0</output_signal_block_id>
+      <output_signal_block_id>Signal Source0</output_signal_block_id>
       <output_socket_index>0</output_socket_index>
     </connection>
   </connections>

Added: grc/branches/jblum_work/examples/valve.grc.xml
===================================================================
--- grc/branches/jblum_work/examples/valve.grc.xml                              
(rev 0)
+++ grc/branches/jblum_work/examples/valve.grc.xml      2007-06-19 03:35:42 UTC 
(rev 5794)
@@ -0,0 +1,126 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<flow_graph>
+  <timestamp>1182223556.24</timestamp>
+  <hostname>tiggle</hostname>
+  <version>0.70 alpha</version>
+  <valid>True</valid>
+  <window_width>800</window_width>
+  <window_height>600</window_height>
+  <vars>
+    <var>
+      <key>samp_rate</key>
+      <value>100e3</value>
+      <min/>
+      <max/>
+      <step/>
+    </var>
+    <var>
+      <key>freq</key>
+      <value>2500</value>
+      <min>0</min>
+      <max>5000</max>
+      <step>50.0</step>
+    </var>
+    <var>
+      <key>amp</key>
+      <value>1</value>
+      <min>0</min>
+      <max>2</max>
+      <step>0.02</step>
+    </var>
+    <var>
+      <key>off</key>
+      <value>0</value>
+      <min>-1</min>
+      <max>1</max>
+      <step>0.02</step>
+    </var>
+    <var>
+      <key>open</key>
+      <value>0</value>
+      <min>0</min>
+      <max>1</max>
+      <step>1</step>
+    </var>
+  </vars>
+  <signal_blocks>
+    <signal_block>
+      <tag>Signal Source</tag>
+      <id>Signal Source0</id>
+      <x_coordinate>47</x_coordinate>
+      <y_coordinate>350</y_coordinate>
+      <rotation>90</rotation>
+      <params>
+        <param>1</param>
+        <param>$samp_rate</param>
+        <param>1</param>
+        <param>$freq</param>
+        <param>$amp</param>
+        <param>$off</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>Scope Sink</tag>
+      <id>Scope Sink0</id>
+      <x_coordinate>276</x_coordinate>
+      <y_coordinate>405</y_coordinate>
+      <rotation>180</rotation>
+      <params>
+        <param>1</param>
+        <param>Scope</param>
+        <param>$samp_rate</param>
+        <param>1</param>
+        <param>0</param>
+        <param>0.001</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>About</tag>
+      <id>About0</id>
+      <x_coordinate>20</x_coordinate>
+      <y_coordinate>20</y_coordinate>
+      <rotation>0</rotation>
+      <params>
+        <param>Valve Demonstration</param>
+        <param>Josh Blum</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>Note</tag>
+      <id>Note0</id>
+      <x_coordinate>255</x_coordinate>
+      <y_coordinate>42</y_coordinate>
+      <rotation>0</rotation>
+      <params>
+        <param>The valve is open and the data flow is stopped when open is 
1.</param>
+      </params>
+    </signal_block>
+    <signal_block>
+      <tag>Valve</tag>
+      <id>Valve0</id>
+      <x_coordinate>270</x_coordinate>
+      <y_coordinate>150</y_coordinate>
+      <rotation>0</rotation>
+      <params>
+        <param>1</param>
+        <param>$samp_rate</param>
+        <param>$open</param>
+        <param>1</param>
+      </params>
+    </signal_block>
+  </signal_blocks>
+  <connections>
+    <connection>
+      <input_signal_block_id>Valve0</input_signal_block_id>
+      <input_socket_index>0</input_socket_index>
+      <output_signal_block_id>Signal Source0</output_signal_block_id>
+      <output_socket_index>0</output_socket_index>
+    </connection>
+    <connection>
+      <input_signal_block_id>Scope Sink0</input_signal_block_id>
+      <input_socket_index>0</input_socket_index>
+      <output_signal_block_id>Valve0</output_signal_block_id>
+      <output_socket_index>0</output_socket_index>
+    </connection>
+  </connections>
+</flow_graph>

Modified: grc/branches/jblum_work/examples/variable_sink.grc.xml
===================================================================
--- grc/branches/jblum_work/examples/variable_sink.grc.xml      2007-06-18 
18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/examples/variable_sink.grc.xml      2007-06-19 
03:35:42 UTC (rev 5794)
@@ -1,11 +1,11 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <flow_graph>
-  <timestamp>1182064071.08</timestamp>
+  <timestamp>1182223110.14</timestamp>
   <hostname>tiggle</hostname>
   <version>0.70 alpha</version>
   <valid>True</valid>
-  <window_width>1600</window_width>
-  <window_height>1200</window_height>
+  <window_width>800</window_width>
+  <window_height>500</window_height>
   <vars>
     <var>
       <key>samp_rate_out</key>
@@ -142,7 +142,6 @@
         <param>1</param>
         <param>output</param>
         <param>$samp_rate_in</param>
-        <param>2</param>
       </params>
     </signal_block>
   </signal_blocks>

Modified: grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py  
2007-06-18 18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py  
2007-06-19 03:35:42 UTC (rev 5794)
@@ -95,7 +95,7 @@
                
        def unselect_all(self):         
                """Stop editing in each renderer and unselect every row in the 
tree view."""
-               #TODO: stop editing doesnt work
+               ##TODO: stop editing doesnt work
                for renderer in self.renderers: renderer.stop_editing(True)
                self.treeview.get_selection().unselect_all()    
                

Modified: grc/branches/jblum_work/src/SignalBlockDefs/Filters.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Filters.py      2007-06-18 
18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Filters.py      2007-06-19 
03:35:42 UTC (rev 5794)
@@ -338,6 +338,15 @@
        sb.add_param('Max Gain', Float(0))      
        return sb, lambda fg, type, attack_rate, decay_rate, ref, gain, 
max_gain: \
                type.parse()[0](attack_rate.parse(), decay_rate.parse(), 
ref.parse(), gain.parse(), max_gain.parse())
+               
+def FeedForwardAGC(sb):
+       fcn = gr.feedforward_agc_cc
+       sb.add_input_socket('in', Complex())
+       sb.add_output_socket('out', Complex())
+       sb.add_param('Num Samples', Int(100, min=1))
+       sb.add_param('Reference', Float(0))
+       sb.set_docs('''Non-causal AGC which computes required gain based on max 
absolute value over nsamples.''')
+       return sb, lambda fg, nsamps, ref: fcn(nsamps.parse(), ref.parse())     
        
 def CMAFilter(sb):
        fcn = gr.cma_equalizer_cc

Modified: grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py       
2007-06-18 18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py       
2007-06-19 03:35:42 UTC (rev 5794)
@@ -22,7 +22,7 @@
 
 from DataTypes import *
 from gnuradio import gr
-from SignalBlockConstants import default_samp_rate
+from SignalBlockConstants import default_samp_rate,ThrottleHelper
 
 number_display_pritority = 0
 fft_display_priority = 1
@@ -56,9 +56,7 @@
                fg.add_window(block.win, fft_display_priority, title.parse())
                fg.add_callback(block.set_ref_level, ref_lvl)
                fg.add_callback(block.set_y_per_div, y_per_div)
-               th = gr.throttle(type.parse()[1].get_num_bytes(), 
samp_rate.parse())
-               fg.connect(th, block)
-               return th
+               return ThrottleHelper(fg, type.parse()[1].get_num_bytes(), 
samp_rate.parse(), block, True)
        return sb, make
        
 def WaterfallSink(sb):
@@ -85,9 +83,7 @@
                block.set_average(average)                      #set the 
average option outside the contructor
                fg.add_window(block.win, waterfall_display_priority, 
title.parse())
                fg.add_callback(block.set_baseband_freq, baseband_freq)
-               th = gr.throttle(type.parse()[1].get_num_bytes(), 
samp_rate.parse())
-               fg.connect(th, block)
-               return th
+               return ThrottleHelper(fg, type.parse()[1].get_num_bytes(), 
samp_rate.parse(), block, True)
        return sb, make
        
 def ScopeSink(sb):
@@ -112,9 +108,7 @@
                        sample_rate=samp_rate.parse(), 
frame_decim=frame_decim.parse(), 
                        v_scale=v_scale, t_scale=t_scale.parse())
                fg.add_window(block.win, scope_display_priority, title.parse()) 
-               th = gr.throttle(type.parse()[1].get_num_bytes(), 
samp_rate.parse())
-               fg.connect(th, block)
-               return th
+               return ThrottleHelper(fg, type.parse()[1].get_num_bytes(), 
samp_rate.parse(), block, True)
        return sb, make
        
 def ConstellationSink(sb):
@@ -136,9 +130,7 @@
                elif marker == 1: block.win.set_format_dot()
                elif marker == 2: block.win.set_format_line()
                fg.add_window(block.win, constellation_display_pritority, 
title.parse())        
-               th = gr.throttle(Complex().get_num_bytes(), samp_rate.parse())
-               fg.connect(th, block)
-               return th
+               return ThrottleHelper(fg, type.parse()[1].get_num_bytes(), 
samp_rate.parse(), block, True)
        return sb, make
 
 def NumericalSink(sb):
@@ -176,9 +168,7 @@
                fg.add_callback(block.set_base_value, base)
                fg.add_callback(block.set_ref_level, ref_lvl)
                fg.add_callback(block.set_decimal_places, decimals)
-               th = gr.throttle(type.parse()[1].get_num_bytes(), 
samp_rate.parse())
-               fg.connect(th, block)
-               return th
+               return ThrottleHelper(fg, type.parse()[1].get_num_bytes(), 
samp_rate.parse(), block, True)
        return sb, make
                
        
\ No newline at end of file

Modified: grc/branches/jblum_work/src/SignalBlockDefs/Misc.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Misc.py 2007-06-18 18:51:07 UTC 
(rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Misc.py 2007-06-19 03:35:42 UTC 
(rev 5794)
@@ -20,9 +20,10 @@
 #These blocks were not categorized. Try to keep the number of misc blocks 
small.
 address@hidden Josh Blum
 
+import gnuradio.gr.gr_threading as threading
 from DataTypes import *
-from gnuradio import gr
-from SignalBlockConstants import default_samp_rate,all_choices
+from gnuradio import gr,blks
+from SignalBlockConstants import 
default_samp_rate,all_choices,DEFAULT_QUEUE_LIMIT,ThrottleHelper
 from Constants import MAX_NUM_SOCKETS
 
 def Throttle(sb):
@@ -62,9 +63,10 @@
        return sb, lambda fg, type, num_items, vlen: 
fcn(type.parse().get_num_bytes()*vlen.parse(), num_items.parse())
        
 def RMS(sb):
-       type = Enum([('Complex', (gr.rms_cf, Complex())),
-                                       ('Float', (gr.rms_ff, Float())),
-                                       ], 1)
+       type = Enum([
+               ('Complex', (gr.rms_cf, Complex())),
+               ('Float', (gr.rms_ff, Float())),
+       ], 1)
        sb.add_input_socket('in', Variable(type, index=1))
        sb.add_output_socket('out', Float())
        sb.add_param('Input Type', type, False, type=True)
@@ -83,3 +85,74 @@
 def Note(sb):
        sb.add_param('Note', String(''))
        return sb, lambda *args: None   
+
+#######################################################################################
+##     Valve Def, Hier Block, and Helper Thread
+#######################################################################################
+
+class ValveThread(threading.Thread):
+       """Thread to forward data between the input message queue and the 
output message queue."""
+       def __init__(self, valve_helper):
+               """!
+               ValveThread contructor.
+               @param valve_helper the valve helper block
+               """
+               self.valve_helper = valve_helper
+               threading.Thread.__init__(self)
+               self.start()
+               print 'Created valve thread.'
+               
+       def run(self):
+               """In an endless while loop: read the msgq_out and write to the 
msgq_in when closed."""
+               while True:
+                       msg = self.valve_helper.msgq_out.delete_head()  
#blocking read of message queue
+                       if self.valve_helper.open: del msg      #delete the 
message
+                       else: self.valve_helper.msgq_in.insert_tail(msg) 
#forward message                       
+
+class ValveHelper(gr.hier_block):
+       """A hier block used to intercept data from a message sink, 
+       and relay it to a message source based on the state of the valve: 
open/closed."""
+       def __init__(self, fg, item_size, open):
+               """!
+               ValveHelper constructor.
+               @param fg the gr flow graph
+               @param item_size the size of the gr data stream in bytes
+               @param open the valve is open if bool(open) evaluates true
+               """
+               self.set_open(open)
+               #create blocks          
+               self.msgq_out = gr.msg_queue(DEFAULT_QUEUE_LIMIT)               
+               msg_sink = gr.message_sink(item_size, self.msgq_out, False)
+               msg_source = gr.message_source(item_size, DEFAULT_QUEUE_LIMIT)
+               self.msgq_in = msg_source.msgq()
+               #connect blocks
+               gr.hier_block.__init__(self, fg, msg_sink, msg_source)          
+               #start the thread               
+               ValveThread(self)
+               
+       def set_open(self, open):
+               """!
+               Set the open state of the valve.
+               @param open the new open state
+               """
+               self.open = open
+
+def Valve(sb):
+       type = Enum(all_choices, 1)
+       vlen = Int(1, min=1)
+       sb.add_input_socket('in', Variable(type), vlen=vlen)
+       sb.add_output_socket('out', Variable(type), vlen=vlen)
+       sb.add_param('Type', type, False, type=True)
+       sb.add_param('Sampling Rate', Float(default_samp_rate)) 
+       sb.add_param('Open', Int(0))    
+       sb.add_param('Vector Length', vlen)
+       sb.set_docs('''\
+When open is 1, the valve will not forward data.
+The valve has a throttle automatically attatched to it at runtime to save the 
CPU.
+''')   
+       def make(fg, type, samp_rate, open, vlen):
+               item_size = type.parse().get_num_bytes()*vlen.parse()
+               block = ValveHelper(fg, item_size, open.parse())
+               fg.add_callback(block.set_open, open)
+               return ThrottleHelper(fg, item_size, samp_rate.parse(), block, 
True)
+       return sb, make

Modified: grc/branches/jblum_work/src/SignalBlockDefs/Packet.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Packet.py       2007-06-18 
18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Packet.py       2007-06-19 
03:35:42 UTC (rev 5794)
@@ -20,15 +20,14 @@
 #Support for the gr packet framework.
 address@hidden Josh Blum
 
-import threading
+import gnuradio.gr.gr_threading as threading
 from DataTypes import *
 from gnuradio import gr,blks,packet_utils
-from SignalBlockConstants import all_choices,default_samp_rate
+from SignalBlockConstants import 
all_choices,default_samp_rate,DEFAULT_QUEUE_LIMIT
 
 MAX_ACCESS_CODE_LENGTH = 64
 MAX_PACKET_LENGTH = len(packet_utils.random_mask_tuple)#4096
-DEFAULT_QUEUE_LIMIT = 2
-DEFAULT_PACKET_LENGTH = 100
+DEFAULT_PACKET_LENGTH = 512
 
 
#######################################################################################
 ##     Packet Modulator and Demodulator Hier Block
@@ -57,22 +56,18 @@
                """In an endless while loop: read the msgq and call send 
packet."""
                r = '' #residual message
                while True:
-                       try:            
-                               msg = self.msgq.delete_head()  # blocking read 
of message queue
-                               sr = r + msg.to_string()
-                               num_packets = len(sr)/int(self.packet_length) 
#integer arithmetic
-                               r_index = self.packet_length*num_packets
-                               s = sr[0:r_index]       #portion of message 
divisible by packet size                            
-                               r = sr[r_index:]        #residual portion of 
message smaller then packet size   
-                               #print len(s), len(r), msg.type(), msg.arg1(), 
msg.arg2()               
-                               for i in range(num_packets): 
self.send_packet(s[i*self.packet_length:(i+1)*self.packet_length])
-                       except Exception, e: 
-                               print "done", e
-                               break
-
+                       msg = self.msgq.delete_head()  # blocking read of 
message queue
+                       sr = r + msg.to_string()
+                       num_packets = len(sr)/int(self.packet_length) #integer 
arithmetic
+                       r_index = self.packet_length*num_packets
+                       s = sr[0:r_index]       #portion of message divisible 
by packet size                            
+                       r = sr[r_index:]        #residual portion of message 
smaller then packet size   
+                       #print len(s), len(r), msg.type(), msg.arg1(), 
msg.arg2()               
+                       for i in range(num_packets): 
self.send_packet(s[i*self.packet_length:(i+1)*self.packet_length])
+               
 class PacketModHelper(gr.hier_block):
        """Forward data from the gr data stream to the mod packet."""
-       def __init__(self, fg, item_size, packet_length, samp_rate, 
samples_per_symbol, bits_per_symbol, access_code, msgq_limit, pad_for_usrp, 
use_whitener_offset):
+       def __init__(self, fg, item_size, packet_length, samp_rate, 
samples_per_symbol, bits_per_symbol, access_code, pad_for_usrp, 
use_whitener_offset):
                """!
                PacketModHelper constructor.
                @param fg the flow graph
@@ -82,7 +77,7 @@
                @param *args the arguments for blks.mod_pkts
                """
                #dummy modulator with access functions          
-               modulator = gr.skiphead(Byte().get_num_bytes(), 0)              
#skip nothing
+               modulator = gr.throttle(Byte().get_num_bytes(), samp_rate)      
                modulator.samples_per_symbol = lambda: samples_per_symbol
                modulator.bits_per_symbol = lambda: bits_per_symbol
                #create the packet modulator (handles the output data stream)
@@ -90,24 +85,21 @@
                        fg=fg, 
                        modulator=modulator, 
                        access_code=access_code, 
-                       msgq_limit=msgq_limit, 
+                       msgq_limit=DEFAULT_QUEUE_LIMIT, 
                        pad_for_usrp=pad_for_usrp, 
                        use_whitener_offset=use_whitener_offset,
                )
-               #the throttle (handles the input data stream)
-               throttle = gr.throttle(item_size, samp_rate)
-               #the message sink 
-               msgq = gr.msg_queue(msgq_limit)
-               msg_sink = gr.message_sink(item_size, msgq, True)
+               #the message sink (handles the input data stream)
+               msgq = gr.msg_queue(DEFAULT_QUEUE_LIMIT)
+               msg_sink = gr.message_sink(item_size, msgq, False)
                #create hier block
-               fg.connect(throttle, msg_sink)
-               gr.hier_block.__init__(self, fg, throttle, packet_mod)
+               gr.hier_block.__init__(self, fg, msg_sink, packet_mod)
                #create/start the thread
                PacketModThread(msgq, packet_mod.send_pkt, packet_length)
 
 class PacketDemodHelper(gr.hier_block):
        """Forward data from demod packet to the gr data stream."""
-       def __init__(self, fg, item_size, samp_rate, access_code, threshold, 
msgq_limit):
+       def __init__(self, fg, item_size, samp_rate, access_code, threshold):
                """!
                PacketDemodHelper constructor.
                @param fg the flow graph
@@ -117,12 +109,12 @@
                @param msgq_limit the queue limit for the message source
                """
                #the message source (handles the output data stream)
-               msg_source = gr.message_source(item_size, msgq_limit)
+               msg_source = gr.message_source(item_size, DEFAULT_QUEUE_LIMIT)
                msgq = msg_source.msgq()
-               callback = lambda ok, payload: \
-                       msgq.insert_tail(gr.message_from_string(payload, 0, 
item_size, len(payload)/item_size))
-               #dummy demodulator with access functions                
-               demodulator = gr.throttle(Byte().get_num_bytes(), samp_rate)    
        #skip nothing
+               def callback(ok, payload):
+                       if ok: msgq.insert_tail(gr.message_from_string(payload, 
0, item_size, len(payload)/item_size))
+               #dummy demodulator + throimport gnuradio.gr.gr_threading as 
threadingttle       
+               demodulator = gr.throttle(Byte().get_num_bytes(), samp_rate)    
                #create the packet demodulator (handles the input data stream)
                packet_demod = blks.demod_pkts( 
                        fg=fg, 
@@ -157,7 +149,6 @@
        sb.add_param('Samples/Symbol', Int(DEFAULT_QUEUE_LIMIT, min=1))
        sb.add_param('Packet Length', Int(DEFAULT_PACKET_LENGTH, min=1, 
max=MAX_PACKET_LENGTH))
        sb.add_param('Access Code', String('', max=MAX_ACCESS_CODE_LENGTH))
-       sb.add_param('Queue Limit', Int(2, min=1))
        sb.add_param('Pad for USRP', Bool(true='Yes', false='No', default=True))
        sb.add_param('Use Whitener Offset', Bool(true='Yes', false='No', 
default=False))
        sb.set_docs('''\
@@ -166,19 +157,17 @@
 Modulator type: tells the packet modulator how many bits per symbol to use. \
 A modulator block should still be connected to the output of this block.
 
-Packet length: length of a packet, no greater than %d.
+Packet length: length of a packet in bytes, must be a multiple of the size of 
the input data stream, and no greater than %d.
 
 Access code/sync vector: string of 1's and 0's between 1 and %d long. Leave 
blank for default.
 
-Queue limit: maximum number of messages in message queue.
-
 Pad for USRP: If true, packets are padded such that they end up a multiple of 
128 samples.
 
 Use whitener offset: If true, start of whitener XOR string is incremented each 
packet.
 ---
 The packet modulator has a throttle automatically attatched to it at runtime 
to save the CPU.
-'''%(MAX_ACCESS_CODE_LENGTH, MAX_PACKET_LENGTH))
-       def make(fg, type, mod_type, samp_rate, samples_per_symbol, 
packet_length, access_code, msgq_limit, pad_for_usrp, use_whitener_offset):
+'''%(MAX_PACKET_LENGTH, MAX_ACCESS_CODE_LENGTH))
+       def make(fg, type, mod_type, samp_rate, samples_per_symbol, 
packet_length, access_code, pad_for_usrp, use_whitener_offset):
                access_code = access_code.parse()
                if access_code == '': access_code = None        #access code 
should be None if blank
                return PacketModHelper(
@@ -189,7 +178,6 @@
                        samples_per_symbol=samples_per_symbol.parse(), 
                        bits_per_symbol=mod_type.parse().bits_per_symbol(),
                        access_code=access_code, 
-                       msgq_limit=msgq_limit.parse(), 
                        pad_for_usrp=pad_for_usrp.parse(), 
                        use_whitener_offset=use_whitener_offset.parse(),
                )       #build packet modulator
@@ -204,7 +192,6 @@
        sb.add_param('Sampling Rate', Float(default_samp_rate)) 
        sb.add_param('Access Code', String('', max=MAX_ACCESS_CODE_LENGTH))
        sb.add_param('Threshold', Int(-1))      
-       sb.add_param('Queue Limit', Int(DEFAULT_QUEUE_LIMIT, min=1))
        sb.set_docs('''\
 The packet demodulator unwraps packets from a data stream.
 ---
@@ -216,7 +203,7 @@
 ---
 The packet demodulator has a throttle automatically attatched to it at runtime 
to save the CPU.
 '''%MAX_ACCESS_CODE_LENGTH)
-       def make(fg, type, samp_rate, access_code, threshold, msgq_limit):
+       def make(fg, type, samp_rate, access_code, threshold):
                access_code = access_code.parse()
                if access_code == '': access_code = None        #access code 
should be None if blank
                return PacketDemodHelper(
@@ -225,7 +212,6 @@
                        samp_rate=samp_rate.parse(),
                        access_code=access_code, 
                        threshold=threshold.parse(),
-                       msgq_limit=msgq_limit.parse(),
                )       #build packet demodulator               
        return sb, make
 

Modified: grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py 
2007-06-18 18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py 
2007-06-19 03:35:42 UTC (rev 5794)
@@ -21,7 +21,32 @@
 address@hidden Josh Blum
 
 from DataTypes import *
+from gnuradio import gr
 
+class ThrottleHelper(gr.hier_block):
+       """A block with a throttle on the input or output."""
+       def __init__(self, fg, item_size, samp_rate, block, position):
+               """!
+               ThrottleHelper contructor.
+               Create a throttle and append it to the block.
+               @param fg the gr flow graph
+               @param item_size the size of the gr data stream in bytes
+               @param block the gr block
+               @param position if true connect a throttle to the input of 
block, otherwise the output
+               """
+               input = output = block
+               throttle = gr.throttle(item_size, samp_rate)
+               if position:
+                       input = throttle
+                       fg.connect(throttle, block)
+               else:
+                       output = throttle
+                       fg.connect(block, throttle)
+               gr.hier_block.__init__(self, fg, input, output)
+
+##default message queue limit
+DEFAULT_QUEUE_LIMIT = 1
+
 ##choices for an Enum of regular data types
 all_choices = [
        ('Complex', Complex()),

Modified: grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py      
2007-06-18 18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py      
2007-06-19 03:35:42 UTC (rev 5794)
@@ -129,6 +129,7 @@
                                ('Fractional Interpolator', 
Filters.FractionalInterpolator),
                                ('Automatic Gain Control', 
Filters.AutomaticGainControl),
                                ('Automatic Gain Control2', 
Filters.AutomaticGainControl2),
+                               ('Feed Forward AGC', Filters.FeedForwardAGC),
                                ('CMA Filter', Filters.CMAFilter),
                                ('Clock Recovery', Filters.ClockRecovery),
                                ('FFT', Filters.FFT),
@@ -174,6 +175,7 @@
                        ]),
                        ('Misc', [      
                                ('Throttle', Misc.Throttle),
+                               ('Valve', Misc.Valve),
                                ('Head', Misc.Head),    
                                ('Skip Head', Misc.SkipHead),                   
                                ('RMS', Misc.RMS),      

Modified: grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py        2007-06-18 
18:51:07 UTC (rev 5793)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py        2007-06-19 
03:35:42 UTC (rev 5794)
@@ -103,7 +103,7 @@
                self.msgq = msgq
                threading.Thread.__init__(self)
                self.start()
-               print 'Created variable sink thread for variable "%s"'%var_key
+               print 'Created variable sink thread for variable "%s".'%var_key
                                
        def run(self):
                """
@@ -111,30 +111,26 @@
                write to the variable, and parse the callbacks.
                """
                while True:
-                       try:            
-                               msg = self.msgq.delete_head()  # blocking read 
of message queue
-                               itemsize = int(msg.arg1())
-                               nitems = int(msg.arg2())                        
        
-                               s = msg.to_string()            # get the body 
of the msg as a string                            
-                               # There may be more than one number in the 
message.
-                               # If so, we take only the last one
-                               if nitems > 1:
-                                       start = itemsize * (nitems - 1)
-                                       s = s[start:start+itemsize]             
                
-                               #       parse the data to a complex or 
float/int string #
-                               complex_data = numpy.fromstring (s, 
numpy.float32)
-                               if len(complex_data) == 2: new_value = "%f + 
%fj"%(complex_data[0], complex_data[1])
-                               else: new_value = "%f"%(complex_data[0],)
-                               while not MUTEX.testandset(): pass      #try to 
lock repeatedly until lock is aquired                           
-                               # write the new value #         
-                               Variables.unregister(self.var_key)
-                               Variables.register(self.var_key, new_value)     
                        
-                               #       parse the call backs    #               
                
-                               self.fg.parse_callbacks()       
-                               MUTEX.unlock()
-                       except Exception, e: 
-                               print "done",self.var_key, e
-                               break
+                       msg = self.msgq.delete_head()  # blocking read of 
message queue
+                       itemsize = int(msg.arg1())
+                       nitems = int(msg.arg2())                                
+                       s = msg.to_string()            # get the body of the 
msg as a string                            
+                       # There may be more than one number in the message.
+                       # If so, we take only the last one
+                       if nitems > 1:
+                               start = itemsize * (nitems - 1)
+                               s = s[start:start+itemsize]                     
        
+                       #       parse the data to a complex or float/int string 
#
+                       complex_data = numpy.fromstring (s, numpy.float32)
+                       if len(complex_data) == 2: new_value = "%f + 
%fj"%(complex_data[0], complex_data[1])
+                       else: new_value = "%f"%(complex_data[0],)
+                       while not MUTEX.testandset(): pass      #try to lock 
repeatedly until lock is aquired                           
+                       # write the new value #         
+                       Variables.unregister(self.var_key)
+                       Variables.register(self.var_key, new_value)             
                
+                       #       parse the call backs    #                       
        
+                       self.fg.parse_callbacks()       
+                       MUTEX.unlock()
                
 def VariableSink(sb):
        type = Enum(all_choices, 1)
@@ -142,20 +138,17 @@
        sb.add_param('Type', type, False, type=True)
        sb.add_param('Variable', VariableKeySelector()) 
        sb.add_param('Samp Rate', Float(default_samp_rate))
-       sb.add_param('Queue Limit', Int(2, min=1))
        sb.set_docs('''\
 A thread reads a message sink and writes to the variable. \
 The variable cannot have a range. \
 The variable must be specified using its name without the "$" symbol. \
 The variable sink has a throttle automatically attatched to it at runtime to 
save the CPU.''') 
-       def make(fg, type, var_key, samp_rate, msgq_limit):
-               msgq = gr.msg_queue(msgq_limit.parse())
-               block = gr.message_sink(type.parse().get_num_bytes(), msgq, 
True)
+       def make(fg, type, var_key, samp_rate):
+               msgq = gr.msg_queue(DEFAULT_QUEUE_LIMIT)
+               item_size = type.parse().get_num_bytes()
+               block = gr.message_sink(item_size, msgq, True)
                var_sink_thread = VariableSinkThread(fg, var_key.parse(), msgq)
-               th = gr.throttle(type.parse().get_num_bytes(), 
samp_rate.parse())
-               fg.connect(th, block)
-               return th
-       return sb, make
+               return throttle(fg, item_size, samp_rate.parse(), block, True)
+       return sb, make 
        
-       
        
\ No newline at end of file





reply via email to

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