commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] gnuradio-examples ChangeLog python/gmsk2/README...


From: Eric Blossom
Subject: [Commit-gnuradio] gnuradio-examples ChangeLog python/gmsk2/README...
Date: Wed, 21 Jun 2006 00:55:02 +0000

CVSROOT:        /sources/gnuradio
Module name:    gnuradio-examples
Changes by:     Eric Blossom <eb>       06/06/21 00:55:01

Modified files:
        .              : ChangeLog 
        python/gmsk2   : README benchmark_gmsk_rx.py 
                         benchmark_gmsk_tx.py receive_path.py 
                         transmit_path.py 
Added files:
        python/gmsk2   : tunnel.py 
Removed files:
        python/gmsk2   : tunnel_ip_null_mac.py 

Log message:
        Refactored all to use modulation independent mod_pkts and demod_pkts.
        Removed "Null MAC" code and example in tunnel_ip_null_mac.py. 
        Replaced with tunnel.py which uses a carrier sense MAC, and uses
        the TAP driver to create a virtual ethernet.
        
        Seems to perform reasonably.  With bitrate set to 500k, moves an 
aggregate 
        of about 50KB/sec over TCP.  This was measured scp'ing big files from 
both 
        nodes simultaneously.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/ChangeLog?cvsroot=gnuradio&r1=1.64&r2=1.65
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/README?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/benchmark_gmsk_rx.py?cvsroot=gnuradio&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/benchmark_gmsk_tx.py?cvsroot=gnuradio&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/receive_path.py?cvsroot=gnuradio&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/transmit_path.py?cvsroot=gnuradio&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/tunnel.py?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/gmsk2/tunnel_ip_null_mac.py?cvsroot=gnuradio&r1=1.13&r2=0

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnuradio/gnuradio-examples/ChangeLog,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -b -r1.64 -r1.65
--- ChangeLog   16 Jun 2006 06:55:34 -0000      1.64
+++ ChangeLog   21 Jun 2006 00:55:01 -0000      1.65
@@ -1,3 +1,20 @@
+2006-06-20  Eric Blossom  <address@hidden>
+
+       * python/gmsk2/receive_path.py, python/gmsk2/transmit_path.py,
+       benchmark_gmsk_{tx,rx}.py: refactored to use modulation
+       independent pkt.py code.  Lays the foundation for a single set of
+       tools that can exercise all modulations.  More work required to
+       meet that goal, but we're closing in.
+
+       * python/gmsk2/tunnel.py: refactored version of
+       tunnel_ip_null_mac.  This creates a virtual ethernet inteface
+       using the TAP driver, and then tunnels packets across the air
+       using GMSK and a simple carrier sense MAC.  Fixed problem with
+       truncation of large packets which was leading to stalls.
+       
+       * python/gmsk2/tunnel_ip_null_mac.py: removed.  Replaced with
+       tunnel.py
+
 2006-06-15  Eric Blossom  <address@hidden>
 
        * python/usrp/usrp_fft.py (app_flow_graph.set_decim): added

Index: python/gmsk2/README
===================================================================
RCS file: /sources/gnuradio/gnuradio-examples/python/gmsk2/README,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- python/gmsk2/README 9 Dec 2005 20:22:54 -0000       1.1
+++ python/gmsk2/README 21 Jun 2006 00:55:01 -0000      1.2
@@ -35,18 +35,18 @@
 second.  This is useful for ensuring that all the receiver control
 loops lock up fast enough.
 
-* tunnel_ip_null_mac.py:  This program provides a framework for
-building your own MACs.  It creates a "TUN" interface in the kernel,
-typically gr0, and sends and receives IP packets through it.  See
+* tunnel.py: This program provides a framework for building your own
+MACs.  It creates a "TAP" interface in the kernel, typically gr0,
+and sends and receives ethernet frames through it.  See
 /usr/src/linux/Documentation/networking/tuntap.txt and/or Google for 
-"universal tun tap".  The Linux kernel includes the tun module.  You
-may have to "modprobe tun" if it's not loaded by default.  If
-/dev/net/tun doesn't exist, try "modprobe tun".
+"universal tun tap".  The Linux 2.6 kernel includes the tun module, you
+don't have to build it.  You may have to "modprobe tun" if it's not
+loaded by default.  If /dev/net/tun doesn't exist, try "modprobe tun".
 
 To run this program you'll need to be root or running with the
 appropriate capability to open the tun interface.  You'll need to fire
 up two copies on different machines.  Once each is running you'll need
-to ifconfig the gr0 interface and add an appropriate route.
+to ifconfig the gr0 interface to set the IP address.
 
 This will allow two machines to talk, but anything beyond the two
 machines depends on your networking setup.  Left as an exercise...
