commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11038 - in gnuradio/branches/developers/eb/vrt/vrt: i


From: eb
Subject: [Commit-gnuradio] r11038 - in gnuradio/branches/developers/eb/vrt/vrt: include/vrt lib
Date: Thu, 14 May 2009 23:06:16 -0600 (MDT)

Author: eb
Date: 2009-05-14 23:06:16 -0600 (Thu, 14 May 2009)
New Revision: 11038

Added:
   gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_cw_tables.h
   gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_switch_body.h
   gnuradio/branches/developers/eb/vrt/vrt/lib/gen_cw_tables.py
   gnuradio/branches/developers/eb/vrt/vrt/lib/gen_switch_body.py
Modified:
   gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_header.h
   gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header.cc
Log:
work-in-progress

Modified: gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_header.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_header.h       
2009-05-15 04:11:05 UTC (rev 11037)
+++ gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_header.h       
2009-05-15 05:06:16 UTC (rev 11038)
@@ -22,6 +22,7 @@
 #define INCLUDED_VRT_EXPANDED_HEADER_H
 
 #include <stdint.h>
+#include <stddef.h>
 #include <vrt/bits.h>
 
 namespace vrt {
@@ -43,13 +44,18 @@
     uint32_t   trailer;                // optional trailer (only possible in 
data pkts)
 
     expanded_header()
-      : header(0), stream_id(0), class_id(0),
-       integer_secs(0), fractional_secs(0), trailer(0) {}
+      : header(0) /*, stream_id(0), class_id(0),
+        integer_secs(0), fractional_secs(0), trailer(0)*/ {}
 
+
     int pkt_type() const {
       return (header & VRTH_PT_MASK) >> 28;
     }
     
+    int pkt_cnt() const { return vrth_pkt_cnt(header); }
+    size_t pkt_size() const { return vrth_pkt_size(header); }
+
+
     // packet type predicates
     bool if_data_p() const { return s_if_data[pkt_type()]; }
     bool ext_data_p() const { return s_ext_data[pkt_type()]; }
@@ -62,10 +68,22 @@
     // optional info predicates
     bool stream_id_p() const { return s_stream_id[pkt_type()]; }
     bool class_id_p() const { return (header & VRTH_HAS_CLASSID) != 0; }
+    bool integer_secs_p() const { return (header & VRTH_TSI_MASK) != 0; }
+    bool fractional_secs_p() const { return (header & VRTH_TSF_MASK) != 0; }
     bool trailer_p() const { return (header & VRTH_HAS_TRAILER) != 0 && 
data_p(); }
 
-    int pkt_cnt() const { return vrth_pkt_cnt(header); }
 
+    // parser
+
+    /*!
+     * \brief parse packet, fill-in expanded header, start of payload and len 
of payload
+     */
+    static bool parse(const uint32_t *packet,          // in
+                     size_t n32_bit_words_packet,      // in
+                     expanded_header *hdr,             // out
+                     const uint32_t **payload,         // out
+                     size_t *n32_bit_words_payload);   // out
+                     
   private:
     static unsigned char s_if_data[16];
     static unsigned char s_ext_data[16];

Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header.cc      
2009-05-15 04:11:05 UTC (rev 11037)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header.cc      
2009-05-15 05:06:16 UTC (rev 11038)
@@ -23,6 +23,7 @@
 #include <config.h>
 #endif
 #include <vrt/expanded_header.h>
+#include <arpa/inet.h>                 // needs autoconf'ing
 
 namespace vrt {
 
@@ -48,4 +49,65 @@
   };
 
 
