Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 228 → Rev 229

/cvi/RedPitaya/soccli/soccli.c
6,6 → 6,9
#include <userint.h>
#include "redpitaya_gui.h"
 
#include "H1D.h"
 
 
#define NBEFORE 150
#define MAXSAMPLES 16384
#define MINTRGDELAY -8192
17,10 → 20,13
static int tfID;
int pfreq;
static int plothandle[2]= {0,0};
static int tdcplothandle[2]= {0,0};
static int adcplothandle[2]= {0,0};
int debug ;
int initialized = 0;
#define MAX_THREADS 10
int nsamples=0;
int ithreshold;
float timebins[0XFFFF];
static CmtThreadPoolHandle poolHandle = 0;
int ctrl_c=0;
29,6 → 35,46
int CVICALLBACK SocketCB (unsigned handle, int xType, int errCode, void *callbackData);
 
 
 
static int export_data (int hid) {
char filename[0xFF],rootcmd[0xFF];
int type=0;
int neve;
GetCtrlVal(panelHandle,PANEL_FILENAME,filename);
GetCtrlVal(panelHandle,PANEL_FILETYPE,&type);
FILE *fp;
switch (type) {
case 0:
case 1:
fp =fopen(filename,"wb");
if (fp) {
H1D_Write2File(hid,fp);
fclose(fp);
if (type) {
sprintf(rootcmd ,"thisroot.bat && root.exe H1Dload.cxx(\\\"%s\\\")", filename);
LaunchExecutable(rootcmd);
 
}
}
break;
case 2:
fp=fopen(filename,"w");
if (fp) {
for (int i=0; i<H1D_GetNbinsX(hid); i++) fprintf(fp,"%f\n", H1D_GetBinContent(hid,i) );
fclose(fp);
}
break;
 
}
 
 
return (0);
}
 
 
int main (int argc, char *argv[]) {
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
39,7 → 85,21
SetStdioPort (CVI_STDIO_WINDOW);
SetSleepPolicy(VAL_SLEEP_MORE);
CmtNewThreadPool (MAX_THREADS, &poolHandle);
 
H1D_Init(1, "ADC ch 1","Pulse height", 100, 0, 5000 );
H1D_SetTitleX(1,"ADC (a.u.)");
H1D_SetTitleY(1,"N");
H1D_Init(3, "TDC ch 1","TDC", 200, 0, 1000 );
H1D_SetTitleX(3,"TDC (a.u.)");
H1D_SetTitleY(3,"N");
H1D_Init(2, "ADC ch 2","Pulse height", 100, 0, 5000 );
H1D_SetTitleX(2,"ADC (a.u.)");
H1D_SetTitleY(2,"N");
H1D_Init(4, "TDC ch 2","TDC", 200, 0, 1000 );
H1D_SetTitleX(4,"TDC (a.u.)");
H1D_SetTitleY(4,"N");
//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));
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
71,8 → 131,9
}
 
 
 
int analyse(int neve, unsigned char *cdata) {
 
int *data = (int *) cdata;
for (int i=0; i<neve; i++) {
 
90,19 → 151,38
}
if ( id != *(data++) ) printf("Error\n");
int nsamples = *(data++);
//printf("nsamples %d\n", nsamples);
if (nsamples<=0 || nsamples>16*1024){
printf("Error nsamples %d\n", nsamples);
return -1;
}
if (i % pfreq == 0) {
if ( nsamples>0 && i % pfreq == 0) {
const int col[4]= {VAL_RED,VAL_GREEN,VAL_BLUE,VAL_WHITE};
if (plothandle[id]) DeleteGraphPlot (panelHandle, PANEL_GRAPH, plothandle[id], VAL_IMMEDIATE_DRAW);
//plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, (float *) data, nsamples, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]);
//float fdata[nsamples];
//for (int k=0;k<nsamples;k++) fdata[k] = *(float *) (data+k);
//printf("data0 %f %d\n", fdata[0], data[0]);
//plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, fdata, nsamples, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]);
 
plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, data, nsamples, VAL_FLOAT, VAL_INTEGER, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]);
 
H1D_Draw(1,panelHandle,PANEL_ADC1,&adcplothandle[0]);
H1D_Draw(2,panelHandle,PANEL_ADC2,&adcplothandle[1]);
H1D_Draw(3,panelHandle,PANEL_TDC1,&tdcplothandle[0]);
H1D_Draw(4,panelHandle,PANEL_TDC2,&tdcplothandle[1]);
if (debug) for (int k=0; k<10; k++) printf("%d %d (%f , %d)\n", id,k, timebins[k],data[k]);
}
data+=nsamples;
float adcdata = 10000;
for (int k=0; k<nsamples; k++) {
if (data[k] < adcdata) adcdata = data[k];
if (data[k] < ithreshold && data[k-1] > ithreshold) H1D_Fill(3+id, k,1);
}
H1D_Fill(1+id, -adcdata,1);
data+=nsamples;
}
recid = *data++;
int event = *data++;
115,12 → 195,13
unsigned char data[100000000];
int *idata = (int *) &data[0];
 
