7 from optparse import OptionParser
9 def write_header(f, comment_char):
10 f.write(comment_char); f.write('\n')
11 f.write(comment_char); f.write(' Machine generated by gen_usrp_dbid.py from usrp_dbid.dat\n')
12 f.write(comment_char); f.write(' Do not edit by hand. All edits will be overwritten.\n')
13 f.write(comment_char); f.write('\n')
17 f = open('usrp_dbid.py', 'w')
19 write_header(f, comment_char)
20 f.write(comment_char); f.write('\n')
21 f.write(comment_char); f.write(" USRP Daughterboard ID's\n")
22 f.write(comment_char); f.write('\n')
25 f.write('%-16s = %s\n' % (x[1], x[2]))
28 f = open('usrp_dbid.h', 'w')
30 write_header(f, comment_char)
31 f.write(comment_char); f.write('\n')
32 f.write(comment_char); f.write(" USRP Daughterboard ID's\n")
33 f.write(comment_char); f.write('\n')
35 f.write('#ifndef INCLUDED_USRP_DBID_H\n')
36 f.write('#define INCLUDED_USRP_DBID_H\n')
39 f.write('#define %-25s %s\n' % ('USRP_DBID_' + x[1], x[2]))
41 f.write('#endif /* INCLUDED_USRP_DBID_H */\n')
44 f = open('usrp_dbid.cc', 'w')
47 * Copyright 2005 Free Software Foundation, Inc.
49 * This file is part of GNU Radio
51 * GNU Radio is free software; you can redistribute it and/or modify
52 * it under the terms of the GNU General Public License as published by
53 * the Free Software Foundation; either version 3, or (at your option)
56 * GNU Radio is distributed in the hope that it will be useful,
57 * but WITHOUT ANY WARRANTY; without even the implied warranty of
58 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59 * GNU General Public License for more details.
61 * You should have received a copy of the GNU General Public License
62 * along with GNU Radio; see the file COPYING. If not, write to
63 * the Free Software Foundation, Inc., 51 Franklin Street,
64 * Boston, MA 02110-1301, USA.
67 #include <usrp_prims.h>
68 #include <usrp_dbid.h>
71 #define NELEM(x) sizeof(x)/sizeof(x[0])
82 usrp_dbid_to_string (int dbid)
88 return "<invalid EEPROM contents>";
90 for (unsigned i = 0; i < NELEM (dbid_map); i++)
91 if (dbid == dbid_map[i].dbid)
92 return dbid_map[i].name;
95 snprintf (tmp, sizeof (tmp), "Unknown (0x%04x)", dbid);
101 f.write(' { %-27s "%s" },\n' % (
102 'USRP_DBID_' + x[1] + ',', x[0]))
105 def gen_all(src_filename):
106 src_file = open(src_filename, 'r')
108 for line in src_file:
110 line = re.sub(r'\s*#.*$','', line)
113 mo = re.match('"([^"]+)"\s*(0x[0-9a-fA-F]+)', line)
115 str_name = mo.group(1)
116 id_name = str_name.upper().replace(' ', '_')
118 r.append((str_name, id_name, id_val))
119 #sys.stdout.write('%-16s\t%-16s\t%s\n' % ('"'+str_name+'"', id_name, id_val))
127 usage = "usage: %prog [options] usrp_dbid.dat"
128 parser = OptionParser(usage=usage)
129 (options, args) = parser.parse_args()
136 if __name__ == '__main__':