commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4391 - in gnuradio/trunk: gnuradio-core/src/lib/gener


From: jcorgan
Subject: [Commit-gnuradio] r4391 - in gnuradio/trunk: gnuradio-core/src/lib/general gnuradio-core/src/python/gnuradio gnuradio-core/src/python/gnuradio/blksimpl gnuradio-examples/python/digital
Date: Mon, 5 Feb 2007 17:10:33 -0700 (MST)

Author: jcorgan
Date: 2007-02-05 17:10:32 -0700 (Mon, 05 Feb 2007)
New Revision: 4391

Added:
   gnuradio/trunk/gnuradio-examples/python/digital/run_length.py
Modified:
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.h
   gnuradio/trunk/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
   gnuradio/trunk/gnuradio-core/src/python/gnuradio/packet_utils.py
   gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am
   gnuradio/trunk/gnuradio-examples/python/digital/README
   gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py
   gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py
Log:
Merged r4354:4390 from developer branch jcorgan/digital into trunk.

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.cc    
2007-02-05 23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.cc    
2007-02-06 00:10:32 UTC (rev 4391)
@@ -52,13 +52,14 @@
 }
 
 inline void
-gr_framer_sink_1::enter_have_header(int payload_len)
+gr_framer_sink_1::enter_have_header(int payload_len, int whitener_offset)
 {
   if (VERBOSE)
-    fprintf(stderr, "@ enter_have_header (payload_len = %d)\n", payload_len);
+    fprintf(stderr, "@ enter_have_header (payload_len = %d) (offset = %d)\n", 
payload_len, whitener_offset);
 
   d_state = STATE_HAVE_HEADER;
   d_packetlen = payload_len;
+  d_packet_whitener_offset = whitener_offset;
   d_packetlen_cnt = 0;
   d_packet_byte = 0;
   d_packet_byte_index = 0;
@@ -125,11 +126,10 @@
 
          // we have a full header, check to see if it has been received 
properly
          if (header_ok()){
-           int payload_len = header_payload_len();
-           if (payload_len <= MAX_PKT_LEN)             // reasonable?
-             enter_have_header(payload_len);           // yes.
-           else
-             enter_search();                           // no.
+           int payload_len;
+           int payload_offset;
+           header_payload(&payload_len, &payload_offset);
+           enter_have_header(payload_len, payload_offset);
          }
          else
            enter_search();                             // no.
@@ -151,7 +151,8 @@
          if (d_packetlen_cnt == d_packetlen){          // packet is filled
 
            // build a message
-           gr_message_sptr msg = gr_make_message(0, 0, 0, d_packetlen_cnt);    
    
+           // NOTE: passing header field as arg1 is not scalable
+           gr_message_sptr msg = gr_make_message(0, d_packet_whitener_offset, 
0, d_packetlen_cnt);         
            memcpy(msg->msg(), d_packet, d_packetlen_cnt);
 
            d_target_queue->insert_tail(msg);           // send it

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.h     
2007-02-05 23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_framer_sink_1.h     
2007-02-06 00:10:32 UTC (rev 4391)
@@ -70,6 +70,7 @@
   unsigned char             d_packet_byte;             // byte being assembled
   int               d_packet_byte_index;       // which bit of d_packet_byte 
we're working on
   int               d_packetlen;               // length of packet
+  int                d_packet_whitener_offset;  // offset into whitener string 
to use
   int               d_packetlen_cnt;           // how many so far
 
  protected:
@@ -77,7 +78,7 @@
 
   void enter_search();
   void enter_have_sync();
-  void enter_have_header(int payload_len);
+  void enter_have_header(int payload_len, int whitener_offset);
   
   bool header_ok()
   {
@@ -85,11 +86,13 @@
     return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
   }
 
-  int header_payload_len()
+  void header_payload(int *len, int *offset)
   {
     // header consists of two 16-bit shorts in network byte order
-    int t = (d_header >> 16) & 0xffff;
-    return t;
+    // payload length is lower 12 bits
+    // whitener offset is upper 4 bits
+    *len = (d_header >> 16) & 0x0fff;
+    *offset = (d_header >> 28) & 0x000f;
   }
 
  public:

Modified: gnuradio/trunk/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
===================================================================
--- gnuradio/trunk/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py    
2007-02-05 23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py    
2007-02-06 00:10:32 UTC (rev 4391)
@@ -36,7 +36,7 @@
 
     Send packets by calling send_pkt
     """
-    def __init__(self, fg, modulator, access_code=None, msgq_limit=2, 
pad_for_usrp=True):
+    def __init__(self, fg, modulator, access_code=None, msgq_limit=2, 
pad_for_usrp=True, use_whitener_offset=False):
         """
        Hierarchical block for sending packets
 
@@ -52,12 +52,15 @@
         @param msgq_limit: maximum number of messages in message queue
         @type msgq_limit: int
         @param pad_for_usrp: If true, packets are padded such that they end up 
a multiple of 128 samples
-
+        @param use_whitener_offset: If true, start of whitener XOR string is 
incremented each packet
+        
         See gmsk_mod for remaining parameters
         """
         self._modulator = modulator
         self._pad_for_usrp = pad_for_usrp
-
+        self._use_whitener_offset = use_whitener_offset
+        self._whitener_offset = 0
+        
         if access_code is None:
             access_code = packet_utils.default_access_code
         if not packet_utils.is_1_0_string(access_code):
@@ -84,9 +87,13 @@
                                            
self._modulator.samples_per_symbol(),
                                            self._modulator.bits_per_symbol(),
                                            self._access_code,
-                                           self._pad_for_usrp)
+                                           self._pad_for_usrp,
+                                           self._whitener_offset)
             #print "pkt =", string_to_hex_list(pkt)
             msg = gr.message_from_string(pkt)
+            if self._use_whitener_offset is True:
+                self._whitener_offset = (self._whitener_offset + 1) % 16
+                
         self._pkt_input.msgq().insert_tail(msg)
 
 
@@ -151,6 +158,6 @@
     def run(self):
         while self.keep_running:
             msg = self.rcvd_pktq.delete_head()
-            ok, payload = packet_utils.unmake_packet(msg.to_string())
+            ok, payload = packet_utils.unmake_packet(msg.to_string(), 
int(msg.arg1()))
             if self.callback:
                 self.callback(ok, payload)

Modified: gnuradio/trunk/gnuradio-core/src/python/gnuradio/packet_utils.py
===================================================================
--- gnuradio/trunk/gnuradio-core/src/python/gnuradio/packet_utils.py    
2007-02-05 23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-core/src/python/gnuradio/packet_utils.py    
2007-02-06 00:10:32 UTC (rev 4391)
@@ -86,22 +86,26 @@
     return map(lambda x: hex(ord(x)), s)
 
 
-def whiten(s):
+def whiten(s, o):
     sa = Numeric.fromstring(s, Numeric.UnsignedInt8)
-    z = sa ^ random_mask_vec8[0:len(sa)]
+    z = sa ^ random_mask_vec8[o:len(sa)+o]
     return z.tostring()
 
-def dewhiten(s):
-    return whiten(s)        # self inverse
+def dewhiten(s, o):
+    return whiten(s, o)        # self inverse
 
 
-def make_header(payload_len):
-    return struct.pack('!HH', payload_len, payload_len)
+def make_header(payload_len, whitener_offset=0):
+    # Upper nibble is offset, lower 12 bits is len
+    val = ((whitener_offset & 0xf) << 12) | (payload_len & 0x0fff)
+    #print "offset =", whitener_offset, " len =", payload_len, " val=", val
+    return struct.pack('!HH', val, val)
 
 def make_packet(payload, samples_per_symbol, bits_per_symbol,
-                access_code=default_access_code, pad_for_usrp=True):
+                access_code=default_access_code, pad_for_usrp=True,
+                whitener_offset=0):
     """
-    Build a packet, given access code and payload.
+    Build a packet, given access code, payload, and whitener offset
 
     @param payload:               packet payload, len [0, 4096]
     @param samples_per_symbol:    samples per symbol (needed for padding 
calculation)
@@ -109,6 +113,7 @@
     @param bits_per_symbol:       (needed for padding calculation)
     @type bits_per_symbol:        int
     @param access_code:           string of ascii 0's and 1's
+    @param whitener_offset        offset into whitener string to use [0-16)
     
     Packet will have access code at the beginning, followed by length, payload
     and finally CRC-32.
@@ -116,6 +121,9 @@
     if not is_1_0_string(access_code):
         raise ValueError, "access_code must be a string containing only 0's 
and 1's (%r)" % (access_code,)
 
+    if not whitener_offset >=0 and whitener_offset < 16:
+        raise ValueError, "whitener_offset must be between 0 and 15, inclusive 
(%i)" % (whitener_offset,)
+
     (packed_access_code, padded) = 
conv_1_0_string_to_packed_binary_string(access_code)
     (packed_preamble, ignore) = 
conv_1_0_string_to_packed_binary_string(preamble)
     
@@ -127,7 +135,8 @@
     if L > MAXLEN:
         raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)
 
-    pkt = ''.join((packed_preamble, packed_access_code, make_header(L), 
whiten(payload_with_crc), '\x55'))
+    pkt = ''.join((packed_preamble, packed_access_code, make_header(L, 
whitener_offset),
+                   whiten(payload_with_crc, whitener_offset), '\x55'))
     if pad_for_usrp:
         pkt = pkt + (_npadding_bytes(len(pkt), samples_per_symbol, 
bits_per_symbol) * '\x55')
 
@@ -156,13 +165,13 @@
     return byte_modulus - r
     
 
-def unmake_packet(whitened_payload_with_crc):
+def unmake_packet(whitened_payload_with_crc, whitener_offset=0):
     """
     Return (ok, payload)
 
     @param whitened_payload_with_crc: string
     """
-    payload_with_crc = dewhiten(whitened_payload_with_crc)
+    payload_with_crc = dewhiten(whitened_payload_with_crc, whitener_offset)
     ok, payload = gru.check_crc32(payload_with_crc)
 
     if 0:

Modified: gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am 2007-02-05 
23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am 2007-02-06 
00:10:32 UTC (rev 4391)
@@ -28,6 +28,7 @@
        pick_bitrate.py         \
        receive_path.py         \
        rx_voice.py             \
+       run_length.py           \
        transmit_path.py        \
        tunnel.py               \
        tx_voice.py             

Modified: gnuradio/trunk/gnuradio-examples/python/digital/README
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/README      2007-02-05 
23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-examples/python/digital/README      2007-02-06 
00:10:32 UTC (rev 4391)
@@ -75,3 +75,10 @@
 
 This now uses a carrier sense MAC, so you should be able to ssh
 between the machines, web browse, etc.
+
+* run_length.py: This program takes a single argument '-f FILE' and
+outputs the number of runs of similar bits within the file. It is
+useful as a diagnostic tool when experimenting with line coding or
+whitening algorithms.
+
+

Modified: gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py     
2007-02-05 23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py     
2007-02-06 00:10:32 UTC (rev 4391)
@@ -71,6 +71,8 @@
                       help="set megabytes to transmit [default=%default]")
     parser.add_option("","--discontinuous", action="store_true", default=False,
                       help="enable discontinous transmission (bursts of 5 
packets)")
+    parser.add_option("","--from-file", default=None,
+                      help="use file for packet contents")
 
     transmit_path.add_options(parser, expert_grp)
 
