/*************************************** * sy227_vi_mon * * * * Monitor V and I and * * of each of the 32 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_vi_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_vi_mon_id = 0; sem_free(evpro_id, caller); } /* unlink dbase module */ 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]; short ndatav, datav[33]; short ndatai, datai[33]; int hra[6]; short i, j, chan, value, code, code1, code2; short dis, cr, sl; short i_res; short ifirst = 1; short n_to_be_read; short n_good_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_to_be_read = 0; n_good_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].cable[0].chamber, "01") && hv_mid->distr[dis].slot[sl].d_used_ch){ if (ifirst){ /* first time get some parameters */ ifirst = 0; ndata = 32; /* maximum size */ if (code = D_Read(D_IRESOL, cr, sl, ALL, data, &ndata)){ printf("%s: error %d reading current res., cr = %d, sl = %d \n", argv[0], code, cr, sl); i_res = 1; printf(" : i_res = %d assumed \n", i_res); } else i_res = data[0]; } /* the Voltage is read only on channel 0 */ ndatav = 1; if (code1 = D_Read(D_VMON, cr, sl, 0, datav, &ndatav)) printf(" %s: error %d reading V monitor, cr = %d, sl = %d, \n", argv[0], code1, cr, sl); ndatai = 32; if (code2 = D_Read(D_IMON, cr, sl, ALL, datai, &ndatai)) printf(" %s: error %d reading I monitor, cr = %d, sl = %d\n", argv[0], code2, cr, sl); n_to_be_read++; if (!code1 && !code2){ 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->vim_tim[i] = hra[i]; for( i = 0; i < 32; i++){ hv_mod->sl_par[cr-1][sl].vmon[i] = datav[0]; hv_mod->sl_par[cr-1][sl].imon[i] = datai[i] * i_res; } sem_free(mev_id, argv[0]); } else { sem_wait(mev_id, argv[0]); hv_mod->nvim_err++; sem_free(mev_id, argv[0]); } } } } /* if (n_to_be_read == n_good_read){ sem_wait(mev_id, argv[0]); hv_mod->nvim++; sem_free(mev_id, argv[0]); } */ sem_wait(mev_id, argv[0]); hv_mod->nvim++; sem_free(mev_id, argv[0]); sem_wait(evpro_id, argv[0]); if (tcycle != 0) { command = hv_procs_mod->sy227_vi_mon_com; hv_procs_mod->sy227_vi_mon_com = 0; /* reset immediately command */ tcycle = hv_procs_mod->sy227_vi_mon_tcycle; } else command = 0; if (tcycle != 0) hv_procs_mod->sy227_vi_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_vi_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_vi_mon_id = 0; sem_free(evpro_id, argv[0]); } /* unlink dbase module */ 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_vi_mon \n"); printf(" |-> == 0 : read once \n"); printf(" >= 0 : cycle in s\n"); printf(" <= 0 : cycle in 1/256 s \n"); exit(0); }