/************************************************************************** * sends a level to BBL3 as soon as the HV are ready * * ( in reality the signal goes to a relais and a circuit is closed * * ***************************************************************************/ #include #include #include #include #include #include #include #include "a200.h" /* definitions relative to the CAEN system */ #include "a200.hmn" #include "../lib/comx.h" #include "../lib/mylib1.h" #include "../dbase/hv_dbase.h" #include "bbl3.h" #define SLEEP_MAX 0 /* nr of cycles for which a chan. is put to sleep */ #define SECONDS #define MINUTES * 60 #define TWENTY_S 20 /* timeout value ( in seconds ) */ BBL3_MBOX *mod; SY227_MBOX *sy227_mod; int sem_227mod_id; SY127_MBOX *sy127_mod; hv_mod_struct *mid; int sem_127mod_id; char *caller; char line[80], cline[80], tmpfile[64], tmpfile_h[64]; int n_order, alarm[40], sleep_count[40]; int cpu_nr, tcp_ip_nr; FILE *fp, *fp1, *fp2, *fopen(); char *outfile = "tubi_sitter.log"; char *outfile_h = "tubi_sitter_hosp.log"; char *outfile_m = "tubi_sitter.msg"; char *tmpfile_0 = "t_s_temp"; char *tmpfile_h_0 = "t_s_h_temp"; char *remfile = "tubi_sitter.log"; char *remfile_h = "tubi_sitter_hosp.log"; int pout; char *scatola_nera = "scatola_nera"; int hosp; int nout1, nout2, nout3; int err1, err2, err3; int to_be_sent, to_be_sent_h; sighand(signal) register int signal; { if ( signal >= 2 && signal <= 3){ /* ^C or ^E ? */ sem_unl_del(sem_127mod_id, "sy127mod", caller); munlink(sy127_mod); sem_unl(sem_227mod_id, "sy227mod", caller); munlink(sy227_mod); munlink(mid); exit(0); } } main(argc, argv) int argc; char *argv[]; { char chamber_code[6]; char old_chamber[6]; char *mod_name0 = "hv_config0"; char *mod_name1 = "hv_config1"; char *mod_name2 = "hv_config2"; char *mod_name, *hv_config[3]; int dis, sl; int ch1, ch2, first_print; int nwrite, nerror, par_val; short ndata, data[45], prot_word; short i, ir, j, k, chan, value, code; int n_good, n_bad; float imean, vmean; short ch_imax, imax, d_vmon[32], d_imon[32], d_status[32]; short hv_ch_A, hv_ch_Ref, on_off, hv_in; int sy127_mod_vim_tim[32]; int sy127_mod_sta_tim[32]; int sy227_mod_vim_tim[32]; int sy227_mod_sta_tim[32]; int sy127_mod_nvim; int sy127_mod_nvim_err; int sy127_mod_nsta; int sy127_mod_nsta_err; int sy227_mod_nvim; int sy227_mod_nvim_err; int sy227_mod_nsta; int sy227_mod_nsta_err; short status_hv_ch_Ref, status_hv_ch_A; short v0_hv_ch_Ref, v0_hv_ch_A; short vmon_hv_ch_Ref, vmon_hv_ch_A; short i0_hv_ch_Ref, i0_hv_ch_A; short imon_hv_ch_Ref, imon_hv_ch_A; int yy, mm, dd, hh, min, sec; int jtime1, jdate1; int jtime2, jdate2; int tick; short day; int time_lost, time_to_sleep; int ncycle, n_anomalous[40]; int skip_ch, switch_off; int send_to_vax = 0; int check_distr = 1; /* if =0 no averages on distr */ int switched = 0; int new_chamber = 1; int v1_status = 0; int hv_status = 0; int hv_status_old = -1; int short_wait = 2; int long_wait = 2; int nslots; int flag = 0; int old_flag = -1; int old_command = -1; strcpy(old_chamber, "??"); intercept(sighand); /* link module for BBL3 Flag */ if ((mod = (BBL3_MBOX *)modlink("BBL3_MOD", 0)) == (BBL3_MBOX *)-1){ flag = 0; } if((sy127_mod = (SY127_MBOX *)modlink("sy127mod", 0)) == (SY127_MBOX *) -1) exit(_errmsg(errno,"tubi_sitter: err. link data module\n")); get_config(&tcp_ip_nr, &cpu_nr, hv_config); mod_name = hv_config[cpu_nr]; if ((mid = (hv_mod_struct *)modlink(mod_name, 0)) == (hv_mod_struct *)-1) if ((mid = (hv_mod_struct *)modload(mod_name, 0)) == (hv_mod_struct *)-1) exit(_errmsg(errno, "%s: error linking module %s\n", argv[0], mod_name)); strcpy (chamber_code, "0"); for (i = 0; i < 40; i++) alarm[i] = sleep_count[i] = n_anomalous[i] = 0; ncycle = 0; while(1){ ncycle++; nslots = 0; for(dis = 0; dis < mid->n_crates; dis++) for(sl = 0; sl < 4; sl++) /* successivamente si potrebbe chiedere soltanto una camera */ if((strcmp(chamber_code, mid->distr[dis].slot[sl].chamber) == 0 || strcmp(chamber_code, mid->distr[dis].slot[sl].cable_name) == 0 || ( strcmp("0", chamber_code) == 0 && mid->distr[dis].slot[sl].hv_ch_Ref >= 0) ) && mid->distr[dis].slot[sl].d_used_ch && !(mid->distr[dis].slot[sl].cond IS_CONDITIONING) ){ /* not cond */ hv_ch_Ref = mid->distr[dis].slot[sl].hv_ch_Ref; hv_ch_A = mid->distr[dis].slot[sl].hv_ch_A; if (nslots++ == 0){ prot_word = sy127_mod->hv_par[1].prot_word; v1_status = prot_word V1_ACTIVE; if (!v1_status){ time_to_sleep = long_wait; /* hv_status_old = -1; */ hv_status = 1; goto lab1; } } status_hv_ch_Ref = sy127_mod->hv_par[1].status[hv_ch_Ref]; status_hv_ch_A = sy127_mod->hv_par[1].status[hv_ch_A]; if (status_hv_ch_Ref IS_RAMPU || status_hv_ch_Ref IS_RAMPD || status_hv_ch_A IS_RAMPU || status_hv_ch_A IS_RAMPD ){ hv_status = 0; goto lab1; } } hv_status = 1; lab1: flag = mod->flag; if (hv_status_old != hv_status || flag != old_flag){ if (hv_status_old != hv_status) hv_status_old = hv_status; if (old_flag != flag) old_flag = flag; if (hv_status == 0 && flag == 1){ if ( old_command != 0) system("onoff 33 off >>>/nil"); old_command = 0; } else { if ( old_command != 1) system("onoff 33 on >>>/nil"); old_command = 1; } } sleep( time_to_sleep); } munlink(sy127_mod); munlink(mid); }