Ignore:
Timestamp:
08/12/09 12:15:02 (15 years ago)
Author:
ogrimm
Message:
Number of HV boards (almost) unlimited.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/HVConfig.cc

    r93 r100  
    1616HVConfig::HVConfig(const char *configfile) {
    1717
    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  
    3518  // Read configuration file
    3619  FILE *f;
    37   char str[MAX_COM_SIZE], dev[MAX_COM_SIZE];
    38   int j = 0;
    3920
    4021  if ((f = fopen(configfile,"r")) == NULL) {
     
    4223    throw;
    4324  }
    44   else printf("Opening configuration file: %s\n", configfile);
     25  printf("Opening configuration file: %s\n", configfile);
    4526 
     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
    4633  ReadCard("LogFile",       fLogFile,    's',f);
    4734  ReadCard("PixMapTable",   fPixMapTable,'s',f);
    4835  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  
    6336  ReadCard("TimeOut",           &fTimeOut,           'f', f);
    6437  ReadCard("StatusRefreshRate", &fStatusRefreshRate, 'f', f);
     
    7649HVConfig::~HVConfig() {
    7750
    78   for (int i=0; i<MAX_NUM_HVBOARDS; i++) delete [] fUSBDevice[i];
    79   delete [] fUSBDevice;
     51  for (int i=0; i<NumHVBoards; i++) delete[] fUSBDevice[i];
     52  delete[] fUSBDevice;
    8053}
    8154
     
    8356// ReadCard function (original version by F. Goebel)
    8457// 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
     60unsigned int ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) {
    8661 
    8762  char *card_name, *card_val, Buffer[MAX_COM_SIZE];
     
    9772
    9873    // 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) {
    10075      switch (Type) {
    10176        case 'I': *(((int *&) store)++) = (int) strtol(card_val, NULL, 10);
     
    11388        case 's': sprintf((char *) store, "%s", card_val);
    11489                  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;
    11695                  break;
    11796        default:  fprintf(stderr,"Warning: Unknown type '%c' for reading of configuration file\n", Type);
    118                   return false;
     97                  return 0;
    11998      }
    12099    }
    121     return true;  // Finished reading data for card name 
     100    return Count;  // Finished reading data for card name 
    122101  }
    123   return false;
     102  return 0;
    124103}
    125104
Note: See TracChangeset for help on using the changeset viewer.