Merge branch 'developer' into hdf5

This commit is contained in:
Dhanya Maliakal 2017-03-03 10:06:34 +01:00
commit 7e00d9f395
31 changed files with 2639 additions and 1773 deletions

View File

@ -328,20 +328,20 @@ int receiveData(int file_des, void* buf,int length, intType itype){
int nreceiving;
int nreceived;
if (file_des<0) return -1;
#ifdef VERY_VERBOSE
//#ifdef VERY_VERBOSE
printf("want to receive %d Bytes\n", length);
#endif
//#endif
while(length>0){
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length;
#ifdef VERY_VERBOSE
printf("want to receive %d Bytes\n", nreceiving);
#endif
//#ifdef VERY_VERBOSE
// printf("want to receive %d Bytes\n", nreceiving);
//#endif
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
#ifdef VERY_VERBOSE
printf("read %d \n", nreceived);
#endif
//#ifdef VERY_VERBOSE
// printf("read %d \n", nreceived);
//#endif
if(!nreceived) break;
// if(nreceived<0) break;
length-=nreceived;
@ -349,9 +349,9 @@ int receiveData(int file_des, void* buf,int length, intType itype){
// cout<<"nrec: "<<nreceived<<" waiting for ("<<length<<")"<<endl;
}
#ifdef VERY_VERBOSE
printf("received %d Bytes\n", total_received);
#endif
//#ifdef VERY_VERBOSE
// printf("received %d Bytes\n", total_received);
//#endif
if (total_received>0)
strcpy(thisClientIP,dummyClientIP);

View File

@ -372,7 +372,8 @@ enum dacIndex {
V_POWER_C = 102, /**new chiptest board */
V_POWER_D = 103, /**new chiptest board */
V_POWER_IO =104, /**new chiptest board */
V_POWER_CHIP=105 /**new chiptest board */
V_POWER_CHIP=105 ,/**new chiptest board */
V_LIMIT=106 /**new chiptest board */
};
/**
@ -439,7 +440,10 @@ enum speedVariable {
OVERSAMPLING, /**< oversampling for analog detectors */
ADC_CLOCK, /**< adc clock divider */
ADC_PHASE, /**< adc clock phase */
ADC_PIPELINE /**< adc pipeline */
ADC_PIPELINE, /**< adc pipeline */
DBIT_CLOCK, /**< adc clock divider */
DBIT_PHASE, /**< adc clock phase */
DBIT_PIPELINE /**< adc pipeline */
};
@ -454,11 +458,14 @@ enum readOutFlags {
ZERO_COMPRESSION=0x4,/**< returned data are 0-compressed */
PUMP_PROBE_MODE=0x8,/**<pump-probe mode */
BACKGROUND_CORRECTIONS=0x1000, /**<background corrections */
TOT_MODE=0x2000,/**<pump-probe mode */
CONTINOUS_RO=0x4000,/**<pump-probe mode */
PARALLEL=0x10000,/** <eiger parallel mode */
NONPARALLEL=0x20000,/** <eiger serial mode */
SAFE=0x40000/** <eiger safe mode */
TOT_MODE=0x2000,/**< pump-probe mode */
CONTINOUS_RO=0x4000,/**< pump-probe mode */
PARALLEL=0x10000,/**< eiger parallel mode */
NONPARALLEL=0x20000,/**< eiger serial mode */
SAFE=0x40000/**< eiger safe mode */,
DIGITAL_ONLY=0x80000, /** chiptest board read only digital bits (not adc values)*/
ANALOG_AND_DIGITAL=0x100000, /** chiptest board read adc values and digital bits digital bits */
DUT_CLK=0x200000, /** chiptest board fifo clock comes from device under test */
};
/**
trimming modes

View File

@ -108,9 +108,13 @@ enum {
F_PROGRAM_FPGA, /**< program FPGA */
F_RESET_FPGA, /**< reset FPGA */
F_POWER_CHIP /**< power chip */
F_POWER_CHIP, /**< power chip */
/* Always append functions hereafter!!! */
/* Always append functions before!!! */
TOO_MANY_FUNCTIONS_DEFINED=128 //you should get a compilation error if there are already so many functions defined. It conflicts with sls_receiver_funcs.h
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -28,16 +28,20 @@ u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function
u_int32_t bus_w(u_int32_t offset, u_int32_t data);
u_int32_t bus_r(u_int32_t offset);
int setPhaseShiftOnce();
int phaseStep(int st);
int getPhase();
//int setPhaseShiftOnce();
//int phaseStep(int st);
//int dbitPhaseStep(int st);
//int getDbitPhase();
int getPhase(int i);
int cleanFifo();
int setDAQRegister();
int configurePhase(int val, int i);
int configureFrequency(int val, int i);
u_int32_t putout(char *s, int modnum);
u_int32_t readin(int modnum);
u_int32_t setClockDivider(int d, int ic);
u_int32_t getClockDivider(int ic);
//u_int32_t setClockDivider(int d, int ic);
//u_int32_t getClockDivider(int ic);
void resetPLL();
u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val, int trig);
@ -47,12 +51,13 @@ u_int32_t setSetLength(int d);
u_int32_t getSetLength();
u_int32_t setWaitStates(int d);
u_int32_t getWaitStates();
u_int32_t setTotClockDivider(int d);
u_int32_t getTotClockDivider();
u_int32_t setTotDutyCycle(int d);
u_int32_t getTotDutyCycle();
//u_int32_t setTotClockDivider(int d);
//u_int32_t getTotClockDivider();
//u_int32_t setTotDutyCycle(int d);
//u_int32_t getTotDutyCycle();
u_int32_t setOversampling(int d);
u_int32_t adcPipeline(int d);
u_int32_t dbitPipeline(int d);
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
int getExtSignal(int d);
@ -184,7 +189,7 @@ int setDac(int dacnum,int dacvalue);
int setPower(int ind, int val);
ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret);
int setROI(int nroi,ROI* arg,int *retvalsize, int *ret);
int getChannels();
/*
@ -211,5 +216,11 @@ int calibration_sensor(int num, int *values, int *dacs) ;
int calibration_chip(int num, int *values, int *dacs);
*/
int64_t setSamples(int64_t value);
//int setOutputMode(int d);
int prepareSlowADCSeq();
int readSlowADC(int ichan);
int setReadOutMode(int arg);
int vLimitCompliant(int val_mV)
#endif

File diff suppressed because it is too large Load Diff

View File

@ -75,6 +75,9 @@
#define FIFO_DATA_REG 6<<11
#define FIFO_STATUS_REG 7<<11
// constant FifoDigitalInReg_c : integer := 60;
#define FIFO_DIGITAL_DATA_LSB_REG 60<<11
#define FIFO_DIGITAL_DATA_MSB_REG 61<<11
#define FIFO_DATA_REG_OFF 0x50<<11 ///////
//to read back dac registers
@ -94,7 +97,7 @@
#define GET_ACTUAL_TIME_MSB_REG 17<<11
#define GET_MEASUREMENT_TIME_LSB_REG 38<<11
#define GET_MEASUREMENT_TIME_MSB_REG 38<<11
#define GET_MEASUREMENT_TIME_MSB_REG 39<<11
#define SET_DELAY_LSB_REG 96<<11 //0x68<<11
@ -333,7 +336,8 @@
#define TIMED_GATE_BIT 0x00000004
#define CONT_RO_ENABLE_BIT 0x00080000
#define GB10_NOT_CPU_BIT 0x00001000
#define ADC_OUTPUT_DISABLE_BIT 0x00100
#define DIGITAL_OUTPUT_ENABLE_BIT 0x00200
/* for speed register */
@ -434,6 +438,9 @@
enum {run_clk_c, adc_clk_c, sync_clk_c, dbit_clk_c};
#define PLL_CNTR_ADDR_OFF 16 //PLL_CNTR_REG bits 21 downto 16 represent the counter address

View File

@ -7,46 +7,30 @@
// Hardware definitions
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHAN 32
#define NCHAN 36
#define NCHIP 1
#define NADC 1
#define NADC 9 //
#ifdef CTB
#define NDAC 24
#define NPWR 5
#else
#define NDAC 16
#define NPWR 0
#endif
/* #ifdef CTB */
/* #define NDAC 24 */
/* #define NPWR 5 */
/* #else */
/* #define NDAC 16 */
/* #define NPWR 0 */
/* #endif */
#define DAC_CMD_OFF 20
#define NMAXMODX 1
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHANS (NCHAN*NCHIP*NMAXMOD)
#define NDACS (NDAC*NMAXMOD)
#define JUNGFRAU_NCHAN (256*256)
#define JUNGFRAU_NCHIP 8
#define JUNGFRAU_NADC 0
#define JUNGFRAU_NDAC 16
#define JUNGFRAU_NCHANS (JUNGFRAU_NCHAN*JUNGFRAU_NCHIP*NMAXMOD)
/**when moench readout tested with gotthard module*/
#define GOTTHARDNCHAN 128
#define GOTTHARDNCHIP 10
#define NTRIMBITS 6
#define NCOUNTBITS 24
#define NCHIPS_PER_ADC 2
//#define TRIM_DR ((2**NTRIMBITS)-1)
//#define COUNT_DR ((2**NCOUNTBITS)-1)
#define TRIM_DR (((int)pow(2,NTRIMBITS))-1)
#define COUNT_DR (((int)pow(2,NCOUNTBITS))-1)

View File

