source: hvcontrol/src/HVStatus.cc@ 20

Last change on this file since 20 was 14, checked in by lstark, 16 years ago
first version of hvcontrol added
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 }
58 }
59
60 status->NumHVBoards = 0;
61 status->FirstBoard = 0;
62 status->LastBoard = -1;
63
64 status->FirstChain = 0;
65 status->LastChain = 3;
66
67
68 if (config->fTimeOut >= (float)MIN_TIMEOUT && config->fTimeOut <= (float)MAX_TIMEOUT)
69 status->fTimeOut = config->fTimeOut;
70 else
71 status->fTimeOut = 1.;
72
73 if (config->fStatusRefreshRate >= (float)MIN_RATE && config->fStatusRefreshRate <= (float)MAX_RATE)
74 status->fStatusRefreshRate = config->fStatusRefreshRate;
75 else
76 status->fStatusRefreshRate = 1.;
77}
78
79
80void ReInitStatus(Status* status) {
81
82 for (int i=0;i<MAX_NUM_HVBOARDS;i++) {
83 status->IsUpdated[i] = FALSE;
84 for (int j=0;j<MAX_NUM_CHAINS;j++) {
85 status->VRef[i][j] = 0;
86 for (int k=0;k<MAX_NUM_CHANNELS;k++)
87 status->HV[i][j][k] = 0;
88 }
89 }
90
91}
92
93
94void ReInitStatusOneBoard(Status* status, int board) {
95
96 status->IsUpdated[board] = FALSE;
97 for (int j=0;j<MAX_NUM_CHAINS;j++) {
98 status->VRef[board][j] = 0;
99 for (int k=0;k<MAX_NUM_CHANNELS;k++)
100 status->HV[board][j][k] = 0;
101 }
102
103}
104
105
106void PrintStatus(Status* status, HVConfig* config, FILE* fptr) {
107
108 fprintf(fptr,"\n");
109 fprintf(fptr,"********************************************* STATUS ********************************************\n\n");
110 fprintf(fptr," Status monitor: %s\n",state_str[status->state]);
111 fprintf(fptr," Logging: %s\n", ((status->Log) ? "on" : "off"));
112 fprintf(fptr," Verbose: %s\n", ((status->Verbose) ? "on" : "off"));
113 fprintf(fptr," Timeout [s]: %.2f\n",status->fTimeOut);
114 fprintf(fptr," Status refresh rate [Hz]: %.2f\n",status->fStatusRefreshRate);
115 fprintf(fptr," CC state: %s\n", cc_state_str[status->cc_state]);
116 fprintf(fptr," CC client: %s\n", status->CCClient);
117 fprintf(fptr," CC port: %d\n", status->CCPort);
118 fprintf(fptr," Total number of HV boards: %d\n", status->NumHVBoards);
119 if (!status->NumHVBoards)
120 fprintf(fptr," Active HV boards: 0\n\n");
121 else if (status->NumHVBoards == ((status->LastBoard - status->FirstBoard) + 1))
122 fprintf(fptr," Active HV boards: all\n\n");
123 else
124 fprintf(fptr," Active HV boards: %d\n\n", (status->LastBoard - status->FirstBoard) + 1);
125
126 for (int i=status->FirstBoard;i<=status->LastBoard;i++) {
127 fprintf(fptr," BOARD %d (%s):\n",status->USBDeviceNumber[i],status->fUSBDevice[i]);
128 fprintf(fptr," Wrap counter: %s (%d)\n",isok_str[status->isok[i]], status->WC[1][i]);
129 fprintf(fptr," Manual reset: %s\n\n",((status->MR[i]) ? "yes" : "no"));
130
131 for (int j=status->FirstChain;j<=status->LastChain;j++) {
132 fprintf(fptr," CHAIN %d:\n",j);
133 fprintf(fptr," Over-current: %s\n",((status->OC[i][j]) ? "yes" : "no"));
134 fprintf(fptr," Reference voltage: %d\n",status->VRef[i][j]);
135 fprintf(fptr," High voltage:\n");
136 for (int k=0;k<4;k++) {
137 fprintf(fptr," Channels %.2d-%.2d: ",k*8,k*8+7);
138 for (int l=0;l<8;l++)
139 fprintf(fptr," %5d ",status->HV[i][j][k*8+l]);
140 fprintf(fptr,"\n");
141 }
142 fprintf(fptr,"\n");
143 }
144 }
145
146
147 fprintf(fptr,"*************************************************************************************************\n\n");
148
149}
150
151
152void sPrintStatus(Status* status, char* str, int i) {
153
154 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],
155 ((status->MR[i]) ? "yes" : "no"),
156 ((status->OC[i][0]) ? "yes" : "no"),
157 ((status->OC[i][1]) ? "yes" : "no"),
158 ((status->OC[i][2]) ? "yes" : "no"),
159 ((status->OC[i][3]) ? "yes" : "no"),
160 isok_str[status->isok[i]],
161 status->WC[1][i]);
162
163 if (status->Socket != -1) // Print status string to socket if open
164 write(status->Socket,str,strlen(str));
165
166}
167
168
169char* GetStateStr(Status* status) {
170
171 return state_str[status->state];
172
173}
Note: See TracBrowser for help on using the repository browser.