/*************************************** * sy127_vi_send * * * * Make time averages of V and I * * and send them to VAX * * * ***************************************/ #include #include #include #include #include #include "a200.h" #include "../lib/mylib1.h" #define PAUSE 1001 #define CONTINUE 1002 #define STOP 1003 SY127_MBOX *hv_mod1; SY227_MBOX *hv_mod2; PROCS_INFO *hv_procs_mod; int mev_id, evpro_id; char *caller; int tcycle, tmin, command; int pid; char *outfile = "hv_report1.txt"; FILE *fp, *fopen(); int yy, mm, dd, hh, min, sec; int hra[6]; int jtime[2], jdate[2], jtick[2]; short jday[2]; int time_dif; int i, j; float vsum[40], vsum2[40], vmin[40], vmax[40], vmean[40], vsigma[40]; float isum[40], isum2[40], imin[40], imax[40], imean[40], isigma[40]; int ch_status[40]; int ntot, nread, crate_status; int tot_chan = 27; char *cline; char *pipe ="/pipe/to_hv_ftp"; int nreport = 0; sighand(signal) register int signal; { printf(" sy127_vi_send : signal %d received \n", signal); if ( signal == STOP || signal == 2 || signal == 3) { /* ^C ^E */ /* put process ID to zero */ average_and_send(); if (tcycle != 0){ sem_wait(evpro_id, caller); hv_procs_mod->sy127_vi_send_id = 0; sem_free(evpro_id, caller); } close(pid); 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[]; { intercept(sighand); if (argc < 2) usage(); caller = argv[0]; tcycle = atoi(argv[1]); /* sleep time in seconds if tcycle > 0 ( read once if tcycle = 0 ) */ mev_id = sem_link("sy127mod", argv[0]); evpro_id = sem_link("hv_pr_info", argv[0]); if((hv_mod = (SY127_MBOX *)modlink("sy127mod", 0)) == (SY127_MBOX *) -1) exit(_errmsg(errno, "hv_mod: err. link data module sy127mod, 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)); if((pid = create(pipe, 0x03, 0x03)) == -1) exit(_errmsg(errno," sy127_vi_send: error creating %s\n",pipe)); _sysdate(1, &jtime[1], &jdate[1], &jtick[1], &jday[1]); /* julian time */ for (i = 0; i < tot_chan; i++){ vsum[i] = vsum2[i] = isum[i] = isum2[i] = 0.; vmin[i] = imin[i] = 9999.; vmax[i] = imax[i] = -1.; ch_status[i] = 0; } ntot = 0; nread = 0; crate_status = 0; sem_wait(evpro_id, argv[0]); tmin = hv_procs_mod->sy127_vi_mon_tcycle; sem_free(evpro_id, argv[0]); if (tmin < 1) tmin = 1; while(1) { sem_wait(mev_id, argv[0]); if( hv_mod->nvim > nread ) { /* there are new values */ nread = hv_mod->nvim; for (i = 0; i < tot_chan; i++){ ch_status[i] |= hv_mod->hv_par[1].status[i]; vsum[i] += hv_mod->hv_par[1].vmon[i]; isum[i] += hv_mod->hv_par[1].imon[i]; vsum2[i] += hv_mod->hv_par[1].vmon[i] * hv_mod->hv_par[1].vmon[i]; isum2[i] += hv_mod->hv_par[1].imon[i] * hv_mod->hv_par[1].imon[i]; if (hv_mod->hv_par[1].vmon[i] > vmax[i]) vmax[i] = hv_mod->hv_par[1].vmon[i]; if (hv_mod->hv_par[1].vmon[i] < vmin[i]) vmin[i] = hv_mod->hv_par[1].vmon[i]; if (hv_mod->hv_par[1].imon[i] > imax[i]) imax[i] = hv_mod->hv_par[1].imon[i]; if (hv_mod->hv_par[1].imon[i] < imin[i]) imin[i] = hv_mod->hv_par[1].imon[i]; } crate_status |= hv_mod->hv_par[1].prot_word; ntot += 1; } sem_free(mev_id, argv[0]); _sysdate(1, &jtime[2], &jdate[2], &jtick[2], &jday[2]); time_dif = jtime[2] -jtime[1] + (jdate[2] - jdate[1]) * 86400; if (time_dif > tcycle) average_and_send(); sem_wait(evpro_id, argv[0]); if (tcycle != 0) { command = hv_procs_mod->sy127_vi_send_com; hv_procs_mod->sy127_vi_send_com = 0; tcycle = hv_procs_mod->sy127_vi_send_tcycle; tmin = hv_procs_mod->sy127_vi_mon_tcycle; if (tmin < 1) tmin = 1; } else command = 0; if (tcycle != 0) hv_procs_mod->sy127_vi_send_active = 0; sem_free(evpro_id, argv[0]); if (!command){ sleep(1); /* instead tcycle gives the report period */ } else if(command == PAUSE) sleep(0); else if(command == STOP) break; sem_wait(evpro_id, argv[0]); hv_procs_mod->sy127_vi_send_active = 1; sem_free(evpro_id, argv[0]); } /* put process ID to zero */ if (tcycle != 0){ sem_wait(evpro_id, argv[0]); hv_procs_mod->sy127_vi_send_id = 0; sem_free(evpro_id, argv[0]); } close(pid); sem_unl(mev_id, caller); sem_unl(evpro_id, caller); munlink(hv_mod); munlink(hv_procs_mod); exit(0); } usage() { printf(" usage : sy127_vi_send \n"); printf(" |-> report time in seconds \n"); printf(" ( = 0 : only once )\n"); exit(0); } average_and_send() { /* calculate averages */ for (i = 0; i < tot_chan; i++){ vmean[i] = 0.; if (ntot > 0) vmean[i] = vsum[i] / (float)ntot; vsigma[i] = 0.; if (ntot > 1){ vsigma[i] = vsum2[i]/(float)ntot - pow( (double) vmean[i], 2.); if (vsigma[i] > 0.) vsigma[i] = pow ( (double) vsigma[i], 0.5); if (vsigma[i] < 0.) vsigma[i] = 0.; } imean[i] = 0.; if (ntot > 0) imean[i] = isum[i] / (float)ntot; isigma[i] = 0.; if (ntot > 1){ isigma[i] = isum2[i]/(float)ntot - pow( (double) imean[i], 2.); if (isigma[i] > 0.) isigma[i] = pow ( (double) isigma[i], 0.5); if (isigma[i] < 0.) isigma[i] = 0.; } } /* write on output file */ data_ora(&yy, &mm, &dd, &hh, &min, &sec); fp = fopen( outfile, "a+"); fprintf(fp, " time %2d-%2d-%4d %2d:%2d:%2d julian : %7d %5d", dd,mm,yy,hh,min,sec, jdate[2], jtime[2]); fprintf(fp, " Dt(s) %5d nr %5d st%3d\n", tcycle, ntot, crate_status); if (ntot) for (i = 0; i < tot_chan; i++){ fprintf(fp, " ch%2d %6.1f %6.1f %5.0f %5.0f", i, vmean[i], vsigma[i], vmin[i], vmax[i]); fprintf(fp, " %6.1f %6.1f %5.0f %5.0f %3d\n", imean[i], isigma[i], imin[i], imax[i], ch_status[i]); } fclose(fp); /* reset counters and times */ for (i = 0; i < tot_chan; i++){ vsum[i] = vsum2[i] = isum[i] = isum2[i] = 0.; vmin[i] = imin[i] = 9999.; vmax[i] = imax[i] = -1.; ch_status[i] = 0; } ntot = 0; crate_status = 0; jtime[1] = jtime[2]; jdate[1] = jdate[2]; /* send the file */ nreport++; cline = "dagostini\n"; write(pid, cline, strlen(cline)); cline = "zeus147\n"; write(pid, cline, strlen(cline)); cline = "chd [.os9]\n"; write(pid, cline, strlen(cline)); cline = "put hv_report1.txt\n"; write(pid, cline, strlen(cline)); cline = "quit\n"; write(pid, cline, strlen(cline)); system("ftp zeus02 >>/nil"); system("del hv_report1.txt"); return 0; }/*************************************** * sy127_vi_send * * * * Make time averages of V and I * * and send them to VAX * * * ***************************************/ #include #include #include #include #include #include "a200.h" #include "../lib/mylib1.h" #define PAUSE 1001 #define CONTINUE 1002 #define STOP 1003 SY227_MBOX *hv_mod; PROCS_INFO *hv_procs_mod; int mev_id, evpro_id; char *caller; int tcycle, tmin, command; int pid; char *outfile = "hv_report1.txt"; FILE *fp, *fopen(); int yy, mm, dd, hh, min, sec; int hra[6]; int jtime[2], jdate[2], jtick[2]; short jday[2]; int time_dif; int i, j; float isum[7][32], isum2[7][32], imin[7][32], float imax[7][32], imean[7][32], isigma[7][32]; int ch_status[7][32]; int ntot, nread, crate_status; int tot_chan = 27; char *cline; char *pipe ="/pipe/to_hv_ftp"; int nreport = 0; int nwrite_st, nerror_st; int nwrite_vi, nerror_vi; short ndata, data[45], on_off, hv_in; short ir, k, chan, value, code; int crate, slot, datv[32], dati[32], dats[32]; sighand(signal) register int signal; { printf(" sy127_vi_send : signal %d received \n", signal); if ( signal == STOP || signal == 2 || signal == 3) { /* ^C ^E */ /* put process ID to zero */ average_and_send(); if (tcycle != 0){ sem_wait(evpro_id, caller); hv_procs_mod->sy127_vi_send_id = 0; sem_free(evpro_id, caller); } close(pid); 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[]; { intercept(sighand); if (argc < 2) usage(); caller = argv[0]; tcycle = atoi(argv[1]); /* sleep time in seconds if tcycle > 0 ( read once if tcycle = 0 ) */ evpro_id = sem_link("hv_pr_info", argv[0]); if((hv_mod = (SY227_MBOX *)modlink("sy227mod", 0)) == (SY227_MBOX *) -1) exit(_errmsg(errno,"guarda: err. link data module\n")); mev_id = sem_link_cr("SY227mod", argv[0]); 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)); if((pid = create(pipe, 0x03, 0x03)) == -1) exit(_errmsg(errno," sy127_vi_send: error creating %s\n",pipe)); _sysdate(1, &jtime[1], &jdate[1], &jtick[1], &jday[1]); /* julian time */ for (i = 0; i < tot_chan; i++){ vsum[i] = vsum2[i] = isum[i] = isum2[i] = 0.; vmin[i] = imin[i] = 9999.; vmax[i] = imax[i] = -1.; ch_status[i] = 0; } ntot = 0; nread = 0; crate_status = 0; sem_wait(evpro_id, argv[0]); tmin = hv_procs_mod->sy227_vi_mon_tcycle; sem_free(evpro_id, argv[0]); if (tmin < 1) tmin = 1; while(1) { sem_wait(mev_id, argv[0]); if( hv_mod->nvim > nread ) { /* there are new values */ nread = hv_mod->nvim; for (i = 0; i < tot_chan; i++){ ch_status[i] |= hv_mod->hv_par[1].status[i]; vsum[i] += hv_mod->hv_par[1].vmon[i]; isum[i] += hv_mod->hv_par[1].imon[i]; vsum2[i] += hv_mod->hv_par[1].vmon[i] * hv_mod->hv_par[1].vmon[i]; isum2[i] += hv_mod->hv_par[1].imon[i] * hv_mod->hv_par[1].imon[i]; if (hv_mod->hv_par[1].vmon[i] > vmax[i]) vmax[i] = hv_mod->hv_par[1].vmon[i]; if (hv_mod->hv_par[1].vmon[i] < vmin[i]) vmin[i] = hv_mod->hv_par[1].vmon[i]; if (hv_mod->hv_par[1].imon[i] > imax[i]) imax[i] = hv_mod->hv_par[1].imon[i]; if (hv_mod->hv_par[1].imon[i] < imin[i]) imin[i] = hv_mod->hv_par[1].imon[i]; } crate_status |= hv_mod->hv_par[1].prot_word; ntot += 1; } sem_free(mev_id, argv[0]); _sysdate(1, &jtime[2], &jdate[2], &jtick[2], &jday[2]); time_dif = jtime[2] -jtime[1] + (jdate[2] - jdate[1]) * 86400; if (time_dif > tcycle) average_and_send(); sem_wait(evpro_id, argv[0]); if (tcycle != 0) { command = hv_procs_mod->sy127_vi_send_com; hv_procs_mod->sy127_vi_send_com = 0; tcycle = hv_procs_mod->sy127_vi_send_tcycle; tmin = hv_procs_mod->sy127_vi_mon_tcycle; if (tmin < 1) tmin = 1; } else command = 0; if (tcycle != 0) hv_procs_mod->sy127_vi_send_active = 0; sem_free(evpro_id, argv[0]); if (!command){ sleep(1); /* instead tcycle gives the report period */ } else if(command == PAUSE) sleep(0); else if(command == STOP) break; sem_wait(evpro_id, argv[0]); hv_procs_mod->sy127_vi_send_active = 1; sem_free(evpro_id, argv[0]); } /* put process ID to zero */ if (tcycle != 0){ sem_wait(evpro_id, argv[0]); hv_procs_mod->sy127_vi_send_id = 0; sem_free(evpro_id, argv[0]); } close(pid); sem_unl(mev_id, caller); sem_unl(evpro_id, caller); munlink(hv_mod); munlink(hv_procs_mod); exit(0); } usage() { printf(" usage : sy127_vi_send \n"); printf(" |-> report time in seconds \n"); printf(" ( = 0 : only once )\n"); exit(0); } average_and_send() { /* calculate averages */ for (i = 0; i < tot_chan; i++){ vmean[i] = 0.; if (ntot > 0) vmean[i] = vsum[i] / (float)ntot; vsigma[i] = 0.; if (ntot > 1){ vsigma[i] = vsum2[i]/(float)ntot - pow( (double) vmean[i], 2.); if (vsigma[i] > 0.) vsigma[i] = pow ( (double) vsigma[i], 0.5); if (vsigma[i] < 0.) vsigma[i] = 0.; } imean[i] = 0.; if (ntot > 0) imean[i] = isum[i] / (float)ntot; isigma[i] = 0.; if (ntot > 1){ isigma[i] = isum2[i]/(float)ntot - pow( (double) imean[i], 2.); if (isigma[i] > 0.) isigma[i] = pow ( (double) isigma[i], 0.5); if (isigma[i] < 0.) isigma[i] = 0.; } } /* write on output file */ data_ora(&yy, &mm, &dd, &hh, &min, &sec); fp = fopen( outfile, "a+"); fprintf(fp, " time %2d-%2d-%4d %2d:%2d:%2d julian : %7d %5d", dd,mm,yy,hh,min,sec, jdate[2], jtime[2]); fprintf(fp, " Dt(s) %5d nr %5d st%3d\n", tcycle, ntot, crate_status); if (ntot) for (i = 0; i < tot_chan; i++){ fprintf(fp, " ch%2d %6.1f %6.1f %5.0f %5.0f", i, vmean[i], vsigma[i], vmin[i], vmax[i]); fprintf(fp, " %6.1f %6.1f %5.0f %5.0f %3d\n", imean[i], isigma[i], imin[i], imax[i], ch_status[i]); } fclose(fp); /* reset counters and times */ for (i = 0; i < tot_chan; i++){ vsum[i] = vsum2[i] = isum[i] = isum2[i] = 0.; vmin[i] = imin[i] = 9999.; vmax[i] = imax[i] = -1.; ch_status[i] = 0; } ntot = 0; crate_status = 0; jtime[1] = jtime[2]; jdate[1] = jdate[2]; /* send the file */ nreport++; cline = "dagostini\n"; write(pid, cline, strlen(cline)); cline = "zeus147\n"; write(pid, cline, strlen(cline)); cline = "chd [.os9]\n"; write(pid, cline, strlen(cline)); cline = "put hv_report1.txt\n"; write(pid, cline, strlen(cline)); cline = "quit\n"; write(pid, cline, strlen(cline)); system("ftp zeus02 >>/nil"); system("del hv_report1.txt"); return 0; } /******************************************* * Look the parameters in the CAEN Mail_box * * * *******************************************/ #include #include #include #include "../lib/mylib1.h" #include "a200.h" /* definitions relative to the CAEN system */ #define NMAX 45 #define NOK 40 #define SECONDS #define MINUTES * 60 #define FINE 1001 SY227_MBOX *hv_mod; int mev_id; char *caller; sighand(signal) register int signal; { printf(" %s : signal %d received \n", *caller, signal); if ( signal >= 2 && signal <= 3){ /* ^C or ^E ? */ sem_unl(mev_id, "sy227mod", caller); munlink(hv_mod); exit(0); } } main(argc, argv) int argc; char *argv[]; { int nwrite_st, nerror_st; int nwrite_vi, nerror_vi; short ndata, data[45], on_off, hv_in; int hra[6]; short i, ir, j, k, chan, value, code; int crate, slot, datv[32], dati[32], dats[32]; intercept(sighand); caller = argv[0]; if (argc < 3) { printf(" usage : guardad crate_nr slot_nr \n"); exit(0); } else crate = atoi(argv[1]) - 1; slot = atoi(argv[2]); if (crate < 0 || crate > 6 || slot < 0 || slot > 3){ printf(" invalid parameters: crate %d, slot %d\n", crate, slot); exit(0); } if((hv_mod = (SY227_MBOX *)modlink("sy227mod", 0)) == (SY227_MBOX *) -1) exit(_errmsg(errno,"guarda: err. link data module\n")); mev_id = sem_link_cr("SY227mod", argv[0]); sem_wait(mev_id, argv[0]); for (i=0; i<6; i++) hra[i] = hv_mod->sta_tim[i]; on_off = hv_mod->sl_par[crate][slot].onoff; hv_in = hv_mod->sl_par[crate][slot].hvin; for(i = 0; i < 32; i++){ datv[i] = hv_mod->sl_par[crate][slot].vmon[i]; dati[i] = hv_mod->sl_par[crate][slot].imon[i]; dats[i] = hv_mod->sl_par[crate][slot].status[i]; } nwrite_st = hv_mod->nsta; nerror_st = hv_mod->nsta_err; nwrite_vi = hv_mod->nvim; nerror_vi = hv_mod->nvim_err; sem_free(mev_id, argv[0]); munlink(hv_mod); printf(" date of last update %d-%d-%d %d:%d:%d\n", hra[2],hra[1],hra[0],hra[3],hra[4],hra[5]); printf(" readouts status %d , errors %d\n",nwrite_st,nerror_st); printf(" readouts V/I %d , errors %d\n",nwrite_vi,nerror_vi); printf(" on_off = 0x%x :", on_off); if (on_off D_SWITCH_IS_ON) printf(" ON, "); else printf(" OFF, "); if (on_off D_RELAY_IS_ON) printf(" RELAY ON\n"); else printf(" RELAY OFF\n"); printf(" hv_in = 0x%x :", hv_in); if (hv_in D_NO_HV) printf(" NO Input HV \n"); else if(hv_in D_POS_HV) printf(" Positive Input HV \n"); else if(hv_in D_NEG_HV) printf(" Negative Input HV \n"); else printf(" ?? \n"); printf(" ch Vmon Imon(nA) status \n"); for (i = 0; i < 32; i++){ printf("%2d %6d %6d ", i, datv[i], dati[i]); if (dats[i] D_IS_OK) printf(" OK "); else printf(" ->> "); if (dats[i] D_IS_OVC) printf(" OVC"); else printf(" "); if (dats[i] D_IS_OFS) printf(" OFS"); else printf(" "); if (dats[i] D_IS_OVC) printf(" OVM"); else printf(" "); printf("\n"); } sem_unl(mev_id, "SY227mod", caller); }