Rev 262 | Rev 322 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 262 | Rev 263 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | //static int tfID; |
20 | //static int tfID; |
21 | int pfreq; |
21 | int pfreq; |
22 | static int plothandle[2]= {0,0}; |
22 | static int plothandle[2]= {0,0}; |
23 | static int tdcplothandle[2]= {0,0}; |
23 | static int tdcplothandle[2]= {0,0}; |
24 | static int adcplothandle[2]= {0,0}; |
24 | static int adcplothandle[2]= {0,0}; |
25 | static int excludefirst[2]= {0,0}; |
25 | static int excludefirst[2]= {0,0}; |
26 | int debug ; |
26 | int debug ; |
27 | int initialized = 0; |
27 | int initialized = 0; |
28 | #define MAX_THREADS 10 |
28 | #define MAX_THREADS 10 |
29 | int nsamples=0; |
29 | int nsamples=0; |
30 | int adctype; |
30 | int adctype; |
31 | float athreshold, twin0,twin1; |
31 | float athreshold, twin0,twin1; |
32 | float timebins[0XFFFF]; |
32 | float timebins[0XFFFF]; |
- | 33 | float daqtime; |
|
- | 34 | double starttime; |
|
33 | 35 | ||
34 | FILE *foutput; |
36 | FILE *foutput; |
35 | int outwaveforms=0; |
37 | int outwaveforms=0; |
36 | 38 | ||
37 | static CmtThreadPoolHandle poolHandle = 0; |
39 | static CmtThreadPoolHandle poolHandle = 0; |
Line 54... | Line 56... | ||
54 | FILE *fp; |
56 | FILE *fp; |
55 | 57 | ||
56 | switch (type) { |
58 | switch (type) { |
57 | case 0: |
59 | case 0: |
58 | case 1: |
60 | case 1: |
59 | sprintf(filename,"%s_%d.root",fname, hid); |
61 | sprintf(filename,"%s_%d.root",fname, hid); |
60 | fp =fopen(filename,"wb"); |
62 | fp =fopen(filename,"wb"); |
61 | if (fp) { |
63 | if (fp) { |
62 | H1D_Write2File(hid,fp); |
64 | H1D_Write2File(hid,fp); |
63 | fclose(fp); |
65 | fclose(fp); |
64 | if (type) { |
66 | if (type) { |
Line 75... | Line 77... | ||
75 | if (fp) { |
77 | if (fp) { |
76 | for (int i=0; i<H1D_GetNbinsX(hid); i++) fprintf(fp,"%g\t%g\n", H1D_GetXBinCenter(hid,i), H1D_GetBinContent(hid,i) ); |
78 | for (int i=0; i<H1D_GetNbinsX(hid); i++) fprintf(fp,"%g\t%g\n", H1D_GetXBinCenter(hid,i), H1D_GetBinContent(hid,i) ); |
77 | fclose(fp); |
79 | fclose(fp); |
78 | printf("Histogram %d exported to %s\n", hid, filename); |
80 | printf("Histogram %d exported to %s\n", hid, filename); |
79 | } |
81 | } |
80 | 82 | ||
81 | break; |
83 | break; |
82 | 84 | ||
83 | } |
85 | } |
84 | 86 | ||
85 | 87 | ||
86 | return (0); |
88 | return (0); |
87 | } |
89 | } |
88 | 90 | ||
89 | 91 | ||
90 | int main (int argc, char *argv[]) { |
92 | int main (int argc, char *argv[]) { |
91 | if (InitCVIRTE (0, argv, 0) == 0) |
93 | if (InitCVIRTE (0, argv, 0) == 0) |
92 | return -1; /* out of memory */ |
94 | return -1; /* out of memory */ |
93 | if ((panelHandle = LoadPanel (0, "redpitaya_gui.uir", PANEL)) < 0) |
95 | if ((panelHandle = LoadPanel (0, "redpitaya_gui.uir", PANEL)) < 0) |
94 | return -1; |
96 | return -1; |
95 | 97 | ||
96 | 98 | ||
97 | SetStdioPort (CVI_STDIO_WINDOW); |
99 | SetStdioPort (CVI_STDIO_WINDOW); |
98 | SetSleepPolicy(VAL_SLEEP_MORE); |
100 | SetSleepPolicy(VAL_SLEEP_MORE); |
99 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
101 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
100 | 102 | ||
101 | //for (int i=0;i<1000;i++) H1D_Fill(1,i,i); |
- | |
102 | //H1D_Draw(1,panelHandle,PANEL_ADC1,&adcplothandle[0]); |
- | |
- | 103 | ||
103 |
|
104 | //printf("size of double = %d\n",sizeof(double)); |
104 | DisplayPanel (panelHandle); |
105 | DisplayPanel (panelHandle); |
105 | RunUserInterface (); |
106 | RunUserInterface (); |
106 | DiscardPanel (panelHandle); |
107 | DiscardPanel (panelHandle); |
107 | CmtDiscardThreadPool (poolHandle); |
108 | CmtDiscardThreadPool (poolHandle); |
108 | if (chandle!=0) DisconnectFromTCPServer (chandle); |
109 | if (chandle!=0) DisconnectFromTCPServer (chandle); |
Line 131... | Line 132... | ||
131 | return(ret); |
132 | return(ret); |
132 | } |
133 | } |
133 | 134 | ||
134 | 135 | ||
135 | int CVICALLBACK SetGraphLogYCB (int panel, int control, int event, |
136 | int CVICALLBACK SetGraphLogYCB (int panel, int control, int event, |
136 |
|
137 | void *callbackData, int eventData1, int eventData2) { |
137 | { |
138 | |
138 | - | ||
139 |
|
139 | int cid=0; |
140 |
|
140 | int logy=0; |
141 |
|
141 | switch (event) { |
142 | { |
- | |
143 |
|
142 | case EVENT_COMMIT: |
144 |
|
143 | GetCtrlVal(panel,control, &logy); |
145 |
|
144 | switch (control) { |
- | 145 | case PANEL_LOGY_1: |
|
146 |
|
146 | cid = PANEL_TDC1; |
- | 147 | break; |
|
- | 148 | case PANEL_LOGY_2: |
|
147 |
|
149 | cid = PANEL_ADC1; |
- | 150 | break; |
|
- | 151 | case PANEL_LOGY_3: |
|
148 |
|
152 | cid = PANEL_TDC2; |
- | 153 | break; |
|
- | 154 | case PANEL_LOGY_4: |
|
149 |
|
155 | cid = PANEL_ADC2; |
- | 156 | break; |
|
150 |
|
157 | } |
151 |
|
158 | if (logy) SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LOG); |
152 |
|
159 | else SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LINEAR); |
153 |
|
160 | break; |
154 |
|
161 | } |
155 |
|
162 | return 0; |
156 | } |
163 | } |
157 | 164 | ||
158 | int CVICALLBACK SetGraphPropertiesCB (int panel, int control, int event, |
165 | int CVICALLBACK SetGraphPropertiesCB (int panel, int control, int event, |
159 |
|
166 | void *callbackData, int eventData1, int eventData2) { |
160 | { |
- | |
161 | 167 | ||
162 |
|
168 | float min, max; |
163 |
|
169 | int autoscale; |
164 |
|
170 | switch (event) { |
- | 171 | case EVENT_COMMIT: |
|
- | 172 | GetCtrlVal(panelHandle,PANEL_MINX_5, &min); |
|
- | 173 | GetCtrlVal(panelHandle,PANEL_MAXX_5, &max); |
|
- | 174 | GetCtrlVal(panelHandle,PANEL_AUTOY, &autoscale); |
|
- | 175 | if (autoscale) |
|
- | 176 | SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
|
- | 177 | else |
|
- | 178 | SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
|
- | 179 | ||
- | 180 | GetCtrlVal(panelHandle,PANEL_MINX_6, &min); |
|
- | 181 | GetCtrlVal(panelHandle,PANEL_MAXX_6, &max); |
|
- | 182 | GetCtrlVal(panelHandle,PANEL_AUTOX, &autoscale); |
|
- | 183 | if (autoscale) |
|
- | 184 | SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_AUTOSCALE, min, max); |
|
- | 185 | else |
|
- | 186 | SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max); |
|
- | 187 | ||
- | 188 | ||
- | 189 | GetCtrlVal(panelHandle,PANEL_MINX_7, &min); |
|
- | 190 | GetCtrlVal(panelHandle,PANEL_MAXX_7, &max); |
|
- | 191 | GetCtrlVal(panelHandle,PANEL_AUTOY_2, &autoscale); |
|
- | 192 | if (autoscale) |
|
- | 193 | SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
|
- | 194 | else |
|
- | 195 | SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
|
165 | { |
196 | |
- | 197 | GetCtrlVal(panelHandle,PANEL_MINX_8, &min); |
|
- | 198 | GetCtrlVal(panelHandle,PANEL_MAXX_8, &max); |
|
- | 199 | GetCtrlVal(panelHandle,PANEL_AUTOY_3, &autoscale); |
|
166 |
|
200 | if (autoscale) |
- | 201 | SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
|
- | 202 | else |
|
- | 203 | SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
|
- | 204 | ||
167 |
|
205 | GetCtrlVal(panelHandle,PANEL_MINX_9, &min); |
168 |
|
206 | GetCtrlVal(panelHandle,PANEL_MAXX_9, &max); |
- | 207 | GetCtrlVal(panelHandle,PANEL_AUTOY_4, &autoscale); |
|
- | 208 | if (autoscale) |
|
- | 209 | SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
|
- | 210 | else |
|
- | 211 | SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
|
- | 212 | ||
- | 213 | GetCtrlVal(panelHandle,PANEL_MINX_10, &min); |
|
- | 214 | GetCtrlVal(panelHandle,PANEL_MAXX_10, &max); |
|
169 |
|
215 | GetCtrlVal(panelHandle,PANEL_AUTOY_5, &autoscale); |
170 |
|
216 | if (autoscale) |
171 |
|
217 | SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
172 |
|
218 | else |
173 |
|
219 | SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
- | 220 | ||
174 | 221 | ||
175 | GetCtrlVal(panelHandle,PANEL_MINX_6, &min); |
- | |
176 | GetCtrlVal(panelHandle,PANEL_MAXX_6, &max); |
- | |
177 | GetCtrlVal(panelHandle,PANEL_AUTOX, &autoscale); |
- | |
178 | if (autoscale) |
- | |
179 | SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_AUTOSCALE, min, max); |
- | |
180 | else |
- | |
181 | SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max); |
- | |
182 | - | ||
183 | - | ||
184 | GetCtrlVal(panelHandle,PANEL_MINX_7, &min); |
- | |
185 | GetCtrlVal(panelHandle,PANEL_MAXX_7, &max); |
- | |
186 | GetCtrlVal(panelHandle,PANEL_AUTOY_2, &autoscale); |
- | |
187 | if (autoscale) |
- | |
188 | SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
- | |
189 | else |
- | |
190 | SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
- | |
191 | - | ||
192 | GetCtrlVal(panelHandle,PANEL_MINX_8, &min); |
- | |
193 | GetCtrlVal(panelHandle,PANEL_MAXX_8, &max); |
- | |
194 | GetCtrlVal(panelHandle,PANEL_AUTOY_3, &autoscale); |
- | |
195 | if (autoscale) |
- | |
196 | SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
- | |
197 | else |
- | |
198 | SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
- | |
199 | - | ||
200 | GetCtrlVal(panelHandle,PANEL_MINX_9, &min); |
- | |
201 | GetCtrlVal(panelHandle,PANEL_MAXX_9, &max); |
- | |
202 | GetCtrlVal(panelHandle,PANEL_AUTOY_4, &autoscale); |
- | |
203 | if (autoscale) |
- | |
204 | SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
- | |
205 | else |
- | |
206 | SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
- | |
207 | 222 | ||
208 | GetCtrlVal(panelHandle,PANEL_MINX_10, &min); |
- | |
209 | GetCtrlVal(panelHandle,PANEL_MAXX_10, &max); |
- | |
210 | GetCtrlVal(panelHandle,PANEL_AUTOY_5, &autoscale); |
- | |
211 | if (autoscale) |
- | |
212 | SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max); |
- | |
213 | else |
- | |
214 | SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max); |
- | |
215 | - | ||
216 | - | ||
217 | - | ||
218 |
|
223 | break; |
219 |
|
224 | } |
220 |
|
225 | return 0; |
221 | } |
226 | } |
222 | 227 | ||
223 | 228 | ||
224 | int histoinit() { |
229 | int histoinit() { |
225 | int nch; |
230 | int nch; |
Line 264... | Line 269... | ||
264 | 269 | ||
265 | SetCtrlAttribute (panelHandle, PANEL_TDC1, ATTR_XNAME, H1D_GetTitleX(3) ); |
270 | SetCtrlAttribute (panelHandle, PANEL_TDC1, ATTR_XNAME, H1D_GetTitleX(3) ); |
266 | SetCtrlAttribute (panelHandle, PANEL_TDC1, ATTR_YNAME, H1D_GetTitleY(3) ); |
271 | SetCtrlAttribute (panelHandle, PANEL_TDC1, ATTR_YNAME, H1D_GetTitleY(3) ); |
267 | SetCtrlAttribute (panelHandle, PANEL_TDC2, ATTR_XNAME, H1D_GetTitleX(4) ); |
272 | SetCtrlAttribute (panelHandle, PANEL_TDC2, ATTR_XNAME, H1D_GetTitleX(4) ); |
268 | SetCtrlAttribute (panelHandle, PANEL_TDC2, ATTR_YNAME, H1D_GetTitleY(4) ); |
273 | SetCtrlAttribute (panelHandle, PANEL_TDC2, ATTR_YNAME, H1D_GetTitleY(4) ); |
269 | SetGraphLogYCB( panelHandle, PANEL_LOGY_1, EVENT_COMMIT,NULL,0,0); |
274 | SetGraphLogYCB( panelHandle, PANEL_LOGY_1, EVENT_COMMIT,NULL,0,0); |
270 | SetGraphLogYCB( panelHandle, PANEL_LOGY_2, EVENT_COMMIT,NULL,0,0); |
275 | SetGraphLogYCB( panelHandle, PANEL_LOGY_2, EVENT_COMMIT,NULL,0,0); |
271 | SetGraphLogYCB( panelHandle, PANEL_LOGY_3, EVENT_COMMIT,NULL,0,0); |
276 | SetGraphLogYCB( panelHandle, PANEL_LOGY_3, EVENT_COMMIT,NULL,0,0); |
272 | SetGraphLogYCB( panelHandle, PANEL_LOGY_4, EVENT_COMMIT,NULL,0,0); |
277 | SetGraphLogYCB( panelHandle, PANEL_LOGY_4, EVENT_COMMIT,NULL,0,0); |
273 | 278 | ||
274 | SetGraphPropertiesCB( panelHandle, PANEL, EVENT_COMMIT,NULL,0,0); |
279 | SetGraphPropertiesCB( panelHandle, PANEL, EVENT_COMMIT,NULL,0,0); |
275 | 280 | ||
276 | SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_LABEL_TEXT , "sampling adc data"); |
281 | SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_LABEL_TEXT , "sampling adc data"); |
277 | SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_XNAME, "t(us)" ); |
282 | SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_XNAME, "t(us)" ); |
278 | SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_YNAME, "U(V)" ); |
283 | SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_YNAME, "U(V)" ); |
279 | 284 | ||
280 | GetCtrlVal(panelHandle,PANEL_TWIN0, &twin0); |
285 | GetCtrlVal(panelHandle,PANEL_TWIN0, &twin0); |
281 | GetCtrlVal(panelHandle,PANEL_TWIN1, &twin1); |
286 | GetCtrlVal(panelHandle,PANEL_TWIN1, &twin1); |
282 | GetCtrlVal(panelHandle,PANEL_ADCTYPE, &adctype); |
287 | GetCtrlVal(panelHandle,PANEL_ADCTYPE, &adctype); |
283 | GetCtrlVal(panelHandle,PANEL_ITRGLEVEL , &athreshold); |
288 | GetCtrlVal(panelHandle,PANEL_ITRGLEVEL , &athreshold); |
284 | return 0; |
289 | return 0; |
285 | } |
290 | } |
286 | 291 | ||
287 | int analyse(int nb, unsigned char *cdata, int *info, int *ninfo) { |
292 | int analyse(int nb, unsigned char *cdata, int *info, int *ninfo) { |
288 | 293 | ||
Line 294... | Line 299... | ||
294 | int nr=0; |
299 | int nr=0; |
295 | static float adc = 10000; |
300 | static float adc = 10000; |
296 | static float qdc = 0; |
301 | static float qdc = 0; |
297 | *ninfo = 0; |
302 | *ninfo = 0; |
298 | printf("Run HDR LEN=%d NEVE=%d dt=%f adc=%f qdc=%f\n", ibuf[0],ibuf[1],fbuf[2],adc,qdc); |
303 | printf("Run HDR LEN=%d NEVE=%d dt=%f adc=%f qdc=%f\n", ibuf[0],ibuf[1],fbuf[2],adc,qdc); |
- | 304 | daqtime += fbuf[2]; |
|
- | 305 | ||
- | 306 | SetCtrlVal(panelHandle, PANEL_CDAQTIME,daqtime); |
|
- | 307 | SetCtrlVal(panelHandle, PANEL_CTIME, Timer() -starttime); |
|
- | 308 | daqtime =0; |
|
299 | while (nr<nb) { |
309 | while (nr<nb) { |
300 | 310 | ||
301 | int recid = *data++; |
311 | int recid = *data++; |
302 | int chmask = *data++; |
312 | int chmask = *data++; |
303 | nr +=8; |
313 | nr +=8; |
Line 315... | Line 325... | ||
315 | 325 | ||
316 | int nsamples = *(data++); |
326 | int nsamples = *(data++); |
317 | if (nsamples<=0 || nsamples>16*1024) { |
327 | if (nsamples<=0 || nsamples>16*1024) { |
318 | printf("Error nsamples %d\n", nsamples); |
328 | printf("Error nsamples %d\n", nsamples); |
319 | return -1; |
329 | return -1; |
320 | } |
330 | } |
321 | float *fdata = (float *) data; |
331 | float *fdata = (float *) data; |
322 | if ( nsamples>0 && neve % pfreq == 0) { |
332 | if ( nsamples>0 && neve % pfreq == 0) { |
323 | const int col[4]= {VAL_RED,VAL_GREEN,VAL_BLUE,VAL_WHITE}; |
333 | const int col[4]= {VAL_RED,VAL_GREEN,VAL_BLUE,VAL_WHITE}; |
324 | if (plothandle[id]) DeleteGraphPlot (panelHandle, PANEL_GRAPH, plothandle[id], VAL_IMMEDIATE_DRAW); |
334 | if (plothandle[id]) DeleteGraphPlot (panelHandle, PANEL_GRAPH, plothandle[id], VAL_IMMEDIATE_DRAW); |
325 | 335 | ||
326 | plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, fdata, nsamples, VAL_FLOAT, VAL_FLOAT, VAL_FAT_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]); |
336 | plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, fdata, nsamples, VAL_FLOAT, VAL_FLOAT, VAL_FAT_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]); |
327 | 337 | ||
328 | H1D_Draw(1,panelHandle,PANEL_ADC1,&adcplothandle[0]); |
338 | H1D_Draw(1,panelHandle,PANEL_ADC1,&adcplothandle[0]); |
329 | H1D_Draw(2,panelHandle,PANEL_ADC2,&adcplothandle[1]); |
339 | H1D_Draw(2,panelHandle,PANEL_ADC2,&adcplothandle[1]); |
330 | H1D_Draw(3,panelHandle,PANEL_TDC1,&tdcplothandle[0]); |
340 | H1D_Draw(3,panelHandle,PANEL_TDC1,&tdcplothandle[0]); |
331 | H1D_Draw(4,panelHandle,PANEL_TDC2,&tdcplothandle[1]); |
341 | H1D_Draw(4,panelHandle,PANEL_TDC2,&tdcplothandle[1]); |
332 | 342 | ||
333 | if (debug) for (int k=0; k<10; k++) printf("%d %d (%f , %d)\n", id,k, timebins[k],data[k]); |
343 | if (debug) for (int k=0; k<10; k++) printf("%d %d (%f , %d)\n", id,k, timebins[k],data[k]); |
334 | } |
344 | } |
335 | 345 | ||
336 | nr+=8; |
346 | nr+=8; |
337 | adc=10000; |
347 | adc=10000; |
338 | qdc=0; |
348 | qdc=0; |
339 | int nqdc=0; |
349 | int nqdc=0; |
340 |
|
350 | int ntdc=0; |
341 | for (int k=1; k<nsamples; k++) { |
351 | for (int k=1; k<nsamples; k++) { |
342 | float t =timebins[k]; |
352 | float t =timebins[k]; |
343 | float tp=timebins[k-1]; |
353 | float tp=timebins[k-1]; |
344 | if (fdata[k] < adc) adc = fdata[k]; |
354 | if (fdata[k] < adc) adc = fdata[k]; |
345 | if (t>twin0 && t<twin1 ) { |
355 | if (t>twin0 && t<twin1 ) { |
346 | nqdc++; |
356 | nqdc++; |
347 | qdc+=fdata[k]; |
357 | qdc+=fdata[k]; |
348 | } |
358 | } |
349 | if (fdata[k]< athreshold && fdata[k-1]> athreshold) { |
359 | if (fdata[k]< athreshold && fdata[k-1]> athreshold) { |
350 | double t0= tp+(athreshold-fdata[k-1])/(fdata[k]-fdata[k-1])* (t-tp); |
360 | double t0= tp+(athreshold-fdata[k-1])/(fdata[k]-fdata[k-1])* (t-tp); |
351 | if (ntdc>0) H1D_Fill(3+id, t0,1); |
361 | if (ntdc>0) H1D_Fill(3+id, t0,1); |
352 | if (ntdc==0 && !excludefirst[id]) H1D_Fill(3+id, t0,1); |
362 | if (ntdc==0 && !excludefirst[id]) H1D_Fill(3+id, t0,1); |
353 |
|
363 | finfo[*ninfo+4+ntdc]=t0; |
354 |
|
364 | ntdc++; |
355 | } |
365 | } |
356 | } |
366 | } |
357 | if (nqdc) qdc/=nqdc; |
367 | if (nqdc) qdc/=nqdc; |
358 | //printf("adc %f qdc %f\n", adc,qdc); |
368 | //printf("adc %f qdc %f\n", adc,qdc); |
359 |
|
369 | info[*ninfo]=(ntdc+4)*sizeof(int); // len |
360 |
|
370 | info[*ninfo+1]=id | 0xF0000000; // recid |
361 |
|
371 | finfo[*ninfo+2]=adc; |
362 |
|
372 | finfo[*ninfo+3]=qdc; |
363 |
|
373 | *ninfo+= ntdc+4; |
364 | 374 | ||
365 | if (adctype) |
375 | if (adctype) |
366 | H1D_Fill(1+id, -adc,1); |
376 | H1D_Fill(1+id, -adc,1); |
367 | else |
377 | else |
368 | H1D_Fill(1+id, -qdc,1); |
378 | H1D_Fill(1+id, -qdc,1); |
369 | 379 | ||
370 | nr+=4*nsamples; |
380 | nr+=4*nsamples; |
371 | data+=nsamples; |
381 | data+=nsamples; |
372 | } |
382 | } |
373 | recid = *data++; |
383 | recid = *data++; |
374 | int event = *data++; |
384 | int event = *data++; |
Line 412... | Line 422... | ||
412 | if (retval<1) break; |
422 | if (retval<1) break; |
413 | nb += retval; |
423 | nb += retval; |
414 | } |
424 | } |
415 | if (debug) printf("Received RECID %d HDRLEN %d == read %d\n", hdr[0], size, nb); |
425 | if (debug) printf("Received RECID %d HDRLEN %d == read %d\n", hdr[0], size, nb); |
416 | 426 | ||
417 |
|
427 | int ninfo=0; |
418 | switch (hdr[0]) { |
428 | switch (hdr[0]) { |
419 | case 0: |
429 | case 0: |
420 | data[nb]=0; |
430 | data[nb]=0; |
421 | printf("%s\n",data); |
431 | printf("%s\n",data); |
422 | break; |
432 | break; |
423 | case 1:// read |
433 | case 1:// read |
424 | 434 | ||
425 | GetCtrlVal(panelHandle,PANEL_CEVE , &event); |
435 | GetCtrlVal(panelHandle,PANEL_CEVE , &event); |
426 | GetCtrlVal(panelHandle,PANEL_NTOTAL , &ncalls); |
436 | GetCtrlVal(panelHandle,PANEL_NTOTAL , &ncalls); |
427 | 437 | ||
428 | event += analyse(nb,data, evinfo, &ninfo); |
438 | event += analyse(nb,data, evinfo, &ninfo); |
429 | if (foutput) { |
439 | if (foutput) { |
430 |
|
440 | if (outwaveforms) fwrite(data, 1, nb, foutput); |
431 |
|
441 | fwrite(evinfo, 1, ninfo*sizeof(int), foutput); |
432 |
|
442 | time(&t1); |
433 |
|
443 | if ((t1-t0)>10000) { |
434 |
|
444 | for (int i=0; i<4; i++) H1D_Write2File(1+i,foutput); |
435 | 445 | ||
436 |
|
446 | time(&t0); |
437 |
|
447 | } |
438 |
|
448 | } |
439 | SetCtrlVal(panelHandle,PANEL_CEVE , event); |
449 | SetCtrlVal(panelHandle,PANEL_CEVE , event); |
440 | if (event>=ncalls) StartCB (panelHandle, PANEL_START, EVENT_COMMIT, NULL,1,0); |
450 | if (event>=ncalls) StartCB (panelHandle, PANEL_START, EVENT_COMMIT, NULL,1,0); |
441 | 451 | ||
442 | break; |
452 | break; |
443 | default: |
453 | default: |
444 | printf("Unknown command = %d\n", hdr[0]); |
454 | printf("Unknown command = %d\n", hdr[0]); |
445 | break; |
455 | break; |
446 | } |
456 | } |
447 | break; |
457 | break; |
448 | 458 | ||
449 | } |
459 | } |
450 | } |
460 | } |
451 | return 0; |
461 | return 0; |
452 | } |
462 | } |
453 | 463 | ||
454 | int rpdecimation(int i){ |
464 | int rpdecimation(int i) { |
455 | 465 | ||
456 |
|
466 | switch (i) { |
- | 467 | case 1: |
|
457 |
|
468 | return 0; |
- | 469 | case 8: |
|
458 |
|
470 | return 1; |
- | 471 | case 64: |
|
459 |
|
472 | return 2; |
- | 473 | case 1024: |
|
460 |
|
474 | return 3; |
- | 475 | case 8192: |
|
461 |
|
476 | return 4; |
- | 477 | case 65536: |
|
462 |
|
478 | return 5; |
463 |
|
479 | } |
464 |
|
480 | return 0; |
465 | 481 | ||
466 | } |
482 | } |
467 | 483 | ||
468 | int CVICALLBACK StartCB (int panel, int control, int event, |
484 | int CVICALLBACK StartCB (int panel, int control, int event, |
469 | void *callbackData, int eventData1, int eventData2) { |
485 | void *callbackData, int eventData1, int eventData2) { |
Line 492... | Line 508... | ||
492 | GetCtrlVal(panel,PANEL_CH1 , &imask[1] ); |
508 | GetCtrlVal(panel,PANEL_CH1 , &imask[1] ); |
493 | GetCtrlVal(panel,PANEL_PFREQ , &pfreq); |
509 | GetCtrlVal(panel,PANEL_PFREQ , &pfreq); |
494 | GetCtrlVal(panel,PANEL_DEBUG , &debug); |
510 | GetCtrlVal(panel,PANEL_DEBUG , &debug); |
495 | GetCtrlVal(panel,PANEL_NBEFORE , &nbefore); |
511 | GetCtrlVal(panel,PANEL_NBEFORE , &nbefore); |
496 | GetCtrlVal(panel,PANEL_ENABLEDOUTPUT, &output); |
512 | GetCtrlVal(panel,PANEL_ENABLEDOUTPUT, &output); |
497 |
|
513 | GetCtrlVal(panel,PANEL_OUTWAVE, &outwaveforms); |
498 | GetCtrlVal(panel,PANEL_FILENAME, filename); |
514 | GetCtrlVal(panel,PANEL_FILENAME, filename); |
499 | 515 | ||
500 | delay= MINTRGDELAY + nsamples - nbefore + 1; |
516 | delay= MINTRGDELAY + nsamples - nbefore + 1; |
501 | 517 | ||
502 | mask = 0; |
518 | mask = 0; |
Line 504... | Line 520... | ||
504 | if (imask[i]) mask |= (1<<i); |
520 | if (imask[i]) mask |= (1<<i); |
505 | } |
521 | } |
506 | 522 | ||
507 | double level =0; |
523 | double level =0; |
508 | GetCtrlVal(panel,PANEL_TRGLEVEL , &level); |
524 | GetCtrlVal(panel,PANEL_TRGLEVEL , &level); |
509 | 525 | ||
510 | 526 | ||
511 | switch (control) { |
527 | switch (control) { |
512 | case PANEL_CONNECT: { |
528 | case PANEL_CONNECT: { |
513 | int state; |
529 | int state; |
514 | GetCtrlVal(panel,PANEL_CONNECT, &state); |
530 | GetCtrlVal(panel,PANEL_CONNECT, &state); |
Line 521... | Line 537... | ||
521 | } |
537 | } |
522 | break; |
538 | break; |
523 | case PANEL_START: { |
539 | case PANEL_START: { |
524 | int state; |
540 | int state; |
525 | GetCtrlVal(panel,PANEL_START, &state); |
541 | GetCtrlVal(panel,PANEL_START, &state); |
526 | GetCtrlVal(panel,PANEL_EXCLUDE_1, &excludefirst[0]); |
542 | GetCtrlVal(panel,PANEL_EXCLUDE_1, &excludefirst[0]); |
527 | GetCtrlVal(panel,PANEL_EXCLUDE_2, &excludefirst[1]); |
543 | GetCtrlVal(panel,PANEL_EXCLUDE_2, &excludefirst[1]); |
528 | if (state && eventData1==0) { |
544 | if (state && eventData1==0) { |
529 | histoinit(); |
545 | histoinit(); |
- | 546 | starttime=Timer(); |
|
- | 547 | daqtime =0; |
|
530 |
|
548 | /* decimation n (=1,8,64...) : frequency = 125/n MHz*/ |
531 | for (int i=0; i<nsamples; i++) timebins[i]=(i-nbefore)* (float)decimation /125.; |
549 | for (int i=0; i<nsamples; i++) timebins[i]=(i-nbefore)* (float)decimation /125.; |
532 | if (output) foutput = fopen(filename, "wb"); |
550 | if (output) foutput = fopen(filename, "wb"); |
533 |
|
551 | printf("decimation %d\n", decimation); |
534 | SetCtrlVal(panel,PANEL_CEVE , 0); |
552 | SetCtrlVal(panel,PANEL_CEVE , 0); |
535 | ctrl_c=0; |
553 | ctrl_c=0; |
536 | hdr[0] = 0; |
554 | hdr[0] = 0; |
537 | hdr[1] = 7*sizeof(int); |
555 | hdr[1] = 7*sizeof(int); |
538 | hdr[2] = delay; |
556 | hdr[2] = delay; |
Line 546... | Line 564... | ||
546 | ClientTCPWrite(chandle,&hdr[0],hdr[1],5000); // acquire |
564 | ClientTCPWrite(chandle,&hdr[0],hdr[1],5000); // acquire |
547 | } else { |
565 | } else { |
548 | hdr[0] = 1; |
566 | hdr[0] = 1; |
549 | hdr[1] = 2*sizeof(int); |
567 | hdr[1] = 2*sizeof(int); |
550 | ClientTCPWrite(chandle,&hdr[0],hdr[1],5000); // stop the transfer |
568 | ClientTCPWrite(chandle,&hdr[0],hdr[1],5000); // stop the transfer |
551 |
|
569 | printf("INFO Stopping the acquisition\n"); |
552 |
|
570 | SetCtrlVal(panel,PANEL_START, 0); |
553 | if (foutput) fclose(foutput); |
571 | if (foutput) fclose(foutput); |
554 | foutput=NULL; |
572 | foutput=NULL; |
555 | } |
573 | } |
556 | break; |
574 | break; |
557 | } |
575 | } |