source: hvcontrol/src/HVConfig.cc@ 97

Last change on this file since 97 was 93, checked in by ogrimm, 15 years ago
Added writing of slow data
File size: 3.8 KB
Line 
1
2/********************************************************************\
3
4 Name: HVConfig.cc
5
6 Created by: Sebastian Commichau, November 2008
7 commichau@phys.ethz.ch
8
9 Contents: Class reading the HV utility configuration file
10
11\********************************************************************/
12
13#include "HVConfig.h"
14
15
16HVConfig::HVConfig(const char *configfile) {
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 // Read configuration file
36 FILE *f;
37 char str[MAX_COM_SIZE], dev[MAX_COM_SIZE];
38 int j = 0;
39
40 if ((f = fopen(configfile,"r")) == NULL) {
41 printf("Could not open configuration file: %s\n", configfile);
42 throw;
43 }
44 else printf("Opening configuration file: %s\n", configfile);
45
46 ReadCard("LogFile", fLogFile, 's',f);
47 ReadCard("PixMapTable", fPixMapTable,'s',f);
48 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 ReadCard("TimeOut", &fTimeOut, 'f', f);
64 ReadCard("StatusRefreshRate", &fStatusRefreshRate, 'f', f);
65 ReadCard("CCPort", &fCCPort, 'I', f);
66 ReadCard("DACMin", &DACMin, 'I', f);
67 ReadCard("DACMax", &DACMax, 'I', f);
68 ReadCard("HVCalibOffset", &fHVCalibOffset, 'f', f);
69 ReadCard("HVCalibSlope", &fHVCalibSlope, 'f', f);
70 ReadCard("HVMaxDiff", &fHVMaxDiff, 'U', f);
71
72 fclose(f);
73}
74
75
76HVConfig::~HVConfig() {
77
78 for (int i=0; i<MAX_NUM_HVBOARDS; i++) delete [] fUSBDevice[i];
79 delete [] fUSBDevice;
80}
81
82
83// ReadCard function (original version by F. Goebel)
84// Data is read into an array if MaxNum is larger than 1
85bool ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) {
86
87 char *card_name, *card_val, Buffer[MAX_COM_SIZE];
88 unsigned int Count=0;
89
90 rewind(File);
91
92 while (fgets(Buffer, sizeof(Buffer), File) != NULL) { // Read line by line
93 card_name = strtok(Buffer," \t\n");
94
95 // Ignore empty lines, comments, and skip if card name does not match
96 if (card_name==NULL || card_name[0]=='#' || strcmp(card_name, card_flag)!=0) continue;
97
98 // Read numbers of given type (if MaxNum>1 read array)
99 while ((card_val=strtok(NULL," \t\n")) != NULL && Count++<MaxNum) {
100 switch (Type) {
101 case 'I': *(((int *&) store)++) = (int) strtol(card_val, NULL, 10);
102 break;
103 case 'i': *(((short *&) store)++) = (short) strtol(card_val, NULL, 10);
104 break;
105 case 'U': *(((unsigned int *&) store)++) = (unsigned int) strtoul(card_val, NULL, 10);
106 break;
107 case 'u': *(((unsigned short *&) store)++) = (unsigned short) strtoul(card_val, NULL, 10);
108 break;
109 case 'f': *(((float *&) store)++) = atof(card_val);
110 break;
111 case 'd': *(((double *&) store)++) = atof(card_val);
112 break;
113 case 's': sprintf((char *) store, "%s", card_val);
114 break;
115 case 'c': *((char *) store) = card_val[0];
116 break;
117 default: fprintf(stderr,"Warning: Unknown type '%c' for reading of configuration file\n", Type);
118 return false;
119 }
120 }
121 return true; // Finished reading data for card name
122 }
123 return false;
124}
125
Note: See TracBrowser for help on using the repository browser.