+  // dispatch codeword bits
+  static const int HAS_STREAM_ID       = 1 << 0;
+  static const int HAS_CLASS_ID        = 1 << 1;
+  static const int HAS_INTEGER_SECS    = 1 << 2;
+  static const int HAS_FRACTIONAL_SECS = 1 << 3;
+  static const int HAS_TRAILER         = 1 << 4;
+
+#include "expanded_header_cw_tables.h"
+
+  static int
+  compute_codeword(const expanded_header &h)
+  {
+    int cw = 0;
+    if (h.stream_id_p())       cw |= HAS_STREAM_ID;
+    if (h.class_id_p())        cw |= HAS_CLASS_ID;
+    if (h.integer_secs_p())    cw |= HAS_INTEGER_SECS;
+    if (h.fractional_secs_p()) cw |= HAS_FRACTIONAL_SECS;
+    if (h.trailer_p())         cw |= HAS_TRAILER;
+    return cw;
+  }
+
+  bool 
+  expanded_header::parse(const uint32_t *packet,       // in
+                       size_t n32_bit_words_packet,    // in
+                       expanded_header *h,             // out
+                       const uint32_t **payload,       // out
+                       size_t *n32_bit_words_payload)  // out
+  {
+    size_t len = n32_bit_words_packet;
+    const uint32_t *p = packet;
+
+    *payload = 0;
+    *n32_bit_words_payload = 0;
+
+    if (len < 1){              // must have at least the header word
+      h->header = 0;
+      return false;
+    }
+
+    h->header = ntohl(p[0]);
+
+    if (h->pkt_size() > len)
+      return false;            // VRT header says packet is bigger than what 
we've got
+
+    len = h->pkt_size();       // valid length of packet
+
+    int cw = compute_codeword(*h);
+    if (cw_header_len(cw) + cw_trailer_len(cw) > len)
+      return false;            // negative payload len
+
+    *payload = p + cw_header_len(cw);
+    *n32_bit_words_payload = len - (cw_header_len(cw) + cw_trailer_len(cw));
+
+    switch (cw & 0x1f){
+#include "expanded_header_switch_body.h"
+    }
+
+    return true;
+  }
+
+
 }; // vrt

Added: gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_cw_tables.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_cw_tables.h     
                        (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_cw_tables.h     
2009-05-15 05:06:16 UTC (rev 11038)
@@ -0,0 +1,14 @@
+inline static size_t cw_header_len(int cw){
+  static const size_t s_cw_header_len[32] = {
+    1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 1, 2, 3, 4, 2, 3, 4, 5, 3, 
4, 5, 6, 4, 5, 6, 7, 
+  };
+  return s_cw_header_len[cw];
+}
+
+inline static size_t cw_trailer_len(int cw){
+  static const size_t s_cw_trailer_len[32] = {
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 
+  };
+  return s_cw_trailer_len[cw];
+}
+


Property changes on: 
gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_cw_tables.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_switch_body.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_switch_body.h   
                        (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_switch_body.h   
2009-05-15 05:06:16 UTC (rev 11038)
@@ -0,0 +1,256 @@
+  case 0:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 1:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 2:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 3:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 4:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[1]);
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 5:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[2]);
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 6:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = ntohl(p[3]);
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 7:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = ntohl(p[4]);
+    h->fractional_secs = 0;
+    h->trailer = 0;
+    break;
+
+  case 8:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->trailer = 0;
+    break;
+
+  case 9:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->trailer = 0;
+    break;
+
+  case 10:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    h->trailer = 0;
+    break;
+
+  case 11:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    h->trailer = 0;
+    break;
+
+  case 12:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[1]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->trailer = 0;
+    break;
+
+  case 13:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[2]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    h->trailer = 0;
+    break;
+
+  case 14:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = ntohl(p[3]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    h->trailer = 0;
+    break;
+
+  case 15:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = ntohl(p[4]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]);
+    h->trailer = 0;
+    break;
+
+  case 16:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 17:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 18:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 19:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = 0;
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 20:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[1]);
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 21:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[2]);
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 22:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = ntohl(p[3]);
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 23:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = ntohl(p[4]);
+    h->fractional_secs = 0;
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 24:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 25:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 26:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 27:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = 0;
+    h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 28:
+    h->stream_id = 0;
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[1]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 29:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = 0;
+    h->integer_secs = ntohl(p[2]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 30:
+    h->stream_id = 0;
+    h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    h->integer_secs = ntohl(p[3]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+
+  case 31:
+    h->stream_id = ntohl(p[1]);
+    h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    h->integer_secs = ntohl(p[4]);
+    h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]);
+    h->trailer = ntohl(p[len-1]);
+    break;
+