@@ -89,6 +91,9 @@
         parser.print_help(sys.stderr)
         sys.exit(1)
 
+    if options.from_file is not None:
+        source_file = open(options.from_file, 'r')
+
     # build the graph
     fg = my_graph(mods[options.modulation], options)
 
@@ -98,7 +103,6 @@
 
     fg.start()                       # start flow graph
 
-
     # generate and send packets
     nbytes = int(1e6 * options.megabytes)
     n = 0
@@ -106,8 +110,16 @@
     pkt_size = int(options.size)
 
     while n < nbytes:
-        send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
-        n += pkt_size
+        if options.from_file is None:
+            data = (pkt_size - 2) * chr(pktno & 0xff) 
+        else:
+            data = source_file.read(pkt_size - 2)
+            if data == '':
+                break;
+
+        payload = struct.pack('!H', pktno) + data
+        send_pkt(payload)
+        n += len(payload)
         sys.stderr.write('.')
         if options.discontinuous and pktno % 5 == 4:
             time.sleep(1)

Copied: gnuradio/trunk/gnuradio-examples/python/digital/run_length.py (from rev 
4390, 
gnuradio/branches/developers/jcorgan/digital/gnuradio-examples/python/digital/run_length.py)
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/run_length.py               
                (rev 0)
+++ gnuradio/trunk/gnuradio-examples/python/digital/run_length.py       
2007-02-06 00:10:32 UTC (rev 4391)
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from optparse import OptionParser
+import sys
+
+def main():
+    parser = OptionParser()
+    parser.add_option("-f", "--file", default=None,
+                      help="Choose file to read data from.")
+    (options, args) = parser.parse_args()
+
+    if options.file == None:
+        print "Must specify file to read from using '-f'."
+        sys.exit(1)
+    print "Using", options.file, "for data."
+
+    f = open(options.file, 'r')
+    runs = []
+    count = 0
+    current = 0
+    bytes = 0
+    bits = 0
+    
+    for ch in f.read():
+        x = ord(ch)
+        bytes = bytes + 1
+        for i in range(7,-1,-1):
+            bits = bits + 1
+            t = (x >> i) & 0x1
+            if t == current:
+                count = count + 1
+            else:
+                if count > 0:
+                    if len(runs) < count:
+                        for j in range(count - len(runs)):
+                            runs.append(0);
+                    runs[count-1] = runs[count-1] + 1
+
+                current = 1-current;
+                count = 1
+
+    # Deal with last run at EOF
+    if len(runs) < count and count > 0:
+        for j in range(count - len(runs)):
+            runs.append(0);
+    runs[count-1] = runs[count-1] + 1
+
+    chk = 0
+    print "Bytes read: ", bytes
+    print "Bits read:  ", bits
+    print
+    for i in range(len(runs)):
+        chk = chk + runs[i]*(i+1)
+        print "Runs of length", i+1, ":", runs[i]
+    print
+    print "Sum of runs:", chk, "bits"
+    print
+    print "Maximum run length is", len(runs), "bits"
+
+if __name__ == "__main__":
+    main()
+
+    

Modified: gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py    
2007-02-05 23:47:05 UTC (rev 4390)
+++ gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py    
2007-02-06 00:10:32 UTC (rev 4391)
@@ -50,7 +50,8 @@
         self._samples_per_symbol = options.samples_per_symbol  # 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._use_whitener_offset = options.use_whitener_offset # increment 
start of whitener XOR data
+        
         self._modulator_class = modulator_class         # the modulator_class 
we are using
     
         if self._tx_freq is None:
@@ -80,7 +81,8 @@
                           self._modulator_class(fg, **mod_kwargs),
                           access_code=None,
                           msgq_limit=4,
-                          pad_for_usrp=True)
+                          pad_for_usrp=True,
+                          use_whitener_offset=options.use_whitener_offset)
 
 
         # Set the USRP for maximum transmit gain
@@ -200,6 +202,8 @@
                           help="set fpga interpolation rate to INTERP 
[default=%default]")
         expert.add_option("", "--log", action="store_true", default=False,
                           help="Log all parts of flow graph to file (CAUTION: 
lots of data)")
+        expert.add_option("","--use-whitener-offset", action="store_true", 
default=False,
+                          help="make sequential packets use different 
whitening")
 
     # 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]