CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
geninits.py
1 #!/usr/bin/python
2 
3 # libfreenect - an open source Kinect driver
4 #
5 # Copyright (C) 2010 Hector Martin "marcan" <hector@marcansoft.com>
6 #
7 # This code is licensed to you under the terms of the GNU GPL, version 2 or version 3;
8 # see:
9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 # http://www.gnu.org/licenses/gpl-3.0.txt
11 
12 import struct, sys
13 
14 fd = open(sys.argv[2], "w")
15 
16 count = 0;
17 
18 print >>fd, '#include "freenect_internal.h"'
19 print >>fd
20 print >>fd, "const struct caminit inits[] = {"
21 for line in open(sys.argv[1]):
22  line = line.replace("\n","").replace("\r","")
23  if line == "":
24  continue
25  if line[0] == "#":
26  continue
27  cmd,tag,cdata,rdata = line.split(",")
28  cmd = int(cmd,16)
29  tag = int(tag,16)
30 
31  cdata = cdata.decode('hex')
32  rdata = rdata.decode('hex')
33 
34  hcdata = ", ".join(["0x%02x"%ord(x) for x in cdata])
35  hrdata = ", ".join(["0x%02x"%ord(x) for x in rdata])
36 
37  print >>fd, "\t{"
38  print >>fd, "\t\t0x%02x, 0x%04x, %d, %d,"%(cmd, tag, len(cdata), len(rdata))
39  print >>fd, "\t\t{%s},"%hcdata
40  print >>fd, "\t\t{%s},"%hrdata
41  print >>fd, "\t},"
42  count += 1
43 print >>fd, "};"
44 print >>fd
45 print >>fd, "const int num_inits = %d;"%count;
46 print >>fd