commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3514 - gnuradio/branches/developers/trondeau/wip2/gnu


From: trondeau
Subject: [Commit-gnuradio] r3514 - gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2
Date: Sun, 10 Sep 2006 16:32:02 -0600 (MDT)

Author: trondeau
Date: 2006-09-10 16:32:02 -0600 (Sun, 10 Sep 2006)
New Revision: 3514

Added:
   
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_rx.py
Modified:
   
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_tx.py
   
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/fusb_options.py
   
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/receive_path.py
   
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/transmit_path.py
Log:
Refactoring digital mod receiver: need to check consistency; need to work on 
tunnel.py

Added: 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_rx.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_rx.py
                           (rev 0)
+++ 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_rx.py
   2006-09-10 22:32:02 UTC (rev 3514)
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+#
+# Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+# 
+
+from gnuradio import gr, gru, blks
+from gnuradio import usrp
+from gnuradio import eng_notation
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+
+import random
+import struct
+
+# from current dir
+from receive_path import receive_path
+import fusb_options
+
+#import os
+#print os.getpid()
+#raw_input('Attach and press enter')
+
+
+class my_graph(gr.flow_graph):
+
+    def __init__(self, demod_class, rx_callback, options):
+        gr.flow_graph.__init__(self)
+        self.rxpath = receive_path(self, demod_class, rx_callback, options)
+
+# /////////////////////////////////////////////////////////////////////////////
+#                                   main
+# /////////////////////////////////////////////////////////////////////////////
+
+global n_rcvd, n_right
+
+def main():
+    global n_rcvd, n_right
+
+    n_rcvd = 0
+    n_right = 0
+    
+    def rx_callback(ok, payload):
+        global n_rcvd, n_right
+        (pktno,) = struct.unpack('!H', payload[0:2])
+        n_rcvd += 1
+        if ok:
+            n_right += 1
+
+        print "ok = %r  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
+            ok, pktno, n_rcvd, n_right)
+
+    # Create Options Parser:
+    parser = OptionParser (option_class=eng_option)
+    parser.add_option("-m", "--modulation", type="choice", 
choices=blks.demodulators.keys(),
+                      default='bpsk',
+                      help="Set modulation type %s" % blks.demodulators.keys())
+    mod_grp = parser.add_option_group("Modulation")
+    for mod in blks.demodulators.values():
+        mod.add_options(mod_grp)
+    receive_path.add_options(parser)
+    fusb_options.add_options(parser)
+    (options, args) = parser.parse_args ()
+
+    if len(args) != 0:
+        parser.print_help()
+        sys.exit(1)
+
+    if options.freq < 1e6:
+        options.freq *= 1e6
+
+    # build the graph
+    fg = my_graph(blks.demodulators[options.modulation], rx_callback, options)
+
+    r = gr.enable_realtime_scheduling()
+    if r != gr.RT_OK:
+        print "Warning: Failed to enable realtime scheduling."
+
+    fg.start()        # start flow graph
+    fg.wait()         # wait for it to finish
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass

Modified: 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_tx.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_tx.py
   2006-09-10 19:21:33 UTC (rev 3513)
+++ 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/benchmark_tx.py
   2006-09-10 22:32:02 UTC (rev 3514)
@@ -26,7 +26,7 @@
 from gnuradio.eng_option import eng_option
 from optparse import OptionParser
 
-import random, time, struct, sys, optparse
+import random, time, struct, sys
 
 # from current dir
 from transmit_path import transmit_path
@@ -62,21 +62,13 @@
                       help="set megabytes to transmit [default=%default]")
     parser.add_option("","--discontinuous", action="store_true", default=False,
                       help="enable discontinous transmission (bursts of 5 
packets)")
-
-    transmit_path.add_options(parser)
-
     parser.add_option("-m", "--modulation", type="choice", 
choices=blks.modulators.keys(),
                       default='dbpsk',
                       help="Set modulation type %s" % blks.modulators.keys())
-
-    # Print out all (unique) options from the modulators
-    # FIXME: work on trying to get a heirarchy of a per-modulation list
+    mod_grp = parser.add_option_group("Modulation")
     for mod in blks.modulators.values():
-        try:
-            mod.add_options(parser)
-        except optparse.OptionConflictError:
-            pass
-
+        mod.add_options(mod_grp)
+    transmit_path.add_options(parser)
     fusb_options.add_options(parser)
     (options, args) = parser.parse_args ()
 

