mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 02:17:26 +01:00
Merge branch 'release'
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
This subversion repository contains
|
||||
This subversion repository contains
|
||||
|
||||
Common directories
|
||||
Please inform Anna, Beat and Ian if you make modifications to these directories
|
||||
@@ -18,4 +18,4 @@ Please inform Beat and Ian if you make modifications to these directories
|
||||
- eigerDetector : eiger specific funcs (mainly files I/O and ..)
|
||||
- eigerDetectorServer : eiger server
|
||||
|
||||
make doc
|
||||
make doc
|
||||
|
||||
@@ -403,7 +403,13 @@ int sendChip(int file_des, sls_detector_chip *myChip) {
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
return sendModuleGeneral(file_des, myMod, 1);
|
||||
}
|
||||
|
||||
|
||||
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
|
||||
int ts=0;
|
||||
#ifdef VERBOSE
|
||||
int idac;
|
||||
@@ -422,8 +428,11 @@ int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
ts+=sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts+=sendData(file_des,myMod->dacs,sizeof(myMod->ndac),OTHER);
|
||||
ts+=sendData(file_des,myMod->adcs,sizeof(myMod->nadc),OTHER);
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER);
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(sendAll){
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER);
|
||||
}
|
||||
ts+=sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
@@ -440,14 +449,19 @@ int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
#ifdef VERBOSE
|
||||
printf("adcs %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
|
||||
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(sendAll){
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
||||
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("module %d of size %d sent register %x\n",myMod->module, ts, myMod->reg);
|
||||
#endif
|
||||
@@ -507,13 +521,16 @@ int receiveChip(int file_des, sls_detector_chip* myChip) {
|
||||
return ts;
|
||||
}
|
||||
|
||||
int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
|
||||
|
||||
int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
return receiveModuleGeneral(file_des,myMod,1);
|
||||
}
|
||||
|
||||
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll) {
|
||||
int ts=0;
|
||||
dacs_t *dacptr=myMod->dacs;
|
||||
dacs_t *adcptr=myMod->adcs;
|
||||
int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs;
|
||||
int ts=0;
|
||||
int nChips, nchipold=myMod->nchip, nchipdiff;
|
||||
int nChans, nchanold=myMod->nchan, nchandiff;
|
||||
int nDacs, ndold=myMod->ndac, ndacdiff;
|
||||
@@ -531,8 +548,11 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
ts+=receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts+=receiveData(file_des,myMod->dacs,sizeof(myMod->ndac),INT32);
|
||||
ts+=receiveData(file_des,myMod->adcs,sizeof(myMod->nadc),INT32);
|
||||
ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32);
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(receiveAll){
|
||||
ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32);
|
||||
}
|
||||
ts+=receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
@@ -540,7 +560,7 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
myMod->adcs=adcptr;
|
||||
myMod->chipregs=chipptr;
|
||||
myMod->chanregs=chanptr;
|
||||
|
||||
|
||||
nChips=myMod->nchip;
|
||||
nchipdiff=nChips-nchipold;
|
||||
if (nchipold!=nChips) {
|
||||
@@ -585,6 +605,7 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
ts+=receiveData(file_des,myMod->dacs, sizeof(dacs_t)*nDacs,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("dacs received\n");
|
||||
int id;
|
||||
for (id=0; id<nDacs; id++)
|
||||
printf("dac %d val %d\n",id, (int)myMod->dacs[id]);
|
||||
|
||||
@@ -601,7 +622,7 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
|
||||
if (nadcdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs,INT32);
|
||||
#ifdef VERBOSE
|
||||
#ifdef VERBOSE
|
||||
printf("adcs received\n");
|
||||
#endif
|
||||
} else {
|
||||
@@ -613,35 +634,41 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchipdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips received\n");
|
||||
#endif
|
||||
} else {
|
||||
chipptr=(int*)malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip=nchipold;
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
|
||||
ts+=receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchandiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans received\n");
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(receiveAll){
|
||||
|
||||
if (nchipdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips received\n");
|
||||
#endif
|
||||
} else {
|
||||
chanptr=(int*)malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan=nchanold;
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
|
||||
ts+=receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
|
||||
free(chanptr);
|
||||
return FAIL;
|
||||
} else {
|
||||
chipptr=(int*)malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip=nchipold;
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
|
||||
ts+=receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchandiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans received\n");
|
||||
#endif
|
||||
} else {
|
||||
chanptr=(int*)malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan=nchanold;
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
|
||||
ts+=receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
|
||||
free(chanptr);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("received module %d of size %d register %x\n",myMod->module,ts,myMod->reg);
|
||||
#endif
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,10 @@ int getServerError(int socketDescriptor);
|
||||
int sendChannel(int file_des, sls_detector_channel *myChan);
|
||||
int sendChip(int file_des, sls_detector_chip *myChip);
|
||||
int sendModule(int file_des, sls_detector_module *myMod);
|
||||
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll);
|
||||
int receiveChannel(int file_des, sls_detector_channel *myChan);
|
||||
int receiveChip(int file_des, sls_detector_chip* myChip);
|
||||
int receiveModule(int file_des, sls_detector_module* myMod);
|
||||
|
||||
int receiveModule(int file_des, sls_detector_module* myMod);
|
||||
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -56,6 +56,8 @@ using namespace std;
|
||||
#define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL
|
||||
#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL
|
||||
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL
|
||||
#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL
|
||||
#define RATE_CORRECTION_TAU_SUBEXPOSURE 0x0000000000400000ULL
|
||||
|
||||
// 0x00000000FFFFFFFFULL
|
||||
/** @short class returning all error messages for error mask */
|
||||
@@ -177,6 +179,16 @@ public:
|
||||
if(slsErrorMask&COULD_NOT_PULSE_CHIP)
|
||||
retval.append("Could not pulse chip\n");
|
||||
|
||||
if(slsErrorMask&COULD_NOT_SET_RATE_CORRECTION)
|
||||
retval.append("Could not set rate correction\n");
|
||||
|
||||
if(slsErrorMask&RATE_CORRECTION_TAU_SUBEXPOSURE)
|
||||
retval.append("Rate Correction Deactivated: (tau/subexptime) must be less than 0.0015\n");
|
||||
|
||||
|
||||
//------------------------------------------------------ length of message
|
||||
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define HEADERLENGTH 12
|
||||
|
||||
#define DEFAULT_SUBFRAME_EXPOSURE_VAL 2621440 /** default value for sub frame value 2.6ms*/
|
||||
#define MAX_SUBFRAME_EXPOSURE_VAL 0x1FFFFFFF /** 29 bit register for max subframe exposure value */
|
||||
#define MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS 0x1FFFFFFF /** 29 bit register for max subframe exposure value */
|
||||
|
||||
/** maximum rois */
|
||||
#define MAX_ROIS 100
|
||||
@@ -348,7 +348,8 @@ enum dacIndex {
|
||||
E_Vcn, /**< eiger */
|
||||
E_Vis, /**< eiger */
|
||||
IO_DELAY, /**< eiger io delay */
|
||||
ADC_VPP /**< adc vpp for jctb */
|
||||
ADC_VPP, /**< adc vpp for jctb */
|
||||
HV_NEW /**< new hv index for jungfrau & c */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -364,6 +365,11 @@ enum detectorSettings{
|
||||
MEDIUMGAIN, /**< medium gain settings */
|
||||
VERYHIGHGAIN, /**< very high gain settings */
|
||||
LOWNOISE, /**< low noise settings */
|
||||
DYNAMICHG0, /**< dynamic high gain 0 */
|
||||
FIXGAIN1, /**< fix gain 1 */
|
||||
FIXGAIN2, /**< fix gain 2 */
|
||||
FORCESWITCHG1, /**< force switch gain 1 */
|
||||
FORCESWITCHG2, /**< force switch gain 2 */
|
||||
UNDEFINED, /**< undefined or custom settings */
|
||||
UNINITIALIZED /**< uninitialiazed (status at startup) */
|
||||
};
|
||||
|
||||
@@ -98,7 +98,9 @@ enum {
|
||||
F_SET_COUNTER_BIT, /** < set/reset counter bit in detector for eiger */
|
||||
F_PULSE_PIXEL, /** < pulse pixel n number of times in eiger at (x,y) */
|
||||
F_PULSE_PIXEL_AND_MOVE, /** < pulse pixel n number of times and move relatively by x and y */
|
||||
F_PULSE_CHIP /** < pulse chip n number of times */
|
||||
F_PULSE_CHIP, /** < pulse chip n number of times */
|
||||
|
||||
F_SET_RATE_CORRECT /** < set/reset rate correction tau */
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
|
||||
|
||||
@@ -43,11 +43,15 @@ unsigned int Feb_Control_triggerMode; //internal timer, external start,
|
||||
unsigned int Feb_Control_externalEnableMode; //external enabling engaged and it's polarity
|
||||
unsigned int Feb_Control_subFrameMode;
|
||||
|
||||
|
||||
unsigned int Feb_Control_nimages;
|
||||
double Feb_Control_exposure_time_in_sec;
|
||||
int Feb_Control_subframe_exposure_time_in_10nsec;
|
||||
double Feb_Control_exposure_period_in_sec;
|
||||
|
||||
int64_t Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||
int64_t Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
|
||||
unsigned int Feb_Control_trimbit_size;
|
||||
unsigned int* Feb_Control_last_downloaded_trimbits;
|
||||
|
||||
@@ -55,7 +59,11 @@ unsigned int* Feb_Control_last_downloaded_trimbits;
|
||||
int Feb_Control_module_number;
|
||||
int Feb_Control_current_index;
|
||||
|
||||
int counter_bit = 1;
|
||||
int Feb_Control_counter_bit = 1;
|
||||
int Feb_control_master = 0;
|
||||
|
||||
unsigned int Feb_Control_rate_correction_table[1024];
|
||||
double Feb_Control_rate_meas[16384];
|
||||
|
||||
|
||||
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
|
||||
@@ -130,17 +138,17 @@ unsigned int Module_GetBottomLeftAddress(struct Module* mod) {return mod->botto
|
||||
unsigned int Module_GetBottomRightAddress(struct Module* mod) {return mod->bottom_right_address;}
|
||||
|
||||
unsigned int Module_SetTopIDelay(struct Module* mod,unsigned int chip,unsigned int value) { return Module_TopAddressIsValid(mod) &&chip<4 ? (mod->idelay_top[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
||||
unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
||||
unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
||||
unsigned int Module_SetBottomIDelay(struct Module* mod,unsigned int chip,unsigned int value) { return Module_BottomAddressIsValid(mod) &&chip<4 ? (mod->idelay_bottom[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
||||
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
||||
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
||||
|
||||
float Module_SetHighVoltage(struct Module* mod,float value) { return Module_TopAddressIsValid(mod) ? (mod->high_voltage=value) : -1;}
|
||||
float Module_GetHighVoltage(struct Module* mod) { return mod->high_voltage;}
|
||||
float Module_SetHighVoltage(struct Module* mod,float value) { return Feb_control_master ? (mod->high_voltage=value) : -1;}// Module_TopAddressIsValid(mod) ? (mod->high_voltage=value) : -1;}
|
||||
float Module_GetHighVoltage(struct Module* mod) { return mod->high_voltage;}
|
||||
|
||||
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_TopAddressIsValid(mod)) ? (mod->top_dac[i]=value) : -1;}
|
||||
int Module_GetTopDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->top_dac[i]:-1;}
|
||||
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_BottomAddressIsValid(mod)) ? (mod->bottom_dac[i]=value) : -1;}
|
||||
int Module_GetBottomDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->bottom_dac[i]:-1;}
|
||||
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_TopAddressIsValid(mod)) ? (mod->top_dac[i]=value) : -1;}
|
||||
int Module_GetTopDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->top_dac[i] : -1;}
|
||||
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_BottomAddressIsValid(mod)) ? (mod->bottom_dac[i]=value): -1;}
|
||||
int Module_GetBottomDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->bottom_dac[i] : -1;}
|
||||
|
||||
|
||||
|
||||
@@ -166,27 +174,16 @@ void Feb_Control_FebControl(){
|
||||
|
||||
|
||||
|
||||
int Feb_Control_Init(int master, int top){
|
||||
int Feb_Control_Init(int master, int top, int module_num){
|
||||
unsigned int i;
|
||||
Feb_Control_module_number = 0;
|
||||
Feb_Control_current_index = 0;
|
||||
Feb_control_master = master;
|
||||
|
||||
//global send
|
||||
Feb_Control_AddModule1(0,1,0xff,0,1);
|
||||
Feb_Control_PrintModuleList();
|
||||
|
||||
//get module nummber
|
||||
int res=0;
|
||||
char hostname[100];
|
||||
if (gethostname(hostname, sizeof hostname) == 0)
|
||||
puts(hostname);
|
||||
else
|
||||
perror("gethostname");
|
||||
char *pch;
|
||||
pch = strtok(hostname,"0");
|
||||
pch = strtok(NULL,"0");
|
||||
sscanf(pch,"%d",&res);
|
||||
Feb_Control_module_number = (res & 0xFF);
|
||||
Feb_Control_module_number = (module_num & 0xFF);
|
||||
|
||||
int serial = !top;
|
||||
|
||||
@@ -538,7 +535,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_CheckSetup(){
|
||||
int Feb_Control_CheckSetup(int master){
|
||||
printf("Checking Set up\n");
|
||||
unsigned int i,j;
|
||||
int ok = 1;
|
||||
@@ -556,7 +553,7 @@ int Feb_Control_CheckSetup(){
|
||||
ok=0;
|
||||
}
|
||||
}
|
||||
if(Module_GetHighVoltage(&modules[i])<0){
|
||||
if((Feb_control_master) &&(Module_GetHighVoltage(&modules[i])<0)){
|
||||
cprintf(RED,"Warning: module %d's high voltage not set.\n",Module_GetModuleNumber(&modules[i]));
|
||||
ok=0;
|
||||
}
|
||||
@@ -709,7 +706,7 @@ int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
|
||||
unsigned int module_index=0;
|
||||
unsigned int i;
|
||||
|
||||
if(Module_TopAddressIsValid(&modules[module_index])){
|
||||
if(Feb_control_master){//if(Module_TopAddressIsValid(&modules[module_index])){
|
||||
if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/
|
||||
cprintf(RED,"Error could not set high voltage module number %d invalid.\n",module_num);
|
||||
return 0;
|
||||
@@ -962,7 +959,9 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
for(l_r=0;l_r<2;l_r++){ // l_r loop
|
||||
//printf("\nl_r:%d\t\t",l_r);
|
||||
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
|
||||
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
|
||||
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
|
||||
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
|
||||
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
|
||||
printf("Could not select chips\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1187,7 +1186,7 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_Reset(){
|
||||
int Feb_Control_Reset(){printf("Reset daq\n");
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
|
||||
cprintf(RED,"Warning: Could not reset daq, no response.\n");
|
||||
return 0;
|
||||
@@ -1378,7 +1377,7 @@ int Feb_Control_SetSubFrameExposureTime(int the_subframe_exposure_time_in_10nsec
|
||||
printf("Sub Frame Exposure time set to: %d\n",Feb_Control_subframe_exposure_time_in_10nsec);
|
||||
return 1;
|
||||
}
|
||||
int Feb_Control_GetSubFrameExposureTime(){return Feb_Control_subframe_exposure_time_in_10nsec;}
|
||||
int Feb_Control_GetSubFrameExposureTime(){return Feb_Control_subframe_exposure_time_in_10nsec*10;}
|
||||
|
||||
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec){
|
||||
Feb_Control_exposure_period_in_sec = the_exposure_period_in_sec;
|
||||
@@ -1545,7 +1544,7 @@ int Feb_Control_PrepareForAcquisition(){//return 1;
|
||||
}
|
||||
|
||||
int ret=0;
|
||||
if(counter_bit)
|
||||
if(Feb_Control_counter_bit)
|
||||
ret = Feb_Control_ResetChipCompletely();
|
||||
else
|
||||
ret = Feb_Control_ResetChipPartially();
|
||||
@@ -1648,11 +1647,11 @@ int Feb_Control_SaveAllTrimbitsTo(int value){
|
||||
|
||||
|
||||
void Feb_Control_Set_Counter_Bit(int value){
|
||||
counter_bit = value;
|
||||
Feb_Control_counter_bit = value;
|
||||
}
|
||||
|
||||
int Feb_Control_Get_Counter_Bit(){
|
||||
return counter_bit;
|
||||
return Feb_Control_counter_bit;
|
||||
}
|
||||
|
||||
int Feb_Control_Pulse_Pixel(int npulses, int x, int y){
|
||||
@@ -1777,8 +1776,8 @@ int Feb_Control_PulseChip(int npulses){
|
||||
cprintf(RED,"some wait error\n");
|
||||
}
|
||||
Feb_Control_SetExternalEnableMode(on,1);
|
||||
counter_bit = (on?0:1);
|
||||
printf("counter_bit:%d\n",counter_bit);
|
||||
Feb_Control_counter_bit = (on?0:1);
|
||||
printf("Feb_Control_counter_bit:%d\n",Feb_Control_counter_bit);
|
||||
|
||||
if(on)
|
||||
printf("Pulse chip success\n\n");
|
||||
@@ -1789,10 +1788,174 @@ int Feb_Control_PulseChip(int npulses){
|
||||
|
||||
|
||||
|
||||
int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;}
|
||||
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec(){ return Feb_Control_RateTable_Subexptime_in_nsec;}
|
||||
|
||||
//returns -1 if slope is too high
|
||||
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
|
||||
double sub_expure_time_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9;
|
||||
double tau_in_sec = (double)tau_in_Nsec/(double)1e9;
|
||||
unsigned int np = 16384; //max slope 16 * 1024
|
||||
double b0[1024];
|
||||
double m[1024];
|
||||
|
||||
|
||||
if(tau_in_sec<0||sub_expure_time_in_sec<0){
|
||||
printf("Error tau %f and sub_expure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec);
|
||||
int i;
|
||||
for(i=0;i<np;i++)
|
||||
Feb_Control_rate_meas[i] = i*exp(-i/sub_expure_time_in_sec*tau_in_sec);
|
||||
|
||||
/*
|
||||
b : index/address of block ram/rate correction table
|
||||
b0 : base in vhdl
|
||||
m : slope in vhdl
|
||||
|
||||
Firmware:
|
||||
data_in(11..2) -> memory address --> memory
|
||||
data_in( 1..0) -> lsb
|
||||
|
||||
mem_data_out(13.. 0) -> base
|
||||
mem_data_out(17..14) -> slope
|
||||
|
||||
delta = slope*lsb
|
||||
corr = base+delta
|
||||
*/
|
||||
|
||||
int next_i=0;
|
||||
|
||||
b0[0] = 0;
|
||||
m[0] = 1;
|
||||
int b;
|
||||
for(b=1;b<1024;b++){
|
||||
if(m[b-1]<14.5){
|
||||
double s=0,sx=0,sy=0,sxx=0,sxy=0;
|
||||
for(;;next_i++){
|
||||
if(next_i>=np){
|
||||
cprintf(RED,"Error: (tau/subexptime) must be < 0.0015 \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
double x = Feb_Control_rate_meas[next_i] - b*4;
|
||||
double y = next_i;
|
||||
/*printf("Start Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||
x, y, s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
|
||||
|
||||
if(x < -0.5) continue;
|
||||
if(x > 3.5) break;
|
||||
s += 1;
|
||||
sx += x;
|
||||
sy += y;
|
||||
sxx += x*x;
|
||||
sxy += x*y;
|
||||
/*printf("End Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||
x, y, s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
|
||||
}
|
||||
double delta = s*sxx - sx*sx;
|
||||
b0[b] = (sxx*sy - sx*sxy)/delta;
|
||||
m[b] = (s*sxy - sx*sy) /delta;
|
||||
|
||||
if(m[b]<0||m[b]>15)
|
||||
m[b]=15;
|
||||
/*printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||
s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
|
||||
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
|
||||
}else{
|
||||
b0[b] = b0[b-1] + 4*m[b-1];
|
||||
m[b] = m[b-1];
|
||||
/*printf("else\n");*/
|
||||
}
|
||||
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
|
||||
/*printf("After Loop 4*b: %d\tbase:%d\tslope:%d\n",4*b, (int)(b0[b]+0.5), (int)(m[b]+0.5) );*/
|
||||
}
|
||||
|
||||
if(Feb_Control_SetRateCorrectionTable(Feb_Control_rate_correction_table)){
|
||||
Feb_Control_RateTable_Tau_in_nsec = tau_in_Nsec;
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = Feb_Control_GetSubFrameExposureTime();
|
||||
return 1;
|
||||
}else{
|
||||
Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
||||
if(!table){
|
||||
printf("Error: could not set rate correction table, point is zero.\n");
|
||||
Feb_Control_SetRateCorrectionVariable(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
printf("Setting rate correction table. %d %d %d %d ....\n",
|
||||
table[0],table[1],table[2],table[3]);
|
||||
|
||||
//was added otherwise after an acquire, startdaqonlywatiforfinish waits forever
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY)){
|
||||
cprintf(RED,"Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n");
|
||||
return 0;
|
||||
}
|
||||
printf("daq reset completely\n");
|
||||
|
||||
if(Module_TopAddressIsValid(&modules[1])){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_GetRateCorrectionVariable(){ return (Feb_Control_subFrameMode&DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION);}
|
||||
|
||||
|
||||
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction){
|
||||
if(activate_rate_correction){
|
||||
Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
||||
printf("Rate correction activated. Note: the rate correction applied only when run in auto summing mode.\n");
|
||||
}else{
|
||||
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
||||
printf("Rate correction deactivated.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_PrintCorrectedValues(){
|
||||
int i;
|
||||
int delta, slope, base, lsb, corr;
|
||||
for (i=0; i < 4096; i++){
|
||||
lsb = i&3;
|
||||
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
|
||||
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
|
||||
delta = slope*lsb;
|
||||
corr = delta+base;
|
||||
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n",
|
||||
i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ int Feb_Control_GetModuleNumber();
|
||||
|
||||
|
||||
void Feb_Control_FebControl();
|
||||
int Feb_Control_Init(int master, int top);
|
||||
int Feb_Control_Init(int master, int top, int module_num);
|
||||
int Feb_Control_ReadSetUpFileToAddModules(char* file_name);
|
||||
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name);
|
||||
int Feb_Control_CheckSetup();
|
||||
@@ -184,5 +184,12 @@ int Feb_Control_GetModuleNumber();
|
||||
int Feb_Control_ClockRowClock(unsigned int ntimes);
|
||||
int Feb_Control_PulseChip(int npulses);
|
||||
|
||||
int64_t Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec);
|
||||
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
|
||||
int Feb_Control_GetRateCorrectionVariable();
|
||||
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
|
||||
int Feb_Control_PrintCorrectedValues();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
/*int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons=0, unsigned int* wait_on_addresses=0);*/
|
||||
int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses);
|
||||
|
||||
|
||||
//mem_num is 0 for trimbit BRAM and 1 for rate correction BRAM
|
||||
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
|
||||
|
||||
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3
slsDetectorSoftware/eigerDetectorServer/renameServer.sh
Normal file
3
slsDetectorSoftware/eigerDetectorServer/renameServer.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
mv bin/eigerDetectorServer bin/$2
|
||||
git rm bin/$1
|
||||
git add bin/$2
|
||||
@@ -51,9 +51,24 @@ unsigned int nimages_per_request=1;
|
||||
int on_dst=0;
|
||||
int dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
//char Module_dac_names[16][10]= {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};;
|
||||
|
||||
int default_dac_values[16] = {0,2480,3300,1400,4000,2556,1000,1000,4000,1000,1000,1000,1000,200,2000,1550};
|
||||
int default_dac_values[16] = {
|
||||
0, //SvP
|
||||
2480, //Vtr
|
||||
3300, //Vrf
|
||||
1400, //Vrs
|
||||
4000, //SvN
|
||||
2556, //Vtgstv
|
||||
1000, //Vcmp_ll
|
||||
1000, //Vcmp_lr
|
||||
4000, //cal
|
||||
1000, //Vcmp_rl
|
||||
1100, //rxb_rb
|
||||
1100, //rxb_lb
|
||||
1000, //Vcmp_rr
|
||||
200, //Vcp
|
||||
2000, //Vcn
|
||||
1550 //Vis
|
||||
};
|
||||
int default_gain_values[3] = {517000,517000,517000};
|
||||
int default_offset_values[3] = {3851000,3851000,3851000};
|
||||
|
||||
@@ -125,7 +140,7 @@ int initDetector(){
|
||||
getModuleConfiguration();
|
||||
Feb_Interface_FebInterface();
|
||||
Feb_Control_FebControl();
|
||||
Feb_Control_Init(master,top);
|
||||
Feb_Control_Init(master,top,getDetectorNumber());
|
||||
printf("FEB Initialization done\n");
|
||||
Beb_Beb();
|
||||
printf("BEB Initialization done\n");
|
||||
@@ -145,10 +160,10 @@ int initDetector(){
|
||||
setReadOutFlags(NONPARALLEL);
|
||||
setSpeed(0,1);//clk_devider,half speed
|
||||
setHighVolage(0,0);
|
||||
setIODelay(675,0);
|
||||
setIODelay(650,0);
|
||||
setTiming(AUTO_TIMING);
|
||||
//SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15);
|
||||
//SetRateCorrection(0); //deactivate rate correction
|
||||
setRateCorrection(0); //deactivate rate correction
|
||||
int enable[2] = {0,1};
|
||||
setExternalGating(enable);//disable external gating
|
||||
Feb_Control_SetInTestModeVariable(0);
|
||||
@@ -166,7 +181,7 @@ int initDetectorStop(){
|
||||
getModuleConfiguration();
|
||||
Feb_Interface_FebInterface();
|
||||
Feb_Control_FebControl();
|
||||
Feb_Control_Init(master,top);
|
||||
Feb_Control_Init(master,top,getDetectorNumber());
|
||||
printf("FEB Initialization done\n");
|
||||
/* Beb_Beb(-1);
|
||||
printf("BEB constructor done\n");*/
|
||||
@@ -279,6 +294,9 @@ u_int64_t getDetectorMAC() {
|
||||
pch = strtok (NULL, ":");
|
||||
}
|
||||
sscanf(mac,"%llx",&res);
|
||||
//increment by 1 for 10g
|
||||
if(send_to_ten_gig)
|
||||
res++;
|
||||
//printf("mac:%llx\n",res);
|
||||
|
||||
return res;
|
||||
@@ -471,9 +489,54 @@ int pulseChip(int n){
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setRateCorrection(int64_t custom_tau_in_nsec){//in nanosec (will never be -1)
|
||||
|
||||
//deactivating rate correction
|
||||
if(custom_tau_in_nsec==0){
|
||||
Feb_Control_SetRateCorrectionVariable(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
int64_t subexp_in_nsec = Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
//same setting
|
||||
if((tau_in_nsec == custom_tau_in_nsec) && (subexp_in_nsec == Feb_Control_GetSubFrameExposureTime())){
|
||||
printf("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
|
||||
tau_in_nsec,subexp_in_nsec);
|
||||
}
|
||||
//different setting, calculate table
|
||||
else{
|
||||
int ret = Feb_Control_SetRateCorrectionTau(custom_tau_in_nsec);
|
||||
if(ret<=0){
|
||||
cprintf(RED,"Rate correction failed. Deactivating rate correction\n");
|
||||
Feb_Control_SetRateCorrectionVariable(0);
|
||||
return ret;//-1 is for tau/subexptime error, 0 for all other errors
|
||||
}
|
||||
}
|
||||
//activating rate correction
|
||||
Feb_Control_SetRateCorrectionVariable(1);
|
||||
#ifdef VERBOSE
|
||||
Feb_Control_PrintCorrectedValues();
|
||||
#endif
|
||||
|
||||
return Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
}
|
||||
|
||||
int getRateCorrectionEnable(){
|
||||
return Feb_Control_GetRateCorrectionVariable();
|
||||
}
|
||||
|
||||
int getDefaultSettingsTau_in_nsec(){
|
||||
switch(thisSettings){
|
||||
case STANDARD: return STANDARD_TAU;
|
||||
case HIGHGAIN: return HIGHGAIN_TAU;
|
||||
case LOWGAIN: return LOWGAIN_TAU;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int setModule(sls_detector_module myMod, int* gain, int* offset){
|
||||
int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){
|
||||
int retval[2];
|
||||
int i;
|
||||
|
||||
@@ -497,6 +560,12 @@ int setModule(sls_detector_module myMod, int* gain, int* offset){
|
||||
printf("offset[%d]:%d\n",i,detectorOffset[i]);
|
||||
}else cprintf(RED,"offset not set\n");
|
||||
}
|
||||
|
||||
if(setIODelay(*delay, -1)!= (*delay)){
|
||||
cprintf(RED,"could not set iodelay %d\n",*delay);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
//copy module locally
|
||||
if (detectorModules)
|
||||
copyModule(detectorModules,&myMod);
|
||||
@@ -761,7 +830,7 @@ int64_t setTimer(enum timerIndex ind, int64_t val){
|
||||
printf(" Setting sub exp time: %dns\n",(int)val/10);
|
||||
Feb_Control_SetSubFrameExposureTime(val/10);
|
||||
}
|
||||
return (Feb_Control_GetSubFrameExposureTime()*10);
|
||||
return (Feb_Control_GetSubFrameExposureTime());
|
||||
|
||||
|
||||
case FRAME_PERIOD:
|
||||
@@ -911,15 +980,15 @@ int executeTrimming(enum trimMode mode, int par1, int par2, int imod){
|
||||
|
||||
|
||||
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int udpport2, int ival){
|
||||
if (detectormacadd != getDetectorMAC()){
|
||||
printf("*************************************************\n");
|
||||
printf("WARNING: actual detector mac address %llx does not match the one from client %llx\n",getDetectorMAC(),detectormacadd);
|
||||
detectormacadd = getDetectorMAC();
|
||||
printf("WARNING: Matched detectormac to the hardware mac now\n");
|
||||
printf("*************************************************\n");
|
||||
}
|
||||
//only for 1Gbe
|
||||
if(!send_to_ten_gig){
|
||||
if (detectormacadd != getDetectorMAC()){
|
||||
printf("*************************************************\n");
|
||||
printf("WARNING: actual detector mac address %llx does not match the one from client %llx\n",getDetectorMAC(),detectormacadd);
|
||||
detectormacadd = getDetectorMAC();
|
||||
printf("WARNING: Matched detectormac to the hardware mac now\n");
|
||||
printf("*************************************************\n");
|
||||
}
|
||||
if (detipad != getDetectorIP()){
|
||||
printf("*************************************************\n");
|
||||
printf("WARNING: actual detector ip address %x does not match the one from client %x\n",getDetectorIP(),detipad);
|
||||
|
||||
@@ -40,4 +40,12 @@
|
||||
|
||||
enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD};
|
||||
|
||||
enum defaultTauValues{
|
||||
HIGHGAIN_TAU=410,
|
||||
STANDARD_TAU=290,
|
||||
LOWGAIN_TAU=180};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SLSDETECTORSERVER_DEFS_H_ */
|
||||
|
||||
Binary file not shown.
BIN
slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv2.0
Executable file
BIN
slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv2.0
Executable file
Binary file not shown.
@@ -725,9 +725,9 @@ int setSettings(int i, int imod) {
|
||||
}
|
||||
}
|
||||
thisSettings=isett;
|
||||
#ifdef VERBOSE
|
||||
//#ifdef VERBOSE
|
||||
printf("detector settings are %d\n",thisSettings);
|
||||
#endif
|
||||
//#endif
|
||||
return thisSettings;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
CROSS = bfin-uclinux-
|
||||
CC = $(CROSS)gcc
|
||||
|
||||
CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1#-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER
|
||||
CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER
|
||||
|
||||
|
||||
PROGS= jungfrauDetectorServer
|
||||
PROGS= jungfrauDetectorServerTest
|
||||
INSTDIR= /tftpboot
|
||||
INSTMODE= 0777
|
||||
|
||||
|
||||
|
||||
BINS = testlib_sharedlibc
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c sharedmemory.c
|
||||
OBJS = $(SRCS:%.c=%.o)
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@ test: clean jungfrauADCTEst
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
jungfrauDetectorServerTest: $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
|
||||
|
||||
|
||||
jungfrauDetectorServer: $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
|
||||
|
||||
1
slsDetectorSoftware/jungfrauDetectorServer/ansi.h
Symbolic link
1
slsDetectorSoftware/jungfrauDetectorServer/ansi.h
Symbolic link
@@ -0,0 +1 @@
|
||||
/afs/psi.ch/project/sls_det_software/dhanya_softwareDevelopment/mySoft/slsDetectorsPackage/slsReceiverSoftware/include/ansi.h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -69,6 +69,8 @@ int setContinousReadOut(int d);
|
||||
int startReceiver(int d);
|
||||
|
||||
int setDACRegister(int idac, int val, int imod);
|
||||
int getDacRegister(int dacnum);
|
||||
|
||||
|
||||
int getTemperature(int tempSensor,int imod);
|
||||
int initHighVoltage(int val,int imod);
|
||||
@@ -82,6 +84,8 @@ int getAdcConfigured();
|
||||
|
||||
u_int64_t getDetectorNumber();
|
||||
u_int32_t getFirmwareVersion();
|
||||
u_int32_t getFirmwareSVNVersion();
|
||||
|
||||
int testFifos(void);
|
||||
u_int32_t testFpga(void);
|
||||
u_int32_t testRAM(void);
|
||||
@@ -144,8 +148,16 @@ int setDynamicRange(int dr);
|
||||
int getDynamicRange();
|
||||
int getNModBoard();
|
||||
int setNMod(int n);
|
||||
int getNMod();
|
||||
|
||||
int setStoreInRAM(int b);
|
||||
int allocateRAM();
|
||||
|
||||
|
||||
int writeADC(int addr, int val);
|
||||
int prepareADC();
|
||||
|
||||
|
||||
int clearRAM();
|
||||
|
||||
|
||||
|
||||
BIN
slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerTest
Executable file
BIN
slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerTest
Executable file
Binary file not shown.
@@ -23,10 +23,6 @@
|
||||
extern int nModX;
|
||||
//extern int dataBytes;
|
||||
extern int dynamicRange;
|
||||
const int nChans=NCHAN;
|
||||
const int nChips=NCHIP;
|
||||
const int nDacs=NDAC;
|
||||
const int nAdcs=NADC;
|
||||
enum detectorSettings thisSettings;
|
||||
|
||||
int sChan, sChip, sMod, sDac, sAdc;
|
||||
@@ -43,7 +39,19 @@ int *detectorAdcs=NULL;
|
||||
|
||||
ROI rois[MAX_ROIS];
|
||||
int nROI=0;
|
||||
extern enum detectorType myDetectorType;
|
||||
|
||||
/** for jungfrau reinitializing macro later in server_funcs.c in initDetector*/
|
||||
extern int N_CHAN;
|
||||
extern int N_CHIP;
|
||||
extern int N_DAC;
|
||||
extern int N_ADC;
|
||||
extern int N_CHANS;
|
||||
|
||||
extern int nChans;
|
||||
extern int nChips;
|
||||
extern int nDacs;
|
||||
extern int nAdcs;
|
||||
|
||||
int initDetector() {
|
||||
|
||||
@@ -55,29 +63,53 @@ int initDetector() {
|
||||
#ifdef VERBOSE
|
||||
printf("Board is for %d modules\n",n);
|
||||
#endif
|
||||
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
N_CHAN=JUNGFRAU_NCHAN;
|
||||
N_CHIP=JUNGFRAU_NCHIP;
|
||||
N_DAC=JUNGFRAU_NDAC;
|
||||
N_ADC=JUNGFRAU_NADC;
|
||||
N_CHANS=JUNGFRAU_NCHANS;
|
||||
|
||||
nChans=N_CHAN;
|
||||
nChips=N_CHIP;
|
||||
nDacs=N_DAC;
|
||||
nAdcs=N_ADC;
|
||||
}
|
||||
|
||||
detectorModules=malloc(n*sizeof(sls_detector_module));
|
||||
detectorChips=malloc(n*NCHIP*sizeof(int));
|
||||
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
||||
detectorDacs=malloc(n*NDAC*sizeof(int));
|
||||
detectorAdcs=malloc(n*NADC*sizeof(int));
|
||||
detectorDacs=malloc(n*N_DAC*sizeof(int));
|
||||
detectorAdcs=malloc(n*N_ADC*sizeof(int));
|
||||
detectorChips=NULL;
|
||||
detectorChans=NULL;
|
||||
detectorAdcs=NULL;
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
detectorChips=malloc(n*N_CHIP*sizeof(int));
|
||||
detectorChans=malloc(n*N_CHIP*N_CHAN*sizeof(int));
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n));
|
||||
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP));
|
||||
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN));
|
||||
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*NDAC));
|
||||
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*NADC));
|
||||
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*N_DAC));
|
||||
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*N_ADC));
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*N_CHIP));
|
||||
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*N_CHIP*N_CHAN));
|
||||
}
|
||||
#endif
|
||||
for (imod=0; imod<n; imod++) {
|
||||
|
||||
|
||||
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
|
||||
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
|
||||
(detectorModules+imod)->chipregs=detectorChips+imod*NCHIP;
|
||||
(detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN;
|
||||
(detectorModules+imod)->ndac=NDAC;
|
||||
(detectorModules+imod)->nadc=NADC;
|
||||
(detectorModules+imod)->nchip=NCHIP;
|
||||
(detectorModules+imod)->nchan=NCHIP*NCHAN;
|
||||
|
||||
for (imod=0; imod<n; imod++) {
|
||||
(detectorModules+imod)->dacs=detectorDacs+imod*N_DAC;
|
||||
(detectorModules+imod)->adcs=detectorAdcs+imod*N_ADC;
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
(detectorModules+imod)->chipregs=detectorChips+imod*N_CHIP;
|
||||
(detectorModules+imod)->chanregs=detectorChans+imod*N_CHIP*N_CHAN;
|
||||
}
|
||||
(detectorModules+imod)->ndac=N_DAC;
|
||||
(detectorModules+imod)->nadc=N_ADC;
|
||||
(detectorModules+imod)->nchip=N_CHIP;
|
||||
(detectorModules+imod)->nchan=N_CHIP*N_CHAN;
|
||||
(detectorModules+imod)->module=imod;
|
||||
(detectorModules+imod)->gain=0;
|
||||
(detectorModules+imod)->offset=0;
|
||||
@@ -103,14 +135,12 @@ int initDetector() {
|
||||
/* dynamicRange=getDynamicRange(); //always 16 not required commented out
|
||||
nModX=setNMod(-1);*/
|
||||
|
||||
//dataBytes=nModX*NCHIP*NCHAN*4;
|
||||
// dynamicRange=32;
|
||||
// initChip(0, 0,ALLMOD);
|
||||
//nModX=n;
|
||||
//
|
||||
allocateRAM();
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -211,22 +241,27 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
||||
|
||||
// printf("copying gain and offset %f %f to %f %f\n",srcMod->gain,srcMod->offset,destMod->gain,destMod->offset);
|
||||
|
||||
for (ichip=0; ichip<(srcMod->nchip); ichip++) {
|
||||
if (*((srcMod->chipregs)+ichip)>=0)
|
||||
*((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip);
|
||||
}
|
||||
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
|
||||
if (*((srcMod->chanregs)+ichan)>=0)
|
||||
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
for (ichip=0; ichip<(srcMod->nchip); ichip++) {
|
||||
if (*((srcMod->chipregs)+ichip)>=0)
|
||||
*((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip);
|
||||
}
|
||||
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
|
||||
if (*((srcMod->chanregs)+ichan)>=0)
|
||||
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
|
||||
}
|
||||
}
|
||||
|
||||
for (idac=0; idac<(srcMod->ndac); idac++) {
|
||||
if (*((srcMod->dacs)+idac)>=0)
|
||||
*((destMod->dacs)+idac)=*((srcMod->dacs)+idac);
|
||||
}
|
||||
|
||||
for (iadc=0; iadc<(srcMod->nadc); iadc++) {
|
||||
if (*((srcMod->adcs)+iadc)>=0)
|
||||
*((destMod->adcs)+iadc)=*((srcMod->adcs)+iadc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -480,15 +515,15 @@ int selChip(const int chip,int imod) {
|
||||
/* sMod=allSelected; */
|
||||
|
||||
/* if (imod>=0 && imod<nModX) { */
|
||||
/* detectorDacs[idac+NDAC*imod]=v; */
|
||||
/* detectorDacs[idac+N_DAC*imod]=v; */
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, (unsigned int)(detectorDacs+idac+NDAC*imod)); */
|
||||
/* printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, (unsigned int)(detectorDacs+idac+N_DAC*imod)); */
|
||||
/* #endif */
|
||||
|
||||
/* setDACRegister(idac,v,imod); */
|
||||
/* } else if (imod==ALLMOD) { */
|
||||
/* for (im=0; im<nModX; im++) { */
|
||||
/* detectorDacs[idac+NDAC*im]=v; */
|
||||
/* detectorDacs[idac+N_DAC*im]=v; */
|
||||
/* setDACRegister(idac,v,im); */
|
||||
/* } */
|
||||
/* } */
|
||||
@@ -544,9 +579,9 @@ int selChip(const int chip,int imod) {
|
||||
|
||||
/* int initDACbyIndex(int ind,int val, int imod) { */
|
||||
/* int v; */
|
||||
/* const int partref[NDAC]=PARTREF; */
|
||||
/* const int partr1[NDAC]=PARTR1; */
|
||||
/* const int partr2[NDAC]=PARTR2; */
|
||||
/* const int partref[N_DAC]=PARTREF; */
|
||||
/* const int partr1[N_DAC]=PARTR1; */
|
||||
/* const int partr2[N_DAC]=PARTR2; */
|
||||
|
||||
/* int ref=partref[ind]; */
|
||||
/* int r1=partr1[ind]; */
|
||||
@@ -561,8 +596,8 @@ int selChip(const int chip,int imod) {
|
||||
|
||||
/* int initDACbyIndexDACU(int ind, int val, int imod) { */
|
||||
|
||||
/* // const double daccs[NDAC]=DACCS; */
|
||||
/* // const double dacaddr[NDAC]=DACADDR; */
|
||||
/* // const double daccs[N_DAC]=DACCS; */
|
||||
/* // const double dacaddr[N_DAC]=DACADDR; */
|
||||
|
||||
/* // int cs=daccs[ind]; */
|
||||
/* // int addr=dacaddr[ind]; */
|
||||
@@ -573,7 +608,7 @@ int selChip(const int chip,int imod) {
|
||||
/* initDAC(ind,val, imod); */
|
||||
|
||||
/* if (imod>=0 && imod<nModX) { */
|
||||
/* // return detectorDacs[ind+imod*NDAC]; */
|
||||
/* // return detectorDacs[ind+imod*N_DAC]; */
|
||||
/* return setDACRegister(ind, -1, imod); */
|
||||
/* } */
|
||||
/* else { */
|
||||
@@ -585,7 +620,7 @@ int selChip(const int chip,int imod) {
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("mod %d dac %d val %d\n",im,ind,setDACRegister(ind, -1, im)); */
|
||||
/* #endif */
|
||||
/* //if (detectorDacs[ind+im*NDAC]!=detectorDacs[ind]) { */
|
||||
/* //if (detectorDacs[ind+im*N_DAC]!=detectorDacs[ind]) { */
|
||||
|
||||
/* if (setDACRegister(ind, -1, im)!=setDACRegister(ind, -1, 0)) { */
|
||||
/* #ifdef VERBOSE */
|
||||
@@ -636,7 +671,7 @@ int selChip(const int chip,int imod) {
|
||||
/* } */
|
||||
|
||||
/* if (myg>0 && myo>0) { */
|
||||
/* //ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg; */
|
||||
/* //ethr=(myo-detectorDacs[VTHRESH+imod*N_DAC])*1000/myg; */
|
||||
|
||||
/* ethr=(myo-setDACRegister(VDAC0,-1,imod))*1000/myg;//edited by dhanya */
|
||||
/* // else */
|
||||
@@ -644,7 +679,7 @@ int selChip(const int chip,int imod) {
|
||||
|
||||
/* } */
|
||||
/* #ifdef VERBOSE */
|
||||
/* //printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]); */
|
||||
/* //printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*N_DAC]); */
|
||||
/* printf("module=%d gain=%f, offset=%f, dacu=%d\n",imod, myg, myo,(int)(setDACRegister(VDAC0,-1,imod)));//edited by dhanya */
|
||||
/* printf("Threshold energy of module %d is %d eV\n", imod, ethr); */
|
||||
/* #endif */
|
||||
@@ -722,7 +757,7 @@ int selChip(const int chip,int imod) {
|
||||
/* if (detectorDacs) { */
|
||||
/* if (imod<getNModBoard()) */
|
||||
/* if (ind<(detectorModules+imod)->ndac) */
|
||||
/* return (detectorDacs[ind+imod*NDAC]); */
|
||||
/* return (detectorDacs[ind+imod*N_DAC]); */
|
||||
/* } */
|
||||
/* return FAIL; */
|
||||
/* *\/ */
|
||||
@@ -847,38 +882,51 @@ int setSettings(int i, int imod) {
|
||||
else
|
||||
printf("\ninside set settings wit settings=%d...\n",i);
|
||||
#endif
|
||||
int confgain[] = CONF_GAIN;
|
||||
int isett=-2,retval;
|
||||
int isett=-1,val=-1,retval=-1;
|
||||
enum conf_gain {
|
||||
dynamic = 0x0f00, //dynamic
|
||||
dynamichighgain0 = 0x0f01, //dynamichighgain0
|
||||
fixgain1 = 0x0f02, //fixgain1
|
||||
fixgain2 = 0x0f06, //fixgain2
|
||||
forceswitchgain1 = 0x1f00, //forceswitchgain1
|
||||
forceswitchgain2 = 0x3f00 //forceswitchgain2
|
||||
};
|
||||
|
||||
//reading settings
|
||||
if(i==GET_SETTINGS){
|
||||
retval=initConfGainByModule(i,i,imod);
|
||||
if(retval==i)
|
||||
isett=UNDEFINED;
|
||||
}
|
||||
//writing settings
|
||||
else{
|
||||
retval=initConfGainByModule(i,confgain[i],imod);
|
||||
if(retval!=i)
|
||||
isett=UNDEFINED;
|
||||
}
|
||||
//if error while read/writing
|
||||
if(isett==UNDEFINED)
|
||||
printf("Error:Weird Value read back from the Gain/Settings Reg\n");
|
||||
else{
|
||||
//validating the settings read back
|
||||
if((retval>=HIGHGAIN)&&(retval<=VERYHIGHGAIN))
|
||||
isett=retval;
|
||||
else{
|
||||
isett=UNDEFINED;
|
||||
printf("Error:Wrong Settings Read out:%d\n",retval);
|
||||
}
|
||||
}
|
||||
thisSettings=isett;
|
||||
#ifdef VERBOSE
|
||||
printf("detector settings are %d\n",thisSettings);
|
||||
#endif
|
||||
return thisSettings;
|
||||
//determine conf value to write
|
||||
if(i!=GET_SETTINGS){
|
||||
switch(i){
|
||||
case DYNAMICGAIN: val = dynamic;break;
|
||||
case DYNAMICHG0: val = dynamichighgain0;break;
|
||||
case FIXGAIN1: val = fixgain1;break;
|
||||
case FIXGAIN2: val = fixgain2;break;
|
||||
case FORCESWITCHG1: val = forceswitchgain1;break;
|
||||
case FORCESWITCHG2: val = forceswitchgain2;break;
|
||||
default:
|
||||
printf("Error: This settings is not defined for this detector %d\n",i);
|
||||
return GET_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
retval=initConfGainByModule(i,val,imod);
|
||||
|
||||
switch(retval){
|
||||
case dynamic: isett=DYNAMICGAIN; break;
|
||||
case dynamichighgain0: isett=DYNAMICHG0; break;
|
||||
case fixgain1: isett=FIXGAIN1; break;
|
||||
case fixgain2: isett=FIXGAIN2; break;
|
||||
case forceswitchgain1: isett=FORCESWITCHG1; break;
|
||||
case forceswitchgain2: isett=FORCESWITCHG2; break;
|
||||
default:
|
||||
isett=UNDEFINED;
|
||||
printf("Error:Wrong settings read out from Gain Reg 0x%x\n",retval);
|
||||
break;
|
||||
}
|
||||
|
||||
thisSettings=isett;
|
||||
//#ifdef VERBOSE
|
||||
printf("detector settings are %d\n",thisSettings);
|
||||
//#endif
|
||||
return thisSettings;
|
||||
}
|
||||
|
||||
|
||||
@@ -886,7 +934,7 @@ int setSettings(int i, int imod) {
|
||||
|
||||
/* Initialization*/
|
||||
|
||||
int initChannelbyNumber(sls_detector_channel myChan) {
|
||||
int initChannelbyNumber(sls_detector_channel myChan) {printf("in init channel by number\n");
|
||||
int reg=myChan.reg;
|
||||
int ft=reg & TRIM_DR;
|
||||
int cae=(reg>>(NTRIMBITS))&1;
|
||||
@@ -930,7 +978,7 @@ int getChannelbyNumber(sls_detector_channel* myChan) {
|
||||
if (detectorChans) {
|
||||
if (imod<nModX && imod>=0) {
|
||||
if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip)
|
||||
myChan->reg=detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan];
|
||||
myChan->reg=detectorChans[imod*N_CHAN*N_CHIP+ichip*N_CHAN+ichan];
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
@@ -942,7 +990,7 @@ int getTrimbit(int imod, int ichip, int ichan) {
|
||||
if (detectorChans) {
|
||||
if (imod<getNModBoard() && imod>=0)
|
||||
if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip)
|
||||
return (detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan] & TRIM_DR);
|
||||
return (detectorChans[imod*N_CHAN*N_CHIP+ichip*N_CHAN+ichan] & TRIM_DR);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -966,8 +1014,8 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
|
||||
if (sChan==allSelected) {
|
||||
// printf("initializing all channels ft=%d coe=%d\n",ft,coe);
|
||||
chanmi=0;
|
||||
chanma=NCHAN;
|
||||
} else if (sChan==noneSelected || sChan>NCHAN || sChan<0) {
|
||||
chanma=N_CHAN;
|
||||
} else if (sChan==noneSelected || sChan>N_CHAN || sChan<0) {
|
||||
// printf("initializing no channels ft=%d coe=%d\n",ft,coe);
|
||||
chanmi=0;
|
||||
chanma=-1;
|
||||
@@ -980,8 +1028,8 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
|
||||
if (sChip==allSelected) {
|
||||
// printf("initializing all chips\n");
|
||||
chipmi=0;
|
||||
chipma=NCHIP;
|
||||
} else if (sChip==noneSelected || sChip>NCHIP || sChip<0) {
|
||||
chipma=N_CHIP;
|
||||
} else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) {
|
||||
// printf("initializing no chips\n");
|
||||
chipmi=0;
|
||||
chipma=-1;
|
||||
@@ -1009,12 +1057,12 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
|
||||
for (ichip=chipmi; ichip<chipma; ichip++) {
|
||||
for (ichan=chanmi; ichan<chanma; ichan++) {
|
||||
#ifdef VERBOSE
|
||||
// printf("im=%d ichi=%d icha=%d tot=%d reg=%x\n",im,ichip, ichan, im*NCHAN*NCHIP+ichip*NCHAN+ichan,detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
|
||||
// printf("im=%d ichi=%d icha=%d tot=%d reg=%x\n",im,ichip, ichan, im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan,detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]);
|
||||
#endif
|
||||
detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]= ft | (cae<<(NTRIMBITS+1)) | (ae<<(NTRIMBITS+2)) | (coe<<(NTRIMBITS+3)) | (ocoe<<(NTRIMBITS+4)) | (counts<<(NTRIMBITS+5));
|
||||
detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]= ft | (cae<<(NTRIMBITS+1)) | (ae<<(NTRIMBITS+2)) | (coe<<(NTRIMBITS+3)) | (ocoe<<(NTRIMBITS+4)) | (counts<<(NTRIMBITS+5));
|
||||
#ifdef VERBOSE
|
||||
//printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*NCHAN*NCHIP+ichip*NCHAN+ichan, detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
|
||||
// printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*NCHAN*NCHIP+ichip*NCHAN+ichan, detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
|
||||
//printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan, detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]);
|
||||
// printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan, detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1214,9 +1262,9 @@ int getChipbyNumber(sls_detector_chip* myChip){
|
||||
if (detectorChips) {
|
||||
if (imod<nModX)
|
||||
if (ichip<(detectorModules+imod)->nchip) {
|
||||
myChip->reg=detectorChips[ichip+imod*NCHIP];
|
||||
myChip->nchan=NCHAN;
|
||||
myChip->chanregs=detectorChans+imod*NCHAN*NCHIP+ichip*NCHIP;
|
||||
myChip->reg=detectorChips[ichip+imod*N_CHIP];
|
||||
myChip->nchan=N_CHAN;
|
||||
myChip->chanregs=detectorChans+imod*N_CHAN*N_CHIP+ichip*N_CHIP;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
@@ -1322,8 +1370,8 @@ int initChip(int obe, int ow,int imod){
|
||||
|
||||
if (sChip==allSelected) {
|
||||
chipmi=0;
|
||||
chipma=NCHIP;
|
||||
} else if (sChip==noneSelected || sChip>NCHIP || sChip<0) {
|
||||
chipma=N_CHIP;
|
||||
} else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) {
|
||||
chipmi=0;
|
||||
chipma=-1;
|
||||
} else {
|
||||
@@ -1347,9 +1395,9 @@ int initChip(int obe, int ow,int imod){
|
||||
for (im=modmi; im<modma; im++) {
|
||||
for (ichip=chipmi; ichip<chipma; ichip++) {
|
||||
// printf("imod %d ichip %d\n",im,ichip);
|
||||
detectorChips[im*NCHIP+ichip]=obe | (ow<<1);
|
||||
detectorChips[im*N_CHIP+ichip]=obe | (ow<<1);
|
||||
#ifdef VERBOSE
|
||||
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
|
||||
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*N_CHIP+ichip],detectorChips+im*N_CHIP+ichip);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1422,8 +1470,8 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
|
||||
|
||||
if (sChip==allSelected) {
|
||||
chipmi=0;
|
||||
chipma=NCHIP;
|
||||
} else if (sChip==noneSelected || sChip>NCHIP || sChip<0) {
|
||||
chipma=N_CHIP;
|
||||
} else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) {
|
||||
chipmi=0;
|
||||
chipma=-1;
|
||||
} else {
|
||||
@@ -1447,9 +1495,9 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
|
||||
for (im=modmi; im<modma; im++) {
|
||||
for (ichip=chipmi; ichip<chipma; ichip++) {
|
||||
// printf("imod %d ichip %d\n",im,ichip);
|
||||
detectorChips[im*NCHIP+ichip]=obe | (ow<<1);
|
||||
detectorChips[im*N_CHIP+ichip]=obe | (ow<<1);
|
||||
#ifdef VERBOSE
|
||||
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
|
||||
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*N_CHIP+ichip],detectorChips+im*N_CHIP+ichip);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1522,15 +1570,16 @@ int initMCBregisters(int cm, int imod){
|
||||
|
||||
int initModulebyNumber(sls_detector_module myMod) {
|
||||
|
||||
printf("\ninside initmoduleynumber..\n");
|
||||
|
||||
printf("\ninside initmoduleynumberrrr..\n");
|
||||
printf("000\n");
|
||||
int nchip,nchan;//int ichip, nchip, ichan, nchan;
|
||||
int im, modmi,modma;
|
||||
// int ft, cae, ae, coe, ocoe, counts, chanreg;
|
||||
int imod;
|
||||
// int obe;
|
||||
// int ow;
|
||||
int v[NDAC];
|
||||
/* int v[N_DAC];*/
|
||||
int retval =-1, idac;
|
||||
|
||||
|
||||
nchip=myMod.nchip;
|
||||
@@ -1553,12 +1602,10 @@ int initModulebyNumber(sls_detector_module myMod) {
|
||||
modma=sMod+1;
|
||||
}
|
||||
|
||||
|
||||
printf("222\n");
|
||||
/*
|
||||
for (idac=0; idac<NDAC; idac++)
|
||||
for (idac=0; idac<N_DAC; idac++)
|
||||
v[idac]=(myMod.dacs)[idac];
|
||||
*/
|
||||
|
||||
|
||||
v[VDAC0]=(myMod.dacs)[0];
|
||||
v[VDAC1]=(myMod.dacs)[1];
|
||||
@@ -1580,24 +1627,29 @@ int initModulebyNumber(sls_detector_module myMod) {
|
||||
printf("vdac6=%d\n",v[VDAC6]);
|
||||
printf("vdac7=%d\n",v[VDAC7]);
|
||||
#endif
|
||||
|
||||
|
||||
*/
|
||||
printf("ndac:%d\n",N_DAC);
|
||||
// initDACs(v,imod);
|
||||
// initMCBregisters(myMod.reg,imod);
|
||||
|
||||
for (idac=0; idac<N_DAC; idac++){
|
||||
retval = setDac(idac,(myMod.dacs)[idac]);
|
||||
if(retval ==(myMod.dacs)[idac])
|
||||
printf("Setting dac %d to %d\n",idac,retval);
|
||||
else
|
||||
printf("Error: Could not set dac %d, wrote %d but read %d\n",idac,(myMod.dacs)[idac],retval);
|
||||
}
|
||||
|
||||
if (detectorModules) {
|
||||
for (im=modmi; im<modma; im++) {
|
||||
for (im=modmi; im<modma; im++) {
|
||||
#ifdef VERBOSE
|
||||
printf("im=%d\n",im);
|
||||
#endif
|
||||
copyModule(detectorModules+im,&myMod);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//setting the conf gain and the settings register
|
||||
setSettings(myMod.reg,imod);
|
||||
|
||||
return myMod.reg;
|
||||
return thisSettings;
|
||||
}
|
||||
|
||||
|
||||
@@ -1739,11 +1791,11 @@ int readOutChan(int *val) {
|
||||
for (k=0; k<nModX; k++) {
|
||||
v=readin(k);
|
||||
//v=bus_r(MCB_DOUT_REG_OFF+(k<<SHIFTMOD)) & 0x3ff;
|
||||
for (j=0; j<NCHIP; j++) {
|
||||
for (j=0; j<N_CHIP; j++) {
|
||||
if (i==0)
|
||||
*(val+j+k*NCHIP)=0;
|
||||
*(val+j+k*N_CHIP)=0;
|
||||
if (v & (1<<j)) {
|
||||
*(val+j+k*NCHIP)= *(val+j+k*NCHIP) | (1 << i);
|
||||
*(val+j+k*N_CHIP)= *(val+j+k*N_CHIP) | (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1877,7 +1929,7 @@ int testShiftStSel(int imod) {
|
||||
int val,i,j,k;
|
||||
printf("testing shift stsel for module %d\n", imod);
|
||||
setCSregister(ALLMOD);
|
||||
for (i=0; i<NCHAN; i++) {
|
||||
for (i=0; i<N_CHAN; i++) {
|
||||
if (i%2) {
|
||||
putout("0100011000000000",ALLMOD);
|
||||
putout("0110011000000000",ALLMOD);
|
||||
@@ -1889,7 +1941,7 @@ int testShiftStSel(int imod) {
|
||||
}
|
||||
}
|
||||
putout("0010011000000000",ALLMOD);
|
||||
for (i=0; i<NCHAN; i++) {
|
||||
for (i=0; i<N_CHAN; i++) {
|
||||
putout("0000011000000000",ALLMOD);
|
||||
|
||||
|
||||
@@ -1897,7 +1949,7 @@ int testShiftStSel(int imod) {
|
||||
//for (k=0; k<nModX; k++) {
|
||||
val=readin(k);
|
||||
//val=bus_r(MCB_DOUT_REG_OFF+(k<<SHIFTMOD)) & 0x3ff;
|
||||
for (j=0; j<NCHIP; j++) {
|
||||
for (j=0; j<N_CHIP; j++) {
|
||||
if ( (val & 1<<j)>0 && i%2==0) {
|
||||
printf("Shift stsel: module %d chip %i bit %d read %d instead of %d \n",k,j,i,val & 1<< j, i%2);
|
||||
result++;
|
||||
@@ -1926,7 +1978,7 @@ int testShiftStSel(int imod) {
|
||||
|
||||
|
||||
int testDataInOut(int num, int imod) {
|
||||
int val[NCHIP*nModX], result=OK;
|
||||
int val[N_CHIP*nModX], result=OK;
|
||||
int ich, ichip;
|
||||
setCSregister(ALLMOD);
|
||||
printf("Testing data in out for module %d pattern 0x%x\n", imod, num);
|
||||
@@ -1936,14 +1988,14 @@ int testDataInOut(int num, int imod) {
|
||||
setCSregister(ALLMOD);
|
||||
initChip(0, 0,ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
for (ich=0; ich<NCHAN; ich++) {
|
||||
for (ich=0; ich<N_CHAN; ich++) {
|
||||
nextStrip(ALLMOD);
|
||||
readOutChan(val);
|
||||
//imod=0;
|
||||
//for (imod=0; imod<nModX; imod++) {
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
if (val[ichip+imod*NCHIP]!=num) {
|
||||
printf("Test datain out: Channel %d read %x instead of %x\n", (imod*NCHIP+ichip)*NCHAN+ich, val[ichip+NCHIP*imod], num);
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
if (val[ichip+imod*N_CHIP]!=num) {
|
||||
printf("Test datain out: Channel %d read %x instead of %x\n", (imod*N_CHIP+ichip)*N_CHAN+ich, val[ichip+N_CHIP*imod], num);
|
||||
result++;
|
||||
}
|
||||
}
|
||||
@@ -1970,7 +2022,7 @@ int testExtPulse(int imod) {
|
||||
putout("0000000000000000",ALLMOD);
|
||||
putout("0000100000000000",ALLMOD);
|
||||
putout("0000000000000000",ALLMOD);
|
||||
for (i=0; i<NCHAN; i++) {
|
||||
for (i=0; i<N_CHAN; i++) {
|
||||
putout("0000000000000000",ALLMOD);
|
||||
putout("0000000000001000",ALLMOD);
|
||||
putout("0000000000000000",ALLMOD);
|
||||
@@ -1989,11 +2041,11 @@ int testExtPulse(int imod) {
|
||||
// val1=fifo_read_event();
|
||||
//imod=0;
|
||||
//for (imod=0; imod<nModX; imod++) {
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
for (ichan=0; ichan<NCHAN; ichan++) {//
|
||||
if ((*(val1+ichan+(ichip+imod*NCHIP)*NCHAN))!=ichan) {
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
for (ichan=0; ichan<N_CHAN; ichan++) {//
|
||||
if ((*(val1+ichan+(ichip+imod*N_CHIP)*N_CHAN))!=ichan) {
|
||||
result++;
|
||||
printf("Counter test: channel %d read %d instead of %d\n",ichan+(ichip+imod*NCHIP)*NCHAN, val1[ichan+(ichip+imod*NCHIP)*NCHAN], ichan);
|
||||
printf("Counter test: channel %d read %d instead of %d\n",ichan+(ichip+imod*N_CHIP)*N_CHAN, val1[ichan+(ichip+imod*N_CHIP)*N_CHAN], ichan);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2035,9 +2087,9 @@ int testExtPulseMux(int imod, int ow) {
|
||||
counterClear(ALLMOD);
|
||||
initChipWithProbes(0, ow,0,ALLMOD);
|
||||
// initChip(0, ow,ALLMOD);
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
setSSregister(ALLMOD);
|
||||
for (i=0; i<NCHAN; i++) {
|
||||
for (i=0; i<N_CHAN; i++) {
|
||||
putout("0000000000000000",ALLMOD);
|
||||
putout("0000000000001000",ALLMOD);
|
||||
putout("0000000000000000",ALLMOD);
|
||||
@@ -2061,16 +2113,16 @@ int testExtPulseMux(int imod, int ow) {
|
||||
printf("no data found in fifos\n");
|
||||
return 1;
|
||||
}
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
chipr=0;
|
||||
for (ichan=0; ichan<NCHAN; ichan++) {
|
||||
ind=ichan+(ichip+imod*NCHIP)*NCHAN;
|
||||
for (ichan=0; ichan<N_CHAN; ichan++) {
|
||||
ind=ichan+(ichip+imod*N_CHIP)*N_CHAN;
|
||||
v=values[ind];
|
||||
vright=(ichan*(ichip+1))&nbit_mask;
|
||||
if (v!=vright) {
|
||||
result++;
|
||||
chipr++;
|
||||
printf("Counter test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
|
||||
printf("Counter test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*N_CHIP)*N_CHAN, ichip, v, vright);
|
||||
//break;
|
||||
}
|
||||
//printf("\n");
|
||||
@@ -2136,15 +2188,15 @@ int testDataInOutMux(int imod, int ow, int num) {
|
||||
printf("no data found in fifos\n");
|
||||
return 1;
|
||||
}
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
chipr=0;
|
||||
for (ichan=0; ichan<NCHAN; ichan++) {
|
||||
ind=ichan+(ichip+imod*NCHIP)*NCHAN;
|
||||
for (ichan=0; ichan<N_CHAN; ichan++) {
|
||||
ind=ichan+(ichip+imod*N_CHIP)*N_CHAN;
|
||||
v=values[ind];
|
||||
if (v!=vright) {
|
||||
result++;
|
||||
chipr++;
|
||||
printf("DataInOut test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
|
||||
printf("DataInOut test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*N_CHIP)*N_CHAN, ichip, v, vright);
|
||||
//break;
|
||||
}
|
||||
//printf("\n");
|
||||
@@ -2231,7 +2283,7 @@ int testOutMux(int imod) {
|
||||
#ifdef DEBUGOUT
|
||||
printf("%d %x\n",i*dist,val);
|
||||
#endif
|
||||
for (j=0; j<NCHIP; j++) {
|
||||
for (j=0; j<N_CHIP; j++) {
|
||||
v=val & 1<< j;
|
||||
if (pat & (1<<(i*dist))) {
|
||||
if (v==0) {
|
||||
@@ -2259,7 +2311,7 @@ int testOutMux(int imod) {
|
||||
#ifdef DEBUGOUT
|
||||
printf("%d %x\n",i*dist, val);
|
||||
#endif
|
||||
for (j=0; j<NCHIP; j++) {
|
||||
for (j=0; j<N_CHIP; j++) {
|
||||
v=val & 1<< j;
|
||||
if (pat & (1<<(i*dist))) {
|
||||
if (v==0) {
|
||||
@@ -2292,7 +2344,7 @@ int testOutMux(int imod) {
|
||||
#ifdef DEBUGOUT
|
||||
printf("%d %x\n",i*dist, val);
|
||||
#endif
|
||||
for (j=0; j<NCHIP; j++) {
|
||||
for (j=0; j<N_CHIP; j++) {
|
||||
v=val & 1<< j;
|
||||
if (pat & (1<<(i*dist))) {
|
||||
if (v==0) {
|
||||
@@ -2320,7 +2372,7 @@ int testOutMux(int imod) {
|
||||
#ifdef DEBUGOUT
|
||||
printf("%d %x\n",i*dist, val);
|
||||
#endif
|
||||
for (j=0; j<NCHIP; j++) {
|
||||
for (j=0; j<N_CHIP; j++) {
|
||||
v=val & 1<< j;
|
||||
if (pat & (1<<(i*dist))) {
|
||||
if (v==0) {
|
||||
@@ -2488,9 +2540,9 @@ int calibration_sensor(int num, int *v, int *dacs) {
|
||||
selChip(ichip,imod);
|
||||
for (ich=0; ich<128; ich++){
|
||||
selChannel(ich,imod);
|
||||
initChannel(*(dacs+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
initChannel(*(dacs+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
clearCounter(imod);
|
||||
//initChannel(*(dacs+ichip*NCHAN+ich),FALSE,FALSE,TRUE,FALSE,0); //disable channel;
|
||||
//initChannel(*(dacs+ichip*N_CHAN+ich),FALSE,FALSE,TRUE,FALSE,0); //disable channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2498,11 +2550,11 @@ int calibration_sensor(int num, int *v, int *dacs) {
|
||||
for (imod=0; imod<nModX; imod++) {
|
||||
//selMod(imod);
|
||||
initMCBregisters(1,imod);
|
||||
for (ich=0; ich<NCHAN; ich++){
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
for (ich=0; ich<N_CHAN; ich++){
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
selChip(ichip,imod); // select channel
|
||||
selChannel(ich,imod); // select channel
|
||||
initChannel(*(dacs+imod*NCHAN*NCHIP+ichip*NCHAN+ich),0,0,1,0,0,imod); // enable channel
|
||||
initChannel(*(dacs+imod*N_CHAN*N_CHIP+ichip*N_CHAN+ich),0,0,1,0,0,imod); // enable channel
|
||||
clearCounter(imod);
|
||||
}
|
||||
setCSregister(imod);
|
||||
@@ -2516,11 +2568,11 @@ int calibration_sensor(int num, int *v, int *dacs) {
|
||||
}
|
||||
readOutChan(val); // readout channel
|
||||
for (imod=0; imod<nModX; imod++) {
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
*(v+(ichip+imod*NCHIP)*NCHAN+ich)=val[ichip+imod*NCHIP];
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
*(v+(ichip+imod*N_CHIP)*N_CHAN+ich)=val[ichip+imod*N_CHIP];
|
||||
selChip(ichip,imod); // select channel
|
||||
selChannel(ich,imod); // select channel
|
||||
initChannel(*(dacs+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
initChannel(*(dacs+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2542,17 +2594,17 @@ int calibration_chip(int num, int *v, int *dacs) {
|
||||
for (ich=0; ich<128; ich++){
|
||||
selChannel(ich,imod);
|
||||
clearCounter(imod);
|
||||
initChannel(*(dacs+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
initChannel(*(dacs+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ich=0; ich<NCHAN; ich++){
|
||||
for (ich=0; ich<N_CHAN; ich++){
|
||||
for (imod=0; imod<nModX; imod++) {
|
||||
//selMod(imod);
|
||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
||||
for (ichip=0; ichip<N_CHIP; ichip++) {
|
||||
selChip(ichip,imod); // select channel
|
||||
selChannel(ich,imod); // select channel
|
||||
initChannel(*(dacs+imod*NCHAN*NCHIP+ichip*NCHAN+ich),1,0,1,0,0,imod); // enable channel
|
||||
initChannel(*(dacs+imod*N_CHAN*N_CHIP+ichip*N_CHAN+ich),1,0,1,0,0,imod); // enable channel
|
||||
clearCounter(imod);
|
||||
}
|
||||
}
|
||||
@@ -2568,10 +2620,10 @@ int calibration_chip(int num, int *v, int *dacs) {
|
||||
for (imod=0; imod<nModX; imod++) {
|
||||
//selMod(imod);
|
||||
for (ichip=0; ichip<10; ichip++) {
|
||||
*(v+(ichip+imod*NCHIP)*NCHAN+ich)=val[ichip+imod*NCHIP];
|
||||
*(v+(ichip+imod*N_CHIP)*N_CHAN+ich)=val[ichip+imod*N_CHIP];
|
||||
selChip(ichip,imod); // select chip
|
||||
selChannel(ich,imod); // select channel
|
||||
initChannel(*(dacs+imod*NCHAN*NCHIP+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
initChannel(*(dacs+imod*N_CHAN*N_CHIP+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
#define RGSH1VALS {300,200,400}
|
||||
#define RGSH2VALS {260,300,260}
|
||||
|
||||
//high,dynamic,low,medium,very high
|
||||
#define CONF_GAIN {0,0, 0, 1, 6, 2, 1}//dynamic gain confgain yet to be figured out-probably 8 or 16
|
||||
|
||||
|
||||
#define DEFAULTGAIN {11.66,9.32,14.99}
|
||||
#define DEFAULTOFFSET {817.5,828.6,804.2}
|
||||
@@ -107,13 +104,16 @@ int selMod(int mod,int imod );
|
||||
/* int set_one_dac(int imod); */
|
||||
/* int initDAC(int dac_addr, int value,int imod ); */
|
||||
/* int initDACs(int* v,int imod ); */
|
||||
/* int setSettings(int i,int imod); */
|
||||
/* int initDACbyIndex(int ind,int val, int imod); */
|
||||
/* int initDACbyIndexDACU(int ind,int val, int imod); */
|
||||
/* int getDACbyIndexDACU(int ind, int imod); */
|
||||
/* int getThresholdEnergy(); */
|
||||
/* int setThresholdEnergy(int ethr); */
|
||||
|
||||
|
||||
int setSettings(int i,int imod);
|
||||
|
||||
|
||||
/* Other DAC index routines*/
|
||||
int getTemperatureByModule(int tempSensor, int imod);
|
||||
int initHighVoltageByModule(int val, int imod);
|
||||
|
||||
@@ -19,96 +19,21 @@
|
||||
#define FPGA_INIT_PAT 0x60008
|
||||
#define FPGA_INIT_ADDR 0xb0000000
|
||||
|
||||
//#ifdef JUNGFRAU_DHANYA
|
||||
#define POWER_ON_REG 0x5e<<11
|
||||
#define ADCREG1 8 //same as PLL_BANDWIDTH_REG
|
||||
#define ADCREG2 20 //0x14
|
||||
#define ADCREG3 4 //same as PLL_M_COUNTER_REG
|
||||
#define ADCREG4 5 //same as PLL_C_COUNTER_REG
|
||||
#define ADCREG_VREFS 24 //0x18
|
||||
#define DBIT_PIPELINE_REG 89<<11 //0x59 same PATTERN_N_LOOP2_REG
|
||||
#define MEM_MACHINE_FIFOS_REG 79<<11 //0x4f same as CONTROL_REG
|
||||
#define CONFGAIN_REG 93<<11 //0x5d same as DAQ_REG
|
||||
#define ADC_PIPELINE_REG 66<<11 //0x42 same as ADC_OFFSET_REG
|
||||
//#endif
|
||||
|
||||
|
||||
|
||||
/* constant FPGAVersionReg_c : integer:= 0; */
|
||||
/* constant FixedPatternReg_c : integer:= 1; */
|
||||
/* constant StatusReg_c : integer:= 2; */
|
||||
/* constant LookAtMeReg_c : integer:= 3; */
|
||||
/* constant SystemStatusReg_c : integer:= 4; */
|
||||
|
||||
/* constant PLL_ParamOutReg_c : integer:=5; -- RO register to check control signals going to the chip */
|
||||
|
||||
|
||||
/* --time registers use only even numbers! */
|
||||
/* constant TimeFromStartReg_c : integer:= 16; */
|
||||
/* --constant TimeFromStartReg_c : integer:= 17; MSB */
|
||||
/* constant GetDelayReg_c : integer:= 18; */
|
||||
/* --constant GetDelayReg_c : integer:= 19; MSB */
|
||||
/* constant GetCyclesReg_c : integer:= 20; */
|
||||
/* --constant GetTrainsReg_c : integer:= 21; MSB */
|
||||
/* constant GetFramesReg_c : integer:= 22; */
|
||||
/* --constant GetFramesReg_c : integer:= 23; MSB */
|
||||
/* constant GetPeriodReg_c : integer:= 24; */
|
||||
/* --constant GetPeriodReg_c : integer:= 25; MSB */
|
||||
/* constant GetExpTimeReg_c : integer:= 26; */
|
||||
/* --constant GetExpTimeReg_c : integer:= 27; MSB */
|
||||
/* constant GetGatesReg_c : integer:= 28; */
|
||||
/* --constant GetGatesReg_c : integer:= 29; MSB */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* -----rw: */
|
||||
|
||||
/* constant DACReg_c : integer:= 64; */
|
||||
/* constant ADCWriteReg_c : integer:= 65; */
|
||||
/* constant ADCsyncReg_c : integer:= 66; */
|
||||
/* constant HVReg_c : integer:= 67; */
|
||||
/* constant DummyReg_c : integer:= 68; */
|
||||
|
||||
/* constant rx_udpip_AReg_c : integer:= 69; */
|
||||
/* constant udpports_AReg_c : integer:= 70; */
|
||||
/* constant rx_udpmacL_AReg_c : integer:= 71; */
|
||||
/* constant rx_udpmacH_AReg_c : integer:= 72; */
|
||||
/* constant detectormacL_AReg_c : integer:= 73; */
|
||||
/* constant detectormacH_AReg_c : integer:= 74; */
|
||||
/* constant detectorip_AReg_c : integer:= 75; */
|
||||
/* constant ipchksum_AReg_c : integer:= 76; */
|
||||
|
||||
/* constant ConfigReg_c : integer:= 77; */
|
||||
/* constant ExtSignalReg_c : integer:= 78; */
|
||||
/* constant ControlReg_c : integer:= 79; */
|
||||
|
||||
|
||||
|
||||
/* constant PLL_ParamReg_c : integer:= 80; */
|
||||
/* constant PLL_CntrlReg_c : integer:=81; */
|
||||
|
||||
|
||||
|
||||
|
||||
/* --time registers use only even numbers! */
|
||||
/* -- DELAY_AFTER_TRIGGER, */
|
||||
/* constant SetDelayReg_c : integer:= 96; */
|
||||
/* --constant SetDelayReg_c : integer:= 97; MSB */
|
||||
/* -- CYCLES_NUMBER, */
|
||||
/* constant SetCyclesReg_c : integer:= 98; */
|
||||
/* --constant SetCyclesReg_c : integer:= 99;MSB */
|
||||
/* -- FRAME_NUMBER, */
|
||||
/* constant SetFramesReg_c : integer:= 100; */
|
||||
/* --constant SetFramesReg_c : integer:= 101; MSB */
|
||||
/* -- FRAME_PERIOD, */
|
||||
/* constant SetPeriodReg_c : integer:= 102; */
|
||||
/* --constant SetPeriodReg_c : integer:= 103; MSB */
|
||||
/* -- ACQUISITION_TIME, */
|
||||
/* constant SetExpTimeReg_c : integer:= 104; */
|
||||
/* --constant SetExpTimeReg_c : integer:= 105; MSB */
|
||||
/* -- GATES_NUMBER, */
|
||||
/* constant SetGatesReg_c : integer:= 106; */
|
||||
/* --constant SetGatesReg_c : integer:= 107; MSB */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ADC_OFFSET_REG 66<<11 //same as ADC_PIPELINE_REG
|
||||
#define ADC_INVERSION_REG 67<<11
|
||||
|
||||
#define DAC_REG 64<<11//0x17<<11// control the dacs
|
||||
//ADC
|
||||
@@ -116,8 +41,8 @@
|
||||
//#define ADC_SYNC_REG 66<<11//0x19<<11
|
||||
//#define HV_REG 67<<11//0x20<<11
|
||||
|
||||
#define ADC_OFFSET_REG 66<<11
|
||||
#define ADC_INVERSION_REG 67<<11
|
||||
|
||||
|
||||
|
||||
//#define MUTIME_REG 0x1a<<11
|
||||
//temperature
|
||||
@@ -223,17 +148,22 @@
|
||||
#define PLL_CNTRL_REG 81<<11//0x34<<11
|
||||
|
||||
|
||||
#ifdef NEW_GBE_INTERFACE
|
||||
#define GBE_PARAM_OUT_REG 40<<11
|
||||
#define GBE_PARAM_REG 69<<11
|
||||
#define GBE_CNTRL_REG 70<<11
|
||||
#else
|
||||
#define RX_UDP_AREG 69<<11 //rx_udpip_AReg_c : integer:= 69; *\/
|
||||
#define UDPPORTS_AREG 70<<11// udpports_AReg_c : integer:= 70; *\/
|
||||
#define RX_UDPMACL_AREG 71<<11//rx_udpmacL_AReg_c : integer:= 71; *\/
|
||||
#define RX_UDPMACH_AREG 72<<11//rx_udpmacH_AReg_c : integer:= 72; *\/
|
||||
#define DETECTORMACL_AREG 73<<11//detectormacL_AReg_c : integer:= 73; *\/
|
||||
#define DETECTORMACH_AREG 74<<11//detectormacH_AReg_c : integer:= 74; *\/
|
||||
#define DETECTORIP_AREG 75<<11//detectorip_AReg_c : integer:= 75; *\/
|
||||
#define IPCHKSUM_AREG 76<<11//ipchksum_AReg_c : integer:= 76; *\/ */
|
||||
#endif
|
||||
|
||||
|
||||
#define RX_UDP_AREG 69<<11 //rx_udpip_AReg_c : integer:= 69; */
|
||||
#define UDPPORTS_AREG 70<<11// udpports_AReg_c : integer:= 70; */
|
||||
#define RX_UDPMACL_AREG 71<<11//rx_udpmacL_AReg_c : integer:= 71; */
|
||||
#define RX_UDPMACH_AREG 72<<11//rx_udpmacH_AReg_c : integer:= 72; */
|
||||
#define DETECTORMACL_AREG 73<<11//detectormacL_AReg_c : integer:= 73; */
|
||||
#define DETECTORMACH_AREG 74<<11//detectormacH_AReg_c : integer:= 74; */
|
||||
#define DETECTORIP_AREG 75<<11//detectorip_AReg_c : integer:= 75; */
|
||||
#define IPCHKSUM_AREG 76<<11//ipchksum_AReg_c : integer:= 76; */
|
||||
|
||||
#define PATTERN_CNTRL_REG 82<<11
|
||||
#define PATTERN_LIMITS_AREG 83<<11
|
||||
|
||||
@@ -255,6 +185,7 @@
|
||||
#define DAQ_REG 93<<11
|
||||
#define ADC_LATCH_DISABLE_REG 94<<11
|
||||
|
||||
#define HV_REG 95<<11
|
||||
|
||||
#define PATTERN_IOCTRL_REG_LSB 108<<11
|
||||
#define PATTERN_IOCTRL_REG_MSB 109<<11
|
||||
@@ -367,14 +298,16 @@
|
||||
#define READSTATE_0_BIT 0x00000100
|
||||
#define READSTATE_1_BIT 0x00000200
|
||||
#define READSTATE_2_BIT 0x00000400
|
||||
#define PLL_RECONFIG_BUSY 0x00100000
|
||||
#define SOME_FIFO_FULL_BIT 0x00000800 // error!
|
||||
|
||||
#define RUNSTATE_0_BIT 0x00001000
|
||||
#define RUNSTATE_1_BIT 0x00002000
|
||||
#define RUNSTATE_2_BIT 0x00004000
|
||||
#define SOME_FIFO_FULL_BIT 0x00008000 // error!
|
||||
#define STOPPED_BIT 0x00008000 // error!
|
||||
#define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready
|
||||
#define RUNMACHINE_BUSY_BIT 0x00020000
|
||||
#define READMACHINE_BUSY_BIT 0x00040000
|
||||
#define PLL_RECONFIG_BUSY 0x00100000
|
||||
|
||||
|
||||
|
||||
@@ -536,11 +469,43 @@
|
||||
#define PPL_BW_PARAM_DEFAULT 0x2EE0
|
||||
#define PPL_VCO_PARAM_DEFAULT 0x1
|
||||
|
||||
#define NEW_PLL_RECONFIG
|
||||
|
||||
#ifdef NEW_PLL_RECONFIG
|
||||
#define PLL_VCO_FREQ_MHZ 400//480//800
|
||||
#else
|
||||
#define PLL_VCO_FREQ_MHZ 480//800
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
GBE parameter and control registers definitions
|
||||
*/
|
||||
|
||||
#define GBE_CTRL_WSTROBE 0
|
||||
#define GBE_CTRL_VAR_OFFSET 16
|
||||
#define GBE_CTRL_VAR_MASK 0XF
|
||||
#define GBE_CTRL_RAMADDR_OFFSET 24
|
||||
#define GBE_CTRL_RAMADDR_MASK 0X3F
|
||||
#define GBE_CTRL_INTERFACE 23
|
||||
|
||||
#define RX_UDP_IP_ADDR 0
|
||||
#define RX_UDP_PORTS_ADDR 1
|
||||
#define RX_UDP_MAC_L_ADDR 2
|
||||
#define RX_UDP_MAC_H_ADDR 3
|
||||
#define IPCHECKSUM_ADDR 4
|
||||
#define GBE_DELAY_ADDR 5
|
||||
#define GBE_RESERVED1_ADDR 6
|
||||
#define GBE_RESERVED2_ADDR 7
|
||||
#define DETECTOR_MAC_L_ADDR 8
|
||||
#define DETECTOR_MAC_H_ADDR 9
|
||||
#define DETECTOR_IP_ADDR 10
|
||||
|
||||
|
||||
|
||||
/**------------------
|
||||
-- pattern registers definitions
|
||||
--------------------------------------------- */
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "communication_funcs.h"
|
||||
#include "server_funcs.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
extern int sockfd;
|
||||
|
||||
@@ -7,25 +7,30 @@
|
||||
|
||||
|
||||
// Hardware definitions
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD (NMAXMODX*NMAXMODY)
|
||||
|
||||
#define NCHAN 32
|
||||
#define NCHIP 1
|
||||
#define NMAXMODX 1
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD (NMAXMODX*NMAXMODY)
|
||||
#define NDAC 16
|
||||
#define NADC 1
|
||||
#define NDAC 16
|
||||
#define NMAXMODX 1
|
||||
#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 NCHANS (NCHAN*NCHIP*NMAXMOD)
|
||||
#define NDACS (NDAC*NMAXMOD)
|
||||
|
||||
#define NTRIMBITS 6
|
||||
#define NCOUNTBITS 24
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "server_defs.h"
|
||||
#include "firmware_funcs.h"
|
||||
#include "mcb_funcs.h"
|
||||
#include "trimming_funcs.h"
|
||||
#include "registers_m.h"
|
||||
#include "gitInfoMoench.h"
|
||||
|
||||
@@ -56,19 +55,26 @@ extern int withGotthard;
|
||||
|
||||
int adcvpp=0x4;
|
||||
|
||||
/** for jungfrau reinitializing macro later */
|
||||
int N_CHAN=NCHAN;
|
||||
int N_CHIP=NCHIP;
|
||||
int N_DAC=NDAC;
|
||||
int N_ADC=NADC;
|
||||
int N_CHANS=NCHANS;
|
||||
|
||||
|
||||
int init_detector(int b, int checkType) {
|
||||
|
||||
int i;
|
||||
int retvalsize,ret;
|
||||
if (mapCSP0()==FAIL) { printf("Could not map memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
//print version
|
||||
printf("v: 0x%x\n",bus_r(FPGA_VERSION_REG));
|
||||
printf("fp: 0x%x\n",bus_r(FIX_PATT_REG));
|
||||
|
||||
//checktype
|
||||
if (checkType) {
|
||||
printf("Bus test... (checktype is %d; b is %d)",checkType,b );
|
||||
for (i=0; i<1000000; i++) {
|
||||
@@ -80,7 +86,9 @@ int init_detector(int b, int checkType) {
|
||||
printf("Finished\n");
|
||||
}else
|
||||
printf("(checktype is %d; b is %d)",checkType,b );
|
||||
//confirm if it is really moench
|
||||
|
||||
|
||||
//confirm the detector type
|
||||
switch ((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) {
|
||||
case MOENCH03_MODULE_ID:
|
||||
myDetectorType=MOENCH;
|
||||
@@ -100,20 +108,15 @@ int init_detector(int b, int checkType) {
|
||||
default:
|
||||
myDetectorType=GENERIC;
|
||||
printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
printf("Detector type is %d\n", myDetectorType);
|
||||
|
||||
|
||||
// return OK;
|
||||
|
||||
//control server only--
|
||||
if (b) {
|
||||
|
||||
|
||||
resetPLL();
|
||||
|
||||
resetPLL();
|
||||
bus_w16(CONTROL_REG, SYNC_RESET);
|
||||
bus_w16(CONTROL_REG, 0);
|
||||
bus_w16(CONTROL_REG, GB10_RESET_BIT);
|
||||
@@ -121,26 +124,94 @@ int init_detector(int b, int checkType) {
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
|
||||
// initDetector();
|
||||
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
|
||||
|
||||
|
||||
// testFpga();
|
||||
// testRAM();
|
||||
// printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG));
|
||||
//moench specific
|
||||
|
||||
// setPhaseShiftOnce(); //firmware.h
|
||||
|
||||
prepareADC(); // server_funcs
|
||||
// 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
|
||||
|
||||
//Initialization
|
||||
|
||||
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
|
||||
setFrames(-1);
|
||||
setTrains(-1);
|
||||
setExposureTime(-1);
|
||||
@@ -152,14 +223,24 @@ int init_detector(int b, int checkType) {
|
||||
setMaster(GET_MASTER);
|
||||
setSynchronization(GET_SYNCHRONIZATION_MODE);
|
||||
startReceiver(0); //firmware
|
||||
}
|
||||
}//end of control server only--
|
||||
else printf("\n\n");
|
||||
|
||||
|
||||
//common for both control and stop server
|
||||
strcpy(mess,"dummy message");
|
||||
strcpy(lastClientIP,"none");
|
||||
strcpy(thisClientIP,"none1");
|
||||
lockStatus=0;
|
||||
// getDynamicRange();
|
||||
setROI(-1,NULL,&retvalsize,&ret);
|
||||
allocateRAM();
|
||||
|
||||
/* 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();
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -169,7 +250,7 @@ int decode_function(int file_des) {
|
||||
int retval=FAIL;
|
||||
#ifdef VERBOSE
|
||||
printf( "receive data\n");
|
||||
#endif
|
||||
#endif
|
||||
n = receiveDataOnly(file_des,&fnum,sizeof(fnum));
|
||||
if (n <= 0) {
|
||||
#ifdef VERBOSE
|
||||
@@ -182,9 +263,9 @@ int decode_function(int file_des) {
|
||||
printf("size of data received %d\n",n);
|
||||
#endif
|
||||
|
||||
//#ifdef VERBOSE
|
||||
#ifdef VERBOSE
|
||||
printf( "calling function fnum = %d %x %x %x\n",fnum,(unsigned int)(flist[fnum]), (unsigned int)(flist[F_READ_REGISTER]),(unsigned int)(&read_register));
|
||||
//#endif
|
||||
#endif
|
||||
if (fnum<0 || fnum>255)
|
||||
fnum=255;
|
||||
retval=(*flist[fnum])(file_des);
|
||||
@@ -955,14 +1036,13 @@ int read_register(int file_des) {
|
||||
|
||||
int set_dac(int file_des) {
|
||||
//default:all mods
|
||||
int retval, retval1;
|
||||
int retval, retval1;
|
||||
int ret=OK;
|
||||
int arg[3];
|
||||
enum dacIndex ind;
|
||||
int imod;
|
||||
int n;
|
||||
int val;
|
||||
int idac=0;
|
||||
int mV=0;
|
||||
sprintf(mess,"Can't set DAC\n");
|
||||
|
||||
@@ -989,8 +1069,8 @@ int set_dac(int file_des) {
|
||||
if (imod<0)
|
||||
imod=ALLMOD;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
|
||||
@@ -998,8 +1078,7 @@ int set_dac(int file_des) {
|
||||
if (differentClients==1 && lockStatus==1) {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else{
|
||||
|
||||
} else{
|
||||
if (ind<16) {
|
||||
|
||||
if (mV) {
|
||||
@@ -1029,36 +1108,30 @@ int set_dac(int file_des) {
|
||||
}
|
||||
retval=adcvpp;;
|
||||
|
||||
}
|
||||
} else if (ind==HV_NEW )
|
||||
retval=initHighVoltageByModule(val,imod);
|
||||
else
|
||||
printf("**********No dac with index %d\n",ind);
|
||||
}
|
||||
}
|
||||
if(ret==OK){
|
||||
/* ret=FAIL; */
|
||||
/* if(idac==HIGH_VOLTAGE){ */
|
||||
/* if(retval==-2) */
|
||||
/* strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200"); */
|
||||
/* else if(retval==-3) */
|
||||
/* strcpy(mess,"Weird value read back or it has not been set yet\n"); */
|
||||
/* else */
|
||||
/* ret=OK; */
|
||||
/* }//since v r saving only msb */
|
||||
/* else if ((retval-val)<=3 || val==-1) */
|
||||
/* ret=OK; */
|
||||
if (ind<16) {
|
||||
if (mV) {
|
||||
if (ind<16) {
|
||||
if (mV) {
|
||||
|
||||
printf("%d DACu is ",retval);
|
||||
retval1=2500*retval/16535;
|
||||
printf("%d mV \n",retval1);
|
||||
} else
|
||||
printf("%d DACu is ",retval);
|
||||
retval1=2500*retval/16535;
|
||||
printf("%d mV \n",retval1);
|
||||
} else
|
||||
retval1=retval;
|
||||
} else
|
||||
retval1=retval;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("DAC set to %d V\n", retval);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(ret==FAIL)
|
||||
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
|
||||
else{
|
||||
@@ -1178,13 +1251,13 @@ int set_channel(int file_des) {
|
||||
#ifdef VERBOSE
|
||||
printf("channel number is %d, chip number is %d, module number is %d, register is %lld\n", myChan.chan,myChan.chip, myChan.module, myChan.reg);
|
||||
#endif
|
||||
|
||||
|
||||
if (ret==OK) {
|
||||
if (myChan.module>=getNModBoard())
|
||||
ret=FAIL;
|
||||
if (myChan.chip>=NCHIP)
|
||||
if (myChan.chip>=N_CHIP)
|
||||
ret=FAIL;
|
||||
if (myChan.chan>=NCHAN)
|
||||
if (myChan.chan>=N_CHAN)
|
||||
ret=FAIL;
|
||||
if (myChan.module<0)
|
||||
myChan.module=ALLMOD;
|
||||
@@ -1258,13 +1331,13 @@ int get_channel(int file_des) {
|
||||
}
|
||||
if (ret==OK) {
|
||||
ret=FAIL;
|
||||
if (ichip>=0 && ichip<NCHIP) {
|
||||
if (ichip>=0 && ichip<N_CHIP) {
|
||||
ret=OK;
|
||||
}
|
||||
}
|
||||
if (ret==OK) {
|
||||
ret=FAIL;
|
||||
if (ichan>=0 && ichan<NCHAN) {
|
||||
if (ichan>=0 && ichan<N_CHAN) {
|
||||
ret=OK;
|
||||
}
|
||||
}
|
||||
@@ -1304,12 +1377,12 @@ int get_channel(int file_des) {
|
||||
int set_chip(int file_des) {
|
||||
|
||||
sls_detector_chip myChip;
|
||||
int ch[NCHAN];
|
||||
int ch[N_CHAN];
|
||||
int n, retval;
|
||||
int ret=OK;
|
||||
|
||||
|
||||
myChip.nchan=NCHAN;
|
||||
myChip.nchan=N_CHAN;
|
||||
myChip.chanregs=ch;
|
||||
|
||||
|
||||
@@ -1336,7 +1409,7 @@ int set_chip(int file_des) {
|
||||
ret=FAIL;
|
||||
if (myChip.module<0)
|
||||
myChip.module=ALLMOD;
|
||||
if (myChip.chip>=NCHIP)
|
||||
if (myChip.chip>=N_CHIP)
|
||||
ret=FAIL;
|
||||
}
|
||||
if (differentClients==1 && lockStatus==1) {
|
||||
@@ -1392,7 +1465,7 @@ int get_chip(int file_des) {
|
||||
}
|
||||
if (ret==OK) {
|
||||
ret=FAIL;
|
||||
if (ichip>=0 && ichip<NCHIP) {
|
||||
if (ichip>=0 && ichip<N_CHIP) {
|
||||
ret=OK;
|
||||
}
|
||||
}
|
||||
@@ -1430,17 +1503,24 @@ int get_chip(int file_des) {
|
||||
|
||||
}
|
||||
int set_module(int file_des) {
|
||||
sls_detector_module myModule;
|
||||
int *myChip=malloc(NCHIP*sizeof(int));
|
||||
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
|
||||
int *myDac=malloc(NDAC*sizeof(int));/**dhanya*/
|
||||
int *myAdc=malloc(NADC*sizeof(int));/**dhanya*/
|
||||
|
||||
int retval, n;
|
||||
int ret=OK;
|
||||
int dr;// ow;
|
||||
int dr;
|
||||
sls_detector_module myModule;
|
||||
int *myDac=malloc(N_DAC*sizeof(int));
|
||||
int *myAdc=malloc(N_ADC*sizeof(int));
|
||||
int *myChip=NULL;
|
||||
int *myChan=NULL;
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
myChip=malloc(N_CHIP*sizeof(int));
|
||||
myChan=malloc(N_CHIP*N_CHAN*sizeof(int));
|
||||
}
|
||||
|
||||
dr=setDynamicRange(-1);
|
||||
dr=setDynamicRange(-1); /* move this down to after initialization?*/
|
||||
|
||||
//initialize myModule values
|
||||
if (myDac)
|
||||
myModule.dacs=myDac;
|
||||
else {
|
||||
@@ -1448,34 +1528,43 @@ int set_module(int file_des) {
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myAdc)
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
myModule.ndac=NDAC;
|
||||
myModule.nchip=NCHIP;
|
||||
myModule.nchan=NCHAN*NCHIP;
|
||||
myModule.nadc=NADC;
|
||||
|
||||
myModule.chipregs=NULL;
|
||||
myModule.chanregs=NULL;
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
myModule.ndac=N_DAC;
|
||||
myModule.nchip=N_CHIP;
|
||||
myModule.nchan=N_CHAN*N_CHIP;
|
||||
myModule.nadc=N_ADC;
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Setting module\n");
|
||||
#endif
|
||||
ret=receiveModule(file_des, &myModule);
|
||||
#endif
|
||||
|
||||
if(myDetectorType != JUNGFRAU)
|
||||
ret=receiveModuleGeneral(file_des, &myModule, 1); //1 is to receive everything
|
||||
else
|
||||
ret=receiveModuleGeneral(file_des, &myModule, 0); //0 is to receive partially (without trimbits etc.)
|
||||
|
||||
if (ret>=0)
|
||||
ret=OK;
|
||||
@@ -1503,6 +1592,8 @@ int set_module(int file_des) {
|
||||
} else {
|
||||
#ifdef MCB_FUNCS
|
||||
retval=initModulebyNumber(myModule);
|
||||
if(retval != myModule.reg)
|
||||
ret = FAIL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1522,14 +1613,15 @@ int set_module(int file_des) {
|
||||
} else {
|
||||
n += sendDataOnly(file_des,mess,sizeof(mess));
|
||||
}
|
||||
free(myChip);
|
||||
free(myChan);
|
||||
|
||||
free(myDac);
|
||||
free(myAdc);
|
||||
if(myAdc != NULL) free(myAdc);
|
||||
if(myChip != NULL) free(myChip);
|
||||
if(myChan != NULL) free(myChan);
|
||||
|
||||
// setDynamicRange(dr); always 16 commented out
|
||||
|
||||
|
||||
//setDynamicRange(dr); always 16 commented out
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1538,21 +1630,22 @@ int set_module(int file_des) {
|
||||
|
||||
int get_module(int file_des) {
|
||||
|
||||
|
||||
int ret=OK;
|
||||
|
||||
|
||||
int arg;
|
||||
int imod;
|
||||
int n;
|
||||
|
||||
|
||||
|
||||
sls_detector_module myModule;
|
||||
int *myChip=malloc(NCHIP*sizeof(int));
|
||||
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
|
||||
int *myDac=malloc(NDAC*sizeof(int));/**dhanya*/
|
||||
int *myAdc=malloc(NADC*sizeof(int));/**dhanya*/
|
||||
int *myDac=malloc(N_DAC*sizeof(int));
|
||||
int *myChip=NULL;
|
||||
int *myChan=NULL;
|
||||
int *myAdc=NULL;
|
||||
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
myChip=malloc(N_CHIP*sizeof(int));
|
||||
myChan=malloc(N_CHIP*N_CHAN*sizeof(int));
|
||||
myAdc=malloc(N_ADC*sizeof(int));
|
||||
}
|
||||
|
||||
|
||||
if (myDac)
|
||||
@@ -1561,34 +1654,40 @@ int get_module(int file_des) {
|
||||
sprintf(mess,"could not allocate dacs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myAdc)
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
|
||||
|
||||
myModule.adcs=NULL;
|
||||
myModule.chipregs=NULL;
|
||||
myModule.chanregs=NULL;
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
if (myAdc)
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
myModule.ndac=NDAC;
|
||||
myModule.nchip=NCHIP;
|
||||
myModule.nchan=NCHAN*NCHIP;
|
||||
myModule.nadc=NADC;
|
||||
myModule.ndac=N_DAC;
|
||||
myModule.nchip=N_CHIP;
|
||||
myModule.nchan=N_CHAN*N_CHIP;
|
||||
myModule.nadc=N_ADC;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
@@ -1619,17 +1718,18 @@ int get_module(int file_des) {
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret!=FAIL) {
|
||||
/* send return argument */
|
||||
ret=sendModule(file_des, &myModule);
|
||||
if(myDetectorType != JUNGFRAU)
|
||||
ret=sendModuleGeneral(file_des, &myModule,1); //1 is to send everything
|
||||
else
|
||||
ret=sendModuleGeneral(file_des, &myModule,0); //0 is to send partially (without trimbits etc.)
|
||||
} else {
|
||||
n += sendDataOnly(file_des,mess,sizeof(mess));
|
||||
}
|
||||
|
||||
|
||||
|
||||
free(myChip);
|
||||
free(myChan);
|
||||
free(myDac);
|
||||
free(myAdc);
|
||||
if(myChip != NULL) free(myChip);
|
||||
if(myChan != NULL) free(myChan);
|
||||
if(myAdc != NULL) free(myAdc);
|
||||
|
||||
|
||||
/*return ok/fail*/
|
||||
@@ -1854,7 +1954,35 @@ int get_run_status(int file_des) {
|
||||
|
||||
retval= runState();
|
||||
printf("\n\nSTATUS=%08x\n",retval);
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
if(!(retval&RUN_BUSY_BIT)){
|
||||
|
||||
if((retval&READMACHINE_BUSY_BIT) ){
|
||||
printf("-----------------------------------READ MACHINE BUSY--------------------------\n");
|
||||
s=TRANSMITTING;
|
||||
}
|
||||
//and readbusy=0,idle
|
||||
else if((!(retval&0xffff))||(retval==SOME_FIFO_FULL_BIT)){
|
||||
printf("-----------------------------------IDLE--------------------------------------\n");
|
||||
s=IDLE;
|
||||
} else {
|
||||
printf("-----------------------------------Unknown status %08x--------------------------------------\n", retval);
|
||||
s=ERROR;
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
//if runbusy=1
|
||||
else {
|
||||
if (retval&WAITING_FOR_TRIGGER_BIT){
|
||||
printf("-----------------------------------WAITING-----------------------------------\n");
|
||||
s=WAITING;
|
||||
}
|
||||
else{
|
||||
printf("-----------------------------------RUNNING-----------------------------------\n");
|
||||
s=RUNNING;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//error
|
||||
if(retval&SOME_FIFO_FULL_BIT){
|
||||
printf("-----------------------------------ERROR--------------------------------------x%0x\n",retval);
|
||||
@@ -1864,10 +1992,13 @@ int get_run_status(int file_des) {
|
||||
// else if(!(retval&RUNMACHINE_BUSY_BIT)){ //commented by Anna 24.10.2012
|
||||
else if(!(retval&RUN_BUSY_BIT)){ // by Anna 24.10.2012
|
||||
|
||||
if((retval&STOPPED_BIT) ){ //
|
||||
|
||||
|
||||
//and readbusy=1, its last frame read
|
||||
if((retval&READMACHINE_BUSY_BIT) ){ //
|
||||
printf("-----------------------------------STOPPED--------------------------\n");
|
||||
s=STOPPED;
|
||||
} else if((retval&READMACHINE_BUSY_BIT) ){ // ///and readbusy=1, its last frame read
|
||||
|
||||
|
||||
|
||||
printf("-----------------------------------READ MACHINE BUSY--------------------------\n");
|
||||
@@ -1898,9 +2029,9 @@ int get_run_status(int file_des) {
|
||||
printf("-----------------------------------RUNNING-----------------------------------\n");
|
||||
s=RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (ret!=OK) {
|
||||
@@ -1924,14 +2055,12 @@ int get_run_status(int file_des) {
|
||||
|
||||
int read_frame(int file_des) {
|
||||
|
||||
|
||||
int ns=0;
|
||||
u_int16_t* p=NULL;
|
||||
|
||||
|
||||
if (differentClients==1 && lockStatus==1) {
|
||||
dataret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
printf("Warning: %s\n",mess);
|
||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
#ifdef VERBOSE
|
||||
@@ -1940,6 +2069,7 @@ int read_frame(int file_des) {
|
||||
return dataret;
|
||||
|
||||
}
|
||||
|
||||
p=fifo_read_frame();
|
||||
if (p) {
|
||||
nframes++;
|
||||
@@ -1971,6 +2101,10 @@ int read_frame(int file_des) {
|
||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return dataret;
|
||||
|
||||
}
|
||||
@@ -2288,53 +2422,48 @@ int set_roi(int file_des) {
|
||||
int retvalsize=0;
|
||||
ROI arg[MAX_ROIS];
|
||||
ROI* retval=0;
|
||||
int iroi;
|
||||
strcpy(mess,"Could not set/get roi\n");
|
||||
|
||||
|
||||
// u_int32_t disable_reg=0;
|
||||
|
||||
|
||||
n = receiveDataOnly(file_des,&nroi,sizeof(nroi));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
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");
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Not applicable/implemented for this detector\n");
|
||||
printf("Error:Set ROI-%s",mess);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
//#ifdef VERBOSE
|
||||
|
||||
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");
|
||||
//#endif
|
||||
}
|
||||
/* 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2490,7 +2619,6 @@ int set_speed(int file_des) {
|
||||
int set_readout_flags(int file_des) {
|
||||
|
||||
enum readOutFlags arg;
|
||||
int n;
|
||||
int ret=FAIL;
|
||||
|
||||
|
||||
@@ -2785,7 +2913,7 @@ int load_image(int file_des) {
|
||||
int ret=OK;
|
||||
int n;
|
||||
enum imageType index;
|
||||
short int ImageVals[NCHAN*NCHIP];
|
||||
short int ImageVals[N_CHAN*N_CHIP];
|
||||
|
||||
sprintf(mess,"Loading image failed\n");
|
||||
|
||||
@@ -2950,7 +3078,7 @@ int read_counter_block(int file_des) {
|
||||
int n;
|
||||
int startACQ;
|
||||
//char *retval=NULL;
|
||||
short int CounterVals[NCHAN*NCHIP];
|
||||
short int CounterVals[N_CHAN*N_CHIP];
|
||||
|
||||
sprintf(mess,"Read counter block failed\n");
|
||||
|
||||
@@ -3319,7 +3447,6 @@ int write_adc_register(int file_des) {
|
||||
int arg[2];
|
||||
int addr, val;
|
||||
int n;
|
||||
u_int32_t address;
|
||||
|
||||
sprintf(mess,"Can't write to register\n");
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ int set_dynamic_range(int);
|
||||
int set_roi(int);
|
||||
int get_roi(int);
|
||||
int set_speed(int);
|
||||
void prepareADC(void);
|
||||
int set_readout_flags(int);
|
||||
int execute_trimming(int);
|
||||
int lock_server(int);
|
||||
|
||||
@@ -1,749 +0,0 @@
|
||||
#ifndef PICASSOD
|
||||
#include "server_defs.h"
|
||||
#else
|
||||
#include "picasso_defs.h"
|
||||
#endif
|
||||
#include "trimming_funcs.h"
|
||||
#include "mcb_funcs.h"
|
||||
#include "firmware_funcs.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
extern int nModX;
|
||||
//extern int *values;
|
||||
|
||||
extern const int nChans;
|
||||
extern const int nChips;
|
||||
extern const int nDacs;
|
||||
extern const int nAdcs;
|
||||
|
||||
|
||||
int trim_fixed_settings(int countlim, int par2, int im)
|
||||
{
|
||||
|
||||
int retval=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming with fixed settings\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
if (par2<=0)
|
||||
retval=trim_with_level(countlim, im);
|
||||
else
|
||||
retval=trim_with_median(countlim,im);
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int trim_with_noise(int countlim, int nsigma, int im)
|
||||
{
|
||||
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming using noise\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
/* threshold scan */
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma, im);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("trimming with noise.....\n");
|
||||
#endif
|
||||
retval2=trim_with_level(countlim, im);
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int trim_with_beam(int countlim, int nsigma, int im) //rpc
|
||||
{
|
||||
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
|
||||
printf("Trimming using beam\n");
|
||||
//return OK;
|
||||
#ifdef VIRTUAL
|
||||
printf("Trimming using beam\n");
|
||||
return OK;
|
||||
#endif
|
||||
/* threshold scan */
|
||||
#ifdef DEBUGOUT
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma,im);
|
||||
retval2=trim_with_median(TRIM_DR, im);
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int trim_improve(int maxit, int par2, int im) //rpc
|
||||
{
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Improve the trimming\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
|
||||
if (par2!=0 && im==ALLMOD)
|
||||
retval1=choose_vthresh();
|
||||
|
||||
retval2=trim_with_median(2*maxit+1, im);
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int calcthr_from_vcal(int vcal) {
|
||||
int thrmin;
|
||||
//thrmin=140+3*vcal/5;
|
||||
thrmin=180+3*vcal/5;
|
||||
return thrmin;
|
||||
}
|
||||
|
||||
int calccal_from_vthr(int vthr) {
|
||||
int vcal;
|
||||
vcal=5*(vthr-140)/3;
|
||||
return vcal;
|
||||
}
|
||||
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int modma, modmi, nm;
|
||||
int thr, thrstep=5, nthr=31;
|
||||
|
||||
int *fifodata;
|
||||
|
||||
double vthreshmean, vthreshSTDev;
|
||||
int *thrmi, *thrma;
|
||||
double c;
|
||||
double b=BVTRIM;
|
||||
double a=AVTRIM;
|
||||
int *trim;
|
||||
int ich, imod, ichan;
|
||||
int nvalid=0;
|
||||
u_int32_t *scan;
|
||||
int ithr;
|
||||
sls_detector_channel myChan;
|
||||
|
||||
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
trim=malloc(sizeof(int)*nChans*nChips*nModX);
|
||||
thrmi=malloc(sizeof(int)*nModX);
|
||||
thrma=malloc(sizeof(int)*nModX);
|
||||
|
||||
|
||||
for (ich=0; ich<nChans*nChips*nm; ich++)
|
||||
trim[ich]=-1;
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
counterClear(im);
|
||||
clearSSregister(im);
|
||||
usleep(500);
|
||||
*/
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE;
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
|
||||
for (ithr=0; ithr<nthr; ithr++) {
|
||||
fifoReset();
|
||||
/* scanning threshold */
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
//commented out by dhanya thr=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if (ithr==0) {
|
||||
thrmi[imod]=thr;
|
||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
} else
|
||||
;//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr+thrstep,imod);
|
||||
}
|
||||
|
||||
/* setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChips*nChans+ichan;
|
||||
if (scan[ich]>countlim && trim[ich]==-1) {
|
||||
//commented out by dhanya trim[ich]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
#ifdef VERBOSE
|
||||
// printf("yes: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
#endif
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else {
|
||||
printf("no: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
vthreshmean=0;
|
||||
vthreshSTDev=0;
|
||||
nvalid=0;
|
||||
//commented out by dhanya thrma[imod]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChans*nChips+ichan;
|
||||
if(trim[ich]>thrmi[imod] && trim[ich]<thrma[imod]) {
|
||||
vthreshmean=vthreshmean+trim[ich];
|
||||
vthreshSTDev=vthreshSTDev+trim[ich]*trim[ich];
|
||||
nvalid++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nvalid>0) {
|
||||
vthreshmean=vthreshmean/nvalid;
|
||||
//commented out by dhanya vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean);
|
||||
} else {
|
||||
vthreshmean=thrmi[imod];
|
||||
vthreshSTDev=nthr*thrstep;
|
||||
printf("No valid channel for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev);
|
||||
#endif
|
||||
// *vthresh=round(vthreshmean-nsigma*vthreshSTDev);
|
||||
thr=(int)(vthreshmean-nsigma*vthreshSTDev);
|
||||
if (thr<0 || thr>(DAC_DR-1)) {
|
||||
thr=thrmi[imod]/2;
|
||||
printf("Can't find correct threshold for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
#ifdef VERBOSE
|
||||
printf("vthresh=%d \n",thr);
|
||||
#endif
|
||||
c=CVTRIM-2.*nsigma*vthreshSTDev/63.;
|
||||
//commented out by dhanya thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a));
|
||||
if (thr<500 || thr>(DAC_DR-1)) {
|
||||
thr=750;
|
||||
printf("Can't find correct trimbit size for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
//commented out by dhanya initDACbyIndexDACU(VTRIM,thr,imod);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("vtrim=%d \n",thr);
|
||||
#endif
|
||||
|
||||
}
|
||||
free(trim);
|
||||
free(thrmi);
|
||||
free(thrma);
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_level(int countlim, int im) {
|
||||
int ich, itrim, ichan, ichip, imod;
|
||||
u_int32_t *scan;
|
||||
int *inttrim;
|
||||
int modma, modmi, nm;
|
||||
int retval=OK;
|
||||
int *fifodata;
|
||||
sls_detector_channel myChan;
|
||||
printf("trimming module number %d", im);
|
||||
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
inttrim=malloc(sizeof(int)*nChips*nChans*nModX);
|
||||
printf("countlim=%d\n",countlim);
|
||||
for (ich=0; ich<nChans*nChips*nModX; ich++)
|
||||
inttrim[ich]=-1;
|
||||
|
||||
for (itrim=0; itrim<TRIM_DR+1; itrim++) {
|
||||
fifoReset();
|
||||
printf("Trimbit %d\n",itrim);
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE|(itrim<<TRIMBIT_OFF);
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(itrim,0,0,1,0,0,ALLMOD);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++) {
|
||||
ich=ichan+imod*nChans*nChips;
|
||||
if (inttrim[ich]==-1) {
|
||||
if (scan[ich]>countlim){
|
||||
inttrim[ich]=itrim;
|
||||
if (scan[ich]>2*countlim && itrim>0) {
|
||||
//if (scan[ich]>2*countlim || itrim==0) {
|
||||
inttrim[ich]=itrim-1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else
|
||||
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
clearCSregister(imod);
|
||||
firstChip(im);
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
clearSSregister(imod);
|
||||
for (ichan=0; ichan<nChans; ichan++) {
|
||||
nextStrip(imod);
|
||||
ich=ichan+imod*nChans*nChips+ichip*nChans;
|
||||
if (*(inttrim+ich)==-1) {
|
||||
*(inttrim+ich)=TRIM_DR;
|
||||
// printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
|
||||
retval=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
// else
|
||||
// printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
|
||||
#endif
|
||||
initChannel(inttrim[ich],0,0,1,0,0,imod);
|
||||
}
|
||||
nextChip(imod);
|
||||
}
|
||||
}
|
||||
free(inttrim);
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
|
||||
#define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
|
||||
|
||||
|
||||
int kth_smallest(int *a, int n, int k)
|
||||
{
|
||||
register int i,j,l,m ;
|
||||
register double x ;
|
||||
|
||||
l=0 ; m=n-1 ;
|
||||
while (l<m) {
|
||||
x=a[k] ;
|
||||
i=l ;
|
||||
j=m ;
|
||||
do {
|
||||
while (a[i]<x) i++ ;
|
||||
while (x<a[j]) j-- ;
|
||||
if (i<=j) {
|
||||
ELEM_SWAP(a[i],a[j]) ;
|
||||
i++ ; j-- ;
|
||||
}
|
||||
} while (i<=j) ;
|
||||
if (j<k) l=i ;
|
||||
if (k<i) m=j ;
|
||||
}
|
||||
return a[k] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ave(int *a, int n)
|
||||
{
|
||||
int av=0,i;
|
||||
for (i=0; i<n; i++)
|
||||
av=av+((double)*(a+i))/((double)n);
|
||||
return av;
|
||||
}
|
||||
|
||||
|
||||
int choose_vthresh() {
|
||||
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int imod, ichan;
|
||||
u_int32_t *scan, *scan1;
|
||||
int olddiff[nModX], direction[nModX];
|
||||
int med[nModX], med1[nModX], diff, media;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int maxiterations=10;
|
||||
int vthreshmean=0;
|
||||
int vthresh;
|
||||
int im=ALLMOD;
|
||||
int modma, modmi, nm;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
|
||||
|
||||
setDynamicRange(32);
|
||||
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
//printf(".");
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
//
|
||||
med[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
//commented out by dhanya vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
|
||||
olddiff[imod]=0xffffff;
|
||||
direction[imod]=0;
|
||||
printf("Median of module %d=%d\n",imod,med[imod]);
|
||||
}
|
||||
vthreshmean=vthreshmean/nm;
|
||||
//media=median(scan,nChans*nChips*nModX);
|
||||
//printf("Median overall=%d\n",media);
|
||||
media=median(med1+modmi,nm);
|
||||
printf("Median of modules=%d\n",media);
|
||||
free(scan);
|
||||
free(scan1);
|
||||
|
||||
|
||||
while(change_flag && iteration<maxiterations) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
change_flag=0;
|
||||
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
|
||||
for (ichan=modmi; ichan<modma; ichan++) {
|
||||
med[ichan]=median(scan1+ichan*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
media=median(med1+modmi,nm);
|
||||
|
||||
diff=med[ichan]-media;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0)
|
||||
direction[ichan]=1;
|
||||
else
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
//commented out by dhanya vthresh=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
vthresh=vthresh-direction[ichan];
|
||||
if (vthresh>(DAC_DR-1)) {
|
||||
vthresh=(DAC_DR-1);
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (vthresh<0) {
|
||||
vthresh=0;
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
vthresh=vthresh+direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
//commented out by dhanya initDACbyIndex(VTHRESH,vthresh, ichan);
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_median(int stop, int im) {
|
||||
|
||||
|
||||
int retval=OK;
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
int ichan, imod, ichip, ich;
|
||||
u_int32_t *scan, *scan1;
|
||||
int *olddiff, *direction;
|
||||
int med, diff;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int me[nModX], me1[nModX];
|
||||
int modma, modmi, nm;
|
||||
int trim;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
olddiff=malloc(4*nModX*nChips*nChans);
|
||||
direction=malloc(4*nModX*nChips*nChans);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
direction[ichan]=0;
|
||||
olddiff[ichan]=0x0fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
/********
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
scan=decode_data(fifo_read_event());
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me,nm);
|
||||
printf("median is %d\n",med);
|
||||
free(scan);
|
||||
**************/
|
||||
while(change_flag && iteration<stop) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
|
||||
/********* calculates median every time ***********/
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
me1[imod]=me[imod];
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me1,nm);
|
||||
printf("median is %d\n",med);
|
||||
|
||||
change_flag=0;
|
||||
printf("Trimbits iteration %d of %d\n",iteration, stop);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
selChip(ichip,imod);
|
||||
clearSSregister(imod);
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
nextStrip(imod);
|
||||
diff=scan[ichan]-me[imod];
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0) {
|
||||
direction[ichan]=1;
|
||||
} else {
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
}
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
|
||||
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
if (trim>TRIM_DR) {
|
||||
trim=63;
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (trim<0) {
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
trim=0;
|
||||
retval=FAIL;
|
||||
}
|
||||
initChannel(trim,0,0,1,0,0,imod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
free(olddiff);
|
||||
free(direction);
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef TRIMMING_FUNCS_H
|
||||
#define TRIMMING_FUNCS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
int trim_fixed_settings(int countlim, int par2, int imod);
|
||||
int trim_with_noise(int countlim, int nsigma, int imod);
|
||||
int trim_with_beam(int countlim, int nsigma, int imod);
|
||||
int trim_improve(int maxit, int par2, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod);
|
||||
|
||||
int choose_vthresh();
|
||||
int trim_with_level(int countlim, int imod);
|
||||
int trim_with_median(int stop, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
|
||||
#endif
|
||||
@@ -1143,6 +1143,7 @@ slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings
|
||||
|
||||
}
|
||||
thisMultiDetector->currentSettings=ret1;
|
||||
|
||||
return ret1;
|
||||
|
||||
}
|
||||
@@ -1255,6 +1256,7 @@ int multiSlsDetector::stopAcquisition(){
|
||||
}
|
||||
}
|
||||
*stoppedFlag=1;
|
||||
setAcquiringFlag(false);
|
||||
return ret1;
|
||||
|
||||
|
||||
@@ -1628,6 +1630,15 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){
|
||||
|
||||
thisMultiDetector->timerValue[index]=ret1;
|
||||
|
||||
|
||||
if (getDetectorsType() == EIGER) {
|
||||
//if subexptime set, update rate correction in server and update result in multi client
|
||||
double r;
|
||||
if((index == SUBFRAME_ACQUISITION_TIME) && (t>=0) && getRateCorrection(r)){
|
||||
setRateCorrection(r);
|
||||
}
|
||||
}
|
||||
|
||||
return ret1;
|
||||
};
|
||||
|
||||
@@ -2413,36 +2424,55 @@ int multiSlsDetector::flatFieldCorrect(double* datain, double *errin, double* da
|
||||
|
||||
|
||||
int multiSlsDetector::setRateCorrection(double t){
|
||||
// double tdead[]=defaultTDead;
|
||||
// double tdead[]=defaultTDead;
|
||||
|
||||
if (t==0) {
|
||||
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
} else {
|
||||
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
|
||||
if (detectors[idet]) {
|
||||
detectors[idet]->setRateCorrection(t);
|
||||
if(detectors[idet]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<idet));
|
||||
}
|
||||
}
|
||||
if (getDetectorsType() == MYTHEN){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
#endif
|
||||
}
|
||||
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
if (t==0) {
|
||||
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
} else
|
||||
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
}
|
||||
|
||||
|
||||
int ret, ret1=-100;
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
ret=detectors[idet]->setRateCorrection(t);
|
||||
if(detectors[idet]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<idet));
|
||||
if (ret1==-100)
|
||||
ret1=ret;
|
||||
else if (ret!=ret1)
|
||||
ret1=-1;
|
||||
}
|
||||
}
|
||||
|
||||
if (getDetectorsType() != MYTHEN){
|
||||
if (ret1==0)
|
||||
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
else
|
||||
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
}
|
||||
|
||||
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::getRateCorrection(double &t){
|
||||
|
||||
if (getDetectorsType() != MYTHEN){
|
||||
t = getRateCorrectionTau();
|
||||
return getRateCorrection();
|
||||
}
|
||||
|
||||
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
#endif
|
||||
//which t should we return if they are all different?
|
||||
return 1;
|
||||
} else
|
||||
t=0;
|
||||
@@ -2455,21 +2485,35 @@ int multiSlsDetector::getRateCorrection(double &t){
|
||||
double multiSlsDetector::getRateCorrectionTau(){
|
||||
|
||||
double ret1=-100,ret;
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
ret=detectors[idet]->getRateCorrectionTau();
|
||||
if (ret1==-100)
|
||||
ret1=ret;
|
||||
else if (ret!=ret1){
|
||||
std::cout<< "Rate correction is different for different readouts " << std::endl;
|
||||
if(getDetectorsType() == EIGER)
|
||||
ret1=-2;
|
||||
else
|
||||
ret1=-1; //same settings also return -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getDetectorsType() != MYTHEN){
|
||||
//if set by the slsDetector
|
||||
if(ret1 == 0)
|
||||
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
else
|
||||
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
return ret1;
|
||||
}
|
||||
|
||||
//only mythen
|
||||
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
#endif
|
||||
//which t should we return if they are all different?
|
||||
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
ret=detectors[idet]->getRateCorrectionTau();
|
||||
if (ret1==-100)
|
||||
ret1=ret;
|
||||
else if (ret!=ret1)
|
||||
ret1=-1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Rate correction is disabled " << std::endl;
|
||||
@@ -4617,7 +4661,6 @@ int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex
|
||||
acquisitionIndex = -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int n,complete=OK;
|
||||
int i,k,offsetX, offsetY, maxX, maxY; double dr;
|
||||
int* retval=new int[nel];
|
||||
|
||||
@@ -72,6 +72,14 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
ng=0;
|
||||
no=0;
|
||||
break;
|
||||
case JUNGFRAU:
|
||||
nch=256*256;
|
||||
nm=1; //modules/detector
|
||||
nc=8; //chips
|
||||
nd=16; //dacs+adcs
|
||||
ng=0;
|
||||
no=0;
|
||||
break;
|
||||
case JUNGFRAUCTB:
|
||||
nch=32;
|
||||
nm=1; //modules/detector
|
||||
@@ -612,6 +620,19 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
thisDetector->nModMax[Y]=1;
|
||||
thisDetector->dynamicRange=16;
|
||||
break;
|
||||
case JUNGFRAU:
|
||||
thisDetector->nChan[X]=256;
|
||||
thisDetector->nChan[Y]=256;
|
||||
thisDetector->nChip[X]=4;
|
||||
thisDetector->nChip[Y]=2;
|
||||
thisDetector->nDacs=16;
|
||||
thisDetector->nAdcs=0;
|
||||
thisDetector->nGain=0;
|
||||
thisDetector->nOffset=0;
|
||||
thisDetector->nModMax[X]=1;
|
||||
thisDetector->nModMax[Y]=1;
|
||||
thisDetector->dynamicRange=16;
|
||||
break;
|
||||
case JUNGFRAUCTB:
|
||||
thisDetector->nChan[X]=32;
|
||||
thisDetector->nChan[Y]=1;
|
||||
@@ -837,6 +858,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
setFramesPerFile(MAX_FRAMES_PER_FILE);
|
||||
if (thisDetector->myDetectorType==MOENCH)
|
||||
setFramesPerFile(MOENCH_MAX_FRAMES_PER_FILE);
|
||||
if (thisDetector->myDetectorType==JUNGFRAU)
|
||||
setFramesPerFile(JFRAU_MAX_FRAMES_PER_FILE);
|
||||
if (thisDetector->myDetectorType==JUNGFRAUCTB)
|
||||
setFramesPerFile(JFCTB_MAX_FRAMES_PER_FILE);
|
||||
thisReceiver = new receiverInterface(dataSocket);
|
||||
@@ -972,6 +995,13 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t)
|
||||
nd=8; //dacs
|
||||
na=1;
|
||||
break;
|
||||
case JUNGFRAU:
|
||||
nch=256*256;//32;
|
||||
nm=1;
|
||||
nc=4*2;
|
||||
nd=16; // dacs+adcs
|
||||
na=0;
|
||||
break;
|
||||
case JUNGFRAUCTB:
|
||||
nch=32;//32;
|
||||
nm=1;
|
||||
@@ -1054,16 +1084,20 @@ int slsDetector::sendModule(sls_detector_module *myMod) {
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->reg),sizeof(myMod->reg));
|
||||
ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(myMod->ndac));
|
||||
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(myMod->nadc));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(myMod->nchip));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(myMod->nchan));
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->gain), sizeof(myMod->gain));
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->offset), sizeof(myMod->offset));
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(myMod->nchip));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(myMod->nchan));
|
||||
}
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->gain),sizeof(myMod->gain));
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->offset), sizeof(myMod->offset));
|
||||
ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
|
||||
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
@@ -1118,16 +1152,19 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
|
||||
ts+=controlSocket->ReceiveDataOnly(&(myMod->reg),sizeof(myMod->reg));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(myMod->ndac));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(myMod->nadc));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(myMod->nchip));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(myMod->nchan));
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(myMod->nchip));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(myMod->nchan));
|
||||
}
|
||||
ts+=controlSocket->ReceiveDataOnly(&(myMod->gain), sizeof(myMod->gain));
|
||||
ts+=controlSocket->ReceiveDataOnly(&(myMod->offset), sizeof(myMod->offset));
|
||||
|
||||
|
||||
myMod->dacs=dacptr;
|
||||
myMod->adcs=adcptr;
|
||||
myMod->chipregs=chipptr;
|
||||
myMod->chanregs=chanptr;
|
||||
myMod->dacs=dacptr;
|
||||
myMod->adcs=adcptr;
|
||||
myMod->chipregs=chipptr;
|
||||
myMod->chanregs=chanptr;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << std::endl;
|
||||
@@ -1140,17 +1177,20 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received adcs " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received chips " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips;
|
||||
std::cout<< "mod - nchans= " << myMod->nchan << " nchips= " <<myMod->nchip;
|
||||
|
||||
std::cout<< "received chans " << myMod->module << " of size "<< ts << std::endl;
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received chips " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips;
|
||||
std::cout<< "mod - nchans= " << myMod->nchan << " nchips= " <<myMod->nchip;
|
||||
std::cout<< "received chans " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << std::endl;
|
||||
#endif
|
||||
@@ -2176,6 +2216,11 @@ dacs_t slsDetector::setDAC(dacs_t val, dacIndex index, int mV, int imod){
|
||||
int ret=FAIL;
|
||||
char mess[100];
|
||||
int arg[3];
|
||||
|
||||
|
||||
if ( (thisDetector->myDetectorType != GOTTHARD) && (thisDetector->myDetectorType != PROPIX) && index==HV_POT)
|
||||
index=HV_NEW;
|
||||
|
||||
arg[0]=index;
|
||||
arg[1]=imod;
|
||||
arg[2]=mV;
|
||||
@@ -2618,6 +2663,7 @@ int slsDetector::setModule(int reg, int imod){
|
||||
sls_detector_module myModule;
|
||||
int* g=0;
|
||||
int* o=0;
|
||||
int* iod=0;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "slsDetector set module " << std::endl;
|
||||
@@ -2686,14 +2732,14 @@ int slsDetector::setModule(int reg, int imod){
|
||||
ads[i]=-1;
|
||||
myModule.adcs=ads;
|
||||
}
|
||||
ret=setModule(myModule,g,o);
|
||||
ret=setModule(myModule,g,o,iod);
|
||||
}
|
||||
return ret;
|
||||
|
||||
|
||||
};
|
||||
|
||||
int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval){
|
||||
int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval, int* iodelay){
|
||||
|
||||
int fnum=F_SET_MODULE;
|
||||
int retval;
|
||||
@@ -2717,6 +2763,8 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
|
||||
controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain);
|
||||
if((thisDetector->nOffset) && (offsetval))
|
||||
controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset);
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
controlSocket->SendDataOnly(iodelay,sizeof(int));
|
||||
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL) {
|
||||
@@ -2731,6 +2779,13 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
|
||||
}
|
||||
}
|
||||
|
||||
if(ret == FAIL && thisDetector->myDetectorType == EIGER && strcasestr(mess,"Rate")){
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
|
||||
if(strcasestr(mess,"tau/subexptime"))
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE));
|
||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
thisDetector->tDead = 0;
|
||||
}
|
||||
|
||||
if (ret!=FAIL) {
|
||||
if (detectorModules) {
|
||||
@@ -2744,24 +2799,27 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
|
||||
thisDetector->nDacs=module.ndac;
|
||||
thisDetector->nAdcs=module.nadc;
|
||||
|
||||
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
|
||||
if (chipregs)
|
||||
chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip];
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
|
||||
if (chipregs)
|
||||
chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip];
|
||||
|
||||
if (chanregs) {
|
||||
for (int i=0; i<thisDetector->nChans; i++) {
|
||||
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i];
|
||||
}
|
||||
}
|
||||
if (chanregs) {
|
||||
for (int i=0; i<thisDetector->nChans; i++) {
|
||||
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (adcs) {
|
||||
for (int i=0; i<thisDetector->nAdcs; i++)
|
||||
adcs[i+imod*thisDetector->nAdcs]=module.adcs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (dacs) {
|
||||
for (int i=0; i<thisDetector->nDacs; i++)
|
||||
dacs[i+imod*thisDetector->nDacs]=module.dacs[i];
|
||||
}
|
||||
if (adcs) {
|
||||
for (int i=0; i<thisDetector->nAdcs; i++)
|
||||
adcs[i+imod*thisDetector->nAdcs]=module.adcs[i];
|
||||
}
|
||||
|
||||
(detectorModules+imod)->gain=module.gain;
|
||||
(detectorModules+imod)->offset=module.offset;
|
||||
@@ -2869,25 +2927,28 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){
|
||||
thisDetector->nDacs=myMod->ndac;
|
||||
thisDetector->nAdcs=myMod->nadc;
|
||||
|
||||
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
|
||||
if (chipregs)
|
||||
chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip];
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
|
||||
if (chipregs)
|
||||
chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip];
|
||||
|
||||
if (chanregs) {
|
||||
for (int i=0; i<thisDetector->nChans; i++) {
|
||||
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i];
|
||||
if (chanregs) {
|
||||
for (int i=0; i<thisDetector->nChans; i++) {
|
||||
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (adcs) {
|
||||
for (int i=0; i<thisDetector->nAdcs; i++)
|
||||
adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (dacs) {
|
||||
for (int i=0; i<thisDetector->nDacs; i++)
|
||||
dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i];
|
||||
}
|
||||
if (adcs) {
|
||||
for (int i=0; i<thisDetector->nAdcs; i++)
|
||||
adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i];
|
||||
}
|
||||
|
||||
(detectorModules+imod)->gain=myMod->gain;
|
||||
(detectorModules+imod)->offset=myMod->offset;
|
||||
(detectorModules+imod)->serialnumber=myMod->serialnumber;
|
||||
@@ -3063,10 +3124,13 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
string ssettings;
|
||||
|
||||
int* gainval=0, *offsetval=0;
|
||||
int* iodelay=0;
|
||||
if(thisDetector->nGain)
|
||||
gainval=new int[thisDetector->nGain];
|
||||
if(thisDetector->nOffset)
|
||||
offsetval=new int[thisDetector->nOffset];
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
iodelay = new int;
|
||||
|
||||
int ret=0;
|
||||
|
||||
@@ -3098,6 +3162,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
case DYNAMICGAIN:
|
||||
if ((thisDetector->myDetectorType == GOTTHARD) ||
|
||||
(thisDetector->myDetectorType == PROPIX) ||
|
||||
(thisDetector->myDetectorType == JUNGFRAU) ||
|
||||
(thisDetector->myDetectorType == MOENCH)) {
|
||||
ssettings="/dynamicgain";
|
||||
thisDetector->currentSettings=DYNAMICGAIN;
|
||||
@@ -3130,6 +3195,36 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
break;
|
||||
case LOWNOISE:
|
||||
break;
|
||||
case DYNAMICHG0:
|
||||
if (thisDetector->myDetectorType == JUNGFRAU) {
|
||||
ssettings="/dynamichg0";
|
||||
thisDetector->currentSettings=DYNAMICHG0;
|
||||
}
|
||||
break;
|
||||
case FIXGAIN1:
|
||||
if (thisDetector->myDetectorType == JUNGFRAU) {
|
||||
ssettings="/fixgain1";
|
||||
thisDetector->currentSettings=FIXGAIN1;
|
||||
}
|
||||
break;
|
||||
case FIXGAIN2:
|
||||
if (thisDetector->myDetectorType == JUNGFRAU) {
|
||||
ssettings="/fixgain2";
|
||||
thisDetector->currentSettings=FIXGAIN2;
|
||||
}
|
||||
break;
|
||||
case FORCESWITCHG1:
|
||||
if (thisDetector->myDetectorType == JUNGFRAU) {
|
||||
ssettings="/forceswitchg1";
|
||||
thisDetector->currentSettings=FORCESWITCHG1;
|
||||
}
|
||||
break;
|
||||
case FORCESWITCHG2:
|
||||
if (thisDetector->myDetectorType == JUNGFRAU) {
|
||||
ssettings="/forceswitchg2";
|
||||
thisDetector->currentSettings=FORCESWITCHG2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -3164,6 +3259,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
case MOENCH:
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case JUNGFRAU:
|
||||
case JUNGFRAUCTB:
|
||||
//settings is saved in myMod.reg
|
||||
myMod->reg=thisDetector->currentSettings;
|
||||
@@ -3184,13 +3280,14 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
#ifdef VERBOSE
|
||||
cout << "the settings file name is "<<settingsfname << endl;
|
||||
#endif
|
||||
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) {
|
||||
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) {
|
||||
//if it didnt open, try default settings file
|
||||
ostringstream ostfn_default;
|
||||
switch(thisDetector->myDetectorType){
|
||||
case MOENCH:
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case JUNGFRAU:
|
||||
case JUNGFRAUCTB:
|
||||
ostfn_default << thisDetector->settingsDir << ssettings << ssettings << ".settings";
|
||||
break;
|
||||
@@ -3203,7 +3300,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
#ifdef VERBOSE
|
||||
cout << settingsfname << endl;
|
||||
#endif
|
||||
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) {
|
||||
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) {
|
||||
//if default doesnt work, return error
|
||||
std::cout << "Could not open settings file" << endl;
|
||||
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
||||
@@ -3248,7 +3345,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
}
|
||||
|
||||
//if everything worked, set module****
|
||||
setModule(*myMod,gainval,offsetval);
|
||||
setModule(*myMod,gainval,offsetval,iodelay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3342,6 +3439,7 @@ int slsDetector::updateDetectorNoWait() {
|
||||
|
||||
if((thisDetector->myDetectorType!= GOTTHARD)&&
|
||||
(thisDetector->myDetectorType!= PROPIX)&&
|
||||
(thisDetector->myDetectorType!= JUNGFRAU)&&
|
||||
(thisDetector->myDetectorType!= MOENCH)){
|
||||
//thr=getThresholdEnergy();
|
||||
n = controlSocket->ReceiveDataOnly( &thr,sizeof(thr));
|
||||
@@ -3600,7 +3698,7 @@ int* slsDetector::getDataFromDetector(int *retval){
|
||||
std::cout<< "Received "<< n << " data bytes" << std::endl;
|
||||
#endif
|
||||
if (n!=thisDetector->dataBytes) {
|
||||
std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
|
||||
std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
|
||||
thisDetector->stoppedFlag=1;
|
||||
ret=FAIL;
|
||||
if (r==NULL) {
|
||||
@@ -3779,123 +3877,120 @@ int slsDetector::startAndReadAllNoWait(){
|
||||
int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
|
||||
|
||||
int fnum=F_SET_TIMER,fnum2=F_SET_RECEIVER_TIMER;
|
||||
int64_t retval = -1;
|
||||
int64_t ut = -2;
|
||||
char mess[100];
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
int fnum=F_SET_TIMER,fnum2=F_SET_RECEIVER_TIMER;
|
||||
int64_t retval = -1;
|
||||
int64_t ut = -2;
|
||||
char mess[100];
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
|
||||
if (index!=MEASUREMENTS_NUMBER) {
|
||||
if (index!=MEASUREMENTS_NUMBER) {
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl;
|
||||
std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl;
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&index,sizeof(index));
|
||||
n=controlSocket->SendDataOnly(&t,sizeof(t));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(DETECTOR_TIMER_VALUE_NOT_SET));
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&index,sizeof(index));
|
||||
n=controlSocket->SendDataOnly(&t,sizeof(t));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(DETECTOR_TIMER_VALUE_NOT_SET));
|
||||
} else {
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
thisDetector->timerValue[index]=retval;
|
||||
}
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE) {
|
||||
updateDetector();
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Updated!" << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//std::cout<< "offline " << std::endl;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
thisDetector->timerValue[index]=retval;
|
||||
if (t>=0)
|
||||
thisDetector->timerValue[index]=t;
|
||||
}
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE) {
|
||||
updateDetector();
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Updated!" << std::endl;
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//std::cout<< "offline " << std::endl;
|
||||
if (t>=0)
|
||||
thisDetector->timerValue[index]=t;
|
||||
if((thisDetector->myDetectorType==GOTTHARD)||
|
||||
(thisDetector->myDetectorType==PROPIX)||
|
||||
(thisDetector->myDetectorType==MOENCH))
|
||||
thisDetector->timerValue[PROBES_NUMBER]=0;
|
||||
}
|
||||
} else {
|
||||
if (t>=0)
|
||||
thisDetector->timerValue[index]=t;
|
||||
}
|
||||
|
||||
/* set progress */
|
||||
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
|
||||
setTotalProgress();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//send acquisiton period/frame number to receiver
|
||||
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){
|
||||
if(ret != FAIL){
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
int64_t args[2];
|
||||
args[1] = retval;
|
||||
if(t == -1) args[1] = -1;
|
||||
|
||||
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
|
||||
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
|
||||
#endif
|
||||
|
||||
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
|
||||
setDynamicRange();
|
||||
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
|
||||
}
|
||||
|
||||
/* set progress */
|
||||
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
|
||||
setTotalProgress();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//send acquisiton period/frame number to receiver
|
||||
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD))
|
||||
{
|
||||
if(ret != FAIL){
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
int64_t args[2];
|
||||
args[1] = retval;
|
||||
if(t == -1)
|
||||
args[1] = -1;
|
||||
|
||||
|
||||
if(index==FRAME_NUMBER){
|
||||
args[0] = FRAME_NUMBER;
|
||||
retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]);
|
||||
if(args[1] != -1) args[1]=retval;
|
||||
}else{
|
||||
#ifdef VERBOSE
|
||||
|
||||
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
|
||||
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
|
||||
#endif
|
||||
args[0] = FRAME_NUMBER;
|
||||
}else{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
|
||||
#endif
|
||||
args[0] = FRAME_PERIOD;
|
||||
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
|
||||
if(!retval)
|
||||
args[1] = timerValue[ACQUISITION_TIME];
|
||||
}
|
||||
args[0] = FRAME_PERIOD;
|
||||
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
|
||||
if(!retval) args[1] = timerValue[ACQUISITION_TIME];
|
||||
}
|
||||
|
||||
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendIntArray(fnum2,ut,args);
|
||||
disconnectData();
|
||||
if((ut != retval)|| (ret==FAIL)){
|
||||
ret = FAIL;
|
||||
if(index==FRAME_PERIOD){
|
||||
//exptime sent if acq period = 0
|
||||
if(retval){
|
||||
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << retval << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
|
||||
}
|
||||
}else{
|
||||
cout << "ERROR:Number of Frames in receiver set incorrectly to " << ut << " instead of " << retval << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
|
||||
}
|
||||
}
|
||||
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
}
|
||||
}
|
||||
return thisDetector->timerValue[index];
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendIntArray(fnum2,ut,args);
|
||||
disconnectData();
|
||||
if((ut != retval)|| (ret==FAIL)){
|
||||
ret = FAIL;
|
||||
if(index==FRAME_PERIOD){
|
||||
//exptime sent if acq period = 0
|
||||
if(retval){
|
||||
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << retval << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
|
||||
}
|
||||
}else{
|
||||
cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << retval << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
|
||||
}
|
||||
}
|
||||
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
}
|
||||
}
|
||||
return thisDetector->timerValue[index];
|
||||
};
|
||||
|
||||
int slsDetector::lockServer(int lock) {
|
||||
@@ -4890,28 +4985,79 @@ int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout
|
||||
};
|
||||
|
||||
int slsDetector::setRateCorrection(double t){
|
||||
double tdead[]=defaultTDead;
|
||||
|
||||
if (t==0) {
|
||||
if (getDetectorsType() == MYTHEN){
|
||||
double tdead[]=defaultTDead;
|
||||
if (t==0) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "unsetting rate correction" << std::endl;
|
||||
std::cout<< "unsetting rate correction" << std::endl;
|
||||
#endif
|
||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
} else {
|
||||
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
if (t>0)
|
||||
thisDetector->tDead=t;
|
||||
else {
|
||||
if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1)
|
||||
thisDetector->tDead=tdead[thisDetector->currentSettings];
|
||||
else
|
||||
thisDetector->tDead=0;
|
||||
}
|
||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
} else {
|
||||
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
if (t>0)
|
||||
thisDetector->tDead=t;
|
||||
else {
|
||||
if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1)
|
||||
thisDetector->tDead=tdead[thisDetector->currentSettings];
|
||||
else
|
||||
thisDetector->tDead=0;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl;
|
||||
std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl;
|
||||
#endif
|
||||
}
|
||||
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
}
|
||||
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
}
|
||||
|
||||
|
||||
int fnum=F_SET_RATE_CORRECT;
|
||||
int ret=FAIL;
|
||||
char mess[1000]="";
|
||||
int64_t arg = t*1e9;
|
||||
int64_t retval = -1;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting Rate Correction to " << arg << endl;
|
||||
#endif
|
||||
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL) {
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
if(retval<0){
|
||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
thisDetector->tDead = 0;
|
||||
}else{
|
||||
if(retval>0){
|
||||
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||
if(t < 0)
|
||||
thisDetector->tDead = -1;
|
||||
else
|
||||
thisDetector->tDead = (double)retval/(double)1e9;
|
||||
}
|
||||
else{
|
||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
thisDetector->tDead = (double)retval/(double)1e9;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
|
||||
if(strcasestr(mess,"tau/subexptime"))
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE));
|
||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||
thisDetector->tDead = 0;
|
||||
}
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
|
||||
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -5948,6 +6094,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
|
||||
|
||||
if ((thisDetector->myDetectorType==GOTTHARD)||
|
||||
(thisDetector->myDetectorType==PROPIX)||
|
||||
(thisDetector->myDetectorType==JUNGFRAU)||
|
||||
(thisDetector->myDetectorType==MOENCH)) {
|
||||
names[0]= "hostname";
|
||||
names[1]= "port";
|
||||
@@ -6019,9 +6166,9 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
|
||||
|
||||
|
||||
|
||||
int slsDetector::writeSettingsFile(string fname, int imod){
|
||||
int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){
|
||||
|
||||
return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod]);
|
||||
return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay);
|
||||
|
||||
};
|
||||
|
||||
@@ -6032,6 +6179,7 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
|
||||
|
||||
sls_detector_module *myMod=NULL;
|
||||
int* gainval=0; int* offsetval=0;
|
||||
int *iodelay=0;
|
||||
if(thisDetector->nGain){
|
||||
gainval=new int[thisDetector->nGain];
|
||||
for(int i=0;i<thisDetector->nGain;i++)
|
||||
@@ -6042,6 +6190,8 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
|
||||
for(int i=0;i<thisDetector->nOffset;i++)
|
||||
offsetval[i] = -1;
|
||||
}
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
iodelay = new int;*iodelay=0;
|
||||
string fn=fname;
|
||||
fn=fname;
|
||||
int mmin=0, mmax=setNumberOfModules();
|
||||
@@ -6061,13 +6211,14 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
|
||||
ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER, im);
|
||||
fn=ostfn.str();
|
||||
}
|
||||
myMod=readSettingsFile(fn, thisDetector->myDetectorType);
|
||||
myMod=readSettingsFile(fn, thisDetector->myDetectorType,myMod,iodelay);
|
||||
|
||||
if (myMod) {
|
||||
myMod->module=im;
|
||||
//settings is saved in myMod.reg for all except mythen
|
||||
if(thisDetector->myDetectorType!=MYTHEN)
|
||||
myMod->reg=thisDetector->currentSettings;
|
||||
setModule(*myMod,gainval,offsetval);
|
||||
setModule(*myMod,gainval,offsetval,iodelay);
|
||||
deleteModule(myMod);
|
||||
if(gainval) delete[] gainval;
|
||||
if(offsetval) delete[] offsetval;
|
||||
@@ -6080,9 +6231,9 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
|
||||
|
||||
int slsDetector::saveSettingsFile(string fname, int imod) {
|
||||
|
||||
|
||||
sls_detector_module *myMod=NULL;
|
||||
int ret=FAIL;
|
||||
int *iod = 0;
|
||||
|
||||
int mmin=0, mmax=setNumberOfModules();
|
||||
if (imod>=0) {
|
||||
@@ -6091,13 +6242,18 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
|
||||
}
|
||||
for (int im=mmin; im<mmax; im++) {
|
||||
ostringstream ostfn;
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
if(thisDetector->myDetectorType == EIGER){
|
||||
ostfn << fname << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER);
|
||||
else
|
||||
} else
|
||||
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,im);
|
||||
if ((myMod=getModule(im))) {
|
||||
ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod);
|
||||
deleteModule(myMod);
|
||||
|
||||
if(thisDetector->myDetectorType == EIGER){
|
||||
iod = new int;
|
||||
*iod = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1);
|
||||
}
|
||||
ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod,iod);
|
||||
deleteModule(myMod);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -6148,6 +6304,7 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
|
||||
string fn=fname;
|
||||
|
||||
int* gainval=0; int* offsetval=0;
|
||||
int* iodelay=0;
|
||||
if(thisDetector->nGain){
|
||||
gainval=new int[thisDetector->nGain];
|
||||
for(int i=0;i<thisDetector->nGain;i++)
|
||||
@@ -6179,7 +6336,8 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
|
||||
}
|
||||
fn=ostfn.str();
|
||||
if((myMod=getModule(im))){
|
||||
|
||||
iodelay = new int;
|
||||
*iodelay = (int)setDAC(-1,IO_DELAY,0);
|
||||
//extra gain and offset
|
||||
if(thisDetector->nGain){
|
||||
if(readCalibrationFile(fn,gainval, offsetval,thisDetector->myDetectorType)==FAIL)
|
||||
@@ -6189,7 +6347,7 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
|
||||
if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
setModule(*myMod,gainval,offsetval);
|
||||
setModule(*myMod,gainval,offsetval,iodelay);
|
||||
|
||||
deleteModule(myMod);
|
||||
if(gainval) delete[]gainval;
|
||||
@@ -6589,7 +6747,7 @@ int slsDetector::startReceiver(){
|
||||
setErrorMask((getErrorMask())|(COULDNOT_START_RECEIVER));
|
||||
}
|
||||
}
|
||||
if((ret==OK))//&& (thisDetector->myDetectorType != EIGER))
|
||||
if((ret==OK) && (thisDetector->myDetectorType != JUNGFRAU))
|
||||
ret=detectorSendToReceiver(true);
|
||||
|
||||
return ret;
|
||||
@@ -6603,7 +6761,7 @@ int slsDetector::stopReceiver(){
|
||||
int ret = FAIL;
|
||||
char mess[] = "";
|
||||
|
||||
if(thisDetector->myDetectorType != EIGER)
|
||||
if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU)
|
||||
detectorSendToReceiver(false);
|
||||
|
||||
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
@@ -6781,7 +6939,6 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int
|
||||
int n;
|
||||
char mess[100]="Nothing";
|
||||
|
||||
|
||||
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
|
||||
@@ -6814,6 +6971,13 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int
|
||||
disconnectData();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//jungfrau masking adcval
|
||||
if(thisDetector->myDetectorType == JUNGFRAU){
|
||||
for(unsigned int i=0;i<nel;i++){
|
||||
retval[i] = (retval[i] & 0x3FFF3FFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
disconnectData();
|
||||
}
|
||||
|
||||
@@ -494,11 +494,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
writes a trim/settings file for module number imod - the values will be read from the current detector structure
|
||||
\param fname name of the file to be written
|
||||
\param imod module number
|
||||
\param iodelay io delay (detector specific)
|
||||
\returns OK or FAIL if the file could not be written
|
||||
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
|
||||
*/
|
||||
using energyConversion::writeSettingsFile;
|
||||
int writeSettingsFile(string fname, int imod);
|
||||
int writeSettingsFile(string fname, int imod, int* iodelay=0);
|
||||
|
||||
|
||||
/**
|
||||
@@ -908,10 +909,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
\param module module to be set - must contain correct module number and also channel and chip registers
|
||||
\param gainval pointer to extra gain values
|
||||
\param offsetval pointer to extra offset values
|
||||
\param iodelay iodelay (detector specific)
|
||||
\returns current register value
|
||||
\sa ::sls_detector_module
|
||||
*/
|
||||
int setModule(sls_detector_module module, int* gainval, int* offsetval);
|
||||
int setModule(sls_detector_module module, int* gainval, int* offsetval,int* iodelay);
|
||||
//virtual int setModule(sls_detector_module module);
|
||||
|
||||
/**
|
||||
|
||||
@@ -234,7 +234,11 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
|
||||
\returns total number of channels
|
||||
*/
|
||||
virtual int getTotalNumberOfChannels()=0;
|
||||
|
||||
|
||||
/**
|
||||
\returns total number of channels for each dimension
|
||||
*/
|
||||
virtual int getTotalNumberOfChannels(dimension d)=0;
|
||||
|
||||
/** generates file name without extension */
|
||||
virtual string createFileName()=0;
|
||||
@@ -638,37 +642,51 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
|
||||
return GET_EXTERNAL_SIGNAL_FLAG ;};
|
||||
|
||||
/** returns detector settings string from index
|
||||
\param s can be STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS
|
||||
\returns standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, undefined
|
||||
\param s can be STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, LOWNOISE,
|
||||
DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2, GET_SETTINGS
|
||||
\returns standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, lownoise,
|
||||
dynamichg0, fixgain1, fixgain2, forceswitchg1, forceswitchg2, undefined
|
||||
*/
|
||||
static string getDetectorSettings(detectorSettings s){\
|
||||
switch(s) {\
|
||||
case STANDARD: return string("standard");\
|
||||
case FAST: return string("fast");\
|
||||
case HIGHGAIN: return string("highgain");\
|
||||
case DYNAMICGAIN: return string("dynamicgain"); \
|
||||
case LOWGAIN: return string("lowgain"); \
|
||||
switch(s) { \
|
||||
case STANDARD: return string("standard"); \
|
||||
case FAST: return string("fast"); \
|
||||
case HIGHGAIN: return string("highgain"); \
|
||||
case DYNAMICGAIN: return string("dynamicgain"); \
|
||||
case LOWGAIN: return string("lowgain"); \
|
||||
case MEDIUMGAIN: return string("mediumgain"); \
|
||||
case VERYHIGHGAIN: return string("veryhighgain"); \
|
||||
case VERYHIGHGAIN: return string("veryhighgain"); \
|
||||
case LOWNOISE: return string("lownoise"); \
|
||||
default: return string("undefined"); \
|
||||
case DYNAMICHG0: return string("dynamichg0"); \
|
||||
case FIXGAIN1: return string("fixgain1"); \
|
||||
case FIXGAIN2: return string("fixgain2"); \
|
||||
case FORCESWITCHG1: return string("forceswitchg1");\
|
||||
case FORCESWITCHG2: return string("forceswitchg2");\
|
||||
default: return string("undefined"); \
|
||||
}};
|
||||
|
||||
/** returns detector settings string from index
|
||||
\param s can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, undefined
|
||||
\returns setting index STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS
|
||||
\param s can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, lownoise,
|
||||
dynamichg0, fixgain1, fixgain2, forceswitchg1, forceswitchg2, undefined
|
||||
\returns setting index STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN,LOWNOISE,
|
||||
DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2, GET_SETTINGS
|
||||
*/
|
||||
|
||||
static detectorSettings getDetectorSettings(string s){ \
|
||||
if (s=="standard") return STANDARD; \
|
||||
if (s=="fast") return FAST; \
|
||||
if (s=="highgain") return HIGHGAIN; \
|
||||
if (s=="dynamicgain") return DYNAMICGAIN; \
|
||||
if (s=="lowgain") return LOWGAIN; \
|
||||
if (s=="mediumgain") return MEDIUMGAIN; \
|
||||
if (s=="veryhighgain") return VERYHIGHGAIN; \
|
||||
if (s=="lownoise") return LOWNOISE; \
|
||||
return GET_SETTINGS; \
|
||||
if (s=="standard") return STANDARD; \
|
||||
if (s=="fast") return FAST; \
|
||||
if (s=="highgain") return HIGHGAIN; \
|
||||
if (s=="dynamicgain") return DYNAMICGAIN; \
|
||||
if (s=="lowgain") return LOWGAIN; \
|
||||
if (s=="mediumgain") return MEDIUMGAIN; \
|
||||
if (s=="veryhighgain") return VERYHIGHGAIN; \
|
||||
if (s=="lownoise") return LOWNOISE; \
|
||||
if (s=="dynamichg0") return DYNAMICHG0; \
|
||||
if (s=="fixgain1") return FIXGAIN1; \
|
||||
if (s=="fixgain2") return FIXGAIN2; \
|
||||
if (s=="forceswitchg1") return FORCESWITCHG1; \
|
||||
if (s=="forceswitchg2") return FORCESWITCHG2; \
|
||||
return GET_SETTINGS; \
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="setctrbit"; //
|
||||
descrToFuncMap[i].m_pFuncName="resmat"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter;
|
||||
i++;
|
||||
|
||||
@@ -1113,7 +1113,7 @@ string slsDetectorCommand::helpLine(int narg, char *args[], int action) {
|
||||
if (narg==0) {
|
||||
os << "Command can be: " << endl;
|
||||
for(int i=0; i<numberOfCommands; ++i) {
|
||||
os << descrToFuncMap[i].m_pFuncName << "\t" ;
|
||||
os << descrToFuncMap[i].m_pFuncName << "\n" ;
|
||||
}
|
||||
os << endl;
|
||||
return os.str();
|
||||
@@ -1247,7 +1247,7 @@ string slsDetectorCommand::cmdStatus(int narg, char *args[], int action) {
|
||||
return string("unknown action");
|
||||
} else if (action==HELP_ACTION) {
|
||||
return helpStatus(narg,args,HELP_ACTION);
|
||||
}
|
||||
}
|
||||
runStatus s=myDet->getRunStatus();
|
||||
return myDet->runStatusType(s);
|
||||
|
||||
@@ -1941,7 +1941,7 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action){
|
||||
}
|
||||
double t;
|
||||
if (myDet->getRateCorrection(t)) {
|
||||
sprintf(answer,"%f",t);
|
||||
sprintf(answer,"%0.9f",t);
|
||||
} else {
|
||||
sprintf(answer,"%f",0.);
|
||||
}
|
||||
@@ -1954,7 +1954,7 @@ string slsDetectorCommand::helpRateCorr(int narg, char *args[], int action){
|
||||
if (action==GET_ACTION || action==HELP_ACTION)
|
||||
os << string("ratecorr \t returns the dead time used for rate correections in ns \n");
|
||||
if (action==PUT_ACTION || action==HELP_ACTION)
|
||||
os << string("ratecorr ns \t sets the deadtime correction constant in ns\n");
|
||||
os << string("ratecorr ns \t sets the deadtime correction constant in ns, -1 in Eiger will set it to default tau of settings\n");
|
||||
return os.str();
|
||||
|
||||
}
|
||||
@@ -2247,10 +2247,10 @@ string slsDetectorCommand::cmdCounter(int narg, char *args[], int action){
|
||||
retval=myDet->resetCounterBlock(ival);
|
||||
}
|
||||
|
||||
else if (string(args[0])==string("setctrbit")){
|
||||
else if (string(args[0])==string("resmat")){
|
||||
if (action==PUT_ACTION){
|
||||
if (!sscanf(args[1],"%d",&ival))
|
||||
return string("Could not scan resetctrbit input ")+string(args[1]);
|
||||
return string("Could not scan resmat input ")+string(args[1]);
|
||||
if(ival>=0)
|
||||
sprintf(answer,"%d",myDet->setCounterBit(ival));
|
||||
}else
|
||||
@@ -2271,12 +2271,12 @@ string slsDetectorCommand::helpCounter(int narg, char *args[], int action){
|
||||
if (action==PUT_ACTION || action==HELP_ACTION){
|
||||
os << "readctr \t Cannot put"<< std::endl;
|
||||
os << "resetctr i \t resets counter in detector, restarts acquisition if i=1"<< std::endl;
|
||||
os << "setctrbit i \t sets/resets counter bit in detector"<< std::endl;
|
||||
os << "resmat i \t sets/resets counter bit in detector"<< std::endl;
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION){
|
||||
os << "readctr i fname\t reads counter in detector to file fname, restarts acquisition if i=1"<< std::endl;
|
||||
os << "resetctr \t Cannot get"<< std::endl;
|
||||
os << "setctrbit i \t gets the counter bit in detector"<< std::endl;
|
||||
os << "resmat i \t gets the counter bit in detector"<< std::endl;
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
@@ -3053,7 +3053,7 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
|
||||
if (cmd=="settings") {
|
||||
if (action==PUT_ACTION)
|
||||
if (action==PUT_ACTION)
|
||||
myDet->setSettings(myDet->getDetectorSettings(string(args[1])));
|
||||
return myDet->getDetectorSettings(myDet->getSettings());
|
||||
} else if (cmd=="threshold") {
|
||||
@@ -3070,7 +3070,7 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
|
||||
string sval=string(args[1]);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< " trimfile " << sval << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
if (action==GET_ACTION) {
|
||||
//create file names
|
||||
myDet->saveSettingsFile(sval, -1);
|
||||
@@ -3145,7 +3145,8 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) {
|
||||
|
||||
ostringstream os;
|
||||
if (action==PUT_ACTION || action==HELP_ACTION) {
|
||||
os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain"<< std::endl;
|
||||
os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain"
|
||||
"lownoise, dynamichg0,fixgain1,fixgain2,forceswitchg1, forceswitchg2"<< std::endl;
|
||||
os << "threshold eV\n sets the detector threshold in eV"<< std::endl;
|
||||
os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl;
|
||||
os << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl;
|
||||
|
||||
@@ -110,22 +110,24 @@ int slsDetectorUsers::getPositions(double *pos){
|
||||
}
|
||||
|
||||
int slsDetectorUsers::setDetectorSize(int x0, int y0, int nx, int ny){
|
||||
if(myDetector->getTotalNumberOfChannels(slsDetectorDefs::Y)>1)
|
||||
return 1;
|
||||
int nmod=nx/(myDetector->getChansPerMod(0));
|
||||
cout << myDetector->getChansPerMod(0) << " " << nx << " " << nmod << endl;
|
||||
return myDetector->setNumberOfModules(nmod)*myDetector->getChansPerMod(0);}
|
||||
|
||||
int slsDetectorUsers::getDetectorSize(int &x0, int &y0, int &nx, int &ny){
|
||||
y0=0;
|
||||
ny=1;
|
||||
x0=0;
|
||||
nx=myDetector->setNumberOfModules()*myDetector->getChansPerMod(0);
|
||||
return nx;
|
||||
nx=myDetector->getTotalNumberOfChannels(slsDetectorDefs::X);
|
||||
ny=myDetector->getTotalNumberOfChannels(slsDetectorDefs::Y);
|
||||
return nx*ny;
|
||||
}
|
||||
|
||||
int slsDetectorUsers::getMaximumDetectorSize(int &nx, int &ny){
|
||||
ny=1;
|
||||
nx=myDetector->getMaxNumberOfModules()*myDetector->getChansPerMod(0);
|
||||
return nx;
|
||||
nx=myDetector->getMaxNumberOfChannelsPerDetector(slsDetectorDefs::X);
|
||||
ny=myDetector->getMaxNumberOfChannelsPerDetector(slsDetectorDefs::Y);
|
||||
return nx*ny;
|
||||
}
|
||||
|
||||
int slsDetectorUsers::setBitDepth(int i){
|
||||
|
||||
@@ -44,14 +44,12 @@ slsDetectorUtils::slsDetectorUtils() {
|
||||
int slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
//ensure acquire isnt started multiple times by same client
|
||||
pthread_mutex_lock(&mp);
|
||||
if(getAcquiringFlag() == false)
|
||||
setAcquiringFlag(true);
|
||||
else{
|
||||
std::cout << "Error: Acquire has already been started." << std::endl;
|
||||
return FAIL;
|
||||
}
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
|
||||
bool receiver = (setReceiverOnline()==ONLINE_FLAG);
|
||||
@@ -157,10 +155,6 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
*stoppedFlag=1;
|
||||
}
|
||||
|
||||
//resets frames caught in receiver
|
||||
resetFramesCaught();
|
||||
|
||||
|
||||
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||
*stoppedFlag=1;
|
||||
}
|
||||
@@ -175,7 +169,10 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
cout << " starting thread " << endl;
|
||||
#endif
|
||||
|
||||
|
||||
//resets frames caught in receiver
|
||||
if(receiver){
|
||||
resetFramesCaught();
|
||||
}
|
||||
|
||||
for(int im=0;im<nm;im++) {
|
||||
|
||||
@@ -183,6 +180,7 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
cout << " starting measurement "<< im << " of " << nm << endl;
|
||||
#endif
|
||||
|
||||
|
||||
//cout << "data thread started " << endl;
|
||||
|
||||
|
||||
@@ -364,7 +362,7 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
usleep(100000);
|
||||
}*/
|
||||
|
||||
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH)){
|
||||
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){
|
||||
if((*correctionMask)&(1<<WRITE_FILE))
|
||||
closeDataFile();
|
||||
}
|
||||
@@ -838,6 +836,7 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
|
||||
break;
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case JUNGFRAU:
|
||||
names[nvar++]="flags";
|
||||
names[nvar++]="delay";
|
||||
names[nvar++]="gates";
|
||||
@@ -922,6 +921,7 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
|
||||
case MYTHEN:
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case JUNGFRAU:
|
||||
names[nvar++]="flatfield";
|
||||
names[nvar++]="badchannels";
|
||||
break;
|
||||
|
||||
@@ -421,6 +421,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
||||
virtual int* startAndReadAll()=0;
|
||||
|
||||
virtual int getTotalNumberOfChannels()=0;
|
||||
virtual int getTotalNumberOfChannels(dimension d)=0;
|
||||
virtual int getMaxNumberOfChannels()=0;
|
||||
virtual int getMaxNumberOfChannels(dimension d)=0;
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset,
|
||||
/* I/O */
|
||||
|
||||
|
||||
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod){
|
||||
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod, int* iodelay){
|
||||
|
||||
|
||||
|
||||
@@ -215,6 +215,24 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
||||
break;
|
||||
case EIGER:
|
||||
break;
|
||||
case JUNGFRAU:
|
||||
names[id++]="VDAC0";
|
||||
names[id++]="VDAC1";
|
||||
names[id++]="VDAC2";
|
||||
names[id++]="VDAC3";
|
||||
names[id++]="VDAC4";
|
||||
names[id++]="VDAC5";
|
||||
names[id++]="VDAC6";
|
||||
names[id++]="VDAC7";
|
||||
names[id++]="VDAC8";
|
||||
names[id++]="VDAC9";
|
||||
names[id++]="VDAC10";
|
||||
names[id++]="VDAC11";
|
||||
names[id++]="VDAC12";
|
||||
names[id++]="VDAC13";
|
||||
names[id++]="VDAC14";
|
||||
names[id++]="VDAC15";
|
||||
break;
|
||||
default:
|
||||
cout << "Unknown detector type - unknown format for settings file" << endl;
|
||||
return NULL;
|
||||
@@ -335,10 +353,12 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
||||
infile.open(myfname.c_str(),ifstream::binary);
|
||||
if (infile.is_open()) {
|
||||
infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
|
||||
infile.read((char*) iodelay,sizeof(iodelay));
|
||||
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||
#ifdef VERBOSE
|
||||
for(int i=0;i<myMod->ndac;i++)
|
||||
std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl;
|
||||
std::cout << "iodelay:" << *iodelay << std::endl;
|
||||
#endif
|
||||
if(infile.eof()){
|
||||
cout<<endl<<"Error, could not load trimbits end of file, "<<myfname<<", reached."<<endl<<endl;
|
||||
@@ -359,6 +379,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
||||
case MOENCH:
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case JUNGFRAU:
|
||||
//---------------dacs---------------
|
||||
infile.open(myfname.c_str(), ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
@@ -417,7 +438,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
||||
};
|
||||
|
||||
|
||||
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod){
|
||||
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay){
|
||||
|
||||
ofstream outfile;
|
||||
|
||||
@@ -458,6 +479,24 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
|
||||
break;
|
||||
case EIGER:
|
||||
break;
|
||||
case JUNGFRAU:
|
||||
names[id++]="VDAC0";
|
||||
names[id++]="VDAC1";
|
||||
names[id++]="VDAC2";
|
||||
names[id++]="VDAC3";
|
||||
names[id++]="VDAC4";
|
||||
names[id++]="VDAC5";
|
||||
names[id++]="VDAC6";
|
||||
names[id++]="VDAC7";
|
||||
names[id++]="VDAC8";
|
||||
names[id++]="VDAC9";
|
||||
names[id++]="VDAC10";
|
||||
names[id++]="VDAC11";
|
||||
names[id++]="VDAC12";
|
||||
names[id++]="VDAC13";
|
||||
names[id++]="VDAC14";
|
||||
names[id++]="VDAC15";
|
||||
break;
|
||||
default:
|
||||
cout << "Unknown detector type - unknown format for settings file" << endl;
|
||||
return FAIL;
|
||||
@@ -475,8 +514,10 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
|
||||
#ifdef VERBOSE
|
||||
for(int i=0;i<mod.ndac;i++)
|
||||
std::cout << "dac " << i << ":" << mod.dacs[i] << std::endl;
|
||||
std::cout << "iodelay: " << *iodelay << std::endl;
|
||||
#endif
|
||||
outfile.write((char*)mod.dacs, sizeof(dacs_t)*(mod.ndac));
|
||||
outfile.write((char*)iodelay, sizeof(iodelay));
|
||||
outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan));
|
||||
|
||||
outfile.close();
|
||||
|
||||
@@ -81,21 +81,23 @@ class energyConversion
|
||||
\param fname name of the file to be read
|
||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
|
||||
\param iodelay io delay (detector specific)
|
||||
\returns the pointer to myMod or NULL if reading the file failed
|
||||
*/
|
||||
|
||||
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL);
|
||||
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL, int* iodelay=0);
|
||||
|
||||
/**
|
||||
writes a trim/settings file
|
||||
\param fname name of the file to be written
|
||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||
\param mod module structure which has to be written to file
|
||||
\param iodelay io delay (detector specific)
|
||||
\returns OK or FAIL if the file could not be written
|
||||
|
||||
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
|
||||
*/
|
||||
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod);
|
||||
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay=0);
|
||||
|
||||
/** allocates the momery for a detector module structure
|
||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||
|
||||
@@ -137,7 +137,7 @@ 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());
|
||||
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels()); //only 1d detectors
|
||||
dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
|
||||
delete thisData;
|
||||
fdata=NULL;
|
||||
@@ -280,7 +280,7 @@ data queue size unlock
|
||||
if (dataReady) {
|
||||
// cout << "callback arg "<< getCurrentProgress()<< " " << (fname+ext).c_str() << " " << np << endl;
|
||||
//cout << "ADATREADY 2 " << endl;
|
||||
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);
|
||||
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);//only 1d detectors
|
||||
dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
|
||||
delete thisData;
|
||||
ang=NULL;
|
||||
@@ -493,7 +493,8 @@ void* postProcessing::processData(int delflag) {
|
||||
int currentSubFrameIndex = -1;
|
||||
bool newData = false;
|
||||
int nthframe = setReadReceiverFrequency(0);
|
||||
|
||||
int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
|
||||
int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "receiver read freq:" << nthframe << std::endl;
|
||||
@@ -640,7 +641,7 @@ void* postProcessing::processData(int delflag) {
|
||||
delete [] receiverData;
|
||||
if ((fdata) && (dataReady)){
|
||||
// cout << "DATAREADY 3" << endl;
|
||||
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,getTotalNumberOfChannels());
|
||||
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,nx,ny);
|
||||
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
|
||||
delete thisData;
|
||||
fdata = NULL;
|
||||
@@ -810,7 +811,7 @@ void postProcessing::initDataset(int r) {
|
||||
}
|
||||
|
||||
double tdead;
|
||||
if (*correctionMask&(1<<RATE_CORRECTION)) {
|
||||
if ((getDetectorsType()==MYTHEN) && (*correctionMask&(1<<RATE_CORRECTION))) {
|
||||
#ifdef VERBOSE
|
||||
cout << "get tau " << endl;
|
||||
#endif
|
||||
|
||||
@@ -51,6 +51,9 @@ int setCounterBit(int val);
|
||||
int pulsePixel(int n, int x, int y);
|
||||
int pulsePixelNMove(int n, int x, int y);
|
||||
int pulseChip(int n);
|
||||
int setRateCorrection(int64_t custom_tau_in_nsec);
|
||||
int getRateCorrectionEnable();
|
||||
int getDefaultSettingsTau_in_nsec();
|
||||
#endif
|
||||
|
||||
#if defined(MYTHEND) || defined(GOTTHARDD)
|
||||
@@ -67,7 +70,7 @@ int getChip(sls_detector_chip *myChip);
|
||||
|
||||
|
||||
#ifdef EIGERD
|
||||
int setModule(sls_detector_module myMod, int* gain, int* offset);
|
||||
int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay);
|
||||
int getModule(sls_detector_module *myMod, int* gain, int* offset);
|
||||
#else
|
||||
int setModule(sls_detector_module myMod);
|
||||
|
||||
@@ -15,10 +15,17 @@
|
||||
|
||||
|
||||
/* examples*/
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
#define NCHAN (256*256)
|
||||
#define NCHIP 8
|
||||
#define NADC 0
|
||||
#else
|
||||
#define NCHAN 1
|
||||
#define NCHIP 1
|
||||
#define NDAC 1
|
||||
#define NADC 1
|
||||
#endif
|
||||
|
||||
#define NMAXMODX 1
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD NMAXMODX*NMAXMODY
|
||||
@@ -27,5 +34,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SLSDETECTORSERVER_DEFS_H_ */
|
||||
|
||||
@@ -32,6 +32,7 @@ const enum detectorType myDetectorType=PICASSO;
|
||||
const enum detectorType myDetectorType=GENERIC;
|
||||
#endif
|
||||
|
||||
extern enum detectorSettings thisSettings;
|
||||
|
||||
//global variables for optimized readout
|
||||
char mess[MAX_STR_LENGTH];
|
||||
@@ -46,7 +47,7 @@ void checkFirmwareCompatibility(){
|
||||
cprintf(BLUE,"\n\n********************************************************\n"
|
||||
"**********************EIGER Server**********************\n"
|
||||
"********************************************************\n");
|
||||
cprintf(BLUE,"\nFirmware Version: %llx\nSoftware Version: %llx\n\n",
|
||||
cprintf(BLUE,"\nFirmware Version: %lld\nSoftware Version: %lld\n\n",
|
||||
getDetectorId(DETECTOR_FIRMWARE_VERSION), getDetectorId(DETECTOR_SOFTWARE_VERSION));
|
||||
|
||||
//check for firmware version compatibility
|
||||
@@ -179,6 +180,7 @@ int function_table() {
|
||||
flist[F_PULSE_PIXEL]=&pulse_pixel;
|
||||
flist[F_PULSE_PIXEL_AND_MOVE]=&pulse_pixel_and_move;
|
||||
flist[F_PULSE_CHIP]=&pulse_chip;
|
||||
flist[F_SET_RATE_CORRECT]=&rate_correct;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
@@ -1791,8 +1793,13 @@ int get_chip(int file_des) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int set_module(int file_des) {
|
||||
int retval, n,i;
|
||||
int retval, n;
|
||||
int ret=OK,ret1=OK;
|
||||
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
@@ -1800,6 +1807,7 @@ int set_module(int file_des) {
|
||||
#ifdef EIGERD
|
||||
int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int));
|
||||
int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int));
|
||||
int *myIODelay = (int*)malloc(sizeof(int));
|
||||
#endif
|
||||
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
|
||||
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
|
||||
@@ -1854,6 +1862,7 @@ int set_module(int file_des) {
|
||||
#ifdef EIGERD
|
||||
n = receiveData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32);
|
||||
n = receiveData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32);
|
||||
n = receiveData(file_des,myIODelay,sizeof(int),INT32);
|
||||
#endif
|
||||
if (ret>=0)
|
||||
ret=OK;
|
||||
@@ -1861,15 +1870,29 @@ int set_module(int file_des) {
|
||||
ret=FAIL;
|
||||
|
||||
|
||||
//#ifdef VERBOSE
|
||||
#ifdef VERBOSE
|
||||
printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset);
|
||||
#ifdef EIGERD
|
||||
int i;
|
||||
for(i=0;i<getNumberOfGainsPerModule();i++)
|
||||
printf("gain[%d]:%d\t%f\n",i,myGain[i],((double)myGain[i]/1000));
|
||||
for(i=0;i<getNumberOfOffsetsPerModule();i++)
|
||||
printf("offset[%d]:%d\t%f\n",i,myOffset[i],((double)myOffset[i]/1000));
|
||||
printf("IO Delay:%d\n",i,*myIODelay);
|
||||
#endif
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
switch(myModule.reg){
|
||||
case STANDARD:
|
||||
case HIGHGAIN:
|
||||
case LOWGAIN:
|
||||
break;
|
||||
default:
|
||||
sprintf(mess,"This setting %d does not exist for this detector\n",myModule.reg);
|
||||
ret = FAIL;
|
||||
cprintf(RED,"%s",mess);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (ret==OK) {
|
||||
@@ -1878,7 +1901,26 @@ int set_module(int file_des) {
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else {
|
||||
#ifdef EIGERD
|
||||
ret=setModule(myModule, myGain, myOffset);
|
||||
ret=setModule(myModule, myGain, myOffset,myIODelay);
|
||||
//rate correction
|
||||
if(getRateCorrectionEnable()){
|
||||
int64_t tau_ns = getDefaultSettingsTau_in_nsec();
|
||||
if(tau_ns < 0){
|
||||
sprintf(mess,"Cannot set Rate correction. Rate correction Deactivated, settings %d not recognized by detector\n",thisSettings);
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
setRateCorrection(0);
|
||||
}
|
||||
retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here
|
||||
if(tau_ns != retval){
|
||||
if(retval == -1)
|
||||
strcpy(mess,"Could not set Rate correction. Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n");
|
||||
else
|
||||
strcpy(mess,"Could not set Rate correction. Rate correction Deactivated\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ret=setModule(myModule);
|
||||
#endif
|
||||
@@ -2518,7 +2560,7 @@ int set_timer(int file_des) {
|
||||
switch(ind) {
|
||||
#ifdef EIGERD
|
||||
case SUBFRAME_ACQUISITION_TIME:
|
||||
if (tns > MAX_SUBFRAME_EXPOSURE_VAL ){
|
||||
if (tns > (MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) ){
|
||||
ret=FAIL;
|
||||
strcpy(mess,"Sub Frame exposure time should not exceed 5.368 seconds\n");
|
||||
break;
|
||||
@@ -3815,3 +3857,72 @@ int pulse_chip(int file_des) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int rate_correct(int file_des) {
|
||||
int64_t tau_ns=-1;
|
||||
int n;
|
||||
int64_t retval=-1;
|
||||
int ret=OK,ret1=OK;
|
||||
|
||||
sprintf(mess,"can't set/unset rate correction\n");
|
||||
|
||||
n = receiveData(file_des,&tau_ns,sizeof(tau_ns),INT64);
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
#ifndef EIGERD
|
||||
sprintf(mess,"Rate Correction not implemented for this detector\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
#endif
|
||||
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
|
||||
//tau = -1, use default tau of settings
|
||||
if((ret==OK)&&(tau_ns<0)){
|
||||
tau_ns = getDefaultSettingsTau_in_nsec();
|
||||
if(tau_ns < 0){
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Cannot set rate correction. Settings %d not recognized by detector\n",thisSettings);
|
||||
cprintf(RED,"%s",mess);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ret==OK) {
|
||||
printf("Setting rate correction to %lld ns\n",tau_ns);
|
||||
|
||||
if (differentClients==1 && lockStatus==1 && tau_ns!=-1) {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else {
|
||||
retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here
|
||||
if(tau_ns != retval){
|
||||
if(retval == -1)
|
||||
strcpy(mess,"Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if ((ret==OK) && (differentClients))
|
||||
ret=FORCE_UPDATE;
|
||||
|
||||
|
||||
//ret could be swapped during sendData
|
||||
ret1 = ret;
|
||||
n = sendData(file_des,&ret1,sizeof(ret),INT32);
|
||||
if (ret==FAIL) {
|
||||
n = sendData(file_des,mess,sizeof(mess),OTHER);
|
||||
} else {
|
||||
n = sendData(file_des,&retval,sizeof(retval),INT64);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ int set_counter_bit(int);
|
||||
int pulse_pixel(int);
|
||||
int pulse_pixel_and_move(int);
|
||||
int pulse_chip(int);
|
||||
int rate_correct(int);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user