@@ -54,30 +54,28 @@
 On machine A:
 
   $ su
-  # ./tunnel_ip_null_mac.py -v
+  # ./tunnel.py --freq 423.0M --bitrate 500k
   # # in another window on A, also as root...
   # ifconfig gr0 10.10.10.1
-  # route add -host 10.10.10.2 gr0
+
 
 On machine B:
 
   $ su
-  # ./tunnel_ip_null_mac.py -v
+  # ./tunnel.py --freq 423.0M --bitrate 500k
   # # in another window on B, also as root...
   # ifconfig gr0 10.10.10.2
-  # route add -host 10.10.10.1 gr0
 
 Now, on machine A you shold be able to ping machine B:
 
   $ ping 10.10.10.2
 
 and you should see some output for each packet in the
-tunnel_ip_null_mac window if you used the -v option.
+tunnel.py window if you used the -v option.
 
 Likewise, on machine B:
 
   $ ping 10.10.10.1
 
-TCP doesn't work so well across this since there's no MAC, and both
-sides keep stepping on each other.  It wouldn't be hard to implement a
-carrier sense MAC, and that should probably be the next step.
+This now uses a carrier sense MAC, so you should be able to ssh
+between the machines, web browse, etc.

Index: python/gmsk2/benchmark_gmsk_rx.py
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-examples/python/gmsk2/benchmark_gmsk_rx.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- python/gmsk2/benchmark_gmsk_rx.py   19 Jun 2006 20:59:06 -0000      1.20
+++ python/gmsk2/benchmark_gmsk_rx.py   21 Jun 2006 00:55:01 -0000      1.21
@@ -40,10 +40,12 @@
 
 class my_graph(gr.flow_graph):
 
-    def __init__(self, rx_subdev_spec, bitrate, decim_rate, spb, rx_callback, 
log, options):
+    def __init__(self, demod_class, rx_subdev_spec,
+                 bitrate, decim_rate, spb, rx_callback, options):
         gr.flow_graph.__init__(self)
-        self.rxpath = receive_path(self, rx_subdev_spec, bitrate, decim_rate,
-                                   spb, rx_callback, log, options)
+        self.rxpath = receive_path(self, demod_class, rx_subdev_spec,
+                                   bitrate, decim_rate, spb,
+                                   rx_callback, options)
 
 # /////////////////////////////////////////////////////////////////////////////
 #                                   main
@@ -74,13 +76,11 @@
                        help="set Rx frequency to FREQ [default=%default]", 
metavar="FREQ")
     parser.add_option("-r", "--bitrate", type="eng_float", default=None,
                       help="specify bitrate.  spb and interp will be derived.")
+    parser.add_option("-g", "--rx-gain", type="eng_float", default=27,
+                      help="set rx gain")
     parser.add_option("-S", "--spb", type="int", default=None, help="set 
samples/baud [default=%default]")
     parser.add_option("-d", "--decim", type="intx", default=None,
                       help="set fpga decim rate to DECIM [default=%default]")
-    parser.add_option("-g", "--gain", type="eng_float", default=27,
-                      help="set rx gain")
-    parser.add_option("","--log", action="store_true", default=False,
-                      help="enable diagnostic logging")
     fusb_options.add_options(parser)
     (options, args) = parser.parse_args ()
 
@@ -92,8 +92,9 @@
         options.freq *= 1e6
 
     # build the graph
-    fg = my_graph(options.rx_subdev_spec, options.bitrate,
-                  options.decim, options.spb, rx_callback, options.log,
+    fg = my_graph(blks.gmsk2_demod,
+                  options.rx_subdev_spec, options.bitrate,
+                  options.decim, options.spb, rx_callback,
                   options)
 
     print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.rxpath.bitrate()),)
@@ -105,6 +106,7 @@
         print "Failed to set Rx frequency to %s" % 
(eng_notation.num_to_str(options.freq),)
         raise SystemExit
     
+    fg.rxpath.set_gain(options.rx_gain)
     print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", 
fg.rxpath.gain
 
     r = gr.enable_realtime_scheduling()

Index: python/gmsk2/benchmark_gmsk_tx.py
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-examples/python/gmsk2/benchmark_gmsk_tx.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- python/gmsk2/benchmark_gmsk_tx.py   19 Jun 2006 20:59:06 -0000      1.16
+++ python/gmsk2/benchmark_gmsk_tx.py   21 Jun 2006 00:55:01 -0000      1.17
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright 2005 Free Software Foundation, Inc.
+# Copyright 2005,2006 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -42,10 +42,11 @@
 
 class my_graph(gr.flow_graph):
 
