/*************************************** * A200_resetter.c * * * * reset periodically the A200 * * * ***************************************/ #include #include #include #include "../lib/mylib1.h" #include "a200.h" /* definitions relative to the CAEN system */ #define PAUSE 1001 #define CONTINUE 1002 #define STOP 1003 PROCS_INFO *hv_procs_mod; int evpro_id; char *caller; int tcycle, command; sighand(signal) register int signal; { printf(" a200_resetter : 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->a200_resetter_id = 0; sem_free(evpro_id, caller); } sem_unl(evpro_id, caller); 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 in 1/256 s if tcycle < 0 ( read once if tcycle = 0 ) */ if (tcycle < 0) usage(); evpro_id = sem_link("hv_pr_info", argv[0]); if((hv_procs_mod = (PROCS_INFO *)modlink("hv_pr_info", 0)) == (PROCS_INFO *)-1) exit(_errmsg(errno, "a200_resetter: err. link data_mod hv_procs_info, errno %d\n", errno)); A200_init(); while(1) { /* att! the action is done at the end of the WHILE !! */ sem_wait(evpro_id, argv[0]); if (tcycle != 0) { command = hv_procs_mod->a200_resetter_com; hv_procs_mod->a200_resetter_com = 0; /* reset immediately command */ tcycle = hv_procs_mod->a200_resetter_tcycle; } else command = 0; if (tcycle != 0) hv_procs_mod->a200_resetter_active = 0; sem_free(evpro_id, argv[0]); if (!command){ if (tcycle > 0) sleep( (unsigned) tcycle); else break; } else if(command == PAUSE) sleep(0); else if(command == STOP) break; sem_wait(evpro_id, argv[0]); hv_procs_mod->a200_resetter_active = 1; sem_free(evpro_id, argv[0]); A200_reset(); } A200_end(); if (tcycle != 0){ sem_wait(evpro_id, argv[0]); hv_procs_mod->a200_resetter_id = 0; sem_free(evpro_id, argv[0]); } sem_unl(evpro_id, caller); munlink(hv_procs_mod); exit(0); } usage() { printf(" usage : a200_resetter \n"); printf(" |-> == 0 : read once \n"); printf(" > 0 : cycle in s\n"); exit(0); }