Modified: 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/fusb_options.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/fusb_options.py
   2006-09-10 19:21:33 UTC (rev 3513)
+++ 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/fusb_options.py
   2006-09-10 22:32:02 UTC (rev 3514)
@@ -25,7 +25,8 @@
     
     @param parser: instance of OptionParser
     """
-    parser.add_option("-B", "--fusb-block-size", type="int", default=0,
-                      help="specify fast usb block size [default=%default]")
-    parser.add_option("-N", "--fusb-nblocks", type="int", default=0,
-                      help="specify number of fast usb blocks 
[default=%default]")
+    fusb_grp = parser.add_option_group("Fast USB")
+    fusb_grp.add_option("-B", "--fusb-block-size", type="int", default=0,
+                        help="specify fast usb block size [default=%default]")
+    fusb_grp.add_option("-N", "--fusb-nblocks", type="int", default=0,
+                        help="specify number of fast usb blocks 
[default=%default]")

Modified: 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/receive_path.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/receive_path.py
   2006-09-10 19:21:33 UTC (rev 3513)
+++ 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/receive_path.py
   2006-09-10 22:32:02 UTC (rev 3514)
@@ -22,6 +22,7 @@
 
 from gnuradio import gr, gru, blks
 from gnuradio import usrp
+from gnuradio import eng_notation
 
 # from current dir
 from pick_bitrate import pick_rx_bitrate
@@ -31,52 +32,53 @@
 # /////////////////////////////////////////////////////////////////////////////
 
 class receive_path(gr.hier_block):
-    def __init__(self, fg, demod_class, rx_subdev_spec,
-                 bitrate, decim, spb,
-                 rx_callback, options, demod_kwargs):
+    def __init__(self, fg, demodulator, rx_callback, options, verbose=True):
 
-        self.u = usrp.source_c (fusb_block_size=options.fusb_block_size,
-                                fusb_nblocks=options.fusb_nblocks)
-        adc_rate = self.u.adc_rate()
+        self._center_freq     = options.freq            # tranmitter's center 
frequency
+        self._gain            = options.gain            # transmitter's 
digital gain
+        self._rx_subdev_spec  = options.rx_subdev_spec  # daughterboard to use
+        self._bitrate         = options.bitrate         # desired bit rate
+        self._decim           = options.decim           # Decimating rate for 
the USRP (prelim)
+        self._spb             = options.spb             # desired samples/baud
+        self._fusb_block_size = options.fusb_block_size # usb info for USRP
+        self._fusb_nblocks    = options.fusb_nblocks    # usb info for USRP
 
-        (self._bitrate, self._spb, self._decim) = \
-            pick_rx_bitrate(bitrate, demod_class.bits_per_baud(), spb, decim, 
adc_rate)
+        self._demodulator     = demodulator             # set demodulator class
+        self._rx_callback     = rx_callback             # callback function 
from lower layesr
 
-        self.u.set_decim_rate(self._decim)
+        # Create the USRP source to get the data
+        self.set_usrp_source()
+        
+        # Create filter to get actual channel we want
         sw_decim = 1
-
-        if rx_subdev_spec is None:
-            rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
-        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
-        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
-
-        self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec))
-
-        # Create filter to get actual channel we want
         chan_coeffs = gr.firdes.low_pass (1.0,                  # gain
                                           sw_decim * self._spb, # sampling rate
                                           1.0,                  # midpoint of 
trans. band
                                           0.1,                  # width of 
trans. band
                                           gr.firdes.WIN_HANN)   # filter type 
 
-        print "len(rx_chan_coeffs) =", len(chan_coeffs)
-
         # Decimating Channel filter
         # complex in and out, float taps
         self.chan_filt = gr.fft_filter_ccc(sw_decim, chan_coeffs)
         #self.chan_filt = gr.fir_filter_ccf(sw_decim, chan_coeffs)
 
+        # Get demod_kwargs
+        demod_kwargs = blks.kwargs(self._demodulator, [self._spb, self._decim, 
self._bitrate])
+        demod_kwargs['debug']=True
+
         # receiver
         self.packet_receiver = \
             blks.demod_pkts(fg,
-                            demod_class(fg, spb=self._spb, **demod_kwargs),
+                            self._demodulator(fg, **demod_kwargs),
                             access_code=None,
-                            callback=rx_callback,
+                            callback=self._rx_callback,
                             threshold=-1)
 
-        fg.connect(self.u, self.chan_filt, self.packet_receiver)
-        gr.hier_block.__init__(self, fg, None, None)
-
+        ok = self.set_freq(self._center_freq)
+        if not ok:
+            print "Failed to set Rx frequency to %s" % 
(eng_notation.num_to_str(self._center_freq))
+            raise SystemExit
+    
         g = self.subdev.gain_range()
         #self.set_gain((g[0] + g[1])/2)        # set gain to midpoint
         self.set_gain(g[1])                    # set gain to max
@@ -88,6 +90,39 @@
         self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
         fg.connect(self.chan_filt, self.probe)
 
+        # Display some information about the setup
+        if verbose:
+            self.verbosity()
+            
+        fg.connect(self.u, self.chan_filt, self.packet_receiver)
+        gr.hier_block.__init__(self, fg, None, None)
+
+    def set_usrp_source(self):
+        self.u = usrp.source_c (fusb_block_size=self._fusb_block_size,
+                                fusb_nblocks=self._fusb_nblocks)
+        adc_rate = self.u.adc_rate()
+
+        self.set_bitrate(adc_rate)
+
+        self.u.set_decim_rate(self._decim)
+
+        # determine the daughterboard subdevice we're using
+        if self._rx_subdev_spec is None:
+            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
+        self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec)
+
+        self.u.set_mux(usrp.determine_rx_mux_value(self.u, 
self._rx_subdev_spec))
+
+    def set_bitrate(self, adc_rate):
+        """
+        determine best set of bitrate, spb, and decim from desired info
+        @param dac_rate: DAC rate of USRP
+        @type dac_rate: int
+        """
+        (self._bitrate, self._spb, self._decim) = \
+            pick_rx_bitrate(self._bitrate, self._demodulator.bits_per_baud(), \
+                            self._spb, self._decim, adc_rate)
+
     def set_freq(self, target_freq):
         """
         Set the center frequency we're interested in.
