commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3903 - in gnuradio/branches/developers/eb/binstats/gn


From: eb
Subject: [Commit-gnuradio] r3903 - in gnuradio/branches/developers/eb/binstats/gnuradio-core/src: lib/general python/gnuradio/gr
Date: Mon, 30 Oct 2006 18:20:30 -0700 (MST)

Author: eb
Date: 2006-10-30 18:20:30 -0700 (Mon, 30 Oct 2006)
New Revision: 3903

Modified:
   
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_feval.i
   
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py
Log:
gr_feval now properly working when calling into Python

Modified: 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_feval.i
===================================================================
--- 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_feval.i
   2006-10-30 22:43:22 UTC (rev 3902)
+++ 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_feval.i
   2006-10-31 01:20:30 UTC (rev 3903)
@@ -81,7 +81,7 @@
 /*
  * These are the real C++ base classes, however we don't want these exposed.
  */
-// %ignore gr_feval_dd;
+%ignore gr_feval_dd;
 class gr_feval_dd
 {
 protected:
@@ -94,7 +94,7 @@
   virtual double calleval(double x);
 };
 
-// %ignore gr_feval_cc;
+%ignore gr_feval_cc;
 class gr_feval_cc
 {
 protected:
@@ -107,7 +107,7 @@
   virtual gr_complex calleval(gr_complex x);
 };
 
-// %ignore gr_feval_ll;
+%ignore gr_feval_ll;
 class gr_feval_ll
 {
 protected:
@@ -120,7 +120,7 @@
   virtual long calleval(long x);
 };
 
-// %ignore gr_feval;
+%ignore gr_feval;
 class gr_feval
 {
 protected:
@@ -136,7 +136,6 @@
 /*
  * These are the ones to derive from in Python.  They have the magic shim
  * that ensures that we're holding the Python GIL when we enter Python land...
- * [ You really don't have to understand this.  Trust me, it works ;) ]
  */
 
 %inline %{
@@ -147,10 +146,7 @@
   double calleval(double x)
   {
     ensure_py_gil_state _lock;
-    std::cerr << "gr_py_feval_dd!\n";
-    double t = eval(x);
-    std::cerr << "eval returned " << t << std::endl;
-    return t;
+    return eval(x);
   }
 };
 

Modified: 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py
===================================================================
--- 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py
  2006-10-30 22:43:22 UTC (rev 3902)
+++ 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py
  2006-10-31 01:20:30 UTC (rev 3903)
@@ -24,6 +24,11 @@
 import random
 import struct
 
+#import os
+#print "pid =", os.getpid()
+#raw_input("Attach gdb and press return...")
+
+
 class counter(gr.feval_dd):
     def __init__(self, step_size=1):
         gr.feval_dd.__init__(self)
@@ -37,6 +42,46 @@
         return t
         
 
+class counter3(gr.feval_dd):
+    def __init__(self, f, step_size):
+        gr.feval_dd.__init__(self)
+        self.f = f
+        self.step_size = step_size
+        self.count = 0
+
+    def eval(self, input):
+        try:
+            #print "eval: self.count =", self.count
+            t = self.count
+            self.count = self.count + self.step_size
+            self.f(self.count)
+        except Exception, e:
+            print "Exception: ", e
+        return t
+        
+def foobar3(new_t):
+    #print "foobar3: new_t =", new_t
+    pass
+
+
+class counter4(gr.feval_dd):
+    def __init__(self, obj_instance, step_size):
+        gr.feval_dd.__init__(self)
+        self.obj_instance = obj_instance
+        self.step_size = step_size
+        self.count = 0
+
+    def eval(self, input):
+        try:
+            #print "eval: self.count =", self.count
+            t = self.count
+            self.count = self.count + self.step_size
+            self.obj_instance.foobar4(self.count)
+        except Exception, e:
+            print "Exception: ", e
+        return t
+        
+
 class parse_msg(object):
     def __init__(self, msg):
         self.center_freq = msg.arg1()
@@ -114,6 +159,68 @@
             self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data)
 
 
+
+    def test_003(self):
+        vlen = 4
+        tune = counter3(foobar3, 1)
+        tune_delay = 1
+        dwell_delay = 2
+        msgq = gr.msg_queue()
+
+        src_data = tuple([float(x) for x in
+                          ( 1,  2,  3,  4,
+                            9,  6, 11,  8,
+                            5, 10,  7, 12,
+                            13, 14, 15, 16
+                            )])
+
+        expected_results = tuple([float(x) for x in
+                                  ( 9, 10, 11, 12)])
+                            
+        src = gr.vector_source_f(src_data, False)
+        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
+        stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay)
+        self.fg.connect(src, s2v, stats)
+        self.fg.run()
+        self.assertEqual(1, msgq.count())
+        for i in range(1):
+            m = parse_msg(msgq.delete_head())
+            #print "m =", m.center_freq, m.data
+            self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data)
+
+
+    def foobar4(self, new_t):
+        #print "foobar4: new_t =", new_t
+        pass
+        
+    def test_004(self):
+        vlen = 4
+        tune = counter4(self, 1)
+        tune_delay = 1
+        dwell_delay = 2
+        msgq = gr.msg_queue()
+
+        src_data = tuple([float(x) for x in
+                          ( 1,  2,  3,  4,
+                            9,  6, 11,  8,
+                            5, 10,  7, 12,
+                            13, 14, 15, 16
+                            )])
+
+        expected_results = tuple([float(x) for x in
+                                  ( 9, 10, 11, 12)])
+                            
+        src = gr.vector_source_f(src_data, False)
+        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
+        stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay)
+        self.fg.connect(src, s2v, stats)
+        self.fg.run()
+        self.assertEqual(1, msgq.count())
+        for i in range(1):
+            m = parse_msg(msgq.delete_head())
+            #print "m =", m.center_freq, m.data
+            self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data)
+
+
 if __name__ == '__main__':
    gr_unittest.main ()
-        





reply via email to

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