Root/Software/xc3sprog/devicedb.cpp

1/* JTAG chain device database
2
3Copyright (C) 2004 Andrew Rogers
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
19
20#include "devicedb.h"
21
22using namespace std;
23
24DeviceDB::DeviceDB(const char *fname)
25{
26  filename=fname;
27  FILE *fp=fopen(fname,"rt");
28  if(fp==0)fprintf(stderr,"Cannot open device database file '%s'\n",fname);
29  else fclose(fp);
30}
31
32int DeviceDB::loadDevice(const unsigned long id)
33{
34  FILE *fp=fopen(filename.c_str(),"rt");
35  if(fp==0){
36    fprintf(stderr,"Cannot open device database file '%s'\n",filename.c_str());
37    return 0;
38  }
39  
40  int irlen;
41  while(!feof(fp)){
42    unsigned long idr;
43    char text[256];
44    char buffer[256];
45    fgets(buffer,256,fp); // Get next line from file
46    sscanf(buffer,"%08x %d %s",&idr,&irlen,text);
47    if(id==idr){
48      device_t dev;
49      dev.text=text;
50      dev.idcode=idr;
51      dev.irlen=irlen;
52      devices.push_back(dev);
53      fclose(fp);
54      return irlen;
55    }
56  }
57  fclose(fp);
58  return 0;
59}
60
61int DeviceDB::getIRLength(int i)
62{
63  if(i>=devices.size())return 0;
64  return devices[i].irlen;
65}
66
67const char *DeviceDB::getDeviceDescription(int i)
68{
69  if(i>=devices.size())return 0;
70  return devices[i].text.c_str();
71}
72

Archive Download this file

Branches:
master



interactive