-    def __init__(self, tx_subdev_spec, bitrate, interp_rate, spb, bt, options):
+    def __init__(self, mod_class, tx_subdev_spec,
+                 bitrate, interp_rate, spb, bt, options):
         gr.flow_graph.__init__(self)
-        self.txpath = transmit_path(self, tx_subdev_spec, bitrate, 
interp_rate, spb,
-                                    bt, False, options)
+        self.txpath = transmit_path(self, mod_class, tx_subdev_spec,
+                                    bitrate, interp_rate, spb, bt, options)
 
 
 # /////////////////////////////////////////////////////////////////////////////
@@ -90,8 +91,10 @@
     pkt_size = int(options.size)
 
     # build the graph
-    fg = my_graph(options.tx_subdev_spec, options.bitrate, options.interp,
-                  options.spb, options.bt, options)
+    fg = my_graph(blks.gmsk2_mod,
+                  options.tx_subdev_spec,
+                  options.bitrate, options.interp, options.spb,
+                  options.bt, options)
 
     print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
     print "spb:     %3d" % (fg.txpath.spb(),)

Index: python/gmsk2/receive_path.py
===================================================================
RCS file: /sources/gnuradio/gnuradio-examples/python/gmsk2/receive_path.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- python/gmsk2/receive_path.py        20 Jun 2006 06:15:37 -0000      1.11
+++ python/gmsk2/receive_path.py        21 Jun 2006 00:55:01 -0000      1.12
@@ -31,29 +31,30 @@
 # /////////////////////////////////////////////////////////////////////////////
 
 class receive_path(gr.hier_block):
-    def __init__(self, fg, subdev_spec, bitrate, decim, spb, rx_callback,
-                 log_p, options):
+    def __init__(self, fg, demod_class, rx_subdev_spec,
+                 bitrate, decim, spb, rx_callback, options):
 
-        gain_mu = 0.03     # default
-        #gain_mu = 0.48    
-        threshold = -1     # use system default
+        # FIXME add this as a parameter
+        demod_kwargs = {
+            'gain_mu' : 0.03,     # default
+            }
 
         self.u = usrp.source_c (fusb_block_size=options.fusb_block_size,
                                 fusb_nblocks=options.fusb_nblocks)
         adc_rate = self.u.adc_rate()
 
-        (self._bitrate, self._spb, self._decim) = pick_rx_bitrate(bitrate, 1, 
spb,
-                                                                  decim, 
adc_rate)
+        (self._bitrate, self._spb, self._decim) = \
+            pick_rx_bitrate(bitrate, demod_class.bits_per_baud(), spb, decim, 
adc_rate)
 
         self.u.set_decim_rate(self._decim)
         sw_decim = 1
 
-        if subdev_spec is None:
-            subdev_spec = usrp.pick_rx_subdevice(self.u)
-        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
+        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, subdev_spec))
+        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
@@ -70,9 +71,12 @@
         #self.chan_filt = gr.fir_filter_ccf(sw_decim, chan_coeffs)
 
         # receiver
-        self.packet_receiver = blks.gmsk2_demod_pkts(fg, callback=rx_callback, 
spb=self._spb,
-                                                     gain_mu=gain_mu,
-                                                     threshold=threshold)
+        self.packet_receiver = \
+            blks.demod_pkts(fg,
+                            demod_class(fg, spb=self._spb, **demod_kwargs),
+                            access_code=None,
+                            callback=rx_callback,
+                            threshold=-1)
 
         fg.connect(self.u, self.chan_filt, self.packet_receiver)
         gr.hier_block.__init__(self, fg, None, None)
@@ -82,14 +86,11 @@
         self.set_gain(g[1])                    # set gain to max
         self.set_auto_tr(True)                 # enable Auto Transmit/Receive 
switching
 
-        if log_p:
-            self._add_logging(fg)
-
         # Carrier Sensing Blocks
         alpha = 0.001
         thresh = 30   # in dB, will have to adjust
         self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
-        fg.connect(self.chan_filt,self.probe)
+        fg.connect(self.chan_filt, self.probe)
 
     def set_freq(self, target_freq):
         """
@@ -101,12 +102,10 @@
         Tuning is a two step process.  First we ask the front-end to
         tune as close to the desired frequency as it can.  Then we use
         the result of that operation and our target_frequency to
-        determine the value for the digital up converter.  Finally, we could
-        feed any residual_freq to the s/w freq translater.
+        determine the value for the digital up converter.
         """
         r = self.u.tune(0, self.subdev, target_freq)
         if r:
-            # Could use residual_freq in s/w freq translator
             return True
 
         return False
