Update revision to release 3.3.0-rc1, update autotools
[debian/gnuradio] / vrt / lib / gen_parse_switch_body.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2009 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 import sys
23
24 # dispatch codeword bits
25 HAS_STREAM_ID       = 1 << 0;
26 HAS_CLASS_ID        = 1 << 1;
27 HAS_INTEGER_SECS    = 1 << 2;
28 HAS_FRACTIONAL_SECS = 1 << 3;
29 HAS_TRAILER         = 1 << 4;
30
31 def do_case(f, cw):
32
33     def do32(name, mask, index):
34         f.write("    ")
35         if cw & mask:
36             f.write("h->%s = ntohl(p[%d]);\n" % (name, index))
37             return 1
38         else:
39             f.write("h->%s = 0;\n" % (name,))
40             return 0
41         
42     def do64(name, mask, index):
43         f.write("    ")
44         if cw & mask:
45             f.write("h->%s = ((uint64_t)(ntohl(p[%d])) << 32) | ntohl(p[%d]);\n" % (name, index, index+1))
46             return 2
47         else:
48             f.write("h->%s = 0;\n" % (name,))
49             return 0
50
51     def dolength(index):
52         f.write("    n32_bit_words_header = %d;\n"%index)
53
54     def dotrailer(name, mask):
55         if cw & mask:
56             f.write("    h->%s = ntohl(p[len-1]);\n" % (name,))
57             f.write("    n32_bit_words_trailer = 1;\n")
58             return 1
59         else:
60             f.write("    h->%s = 0;\n" % (name,))
61             f.write("    n32_bit_words_trailer = 0;\n")
62             return 0
63         
64     f.write("  case %d:\n" % (cw,))
65
66     index = 1
67     index += do32("stream_id", HAS_STREAM_ID, index)
68     index += do64("class_id",  HAS_CLASS_ID,  index)
69     index += do32("integer_secs", HAS_INTEGER_SECS, index)
70     index += do64("fractional_secs", HAS_FRACTIONAL_SECS, index)
71     dolength(index)
72     dotrailer("trailer", HAS_TRAILER)
73     
74     f.write("    break;\n\n")
75         
76
77 def main():
78     f = sys.stdout
79
80     for cw in range(32):
81         do_case(f, cw)
82
83
84 if __name__ == '__main__':
85     main()