Update revision to release 3.3.0-rc1, update autotools
[debian/gnuradio] / vrt / lib / gen_unparse_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         if cw & mask:
35             f.write("    header[%d] = htonl(h->%s);\n" % (index, name))
36             return 1
37         return 0
38         
39     def do64(name, mask, index):
40         if cw & mask:
41             f.write("    header[%d] = htonl((uint32_t)((h->%s >> 32) & 0xffffffff));\n" % (index, name))
42             f.write("    header[%d] = htonl((uint32_t)((h->%s >>  0) & 0xffffffff));\n" % (index+1, name))
43             return 2
44         return 0
45
46     def dolength(index):
47         f.write("    *n32_bit_words_header = %d;\n"%index)
48
49     def dotrailer(name, mask):
50         if cw & mask:
51             f.write("    trailer[%d] = htonl(h->%s);\n" % (0, name))
52             f.write("    *n32_bit_words_trailer = 1;\n")
53             return 1
54         else:
55             f.write("    *n32_bit_words_trailer = 0;\n")
56             return 0
57         
58     f.write("  case %d:\n" % (cw,))
59
60     index = 1
61     index += do32("stream_id", HAS_STREAM_ID, index)
62     index += do64("class_id",  HAS_CLASS_ID,  index)
63     index += do32("integer_secs", HAS_INTEGER_SECS, index)
64     index += do64("fractional_secs", HAS_FRACTIONAL_SECS, index)
65     dolength(index)
66     dotrailer("trailer", HAS_TRAILER)
67     
68     f.write("    break;\n\n")
69         
70
71 def main():
72     f = sys.stdout
73
74     for cw in range(32):
75         do_case(f, cw)
76
77
78 if __name__ == '__main__':
79     main()