@@ -130,16 +129,26 @@
     def decim(self):
         return self._decim
 
+
     def carrier_sensed(self):
         """
-        Return True if we think carrier is present
+        Return True if we think carrier is present.
         """
-        #return self.packet_receiver.carrier_sensed()
         #return self.probe.level() > X
         return self.probe.unmuted()
     
+    def carrier_threshold(self):
+        """
+        Return current setting in dB.
+        """
+        return self.probe.threshold()
     
-    def _add_logging(self, fg):
-        fg.connect(self.packet_receiver.gmsk_demod.freq_offset,
-                   gr.file_sink(gr.sizeof_float, "freq_offset.dat"))
+    def set_carrier_threshold(self, threshold_in_db):
+        """
+        Set carrier threshold.
+
+        @param threshold_in_db: set detection threshold
+        @type threshold_in_db:  float (dB)
+        """
+        self.probe.set_threshold(threshold_in_db)
 

Index: python/gmsk2/transmit_path.py
===================================================================
RCS file: /sources/gnuradio/gnuradio-examples/python/gmsk2/transmit_path.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- python/gmsk2/transmit_path.py       19 Jun 2006 22:55:38 -0000      1.8
+++ python/gmsk2/transmit_path.py       21 Jun 2006 00:55:01 -0000      1.9
@@ -1,5 +1,5 @@
 #
-# Copyright 2005 Free Software Foundation, Inc.
+# Copyright 2005,2006 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -30,8 +30,13 @@
 # /////////////////////////////////////////////////////////////////////////////
 
 class transmit_path(gr.hier_block):
-    def __init__(self, fg, subdev_spec, bitrate, interp, spb, bt,
-                 log_p, options):
+    def __init__(self, fg, mod_class, tx_subdev_spec,
+                 bitrate, interp, spb, bt, options):
+
+        # FIXME add this as a parameter, and move bt arg into dict
+        mod_kwargs = {
+            'bt' : bt
+            }
 
         self.normal_gain = 8000
 
@@ -39,19 +44,26 @@
                               fusb_nblocks=options.fusb_nblocks)
         dac_rate = self.u.dac_rate();
 
-        (self._bitrate, self._spb, self._interp) = pick_tx_bitrate(bitrate, 1, 
spb,
-                                                                   interp, 
dac_rate)
+        (self._bitrate, self._spb, self._interp) = \
+            pick_tx_bitrate(bitrate, mod_class.bits_per_baud(), spb, interp, 
dac_rate)
+
         self.u.set_interp_rate(self._interp)
 
         # determine the daughterboard subdevice we're using
-        if subdev_spec is None:
-            subdev_spec = usrp.pick_tx_subdevice(self.u)
-        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
-        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
+        if tx_subdev_spec is None:
+            tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
+        self.u.set_mux(usrp.determine_tx_mux_value(self.u, tx_subdev_spec))
+        self.subdev = usrp.selected_subdev(self.u, tx_subdev_spec)
         print "Using TX d'board %s" % (self.subdev.side_and_name(),)
 
         # transmitter
-        self.packet_transmitter = blks.gmsk2_mod_pkts(fg, spb=self._spb, 
bt=bt, msgq_limit=2)
+        self.packet_transmitter = \
+            blks.mod_pkts(fg,
+                          mod_class(fg, spb=self._spb, **mod_kwargs),
+                          access_code=None,
+                          msgq_limit=4,
+                          pad_for_usrp=True)
+
         self.amp = gr.multiply_const_cc (self.normal_gain)
 
         fg.connect(self.packet_transmitter, self.amp, self.u)
@@ -70,12 +82,10 @@
         Tuning is a two step process.  First we ask the front-end to
         tune as close to the desired frequency as it can.  Then we use
         the result of that operation and our target_frequency to
