/*********************************************** * * ************************************************/ #include #include #include #include #include #include "lv.h" #define BASE_ADDR 0x02000800 #define J1_ODD 48 #define J1_EVEN 0 #define J2_ODD 72 #define J2_EVEN 24 #define T1 60. #define T2 65. #define T3 70. int stato[] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 }; LV_MBOX *mod; int evid; char *caller; sighand(signal) register int signal; { printf(" %s : signal %d received \n", *caller, signal); if ( signal == 0 || (signal >= 2 && signal <= 3)){ /* ^C or ^E ? */ sem_unl_del(evid, "lv_mbox", caller); munlink(mod); exit(0); } } main(argc, argv) int argc; char **argv; { int gains_set[96], gains_read[96], data[96]; float datv[96]; unsigned base; int ndata, gain_mode, diff_mode, i; float vmin = 0.; /* give range of the A/D : settable only hardware ! */ float vmax = 10.; float nch = 4096; int cpu_nr, tcp_ip_nr; char *hv_config[3]; int sonda, cycle; int hra[6]; caller = argv[0]; if (argc < 2) cycle = 0; else if(strcmp(argv[1],"cycle") == 0 && argc > 2) cycle = atoi(argv[2]); /* time to cycle in seconds */ if (cycle < 0) cycle = - cycle; if (get_config( &tcp_ip_nr, &cpu_nr, hv_config) != 0){ printf (" error in get_config \n"); exit (0); } if (cpu_nr < 1 || cpu_nr > 2) { printf(" No termometer probes readable from this CPU \n"); printf(" Move to OS9B1 ( 131.169.32.121 ) or OS9B2 "); printf("( 131.169.32.122)\n"); exit(0); } intercept(sighand); if (cycle){ evid = sem_link_cr("lv_mbox", caller); if((mod = (LV_MBOX *)modlink("lv_mod", 0)) == (LV_MBOX *)-1){ data_ora(&hra[0], &hra[1], &hra[2], &hra[3], &hra[4], &hra[5]); sem_wait(evid, caller); if((mod = (LV_MBOX *)_mkdata_module("lv_mod", sizeof(LV_MBOX), 0x8001, 0x0033)) == (LV_MBOX *)-1){ /* see module.h for attr,perm */ sem_free(evid, caller); sem_unl_del(evid, "lv_mbox", caller); exit(_errmsg(errno,"termometri: err. link/create data module\n")); } for(i=0; i<6; i++) mod->creat_tim[i] = hra[i]; for( i = 0; i < N_CHAMBERS - (cpu_nr - 1) ; i++) strcpy(mod->name[i],ch_name[ N_CHAMBERS * ( cpu_nr - 1 ) + i]); sem_free(evid, caller); } sem_wait(evid, caller); mod->nread_t = 0; mod->nerr_t = 0; for( i = 0; i < N_CHAMBERS - ( cpu_nr - 1); i++) { sonda = (cpu_nr - 1) * N_CHAMBERS + i; mod->st[i][0] = stato [sonda * 2]; mod->st[i][1] = stato [sonda * 2 + 1]; } sem_free(evid, caller); } base = (unsigned) BASE_ADDR; diff_mode = 0; /* 1: 48 diff chan's; 0: 96 single ended chan's */ gain_mode = 1; /* 1: common amplification for all chan's 0: individual amplification */ gains_set[0] = gain_word(1); /* -> amplification = 1 */ while(1){ anl_adc_init(base, &gain_mode, gains_set, &diff_mode); anl_adc_read(base, data, &ndata, &gain_mode, gains_read, &diff_mode); for ( i = 0; i < ndata; i++){ datv[i] = ((vmax - vmin)/(float) (nch-1)) * (float) data[i] + vmin; datv[i] = datv[i] / 0.01026 - 273. ; if (datv[i] < 0.) datv[i] = -1.; } if (!cycle){ printf(" TEMPERATURE PROBES \n\n"); printf(" i Chamber Probe 1 Probe 2 \n"); printf(" Name T(C) T(C) \n\n"); for( i = 0; i < N_CHAMBERS - (cpu_nr - 1); i++) { printf(" %2d %2s ", 1 + i, ch_name[ sonda = (cpu_nr - 1) * N_CHAMBERS + i ]); if (stato [sonda * 2]) printf("%4.0f ", datv[J2_ODD + i]); else printf(" "); if (stato [sonda * 2 + 1]) printf("%4.0f ", datv[J2_EVEN + i]); else printf(" "); printf(" "); if ( datv[J2_ODD + i ] > T1 || datv[J2_EVEN + i] > T1 ) printf("! "); if ( datv[J2_ODD + i ] > T2 || datv[J2_EVEN + i] > T2 ) printf("! "); if ( datv[J2_ODD + i ] > T3 || datv[J2_EVEN + i] > T3 ) printf("! "); printf("\n"); } } else { data_ora(&hra[0], &hra[1], &hra[2], &hra[3], &hra[4], &hra[5]); sem_wait(evid, caller); for(i = 0; i < 6; i++) mod->t_tim[i] = hra[i]; for ( i = 0; i < N_CHAMBERS - (cpu_nr - 1); i++) { mod->t[i][0] = datv[J2_ODD + i]; mod->t[i][1] = datv[J2_EVEN + i]; } mod->nread_t++; sem_free(evid, caller); } if (cycle) sleep(cycle); else break; /* only one reading if cicle == 0 */ } }