Property changes on: 
gnuradio/branches/developers/eb/vrt/vrt/lib/expanded_header_switch_body.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: gnuradio/branches/developers/eb/vrt/vrt/lib/gen_cw_tables.py
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/gen_cw_tables.py                
                (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/gen_cw_tables.py        
2009-05-15 05:06:16 UTC (rev 11038)
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 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 3, 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+import sys
+
+# dispatch codeword bits
+HAS_STREAM_ID       = 1 << 0;
+HAS_CLASS_ID        = 1 << 1;
+HAS_INTEGER_SECS    = 1 << 2;
+HAS_FRACTIONAL_SECS = 1 << 3;
+HAS_TRAILER         = 1 << 4;
+
+def main():
+    f = sys.stdout
+    header_len  = 32 * [0]
+    trailer_len = 32 * [0]
+
+    for cw in range(32):
+        t = 0
+        if cw & HAS_TRAILER:         t += 1
+        trailer_len[cw] = t
+
+        t = 1
+        if cw & HAS_STREAM_ID:       t += 1
+        if cw & HAS_CLASS_ID:        t += 2
+        if cw & HAS_INTEGER_SECS:    t += 1
+        if cw & HAS_FRACTIONAL_SECS: t += 2
+        header_len[cw] = t
+
+    write_table(f, "cw_header_len", header_len)
+    write_table(f, "cw_trailer_len", trailer_len)
+    
+def write_table(f, name, table):
+    f.write("inline static size_t ")
+    f.write(name)
+    f.write("(int cw){\n")
+
+    f.write("  static const size_t s_")
+    f.write(name)
+    f.write("[32] = {\n    ")
+    for t in table:
+        f.write("%d, " % (t,))
+    f.write("\n  };\n")
+
+    f.write("  return s_")
+    f.write(name)
+    f.write("[cw];\n}\n\n")
+
+
+if __name__ == '__main__':
+    main()


Property changes on: 
gnuradio/branches/developers/eb/vrt/vrt/lib/gen_cw_tables.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:eol-style
   + native

Added: gnuradio/branches/developers/eb/vrt/vrt/lib/gen_switch_body.py
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/gen_switch_body.py              
                (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/gen_switch_body.py      
2009-05-15 05:06:16 UTC (rev 11038)
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 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 3, 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+import sys
+
+# dispatch codeword bits
+HAS_STREAM_ID       = 1 << 0;
+HAS_CLASS_ID        = 1 << 1;
+HAS_INTEGER_SECS    = 1 << 2;
+HAS_FRACTIONAL_SECS = 1 << 3;
+HAS_TRAILER         = 1 << 4;
+
+def do_case(f, cw):
+
+    def do32(name, mask, index):
+        f.write("    ")
+        if cw & mask:
+            f.write("h->%s = ntohl(p[%d]);\n" % (name, index))
+            return 1
+        else:
+            f.write("h->%s = 0;\n" % (name,))
+            return 0
+        
+    def do64(name, mask, index):
+        f.write("    ")
+        if cw & mask:
+            f.write("h->%s = ((uint64_t)(ntohl(p[%d])) << 32) | 
ntohl(p[%d]);\n" % (name, index, index+1))
+            return 2
+        else:
+            f.write("h->%s = 0;\n" % (name,))
+            return 0
+
+    def dotrailer(name, mask):
+        f.write("    ")
+        if cw & mask:
+            f.write("h->%s = ntohl(p[len-1]);\n" % (name,))
+            return 1
+        else:
+            f.write("h->%s = 0;\n" % (name,))
+            return 0
+        
+    f.write("  case %d:\n" % (cw,))
+
+    index = 1
+    index += do32("stream_id", HAS_STREAM_ID, index)
+    index += do64("class_id",  HAS_CLASS_ID,  index)
+    index += do32("integer_secs", HAS_INTEGER_SECS, index)
+    index += do64("fractional_secs", HAS_FRACTIONAL_SECS, index)
+    dotrailer("trailer", HAS_TRAILER)
+    
+    f.write("    break;\n\n")
+        
+
+def main():
+    f = sys.stdout
+
+    for cw in range(32):
+        do_case(f, cw)
+
+
+if __name__ == '__main__':
+    main()


Property changes on: 
gnuradio/branches/developers/eb/vrt/vrt/lib/gen_switch_body.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:eol-style
   + native





reply via email to

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