@ -14,6 +14,7 @@
int (*flist[256])(int);
//defined in the detector specific file
/* #ifdef MYTHEND */
/* const enum detectorType myDetectorType=MYTHEN; */
@ -58,8 +59,9 @@ int adcvpp=0x4;
/** for jungfrau reinitializing macro later */
int N_CHAN=NCHAN;
int N_CHIP=NCHIP;
int N_DAC=NDAC;
int N_DAC=24;
int N_ADC=NADC;
int N_PWR=5;
int N_CHANS=NCHANS;
@ -93,21 +95,30 @@ int init_detector(int b, int checkType) {
case MOENCH03_MODULE_ID:
myDetectorType=MOENCH;
printf("This is a MOENCH03 module %d\n",MOENCH);
N_DAC=8;
N_PWR=0;
break;
case JUNGFRAU_MODULE_ID:
myDetectorType=JUNGFRAU;
printf("This is a Jungfrau module %d\n", JUNGFRAU);
printf("This is a Jungfrau module %d\n Not supported: exiting!", JUNGFRAU);
N_DAC=8;
N_PWR=0;
exit(1);
break;
case JUNGFRAU_CTB_ID:
myDetectorType=JUNGFRAUCTB;
printf("This is a Jungfrau CTB %d\n", JUNGFRAUCTB);
printf("This is a CTB %d\n", JUNGFRAUCTB);
N_DAC=24;
N_PWR=5;
break;
default:
myDetectorType=GENERIC;
printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET);
N_DAC=8;
N_PWR=0;
break;
}
@ -116,100 +127,23 @@ int init_detector(int b, int checkType) {
//control server only--
if (b) {
resetPLL();
bus_w16(CONTROL_REG, SYNC_RESET);
bus_w16(CONTROL_REG, 0);
bus_w16(CONTROL_REG, GB10_RESET_BIT);
bus_w16(CONTROL_REG, 0);
resetPLL();
bus_w16(CONTROL_REG, SYNC_RESET);
bus_w16(CONTROL_REG, 0);
bus_w16(CONTROL_REG, GB10_RESET_BIT);
bus_w16(CONTROL_REG, 0);
#ifdef MCB_FUNCS
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
if(myDetectorType == JUNGFRAU)
initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/
dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
// if(myDetectorType == JUNGFRAU)
initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/
dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/
printf("Initializing Detector\n");
//bus_w16(CONTROL_REG, SYNC_RESET); // reset registers
#endif
if (myDetectorType==JUNGFRAUCTB) prepareSlowADCSeq();
prepareSlowADC();
// testFpga();
// testRAM();
// printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG));
//moench specific
// setPhaseShiftOnce();
/*some registers set, which is in common with jungfrau, please check */
prepareADC();
//setADC(-1); //already does setdaqreg and clean fifo
// setSettings(GET_SETTINGS,-1);
/*some registers set, which is in common with jungfrau, please check */
initDac(0); initDac(8); //initializes the two dacs
if(myDetectorType==JUNGFRAU){
/** for jungfrau reinitializing macro */
N_CHAN=JUNGFRAU_NCHAN;
N_CHIP=JUNGFRAU_NCHIP;
N_DAC=JUNGFRAU_NDAC;
N_ADC=JUNGFRAU_NADC;
N_CHANS=JUNGFRAU_NCHANS;
//set dacs
int retval = -1;
int dacvalues[14][2]={
{0, 1250}, //vout_cm
{10, 1053}, //vin_com
{1, 600}, //vb_sda
{11, 1000}, //vb_colbuf
{2, 3000}, //vb_test_cur
{3, 830}, //vcascp_pixbuf
{4, 1630}, //vcascn_pixbuf
{12, 750}, //vb_pixbuf
{6, 480}, //vref_ds
{5, 1000}, //vb_ds
{7, 400}, //vref_comp
{13, 1220}, //vb_comp
{8, 1500}, //vref_prech
{9, 3000}, //vdd_prot
};
for(i=0;i<14;++i){
retval=setDac(dacvalues[i][0], dacvalues[i][1]);
if(retval!=dacvalues[i][1])
printf("Error: Setting dac %d failed, wrote %d, read %d\n",dacvalues[i][0],dacvalues[i][1],retval);
}
//power on the chips
bus_w(POWER_ON_REG,0x1);
//reset adc
writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0);
writeADC(ADCREG2,0x40);
writeADC(ADCREG3,0xf);
writeADC(ADCREG4,0x3f);
//vrefs - configurable?
writeADC(ADCREG_VREFS,0x2);
//set ADCINVERSionreg (by trial and error)
bus_w(ADC_INVERSION_REG,0x453b2a9c);
//set adc_pipeline
bus_w(ADC_PIPELINE_REG,0x20); //same as ADC_OFFSET_REG
//set dbit_pipeline
bus_w(DBIT_PIPELINE_REG,0x100e);
usleep(1000000);//1s
//reset mem machine fifos fifos
bus_w(MEM_MACHINE_FIFOS_REG,0x4000);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
//reset run control
bus_w(MEM_MACHINE_FIFOS_REG,0x0400);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
//set default setting
setSettings(DYNAMICGAIN,-1);
}
//Initialization of acquistion parameters
@ -236,12 +170,13 @@ int init_detector(int b, int checkType) {
// getDynamicRange();
/* both these functions setROI and allocateRAM should go into the control server part. */
if(myDetectorType!=JUNGFRAU){
int retvalsize,ret;
setROI(-1,NULL,&retvalsize,&ret);
allocateRAM();
}
int retvalsize,ret;
setROI(-1,NULL,&retvalsize,&ret);
allocateRAM();
setSamples(1);
bus_w(DAC_REG,0xffff);
return OK;
}
@ -332,6 +267,7 @@ int function_table() {
flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal;
flist[F_SET_CTB_PATTERN]=&set_ctb_pattern;
flist[F_WRITE_ADC_REG]=&write_adc_register;
flist[F_POWER_CHIP]=&power_chip;
return OK;
}
@ -418,7 +354,7 @@ int get_detector_type(int file_des) {
/* receive arguments */
/* execute action */
ret=myDetectorType;
ret=JUNGFRAUCTB;//myDetectorType;
#ifdef VERBOSE
printf("Returning detector type %d\n",ret);
@ -1045,6 +981,7 @@ int set_dac(int file_des) {
int n;
int val;
int mV=0;
int v;
sprintf(mess,"Can't set DAC\n");
n = receiveDataOnly(file_des,arg,sizeof(arg));
@ -1081,27 +1018,35 @@ int set_dac(int file_des) {
#ifdef MCB_FUNCS
if (ret==OK) {
if (differentClients==1 && lockStatus==1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if (ind<NDAC-NPWR) {
if (ind<N_DAC-N_PWR) {
if (mV) {
v=val;
if (val>2500)
val=-1;
printf("%d mV is ",val);
if (val>0)
val=val/2500*4095;
printf("%d DACu\n", val);
} else if (val>4095)
val=-1;
} else {
v=val*2500/4095;
if (val>4095) {
val=-1;
}
}
if (vLimitCompliant(v))
retval=setDac(ind,val);
retval=setDac(ind,val);
} else {
switch (ind) {
case ADC_VPP:
@ -1126,23 +1071,36 @@ int set_dac(int file_des) {
case V_POWER_D:
case V_POWER_IO:
case V_POWER_CHIP:
if (mV) {
if (vLimitCompliant(val))
retval=setPower(ind,val);
else
printf("********power %d exceeds voltage limits", ind);
} else
printf("********power %d should be set in mV instead od DACu", ind);
break;
case V_LIMIT:
if (mV) {
retval=setPower(ind,val);
} else
printf("********power %d should be set in mV instead od DACu", ind);
break;
default:
printf("**********No dac with index %d\n",ind);
printf("**********%d %d\n",N_DAC,N_PWR);
ret=FAIL;
}
}
}
}
if(ret==OK){
if (ind<NDAC-NPWR) {
if (ind<N_DAC-N_PWR) {
if (mV) {
printf("%d DACu is ",retval);
retval1=2500*retval/4095;
@ -1152,17 +1110,17 @@ int set_dac(int file_des) {
} else
retval1=retval;
}
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
//#ifdef VERBOSE
printf("DAC set to %d mV\n", retval);
//#endif
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
else{
if (differentClients)
ret=FORCE_UPDATE;
}
@ -1223,7 +1181,6 @@ int get_adc(int file_des) {
idac=TEMP_ADC;
break;
default:
readSlowADC(ind);
printf("Unknown DAC index %d\n",ind);
sprintf(mess,"Unknown DAC index %d\n",ind);
ret=FAIL;
@ -1231,7 +1188,16 @@ int get_adc(int file_des) {
}
if (ret==OK)
retval=getTemperatureByModule(idac,imod);
retval=getTemperatureByModule(idac,imod);
else {
retval=readSlowADC(ind-1000);
if (retval>=0) {
ret=OK;
}
}
#endif
#ifdef VERBOSE
@ -2066,7 +2032,7 @@ int get_run_status(int file_des) {
}
int read_frame(int file_des) {
int n;
u_int16_t* p=NULL;
if (differentClients==1 && lockStatus==1) {
@ -2087,14 +2053,15 @@ int read_frame(int file_des) {
nframes++;
dataretval=(char*)ram_values;
dataret=OK;
#ifdef VERBOSE
//#ifdef VERBOSE
printf("sending data of %d frames\n",nframes);
#endif
//#endif
sendDataOnly(file_des,&dataret,sizeof(dataret));
#ifdef VERYVERBOSE
printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes*nSamples);
#endif
sendDataOnly(file_des,dataretval,dataBytes*nSamples);
//#ifdef VERYVERBOSE
printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes);
//#endif
n=sendDataOnly(file_des,dataretval,dataBytes);
printf("Sent %d bytes\n",n);
} else {
if (getFrames()>-1) {
dataret=FAIL;
@ -2242,6 +2209,9 @@ int set_timer(int file_des) {
case CYCLES_NUMBER:
retval=setTrains(tns);
break;
case SAMPLES_JCTB:
retval=setSamples(tns);
break;
default:
ret=FAIL;
sprintf(mess,"timer index unknown %d\n",ind);
@ -2343,6 +2313,9 @@ int get_time_left(int file_des) {
case FRAMES_FROM_START_PG:
retval=getFramesFromStart();
break;
case SAMPLES_JCTB:
retval=setSamples(-1);
break;
default:
ret=FAIL;
sprintf(mess,"timer index unknown %d\n",ind);
@ -2433,7 +2406,7 @@ int set_roi(int file_des) {
int n=0;
int retvalsize=0;
ROI arg[MAX_ROIS];
ROI* retval=0;
int retval;
strcpy(mess,"Could not set/get roi\n");
// u_int32_t disable_reg=0;
@ -2443,43 +2416,33 @@ int set_roi(int file_des) {
ret=FAIL;
}
if(myDetectorType == JUNGFRAU){
ret = FAIL;
strcpy(mess,"Not applicable/implemented for this detector\n");
printf("Error:Set ROI-%s",mess);
if(nroi>=0){
n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI));
if (n != (nroi*sizeof(ROI))) {
sprintf(mess,"Received wrong number of bytes for ROI\n");
ret=FAIL;
}
printf("Setting ROI to:");
for( i=0;i<nroi;i++)
printf("%d\t%d\t%d\t%d\n",arg[i].xmin,arg[i].xmax,arg[i].ymin,arg[i].ymax);
// printf("Error: Function 41 or Setting ROI is not yet implemented in Moench!\n");
}
else{
if(nroi>=0){
n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI));
if (n != (nroi*sizeof(ROI))) {
sprintf(mess,"Received wrong number of bytes for ROI\n");
ret=FAIL;
}
printf("Setting ROI to:");
for( i=0;i<nroi;i++)
printf("%d\t%d\t%d\t%d\n",arg[i].xmin,arg[i].xmax,arg[i].ymin,arg[i].ymax);
printf("Error: Function 41 or Setting ROI is not yet implemented in Moench!\n");
}
/* execute action if the arguments correctly arrived*/
if (lockStatus==1 && differentClients==1){//necessary???
sprintf(mess,"Detector locked by %s\n", lastClientIP);
ret=FAIL;
}
else{
retval=setROI(nroi,arg,&retvalsize,&ret);
if (ret==FAIL){
printf("mess:%s\n",mess);
sprintf(mess,"Could not set all roi, should have set %d rois, but only set %d rois\n",nroi,retvalsize);
}
}
/* execute action if the arguments correctly arrived*/
if (lockStatus==1 && differentClients==1 && nroi>=0){//necessary???
sprintf(mess,"Detector locked by %s\n", lastClientIP);
ret=FAIL;
} else{
retval=setROI(nroi,arg,&retvalsize,&ret);
if (ret==FAIL){
printf("mess:%s\n",mess);
sprintf(mess,"Could not set all roi, should have set %d rois, but only set %d rois\n",nroi,retvalsize);
}
}
if(ret==OK && differentClients){
printf("Force update\n");
ret=FORCE_UPDATE;
@ -2491,7 +2454,7 @@ int set_roi(int file_des) {
n = sendDataOnly(file_des,mess,sizeof(mess));
else{
sendDataOnly(file_des,&retvalsize,sizeof(retvalsize));
sendDataOnly(file_des,retval,retvalsize*sizeof(ROI));
sendDataOnly(file_des,arg,retvalsize*sizeof(ROI));
}
/*return ok/fail*/
return ret;
@ -2525,15 +2488,17 @@ int set_speed(int file_des) {
if (ret==OK) {
if (arg==PHASE_SHIFT || arg==ADC_PHASE) {
/* if (arg==PHASE_SHIFT || arg==ADC_PHASE) { */
retval=phaseStep(val);
/* retval=phaseStep(val); */
} else {
/* } else if ( arg==DBIT_PHASE) { */
/* retval=dbitPhaseStep(val); */
/* } else { */
if (val!=-1) {
/* if (val!=-1) { */
if (differentClients==1 && lockStatus==1 && val>=0) {
@ -2541,8 +2506,23 @@ int set_speed(int file_des) {
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else {
switch (arg) {
case PHASE_SHIFT:
case ADC_PHASE:
if (val==-1)
retval=getPhase(run_clk_c);
else
retval=configurePhase(val,run_clk_c);
break;
case DBIT_PHASE:
if (val==-1)
retval=getPhase(dbit_clk_c);
else
retval=configurePhase(val,dbit_clk_c);
break;
case CLOCK_DIVIDER:
retval=setClockDivider(val,0);
retval=configureFrequency(val,run_clk_c);//setClockDivider(val,0);
break;
/* case PHASE_SHIFT: */
@ -2554,12 +2534,14 @@ int set_speed(int file_des) {
break;
case ADC_CLOCK:
retval=setClockDivider(val,1);
retval=configureFrequency(val,adc_clk_c);//setClockDivider(val,1);
configureFrequency(val,sync_clk_c);
break;
case DBIT_CLOCK:
retval=configureFrequency(val,dbit_clk_c);//setClockDivider(val,2);
break;
/* case ADC_PHASE: */
/* retval=phaseStep(val,1); */
/* break; */
case ADC_PIPELINE:
@ -2567,56 +2549,23 @@ int set_speed(int file_des) {
break;
case DBIT_PIPELINE:
retval=dbitPipeline(val);
break;
default:
ret=FAIL;
sprintf(mess,"Unknown speed parameter %d",arg);
}
}
}
// }
}
switch (arg) {
case CLOCK_DIVIDER:
retval=getClockDivider(0);
break;
case PHASE_SHIFT:
retval=getPhase();
// retval=phaseStep(-1);
//ret=FAIL;
//sprintf(mess,"Cannot read phase",arg);
break;
case OVERSAMPLING:
retval=setOversampling(-1);
break;
case ADC_CLOCK:
retval=getClockDivider(1);
break;
case ADC_PHASE:
retval=getPhase();
break;
case ADC_PIPELINE:
retval=adcPipeline(-1);
break;
default:
ret=FAIL;
sprintf(mess,"Unknown speed parameter %d",arg);
}
}
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL) {
n = sendDataOnly(file_des,mess,sizeof(mess));
@ -2631,15 +2580,34 @@ int set_speed(int file_des) {
int set_readout_flags(int file_des) {
enum readOutFlags arg;
int ret=FAIL;
int ret=OK;
enum readOutFlags v=-1;
receiveDataOnly(file_des,&arg,sizeof(arg));
sprintf(mess,"can't set readout flags for moench\n");
switch (arg) {
case NORMAL_READOUT:
case DIGITAL_ONLY:
case ANALOG_AND_DIGITAL:
case GET_READOUT_FLAGS:
break;
default:
sprintf(mess,"unknown readout flags for jctb\n");
ret=FAIL;
}
if (ret==OK)
v=setReadOutMode(arg);
if (v<0) {
ret=FAIL;
sprintf(mess,"found non valid readout mode (neither analog nor digital)\n");
}
sendDataOnly(file_des,&ret,sizeof(ret));
sendDataOnly(file_des,mess,sizeof(mess));
if (ret==OK)
sendDataOnly(file_des,&v,sizeof(v));
else
sendDataOnly(file_des,mess,sizeof(mess));
// sendDataOnly(file_des,mess,sizeof(mess));
return ret;
}
@ -2786,6 +2754,7 @@ int send_update(int file_des) {
int n;//int thr, n;
//int it;
int64_t retval, tns=-1;
enum readOutFlags v=-1;
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
n = sendDataOnly(file_des,&nModX,sizeof(nModX));
n = sendDataOnly(file_des,&nModY,sizeof(nModY));
@ -2809,6 +2778,11 @@ int send_update(int file_des) {
n = sendDataOnly(file_des,&retval,sizeof(int64_t));*/
retval=setTrains(tns);
n = sendDataOnly(file_des,&retval,sizeof(int64_t));
retval=setSamples(tns);
n = sendDataOnly(file_des,&retval,sizeof(int64_t));
v=setReadOutMode(-1);
sendDataOnly(file_des,&v,sizeof(v));
if (lockStatus==0) {
strcpy(lastClientIP,thisClientIP);
@ -3179,13 +3153,14 @@ int reset_counter_block(int file_des) {
int start_receiver(int file_des) {
int ret=OK;
int n=0;
strcpy(mess,"Could not start receiver\n");
/* execute action if the arguments correctly arrived*/
#ifdef MCB_FUNCS
//#ifdef MCB_FUNCS
if (lockStatus==1 && differentClients==1){//necessary???
sprintf(mess,"Detector locked by %s\n", lastClientIP);
ret=FAIL;
@ -3193,7 +3168,7 @@ int start_receiver(int file_des) {
else
ret = startReceiver(1);
#endif
//#endif
if(ret==OK && differentClients){
@ -3513,3 +3488,51 @@ int write_adc_register(int file_des) {
return ret;
}
int power_chip(int file_des) {
int retval=-1;
int ret=OK;
int arg=-1;
int n;
n = receiveDataOnly(file_des,&arg,sizeof(arg));
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
#ifdef VERBOSE
printf("Power chip to %d\n", arg);
#endif
if (differentClients==1 && lockStatus==1 && arg!=-1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else {
retval=powerChip(arg);
#ifdef VERBOSE
printf("Chip powered: %d\n",retval);
#endif
if (retval==arg || arg<0) {
ret=OK;
} else {
ret=FAIL;
printf("Powering chip failed, wrote %d but read %d\n", arg, retval);
}
}
if (ret==OK && differentClients==1)
ret=FORCE_UPDATE;
/* send answer */
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL) {
n += sendDataOnly(file_des,mess,sizeof(mess));
} else
n += sendDataOnly(file_des,&retval,sizeof(retval));
return ret;
}

View File

@ -94,5 +94,6 @@ int calibrate_pedestal(int);
int set_roi(int);
int set_ctb_pattern(int);
int write_adc_register(int);;
int write_adc_register(int);
int power_chip(int);
#endif

View File

@ -1032,6 +1032,35 @@ int setContinousReadOut(int d) {
}
<<<<<<< HEAD
int startReceiver(int start) {
u_int32_t addr=CONFIG_REG;
//#ifdef VERBOSE
if(start)
printf("Setting up detector to send to Receiver\n");
else
printf("Setting up detector to send to CPU\n");
//#endif
int reg=bus_r(addr);
//for start recever, write 0 and for stop, write 1
if (!start)
bus_w(CONFIG_REG,reg&(~GB10_NOT_CPU_BIT));
else
bus_w(CONFIG_REG,reg|GB10_NOT_CPU_BIT);
reg=bus_r(addr);
//#ifdef VERBOSE
printf("Config Reg %x\n", reg);
//#endif
int d =reg&GB10_NOT_CPU_BIT;
if(d!=0) d=1;
if(d!=start)
return OK;
else
return FAIL;
}
=======
>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a
u_int64_t getDetectorNumber() {
@ -1261,6 +1290,17 @@ int64_t getTrains(){
}
int64_t setSamples(int64_t value){
if (value>=0)
bus_w(NSAMPLES_REG,value);
return bus_r(NSAMPLES_REG);
}
int64_t getSamples(){
return bus_r(NSAMPLES_REG);//get64BitReg(GET_CYCLES_LSB_REG, GET_CYCLES_MSB_REG);
}
int64_t setProbes(int64_t value){
return 0;
}
@ -1835,8 +1875,123 @@ u_int32_t fifoReadStatus(){
return bus_r(STATUS_REG)&(SOME_FIFO_FULL_BIT | ALL_FIFO_EMPTY_BIT);
}
<<<<<<< HEAD
u_int16_t* fifo_read_event(int ns)
{
int i=0;//, j=0;
/* volatile u_int16_t volatile *dum; */
volatile u_int16_t a;
/*volatile u_int32_t val;*/
// volatile u_int32_t volatile *dum;
// volatile u_int32_t a;
bus_w16(DUMMY_REG,0); //
/* #ifdef TIMEDBG */
/* gettimeofday(&tse,NULL); */
/* #endif */
if (ns==0) {
a=bus_r16(LOOK_AT_ME_REG);
// volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG);
// bus_w(DUMMY_REG,0);
while(a==0) {
if (runBusy()==0) {
a = bus_r(LOOK_AT_ME_REG);
if (a==0) {
printf("no frame found and acquisition finished - exiting\n");
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
return NULL;
} else {
// printf("status idle, look at me %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
break;
}
}
a = bus_r(LOOK_AT_ME_REG);
//#ifdef VERBOSE
// printf(".");
//#endif
}
/* #ifdef TIMEDBG */
/* // tsss=tss; */
/* gettimeofday(&tss,NULL); */
/* printf("look for data = %ld usec\n", (tss.tv_usec) - (tse.tv_usec)); */
/* #endif */
}
// printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
/* dma_memcpy(now_ptr,values ,dataBytes); */
/* #else */
bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos
bus_w16(DUMMY_REG,0);
// i=0;//
/* for (i=0; i<32; i++) { */
/* /\* while (((adcDisableMask&(3<<((i)*2)))>>((i)*2))==3) { *\/ */
/* /\* i++; *\/ */
/* /\* if (i>15) *\/ */
/* /\* break; *\/ */
/* /\* } *\/ */
/* /\* if (i<16) { *\/ */
/* bus_w16(DUMMY_REG,i); */
/* } */
/* val=*values; */
// bus_w16(DUMMY_REG,0); //
for (i=0; i<32; i++) {
// bus_w16(DUMMY_REG,i);
// bus_r16(DUMMY_REG);
/* dum=(((u_int16_t*)(now_ptr))+i); */
/* *dum=bus_r16(FIFO_DATA_REG); */
/* a=bus_r16(FIFO_DATA_REG); */
//dum=(((u_int32_t*)(now_ptr))+i);
// a=*values;//bus_r(FIFO_DATA_REG);
// if ((adcDisableMask&(3<<(i*2)))==0) {
*((u_int32_t*)now_ptr)=*values;//bus_r(FIFO_DATA_REG);
if (i!=0 || ns!=0) {
a=0;
while (*((u_int32_t*)now_ptr)==*((u_int32_t*)(now_ptr)-1) && a++<10) {
// printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1));
*((u_int32_t*)now_ptr)=*values;
// printf("%d-",i);
}
}
now_ptr+=4;
// }
/* while (((adcDisableMask&(3<<((i+1)*2)))>>((i+1)*2))==3) { */
/* i++; */
/* } */
// if (((adcDisableMask&(3<<((i+1)*2)))>>((i+1)*2))!=3) {
printf("sample %d fifo %d status %08x\n",ns,i,bus_r16(FIFO_STATUS_REG));
bus_w16(DUMMY_REG,i+1);
// }
// *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG);
}
// bus_w16(DUMMY_REG,0); //
/* #ifdef TIMEDBG */
/* gettimeofday(&tss,NULL); */
/* printf("read data loop = %ld usec\n",(tss.tv_usec) - (tse.tv_usec)); */
/* #endif */
#ifdef VERBOSE
printf("*");
#endif
return ram_values;
=======
u_int32_t fifo_full(void){
return bus_r(STATUS_REG)&SOME_FIFO_FULL_BIT;
>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a
}
@ -1921,12 +2076,36 @@ return dataout;
int setDynamicRange(int dr) {
<<<<<<< HEAD
if (dr%16==0 && dr>0) {
dynamicRange=16;
// nSamples=dr/16;
// bus_w(NSAMPLES_REG,nSamples);
}
getDynamicRange();
allocateRAM();
printf("Setting dataBytes to %d: dr %d; samples %d\n",dataBytes, dynamicRange, nSamples);
return getDynamicRange();
=======
return dynamicRange;
>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a
}
int getDynamicRange() {
<<<<<<< HEAD
if(myDetectorType == JUNGFRAU){
dynamicRange=16;
return dynamicRange;
}
nSamples=bus_r(NSAMPLES_REG);
getChannels();
dataBytes=nModX*N_CHIP*getChannels()*2*nSamples;
return dynamicRange;//*bus_r(NSAMPLES_REG);//nSamples;
=======
return dynamicRange;
>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a
}
int testBus() {

View File

@ -120,9 +120,13 @@ int64_t getPeriod();
int64_t setTrains(int64_t value);
int64_t getTrains();
int64_t setProbes(int64_t value);
int64_t getProbes();
int64_t setSamples(int64_t value);
int64_t getSamples();
int64_t getProgress();
int64_t setProgress();

View File

@ -71,7 +71,7 @@
#define CONTROL_REG 79<<11//0x24<<11
#define STATUS_REG 2<<11 //0x25<<11
#define CONFIG_REG 77<<11//0x26<<11
#define EXT_SIGNAL_REG 78<<11// 0x27<<11
#define EXT_SIGNAL_REG 78<<11// 0x4E<<11
#define FPGA_SVN_REG 0x29<<11

View File

@ -1850,13 +1850,38 @@ int set_timer(int file_des) {
ret=FAIL;
}
if (ret!=OK) {
printf(mess);
}
int set_timer(int file_des) {
enum timerIndex ind;
int64_t tns;
int n;
int64_t retval;
int ret=OK;
printf("set\n");
sprintf(mess,"can't set timer\n");
n = receiveDataOnly(file_des,&ind,sizeof(ind));
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
n = receiveDataOnly(file_des,&tns,sizeof(tns));
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
if (ret!=OK) {
printf(mess);
}
#ifdef VERBOSE
printf("setting timer %d to %lld ns\n",ind,tns);
#endif
if (ret==OK) {
if (differentClients==1 && lockStatus==1 && tns!=-1) {

View File

@ -1463,7 +1463,8 @@ int* multiSlsDetector::getDataFromDetector() {
if(!nodatadetectortype)
retval=new int[nel];
p=retval;
// cout << "multi: " << thisMultiDetector->dataBytes << endl;
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
if (detectors[id]) {
@ -1807,6 +1808,8 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){
}
}
if (index==SAMPLES_JCTB)
setDynamicRange();
// check return values!!!
thisMultiDetector->timerValue[index]=ret1;
@ -2272,30 +2275,41 @@ slsDetectorDefs::ROI* multiSlsDetector::getROI(int &n){
double* multiSlsDetector::decodeData(int *datain, double *fdata) {
double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) {
double *dataout;
if (fdata)
dataout=fdata;
else
dataout=new double[thisMultiDetector->numberOfChannels];
else {
if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) {
nn=thisMultiDetector->dataBytes/2;
dataout=new double[nn];
} else {
nn=thisMultiDetector->numberOfChannels;
dataout=new double[nn];
}
}
// int ich=0;
int n;
double *detp=dataout;
int *datap=datain;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
detectors[i]->decodeData(datap, detp);
detectors[i]->decodeData(datap, n, detp);
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
#ifdef VERBOSE
cout << "increment pointers " << endl;
#endif
datap+=detectors[i]->getDataBytes()/sizeof(int);
detp+=detectors[i]->getTotalNumberOfChannels();
detp+=n;
// if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) {
// detp+=detectors[i]->getDataBytes()/2;
// } else {
// detp+=detectors[i]->getTotalNumberOfChannels();
// }
#ifdef VERBOSE
cout << "done " << endl;
#endif
@ -3731,6 +3745,7 @@ int multiSlsDetector::setDynamicRange(int p) {
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
thisMultiDetector->dataBytes+=detectors[idet]->getDataBytes();
// cout << "db " << idet << " " << detectors[idet]->getDataBytes() << endl;
thisMultiDetector->numberOfChannels+=detectors[idet]->getTotalNumberOfChannels();
if (ret==-100)
ret=ret1;
@ -5196,6 +5211,7 @@ int multiSlsDetector::getData(const int isocket, const bool masking, int* image,
void multiSlsDetector::readFrameFromReceiver(){
//determine number of half readouts and maxX and maxY
@ -5259,7 +5275,7 @@ void multiSlsDetector::readFrameFromReceiver(){
return;
}
int* multiframe=new int[nel]();
int nch;
volatile uint64_t dataThreadMask = 0x0;
@ -5335,7 +5351,7 @@ void multiSlsDetector::readFrameFromReceiver(){
//send data to callback
if(running){
fdata = decodeData(multiframe);
fdata = decodeData(multiframe,nch);
if ((fdata) && (dataReady)){
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny);
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
@ -5356,8 +5372,6 @@ void multiSlsDetector::readFrameFromReceiver(){
}
int multiSlsDetector::lockReceiver(int lock) {
int ret=-100, ret1;

View File

@ -838,7 +838,7 @@ class multiSlsDetector : public slsDetectorUtils {
\param datain data from the detector
\returns pointer to a double array with a data per channel
*/
double* decodeData(int *datain, double *fdata=NULL);
double* decodeData(int *datain, int &nn, double *fdata=NULL);
@ -1242,8 +1242,7 @@ class multiSlsDetector : public slsDetectorUtils {
/** Reads frames from receiver through a constant socket
*/
void readFrameFromReceiver();
/** Locks/Unlocks the connection to the receiver
/** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver
*/

View File

@ -63,15 +63,15 @@ int initDetector() {
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
detectorDacs=malloc(n*NDAC*sizeof(dacs_t));
detectorAdcs=malloc(n*NADC*sizeof(dacs_t));
#ifdef VERBOSE
//#ifdef VERBOSE
printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n);
printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP);
printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN);
printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC);
printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC);
#endif
//#endif
for (imod=0; imod<n; imod++) {
printf("module %d\n",imod);
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
@ -87,6 +87,7 @@ int initDetector() {
(detectorModules+imod)->reg=0;
/* initialize registers, dacs, retrieve sn, adc values etc */
}
printf("modules done\n");
thisSettings=UNINITIALIZED;
sChan=noneSelected;
sChip=noneSelected;
@ -99,9 +100,12 @@ int initDetector() {
clearSSregister(ALLMOD);
putout("0000000000000000",ALLMOD);
printf("dr\n");
/* initialize dynamic range etc. */
dynamicRange=getDynamicRange();
printf("nmod\n");
nModX=setNMod(-1);
printf("done\n");
@ -919,6 +923,7 @@ int setSettings(int i) {
for (ind=0; ind<NDAC; ind++)
v[ind]=-1;
// printf("vind\n");
if (i!=GET_SETTINGS) {
switch (i) {
case STANDARD:; case FAST:; case HIGHGAIN:
@ -938,19 +943,20 @@ int setSettings(int i) {
irgpr=detectorDacs[4+imod*NDAC];
irgsh1=detectorDacs[imod*NDAC+RGSH1];
irgsh2=detectorDacs[imod*NDAC+RGSH2];
*/
*/
// printf("regs\n");
irgpr=setDACRegister(RGPR,-1,imod);
irgsh1=setDACRegister(RGSH1,-1,imod);
irgsh2=setDACRegister(RGSH2,-1,imod);
for (is=STANDARD; is<UNDEFINED; is++) {
for (is=STANDARD; is<sizeof(rgpr); is++){//;UNDEFINED; is++) {
if (irgpr==rgpr[is] && irgsh1==rgsh1[is] && irgsh2==rgsh2[is]) {
isett=is;
}
}
#ifdef VERBOSE
printf("Settings of module 0 are %d\n",isett);
#endif
//#ifdef VERBOSE
// printf("Settings of module 0 are %d\n",isett);
//#endif
for (imod=1; imod<nModX; imod++) {
if (isett!=UNDEFINED) {
irgpr=setDACRegister(RGPR,-1,imod);

View File

@ -61,12 +61,18 @@ int init_detector( int b) {
if (b) {
#ifdef MCB_FUNCS
initDetector();
printf("init \n");
setSettings(GET_SETTINGS);
printf("get settings \n");
testRAM();
printf("test ram \n");
#endif
setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
printf("timing \n");
setMaster(GET_MASTER);
printf("master \n");
setSynchronization(GET_SYNCHRONIZATION_MODE);
printf("sync \n");
}
strcpy(mess,"dummy message");
strcpy(lastClientIP,"none");

View File

@ -23,7 +23,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
int sz;
//shmId=-1;
#ifdef VERBOSE
cout << "init shm"<< endl;
#endif
switch(type) {
case MYTHEN:
nch=128; // complete mythen system
@ -80,7 +82,7 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
no=0;
break;
case JUNGFRAUCTB:
nch=32;
nch=36; //36? is using digital value as well
nm=1; //modules/detector
nc=1; //chips
nd=16; //dacs+adcs
@ -123,7 +125,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
std::cout<<"*** shmat error (server) ***" << std::endl;
return shm_id;
}
#ifdef VERBOSE
cout <<"shm done"<<endl;
#endif
/**
shm_id returns -1 is shared memory initialization fails
@ -243,6 +247,7 @@ slsDetector::slsDetector(int pos, detectorType type, int id, multiSlsDetector *p
/**Initializes the detector stucture \sa initializeDetectorSize
*/
cout << "init det size"<< endl;
initializeDetectorSize(type);
@ -636,12 +641,12 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->dynamicRange=16;
break;
case JUNGFRAUCTB:
thisDetector->nChan[X]=32;
thisDetector->nChan[X]=36;
thisDetector->nChan[Y]=1;
thisDetector->nChip[X]=1;
thisDetector->nChip[Y]=1;
thisDetector->nDacs=16;
thisDetector->nAdcs=1;
thisDetector->nAdcs=9;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=1;
@ -686,12 +691,14 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->timerValue[FRAME_NUMBER]=1;
thisDetector->timerValue[MEASUREMENTS_NUMBER]=1;
thisDetector->timerValue[CYCLES_NUMBER]=1;
thisDetector->timerValue[SAMPLES_JCTB]=1;
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8;
if(thisDetector->myDetectorType==JUNGFRAUCTB) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->dynamicRange/8;
cout << "here1" << endl;
getTotalNumberOfChannels();
// thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
}
if(thisDetector->myDetectorType==MYTHEN){
if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0)
@ -793,6 +800,15 @@ int slsDetector::initializeDetectorSize(detectorType type) {
//update?!?!?!?
if(thisDetector->myDetectorType==JUNGFRAUCTB) {
// cout << "here2" << endl;
getTotalNumberOfChannels();
//thisDetector->nChan[X]=32;
//thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y];
//thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
}
}
@ -1030,7 +1046,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t)
na=0;
break;
case JUNGFRAUCTB:
nch=32;//32;
nch=36;
nm=1;
nc=1;
nd=8; // dacs+adcs
@ -1673,7 +1689,56 @@ slsDetectorDefs::detectorType slsDetector::getDetectorsType(int pos){
}
// /** number of rois defined */
// int nROI;
// /** list of rois */
// ROI roiLimits[MAX_ROIS];
// /** readout flags */
// readOutFlags roFlags;
int slsDetector::getTotalNumberOfChannels() {
cout << "total number of channels" << endl;
if(thisDetector->myDetectorType==JUNGFRAUCTB){
if (thisDetector->roFlags&DIGITAL_ONLY)
thisDetector->nChan[X]=4;
else if (thisDetector->roFlags&ANALOG_AND_DIGITAL)
thisDetector->nChan[X]=36;
else
thisDetector->nChan[X]=32;
if (thisDetector->nChan[X]>=32) {
if (thisDetector->nROI>0) {
thisDetector->nChan[X]-=32;
for (int iroi=0; iroi<thisDetector->nROI; iroi++)
thisDetector->nChan[X]+=thisDetector->roiLimits[iroi].xmax-thisDetector->roiLimits[iroi].xmin+1;
}
}
thisDetector->nChans=thisDetector->nChan[X];
thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB];
} else
cout << "det type is "<< thisDetector->myDetectorType << endl;
cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl;
return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
};
int slsDetector::getTotalNumberOfChannels(dimension d) {
getTotalNumberOfChannels();
return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d];
};
int slsDetector::getMaxNumberOfChannels(){
if(thisDetector->myDetectorType==JUNGFRAUCTB) return 36*thisDetector->nChips*thisDetector->nModsMax;
return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;
};
int slsDetector::getMaxNumberOfChannels(dimension d){
if(thisDetector->myDetectorType==JUNGFRAUCTB) if (d==X) return 36*thisDetector->nChip[d]*thisDetector->nModMax[d]; else return 1*thisDetector->nChip[d]*thisDetector->nModMax[d];
return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];
};
/* needed to set/get the size of the detector */
// if n=GET_FLAG returns the number of installed modules,
@ -1751,14 +1816,6 @@ int slsDetector::setNumberOfModules(int n, dimension d){
if (thisDetector->nModMax[Y]<thisDetector->nMod[Y])
thisDetector->nModMax[Y]=thisDetector->nMod[Y];
int dr=thisDetector->dynamicRange;
if ((thisDetector->myDetectorType==MYTHEN) && (dr==24))
dr=32;
@ -1771,8 +1828,8 @@ int slsDetector::setNumberOfModules(int n, dimension d){
}
if(thisDetector->myDetectorType==JUNGFRAUCTB){
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*dr/8;
getTotalNumberOfChannels();
//thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->nChans*dr/8*thisDetector->nChips*thisDetector->timerValue[SAMPLES_JCTB];
}
@ -3742,6 +3799,7 @@ int slsDetector::getChanRegs(double* retval,bool fromDetector){
int slsDetector::updateDetectorNoWait() {
enum readOutFlags ro;
// int ret=OK;
enum detectorSettings t;
int thr, n, nm;
@ -3789,7 +3847,7 @@ int slsDetector::updateDetectorNoWait() {
if((thisDetector->myDetectorType!= GOTTHARD)&&
(thisDetector->myDetectorType!= PROPIX)&&
(thisDetector->myDetectorType!= JUNGFRAU)&&
(thisDetector->myDetectorType!= MOENCH)){
(thisDetector->myDetectorType!= MOENCH) && (thisDetector->myDetectorType!= JUNGFRAUCTB)){
//thr=getThresholdEnergy();
n = controlSocket->ReceiveDataOnly( &thr,sizeof(thr));
thisDetector->currentThresholdEV=thr;
@ -3823,10 +3881,26 @@ int slsDetector::updateDetectorNoWait() {
thisDetector->timerValue[PROBES_NUMBER]=retval;
}
//retval=setTrains(tns);
n = controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t));
thisDetector->timerValue[CYCLES_NUMBER]=retval;
//retval=setProbes(tns);
if (thisDetector->myDetectorType == JUNGFRAUCTB){
n = controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t));
if (retval>=0)
thisDetector->timerValue[SAMPLES_JCTB]=retval;
n = controlSocket->ReceiveDataOnly( &ro,sizeof(ro));
thisDetector->roFlags=ro;
//retval=setProbes(tns);
getTotalNumberOfChannels();
// thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
}
return OK;
}
@ -4013,6 +4087,7 @@ int* slsDetector::getDataFromDetector(int *retval){
nodatadetectortype = true;
}
if (!nodatadetectortype && retval==NULL)
retval=new int[nel];
@ -4057,8 +4132,13 @@ int* slsDetector::getDataFromDetector(int *retval){
}
return NULL;
}
// for (int ib=0; ib<thisDetector->dataBytes/8; ib++)
// cout << ((*(((u_int64_t*)retval)+ib))>>17&1) ;
}
// cout << "get data returning " << endl;
// cout << "get data returning " << endl;
// cout << endl;
return retval;
};
@ -4073,8 +4153,8 @@ int* slsDetector::readAll(){
int fnum=F_READ_ALL;
int* retval; // check what we return!
int i=0;
#ifdef VERBOSE
int i=0;
std::cout<< "Reading all frames "<< std::endl;
#endif
if (thisDetector->onlineFlag==ONLINE_FLAG) {
@ -4082,22 +4162,17 @@ int* slsDetector::readAll(){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
while ((retval=getDataFromDetector())){
#ifdef VERBOSE
i++;
//#ifdef VERBOSE
std::cout<< i << std::endl;
//#else
//std::cout << "-" << flush ;
//#endif
#endif
dataQueue.push(retval);
std::cout<< "pushed" << std::endl;
}
disconnectControl();
}
}
#ifdef VERBOSE
std::cout<< "received "<< i<< " frames" << std::endl;
//#else
// std::cout << std::endl;
#endif
return dataQueue.front(); // check what we return!
@ -4132,12 +4207,14 @@ int slsDetector::readAllNoWait(){
int* slsDetector::startAndReadAll(){
//cout << "Start and read all "<< endl;
int* retval;
//#ifdef VERBOSE
#ifdef VERBOSE
int i=0;
#endif
//#endif
startAndReadAllNoWait();
//#ifdef VERBOSE
// std::cout<< "started" << std::endl;
@ -4150,6 +4227,8 @@ int* slsDetector::startAndReadAll(){
//std::cout<< "-" << flush;
#endif
dataQueue.push(retval);
//std::cout<< "pushed" << std::endl;
}
disconnectControl();
@ -4268,10 +4347,15 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
if (t>=0)
thisDetector->timerValue[index]=t;
if((thisDetector->myDetectorType==GOTTHARD)||
(thisDetector->myDetectorType==PROPIX)||
(thisDetector->myDetectorType==JUNGFRAU)||
(thisDetector->myDetectorType==MOENCH))
thisDetector->timerValue[PROBES_NUMBER]=0;
(thisDetector->myDetectorType==PROPIX)||
(thisDetector->myDetectorType==JUNGFRAU)||
(thisDetector->myDetectorType==MOENCH))
thisDetector->timerValue[PROBES_NUMBER]=0;
if(thisDetector->myDetectorType==JUNGFRAUCTB && index==SAMPLES_JCTB) {
getTotalNumberOfChannels();
// thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
}
}
} else {
if (t>=0)
@ -4281,6 +4365,19 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
#endif
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
setDynamicRange();
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
}
if ((thisDetector->myDetectorType==JUNGFRAUCTB) && (index==SAMPLES_JCTB)) {
setDynamicRange();
cout << "Changing samples: data size = " << thisDetector->dataBytes <<endl;
}
/* set progress */
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
setTotalProgress();
}
if(t!=-1){
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
@ -4843,7 +4940,7 @@ int slsDetector::setDynamicRange(int n){
thisDetector->dynamicRange=n;
retval=thisDetector->dynamicRange;
}
//cout << "detector returned dynamic range " << retval << endl;
if (ret!=FAIL && retval>0) {
/* checking the number of probes to chose the data size */
@ -4852,9 +4949,12 @@ int slsDetector::setDynamicRange(int n){
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8;
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
thisDetector->nChip[X]=retval/16;
thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y];
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*retval/8;
// thisDetector->nChip[X]=retval/16;
// thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y];
// cout << thisDetector->nMod[X]*thisDetector->nMod[Y] << " " << thisDetector->nChans*thisDetector->nChips << " " << retval<< " ";
getTotalNumberOfChannels();
//thisDetector->dataBytes=getTotalNumberOfChannels()*retval/8*thisDetector->timerValue[SAMPLES_JCTB];
//cout << "data bytes: "<< thisDetector->dataBytes << endl;
}
if(thisDetector->myDetectorType==MYTHEN){
if (thisDetector->timerValue[PROBES_NUMBER]!=0)
@ -4907,29 +5007,40 @@ int slsDetector::setROI(int n,ROI roiLimits[]){
int ret = FAIL;
//sort ascending order
int temp;
for(int i=0;i<n;i++){
// cout << "*** ROI "<< i << " xmin " << roiLimits[i].xmin << " xmax "<< roiLimits[i].xmax << endl;
for(int j=i+1;j<n;j++){
if(roiLimits[j].xmin<roiLimits[i].xmin){
temp=roiLimits[i].xmin;roiLimits[i].xmin=roiLimits[j].xmin;roiLimits[j].xmin=temp;
temp=roiLimits[i].xmax;roiLimits[i].xmax=roiLimits[j].xmax;roiLimits[j].xmax=temp;
temp=roiLimits[i].ymin;roiLimits[i].ymin=roiLimits[j].ymin;roiLimits[j].ymin=temp;
temp=roiLimits[i].ymax;roiLimits[i].ymax=roiLimits[j].ymax;roiLimits[j].ymax=temp;
temp=roiLimits[i].xmin;roiLimits[i].xmin=roiLimits[j].xmin;roiLimits[j].xmin=temp;
temp=roiLimits[i].xmax;roiLimits[i].xmax=roiLimits[j].xmax;roiLimits[j].xmax=temp;
temp=roiLimits[i].ymin;roiLimits[i].ymin=roiLimits[j].ymin;roiLimits[j].ymin=temp;
temp=roiLimits[i].ymax;roiLimits[i].ymax=roiLimits[j].ymax;roiLimits[j].ymax=temp;
}
}
// cout << "UUU ROI "<< i << " xmin " << roiLimits[i].xmin << " xmax "<< roiLimits[i].xmax << endl;
}
ret = sendROI(n,roiLimits);
if(ret==FAIL)
setErrorMask((getErrorMask())|(COULDNOT_SET_ROI));
if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels();
return ret;
}
slsDetectorDefs::ROI* slsDetector::getROI(int &n){
sendROI();
n=thisDetector->nROI;
return thisDetector->roiLimits;
sendROI(-1,NULL);
n=thisDetector->nROI;
if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels();
return thisDetector->roiLimits;
}
@ -4941,7 +5052,8 @@ int slsDetector::sendROI(int n,ROI roiLimits[]){
int retvalsize=0;
ROI retval[MAX_ROIS];
int nrec=-1;
if (roiLimits==NULL)
roiLimits=thisDetector->roiLimits;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
@ -4983,10 +5095,10 @@ int slsDetector::sendROI(int n,ROI roiLimits[]){
thisDetector->nROI = retvalsize;
}
#ifdef VERBOSE
//#ifdef VERBOSE
for(int j=0;j<thisDetector->nROI;j++)
cout<<roiLimits[j].xmin<<"\t"<<roiLimits[j].xmax<<"\t"<<roiLimits[j].ymin<<"\t"<<roiLimits[j].ymax<<endl;
#endif
cout<<"get"<< roiLimits[j].xmin<<"\t"<<roiLimits[j].xmax<<"\t"<<roiLimits[j].ymin<<"\t"<<roiLimits[j].ymax<<endl;
//#endif
return ret;
}
@ -5029,6 +5141,11 @@ int slsDetector::setReadOutFlags(readOutFlags flag){
} else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
thisDetector->roFlags=retval;
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
getTotalNumberOfChannels();
//thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
}
}
disconnectControl();
if (ret==FORCE_UPDATE)
@ -5103,49 +5220,52 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
};
double* slsDetector::decodeData(int *datain, double *fdata) {
double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
double *dataout;
if (fdata) {
dataout=fdata;
// printf("not allocating fdata!\n");
}
else {
dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
// printf("allocating fdata!\n");
}
const int bytesize=8;
int ival=0;
char *ptr=(char*)datain;
char iptr;
double *dataout;
if (fdata) {
dataout=fdata;
// printf("not allocating fdata!\n");
if (thisDetector->myDetectorType==JUNGFRAUCTB) nn=thisDetector->dataBytes/2;
} else {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
nn=thisDetector->dataBytes/2;
dataout=new double[nn];
int nbits=thisDetector->dynamicRange;
int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
int ipos=0, ichan=0, ibyte;
// std::cout<< "nn is "<< nn << std::endl;
} else {
dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
nn=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
}
if (thisDetector->timerValue[PROBES_NUMBER]==0) {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
// printf("allocating fdata!\n");
}
const int bytesize=8;
for (ichan=0; ichan<nch; ichan++) {
// dataout[ichan]=0;
ival=0;
// for (ibyte=0; ibyte<2; ibyte++) {
ibyte=0;
iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
ibyte=1;
iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0x3f<<(ibyte*bytesize)));
int ival=0;
char *ptr=(char*)datain;
char iptr;
// }
dataout[ichan]=ival;
}
} else {
int nbits=thisDetector->dynamicRange;
int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
int ipos=0, ichan=0, ibyte;
if (thisDetector->timerValue[PROBES_NUMBER]==0) {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
for (ichan=0; ichan<nn; ichan++) {
// // }
dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2;
}
std::cout<< "decoded "<< ichan << " channels" << std::endl;
} else {
switch (nbits) {
case 1:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0x1;
iptr=ptr[ibyte];//&0x1;
for (ipos=0; ipos<8; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos))&0x1;
@ -5156,7 +5276,7 @@ double* slsDetector::decodeData(int *datain, double *fdata) {
break;
case 4:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0xff;
iptr=ptr[ibyte];
for (ipos=0; ipos<2; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos*4))&0xf;
@ -5174,36 +5294,32 @@ double* slsDetector::decodeData(int *datain, double *fdata) {
case 16:
for (ichan=0; ichan<nch; ichan++) {
// dataout[ichan]=0;
ival=0;
for (ibyte=0; ibyte<2; ibyte++) {
iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
}
dataout[ichan]=ival;
// ival=0;
// for (ibyte=0; ibyte<2; ibyte++) {
// iptr=ptr[ichan*2+ibyte];
// ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
// }
dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2;
}
break;
default:
if(thisDetector->myDetectorType == MYTHEN){
for (ichan=0; ichan<nch; ichan++) {
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival;
}
}
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
int mask=0xffffffff;
if(thisDetector->myDetectorType == MYTHEN) mask=0xffffff;
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan]&mask;
}
}
}
} else {
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
}
}
} else {
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
}
#ifdef VERBOSE
std::cout<< "decoded "<< ichan << " channels" << std::endl;
#endif
//#ifdef VERBOSE
//#endif
return dataout;
}
@ -5293,7 +5409,7 @@ int slsDetector::fillModuleMask(int *mM){
int slsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
if (corr!=NULL) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) {
for (int ichan=0; ichan<thisDetector->nMod[Y]*thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) {
// #ifdef VERBOSE
// std::cout<< ichan << " "<< corr[ichan] << std::endl;
// #endif
@ -6271,7 +6387,7 @@ int slsDetector:: writeAngularConversion(ofstream &ofs) {
int slsDetector::loadImageToDetector(imageType index,string const fname){
int ret=FAIL;
short int arg[thisDetector->nChans*thisDetector->nChips];
short int arg[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
#ifdef VERBOSE
std::cout<< std::endl<< "Loading ";
@ -6352,7 +6468,7 @@ int slsDetector::getCounterBlock(short int arg[],int startACQ){
int slsDetector::writeCounterBlockFile(string const fname,int startACQ){
int ret=FAIL;
short int counterVals[thisDetector->nChans*thisDetector->nChips];
short int counterVals[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
#ifdef VERBOSE
std::cout<< std::endl<< "Reading Counter to \""<<fname;
@ -6924,7 +7040,7 @@ int slsDetector::powerChip(int ival){
char mess[MAX_STR_LENGTH]="";
int retval=-1;
if(thisDetector->myDetectorType != JUNGFRAU){
if(thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB ){
std::cout << "Not implemented for this detector" << std::endl;
return FAIL;
}
@ -7571,6 +7687,7 @@ int slsDetector::startReceiver(){
#ifdef VERBOSE
std::cout << "Starting Receiver " << std::endl;
#endif
if (connectData() == OK){
ret=thisReceiver->executeFunction(fnum,mess);
disconnectData();
@ -7587,7 +7704,7 @@ int slsDetector::startReceiver(){
}
}
//let detector prepare anyway even if receiver didnt work
if((thisDetector->myDetectorType != JUNGFRAU))
if((thisDetector->myDetectorType !=JUNGFRAU))
ret=detectorSendToReceiver(true);
return ret;
@ -7774,7 +7891,54 @@ int slsDetector::resetFramesCaught(){
}
// int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
// int fnum=F_READ_RECEIVER_FRAME;
// int nel=thisDetector->dataBytes/sizeof(int);
// int* retval=new int[nel];
// int ret=FAIL;
// int n;
// char mess[MAX_STR_LENGTH]="Nothing";
// if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
// #ifdef VERBOSE
// std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
// #endif
// if (connectData() == OK){
// dataSocket->SendDataOnly(&fnum,sizeof(fnum));
// dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
// if (ret==FAIL) {
// n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
// std::cout<< "Detector returned: " << mess << " " << n << std::endl;
// delete [] retval;
// disconnectData();
// return NULL;
// } else {
// n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
// n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
// n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
// if(thisDetector->myDetectorType == EIGER)
// n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
// n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
// #ifdef VERBOSE
// std::cout<< "Received "<< n << " data bytes" << std::endl;
// #endif
// if (n!=thisDetector->dataBytes) {
// std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
// ret=FAIL;
// delete [] retval;
// disconnectData();
// return NULL; }
// //jungfrau masking adcval
// if(thisDetector->myDetectorType == JUNGFRAU){
// for(unsigned int i=0;i<nel;i++){
// retval[i] = (retval[i] & 0x3FFF3FFF);
// }
// }
// }
// disconnectData();
// }
// }
// return retval;
// };

View File

@ -655,13 +655,24 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int getMaxMods(){return thisDetector->nModsMax;}; //
int getTotalNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;};
/** number of rois defined */
int nROI;
/** list of rois */
ROI roiLimits[MAX_ROIS];
int getTotalNumberOfChannels(dimension d){return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d];};
/** readout flags */
readOutFlags roFlags;
int getMaxNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;};
int getMaxNumberOfChannels(dimension d){return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];};
int getTotalNumberOfChannels();
//{return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;};
int getTotalNumberOfChannels(dimension d);
//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d];};
int getMaxNumberOfChannels();//{return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;};
int getMaxNumberOfChannels(dimension d);//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];};
/** returns the enable if data will be flipped across x or y axis
* \param d axis across which data is flipped
@ -1297,7 +1308,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
\param datain data from the detector
\returns pointer to a double array with a data per channel
*/
double* decodeData(int *datain, double *fdata=NULL);
double* decodeData(int *datain, int &nn, double *fdata=NULL);
@ -1625,6 +1636,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
int resetFramesCaught();
/** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver

View File

@ -146,6 +146,7 @@ int slsDetectorActions::getActionMode(int iaction){
int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *values, string par, int precision) {
if (iscan>=0 && iscan<MAX_SCAN_LEVELS) {
// cout << "settings script to " << script <<endl;
if (script=="") {
scanMode[iscan]=noScan;
} else {
@ -160,6 +161,8 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
scanMode[iscan]=trimbitsScan;
} else if (script=="position") {
scanMode[iscan]=positionScan;
} else if (script=="dac") {
scanMode[iscan]=dacScan;
} else {
scanMode[iscan]=scriptScan;
}
@ -202,15 +205,6 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
setTotalProgress();
return scanMode[iscan];
} else
return -1;
@ -233,6 +227,8 @@ int slsDetectorActions::setScanScript(int iscan, string script) {
scanMode[iscan]=trimbitsScan;
} else if (script=="position") {
scanMode[iscan]=positionScan;
} else if (script=="dac") {
scanMode[iscan]=dacScan;
} else {
scanMode[iscan]=scriptScan;
}
@ -425,6 +421,9 @@ int slsDetectorActions::executeScan(int level, int istep) {
case thresholdScan:
setDAC((dacs_t)currentScanVariable[level],THRESHOLD,0); // threshold scan
break;
case dacScan:
setDAC((dacs_t)currentScanVariable[level],(slsDetectorDefs::dacIndex)atoi(getScanParameter(level).c_str()),0);
break;
case trimbitsScan:
trimbit=(int)currentScanVariable[level];
if(getDetectorsType() == EIGER)

View File

@ -25,7 +25,7 @@ class slsDetectorActions : public virtual slsDetectorBase
{
public :
enum {noScan, energyScan, thresholdScan, trimbitsScan, positionScan, scriptScan };
enum {noScan, energyScan, thresholdScan, trimbitsScan, positionScan, scriptScan, dacScan };
/** default constructor */

View File

@ -251,7 +251,7 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
virtual int setTotalProgress()=0;
virtual double* decodeData(int *datain, double *fdata=NULL)=0;
virtual double* decodeData(int *datain, int &nn, double *fdata=NULL)=0;
virtual string getCurrentFileName()=0;
@ -504,8 +504,8 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
/** Reads frames from receiver through a constant socket
*/
virtual void readFrameFromReceiver()=0;
// virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
virtual void readFrameFromReceiver()=0;
/** Sets the read receiver frequency
if data required from receiver randomly readRxrFrequency=0,

View File

@ -791,6 +791,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++;
descrToFuncMap[i].m_pFuncName="v_limit"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++;
/* r/w timers */
descrToFuncMap[i].m_pFuncName="temp_adc"; //
@ -878,6 +882,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer;
i++;
descrToFuncMap[i].m_pFuncName="samples"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer;
i++;
/* read only timers */
descrToFuncMap[i].m_pFuncName="exptimel"; //
@ -964,6 +972,20 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
i++;
descrToFuncMap[i].m_pFuncName="dbitclk"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
descrToFuncMap[i].m_pFuncName="dbitphase"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
descrToFuncMap[i].m_pFuncName="dbitpipeline"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
/* settings dump/retrieve */
descrToFuncMap[i].m_pFuncName="config";
@ -1127,6 +1149,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
i++;
descrToFuncMap[i].m_pFuncName="dut_clk"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPattern;
i++;
/* pulse */
descrToFuncMap[i].m_pFuncName="pulse"; //
@ -3830,6 +3857,8 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
dac=V_POWER_IO;
else if (cmd== "v_chip")
dac=V_POWER_CHIP;
else if (cmd== "v_limit")
dac=V_LIMIT;
else
return string("cannot decode dac ")+cmd;
@ -3863,7 +3892,7 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
sprintf(answer,"%f",myDet->setDAC(-1,dac,mode));
#endif
if(mode)
strcat(answer,"mV");
strcat(answer," mV");
return string(answer);
}
@ -4021,7 +4050,7 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
return string("cannot set ")+cmd;
if (sscanf(args[0],"adc:%d",&idac)==1) {
printf("chiptestboard!\n");
// printf("chiptestboard!\n");
adc=(dacIndex)(idac+1000);
} else if (cmd=="temp_adc")
adc=TEMPERATURE_ADC;
@ -4147,6 +4176,8 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) {
index=PROBES_NUMBER;
else if (cmd=="measurements")
index=MEASUREMENTS_NUMBER;
else if (cmd=="samples")
index=SAMPLES_JCTB;
else
return string("could not decode timer ")+cmd;
@ -4200,6 +4231,7 @@ string slsDetectorCommand::helpTimer(int narg, char *args[], int action) {
os << "frames t \t sets the number of frames per cycle (e.g. after each trigger)" << std::endl;
os << "cycles t \t sets the number of cycles (e.g. number of triggers)" << std::endl;
os << "probes t \t sets the number of probes to accumulate (max 3! cycles should be set to 1, frames to the number of pump-probe events)" << std::endl;
os << "samples t \t sets the number of samples expected from the jctb" << std::endl;
os << std::endl;
@ -4213,6 +4245,8 @@ string slsDetectorCommand::helpTimer(int narg, char *args[], int action) {
os << "frames \t gets the number of frames per cycle (e.g. after each trigger)" << std::endl;
os << "cycles \t gets the number of cycles (e.g. number of triggers)" << std::endl;
os << "probes \t gets the number of probes to accumulate" << std::endl;
os << "samples t \t gets the number of samples expected from the jctb" << std::endl;
os << std::endl;
}
@ -4348,9 +4382,16 @@ string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) {
index=ADC_CLOCK;
else if (cmd=="adcphase") {
index=ADC_PHASE;
t=100000;
t=100000;
} else if (cmd=="adcpipeline")
index=ADC_PIPELINE;
else if (cmd=="dbitclk")
index=DBIT_CLOCK;
else if (cmd=="dbitphase") {
index=DBIT_PHASE;
t=100000;
} else if (cmd=="dbitpipeline")
index=DBIT_PIPELINE;
else
return string("could not decode speed variable ")+cmd;
@ -4425,50 +4466,59 @@ string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) {
readOutFlags flag=GET_READOUT_FLAGS;
if (action==PUT_ACTION) {
string sval=string(args[1]);
if (sval=="none")
flag=NORMAL_READOUT;
else if (sval=="storeinram")
flag=STORE_IN_RAM;
else if (sval=="tot")
flag=TOT_MODE;
else if (sval=="continous")
flag=CONTINOUS_RO;
else if (sval=="parallel")
flag=PARALLEL;
else if (sval=="nonparallel")
flag=NONPARALLEL;
else if (sval=="safe")
flag=SAFE;
else
return string("could not scan flag ")+string(args[1]);
}
if (action==PUT_ACTION) {
string sval=string(args[1]);
if (sval=="none")
flag=NORMAL_READOUT;
else if (sval=="storeinram")
flag=STORE_IN_RAM;
else if (sval=="tot")
flag=TOT_MODE;
else if (sval=="continous")
flag=CONTINOUS_RO;
else if (sval=="parallel")
flag=PARALLEL;
else if (sval=="nonparallel")
flag=NONPARALLEL;
else if (sval=="safe")
flag=SAFE;
else if (sval=="digital")
flag=DIGITAL_ONLY;
else if (sval=="analog_digital")
flag=ANALOG_AND_DIGITAL;
else
return string("could not scan flag ")+string(args[1]);
}
myDet->setOnline(ONLINE_FLAG);
retval = myDet->setReadOutFlags(flag);
retval = myDet->setReadOutFlags(flag);
// cout << hex << flag << " " << retval << endl;
if(retval == NORMAL_READOUT)
return string("none");
if(retval == NORMAL_READOUT)
return string("none");
if(retval & STORE_IN_RAM)
strcat(answer,"storeinram ");
if(retval & TOT_MODE)
strcat(answer,"tot ");
if(retval & CONTINOUS_RO)
strcat(answer,"continous ");
if(retval & PARALLEL)
strcat(answer,"parallel ");
if(retval & NONPARALLEL)
strcat(answer,"nonparallel ");
if(retval & SAFE)
strcat(answer,"safe ");
if(strlen(answer))
return string(answer);
if(retval & STORE_IN_RAM)
strcat(answer,"storeinram ");
if(retval & TOT_MODE)
strcat(answer,"tot ");
if(retval & CONTINOUS_RO)
strcat(answer,"continous ");
if(retval & PARALLEL)
strcat(answer,"parallel ");
if(retval & NONPARALLEL)
strcat(answer,"nonparallel ");
if(retval & SAFE)
strcat(answer,"safe ");
if (retval & DIGITAL_ONLY)
strcat(answer,"digital " );
if (retval & ANALOG_AND_DIGITAL)
strcat(answer,"analog_digital ");
if(strlen(answer))
return string(answer);
return string("unknown");
return string("unknown");
} else if (cmd=="extsig") {
externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG;
@ -4487,10 +4537,8 @@ string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) {
return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is));
}
else if (cmd=="programfpga") {
} else if (cmd=="programfpga") {
if (action==GET_ACTION)
return string("cannot get");
if(strstr(args[1],".pof")==NULL)
@ -4543,14 +4591,15 @@ string slsDetectorCommand::helpAdvanced(int narg, char *args[], int action) {
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl;
os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, unknown" << std::endl;
os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, digital, analog_digital, unknown" << std::endl;
os << "programfpga f \t programs the fpga with file f (with .pof extension)." << std::endl;
os << "resetfpga f \t resets fpga, f can be any value" << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "extsig:i \t gets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl;
os << "flags \t gets the readout flags. can be none, storeinram, tot, continous, parallel, nonparallel, safe, unknown" << std::endl;
os << "flags \t gets the readout flags. can be none, storeinram, tot, continous, parallel, nonparallel, safe, digital, analog_digital, unknown" << std::endl;
}
return os.str();
@ -5261,7 +5310,26 @@ string slsDetectorCommand::cmdPattern(int narg, char *args[], int action) {
os << hex << myDet->readRegister(67) << dec;
} else if (cmd=="dut_clk") {
if (action==PUT_ACTION) {
if (sscanf(args[1],"%x",&addr))
;
else
return string("Could not scan dut_clk reg ")+string(args[1]);
myDet->writeRegister(123,addr); //0x7b
}
os << hex << myDet->readRegister(123) << dec; //0x7b
} else if (cmd=="adcdisable") {
int nroi=0;
ROI roiLimits[MAX_ROIS];
if (action==PUT_ACTION) {
if (sscanf(args[1],"%x",&addr))
@ -5269,19 +5337,69 @@ string slsDetectorCommand::cmdPattern(int narg, char *args[], int action) {
else
return string("Could not scan adcdisable reg ")+string(args[1]);
myDet->writeRegister(94,addr);
/******USE ROI?!?!?!?*********/
// roiLimits[i].xmin;roiLimits[i].xmax;roiLimits[i].ymin;roiLimits[i].ymin;roiLimits[i].ymax
//int mask=1;
int ii=0;
while (ii<32) {
nroi++;
roiLimits[nroi-1].xmin=ii;
roiLimits[nroi-1].ymin=0;
roiLimits[nroi-1].ymax=0;
while ((addr&(1<<ii))) {
ii++;
if (ii>=32)
break;
}
if (ii>=32) {
break;
cout << "ROI "<< nroi << " xmin "<<roiLimits[nroi-1].xmin << " xmax "<< roiLimits[nroi-1].xmax << endl;
roiLimits[nroi-1].xmax=31;
break;
}
roiLimits[nroi-1].xmin=ii;
while ((addr&(1<<ii))==0) {
ii++;
if (ii>=32)
break;
}
roiLimits[nroi-1].xmax=ii-1;
if (ii>=32) {
cout << "ROI "<< nroi << " xmin "<<roiLimits[nroi-1].xmin << " xmax "<< roiLimits[nroi-1].xmax << endl;
nroi++;
break;
}
cout << "ROI "<< nroi << " xmin "<<roiLimits[nroi-1].xmin << " xmax "<< roiLimits[nroi-1].xmax << endl;
}
cout << "********ROI "<< nroi << endl;
myDet->setROI(nroi-1,roiLimits);
// myDet->writeRegister(94,addr);
// myDet->writeRegister(120,addr);
}
ROI *aa=myDet->getROI(nroi);
int reg=0xffffffff;
if (nroi<1)
reg=0;
else {
for (int iroi=0; iroi<nroi; iroi++) {
cout << iroi << " xmin "<< (aa+iroi)->xmin<< " xmax "<< (aa+iroi)->xmax<< endl;
for (int ich=(aa+iroi)->xmin; ich<=(aa+iroi)->xmax; ich++) {
reg&=~(1<<ich);
}
}
}
os << hex << reg << dec;
os << hex << myDet->readRegister(94) << dec;
//os <<" "<< hex << myDet->readRegister(120) << dec;
}
else return helpPattern(narg, args, action);
else return helpPattern(narg, args, action);

View File

@ -151,7 +151,7 @@ int slsDetectorUtils::acquire(int delflag){
}
if(receiver){
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
if(getReceiverStatus()!=IDLE)
stopReceiver();
//multi detectors shouldnt have different receiver read frequencies enabled/disabled
@ -161,7 +161,7 @@ int slsDetectorUtils::acquire(int delflag){
}
if(setReceiverOnline()==OFFLINE_FLAG)
*stoppedFlag=1;
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
@ -173,9 +173,9 @@ int slsDetectorUtils::acquire(int delflag){
//resets frames caught in receiver
if(receiver){
pthread_mutex_lock(&mg);
resetFramesCaught();
pthread_mutex_unlock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
resetFramesCaught();
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
@ -269,7 +269,7 @@ int slsDetectorUtils::acquire(int delflag){
aclog->addStep(getCurrentPosition(), getCurrentFileName());
if (eclog)
eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName());
eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName());
if (*correctionMask&(1<< I0_NORMALIZATION)) {
@ -280,7 +280,7 @@ int slsDetectorUtils::acquire(int delflag){
setCurrentFrameIndex(0);
if(receiver)
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
if (multiframe>1)
setFrameIndex(0);
else
@ -288,30 +288,33 @@ int slsDetectorUtils::acquire(int delflag){
if(receiver){
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
pthread_mutex_lock(&mp);
createFileName();
pthread_mutex_unlock(&mp);
//send receiver file name
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileName(fileIO::getFileName());
//start receiver
if(startReceiver() == FAIL) {
cout << "Start receiver failed " << endl;
stopReceiver();
*stoppedFlag=1;
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
pthread_mutex_unlock(&mg);
cout << "Receiver started " << endl;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
#ifdef VERBOSE
#ifdef VERBOSE
cout << "Acquiring " << endl;
#endif
#endif
startAndReadAll();
#ifdef VERBOSE
cout << "finished " << endl;
cout << "detector finished " << endl;
#ifdef VERBOSE
cout << "returned! " << endl;
#endif
#endif
@ -341,17 +344,20 @@ int slsDetectorUtils::acquire(int delflag){
} else
break;
pthread_mutex_lock(&mg);
while (dataQueueSize()) usleep(100000);
// cout << "mglock " << endl;;
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;;
//offline
if(setReceiverOnline()==OFFLINE_FLAG){
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){
if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile();
}
}
//online
else{
if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){
stopAcquisition();
stopReceiver();
@ -359,9 +365,9 @@ int slsDetectorUtils::acquire(int delflag){
break;
}
stopReceiver();
// cout<<"***********receiver stopped"<<endl;
// cout<<"***********receiver stopped"<<endl;
}
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
@ -439,9 +445,9 @@ int slsDetectorUtils::acquire(int delflag){
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileIndex(fileIO::getFileIndex());
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
@ -452,14 +458,14 @@ int slsDetectorUtils::acquire(int delflag){
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileIndex(fileIO::getFileIndex());
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
if (measurement_finished){
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
measurement_finished(im,*fileIndex,measFinished_p);
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
if (*stoppedFlag) {

View File

@ -690,6 +690,7 @@ virtual int createReceivingDataSockets(const bool destroy = false){return -1;};
/** Reads frames from receiver through a constant socket
*/
virtual void readFrameFromReceiver(){};
/**

View File

@ -22,10 +22,10 @@ string fileIO::createFileName() {
detIndex \
);
if (getDetectorsType()==JUNGFRAUCTB) {
nBytes=2*getTotalNumberOfChannels();
} else
nBytes=getDataBytes();
//if (getDetectorsType()==JUNGFRAUCTB) {
// nBytes=2*getTotalNumberOfChannels();
//} else
nBytes=getDataBytes();
return currentFileName;
}
@ -57,7 +57,7 @@ int fileIO::writeDataFile(string fname, double *data, double *err, double *ang,
if (nch==-1)
nch=getTotalNumberOfChannels();
cout << "Write filexxx...." << endl;
// cout << "Write filexxx...." << endl;
return fileIOStatic::writeDataFile(fname, nch, data, err, ang, dataformat);
@ -66,7 +66,7 @@ int fileIO::writeDataFile(ofstream &outfile, double *data, double *err, double *
if (nch==-1)
nch=getTotalNumberOfChannels();
cout << "Write file...." << endl;
//cout << "Write file...." << endl;
return fileIOStatic::writeDataFile(outfile, nch, data, err, ang, dataformat, offset);
@ -97,13 +97,14 @@ int fileIO::writeDataFile(void *data, int iframe) {
if ((*framesPerFile)<2)
iframe=-1;
if ((iframe%(*framesPerFile))==0 || (iframe<0)) {
if ((iframe%(*framesPerFile))==0 || (iframe<0) || filefd==0) {
createFileName();
filefd = fopen((currentFileName+string(".raw")).c_str(), "w");
}
if (filefd){
// fileIOStatic::writeBinaryDataFile(filefd,getDataBytes(), data);
cout <<"Writing "<< nBytes<< " dataBytes"<< endl;
fileIOStatic::writeBinaryDataFile(filefd,nBytes, data);
iframe++;
}

View File

@ -84,6 +84,7 @@ postProcessing::~postProcessing(){
void postProcessing::processFrame(int *myData, int delflag, int jctb) {
string fname;
int nn;
//double *fdata=NULL;
#ifdef VERBOSE
@ -98,20 +99,29 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) {
/** decode data */
// cout << "decode 0"<< endl;
// if (getDetectorsType()==MYTHEN) {
fdata=decodeData(myData, fdata);
#ifdef VERBOSE
cout << "decode"<< endl;
#endif
// for (int ib=0; ib<1000; ib++)
// cout << ((*(((u_int64_t*)myData)+ib))>>17&1) ;
// cout << endl;
fdata=decodeData(myData,nn, fdata);
//#ifdef VERBOSE
// cout << "decode 1"<< endl;
//#endif
// } else
// fdata=NULL;
if (rawDataReady) {
#ifdef VERBOSE
#ifdef VERBOSE
cout << "decoded data size is "<<nn << endl;
cout << "raw data ready..." << endl;
#endif
rawDataReady(fdata,numberOfChannels, pRawDataArg);
#endif
// rawDataReady(fdata,numberOfChannels, pRawDataArg);
rawDataReady(fdata,nn, pRawDataArg);
#ifdef VERBOSE
cout << "done" << endl;
cout << "NO FILE WRITING AND/OR DATA PROCESSING DONE BY SLS DETECTOR SOFTWARE!!!" << endl;
@ -153,7 +163,8 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) {
// cout << "callback arg "<< getCurrentProgress()<< " " << (fname+string(".raw")).c_str() << " " << getTotalNumberOfChannels() << endl;
// cout << "DATAREADY 1" <<endl;
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels()); //only 1d detectors
// thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels()); //only 1d detectors
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),nn); //only 1d detectors
dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
delete thisData;
fdata=NULL;
@ -407,9 +418,9 @@ int postProcessing::fillBadChannelMask() {
void* postProcessing::processData(int delflag) {
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg);
if(setReceiverOnline()==OFFLINE_FLAG){
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);
#ifdef VERBOSE
std::cout<< " ??????????????????????????????????????????? processing data - threaded mode " << *threadedProcessing << endl;
@ -443,14 +454,14 @@ void* postProcessing::processData(int delflag) {
// cout << "loop" << endl;
while((queuesize=dataQueueSize())>0) {
/** Pop data queue */
//#ifdef VERBOSE
#ifdef VERBOSE
cout << "data found"<< endl<<endl;;
//#endif
#endif
myData=dataQueueFront(); // get the data from the queue
#ifdef VERBOSE
cout << "got them"<< endl;
#endif
//#ifdef VERBOSE
// cout << "got them"<< endl;
//#endif
if (myData) {
@ -493,31 +504,32 @@ void* postProcessing::processData(int delflag) {
fdata = NULL;
//cout << "delete done "<< endl;
}
}
//receiver
} //receiver
else{
pthread_mutex_unlock(&mg);
//cprintf(RED,"In post processing threads\n");
pthread_mutex_unlock(&mg);
//cprintf(RED,"In post processing threads\n");
if(dataReady){
readFrameFromReceiver();
}
if(dataReady){
readFrameFromReceiver();
}
//only update progress
else{
int caught = -1;
char c;
int ifp;
//only update progress
else{
int caught = -1;
char c;
int ifp;
while(true){
//cout.flush();
//cout<<flush;
usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
//cout.flush();
//cout<<flush;
usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
if (checkJoinThread()){
break;
}
if (checkJoinThread()){
break;
}
ifp=kbhit();
@ -530,33 +542,32 @@ void* postProcessing::processData(int delflag) {
}
//get progress
pthread_mutex_lock(&mg);
if(setReceiverOnline() == ONLINE_FLAG){
caught = getFramesCaughtByReceiver();
}
pthread_mutex_unlock(&mg);
//get progress
pthread_mutex_lock(&mg);
if(setReceiverOnline() == ONLINE_FLAG){
caught = getFramesCaughtByReceiver();
}
pthread_mutex_unlock(&mg);
//updating progress
if(caught!= -1){
setCurrentProgress(caught);
#ifdef VERY_VERY_DEBUG
cout << "caught:" << caught << endl;
#endif
}
if (checkJoinThread()){
break;
}
//updating progress
if(caught!= -1){
setCurrentProgress(caught);
#ifdef VERY_VERY_DEBUG
cout << "caught:" << caught << endl;
#endif
}
if (checkJoinThread()){
break;
}
}
}
}
}
//cout<<"exiting from proccessing thread"<<endl;
//cprintf(RED,"Exiting post processing thread\n");
}
return 0;

View File

@ -296,11 +296,13 @@ s
*/
queue<detectorData*> finalDataQueue;
/** data queue size */
int queuesize;
/** queue mutex */
sem_t sem_queue;
/** set when detector finishes acquiring */
int acquiringDone;
/**