AlcapDAQ  1
Functions | Variables
frontend.c File Reference
#include <stdio.h>
#include "midas.h"

Go to the source code of this file.

Functions

INT read_temperature_probe (char *pevent, INT off)
 
INT pre_begin_of_run ()
 
INT frontend_early_init ()
 
INT poll_event (INT source[], INT count, BOOL test)
 
INT interrupt_configure (INT cmd, INT source[], PTYPE adr)
 
INT frontend_init ()
 
INT frontend_exit ()
 
INT frontend_loop ()
 
INT begin_of_run (INT run_number, char *error)
 
INT end_of_run (INT run_number, char *error)
 
INT pause_run (INT run_number, char *error)
 
INT resume_run (INT run_number, char *error)
 

Variables

INT crate_number =0
 
HNDLE hDB
 
HNDLE hKey
 
int size
 
int sepDemand
 
char Alarm [128] = "/Equipment/TemperatureMonitor/Variables/Alarm_Triggered"
 
char * frontend_name = "TemperatureMonitor"
 
char * frontend_file_name = __FILE__
 
BOOL frontend_call_loop = TRUE
 
INT display_period = 1000
 
INT max_event_size = 10000
 
INT max_event_size_frag = 5 * 1024 * 1024
 
INT event_buffer_size = 10 * 10000
 
BANK_LIST temperature_bank_list []
 
EQUIPMENT equipment []
 

Function Documentation

INT begin_of_run ( INT  run_number,
char *  error 
)

Definition at line 191 of file frontend.c.

192 {
193  return CM_SUCCESS;
194 }
INT end_of_run ( INT  run_number,
char *  error 
)

Definition at line 198 of file frontend.c.

199 {
200  return CM_SUCCESS;
201 }
INT frontend_early_init ( void  )

Definition at line 145 of file crate.cpp.

References crate_number, equipment, FALSE, frontend_index, frontend_name, i, printf(), sprintf(), and SUCCESS.

146 {
147  // Determine our crate ID by comparing against a list of hostnames
148  printf("Entering frontend_early_init ... \n");
149  //char *hostnames[] = {"fe1", "fe2", "fe3", "turtle", "fe5", "fe6"};
150  //char *hostnames[] = {"fe1", "fe2", "daq2.MuSIC", "fe4", "fe5", "fe6", "fe7"};
151  //int crate_numbers[] = {1, 2, 3, 4, 5, 6, 9};
152  //char *hostnames[] = {"daq2.MuSIC"};
153  //int crate_numbers[] = {3};
154  //BOOL crate_has_periodic[] = {FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE};
155 
156  //int num_hostnames = sizeof(hostnames)/sizeof(char *);
157 
158  //char my_hostname[256];
159 
160  //gethostname(my_hostname, sizeof(my_hostname));
161 
162 #if 0
163  BOOL has_periodic = FALSE;
164  for(int i = 0; i < num_hostnames; i++) {
165  if(!strcmp(my_hostname, hostnames[i])) {
166  crate_number = crate_numbers[i];
167  has_periodic = crate_has_periodic[i];
168  }
169  }
170 #endif
171 
172  crate_number = 3;
173  BOOL has_periodic = FALSE;
174 
175  printf("Hostname and crate cumber defined, crate number = %d ... \n",crate_number);
176 
177  if(crate_number > 0) {
178  frontend_name = new char[32];
179  strcpy(frontend_name, "Crate ");
180 
181 
182 #if 0
183  sprintf(equipment[0].name, "Crate %d", crate_number);
184  sprintf(equipment[0].info.buffer, "BUF%d", crate_number);
185  equipment[0].info.event_id = 1000 + crate_number;
186 #endif
188 
189  printf("Crate number = %d\n",crate_number);
190 
191  if(has_periodic) {
192  sprintf(equipment[1].name, "Periodic %d", crate_number);
193  equipment[1].info.event_id = 2000 + crate_number;
194  } else {
195  sprintf(equipment[1].name, "");
196  }
197  }
198  printf("Frontend early init returns success \n");
199  return SUCCESS;
200 }
INT frontend_exit ( void  )

Definition at line 176 of file frontend.c.

177 {
178  return CM_SUCCESS;
179 }
INT frontend_init ( void  )

Definition at line 161 of file frontend.c.

References Alarm, hDB, hKey, and SUCCESS.

162 {
163 
164  // get the LabView filename
165  cm_get_experiment_database(&hDB, NULL);
166 
167  if(db_find_key(hDB, 0, Alarm, &hKey) != SUCCESS){
168  db_create_key(hDB,0,Alarm,TID_INT);
169  }
170 
171  return CM_SUCCESS;
172 }
INT frontend_loop ( void  )

Definition at line 183 of file frontend.c.

184 {
185  ss_sleep(100);
186  return CM_SUCCESS;
187 }
INT interrupt_configure ( INT  cmd,
INT  source[],
PTYPE  adr 
)

Definition at line 154 of file frontend.c.

155 {
156  return 1;
157 };
INT pause_run ( INT  run_number,
char *  error 
)

Definition at line 205 of file frontend.c.

206 {
207  return CM_SUCCESS;
208 }
INT poll_event ( INT  source[],
INT  count,
BOOL  test 
)

Definition at line 150 of file frontend.c.

