source: hvcontrol/src/HVConfig.cc@ 40

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