/*************************************** * sy227_st_mon * * * * Monitor status * * of each of the 32 distr. ch * * * ***************************************/ #include #include #include #include "../lib/mylib1.h" #include "a200.h" /* definitions relative to the CAEN system */ #include "../dbase/hv_dbase.h" #define NMAX 45 #define NOK 40 #define SECONDS #define MINUTES * 60 #define PAUSE 1001 #define CONTINUE 1002 #define STOP 1003 SY227_MBOX *hv_mod; PROCS_INFO *hv_procs_mod; int mev_id, evpro_id; hv_mod_struct *hv_mid; int tcp_ip_nr, cpu_nr; char *hv_config[3]; char *caller; int tcycle, command; sighand(signal) register int signal; { printf(" sy227_st_mon : signal %d received \n", signal); if ( signal == STOP || signal == 2 || signal == 3) { /* ^C ^E */ A200_end(); /* put process ID to zero */ if (tcycle != 0){ sem_wait(evpro_id, caller); hv_procs_mod->sy227_st_mon_id = 0; sem_free(evpro_id, caller); } munlink(hv_mid); sem_unl(mev_id, caller); sem_unl(evpro_id, caller); munlink(hv_mod); munlink(hv_procs_mod); exit(0); } else if ( signal == PAUSE ) sleep(0); else if ( signal == CONTINUE ) ; /* do nothing , used to awaike the process */ } main(argc, argv) int argc; char *argv[]; { short ndata, data[33]; int hra[6]; short i, j, chan, value, code, code1, code2; short dis, cr, sl; short sum_codes; short hv_in, on_off; short n_good_read, n_to_be_read; intercept(sighand); if (argc < 2) usage(); caller = argv[0]; tcycle = atoi(argv[1]); /* sleep time in seconds if tcycle > 0 in 1/256 s if tcycle < 0 ( read once if tcycle = 0 ) */ mev_id = sem_link("sy227mod", argv[0]); evpro_id = sem_link("hv_pr_info", argv[0]); if((hv_mod = (SY227_MBOX *)modlink("sy227mod", 0)) == (SY227_MBOX *) -1) exit(_errmsg(errno, "hv_mod: err. link data module sy227mod, errno %d\n", errno)); if((hv_procs_mod = (PROCS_INFO *)modlink("hv_pr_info", 0)) == (PROCS_INFO *)-1) exit(_errmsg(errno, "hv_mod: err. link data module hv_procs_info, errno %d\n", errno)); get_config(&tcp_ip_nr, &cpu_nr, hv_config); if ((hv_mid = (hv_mod_struct *)modlink(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) if ((hv_mid = (hv_mod_struct *)modload(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) exit(_errmsg(errno, " %s: error loading/linking module %s\n", argv[0], hv_config[cpu_nr])); A200_init(); while(1) { n_good_read = 0; n_to_be_read = 0; for (dis = 0; dis < hv_mid->n_crates; dis++){ cr = hv_mid->distr[dis].crate_nr; for ( sl = 0; sl < 4; sl++){ if (strcmp(hv_mid->distr[dis].slot[sl].chamber, "01") && hv_mid->distr[dis].slot[sl].d_used_ch){ sum_codes = 0; ndata = 32; if (code = D_Read(D_ONOFF, cr, sl, ALL, data, &ndata)) printf("%s : error %d reading ONOFF, cr = %d, sl = %d\n", argv[0], code, cr, sl); else on_off = data[0]; sum_codes += code; ndata = 32; if (code = D_Read(D_HV_IN_STATUS, cr, sl, ALL, data, &ndata)) printf("%s : error %d reading HV_IN, cr = %d, sl = %d \n", argv[0], code, cr, sl); else hv_in = data[0]; sum_codes += code; ndata = 32; if (code = D_Read(D_STATUS, cr, sl, ALL, data, &ndata)) printf("%s : error %d reading STATUS, cr = %d, sl = %d \n", argv[0], code, cr, sl); sum_codes += code; n_to_be_read++; if(!sum_codes){ n_good_read++; data_ora(&hra[0], &hra[1], &hra[2], &hra[3], &hra[4], &hra[5]); sem_wait(mev_id, argv[0]); for(i=0; i<6; i++) hv_mod->sta_tim[i] = hra[i]; for(i=0; i < 32; i++) hv_mod->sl_par[cr-1][sl].status[i] = data[i]; hv_mod->sl_par[cr-1][sl].hvin = hv_in; hv_mod->sl_par[cr-1][sl].onoff = on_off; sem_free(mev_id, argv[0]); } else { sem_wait(mev_id, argv[0]); hv_mod->nsta_err++; sem_free(mev_id, argv[0]); } } } } /* if (n_to_be_read == n_good_read){ */ sem_wait(mev_id, argv[0]); hv_mod->nsta++; sem_free(mev_id, argv[0]); /* } */ sem_wait(evpro_id, argv[0]); if (tcycle != 0) { command = hv_procs_mod->sy227_st_mon_com; hv_procs_mod->sy227_st_mon_com = 0; /* reset immediately command */ tcycle = hv_procs_mod->sy227_st_mon_tcycle; } else command = 0; if (tcycle != 0) hv_procs_mod->sy227_st_mon_active = 0; sem_free(evpro_id, argv[0]); if (!command){ if (tcycle > 0) sleep( (unsigned) tcycle); else if(tcycle < 0) tsleep(BIT32 | (unsigned) -tcycle); else break; } else if(command == PAUSE) sleep(0); else if(command == STOP) break; sem_wait(evpro_id, argv[0]); hv_procs_mod->sy227_st_mon_active = 1; sem_free(evpro_id, argv[0]); } A200_end(); /* put process ID to zero */ if (tcycle != 0){ sem_wait(evpro_id, argv[0]); hv_procs_mod->sy227_st_mon_id = 0; sem_free(evpro_id, argv[0]); } munlink(hv_mid); sem_unl(mev_id, caller); sem_unl(evpro_id, caller); munlink(hv_mod); munlink(hv_procs_mod); exit(0); } usage() { printf(" usage : sy227_st_mon \n"); printf(" |-> == 0 : read once \n"); printf(" >= 0 : cycle in s\n"); printf(" <= 0 : cycle in 1/256 s \n"); exit(0); }