source: hvcontrol/src/HVConfig.cc@ 80

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