Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 262 → Rev 263

/cvi/apps/RedPitaya/soccli/soccli.c
22,7 → 22,7
static int plothandle[2]= {0,0};
static int tdcplothandle[2]= {0,0};
static int adcplothandle[2]= {0,0};
static int excludefirst[2]= {0,0};
static int excludefirst[2]= {0,0};
int debug ;
int initialized = 0;
#define MAX_THREADS 10
30,6 → 30,8
int adctype;
float athreshold, twin0,twin1;
float timebins[0XFFFF];
float daqtime;
double starttime;
 
FILE *foutput;
int outwaveforms=0;
56,7 → 58,7
switch (type) {
case 0:
case 1:
sprintf(filename,"%s_%d.root",fname, hid);
sprintf(filename,"%s_%d.root",fname, hid);
fp =fopen(filename,"wb");
if (fp) {
H1D_Write2File(hid,fp);
77,7 → 79,7
fclose(fp);
printf("Histogram %d exported to %s\n", hid, filename);
}
 
break;
 
}
98,9 → 100,8
SetSleepPolicy(VAL_SLEEP_MORE);
CmtNewThreadPool (MAX_THREADS, &poolHandle);
 
//for (int i=0;i<1000;i++) H1D_Fill(1,i,i);
//H1D_Draw(1,panelHandle,PANEL_ADC1,&adcplothandle[0]);
printf("size of double = %d\n",sizeof(double));
//printf("size of double = %d\n",sizeof(double));
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
133,91 → 134,95
 
 
int CVICALLBACK SetGraphLogYCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int cid=0;
int logy=0;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal(panel,control, &logy);
switch (control){
case PANEL_LOGY_1: cid = PANEL_TDC1; break;
case PANEL_LOGY_2: cid = PANEL_ADC1; break;
case PANEL_LOGY_3: cid = PANEL_TDC2; break;
case PANEL_LOGY_4: cid = PANEL_ADC2; break;
}
if (logy) SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LOG);
else SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LINEAR);
break;
}
return 0;
void *callbackData, int eventData1, int eventData2) {
 
int cid=0;
int logy=0;
switch (event) {
case EVENT_COMMIT:
GetCtrlVal(panel,control, &logy);
switch (control) {
case PANEL_LOGY_1:
cid = PANEL_TDC1;
break;
case PANEL_LOGY_2:
cid = PANEL_ADC1;
break;
case PANEL_LOGY_3:
cid = PANEL_TDC2;
break;
case PANEL_LOGY_4:
cid = PANEL_ADC2;
break;
}
if (logy) SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LOG);
else SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LINEAR);
break;
}
return 0;
}
 
