/*********************************************** * * ************************************************/ #include #include #include #include #include #define BASE_ADDR 0x02000600 #define HIGH_FLOW_D1 0 #define HIGH_FLOW_D2 48 #define LOW_FLOW_D1 24 #define LOW_FLOW_D2 72 #define IN + 2 * #define OUT + 1 + 2 * struct flow_mbox{ struct modhcom _mh; /* Standard module header */ float fl_cal[2][40][2][4]; }; typedef struct flow_mbox FLOW_MBOX; char *ch_name[] = { /* sud, low */ "CH96/2", "CH96/1", "CH95/2", "CH95/1", "CH94/2", "CH94/1", "CH93/2", "CH93/1", "CH99/1", "CH72/2", " -- ", "CH72/1", "CH62/2", "CH62/1", "CH61/2", "CH61/1", "CH41/2", "CH41/1", "CH33/2", "CH33/1", /* sud, high */ " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", "CH52/2", "CH52/1", "CH51/2", "CH51/1", "CH42/2", "CH42/1", "CH34/2", "CH34/1", /* nord, low */ "CH98/2", "CH98/1", "CH97/2", "CH97/1", "CH92/2", "CH92/1", "CH91/2", "CH91/1", " -- ", " -- ", " -- ", "CH99/1", "CH82/2", "CH82/1", "CH81/2", "CH81/1", "CH31/2", "CH31/1", "CH21/2", "CH21/1", /* nord, high */ " -- ", " -- ", "CH32/2", "CH32/1", "CH22/2", "CH22/1", "CH12/2", "CH12/1", "CH11/2", "CH11/1", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- ", " -- "}; float conv(); main(argc, argv) int argc; char **argv; { FLOW_MBOX *mod; 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 only_v = 0; int cal_init = 0; int pin, balc, i_o_code, ch_i, ch_nr, id12; char line[80], i_o[1], ch[2]; int linel, channel; float c[4]; if (argc > 1){ if ( strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"-V") == 0 ) only_v = 1; /* display volatges */ else if ( strcmp(argv[1],"-i") == 0 || strcmp(argv[1],"-I") == 0 ) cal_init = 1; /* read the cal coefficients and store in data module */ } if (!only_v){ if((mod = (FLOW_MBOX *)modlink("FLOW_MOD", 0)) == (FLOW_MBOX *)-1){ if((mod = (FLOW_MBOX *)_mkdata_module("FLOW_MOD", sizeof(FLOW_MBOX), 0x8001, 0x0033)) == (FLOW_MBOX *)-1){ exit(_errmsg(errno,"kessler: err. link/create data module\n")); } } } if ( cal_init ) { if ((pin = open("flow_cal.dat", 0x03)) == -1) exit(_errmsg(errno," kessler: error opening flcal_os9.dat\n")); linel = readln(pin, line, 80); /* first line not used */ /* printf(" linel = %d\n %s\n", linel, line); */ while((linel = readln(pin, line, 80)) > 0) { /* printf(" linel = %d\n %s\n", linel, line); */ sscanf(line, "CH%2d/%1d-%1s %f %f %f %f", &ch_nr, &channel, i_o, &c[0], &c[1], &c[2], &c[3]); /* printf(" riga scannata \n"); printf(" ch_nr %d, channel %d, i_o %s, c[] %f %f %f %f\n", ch_nr, channel, i_o, c[0], c[1], c[2], c[3]); */ if (strcmp( i_o, "I") == 0) i_o_code = 0; /* INPUT */ else i_o_code = 1; /* OUTPUT */ /* look for match with Chamber name in table */ for ( balc = 1; balc < 3; balc ++) { for ( i = 0; i < 40; i++ ){ sscanf(ch_name[(balc - 1) * 40 + i], "CH%2d/%1d", &ch_i, &id12); /* printf(" ch_nr %d, ch_i %d, chann %d, id12 %d\n", ch_nr, ch_i, channel, id12); */ if (ch_nr == ch_i && channel == id12){ if ( strncmp(ch_name[(balc - 1) * 40 + i],"CH", 2) == 0 ){ /* printf(" chamber %s (%d) calibrated\n", ch_name[(balc - 1) * 40 + i], i_o_code); */ mod->fl_cal[balc-1][i][i_o_code][0] = c[0]; mod->fl_cal[balc-1][i][i_o_code][1] = c[1]; mod->fl_cal[balc-1][i][i_o_code][2] = c[2]; mod->fl_cal[balc-1][i][i_o_code][3] = c[3]; /* printf(" balc %d, i=%d, i_o = %d", balc, i, i_o_code); printf(" c[]: %f, %f, %f, %f \n", mod->fl_cal[balc-1][i][i_o_code][0], mod->fl_cal[balc-1][i][i_o_code][1], mod->fl_cal[balc-1][i][i_o_code][2], mod->fl_cal[balc-1][i][i_o_code][3]); */ } else { mod->fl_cal[balc-1][i][i_o_code][0] = 0.; mod->fl_cal[balc-1][i][i_o_code][1] = 0.; mod->fl_cal[balc-1][i][i_o_code][2] = 0.; mod->fl_cal[balc-1][i][i_o_code][3] = 0.; } } } } } } /* printf(" sto per uscire. Ciao\n"); if (1) exit(0); /* esce per test */ base = (unsigned) BASE_ADDR; if (get_config( &tcp_ip_nr, &cpu_nr, hv_config) != 0){ printf (" error in get_config \n"); exit (0); } 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 */ 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)/(nch-1) * (float) data[i] + vmin; /* printf(" LOW FLOW HIGH FLOW \n"); */ if (only_v){ printf("Chamber In Out I-O "); printf("Chamber In Out I-O \n"); printf(" (V) (V) (V) "); printf("Chamber (V) (V) (V) \n\n"); for( i = 0; i < 10; i++) { printf(" %s %5.2f %5.2f %6.2f %s %5.2f %5.2f %6.2f \n", ch_name[ (cpu_nr - 1) * 40 + i], datv[LOW_FLOW_D1 IN i], datv[LOW_FLOW_D1 OUT i], datv[LOW_FLOW_D1 IN i] - datv[LOW_FLOW_D1 OUT i], ch_name[ (cpu_nr - 1) * 40 + 20 + i], datv[HIGH_FLOW_D1 IN i], datv[HIGH_FLOW_D1 OUT i], datv[HIGH_FLOW_D1 IN i] - datv[HIGH_FLOW_D1 OUT i]); } for( i = 0; i < 10; i++) { printf(" %s %5.2f %5.2f %6.2f %s %5.2f %5.2f %6.2f \n", ch_name[ (cpu_nr - 1) * 40 + 10 + i], datv[LOW_FLOW_D2 IN i], datv[LOW_FLOW_D2 OUT i], datv[LOW_FLOW_D2 IN i] - datv[LOW_FLOW_D2 OUT i], ch_name[ (cpu_nr - 1) * 40 + 30 + i], datv[HIGH_FLOW_D2 IN i], datv[HIGH_FLOW_D2 OUT i], datv[HIGH_FLOW_D2 IN i] - datv[HIGH_FLOW_D2 OUT i]); } } else{ printf("Chamber In Out I-O "); printf("Chamber In Out I-O \n"); printf(" (L/h) (L/h) (L/h) "); printf("Chamber (L/h) (L/h) (L/h) \n\n"); for( i = 0; i < 10; i++){ /* balc = cpu_nr; i_o_code = 0; printf(" balc, i_o_code : %d, %d, %s\n", balc,i_o_code, ch_name[ (cpu_nr - 1) * 40 + i]); printf(" c[]: %f, %f, %f, %f \n", mod->fl_cal[balc-1][i][i_o_code][0], mod->fl_cal[balc-1][i][i_o_code][1], mod->fl_cal[balc-1][i][i_o_code][2], mod->fl_cal[balc-1][i][i_o_code][3]); i_o_code = 1; printf(" balc, i_o_code : %d, %d\n", balc,i_o_code); printf(" c[]: %f, %f, %f, %f \n", mod->fl_cal[balc-1][i][i_o_code][0], mod->fl_cal[balc-1][i][i_o_code][1], mod->fl_cal[balc-1][i][i_o_code][2], mod->fl_cal[balc-1][i][i_o_code][3]); /* printf(" %s (I) %f %f %f %f \n", ch_name[ (cpu_nr - 1) * 40 + i], mod->fl_cal[cpu_nr-1][i][0][0], mod->fl_cal[cpu_nr-1][i][0][1], mod->fl_cal[cpu_nr-1][i][0][2], mod->fl_cal[cpu_nr-1][i][0][3]); printf(" %s (O) %f %f %f %f \n", ch_name[ (cpu_nr - 1) * 40 + i], mod->fl_cal[cpu_nr-1][i][1][0], mod->fl_cal[cpu_nr-1][i][1][1], mod->fl_cal[cpu_nr-1][i][1][2], mod->fl_cal[cpu_nr-1][i][1][3]); */ printf(" %s %5.1f %5.1f %5.1f %s %5.1f %5.1f %5.1f \n", ch_name[ (cpu_nr - 1) * 40 + i], conv(datv[LOW_FLOW_D1 IN i], &mod->fl_cal[cpu_nr-1][i][0][0]), conv(datv[LOW_FLOW_D1 OUT i], &mod->fl_cal[cpu_nr-1][i][1][0]), conv(datv[LOW_FLOW_D1 IN i], &mod->fl_cal[cpu_nr-1][i][0][0]) - conv(datv[LOW_FLOW_D1 OUT i], &mod->fl_cal[cpu_nr-1][i][1][0]), ch_name[ (cpu_nr - 1) * 40 + 20 + i], conv(datv[HIGH_FLOW_D1 IN i], &mod->fl_cal[cpu_nr-1][20+i][0][0]), conv(datv[HIGH_FLOW_D1 OUT i], &mod->fl_cal[cpu_nr-1][20+i][1][0]), conv(datv[HIGH_FLOW_D1 IN i], &mod->fl_cal[cpu_nr-1][20+i][0][0]) - conv(datv[HIGH_FLOW_D1 OUT i], &mod->fl_cal[cpu_nr-1][20+i][1][0]) ); } for( i = 0; i < 10; i++) { printf(" %s %5.1f %5.1f %5.1f %s %5.1f %5.1f %5.1f \n", ch_name[ (cpu_nr - 1) * 40 + 10 + i], conv(datv[LOW_FLOW_D2 IN i], &mod->fl_cal[cpu_nr-1][10+i][0][0]), conv(datv[LOW_FLOW_D2 OUT i], &mod->fl_cal[cpu_nr-1][10+i][1][0]), conv(datv[LOW_FLOW_D2 IN i], &mod->fl_cal[cpu_nr-1][10+i][0][0]) - conv(datv[LOW_FLOW_D2 OUT i], &mod->fl_cal[cpu_nr-1][10+i][1][0]), ch_name[ (cpu_nr - 1) * 40 + 30 + i], conv(datv[HIGH_FLOW_D2 IN i], &mod->fl_cal[cpu_nr-1][30+i][0][0]), conv(datv[HIGH_FLOW_D2 OUT i], &mod->fl_cal[cpu_nr-1][30+i][1][0]), conv(datv[HIGH_FLOW_D2 IN i], &mod->fl_cal[cpu_nr-1][30+i][0][0]) - conv(datv[HIGH_FLOW_D2 OUT i], &mod->fl_cal[cpu_nr-1][30+i][1][0]) ); } } } float conv(volt, coeff) float volt; float coeff[4]; { float x; /* printf("coeff[]: %f, %f, %f, %f\n", coeff[0],coeff[1],coeff[2],coeff[3]); */ x = coeff[3]; x = x * volt + coeff[2]; x = x * volt + coeff[1]; x = x * volt + coeff[0]; return x; }