source: hvcontrol/src/HVStatus.cc@ 40

Last change on this file since 40 was 39, checked in by lstark, 16 years ago
several bugs fixed, higher precision reached
File size: 5.3 KB
Line 
1
2/********************************************************************\
3
4 Name: HVStatus.cc
5
6 Created by: Sebastian Commichau, November 2008
7 commichau@phys.ethz.ch
8
9 Contents: Store HV supply status information
10
11\********************************************************************/
12
13#include "HVStatus.h"
14
15static char* state_str[] = {"active", "stopped", "n.a."};
16static char* isok_str[] = {"error", "ok"};
17static char* cc_state_str[] = {"disconnected", "connected"};
18
19void InitStatus(Status* status, HVConfig* config) {
20
21 status->state = active;
22 status->cc_state = disconnected;
23 status->Exit = FALSE;
24 status->Stop = FALSE;
25 status->Log = TRUE;
26 status->Verbose = FALSE;
27 status->CCCommand = FALSE;
28
29 status->Socket = -1;
30 sprintf(status->CCClient,"%s", config->fCCClient);
31 status->CCPort = config->fCCPort;
32
33
34 status->fUSBDevice = new char*[MAX_NUM_HVBOARDS];
35
36 for (int i=0; i<MAX_NUM_HVBOARDS; i++) {
37 status->fUSBDevice[i] = new char[FILENAME_MAX_SIZE];
38 status->USBDeviceNumber[i] = USB_MAX_DEVICE_NUMBER+1;
39 }
40
41 status->USBMinDeviceNumber = USB_MAX_DEVICE_NUMBER;
42 status->USBMaxDeviceNumber = USB_MIN_DEVICE_NUMBER;
43
44 for (int i=0;i<MAX_NUM_HVBOARDS;i++) {
45 status->IsUpdated[i] = FALSE;
46 status->isok[i] = TRUE;
47 status->MR[i] = FALSE;
48 status->WC[0][i] = 0;
49 status->WC[1][i] = 1;
50
51 for (int j=0;j<MAX_NUM_CHAINS;j++) {
52 status->VRef[i][j] = 0;
53 status->OC[i][j] = FALSE;
54
55 for (int k=0;k<MAX_NUM_CHANNELS;k++){
56 status->HV[i][j][k] = 0;
57 status->HVV[i][j][k] = 0.0;
58 }
59 }
60 }
61
62 status->NumHVBoards = 0;
63 status->FirstBoard = 0;
64 status->LastBoard = -1;
65
66 status->FirstChain = 0;
67 status->LastChain = 3;
68
69
70 if (config->fTimeOut >= (float)MIN_TIMEOUT && config->fTimeOut <= (float)MAX_TIMEOUT)
71 status->fTimeOut = config->fTimeOut;
72 else
73 status->fTimeOut = 1.;
74
75 if (config->fStatusRefreshRate >= (float)MIN_RATE && config->fStatusRefreshRate <= (float)MAX_RATE)
76 status->fStatusRefreshRate = config->fStatusRefreshRate;
77 else
78 status->fStatusRefreshRate = 1.;
79}
80
81
82void ReInitStatus(Status* status) {
83
84 for (int i=0;i<MAX_NUM_HVBOARDS;i++) {
85 status->IsUpdated[i] = FALSE;
86 for (int j=0;j<MAX_NUM_CHAINS;j++) {
87 status->VRef[i][j] = 0;
88 for (int k=0;k<MAX_NUM_CHANNELS;k++)
89 status->HV[i][j][k] = 0;
90 }
91 }
92
93}
94
95
96void ReInitStatusOneBoard(Status* status, int board) {
97
98 status->IsUpdated[board] = FALSE;
99 for (int j=0;j<MAX_NUM_CHAINS;j++) {
100 status->VRef[board][j] = 0;
101 for (int k=0;k<MAX_NUM_CHANNELS;k++)
102 status->HV[board][j][k] = 0;
103 }
104
105}
106
107
108void PrintStatus(Status* status, HVConfig* config, FILE* fptr) {
109
110 fprintf(fptr,"\n");
111 fprintf(fptr,"********************************************* STATUS ********************************************\n\n");
112 fprintf(fptr," Status monitor: %s\n",state_str[status->state]);
113 fprintf(fptr," Logging: %s\n", ((status->Log) ? "on" : "off"));
114 fprintf(fptr," Verbose: %s\n", ((status->Verbose) ? "on" : "off"));
115 fprintf(fptr," Timeout [s]: %.2f\n",status->fTimeOut);
116 fprintf(fptr," Status refresh rate [Hz]: %.2f\n",status->fStatusRefreshRate);
117 fprintf(fptr," CC state: %s\n", cc_state_str[status->cc_state]);
118 fprintf(fptr," CC client: %s\n", status->CCClient);
119 fprintf(fptr," CC port: %d\n", status->CCPort);
120 fprintf(fptr," Total number of HV boards: %d\n", status->NumHVBoards);
121 if (!status->NumHVBoards)
122 fprintf(fptr," Active HV boards: 0\n\n");
123 else if (status->NumHVBoards == ((status->LastBoard - status->FirstBoard) + 1))
124 fprintf(fptr," Active HV boards: all\n\n");
125 else
126 fprintf(fptr," Active HV boards: %d\n\n", (status->LastBoard - status->FirstBoard) + 1);
127
128 for (int i=status->FirstBoard;i<=status->LastBoard;i++) {
129 fprintf(fptr," BOARD %d (%s):\n",status->USBDeviceNumber[i],status->fUSBDevice[i]);
130 fprintf(fptr," Wrap counter: %s (%d)\n",isok_str[status->isok[i]], status->WC[1][i]);
131 fprintf(fptr," Manual reset: %s\n\n",((status->MR[i]) ? "yes" : "no"));
132
133 for (int j=status->FirstChain;j<=status->LastChain;j++) {
134 fprintf(fptr," CHAIN %d:\n",j);
135 fprintf(fptr," Over-current: %s\n",((status->OC[i][j]) ? "yes" : "no"));
136 fprintf(fptr," Reference voltage: %d\n",status->VRef[i][j]);
137 fprintf(fptr," High voltage:\n");
138 for (int k=0;k<4;k++) {
139 fprintf(fptr," Channels %.2d-%.2d: ",k*8,k*8+7);
140 for (int l=0;l<8;l++)
141 fprintf(fptr," %5d ",status->HV[i][j][k*8+l]);
142 fprintf(fptr,"\n");
143 }
144 fprintf(fptr,"\n");
145 }
146 }
147
148
149 fprintf(fptr,"*************************************************************************************************\n\n");
150
151}
152
153
154void sPrintStatus(Status* status, char* str, int i) {
155
156 sprintf(str,"status board %d (%s): MR %s OC0 %s OC1 %s OC2 %s OC3 %s WC %s (%d)\n",status->USBDeviceNumber[i],status->fUSBDevice[i],
157 ((status->MR[i]) ? "yes" : "no"),
158 ((status->OC[i][0]) ? "yes" : "no"),
159 ((status->OC[i][1]) ? "yes" : "no"),
160 ((status->OC[i][2]) ? "yes" : "no"),
161 ((status->OC[i][3]) ? "yes" : "no"),
162 isok_str[status->isok[i]],
163 status->WC[1][i]);
164
165 if (status->Socket != -1) // Print status string to socket if open
166 write(status->Socket,str,strlen(str)+1);
167
168}
169
170
171char* GetStateStr(Status* status) {
172
173 return state_str[status->state];
174
175}
Note: See TracBrowser for help on using the repository browser.