151 {
152  return 1;
153 };
INT pre_begin_of_run ( )
INT read_temperature_probe ( char *  pevent,
INT  off 
)

Definition at line 219 of file frontend.c.

References count, and printf().

219  {
220 //
221 // static char oldtimestamp[80];
222 // char timestamp[80];
223 // char timestring[80];
224 // FILE *infile=NULL;
225  float *pdata;
226 // static float lastHVs[4] = {-1., -1., -1., -1.};
227 // static int initDone = 0;
228 // int i;
229 //
230 // size = sizeof(sepDemand);
231 // db_get_value(hDB,0, "/Experiment/Edit on start/Temperature HV",
232 // &sepDemand, &size, TID_INT, 1);
233 //
234 // timestamp[0]='\0';
235 //
236 // infile=fopen("/tmp/temperature.txt","r");
237 // if (infile==NULL){
238 // cm_msg(MERROR,frontend_name,
239 // "Could not open tempfile. temperature_daemon.pl not running?");
240 // temperature_data.hv =-1;
241 // temperature_data.vac =-1;
242 // temperature_data.sep_stat =-1;
243 // }
244 // else{
245 // fscanf(infile,"%s\n%f\n%f\n%f\n%f",timestamp,&temperature_data.hv,
246 // &temperature_data.current,&temperature_data.vac,
247 // &temperature_data.sep_stat);
248 // fclose(infile);
249 //
250 // if(!strcmp(oldtimestamp, timestamp)){
251 // temperature_data.hv=-1;
252 // temperature_data.vac=-1;
253 // temperature_data.sep_stat=-1;
254 // }
255 // }
256 //
257 // if(initDone == 0){
258 // for(i=0; i<4; i++) lastHVs[i] = temperature_data.hv;
259 // initDone = 1;
260 // }
261 // else{
262 // for(i=0; i<3; i++) lastHVs[i] = lastHVs[i+1];
263 // lastHVs[3] = temperature_data.hv;
264 // }
265 //
266 // //for(i=0; i<4; i++) printf("HV[%d]=%d\n",i,(int)lastHVs[i]);
267 // //printf("Demand = %d\n", sepDemand);
268 //
269  //Send to midas:
270  bk_init(pevent);
271 //bk_create(pevent,"SEPA",TID_FLOAT,&pdata);
272 //pdata[0] = 1;
273 // pdata[1] = temperature_data.current;
274 // pdata[2] = temperature_data.vac;
275 // pdata[3] = temperature_data.sep_stat;
276 //bk_close(pevent,pdata+0);
277 //
278 // int sepError = 1;
279 //
280 // for(i=0; i<4; i++){
281 // if((int)lastHVs[i] == sepDemand) sepError = 0;
282 // }
283 //
284 // if(sepError==1){
285 // if(strcmp(oldtimestamp, timestamp)){
286 // cm_msg(MERROR,frontend_name,"Temperature high voltage not same as demand!");
287 // printf("Demand = %d", sepDemand);
288 // }
289 // else{
290 // cm_msg(MERROR,frontend_name,"Old and new timestamps identical."
291 // " Refresh too high or temperature_daemon.pl not running.");
292 // }
293 // int on = 1;
294 // db_set_value(hDB, 0, Alarm, &on, sizeof(on), 1, TID_INT);
295 // }
296 // else{
297 // int off = 0;
298 // db_set_value(hDB, 0, Alarm, &off, sizeof(off), 1, TID_INT);
299 // }
300 //
301 // strcpy(oldtimestamp,timestamp);
302 //
303 // return bk_size(pevent);
304 //
305  static int count=0;
306  printf("hello from temperature probe %d\n", count++);
307  return 1;
308 }
INT resume_run ( INT  run_number,
char *  error 
)

Definition at line 212 of file frontend.c.

213 {
214  return CM_SUCCESS;
215 }

Variable Documentation

char Alarm[128] = "/Equipment/TemperatureMonitor/Variables/Alarm_Triggered"

Definition at line 74 of file frontend.c.

INT crate_number =0

Definition at line 68 of file frontend.c.

INT display_period = 1000

Definition at line 91 of file frontend.c.

EQUIPMENT equipment[]
Initial value:
= {
{"TemperatureMonitor",
{ 23, 0,
"SYSTEM",
EQ_PERIODIC,
0,
"MIDAS",
TRUE,
RO_ALWAYS|RO_ODB,
10000,
0,
0,
0,
"", "", "", },
NULL, NULL,
},
{""}
}

Definition at line 111 of file frontend.c.

INT event_buffer_size = 10 * 10000

Definition at line 100 of file frontend.c.

BOOL frontend_call_loop = TRUE

Definition at line 88 of file frontend.c.

char* frontend_file_name = __FILE__

Definition at line 85 of file frontend.c.

char* frontend_name = "TemperatureMonitor"

Definition at line 83 of file frontend.c.

HNDLE hDB

Definition at line 70 of file frontend.c.

HNDLE hKey

Definition at line 71 of file frontend.c.

INT max_event_size = 10000

Definition at line 94 of file frontend.c.

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 97 of file frontend.c.

int sepDemand

Definition at line 73 of file frontend.c.

int size

Definition at line 72 of file frontend.c.

BANK_LIST temperature_bank_list[]
Initial value:
= {
{ "TMP1", TID_FLOAT, 1, NULL },
{ "" },
}

Definition at line 104 of file frontend.c.