int CVICALLBACK SetGraphPropertiesCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
void *callbackData, int eventData1, int eventData2) {
 
float min, max;
int autoscale;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal(panelHandle,PANEL_MINX_5, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_5, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
float min, max;
int autoscale;
switch (event) {
case EVENT_COMMIT:
GetCtrlVal(panelHandle,PANEL_MINX_5, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_5, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
 
GetCtrlVal(panelHandle,PANEL_MINX_6, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_6, &max);
GetCtrlVal(panelHandle,PANEL_AUTOX, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max);
GetCtrlVal(panelHandle,PANEL_MINX_7, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_7, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_2, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
GetCtrlVal(panelHandle,PANEL_MINX_8, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_8, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_3, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
GetCtrlVal(panelHandle,PANEL_MINX_9, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_9, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_4, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
GetCtrlVal(panelHandle,PANEL_MINX_6, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_6, &max);
GetCtrlVal(panelHandle,PANEL_AUTOX, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max);
 
GetCtrlVal(panelHandle,PANEL_MINX_10, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_10, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_5, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
 
GetCtrlVal(panelHandle,PANEL_MINX_7, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_7, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_2, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
 
break;
}
return 0;
GetCtrlVal(panelHandle,PANEL_MINX_8, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_8, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_3, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
 
GetCtrlVal(panelHandle,PANEL_MINX_9, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_9, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_4, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
 
GetCtrlVal(panelHandle,PANEL_MINX_10, &min);
GetCtrlVal(panelHandle,PANEL_MAXX_10, &max);
GetCtrlVal(panelHandle,PANEL_AUTOY_5, &autoscale);
if (autoscale)
SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
else
SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
 
 
 
break;
}
return 0;
}
 
 
266,13 → 271,13
SetCtrlAttribute (panelHandle, PANEL_TDC1, ATTR_YNAME, H1D_GetTitleY(3) );
SetCtrlAttribute (panelHandle, PANEL_TDC2, ATTR_XNAME, H1D_GetTitleX(4) );
SetCtrlAttribute (panelHandle, PANEL_TDC2, ATTR_YNAME, H1D_GetTitleY(4) );
SetGraphLogYCB( panelHandle, PANEL_LOGY_1, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_2, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_3, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_4, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_1, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_2, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_3, EVENT_COMMIT,NULL,0,0);
SetGraphLogYCB( panelHandle, PANEL_LOGY_4, EVENT_COMMIT,NULL,0,0);
 
SetGraphPropertiesCB( panelHandle, PANEL, EVENT_COMMIT,NULL,0,0);
 
SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_LABEL_TEXT , "sampling adc data");
SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_XNAME, "t(us)" );
SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_YNAME, "U(V)" );
280,7 → 285,7
GetCtrlVal(panelHandle,PANEL_TWIN0, &twin0);
GetCtrlVal(panelHandle,PANEL_TWIN1, &twin1);
GetCtrlVal(panelHandle,PANEL_ADCTYPE, &adctype);
GetCtrlVal(panelHandle,PANEL_ITRGLEVEL , &athreshold);
GetCtrlVal(panelHandle,PANEL_ITRGLEVEL , &athreshold);
return 0;
}
 
296,6 → 301,11
static float qdc = 0;
*ninfo = 0;
printf("Run HDR LEN=%d NEVE=%d dt=%f adc=%f qdc=%f\n", ibuf[0],ibuf[1],fbuf[2],adc,qdc);
daqtime += fbuf[2];
 
SetCtrlVal(panelHandle, PANEL_CDAQTIME,daqtime);
SetCtrlVal(panelHandle, PANEL_CTIME, Timer() -starttime);
daqtime =0;
while (nr<nb) {
 
int recid = *data++;
337,36 → 347,36
adc=10000;
qdc=0;
int nqdc=0;
int ntdc=0;
int ntdc=0;
for (int k=1; k<nsamples; k++) {
float t =timebins[k];
float tp=timebins[k-1];
if (fdata[k] < adc) adc = fdata[k];
if (t>twin0 && t<twin1 ) {
nqdc++;
nqdc++;
qdc+=fdata[k];
}
}
if (fdata[k]< athreshold && fdata[k-1]> athreshold) {
double t0= tp+(athreshold-fdata[k-1])/(fdata[k]-fdata[k-1])* (t-tp);
if (ntdc>0) H1D_Fill(3+id, t0,1);
if (ntdc==0 && !excludefirst[id]) H1D_Fill(3+id, t0,1);
finfo[*ninfo+4+ntdc]=t0;
ntdc++;
finfo[*ninfo+4+ntdc]=t0;
ntdc++;
}
}
if (nqdc) qdc/=nqdc;
//printf("adc %f qdc %f\n", adc,qdc);
info[*ninfo]=(ntdc+4)*sizeof(int); // len
info[*ninfo+1]=id | 0xF0000000; // recid
finfo[*ninfo+2]=adc;
finfo[*ninfo+3]=qdc;
*ninfo+= ntdc+4;
info[*ninfo]=(ntdc+4)*sizeof(int); // len
info[*ninfo+1]=id | 0xF0000000; // recid
finfo[*ninfo+2]=adc;
finfo[*ninfo+3]=qdc;
*ninfo+= ntdc+4;
 
if (adctype)
H1D_Fill(1+id, -adc,1);
else
H1D_Fill(1+id, -qdc,1);
 
nr+=4*nsamples;
data+=nsamples;
}
414,7 → 424,7
}
if (debug) printf("Received RECID %d HDRLEN %d == read %d\n", hdr[0], size, nb);
 
int ninfo=0;
int ninfo=0;
switch (hdr[0]) {
case 0:
data[nb]=0;
424,18 → 434,18
 
GetCtrlVal(panelHandle,PANEL_CEVE , &event);
GetCtrlVal(panelHandle,PANEL_NTOTAL , &ncalls);
 
event += analyse(nb,data, evinfo, &ninfo);
if (foutput) {
if (outwaveforms) fwrite(data, 1, nb, foutput);
fwrite(evinfo, 1, ninfo*sizeof(int), foutput);
time(&t1);
if ((t1-t0)>10000) {
for (int i=0;i<4;i++) H1D_Write2File(1+i,foutput);
time(&t0);
}
}
if (outwaveforms) fwrite(data, 1, nb, foutput);
fwrite(evinfo, 1, ninfo*sizeof(int), foutput);
time(&t1);
if ((t1-t0)>10000) {
for (int i=0; i<4; i++) H1D_Write2File(1+i,foutput);
 
time(&t0);
}
}
SetCtrlVal(panelHandle,PANEL_CEVE , event);
if (event>=ncalls) StartCB (panelHandle, PANEL_START, EVENT_COMMIT, NULL,1,0);
 
451,17 → 461,23
return 0;
}
 
int rpdecimation(int i){
int rpdecimation(int i) {
 
switch (i){
case 1: return 0;
case 8: return 1;
case 64: return 2;
case 1024: return 3;
case 8192: return 4;
case 65536: return 5;
}
return 0;
switch (i) {
case 1:
return 0;
case 8:
return 1;
case 64:
return 2;
case 1024:
return 3;
case 8192:
return 4;
case 65536:
return 5;
}
return 0;
 
}
 
494,7 → 510,7
GetCtrlVal(panel,PANEL_DEBUG , &debug);
GetCtrlVal(panel,PANEL_NBEFORE , &nbefore);
GetCtrlVal(panel,PANEL_ENABLEDOUTPUT, &output);
GetCtrlVal(panel,PANEL_OUTWAVE, &outwaveforms);
GetCtrlVal(panel,PANEL_OUTWAVE, &outwaveforms);
GetCtrlVal(panel,PANEL_FILENAME, filename);
 
delay= MINTRGDELAY + nsamples - nbefore + 1;
506,8 → 522,8
 
double level =0;
GetCtrlVal(panel,PANEL_TRGLEVEL , &level);
 
 
switch (control) {
case PANEL_CONNECT: {
int state;
523,14 → 539,16
case PANEL_START: {
int state;
GetCtrlVal(panel,PANEL_START, &state);
GetCtrlVal(panel,PANEL_EXCLUDE_1, &excludefirst[0]);
GetCtrlVal(panel,PANEL_EXCLUDE_1, &excludefirst[0]);
GetCtrlVal(panel,PANEL_EXCLUDE_2, &excludefirst[1]);
if (state && eventData1==0) {
histoinit();
/* decimation n (=1,8,64...) : frequency = 125/n MHz*/
starttime=Timer();
daqtime =0;
/* decimation n (=1,8,64...) : frequency = 125/n MHz*/
for (int i=0; i<nsamples; i++) timebins[i]=(i-nbefore)* (float)decimation /125.;
if (output) foutput = fopen(filename, "wb");
printf("decimation %d\n", decimation);
printf("decimation %d\n", decimation);
SetCtrlVal(panel,PANEL_CEVE , 0);
ctrl_c=0;
hdr[0] = 0;
548,8 → 566,8
hdr[0] = 1;
hdr[1] = 2*sizeof(int);
ClientTCPWrite(chandle,&hdr[0],hdr[1],5000); // stop the transfer
printf("INFO Stopping the acquisition\n");
SetCtrlVal(panel,PANEL_START, 0);
printf("INFO Stopping the acquisition\n");
SetCtrlVal(panel,PANEL_START, 0);
if (foutput) fclose(foutput);
foutput=NULL;
}