Merged VRT work-in-progress from eb/vrt2 (11518:11598) into trunk.
[debian/gnuradio] / vrt / lib / gen_cw_tables.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 main():
32     f = sys.stdout
33     header_len  = 32 * [0]
34     trailer_len = 32 * [0]
35
36     for cw in range(32):
37         t = 0
38         if cw & HAS_TRAILER:         t += 1
39         trailer_len[cw] = t
40
41         t = 1
42         if cw & HAS_STREAM_ID:       t += 1
43         if cw & HAS_CLASS_ID:        t += 2
44         if cw & HAS_INTEGER_SECS:    t += 1
45         if cw & HAS_FRACTIONAL_SECS: t += 2
46         header_len[cw] = t
47
48     write_table(f, "cw_header_len", header_len)
49     write_table(f, "cw_trailer_len", trailer_len)
50     
51 def write_table(f, name, table):
52     f.write("inline static size_t ")
53     f.write(name)
54     f.write("(int cw){\n")
55
56     f.write("  static const size_t s_")
57     f.write(name)
58     f.write("[32] = {\n    ")
59     for t in table:
60         f.write("%d, " % (t,))
61     f.write("\n  };\n")
62
63     f.write("  return s_")
64     f.write(name)
65     f.write("[cw];\n}\n\n")
66
67
68 if __name__ == '__main__':
69     main()