source: hvcontrol/src/HVConfig.cc@ 63

Last change on this file since 63 was 46, checked in by lstark, 15 years ago
path of pixel map integrated in config file
File size: 6.7 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
14#include "ReadCard.h"
15#include "HVConfig.h"
16
17
18HVConfig::HVConfig(FILE* fptr, char *configfile) {
19
20 fLogPath = new char[FILENAME_MAX_SIZE];
21 fUSBDevice = new char*[MAX_NUM_HVBOARDS];
22 fCCClient = new char[FILENAME_MAX_SIZE];
23
24 fPixMapTable = new char[FILENAME_MAX_SIZE];
25
26 for (int i=0; i<MAX_NUM_HVBOARDS; i++) {
27 fUSBDevice[i] = new char[FILENAME_MAX_SIZE];
28 USBDeviceNumber[i] = 0;
29
30 for (int j=0; j<MAX_NUM_CHAINS; j++)
31 for (int k=0; k<2; k++)
32 Coef[i][j][k] = 0.;
33 }
34
35 NumHVBoards = 0;
36 FileName = configfile;
37 fStatusRefreshRate = 1.;
38 fTimeOut = 1.;
39 IsDAC = true;
40 DACMin = 11008;
41 DACMax = 12496;
42 HVMin = 67.0;
43 HVMax = 76.0;
44 fHVCalibOffset = -.8;
45 fHVCalibSlope = 0.0064;
46 fHVMaxDiff = 1.0;
47
48 if (configfile != NULL) {
49 if (!ReadHVConfig(fptr, configfile)) {
50 fprintf(fptr, "Error (HVConfig): could not configure HV control\n");
51 exit(1);
52 }
53 }
54}
55
56
57HVConfig::~HVConfig() {
58
59 delete [] fLogPath;
60 delete [] fPixMapTable;
61
62 for (int i=0; i<MAX_NUM_HVBOARDS; i++)
63 delete [] fUSBDevice[i];
64 delete [] fUSBDevice;
65
66}
67
68
69int HVConfig::ReadHVConfig(FILE* fptr, char *configfile) {
70
71 FILE *f;
72 char str[MAX_COM_SIZE], dev[MAX_COM_SIZE];
73 int j = 0;
74
75 if ((f = fopen(configfile,"r")) == NULL) {
76 fprintf(fptr,"Could not open configuration file: %s\n", configfile);
77 return 0;
78 }
79 else {
80 fprintf(fptr,"Opening configuration file: %s\n", configfile);
81 }
82
83 ReadCard("LogPath", fLogPath,'s',f);
84
85 ReadCard("PixMapTable",fPixMapTable,'s',f);
86
87 for (int i=0;i<MAX_NUM_HVBOARDS;i++) {
88 sprintf(str,"Board%d",i);
89
90 if (ReadCard(str, dev, 's', f)==0) {
91 USBDeviceNumber[j] = i;
92 sprintf(fUSBDevice[j++],"%s",dev);
93 NumHVBoards++;
94 }
95 }
96
97 ReadCard("TimeOut", &fTimeOut, 'f', f);
98 ReadCard("StatusRefreshRate", &fStatusRefreshRate, 'f', f);
99 ReadCard("CCPort", &fCCPort, 'I', f);
100 ReadCard("CCClient", fCCClient, 's', f);
101 ReadCard("IsDAC", &str, 's', f);
102 ReadCard("DACMin", &DACMin, 'I', f);
103 ReadCard("DACMax", &DACMax, 'I', f);
104 ReadCard("HVMin", &HVMin, 'f', f);
105 ReadCard("HVMax", &HVMax, 'f', f);
106 ReadCard("HVCalibOffset", &fHVCalibOffset, 'f', f);
107 ReadCard("HVCalibSlope", &fHVCalibSlope, 'f', f);
108 ReadCard("HVMaxDiff", &fHVMaxDiff, 'f', f);
109
110 if (strcmp(str,"TRUE"))
111 IsDAC = false;
112
113 fclose(f);
114 return 1;
115}
116
117
118int HVConfig::PrintHVConfig(FILE *fptr) {
119
120 fprintf(fptr,"\n");
121 fprintf(fptr,"********************************************* CONFIG ********************************************\n\n");
122
123 fprintf(fptr," HV control configuration (%s):\n\n", FileName);
124 fprintf(fptr," Log path: %s\n\n", fLogPath);
125 fprintf(fptr," Pixel map table: %s\n\n", fPixMapTable);
126 fprintf(fptr," %.2d USB devices:\n\n", NumHVBoards);
127
128 for (int i=0;i<NumHVBoards;i++)
129 fprintf(fptr," Board%d: %s\n", USBDeviceNumber[i], fUSBDevice[i]);
130
131 fprintf(fptr,"\n");
132 fprintf(fptr," TimeOut: %.2f s\n", fTimeOut);
133 fprintf(fptr," StatusRefreshRate: %.2f Hz\n\n",fStatusRefreshRate);
134 fprintf(fptr," CCPort: %d\n", fCCPort);
135 fprintf(fptr," CCClient: %s\n\n", fCCClient);
136 fprintf(fptr," Set DAC values: %s\n\n", IsDAC ? "yes" : "no");
137 fprintf(fptr," DACMin value: %d\n\n", DACMin);
138 fprintf(fptr," DACMax value: %d\n\n", DACMax);
139 fprintf(fptr," HVMin value: %f\n\n", HVMin);
140 fprintf(fptr," HVMax value: %f\n\n", HVMax);
141 fprintf(fptr," HVCalibOffset : %f\n\n", fHVCalibOffset);
142 fprintf(fptr," HVCalibSlope : %f\n\n", fHVCalibSlope);
143 fprintf(fptr," HVMaxDiff : %f\n\n", fHVMaxDiff);
144
145 fprintf(fptr,"*************************************************************************************************\n\n");
146
147 return 1;
148}
149
150
151int HVConfig::WriteHVConfig(FILE* fptr, char *configfile) {
152
153 FILE *f;
154
155 time_t time_now_secs;
156 struct tm *time_now;
157
158 time(&time_now_secs);
159 time_now = localtime(&time_now_secs);
160
161 if ((f = fopen(configfile,"w")) == NULL) {
162 fprintf(fptr,"Could not open file: %s\n", configfile);
163 return 0;
164 }
165
166 fprintf(f,"# Main configuration file for the HV control program %s, %04d %02d %02d, %02d:%02d:%02d\n",
167 HV_CONTROL_VERSION,
168 1900 + time_now->tm_year,
169 1 + time_now->tm_mon,
170 time_now->tm_mday,
171 time_now->tm_hour,
172 time_now->tm_min,
173 time_now->tm_sec);
174
175 fprintf(f,"# Note: this file will be updated at program exit\n\n");
176
177 fprintf(f,"LogPath %s\n\n", fLogPath);
178 fprintf(f,"PixMapTable %s\n\n", fPixMapTable);
179
180 fprintf(f,"TimeOut %.2f s # Timeout to return from read (%.2f,...%.2f) s\n\n",fTimeOut,MIN_TIMEOUT,MAX_TIMEOUT);
181
182 fprintf(f,"StatusRefreshRate %.2f Hz # Status update rate (%.2f,...%.2f) Hz\n\n",fStatusRefreshRate,MIN_RATE,MAX_RATE);
183
184 fprintf(f,"CCPort %d # Port used to look for commands from the Central Control\n",fCCPort);
185 fprintf(f,"CCClient %s # Central Control client name\n\n",fCCClient);
186 fprintf(f,"IsDAC %s # Define here if user input is interpreted as DAC value or voltage\n\n",((IsDAC) ? "TRUE" : "FALSE"));
187 fprintf(f,"DACMin %d # Starting point for calibration of DAC to voltage values\n",DACMin);
188 fprintf(f,"DACMax %d # End point for calibration of DAC to voltage values\n",DACMax);
189 fprintf(f,"HVMin %f # Starting point for calibration of voltage to DAC values\n",HVMin);
190 fprintf(f,"HVMax %f # End point for calibration of voltage to DAC values\n",HVMax);
191 fprintf(f,"HVCalibOffset %f # Calibration of DAC to voltage values\n",fHVCalibOffset);
192 fprintf(f,"HVCalibSlope %f # Calibration of DAC to voltage values\n\n",fHVCalibSlope);
193 fprintf(f,"HVMaxDiff %f # Speed for HV changes limited to 1V/ms\n",fHVMaxDiff);
194
195 fprintf(f,"# List of HV boards (at most %d HV boards will be recognized):\n",MAX_NUM_HVBOARDS);
196
197 for (int i=0;i<NumHVBoards;i++)
198 fprintf(f,"Board%d %s\n",USBDeviceNumber[i],fUSBDevice[i]);
199
200 fprintf(fptr,"Configuration file successfully updated\n");
201
202 fclose(f);
203 return 1;
204
205}
206
207
Note: See TracBrowser for help on using the repository browser.