-        determine the value for the digital up converter.  Finally, we feed
-        any residual_freq to the s/w freq translater.
+        determine the value for the digital up converter.
         """
         r = self.u.tune(self.subdev._which, self.subdev, target_freq)
         if r:
-            # Could use residual_freq in s/w freq translator
             return True
 
         return False

Index: python/gmsk2/tunnel.py
===================================================================
RCS file: python/gmsk2/tunnel.py
diff -N python/gmsk2/tunnel.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ python/gmsk2/tunnel.py      21 Jun 2006 00:55:01 -0000      1.1
@@ -0,0 +1,300 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2006 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.
+# 
+
+
+# /////////////////////////////////////////////////////////////////////////////
+#
+#    This code sets up up a virtual ethernet interface (typically gr0),
+#    and relays packets between the interface and the GNU Radio PHY+MAC
+#
+#    What this means in plain language, is that if you've got a couple
+#    of USRPs on different machines, and if you run this code on those
+#    machines, you can talk between them using normal TCP/IP networking.
+#
+# /////////////////////////////////////////////////////////////////////////////
+
+
+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 time
+import struct
+import sys
+import os
+
+# from current dir
+from transmit_path import transmit_path
+from receive_path import receive_path
+import fusb_options
+
+#print os.getpid()
+#raw_input('Attach and press enter')
+
+
+# /////////////////////////////////////////////////////////////////////////////
+#
+#   Use the Universal TUN/TAP device driver to move packets to/from kernel
+#
+#   See /usr/src/linux/Documentation/networking/tuntap.txt
+#
+# /////////////////////////////////////////////////////////////////////////////
+
+# Linux specific...
+# TUNSETIFF ifr flags from <linux/tun_if.h>
+
+IFF_TUN                = 0x0001   # tunnel IP packets
+IFF_TAP                = 0x0002   # tunnel ethernet frames
+IFF_NO_PI      = 0x1000   # don't pass extra packet info
+IFF_ONE_QUEUE  = 0x2000   # beats me ;)
+
+def open_tun_interface(tun_device_filename):
+    from fcntl import ioctl
+    
+    mode = IFF_TAP | IFF_NO_PI
+    TUNSETIFF = 0x400454ca
+
+    tun = os.open(tun_device_filename, os.O_RDWR)
+    ifs = ioctl(tun, TUNSETIFF, struct.pack("16sH", "gr%d", mode))
+    ifname = ifs[:16].strip("\x00")
+    return (tun, ifname)
+    
+
+# /////////////////////////////////////////////////////////////////////////////
+#                             the flow graph
+# /////////////////////////////////////////////////////////////////////////////
+
+class my_graph(gr.flow_graph):
+
+    def __init__(self, mod_class, demod_class, tx_subdev_spec, rx_subdev_spec,
+                 bitrate, decim_rate, interp_rate, spb,
+                 bt, rx_callback, options):
+
+        gr.flow_graph.__init__(self)
+        self.txpath = transmit_path(self, mod_class, tx_subdev_spec,
+                                    bitrate, interp_rate, spb,
+                                    bt, options)
+        self.rxpath = receive_path(self, demod_class, rx_subdev_spec,
+                                   bitrate, decim_rate, spb,
+                                   rx_callback, options)
+
+    def send_pkt(self, payload='', eof=False):
+        return self.txpath.send_pkt(payload, eof)
+
+    def carrier_sensed(self):
+        """
+        Return True if the receive path thinks there's carrier
+        """
+        return self.rxpath.carrier_sensed()
+
+
+# /////////////////////////////////////////////////////////////////////////////
+#                           Carrier Sense MAC
+# /////////////////////////////////////////////////////////////////////////////
+
+class cs_mac(object):
+    """
+    Prototype carrier sense MAC
+
+    Reads packets from the TUN/TAP interface, and sends them to the PHY.
+    Receives packets from the PHY via phy_rx_callback, and sends them
+    into the TUN/TAP interface.
+
+    Of course, we're not restricted to getting packets via TUN/TAP, this
+    is just an example.
+    """
+    def __init__(self, tun_fd, verbose=False):
+        self.tun_fd = tun_fd       # file descriptor for TUN/TAP interface
+        self.verbose = verbose
+        self.fg = None             # flow graph (access to PHY)
+
+    def set_flow_graph(self, fg):
+        self.fg = fg
+
+    def phy_rx_callback(self, ok, payload):
+        """
+        Invoked by thread associated with PHY to pass received packet up.
+
+        @param ok: bool indicating whether payload CRC was OK
+        @param payload: contents of the packet (string)
+        """
+        if self.verbose:
+            print "Rx: ok = %r  len(payload) = %4d" % (ok, len(payload))
+        if ok:
+            os.write(self.tun_fd, payload)
+
+    def main_loop(self):
+        """
+        Main loop for MAC.
+        Only returns if we get an error reading from TUN.
+
+        FIXME: may want to check for EINTR and EAGAIN and reissue read
+        """
+        min_delay = 0.001               # seconds
+
+        while 1:
+            payload = os.read(self.tun_fd, 10*1024)
+            if not payload:
+                self.fg.send_pkt(eof=True)
+                break
+
+            if self.verbose:
+                print "Tx: len(payload) = %4d" % (len(payload),)
+
+            delay = min_delay
+            while self.fg.carrier_sensed():
+                sys.stderr.write('B')
+                time.sleep(delay)
+                if delay < 0.050:
+                    delay = delay * 2       # exponential back-off
+
+            self.fg.send_pkt(payload)
+
+
+# /////////////////////////////////////////////////////////////////////////////
+#                                   main
+# /////////////////////////////////////////////////////////////////////////////
+
+def main():
+
+    parser = OptionParser (option_class=eng_option)
+    parser.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,
+                      help="specify bitrate.  spb and interp will be derived.")
+    parser.add_option("-g", "--rx-gain", type="eng_float", default=27,
+                      help="set rx gain")
+    parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
+                      help="select USRP Tx side A or B")
+    parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
+                      help="select USRP Rx side A or B")
+    parser.add_option("-S", "--spb", type="int", default=None, help="set 
samples/baud [default=%default]")
+    parser.add_option("-d", "--decim", type="intx", default=None,
+                      help="set fpga decim rate to DECIM [default=%default]")
+    parser.add_option("-i", "--interp", type="intx", default=None,
+                      help="set fpga interpolation rate to INTERP 
[default=%default]")
+    parser.add_option("-c", "--carrier-threshold", type="eng_float", 
default=30,
+                      help="set carrier detect threshold (dB) 
[default=%default]")
+    parser.add_option("", "--bt", type="float", default=0.3, help="set 
bandwidth-time product [default=%default]")
+    parser.add_option("","--tun-device-filename", default="/dev/net/tun",
+                      help="path to tun device file [default=%default]")
+    parser.add_option("-v","--verbose", action="store_true", default=False)
+    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
+
+    # open the TUN/TAP interface
+    (tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)
+
+    # Attempt to enable realtime scheduling
+    r = gr.enable_realtime_scheduling()
+    if r == gr.RT_OK:
+        realtime = True
+    else:
+        realtime = False
+        print "Note: failed to enable realtime scheduling"
+
+
+    # If the user hasn't set the fusb_* parameters on the command line,
+    # pick some values that will reduce latency.
+
+    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
+        if realtime:                        # be more aggressive
+            options.fusb_block_size = gr.prefs().get_long('fusb', 
'rt_block_size', 1024)
+            options.fusb_nblocks    = gr.prefs().get_long('fusb', 
'rt_nblocks', 16)
+        else:
+            options.fusb_block_size = gr.prefs().get_long('fusb', 
'block_size', 4096)
+            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 
16)
+    
+    print "fusb_block_size =", options.fusb_block_size
+    print "fusb_nblocks    =", options.fusb_nblocks
+
+    # instantiate the MAC
+    mac = cs_mac(tun_fd, verbose=True)
+
+
+    # build the graph (PHY)
+    fg = my_graph(blks.gmsk2_mod, blks.gmsk2_demod,
+                  options.tx_subdev_spec, options.rx_subdev_spec,
+                  options.bitrate, options.decim, options.interp,
+                  options.spb, options.bt, mac.phy_rx_callback,
+                  options)
+
+    mac.set_flow_graph(fg)    # give the MAC a handle for the PHY
+
+    if fg.txpath.bitrate() != fg.rxpath.bitrate():
+        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" 
% (
+            eng_notation.num_to_str(fg.txpath.bitrate()),
+            eng_notation.num_to_str(fg.rxpath.bitrate()))
+             
+    print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
+    print "spb:     %3d" % (fg.txpath.spb(),)
+    print "interp:  %3d" % (fg.txpath.interp(),)
+
+    ok = fg.txpath.set_freq(options.freq)
+    if not ok:
+        print "Failed to set Tx frequency to %s" % 
(eng_notation.num_to_str(options.freq),)
+        raise SystemExit
+
+    ok = fg.rxpath.set_freq(options.freq)
+    if not ok:
+        print "Failed to set Rx frequency to %s" % 
(eng_notation.num_to_str(options.freq),)
+        raise SystemExit
+
+    fg.rxpath.set_gain(options.rx_gain)
+    print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", 
fg.rxpath.gain
+
+    fg.rxpath.set_carrier_threshold(options.carrier_threshold)
+    print "Carrier sense threshold:", options.carrier_threshold, "dB"
+    
+    print
+    print "Allocated virtual ethernet interface: %s" % (tun_ifname,)
+    print "You must now use ifconfig to set its IP address. E.g.,"
+    print
+    print "  $ sudo ifconfig %s 10.10.10.1" % (tun_ifname,)
+    print
+    print "Be sure to use a different address in the same subnet for each 
machine."
+    print
+
+
+    fg.start()    # Start executing the flow graph (runs in separate threads)
+
+    mac.main_loop()    # don't expect this to return...
+
+    fg.stop()     # but if it does, tell flow graph to stop.
+    fg.wait()     # wait for it to finish
+                
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass

Index: python/gmsk2/tunnel_ip_null_mac.py
===================================================================
RCS file: python/gmsk2/tunnel_ip_null_mac.py
diff -N python/gmsk2/tunnel_ip_null_mac.py
--- python/gmsk2/tunnel_ip_null_mac.py  20 Jun 2006 06:15:37 -0000      1.13
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,292 +0,0 @@
-#!/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 time
-import struct
-import sys
-import os
-
-# from current dir
-from transmit_path import transmit_path
-from receive_path import receive_path
-import fusb_options
-
-#print os.getpid()
-#raw_input('Attach and press enter')
-
-
-# /////////////////////////////////////////////////////////////////////////////
-#
-#   Use the Universal TUN/TAP device driver to moves packets to/from kernel
-#
-# See /usr/src/linux/Documentation/networking/tuntap.txt
-#
-# /////////////////////////////////////////////////////////////////////////////
-
-# Linux specific...
-# TUNSETIFF ifr flags from <linux/tun_if.h>
-
-IFF_TUN                = 0x0001   # tunnel IP packets
-IFF_TAP                = 0x0002   # tunnel ethernet frames
-IFF_NO_PI      = 0x1000   # don't pass extra packet info
-IFF_ONE_QUEUE  = 0x2000   # beats me ;)
-
-def open_tun_interface(tun_device_filename):
-    from fcntl import ioctl
-    
-    mode = IFF_TAP | IFF_NO_PI
-    TUNSETIFF = 0x400454ca
-
-    tun = os.open(tun_device_filename, os.O_RDWR)
-    ifs = ioctl(tun, TUNSETIFF, struct.pack("16sH", "gr%d", mode))
-    ifname = ifs[:16].strip("\x00")
-    return (tun, ifname)
-    
-
-# /////////////////////////////////////////////////////////////////////////////
-#                             the flow graph
-# /////////////////////////////////////////////////////////////////////////////
-
-class my_graph(gr.flow_graph):
-
-    def __init__(self, rx_subdev_spec, tx_subdev_spec,
-                 bitrate, decim_rate, interp_rate, spb, bt, rx_callback, log_p,
-                 options):
-
-        gr.flow_graph.__init__(self)
-        self.txpath = transmit_path(self, tx_subdev_spec, bitrate, interp_rate,
-                                    spb, bt, log_p, options)
-        self.rxpath =  receive_path(self, rx_subdev_spec, bitrate, decim_rate,
-                                    spb, rx_callback, log_p, options)
-
-    def send_pkt(self, payload='', eof=False):
-        return self.txpath.send_pkt(payload, eof)
-
-    def carrier_sensed(self):
-        """
-        Return True if the receive path thinks there's carrier
-        """
-        return self.rxpath.carrier_sensed()
-
-
-# /////////////////////////////////////////////////////////////////////////////
-#                              Null MAC
-# /////////////////////////////////////////////////////////////////////////////
-
-class null_mac(object):
-    """
-    Prototype Null MAC
-
-    Reads packets from the TUN interface, and sends them to the PHY.
-    Receives packets from the PHY via phy_rx_callback, and sends them
-    into the TUN interface.
-
-    In a 'Real MAC' we'd want more info from the PHY, such as carrier
-    sense etc.  Of course, we're not restricted to getting packets via
-    TUN, this is just an example.
-    """
-    def __init__(self, tun_fd, mtu, verbose=False):
-        self.tun_fd = tun_fd       # file descriptor for TUN interface
-        self.mtu = mtu
-        self.verbose = verbose
-        self.fg = None             # flow graph (access to PHY)
-
-    def set_flow_graph(self, fg):
-        self.fg = fg
-
-    def phy_rx_callback(self, ok, payload):
-        """
-        Invoked by thread associated with PHY to pass received packet up.
-
-        @param ok: bool indicating whether payload CRC was OK
-        @param payload: contents of the packet (string)
-        """
-        if self.verbose:
-            print "Rx: ok = %r  len(payload) = %4d" % (ok, len(payload))
-        if ok:
-            os.write(self.tun_fd, payload)
-
-    def main_loop(self):
-        """
-        Main loop for MAC.
-        Only returns if we get an error reading from TUN.
-
-        FIXME: may want to check for EINTR and EAGAIN and reissue read
-        """
-        while 1:
-            #
-            # Your state machine here...
-            #
-            payload = os.read(self.tun_fd, self.mtu)
-            if not payload:
-                self.fg.send_pkt(eof=True)
-                break
-            if self.verbose:
-                print "Tx: len(payload) = %4d" % (len(payload),)
-            self.fg.send_pkt(payload)
-
-
-# /////////////////////////////////////////////////////////////////////////////
-#                           Carrier Sense MAC
-# /////////////////////////////////////////////////////////////////////////////
-
-class cs_mac(null_mac):
-    """
-    Prototype carrier sense MAC
-
-    Reads packets from the TUN interface, and sends them to the PHY.
-    Receives packets from the PHY via phy_rx_callback, and sends them
-    into the TUN interface.
-
-    Of course, we're not restricted to getting packets via TUN, this
-    is just an example.
-    """
-    def __init__(self, tun_fd, mtu, verbose=False):
-        null_mac.__init__(self, tun_fd, mtu, verbose)
-
-    def main_loop(self):
-        """
-        Main loop for MAC.
-        Only returns if we get an error reading from TUN.
-
-        FIXME: may want to check for EINTR and EAGAIN and reissue read
-        """
-        min_delay = 0.001               # seconds
-
-        while 1:
-            #payload = os.read(self.tun_fd, self.mtu)
-            payload = os.read(self.tun_fd, 2*self.mtu)
-            if not payload:
-                self.fg.send_pkt(eof=True)
-                break
-
-            if self.verbose:
-                print "Tx: len(payload) = %4d" % (len(payload),)
-
-            delay = min_delay
-            while self.fg.carrier_sensed():
-                sys.stderr.write('B')
-                time.sleep(delay)
-                if delay < 0.050:
-                    delay = delay * 2       # exponential back-off
-
-            self.fg.send_pkt(payload)
-
-
-# /////////////////////////////////////////////////////////////////////////////
-#                                   main
-# /////////////////////////////////////////////////////////////////////////////
-
-def main():
-
-    parser = OptionParser (option_class=eng_option)
-    parser.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,
-                      help="specify bitrate.  spb and interp will be derived.")
-    parser.add_option("-g", "--gain", type="eng_float", default=27,
-                      help="set rx gain")
-    parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
-                      help="select USRP Rx side A or B")
-    parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
-                      help="select USRP Tx side A or B")
-    parser.add_option("-S", "--spb", type="int", default=None, help="set 
samples/baud [default=%default]")
-    parser.add_option("-d", "--decim", type="intx", default=None,
-                      help="set fpga decim rate to DECIM [default=%default]")
-    parser.add_option("-i", "--interp", type="intx", default=None,
-                      help="set fpga interpolation rate to INTERP 
[default=%default]")
-    parser.add_option("", "--bt", type="float", default=0.3, help="set 
bandwidth-time product [default=%default]")
-    parser.add_option("","--log", action="store_true", default=False,
-                      help="enable diagnostic logging")
-    parser.add_option("","--tun-device-filename", default="/dev/net/tun",
-                      help="path to tun device file [default=%default]")
-    parser.add_option("-v","--verbose", action="store_true", default=False)
-    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
-
-    MTU = 1500
-    
-    # open the TUN interface
-    (tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)
-
-    # instantiate the MAC
-    #mac = null_mac(tun_fd, MTU, verbose=True)
-    mac = cs_mac(tun_fd, MTU, verbose=True)
-
-    # build the graph (PHY)
-    fg = my_graph(options.tx_subdev_spec, options.rx_subdev_spec,
-                  options.bitrate, options.decim, options.interp,
-                  options.spb, options.bt, mac.phy_rx_callback, options.log,
-                  options)
-
-    mac.set_flow_graph(fg)    # give the MAC a handle for the PHY
-
-    if fg.txpath.bitrate() != fg.rxpath.bitrate():
-        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" 
% (
-            eng_notation.num_to_str(fg.txpath.bitrate()),
-            eng_notation.num_to_str(fg.rxpath.bitrate()))
-             
-    print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
-    print "spb:     %3d" % (fg.txpath.spb(),)
-    print "interp:  %3d" % (fg.txpath.interp(),)
-
-    fg.txpath.set_freq(options.freq)
-    fg.rxpath.set_freq(options.freq)
-    fg.rxpath.set_gain(options.gain)
-    print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", 
fg.rxpath.gain
-
-    print "Allocated tun interface: %s" % (tun_ifname,)
-    print "You must ifconfig it and set up your routing now." 
-
-
-    r = gr.enable_realtime_scheduling()
-    if r != gr.RT_OK:
-        print "Warning: failed to enable realtime scheduling"
-
-
-    fg.start()    # Start executing the flow graph (runs in separate threads)
-
-    mac.main_loop()    # don't expect this to return...
-
-    fg.stop()     # but if it does, tell flow graph to stop.
-    fg.wait()     # wait for it to finish
-                
-
-if __name__ == '__main__':
-    try:
-        main()
-    except KeyboardInterrupt:
-        pass




reply via email to

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