Changeset 100 for hvcontrol/src/HVConfig.cc
- Timestamp:
- 08/12/09 12:15:02 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/src/HVConfig.cc
r93 r100 16 16 HVConfig::HVConfig(const char *configfile) { 17 17 18 fUSBDevice = new char*[MAX_NUM_HVBOARDS];19 20 for (int i=0; i<MAX_NUM_HVBOARDS; i++) {21 fUSBDevice[i] = new char[BUFFER_LENGTH];22 USBDeviceNumber[i] = 0;23 }24 25 TestMode = false;26 NumHVBoards = 0;27 fStatusRefreshRate = 1.;28 fTimeOut = 1.;29 DACMin = 11008;30 DACMax = 12496;31 fHVCalibOffset = -.8;32 fHVCalibSlope = 0.0064;33 fHVMaxDiff = 1;34 35 18 // Read configuration file 36 19 FILE *f; 37 char str[MAX_COM_SIZE], dev[MAX_COM_SIZE];38 int j = 0;39 20 40 21 if ((f = fopen(configfile,"r")) == NULL) { … … 42 23 throw; 43 24 } 44 elseprintf("Opening configuration file: %s\n", configfile);25 printf("Opening configuration file: %s\n", configfile); 45 26 27 // Determine number of entries in 'Boards' card and allocate memeory 28 NumHVBoards = (int) ReadCard("Boards", NULL, 'n', f); 29 fUSBDevice = new char* [NumHVBoards]; 30 for (int i=0; i<NumHVBoards; i++) fUSBDevice[i] = new char [BUFFER_LENGTH]; 31 ReadCard("Boards", fUSBDevice, 'S', f, NumHVBoards); 32 46 33 ReadCard("LogFile", fLogFile, 's',f); 47 34 ReadCard("PixMapTable", fPixMapTable,'s',f); 48 35 ReadCard("SlowDirectory", fSlowDir, 's',f); 49 50 ReadCard("TestMode", &str, 's',f);51 if (!strcmp(str,"TRUE")) TestMode = true;52 53 for (int i=0; i<MAX_NUM_HVBOARDS; i++) {54 sprintf(str,"Board%d",i);55 56 if (ReadCard(str, dev, 's', f)) {57 USBDeviceNumber[j] = i;58 sprintf(fUSBDevice[j++],"%s",dev);59 NumHVBoards++;60 }61 }62 63 36 ReadCard("TimeOut", &fTimeOut, 'f', f); 64 37 ReadCard("StatusRefreshRate", &fStatusRefreshRate, 'f', f); … … 76 49 HVConfig::~HVConfig() { 77 50 78 for (int i=0; i< MAX_NUM_HVBOARDS; i++) delete[] fUSBDevice[i];79 delete 51 for (int i=0; i<NumHVBoards; i++) delete[] fUSBDevice[i]; 52 delete[] fUSBDevice; 80 53 } 81 54 … … 83 56 // ReadCard function (original version by F. Goebel) 84 57 // Data is read into an array if MaxNum is larger than 1 85 bool ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) { 58 // If Type is 'n', the number of elements for the card is counted. 59 // Type 'S' is for reading an array of strings 60 unsigned int ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) { 86 61 87 62 char *card_name, *card_val, Buffer[MAX_COM_SIZE]; … … 97 72 98 73 // Read numbers of given type (if MaxNum>1 read array) 99 while ((card_val=strtok(NULL," \t\n")) != NULL&& Count++<MaxNum) {74 while ((card_val=strtok(NULL," \t\n"))!=NULL && card_val[0]!='#' && Count++<MaxNum) { 100 75 switch (Type) { 101 76 case 'I': *(((int *&) store)++) = (int) strtol(card_val, NULL, 10); … … 113 88 case 's': sprintf((char *) store, "%s", card_val); 114 89 break; 115 case 'c': *((char *) store) = card_val[0]; 90 case 'S': sprintf(*(((char **&) store)++), "%s", card_val); 91 break; 92 case 'c': *(((char *&) store)++) = card_val[0]; 93 break; 94 case 'n': MaxNum = UINT_MAX; 116 95 break; 117 96 default: fprintf(stderr,"Warning: Unknown type '%c' for reading of configuration file\n", Type); 118 return false;97 return 0; 119 98 } 120 99 } 121 return true; // Finished reading data for card name100 return Count; // Finished reading data for card name 122 101 } 123 return false;102 return 0; 124 103 } 125 104
Note:
See TracChangeset
for help on using the changeset viewer.