static int ncalls = 0;
 
 
int CVICALLBACK SocketCB (unsigned handle, int xType, int errCode, void *callbackData) {
 
int nb = 0 ;
static int event = 0;
static int ncalls = 0;
unsigned char cmd;
switch (xType) {
case TCP_DISCONNECT:
159,7 → 240,11
}
printf("Read nb = %d size %d\n", nb, size);
analyse(neve, data);
if (ctrl_c==0) StartCB (panelHandle, PANEL_START,EVENT_COMMIT,NULL, 0, 0 );
GetCtrlVal(panelHandle,PANEL_CEVE , &event);
GetCtrlVal(panelHandle,PANEL_NCALLS , &ncalls);
event +=1;
SetCtrlVal(panelHandle,PANEL_CEVE , event);
if (ctrl_c==0 && event < ncalls) StartCB (panelHandle, PANEL_START,EVENT_COMMIT,NULL, 0, 0 );
}
188,12 → 273,12
unsigned char mask;
unsigned char trigger;
unsigned short nsamples;
unsigned short delay;
int delay;
int nbefore;
unsigned short decimation;
unsigned short neve;
switch (event) {
case EVENT_COMMIT: {
ncalls = 0;
GetCtrlVal(panel,PANEL_IP, ip);
GetCtrlVal(panel,PANEL_TRIGGER, &trigger);
GetCtrlVal(panel,PANEL_SAMPLES, &nsamples);
203,8 → 288,10
GetCtrlVal(panel,PANEL_CH1 , &imask[1] );
GetCtrlVal(panel,PANEL_PFREQ , &pfreq);
GetCtrlVal(panel,PANEL_DEBUG , &debug);
delay= MINTRGDELAY + nsamples - NBEFORE + 1;
delay= nsamples - NBEFORE + 1;
GetCtrlVal(panel,PANEL_NBEFORE , &nbefore);
delay= MINTRGDELAY + nsamples - nbefore + 1;
//delay= nsamples - NBEFORE + 1;
mask = 0;
for (int i=0; i<2; i++) {
if (imask[i]) mask |= (1<<i);
212,8 → 299,8
 
double level =0;
GetCtrlVal(panel,PANEL_TRGLEVEL , &level);
GetCtrlVal(panel,PANEL_ITRGLEVEL , &ithreshold);
 
 
switch (control) {
case PANEL_CONNECT:
ConnectToTCPServerEx (&chandle, 9930, ip, SocketCB, NULL, 0, TCP_ANY_LOCAL_PORT);
224,6 → 311,7
hdr[0] = delay;
hdr[1] = decimation;
hdr[2] = level * 1000;
SetCtrlVal(panel,PANEL_CEVE , 0);
ClientTCPWrite(chandle,&msg[0],13,5000); // init
break;
case PANEL_START:
290,3 → 378,31
}
return 0;
}
 
int CVICALLBACK ExportCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2) {
int hid=0;
switch (event) {
case EVENT_COMMIT:
switch (control){
case PANEL_EXPORT_1: hid=1; break;
case PANEL_EXPORT_2: hid=2; break;
case PANEL_EXPORT_3: hid=3; break;
case PANEL_EXPORT_4: hid=4; break;
}
export_data(hid);
break;
}
return 0;
}
 
int CVICALLBACK ResetCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2) {
switch (event) {
case EVENT_COMMIT:
for (int i=1;i<=4;i++) H1D_Clear(i);
break;
}
return 0;
}