@@ -107,6 +142,9 @@
         return False
 
     def set_gain(self, gain):
+        """
+        Sets the analog gain in the USRP
+        """
         if gain is None:
             r = self.subdev.gain_range()
             gain = (r[0] + r[1])/2               # set gain to midpoint
@@ -125,7 +163,6 @@
     def decim(self):
         return self._decim
 
-
     def carrier_sensed(self):
         """
         Return True if we think carrier is present.
@@ -148,3 +185,35 @@
         """
         self.probe.set_threshold(threshold_in_db)
     
+    def verbosity(self):
+        """
+        Prints information about the receive path
+        """
+        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
+        print "modulation: %s" % (self._demodulator.__name__)
+        print "bitrate:    %sb/sec" % (eng_notation.num_to_str(self._bitrate))
+        print "spb:        %3d" % (self._spb)
+        print "decim:      %3d" % (self._decim)
+        print "Center Frequency: %s" % 
(eng_notation.num_to_str(self._center_freq))
+        
+    def add_options(parser):
+        """
+        Adds receiver-specific options to the Options Parser
+        """
+        rx_grp = parser.add_option_group("Receiver Path")
+        rx_grp.add_option("-R", "--rx-subdev-spec", type="subdev", 
default=None,
+                          help="select USRP Rx side A or B")
+        rx_grp.add_option("-f", "--freq", type="eng_float", default=423.1e6,
+                          help="set Tx and Rx frequency to FREQ 
[default=%default]",
+                          metavar="FREQ")
+        rx_grp.add_option("-r", "--bitrate", type="eng_float", default=None,
+                          help="specify bitrate.  spb and interp will be 
derived.")
+        rx_grp.add_option("-S", "--spb", type="int", default=None,
+                          help="set samples/baud [default=%default]")
+        rx_grp.add_option("-d", "--decim", type="intx", default=None,
+                          help="set fpga decimation rate to DECIM 
[default=%default]")
+        rx_grp.add_option("-g", "--gain", type="eng_float", default=100.0,
+                          help="transmitter gain [default=%default]")
+    # Make a static method to call before instantiation
+    add_options = staticmethod(add_options)
+

Modified: 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/transmit_path.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/transmit_path.py
  2006-09-10 19:21:33 UTC (rev 3513)
+++ 
gnuradio/branches/developers/trondeau/wip2/gnuradio-examples/python/gmsk2/transmit_path.py
  2006-09-10 22:32:02 UTC (rev 3514)
@@ -36,7 +36,7 @@
         See below for what options should hold
         '''
 
-        self._center_freq     = options.freq            # tranmitter's carrier 
frequency
+        self._center_freq     = options.freq            # tranmitter's center 
frequency
         self._gain            = options.gain            # transmitter's 
digital gain
         self._tx_subdev_spec  = options.tx_subdev_spec  # daughterboard to use
         self._bitrate         = options.bitrate         # desired bit rate
@@ -76,12 +76,7 @@
 
         # Display some information about the setup
         if verbose:
-            print "modulation: %s" % (self._modulator.__name__)
-            print "bitrate:    %sb/sec" % 
(eng_notation.num_to_str(self._bitrate))
-            print "spb:        %3d" % (self._spb)
-            print "interp:     %3d" % (self._interp)
-            print "Center Frequency: %s" % 
(eng_notation.num_to_str(self._center_freq))
-            print "Using TX d'board %s" % (self.subdev.side_and_name(),)
+            self.verbosity()
 
         # Create and setup transmit path flow graph
         fg.connect(self.packet_transmitter, self.amp, self.u)
@@ -107,13 +102,15 @@
         self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec)
 
     def set_bitrate(self, dac_rate):
-        # determine best set of bitrate, spb, and interp from desired info
+        """
+        determine best set of bitrate, spb, and interp from desired info
+        @param dac_rate: DAC rate of USRP
+        @type dac_rate: int
+        """
         (self._bitrate, self._spb, self._interp) = \
             pick_tx_bitrate(self._bitrate, self._modulator.bits_per_baud(), \
                             self._spb, self._interp, dac_rate)
 
-        print self._spb
-
     def set_freq(self, target_freq):
         """
         Set the center frequency we're interested in.
@@ -133,13 +130,22 @@
         return False
 
     def set_gain(self, gain):
+        """
+        Sets the analog gain in the USRP
+        """
         self.gain = gain
         self.subdev.set_gain(gain)
 
     def set_auto_tr(self, enable):
+        """
+        Turns on auto transmit/receive of USRP daughterboard (if exits; else 
ignored)
+        """
         return self.subdev.set_auto_tr(enable)
         
     def send_pkt(self, payload='', eof=False):
+        """
+        Calls the transmitter method to send a packet
+        """
         return self.packet_transmitter.send_pkt(payload, eof)
         
     def bitrate(self):
@@ -151,22 +157,34 @@
     def interp(self):
         return self._interp
 
+    def verbosity(self):
+        """
+        Prints information about the transmit path
+        """
+        print "modulation: %s" % (self._modulator.__name__)
+        print "bitrate:    %sb/sec" % (eng_notation.num_to_str(self._bitrate))
+        print "spb:        %3d" % (self._spb)
+        print "interp:     %3d" % (self._interp)
+        print "Center Frequency: %s" % 
(eng_notation.num_to_str(self._center_freq))
+        print "Using TX d'board %s" % (self.subdev.side_and_name(),)
+        
     def add_options(parser):
         """
         Adds transmitter-specific options to the Options Parser
         """
-        parser.add_option("-T", "--tx-subdev-spec", type="subdev", 
default=None,
+        tx_grp = parser.add_option_group("Transmit Path")
+        tx_grp.add_option("-T", "--tx-subdev-spec", type="subdev", 
default=None,
                           help="select USRP Tx side A or B")
-        parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
+        tx_grp.add_option("-f", "--freq", type="eng_float", default=423.1e6,
                           help="set Tx and Rx frequency to FREQ 
[default=%default]",
                           metavar="FREQ")
-        parser.add_option("-r", "--bitrate", type="eng_float", default=None,
+        tx_grp.add_option("-r", "--bitrate", type="eng_float", default=None,
                           help="specify bitrate.  spb and interp will be 
derived.")
-        parser.add_option("-S", "--spb", type="int", default=None,
+        tx_grp.add_option("-S", "--spb", type="int", default=None,
                           help="set samples/baud [default=%default]")
-        parser.add_option("-i", "--interp", type="intx", default=None,
+        tx_grp.add_option("-i", "--interp", type="intx", default=None,
                           help="set fpga interpolation rate to INTERP 
[default=%default]")
-        parser.add_option("-g", "--gain", type="eng_float", default=100.0,
+        tx_grp.add_option("-g", "--gain", type="eng_float", default=100.0,
                           help="transmitter gain [default=%default]")
     # Make a static method to call before instantiation
     add_options = staticmethod(add_options)





reply via email to

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