/*************************************** * lv_check.c version 23/2/92 * * * ***************************************/ /* #include "std.h" */ #include #include #define NCH 3 #define BIT32 0x80000000 sighand(signal) register int signal; { printf(" lv_check: signal %d received \n", signal); if ( signal == 1001){ TVM_End(0); exit(0); } else { printf("lv_check received unaspected signal %d\n", signal); exit(1); } } main(argc,argv) int argc; char **argv; { int i, tms, change, iev, stat[NCH], stat0[NCH]; int yy, mm, dd, hh, min, sec; int ev_id, vect; char *outfile; FILE *fp, *fopen(); for (i = 0; i < NCH; i++) stat0[i] = -1; if (argc >= 2) tms = atoi( argv[1]); else tms = 4; if (argc == 3){ outfile = argv[2]; printf(" lv_check: output will be on file %s\n",outfile); } /* create or link to the event to share printout */ if ((ev_id = _ev_link("LV_print")) == -1) if ((ev_id = _ev_creat(1, -1, 1, "LV_print")) == -1) exit(_errmsg(errno,"lv_check: error getting access to event -")); intercept(sighand); TVM_Init(0); for (;;){ change = 0; for ( i = 0; i < NCH; i++) if ( (stat[i] = In16_Ch_Check(0, i + 1)) != stat0[i]) ++change; if (change){ data_ora(&yy, &mm, &dd, &hh, &min, &sec); if ( _ev_wait(ev_id, 1, 1) == -1) exit(_errmsg(errno,"lv_check: error waiting for event")); fp = fopen( outfile, "a+"); fprintf(fp, " %d-%d-%d %d:%d:%d ",dd,mm,yy,hh,min,sec); fprintf(fp, " : variation of status \n"); for ( i = 0; i < NCH ; i++) if (stat[i] != stat0[i]){ stat0[i] = stat[i]; fprintf(fp, " ch %d, status %d \n", i, stat[i]); } fprintf(fp,"\n"); fclose(fp); if ( _ev_signal(ev_id, 0) == -1) exit(_errmsg(errno,"lv_check: error signalling event ")); } tsleep(BIT32 + tms/4); } }