From 33ac63d14abb3ebf359d1576fc6ab9c724e01810 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 26 Oct 2018 17:40:18 +0200 Subject: [PATCH] still updating slsdetector.cpp --- .../slsDetectorFunctionList.c | 162 +- .../slsDetectorServer_defs.h | 2 - .../slsDetectorServer/communication_funcs.c | 246 +- .../slsDetectorServer/communication_funcs.h | 2 - .../slsDetectorFunctionList.h | 11 +- .../slsDetectorServer_funcs.c | 280 +- .../multiSlsDetector/multiSlsDetector.cpp | 33 +- .../multiSlsDetector/multiSlsDetector.h | 20 +- .../slsDetector/slsDetector.cpp | 2977 +++++++---------- slsDetectorSoftware/slsDetector/slsDetector.h | 73 +- .../slsDetector/slsDetectorCommand.cpp | 27 +- .../include/slsReceiverImplementation.h | 8 +- .../src/slsReceiverImplementation.cpp | 49 +- .../src/slsReceiverTCPIPInterface.cpp | 117 +- slsSupportLib/include/sls_detector_defs.h | 15 +- slsSupportLib/include/sls_detector_funcs.h | 2 - 16 files changed, 1501 insertions(+), 2523 deletions(-) diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index d1cfcf860..d03c23f3d 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -24,7 +24,6 @@ const char* dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","V int default_tau_from_file= -1; enum detectorSettings thisSettings; sls_detector_module *detectorModules=NULL; -int *detectorChips=NULL; int *detectorChans=NULL; int *detectorDacs=NULL; int *detectorAdcs=NULL; @@ -383,26 +382,24 @@ void allocateDetectorStructureMemory() { //Allocation of memory detectorModules=malloc(sizeof(sls_detector_module)); - detectorChips=malloc(NCHIP*sizeof(int)); detectorChans=malloc(NCHIP*NCHAN*sizeof(int)); detectorDacs=malloc(NDAC*sizeof(int)); detectorAdcs=malloc(NADC*sizeof(int)); FILE_LOG(logDEBUG5, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules)); - FILE_LOG(logDEBUG5, ("chips from 0x%x to 0x%x\n",detectorChips, detectorChips)); FILE_LOG(logDEBUG5, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans)); FILE_LOG(logDEBUG5, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs)); FILE_LOG(logDEBUG5, ("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs)); (detectorModules)->dacs=detectorDacs; (detectorModules)->adcs=detectorAdcs; - (detectorModules)->chipregs=detectorChips; (detectorModules)->chanregs=detectorChans; (detectorModules)->ndac=NDAC; (detectorModules)->nadc=NADC; (detectorModules)->nchip=NCHIP; (detectorModules)->nchan=NCHIP*NCHAN; - (detectorModules)->gain=0; - (detectorModules)->offset=0; (detectorModules)->reg=0; + (detectorModules)->iodelay=0; + (detectorModules)->tau=0; + (detectorModules)->eV=0; thisSettings = UNINITIALIZED; // if trimval requested, should return -1 to acknowledge unknown @@ -805,63 +802,123 @@ int64_t getTimeLeft(enum timerIndex ind) { -/* parameters - channel, chip, module, settings */ +/* parameters - channel, module, settings */ -int setModule(sls_detector_module myMod, int delay) { - int retval[2]; - int i; +int setModule(sls_detector_module myMod, char* mess) { + FILE_LOG(logINFO, ("Setting module with settings %d\n",myMod.reg)); - //copy module locally (module number, serial number, gain offset, - //dacs (pointless), trimbit values(if needed) - if (detectorModules) - if (copyModule(detectorModules,&myMod) == FAIL) - return FAIL; - // settings setSettings( (enum detectorSettings)myMod.reg); + //copy module locally (module number, serial number + //dacs (pointless), trimbit values(if needed) + if (detectorModules) { + if (copyModule(detectorModules,&myMod) == FAIL) { + sprintf(mess, "Could not copy module\n"); + FILE_LOG(logERROR, (mess)); + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined\n")); + return FAIL; + } + } + // iodelay - if (setIODelay(delay)!= delay) { - FILE_LOG(logERROR, ("Could not set iodelay %d\n", delay)); + if (setIODelay(myMod.iodelay)!= myMod.iodelay) { + sprintf(mess, "Could not set module. Could not set iodelay %d\n", myMod.iodelay); + FILE_LOG(logERROR, (mess)); + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined\n")); return FAIL; } - // dacs - for(i=0;i= 0) + setThresholdEnergy(myMod.eV); + else { + // (loading a random trim file) (dont return fail) + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n")); + } + // dacs + { + int i = 0; + int retval[2] = {0, 0}; + for(i = 0; i < myMod.ndac; ++i) { + setDAC((enum DACINDEX)i, myMod.dacs[i] , 0, retval); + if (myMod.dacs[i] != retval[0]) { + sprintf(mess, "Could not set module. Could not set dac %d\n", i); + FILE_LOG(logERROR, (mess)); + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined\n")); + return FAIL; + } + } + } // trimbits #ifndef VIRTUAL - if (myMod.nchan==0 && myMod.nchip == 0) { + if (myMod.nchan == 0) { FILE_LOG(logINFO, ("Setting module without trimbits\n")); } else { FILE_LOG(logINFO, ("Setting module with trimbits\n")); //includ gap pixels unsigned int tt[263680]; - int iy,ichip,ix,ip=0,ich=0; - for(iy=0;iy<256;iy++) { - for (ichip=0; ichip<4; ichip++) { - for(ix=0;ix<256;ix++) { - tt[ip++]=myMod.chanregs[ich++]; + int iy, ichip, ix, ip = 0, ich = 0; + for (iy = 0; iy < 256; ++iy) { + for (ichip = 0; ichip < 4; ++ichip) { + for (ix = 0; ix < 256; ++ix) { + tt[ip++] = myMod.chanregs[ich++]; } - if (ichip<3) { - tt[ip++]=0; - tt[ip++]=0; + if (ichip < 3) { + tt[ip++] = 0; + tt[ip++] = 0; } } } //set trimbits - if (!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(),tt)) { - FILE_LOG(logERROR, ("Could not set trimbits\n")); + if (!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(), tt)) { + sprintf(mess, "Could not set module. Could not set trimbits\n"); + FILE_LOG(logERROR, (mess)); + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n")); return FAIL; } } + + + //rate correction + //switch off rate correction: no value read from load settings) + if (myMod.tau == -1) { + if (getRateCorrectionEnable()) { + setRateCorrection(0); + sprintf(mess,"Cannot set module. Cannot set Rate correction. " + "No default tau provided. Deactivating Rate Correction\n"); + FILE_LOG(logERROR, (mess)); + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n")); + return FAIL; + } + } + //normal tau value (only if enabled) + else { + setDefaultSettingsTau_in_nsec(myMod.tau); + if (getRateCorrectionEnable()) { + int64_t retvalTau = setRateCorrection(myMod.tau); + if (myMod.tau != retvalTau) { + sprintf(mess, "Cannot set module. Could not set rate correction\n"); + FILE_LOG(logERROR, (mess)); + setSettings(UNDEFINED); + FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n")); + return FAIL; + } + } + } #endif - return thisSettings; + return OK; } @@ -882,13 +939,13 @@ int getModule(sls_detector_module *myMod) { tt = Feb_Control_GetTrimbits(); //exclude gap pixels - int iy,ichip,ix,ip=0,ich=0; - for(iy=0;iy<256;iy++) { - for (ichip=0; ichip<4; ichip++) { - for(ix=0;ix<256;ix++) { - myMod->chanregs[ich++]=tt[ip++]; + int iy, ichip, ix, ip = 0, ich = 0; + for (iy = 0; iy < 256; ++iy) { + for (ichip = 0; ichip < 4; ++ichip) { + for (ix = 0; ix < 256; ++iy) { + myMod->chanregs[ich++] = tt[ip++]; } - if (ichip<3) { + if (ichip < 3) { ip++; ip++; } @@ -1728,7 +1785,7 @@ void readFrame(int *ret, char *mess) { int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { - int ichip, idac, ichan, iadc; + int idac, ichan, iadc; int ret=OK; FILE_LOG(logDEBUG5, ("Copying module %x to module %x\n",srcMod,destMod)); @@ -1738,11 +1795,6 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { destMod->serialnumber=srcMod->serialnumber; } //no trimbit feature - if (destMod->nchip && ((srcMod->nchip)>(destMod->nchip))) { - FILE_LOG(logINFO, ("Number of chip of source is larger than number of chips of destination\n")); - return FAIL; - } - //no trimbit feature if (destMod->nchan && ((srcMod->nchan)>(destMod->nchan))) { FILE_LOG(logINFO, ("Number of channels of source is larger than number of channels of destination\n")); return FAIL; @@ -1758,7 +1810,6 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { FILE_LOG(logDEBUG5, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac)); FILE_LOG(logDEBUG5, ("ADCs: src %d, dest %d\n",srcMod->nadc,destMod->nadc)); - FILE_LOG(logDEBUG5, ("Chips: src %d, dest %d\n",srcMod->nchip,destMod->nchip)); FILE_LOG(logDEBUG5, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan)); destMod->ndac=srcMod->ndac; destMod->nadc=srcMod->nadc; @@ -1766,23 +1817,22 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { destMod->nchan=srcMod->nchan; if (srcMod->reg>=0) destMod->reg=srcMod->reg; + if (srcMod->iodelay>=0) + destMod->iodelay=srcMod->iodelay; + if (srcMod->tau>=0) + destMod->tau=srcMod->tau; + if (srcMod->eV>=0) + destMod->eV=srcMod->eV; FILE_LOG(logDEBUG5, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg )); - if (srcMod->gain>=0) - destMod->gain=srcMod->gain; - if (srcMod->offset>=0) - destMod->offset=srcMod->offset; - if ((destMod->nchip!=0) || (destMod->nchan!=0)) { - for (ichip=0; ichip<(srcMod->nchip); ichip++) { - if (*((srcMod->chipregs)+ichip)>=0) - *((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip); - } + if (destMod->nchan!=0) { for (ichan=0; ichan<(srcMod->nchan); ichan++) { if (*((srcMod->chanregs)+ichan)>=0) *((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan); } } else FILE_LOG(logINFO, ("Not Copying trimbits\n")); + for (idac=0; idac<(srcMod->ndac); idac++) { if (*((srcMod->dacs)+idac)>=0) { *((destMod->dacs)+idac)=*((srcMod->dacs)+idac); @@ -1811,8 +1861,6 @@ int getNumberOfChips() {return NCHIP;} int getNumberOfDACs() {return NDAC;} int getNumberOfADCs() {return NADC;} int getNumberOfChannelsPerChip() {return NCHAN;} -int getNumberOfGains() {return NGAIN;} -int getNumberOfOffsets() {return NOFFSET;} diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index dfc4d745b..8788688c5 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -49,8 +49,6 @@ enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE}; #define NCHIP (4) #define NADC (0) #define NDAC (16) -#define NGAIN (0) -#define NOFFSET (0) #define TEN_GIGA_BUFFER_SIZE (4112) diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.c b/slsDetectorServers/slsDetectorServer/communication_funcs.c index a82f9bd82..ed9e79d6d 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.c +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.c @@ -351,64 +351,36 @@ int receiveDataOnly(int file_des, void* buf,int length) { 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, n = 0; - int nChips = myMod->nchip; - int nChans = myMod->nchan; - int nAdcs = myMod->nadc; - int nDacs = myMod->ndac; - - // send module structure n = sendData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32); + n = sendData(file_des,&(myMod->nchan), sizeof(myMod->nchan), INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32); + n = sendData(file_des,&(myMod->nchip), sizeof(myMod->nchip), INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32); + n = sendData(file_des,&(myMod->ndac), sizeof(myMod->ndac), INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32); + n = sendData(file_des,&(myMod->nadc), sizeof(myMod->nadc), INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32); + n = sendData(file_des,&(myMod->reg), sizeof(myMod->reg), INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER); + n = sendData(file_des,&(myMod->iodelay), sizeof(myMod->iodelay), INT32); if (!n) return -1; ts += n; - n = sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER); + n = sendData(file_des,&(myMod->tau), sizeof(myMod->tau), INT32); if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("module of size %d sent\n",ts)); - - // send dac - n = sendData(file_des,myMod->dacs,sizeof(int)*nDacs,INT32); + n = sendData(file_des,&(myMod->eV), sizeof(myMod->eV), INT32); if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("dacs of size %d sent\n",ts)); - { - int idac; - for (idac = 0; idac < nDacs; idac++) - FILE_LOG(logDEBUG5, ("dac %d is %d\n",idac,(int)myMod->dacs[idac])); - } - - // send adc - n = sendData(file_des,myMod->adcs,sizeof(int)*nAdcs,INT32); + // dacs + n = sendData(file_des,myMod->dacs, sizeof(int)*(myMod->ndac), INT32); if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("adcs of size %d sent\n", ts)); - - // some detectors dont require sending all trimbits etc. - if(sendAll) { - // chips - n = sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32); - if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("chips of size %d sent\n", ts)); - - // channels - n = sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32); - FILE_LOG(logDEBUG5, ("chans of size %d sent - %d\n", ts, myMod->nchan)); - if (!n) return -1; ts += n; - } - + // adcs + n = sendData(file_des,myMod->adcs, sizeof(int)*(myMod->nadc), INT32); + if (!n) return -1; ts += n; + // channels +#ifdef EIGERD + n = sendData(file_des,myMod->chanregs, sizeof(int) * (myMod->nchan), INT32); + if (!n) return -1; ts += n; +#endif FILE_LOG(logDEBUG5, ("module of size %d sent register %x\n", ts, myMod->reg)); return ts; } @@ -416,149 +388,57 @@ int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) { 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, n = 0; - int *dacptr = myMod->dacs; - int *adcptr = myMod->adcs; - int *chipptr = myMod->chipregs, *chanptr = myMod->chanregs; - int nChips, nchipold = myMod->nchip, nchipdiff; - int nChans, nchanold = myMod->nchan, nchandiff; - int nDacs, ndold = myMod->ndac, ndacdiff; - int nAdcs, naold = myMod->nadc, nadcdiff; - n = receiveData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER); - if (!n) return -1; ts += n; - n = receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER); - if (!n) return -1; ts += n; - - myMod->dacs = dacptr; - myMod->adcs = adcptr; - myMod->chipregs = chipptr; - myMod->chanregs = chanptr; - + int nDacs = myMod->ndac; + int nAdcs = myMod->nadc; #ifdef EIGERD -//exclude sending of trimbtis, nchips = 0,nchans = 0 in that case - if(myMod->nchip == 0 && myMod->nchan == 0) { - receiveAll = 0; - nchipold = 0; - nchanold = 0; - } + int nChans = myMod->nchan; // can be zero for no trimbits #endif - - - nChips = myMod->nchip; - nchipdiff = nChips-nchipold; - if (nchipold != nChips) { - FILE_LOG(logERROR, ("received wrong number of chips\n")); + n = receiveData(file_des,&(myMod->serialnumber), sizeof(myMod->serialnumber), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->nchan), sizeof(myMod->nchan), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->nchip), sizeof(myMod->nchip), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->ndac), sizeof(myMod->ndac), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->nadc), sizeof(myMod->nadc), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->reg), sizeof(myMod->reg), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->iodelay), sizeof(myMod->iodelay), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->tau), sizeof(myMod->tau), INT32); + if (!n) return -1; ts += n; + n = receiveData(file_des,&(myMod->eV), sizeof(myMod->eV), INT32); + if (!n) return -1; ts += n; + // dacs + if (nDacs != (myMod->ndac)) { + FILE_LOG(logERROR, ("received wrong number of dacs. " + "Expected %d, got %d\n", nDacs, myMod->ndac)); + return 0; } - else - FILE_LOG(logDEBUG5, ("received %d chips\n",nChips)); - - nChans = myMod->nchan; - nchandiff = nChans-nchanold; - if (nchanold != nChans) { - FILE_LOG(logERROR, ("received wrong number of channels\n")); + n = receiveData(file_des,&(myMod->dacs), sizeof(int) * (myMod->ndac), INT32); + if (!n) return -1; ts += n; + // adcs + if (nAdcs != (myMod->nadc)) { + FILE_LOG(logERROR, ("received wrong number of adcs. " + "Expected %d, got %d\n", nAdcs, myMod->nadc)); + return 0; } - else - FILE_LOG(logDEBUG5, ("received %d chans\n",nChans)); - - - nDacs = myMod->ndac; - ndacdiff = nDacs-ndold; - if (ndold != nDacs) { - FILE_LOG(logERROR, ("received wrong number of dacs\n")); - } - else - FILE_LOG(logDEBUG5, ("received %d dacs\n",nDacs)); - - nAdcs = myMod->nadc; - nadcdiff = nAdcs-naold; - if (naold != nAdcs) { - FILE_LOG(logERROR, ("received wrong number of adcs\n")); - } - else - FILE_LOG(logDEBUG5, ("received %d adcs\n",nAdcs)); - if (ndacdiff <= 0) { - n = receiveData(file_des,myMod->dacs, sizeof(int)*nDacs,INT32); - if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("dacs received\n")); - int id; - for (id = 0; iddacs[id])); - } else { - dacptr = (int*)malloc(ndacdiff*sizeof(int)); - myMod->ndac = ndold; - n = receiveData(file_des,myMod->dacs, sizeof(int)*ndold,INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,dacptr, sizeof(int)*ndacdiff,INT32); - if (!n) return -1; ts += n; - free(dacptr); - return FAIL; - } - - if (nadcdiff <= 0) { - n = receiveData(file_des,myMod->adcs, sizeof(int)*nAdcs,INT32); - if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("adcs received\n")); - } else { - adcptr = (int*)malloc(nadcdiff*sizeof(int)); - myMod->nadc = naold; - n = receiveData(file_des,myMod->adcs, sizeof(int)*naold,INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,adcptr, sizeof(int)*nadcdiff,INT32); - if (!n) return -1; ts += n; - free(adcptr); - return FAIL; - } - - - // some detectors dont require sending all trimbits etc. - if(receiveAll){ - - if (nchipdiff <= 0) { - n = receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32); - if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("chips received\n")); - } else { - chipptr = (int*)malloc(nchipdiff*sizeof(int)); - myMod->nchip = nchipold; - n = receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32); - if (!n) return -1; ts += n; - free(chipptr); - return FAIL; - } - - if (nchandiff <= 0) { - n = receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32); - if (!n) return -1; ts += n; - FILE_LOG(logDEBUG5, ("chans received\n")); - } else { - chanptr = (int*)malloc(nchandiff*sizeof(int)); - myMod->nchan = nchanold; - n = receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32); - if (!n) return -1; ts += n; - n = receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32); - if (!n) return -1; ts += n; - free(chanptr); - return FAIL; - } + n = receiveData(file_des,&(myMod->adcs), sizeof(int) * (myMod->nadc), INT32); + if (!n) return -1; ts += n; + // channels +#ifdef EIGERD + if (((myMod->nchan) != 0 ) || // no trimbits + (nChans != (myMod->nchan))) { // with trimbits + FILE_LOG(logERROR, ("received wrong number of channels. " + "Expected %d, got %d\n", nChans, (myMod->nchan))); + return 0; } + n = receiveData(file_des,&(myMod->chanregs), sizeof(int) * (myMod->nchan), INT32); + if (!n) return -1; ts += n; +#endif FILE_LOG(logDEBUG5, ("received module of size %d register %x\n",ts,myMod->reg)); return ts; } diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.h b/slsDetectorServers/slsDetectorServer/communication_funcs.h index 0089fc16e..25cb8ef9a 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.h +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.h @@ -38,9 +38,7 @@ int sendDataOnly(int file_des, void* buf,int length); int receiveDataOnly(int file_des, void* buf,int length); int sendModule(int file_des, sls_detector_module *myMod); -int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll); int receiveModule(int file_des, sls_detector_module* myMod); -int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll); /** * Servers sets and prints error message for locked server diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h index 05861f3e0..592083234 100644 --- a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h @@ -102,12 +102,7 @@ int64_t getTimeLeft(enum timerIndex ind); // parameters - module, settings - -#ifdef EIGERD -int setModule(sls_detector_module myMod, int delay); -#else -int setModule(sls_detector_module myMod); -#endif +int setModule(sls_detector_module myMod, char* mess); int getModule(sls_detector_module *myMod); enum detectorSettings setSettings(enum detectorSettings sett); enum detectorSettings getSettings(); @@ -233,10 +228,6 @@ int getTotalNumberOfChannels(); int getNumberOfChips(); int getNumberOfDACs(); int getNumberOfADCs(); -#ifdef EIGERD -int getNumberOfGains(); -int getNumberOfOffsets(); -#endif int getNumberOfChannelsPerChip(); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index ab06fb6e4..94c830ae3 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -156,7 +156,6 @@ const char* getFunctionName(enum detFuncs func) { case F_LOAD_IMAGE: return "F_LOAD_IMAGE"; case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK"; case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK"; - case F_CALIBRATE_PEDESTAL: return "F_CALIBRATE_PEDESTAL"; case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA"; case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS"; case F_SET_CTB_PATTERN: return "F_SET_CTB_PATTERN"; @@ -221,7 +220,6 @@ void function_table() { flist[F_LOAD_IMAGE] = &load_image; flist[F_READ_COUNTER_BLOCK] = &read_counter_block; flist[F_RESET_COUNTER_BLOCK] = &reset_counter_block; - flist[F_CALIBRATE_PEDESTAL] = &calibrate_pedestal; flist[F_ENABLE_TEN_GIGA] = &enable_ten_giga; flist[F_SET_ALL_TRIMBITS] = &set_all_trimbits; flist[F_SET_CTB_PATTERN] = &set_ctb_pattern; @@ -304,7 +302,7 @@ int M_nofunc(int file_des) { memset(mess, 0, sizeof(mess)); // to receive any arguments - int n = 0; + int n = 1; while (n > 0) n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); @@ -320,7 +318,7 @@ int M_nofuncMode(int file_des) { memset(mess, 0, sizeof(mess)); // to receive any arguments - int n = 0; + int n = 1; while (n > 0) n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); @@ -836,112 +834,83 @@ int read_register(int file_des) { int set_module(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - int retval = -1; + enum detectorSettings retval = -1; sls_detector_module module; int *myDac = NULL; int *myAdc = NULL; - int *myChip = NULL; int *myChan = NULL; -#ifdef EIGERD - int ioDelay = -1; - int tau = -1; - int eV = -1; -#endif + module.dacs = NULL; + module.adcs = NULL; + module.chanregs = NULL; // allocate to receive arguments - // infinite loop to break out when FAIL or a final OK - while(1) { - // allocate dacs - myDac = (int*)malloc(getNumberOfDACs() * sizeof(int)); - // error - if (getNumberOfDACs() > 0 && myDac == NULL) { - ret = FAIL; - sprintf(mess, "Could not allocate dacs\n"); - FILE_LOG(logERROR,(mess)); - break; - } + // allocate dacs + myDac = (int*)malloc(getNumberOfDACs() * sizeof(int)); + // error + if (getNumberOfDACs() > 0 && myDac == NULL) { + ret = FAIL; + sprintf(mess, "Could not allocate dacs\n"); + FILE_LOG(logERROR,(mess)); + } else module.dacs = myDac; - // allocate adcs + // allocate adcs + if (ret == OK) { myAdc = (int*)malloc(getNumberOfADCs() * sizeof(int)); // error if (getNumberOfADCs() > 0 && myAdc == NULL) { ret = FAIL; sprintf(mess,"Could not allocate adcs\n"); FILE_LOG(logERROR,(mess)); - break; - } - module.adcs=myAdc; + } else + module.adcs = myAdc; + } - // no need to allocate chips and chans for jungfrau, too much memory -#ifdef JUNGFRAUD - module.chipregs = NULL; - module.chanregs = NULL; -#else - // allocate chips - myChip = (int*)malloc(getNumberOfChips() * sizeof(int)); - if (getNumberOfChips() > 0 && myChip == NULL) { - ret = FAIL; - sprintf(mess,"Could not allocate chips\n"); - FILE_LOG(logERROR,(mess)); - break; - } - module.chipregs = myChip; - - // allocate chans + // allocate chans +#ifdef EIGERD + if (ret == OK) { myChan = (int*)malloc(getTotalNumberOfChannels() * sizeof(int)); if (getTotalNumberOfChannels() > 0 && myChan == NULL) { ret = FAIL; sprintf(mess,"Could not allocate chans\n"); FILE_LOG(logERROR,(mess)); - break; - } - module.chanregs=myChan; + } else + module.chanregs = myChan; + } #endif + // receive arguments + if (ret == OK) { module.nchip = getNumberOfChips(); module.nchan = getTotalNumberOfChannels(); module.ndac = getNumberOfDACs(); module.nadc = getNumberOfADCs(); - - // receive arguments (0 to partially receive module without trimbits - if (receiveModuleGeneral(file_des, &module, (myDetectorType == JUNGFRAU) ? 0 : 1) < 0) { - if (myChip != NULL) free(myChip); - if (myChan != NULL) free(myChan); + int ts = receiveModule(file_des, &module); + if (ts < 0) { + if (myChan != NULL) free(myChan); if (myDac != NULL) free(myDac); if (myAdc != NULL) free(myAdc); return printSocketReadError(); } FILE_LOG(logDEBUG5, ("module register is %d, nchan %d, nchip %d, " - "ndac %d, nadc %d, gain %f, offset %f\n", + "ndac %d, nadc %d, iodelay %d, tau %d, eV %d\n", module.reg, module.nchan, module.nchip, - module.ndac, module.nadc, module.gain,module.offset)); - -#ifdef EIGERD - int args[3] = {-1, -1}; - if (receiveData(file_des, args, sizeof(args), INT32) < 0) { - if (myChip != NULL) free(myChip); - if (myChan != NULL) free(myChan); - if (myDac != NULL) free(myDac); - if (myAdc != NULL) free(myAdc); - return printSocketReadError(); - } - ioDelay = args[0]; - tau = args[1]; - eV = args[2]; - FILE_LOG(logDEBUG5, ("ioDelay: %d, tau: d, ev:%d\n", ioDelay, tau, eV)); -#endif + module.ndac, module.nadc, module.iodelay, module.tau, module.eV)); + // should at least have a dac + if (ts <= sizeof(sls_detector_module)) { + ret = FAIL; + sprintf(mess, "Cannot set module. Received incorrect number of dacs or adcs or channels\n"); + FILE_LOG(logERROR,(mess)); + } } - // receive all arguments if (ret == FAIL) { - int n = 0; + int n = 1; while (n > 0) n = receiveData(file_des, mess, MAX_STR_LENGTH, OTHER); } - // only set else if (Server_VerifyLock() != FAIL) { // check index @@ -972,52 +941,12 @@ int set_module(int file_des) { break; } - // set -#ifndef EIGERD - retval = setModule(module); - validate(module.reg, retval, "set module (settings)", 0); - // eiger -#else - //set dacs, trimbits and iodelay - ret = setModule(module, ioDelay); - //set threshhold - if (eV >= 0) - setThresholdEnergy(eV); - else { - //changes settings to undefined (loading a random trim file) - setSettings(UNDEFINED); - FILE_LOG(logERROR, ("Settings has been changed to undefined " - "(random trim file)\n")); - } - //rate correction - //switch off rate correction: no value read from load calib/load settings) - if (tau == -1) { - if (getRateCorrectionEnable()) { - setRateCorrection(0); - ret = FAIL; - sprintf(mess,"Cannot set module. Cannot set Rate correction. " - "No default tau provided. Deactivating Rate Correction\n"); - FILE_LOG(logERROR, (mess)); - } - } - //normal tau value (only if enabled) - else { - setDefaultSettingsTau_in_nsec(tau); - if (getRateCorrectionEnable()) { - int64_t retvalTau = setRateCorrection(tau); - if (tau != retvalTau) { - ret = FAIL; - sprintf(mess, "Cannot set module. Could not set rate correction\n"); - FILE_LOG(logERROR, (mess)); - } - } - } + ret = setModule(module, mess); retval = getSettings(); -#endif + validate(module.reg, (int)retval, "set module (settings)", 0); FILE_LOG(logDEBUG5, ("Settings: %d\n", retval)); } - if (myChip != NULL) free(myChip); - if (myChan != NULL) free(myChan); + if (myChan != NULL) free(myChan); if (myDac != NULL) free(myDac); if (myAdc != NULL) free(myAdc); return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); @@ -1026,70 +955,55 @@ int set_module(int file_des) { - - - - int get_module(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); sls_detector_module module; int *myDac = NULL; int *myAdc = NULL; - int *myChip = NULL; int *myChan = NULL; + module.dacs = NULL; + module.adcs = NULL; + module.chanregs = NULL; // allocate to send arguments - // infinite loop to break out when FAIL or a final OK - while(1) { - - // allocate dacs - myDac = (int*)malloc(getNumberOfDACs() * sizeof(int)); - // error - if (getNumberOfDACs() > 0 && myDac == NULL) { - ret = FAIL; - sprintf(mess, "Could not allocate dacs\n"); - FILE_LOG(logERROR,(mess)); - break; - } + // allocate dacs + myDac = (int*)malloc(getNumberOfDACs() * sizeof(int)); + // error + if (getNumberOfDACs() > 0 && myDac == NULL) { + ret = FAIL; + sprintf(mess, "Could not allocate dacs\n"); + FILE_LOG(logERROR,(mess)); + } else module.dacs = myDac; - // allocate adcs + // allocate adcs + if (ret == OK) { myAdc = (int*)malloc(getNumberOfADCs() * sizeof(int)); // error if (getNumberOfADCs() > 0 && myAdc == NULL) { ret = FAIL; sprintf(mess,"Could not allocate adcs\n"); FILE_LOG(logERROR,(mess)); - break; - } - module.adcs=myAdc; + } else + module.adcs=myAdc; + } - // no need to allocate chips and chans for jungfrau, too much memory -#ifdef JUNGFRAUD - module.chipregs = NULL; - module.chanregs = NULL; -#else - // allocate chips - myChip = (int*)malloc(getNumberOfChips() * sizeof(int)); - if (getNumberOfChips() > 0 && myChip == NULL) { - ret = FAIL; - sprintf(mess,"Could not allocate chips\n"); - FILE_LOG(logERROR,(mess)); - break; - } - module.chipregs = myChip; - - // allocate chans + // allocate chans +#ifdef EIGERD + if (ret == OK) { myChan = (int*)malloc(getTotalNumberOfChannels() * sizeof(int)); if (getTotalNumberOfChannels() > 0 && myChan == NULL) { ret = FAIL; sprintf(mess,"Could not allocate chans\n"); FILE_LOG(logERROR,(mess)); - break; - } - module.chanregs=myChan; + } else + module.chanregs=myChan; + } #endif + + // get module + if (ret == OK) { module.nchip = getNumberOfChips(); module.nchan = getTotalNumberOfChannels(); module.ndac = getNumberOfDACs(); @@ -1105,10 +1019,9 @@ int get_module(int file_des) { // send module, 0 is to receive partially (without trimbits etc) if (ret != FAIL) { - ret = sendModuleGeneral(file_des, &module, (myDetectorType == JUNGFRAU) ? 0 : 1); + ret = sendModule(file_des, &module); } - if (myChip != NULL) free(myChip); - if (myChan != NULL) free(myChan); + if (myChan != NULL) free(myChan); if (myDac != NULL) free(myDac); if (myAdc != NULL) free(myAdc); return ret; @@ -2014,7 +1927,6 @@ int load_image(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); int args[2] = {-1, -1}; - int retval = -1; if (receiveData(file_des, args, sizeof(args), INT32) < 0) return printSocketReadError(); @@ -2039,10 +1951,9 @@ int load_image(int file_des) { switch (index) { case DARK_IMAGE : case GAIN_IMAGE : - retval = loadImage(index, ImageVals); - FILE_LOG(logDEBUG5, ("Loading image retval: %d\n", retval)); - if (retval == -1) { - ret = FAIL; + ret = loadImage(index, ImageVals); + FILE_LOG(logDEBUG5, ("Loading image ret: %d\n", ret)); + if (ret == FAIL) { sprintf(mess, "Could not load image\n"); FILE_LOG(logERROR,(mess)); } @@ -2053,7 +1964,7 @@ int load_image(int file_des) { } } #endif - return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); + return Server_SendResult(file_des, INT32, 1, NULL, 0); } @@ -2096,8 +2007,6 @@ int reset_counter_block(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); int startACQ = -1; - char retval[dataBytes]; - memset(retval, 0, dataBytes); if (receiveData(file_des, &startACQ, sizeof(startACQ), INT32) < 0) return printSocketReadError(); @@ -2109,7 +2018,7 @@ int reset_counter_block(int file_des) { // only set if (Server_VerifyLock() != FAIL) { - ret = resetCounterBlock(startACQ, retval); + ret = resetCounterBlock(startACQ); if (ret == FAIL) { strcpy(mess, "Could not reset counter block\n"); FILE_LOG(logERROR, (mess)); @@ -2123,27 +2032,6 @@ int reset_counter_block(int file_des) { -int calibrate_pedestal(int file_des) { - ret = OK; - memset(mess, 0, sizeof(mess)); - int frames = -1; - int retval = -1; - - if (receiveData(file_des, &frames, sizeof(frames), INT32) < 0) - return printSocketReadError(); - FILE_LOG(logDEBUG5, ("Calibrate pedestal, frames: %d\n", frames)); - - functionNotImplemented(); - return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); -} - - - - - - - - int enable_ten_giga(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2215,12 +2103,12 @@ int set_ctb_pattern(int file_des) { int write_adc_register(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - int args[2] = {-1, -1}; + uint32_t args[2] = {-1, -1}; if (receiveData(file_des, args, sizeof(args), INT32) < 0) return printSocketReadError(); - int addr = args[0]; - int val = args[1]; + uint32_t addr = args[0]; + uint32_t val = args[1]; FILE_LOG(logDEBUG5, ("Writing 0x%x to ADC Register 0x%x\n", val, addr)); #ifndef JUNGFRAUD @@ -2484,7 +2372,7 @@ int program_fpga(int file_des) { FILE_LOG(logDEBUG5, ("Programming FPGA\n")); #ifndef JUNGFRAUD //to receive any arguments - int n = 0; + int n = 1; while (n > 0) n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); functionNotImplemented(); @@ -2708,7 +2596,7 @@ int prepare_acquisition(int file_des) { - +// stop server int threshold_temp(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2738,11 +2626,11 @@ int threshold_temp(int file_des) { } } #endif - return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); + return Server_SendResult(file_des, INT32, 0, &retval, sizeof(retval)); } - +// stop server int temp_control(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2763,12 +2651,12 @@ int temp_control(int file_des) { validate(arg, retval, "set temperature control", 0); } #endif - return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); + return Server_SendResult(file_des, INT32, 0, &retval, sizeof(retval)); } - +// stop server int temp_event(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2789,7 +2677,7 @@ int temp_event(int file_des) { validate(arg, retval, "set temperature event", 0); } #endif - return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); + return Server_SendResult(file_des, INT32, 0, &retval, sizeof(retval)); } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index ae4e2f10c..f7e69bc84 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -2196,14 +2196,7 @@ int multiSlsDetector::writeAdcRegister(int addr, int val, int detPos) { // multi auto r = parallelCall(&slsDetector::writeAdcRegister, addr, val); - if (sls::allEqual(r)) - return r.front(); - - // can't have different values - FILE_LOG(logERROR) << "Error: Different Values for function writeAdcRegister " - "(write 0x" << std::hex << val << " to addr 0x" << std::hex << addr << std::dec << ")"; - setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES); - return -1; + return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; } @@ -2458,33 +2451,22 @@ int multiSlsDetector::setAutoComparatorDisableMode(int ival, int detPos) { } -int multiSlsDetector::getChanRegs(double* retval, bool fromDetector, int detPos) { +int multiSlsDetector::getChanRegs(double* retval, int detPos) { int offset = 0; std::vector r; for (auto& d : detectors) { int nch = d->getTotalNumberOfChannels(); double result[nch]; - r.push_back(d->getChanRegs(result, fromDetector)); + r.push_back(d->getChanRegs(result)); memcpy(retval + offset, result, nch * sizeof(double)); } return sls::minusOneIfDifferent(r); } -int multiSlsDetector::calibratePedestal(int frames, int detPos) { - // single - if (detPos >= 0) { - return detectors[detPos]->calibratePedestal(frames); - } - // multi - auto r = parallelCall(&slsDetector::calibratePedestal, frames); - return sls::minusOneIfDifferent(r); -} - - -int multiSlsDetector::setRateCorrection(int t, int detPos) { +int multiSlsDetector::setRateCorrection(int64_t t, int detPos) { // single if (detPos >= 0) { return detectors[detPos]->setRateCorrection(t); @@ -2496,7 +2478,7 @@ int multiSlsDetector::setRateCorrection(int t, int detPos) { } -int multiSlsDetector::getRateCorrection(int detPos) { +int64_t multiSlsDetector::getRateCorrection(int detPos) { // single if (detPos >= 0) { return detectors[detPos]->getRateCorrection(); @@ -2508,15 +2490,14 @@ int multiSlsDetector::getRateCorrection(int detPos) { } -int multiSlsDetector::printReceiverConfiguration(int detPos) { +void multiSlsDetector::printReceiverConfiguration(int detPos) { // single if (detPos >= 0) { return detectors[detPos]->printReceiverConfiguration(); } // multi - auto r = parallelCall(&slsDetector::printReceiverConfiguration); - return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; + parallelCall(&slsDetector::printReceiverConfiguration); } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 7dd5d5c49..9c64d1c61 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1153,21 +1153,10 @@ public: /** * Returns the trimbits from the detector's shared memmory (Mythen, Eiger) * @param retval is the array with the trimbits - * @param fromDetector is true if the trimbits shared memory have to be - * uploaded from detector * @param detPos -1 for all detectors in list or specific detector position * @returns total number of channels for the detector */ - int getChanRegs(double* retval,bool fromDetector, int detPos = -1); - - /** - * Calibrate Pedestal (ChipTestBoard) - * Starts acquisition, calibrates pedestal and writes to fpga - * @param frames number of frames - * @param detPos -1 for all detectors in list or specific detector position - * @returns number of frames - */ - int calibratePedestal(int frames = 0, int detPos = -1); + int getChanRegs(double* retval, int detPos = -1); /** * Set Rate correction ( Eiger) @@ -1177,21 +1166,20 @@ public: * @param detPos -1 for all detectors in list or specific detector position * @returns 0 if rate correction disabled, >0 otherwise */ - int setRateCorrection(int t=0, int detPos = -1); + int setRateCorrection(int64_t t = 0, int detPos = -1); /** * Get rate correction ( Eiger) * @param detPos -1 for all detectors in list or specific detector position * @returns 0 if rate correction disabled, > 0 otherwise (ns) */ - int getRateCorrection(int detPos = -1); + int64_t getRateCorrection(int detPos = -1); /** * Prints receiver configuration * @param detPos -1 for all detectors in list or specific detector position - * @returns OK or FAIL */ - int printReceiverConfiguration(int detPos = -1); + void printReceiverConfiguration(int detPos = -1); /** * Sets up receiver socket if online and sets the flag diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index a8092b5f6..0adf416d2 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -36,10 +36,7 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify) detectorModules(0), dacs(0), adcs(0), - chipregs(0), - chanregs(0), - gain(0), - offset(0) { + chanregs(0) { /* called from put hostname command, * so sls shared memory will be created */ @@ -71,10 +68,7 @@ slsDetector::slsDetector(int multiId, int id, bool verify) detectorModules(0), dacs(0), adcs(0), - chipregs(0), - chanregs(0), - gain(0), - offset(0) { + chanregs(0) { /* called from multi constructor to populate structure, * so sls shared memory will be opened, not created */ @@ -322,8 +316,6 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL list.nChipY = 1; list.nDacs = 8; list.nAdcs = 5; - list.nGain = 0; - list.nOffset = 0; list.dynamicRange = 16; list.nGappixelsX = 0; list.nGappixelsY = 0; @@ -335,8 +327,6 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL list.nChipY = 2; list.nDacs = 16; list.nAdcs = 0; - list.nGain = 0; - list.nOffset = 0; list.dynamicRange = 16; list.nGappixelsX = 0; list.nGappixelsY = 0; @@ -348,8 +338,6 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL list.nChipY = 1; list.nDacs = 16; list.nAdcs = 9;//???? When calculating size, only d+a=16 how come?FIXME - list.nGain = 0; - list.nOffset = 0; list.dynamicRange =16; list.nGappixelsX = 0; list.nGappixelsY = 0; @@ -361,8 +349,6 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL list.nChipY = 1; list.nDacs = 16; list.nAdcs = 0; - list.nGain = 0; // can be set back to 4 in case we require it again - list.nOffset = 0; // can be set back to 4 in case we require it again list.dynamicRange = 16; list.nGappixelsX = 6; list.nGappixelsY = 1; @@ -381,20 +367,15 @@ int slsDetector::calculateSharedMemorySize(detectorType type) { int nch = detlist.nChanX * detlist.nChanY; int nc = detlist.nChipX * detlist.nChipY; int nd = detlist.nDacs + detlist.nAdcs; - int ng = detlist.nGain; - int no = detlist.nOffset; /** The size of the shared memory is * size of shared structure + - * ffcoefficents+fferrors+modules+dacs+adcs+chips+chans+gain+offset */ + * ffcoefficents+fferrors+modules+dacs+adcs+chans */ int sz = sizeof(sharedSlsDetector) + 2 * nch * nc * sizeof(double) + sizeof(sls_detector_module) + - sizeof(int) * nc + sizeof(int) * nd + - sizeof(int) * nch * nc + - sizeof(int) * ng + - sizeof(int) * no; + sizeof(int) * nch * nc; FILE_LOG(logDEBUG5) << "Size of shared memory is " << sz; return sz; } @@ -505,8 +486,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) { thisDetector->nChip[Y] = detlist.nChipY; thisDetector->nDacs = detlist.nDacs; thisDetector->nAdcs = detlist.nAdcs; - thisDetector->nGain = detlist.nGain; - thisDetector->nOffset = detlist.nOffset; thisDetector->dynamicRange = detlist.dynamicRange; thisDetector->nGappixels[X] = detlist.nGappixelsX; thisDetector->nGappixels[Y] = detlist.nGappixelsY; @@ -539,15 +518,8 @@ void slsDetector::initializeDetectorStructure(detectorType type) { sizeof(sls_detector_module); thisDetector->adcoff = thisDetector->dacoff + sizeof(int) * thisDetector->nDacs; - thisDetector->chipoff = thisDetector->adcoff + - sizeof(int) * thisDetector->nAdcs; - thisDetector->chanoff = thisDetector->chipoff + + thisDetector->chanoff = thisDetector->adcoff + sizeof(int) * thisDetector->nChips; - thisDetector->gainoff = thisDetector->chanoff + - sizeof(int) * thisDetector->nGain; - thisDetector->offsetoff = thisDetector->gainoff + - sizeof(int) * thisDetector->nOffset; - } @@ -558,10 +530,7 @@ void slsDetector::initializeMembers() { detectorModules = (sls_detector_module*)(goff + thisDetector->modoff); dacs = (int*)(goff + thisDetector->dacoff); adcs = (int*)(goff + thisDetector->adcoff); - chipregs = (int*)(goff + thisDetector->chipoff); chanregs = (int*)(goff + thisDetector->chanoff); - gain = (int*)(goff + thisDetector->gainoff); - offset = (int*)(goff + thisDetector->offsetoff); if (thisDetectorControl) { delete thisDetectorControl; thisDetectorControl = 0; @@ -594,11 +563,12 @@ void slsDetector::initializeDetectorStructurePointers() { thisMod->ndac = thisDetector->nDacs; thisMod->nadc = thisDetector->nAdcs; thisMod->reg = 0; - // dacs, adcs, chipregs and chanregs for thisMod is not allocated in + thisMod->iodelay = 0; + thisMod->tau = 0; + thisMod->eV = 0; + // dacs, adcs and chanregs for thisMod is not allocated in // detectorModules in shared memory as they are already allocated separately // in shared memory (below) - thisMod->gain = -1.; - thisMod->offset = -1.; // initializes the dacs values to 0 for (int i = 0; i < thisDetector->nDacs; ++i) { @@ -608,22 +578,10 @@ void slsDetector::initializeDetectorStructurePointers() { for (int i = 0; i < thisDetector->nAdcs; ++i) { *(adcs + i) = 0; } - // initializes the chip registers to 0 - for (int i = 0; i < thisDetector->nChips; ++i) { - *(chipregs + i) = -1; - } // initializes the channel registers to 0 for (int i = 0; i < thisDetector->nChans * thisDetector->nChips; ++i) { *(chanregs + i) = -1; } - // initializes the gain values to 0 - for (int i = 0; i < thisDetector->nGain; ++i) { - *(gain + i) = 0; - } - // initializes the offset values to 0 - for (int i = 0; i < thisDetector->nOffset; ++i) { - *(offset + i) = 0; - } } @@ -647,7 +605,6 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType ty } int *dacs = new int[nd]; int *adcs = new int[na]; - int *chipregs = new int[nc]; int *chanregs = new int[nch*nc]; sls_detector_module *myMod = (sls_detector_module*)malloc(sizeof(sls_detector_module)); @@ -657,7 +614,6 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType ty myMod->nchan = nch*nc; myMod->dacs = dacs; myMod->adcs = adcs; - myMod->chipregs = chipregs; myMod->chanregs = chanregs; return myMod; } @@ -666,7 +622,6 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType ty void slsDetector::deleteModule(sls_detector_module *myMod) { delete [] myMod->dacs; delete [] myMod->adcs; - delete [] myMod->chipregs; delete [] myMod->chanregs; delete myMod; } @@ -735,67 +690,47 @@ void slsDetector::disconnectStop() { int slsDetector::sendModule(sls_detector_module *myMod) { int ts = 0; - //send module structure - ts += controlSocket->SendDataOnly(&(myMod->serialnumber),sizeof(myMod->serialnumber)); - ts += controlSocket->SendDataOnly(&(myMod->nchan),sizeof(myMod->nchan)); - ts += controlSocket->SendDataOnly(&(myMod->nchip),sizeof(myMod->nchip)); - ts += controlSocket->SendDataOnly(&(myMod->ndac),sizeof(myMod->ndac)); - ts += controlSocket->SendDataOnly(&(myMod->nadc),sizeof(myMod->nadc)); - ts += controlSocket->SendDataOnly(&(myMod->reg),sizeof(myMod->reg)); - ts += controlSocket->SendDataOnly(&(myMod->gain),sizeof(myMod->gain)); - ts += controlSocket->SendDataOnly(&(myMod->offset), sizeof(myMod->offset)); + ts += controlSocket->SendDataOnly(&(myMod->serialnumber), sizeof(myMod->serialnumber)); + ts += controlSocket->SendDataOnly(&(myMod->nchan), sizeof(myMod->nchan)); + ts += controlSocket->SendDataOnly(&(myMod->nchip), sizeof(myMod->nchip)); + ts += controlSocket->SendDataOnly(&(myMod->ndac), sizeof(myMod->ndac)); + ts += controlSocket->SendDataOnly(&(myMod->nadc), sizeof(myMod->nadc)); + ts += controlSocket->SendDataOnly(&(myMod->reg), sizeof(myMod->reg)); + ts += controlSocket->SendDataOnly(&(myMod->iodelay), sizeof(myMod->iodelay)); + ts += controlSocket->SendDataOnly(&(myMod->tau), sizeof(myMod->tau)); + ts += controlSocket->SendDataOnly(&(myMod->eV), sizeof(myMod->eV)); - // actual data to the pointers - ts += controlSocket->SendDataOnly(myMod->dacs,sizeof(int)*(myMod->ndac)); - ts += controlSocket->SendDataOnly(myMod->adcs,sizeof(int)*(myMod->nadc)); - if (thisDetector->myDetectorType != JUNGFRAU) { - ts += controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); - ts += controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); + ts += controlSocket->SendDataOnly(myMod->dacs, sizeof(int) * (myMod->ndac)); + ts += controlSocket->SendDataOnly(myMod->adcs, sizeof(int) * (myMod->nadc)); + if (thisDetector->myDetectorType == EIGER) { + ts += controlSocket->SendDataOnly(myMod->chanregs, sizeof(int) * (myMod->nchan)); } return ts; } int slsDetector::receiveModule(sls_detector_module* myMod) { - - int *dacptr = myMod->dacs; - int *adcptr = myMod->adcs; - int *chipptr = myMod->chipregs; - int *chanptr = myMod->chanregs; int ts = 0; - //send module structure - ts += controlSocket->ReceiveDataOnly(&(myMod->serialnumber),sizeof(myMod->serialnumber)); - ts += controlSocket->ReceiveDataOnly(&(myMod->nchan),sizeof(myMod->nchan)); - ts += controlSocket->ReceiveDataOnly(&(myMod->nchip),sizeof(myMod->nchip)); - ts += controlSocket->ReceiveDataOnly(&(myMod->ndac),sizeof(myMod->ndac)); - ts += controlSocket->ReceiveDataOnly(&(myMod->nadc),sizeof(myMod->nadc)); - ts += controlSocket->ReceiveDataOnly(&(myMod->reg),sizeof(myMod->reg)); - 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; - FILE_LOG(logDEBUG5) << "received module of size "<< ts << " register " << myMod->reg; + ts += controlSocket->ReceiveDataOnly(&(myMod->serialnumber), sizeof(myMod->serialnumber)); + ts += controlSocket->ReceiveDataOnly(&(myMod->nchan), sizeof(myMod->nchan)); + ts += controlSocket->ReceiveDataOnly(&(myMod->nchip), sizeof(myMod->nchip)); + ts += controlSocket->ReceiveDataOnly(&(myMod->ndac), sizeof(myMod->ndac)); + ts += controlSocket->ReceiveDataOnly(&(myMod->nadc), sizeof(myMod->nadc)); + ts += controlSocket->ReceiveDataOnly(&(myMod->reg), sizeof(myMod->reg)); + ts += controlSocket->ReceiveDataOnly(&(myMod->iodelay), sizeof(myMod->iodelay)); + ts += controlSocket->ReceiveDataOnly(&(myMod->tau), sizeof(myMod->tau)); + ts += controlSocket->ReceiveDataOnly(&(myMod->eV), sizeof(myMod->eV)); ts += controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(int)*(myMod->ndac)); FILE_LOG(logDEBUG5) << "received dacs of size "<< ts; - ts += controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(int)*(myMod->nadc)); FILE_LOG(logDEBUG5) << "received adc of size "<< ts; - - if (thisDetector->myDetectorType != JUNGFRAU) { - ts += controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); - FILE_LOG(logDEBUG5) << "received chips of size "<< ts; - - ts += controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); + if (thisDetector->myDetectorType == EIGER) { + ts += controlSocket->ReceiveDataOnly(myMod->chanregs, sizeof(int)*(myMod->nchan)); FILE_LOG(logDEBUG5) << "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips << "mod - nchans= " << myMod->nchan << " nchips= " <nchip; << "received chans of size "<< ts; } - FILE_LOG(logDEBUG5) << "received module of size "<< ts << " register " << myMod->reg; return ts; } @@ -1010,11 +945,11 @@ void slsDetector::updateMultiSize(int detx, int dety) { int slsDetector::setOnline(int off) { - int old = thisDetector->onlineFlag; - // setting it online/offline if (off != GET_ONLINE_FLAG) { thisDetector->onlineFlag = off; + // set online if (thisDetector->onlineFlag == ONLINE_FLAG) { + int old = thisDetector->onlineFlag; setTCPSocket(); // connecting first time if (thisDetector->onlineFlag == ONLINE_FLAG && old == OFFLINE_FLAG) { @@ -1034,13 +969,13 @@ int slsDetector::setOnline(int off) { std::string slsDetector::checkOnline() { std::string retval; + //if it doesnt exit, create socket and call this function again if (!controlSocket) { - //this already sets the online/offline flag setTCPSocket(); if (thisDetector->onlineFlag == OFFLINE_FLAG) return std::string(thisDetector->hostname); else - return std::string(""); + return retval; } //still cannot connect to socket, controlSocket=0 if (controlSocket) { @@ -1088,8 +1023,8 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in strcpy(thisName,thisDetector->hostname); } else { FILE_LOG(logDEBUG5) << "Setting hostname"; - strcpy(thisName,name.c_str()); - strcpy(thisDetector->hostname,thisName); + strcpy(thisName, name.c_str()); + strcpy(thisDetector->hostname, thisName); if (controlSocket) { delete controlSocket; controlSocket = 0; @@ -1101,7 +1036,9 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in } // control port - if (control_port > 0) { + if (control_port <= 0) { + thisCP = thisDetector->controlPort; + } else { FILE_LOG(logDEBUG5) << "Setting control port"; thisCP = control_port; thisDetector->controlPort = thisCP; @@ -1109,11 +1046,12 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in delete controlSocket; controlSocket = 0; } - } else - thisCP = thisDetector->controlPort; + } // stop port - if (stop_port > 0) { + if (stop_port <= 0) { + thisSP = thisDetector->stopPort; + } else { FILE_LOG(logDEBUG5) << "Setting stop port"; thisSP = stop_port; thisDetector->stopPort = thisSP; @@ -1121,9 +1059,7 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in delete stopSocket; stopSocket = 0; } - } else - thisSP = thisDetector->stopPort; - + } // create control socket if (!controlSocket) { @@ -1342,7 +1278,7 @@ int slsDetector::lockServer(int lock) { std::string slsDetector::getLastClientIP() { - int fnum = F_LOCK_SERVER; + int fnum = F_GET_LAST_CLIENT_IP; int ret = FAIL; char retval[INET_ADDRSTRLEN] = {0}; FILE_LOG(logDEBUG5) << "Getting last client ip to detector server"; @@ -1398,8 +1334,7 @@ int slsDetector::execCommand(std::string cmd) { setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); } else { FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval; - if (ret == FORCE_UPDATE) - ret = updateDetector(); + } } return ret; @@ -1409,7 +1344,7 @@ int slsDetector::execCommand(std::string cmd) { int slsDetector::updateDetectorNoWait() { int n = 0, i32 = 0; int64_t i64 = 0; - char lastClientIP[INET_ADDRSTRLEN]; + char lastClientIP[INET_ADDRSTRLEN] = {0}; n += controlSocket->ReceiveDataOnly(lastClientIP, sizeof(lastClientIP)); FILE_LOG(logDEBUG5) << "Updating detector last modified by " << lastClientIP; @@ -1581,8 +1516,8 @@ std::string slsDetector::getSettingsFile() { } -int slsDetector::writeSettingsFile(std::string fname, int iodelay, int tau) { - return writeSettingsFile(fname, detectorModules[0], iodelay, tau); +int slsDetector::writeSettingsFile(std::string fname) { + return writeSettingsFile(fname, detectorModules[0]); } @@ -1737,8 +1672,6 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti //fill detector module structure sls_detector_module *myMod = NULL; - int iodelay = -1; //not included in the module - int tau = -1; //not included in the module //normal if (!interpolate) { @@ -1751,7 +1684,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti //read the files myMod=createModule(); - if (NULL == readSettingsFile(settingsfname, iodelay, tau, myMod, tb)) { + if (NULL == readSettingsFile(settingsfname, myMod, tb)) { if (myMod)deleteModule(myMod); return FAIL; } @@ -1784,30 +1717,26 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti FILE_LOG(logDEBUG5) << "Settings Files are " << settingsfname1 << " and " << settingsfname2; sls_detector_module *myMod1=createModule(); sls_detector_module *myMod2=createModule(); - int iodelay1 = -1; //not included in the module - int tau1 = -1; //not included in the module - int iodelay2 = -1; //not included in the module - int tau2 = -1; //not included in the module - if (NULL == readSettingsFile(settingsfname1,iodelay1, tau1, myMod1, tb)) { + if (NULL == readSettingsFile(settingsfname1, myMod1, tb)) { setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); deleteModule(myMod1); deleteModule(myMod2); return FAIL; } - if (NULL == readSettingsFile(settingsfname2, iodelay2, tau2, myMod2, tb)) { + if (NULL == readSettingsFile(settingsfname2, myMod2, tb)) { setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); deleteModule(myMod1); deleteModule(myMod2); return FAIL; } - if (iodelay1 != iodelay2) { + if (myMod1->iodelay != myMod2->iodelay) { FILE_LOG(logERROR) << "Iodelays do not match between files"; setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); deleteModule(myMod1); deleteModule(myMod2); return FAIL; } - iodelay = iodelay1; + myMod->iodelay = myMod1->iodelay; //interpolate module myMod = interpolateTrim( myMod1, myMod2, e_eV, trim1, trim2, tb); @@ -1819,7 +1748,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti return FAIL; } //interpolate tau - tau = linearInterpolation(e_eV, trim1, trim2, tau1, tau2); + myMod->tau = linearInterpolation(e_eV, trim1, trim2, myMod1->tau, myMod2->tau); //printf("new tau:%d\n",tau); deleteModule(myMod1); @@ -1827,8 +1756,9 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti } - myMod->reg=thisDetector->currentSettings; - setModule(*myMod, iodelay, tau, e_eV, 0, 0, tb); + myMod->reg = thisDetector->currentSettings; + myMod->eV = e_eV; + setModule(*myMod, tb); deleteModule(myMod); if (getSettings() != is) { FILE_LOG(logERROR) << "Could not set settings in detector"; @@ -1867,15 +1797,14 @@ int slsDetector::loadSettingsFile(std::string fname) { // read settings file sls_detector_module *myMod=NULL; - int iodelay = -1; - int tau = -1; - myMod = readSettingsFile(fn, iodelay, tau, myMod); + myMod = readSettingsFile(fn, myMod); // set module int ret = FAIL; if (myMod != NULL) { myMod->reg = -1; - ret = setModule(*myMod, iodelay, tau, -1, 0, 0); + myMod->eV = -1; + ret = setModule(*myMod); deleteModule(myMod); } return ret; @@ -1898,13 +1827,7 @@ int slsDetector::saveSettingsFile(std::string fname) { int ret = FAIL; sls_detector_module *myMod = NULL; if ((myMod = getModule())) { - int iodelay = -1; - int tau = -1; - if (thisDetector->myDetectorType == EIGER) { - iodelay = (int)setDAC((int)-1, IO_DELAY, 0); - tau = getRateCorrection(); - } - ret = writeSettingsFile(fn, *myMod, iodelay, tau); + ret = writeSettingsFile(fn, *myMod); deleteModule(myMod); } return ret; @@ -2924,7 +2847,7 @@ std::string slsDetector::getReceiverRealUDPSocketBufferSize() { } else { FILE_LOG(logDEBUG5) << "Real Receiver UDP Socket Buffer size: " << retval; if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateReceiver(); } } return std::string(retval); @@ -3175,7 +3098,7 @@ std::string slsDetector::setReceiverStreamingPort(std::string port) { FILE_LOG(logDEBUG5) << "Receiver streaming port: " << retval; thisDetector->receiver_zmqport = retval; if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateReceiver(); } } return getReceiverStreamingPort(); @@ -3248,7 +3171,7 @@ std::string slsDetector::setReceiverStreamingIP(std::string sourceIP) { memset(thisDetector->receiver_zmqip, 0, MAX_STR_LENGTH); strcpy(thisDetector->receiver_zmqip, retvals); if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateReceiver(); } } return getReceiverStreamingIP(); @@ -3275,7 +3198,7 @@ std::string slsDetector::setAdditionalJsonHeader(std::string jsonheader) { memset(thisDetector->receiver_additionalJsonHeader, 0, MAX_STR_LENGTH); strcpy(thisDetector->receiver_additionalJsonHeader, retvals); if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateReceiver(); } } return getAdditionalJsonHeader(); @@ -3299,7 +3222,7 @@ std::string slsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize) { } else { FILE_LOG(logDEBUG5) << "Receiver UDP Socket Buffer size: " << retval; if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateReceiver(); } } return std::to_string(retval); @@ -3309,61 +3232,45 @@ std::string slsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize) { std::string slsDetector::setDetectorNetworkParameter(networkParameter index, int delay) { int fnum = F_SET_NETWORK_PARAMETER; int ret = FAIL; + int args[2] = {(int)index, delay}; int retval = -1; - char mess[MAX_STR_LENGTH]=""; + FILE_LOG(logDEBUG5) << "Setting network parameter index " << index << " to " << delay; -#ifdef VERBOSE - FILE_LOG(logINFO) << "Setting Transmission delay of mode "<< index << " to " << delay << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&index,sizeof(index)); - controlSocket->SendDataOnly(&delay,sizeof(delay)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_NETWORK_PARAMETER)); - } else - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(DETECTOR_NETWORK_PARAMETER)); + } else { + FILE_LOG(logDEBUG5) << "Network Parameter (" << index << "): " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } -#ifdef VERBOSE - FILE_LOG(logINFO) << "Speed set to "<< retval << std::endl; -#endif - - std::ostringstream ss; - ss << retval; - std::string s = ss.str(); - return s; + return std::to_string(retval); } int slsDetector::setUDPConnection() { - - int ret = FAIL; int fnum = F_SETUP_RECEIVER_UDP; + int ret = FAIL; char args[3][MAX_STR_LENGTH] = {0}; - char retval[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + FILE_LOG(logDEBUG5) << "Setting UDP Connection"; - //called before set up - if (!strcmp(thisDetector->receiver_hostname,"none")) { -#ifdef VERBOSE - std::cout << "Warning: Receiver hostname not set yet." << std::endl; -#endif + // called before set up + if (!strcmp(thisDetector->receiver_hostname, "none")) { + FILE_LOG(logDEBUG5) << "Receiver hostname not set yet."; return FAIL; } - - //if no udp ip given, use hostname - if (!strcmp(thisDetector->receiverUDPIP,"none")) { - //hostname is an ip address - if (strchr(thisDetector->receiver_hostname,'.')!=NULL) - strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); - //if hostname not ip, convert it to ip + // if no udp ip given, use hostname + if (!strcmp(thisDetector->receiverUDPIP, "none")) { + // hostname is an ip address + if (strchr(thisDetector->receiver_hostname,'.') != NULL) + strcpy(thisDetector->receiverUDPIP, thisDetector->receiver_hostname); + // if hostname not ip, convert it to ip else { struct addrinfo *result; if (!dataSocket->ConvertHostnameToInternetAddress( @@ -3378,368 +3285,276 @@ int slsDetector::setUDPConnection() { } } } - - //copy arguments to args[][] strcpy(args[0],thisDetector->receiverUDPIP); sprintf(args[1],"%d",thisDetector->receiverUDPPort); sprintf(args[2],"%d",thisDetector->receiverUDPPort2); -#ifdef VERBOSE - std::cout << "Receiver udp ip address: " << thisDetector->receiverUDPIP << std::endl; - std::cout << "Receiver udp port: " << thisDetector->receiverUDPPort << std::endl; - std::cout << "Receiver udp port2: " << thisDetector->receiverUDPPort2 << std::endl; -#endif + FILE_LOG(logDEBUG5) << "Receiver udp ip address: " << thisDetector->receiverUDPIP; + FILE_LOG(logDEBUG5) << "Receiver udp port: " << thisDetector->receiverUDPPort; + FILE_LOG(logDEBUG5) << "Receiver udp port2: " << thisDetector->receiverUDPPort2; - //set up receiver for UDP Connection and get receivermac address - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - std::cout << "Setting up UDP Connection for Receiver " << args[0] << "\t" << args[1] << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &args, sizeof(args), &retval, sizeof(retval)); - disconnectData(); - } - if (ret!=FAIL) { - strcpy(thisDetector->receiverUDPMAC,retval); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, args, sizeof(args), retvals, sizeof(retvals)); + disconnectControl(); -#ifdef VERBOSE - std::cout << "Receiver mac address: " << thisDetector->receiverUDPMAC << std::endl; -#endif - if (ret==FORCE_UPDATE) - updateReceiver(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Receiver UDP MAC returned : " << retvals; + memset(thisDetector->receiverUDPMAC, 0, MAX_STR_LENGTH); + strcpy(thisDetector->receiverUDPMAC, retvals); + if (ret == FORCE_UPDATE) + ret = updateReceiver(); - //configure detector with udp details, -100 is so it doesnt overwrite - //the previous value - if (configureMAC()==FAIL) { - setReceiverOnline(OFFLINE_FLAG); - std::cout << "could not configure mac" << std::endl; + //configure detector with udp details + if (configureMAC() == FAIL) { + setReceiverOnline(OFFLINE_FLAG); //FIXME: Needed?? } } - } else - ret=FAIL; -#ifdef VERBOSE - printReceiverConfiguration(); -#endif + } + printReceiverConfiguration(logDEBUG5); return ret; } - int slsDetector::digitalTest( digitalTestMode mode, int ival) { int fnum = F_DIGITAL_TEST; int ret = FAIL; - int args[2] = {mode, ival}; + int args[2] = {(int)mode, ival}; int retval = -1; - FILE_LOG(logDEBUG5) << "Sending digital test of mode " << mode << ", ival " << ival; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - ret = thisDetectorControl->Client_Send(fnum, - args, sizeof(args), &retval, sizeof(retval)); - disconnectControl(); - // handle ret - if (ret == FAIL) - setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); - else if (ret == FORCE_UPDATE) - updateDetector(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Digital Test returned: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } - if (ret != FAIL && mode == DIGITAL_BIT_TEST) { - FILE_LOG(logDEBUG5) << "Digital test bit: " << retval; - } - return retval; } int slsDetector::loadImageToDetector(imageType index,std::string const fname) { - - int ret=FAIL; - short int arg[thisDetector->nChans*thisDetector->nChips]; - -#ifdef VERBOSE - std::cout<< std::endl<< "Loading "; - if (!index) - std::cout<<"Dark"; - else - std::cout<<"Gain"; - std::cout<<" image from file " << fname << std::endl; -#endif + int ret = FAIL; + short int args[thisDetector->nChans * thisDetector->nChips]; + FILE_LOG(logDEBUG5) << "Loading " << (!index ? "Dark" : "Gain") << "image from file " << fname; if (readDataFile(fname,arg,getTotalNumberOfChannels())) { ret = sendImageToDetector(index,arg); return ret; } - FILE_LOG(logERROR) << "Could not open file "<< fname << std::endl; + + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + FILE_LOG(logERROR) << "Could not open file " << fname; return ret; } - int slsDetector::sendImageToDetector(imageType index,short int imageVals[]) { + int fnum = F_LOAD_IMAGE; + int ret = FAIL; + int arg = (int)isettings; + FILE_LOG(logDEBUG5) << "Sending image to detector"; - int ret=FAIL; - int retval; - int fnum=F_LOAD_IMAGE; - char mess[MAX_STR_LENGTH]=""; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, + imageVals, thisDetector->dataBytes, NULL, 0); + disconnectControl(); -#ifdef VERBOSE - std::cout<<"Sending image to detector " <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&index,sizeof(index)); - controlSocket->SendDataOnly(imageVals,thisDetector->dataBytes); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } - return ret; } - int slsDetector::writeCounterBlockFile(std::string const fname,int startACQ) { -#ifdef VERBOSE - std::cout<< std::endl<< "Reading Counter to \""<nChans*thisDetector->nChips]; - int ret=getCounterBlock(counterVals,startACQ); - if (ret==OK) - ret=writeDataFile(fname, getTotalNumberOfChannels(), counterVals); + int ret = FAIL; + short int retvals[thisDetector->nChans * thisDetector->nChips]; + FILE_LOG(logDEBUG5) << "Reading Counter to " << fname << + (startACQ ? " and Restarting Acquisition" : "\n"); + + ret = getCounterBlock(retvals, startACQ); + if (ret == FAIL) + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + else + ret=writeDataFile(fname, getTotalNumberOfChannels(), retvals); return ret; } -int slsDetector::getCounterBlock(short int arg[],int startACQ) { - int ret=FAIL; - int fnum=F_READ_COUNTER_BLOCK; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&startACQ,sizeof(startACQ)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(arg,thisDetector->dataBytes); - else { - char mess[MAX_STR_LENGTH]=""; - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } +int slsDetector::getCounterBlock(short int image[],int startACQ) { + int fnum = F_READ_COUNTER_BLOCK; + int ret = FAIL; + int arg = startACQ; + FILE_LOG(logDEBUG5) << "Reading Counter block with startacq: " << startACQ; + + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, + &arg, sizeof(arg), image, thisDetector->dataBytes); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } return ret; } int slsDetector::resetCounterBlock(int startACQ) { + int fnum = F_RESET_COUNTER_BLOCK; + int ret = FAIL; + int arg = startACQ; + FILE_LOG(logDEBUG5) << "Resetting Counter with startacq: " << startACQ; - int ret=FAIL; - int fnum=F_RESET_COUNTER_BLOCK; - char mess[MAX_STR_LENGTH]=""; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + disconnectControl(); -#ifdef VERBOSE - std::cout<< std::endl<< "Resetting Counter"; - if (startACQ==1) - std::cout<<" and Restarting Acquisition"; - std::cout<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&startACQ,sizeof(startACQ)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } - return ret; } - - int slsDetector::setCounterBit(int i) { - int fnum=F_SET_COUNTER_BIT; + int fnum = F_SET_COUNTER_BIT; int ret = FAIL; - int retval=-1; - char mess[MAX_STR_LENGTH]=""; + int arg = i; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending counter bit " << arg; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - - FILE_LOG(logINFO) << - ((i == -1) ? "Getting" : ((i == 0) ? "Reseting" : "Setting")) << - " counter bit from detector" << std::endl; - - if (connectControl() == OK) { - - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&i,sizeof(i)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_SET_COUNTER_BIT)); - } - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(COULD_NOT_SET_COUNTER_BIT)); + } else { + FILE_LOG(logDEBUG5) << "Counter bit: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } return retval; } - - int slsDetector::setROI(int n,ROI roiLimits[]) { - int ret = FAIL; - //sort ascending order - int temp; - - for(int i=0;imyDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + int ret = sendROI(n,roiLimits); + if (thisDetector->myDetectorType == JUNGFRAUCTB) + getTotalNumberOfChannels(); return ret; } slsDetectorDefs::ROI* slsDetector::getROI(int &n) { sendROI(-1,NULL); - n=thisDetector->nROI; - if (thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + n = thisDetector->nROI; + if (thisDetector->myDetectorType == JUNGFRAUCTB) + getTotalNumberOfChannels(); return thisDetector->roiLimits; } + int slsDetector::getNRoi() { return thisDetector->nROI; } -int slsDetector::sendROI(int n,ROI roiLimits[]) { - int ret=FAIL; - int fnum=F_SET_ROI; - char mess[MAX_STR_LENGTH]=""; - int arg = n; - int retvalsize=0; +int slsDetector::sendROI(int n, ROI roiLimits[]) { + int fnum = F_SET_ROI; + int ret = FAIL; + int narg = n; + // send roiLimits if given, else from shm + ROI* arg = (roiLimits != NULL) ? roiLimits : thisDetector->roiLimits; + int nretval = 0; ROI retval[MAX_ROIS]; - int nrec=-1; - if (roiLimits==NULL) - roiLimits=thisDetector->roiLimits; + FILE_LOG(logDEBUG5) << "Sending ROI to detector" << narg; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - if (arg==-1) {; -#ifdef VERBOSE - std::cout << "Getting ROI from detector" << std::endl; -#endif - } else { -#ifdef VERBOSE - std::cout << "Sending ROI of size " << arg << " to detector" << std::endl; -#endif - for(int i = 0; i < n; ++i) { - controlSocket->SendDataOnly(&roiLimits[i].xmin, sizeof(int)); - controlSocket->SendDataOnly(&roiLimits[i].xmax, sizeof(int)); - controlSocket->SendDataOnly(&roiLimits[i].ymin, sizeof(int)); - controlSocket->SendDataOnly(&roiLimits[i].ymax, sizeof(int)); - } - //controlSocket->SendDataOnly(roiLimits,arg*sizeof(ROI)); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + controlSocket->SendDataOnly(&fnum, sizeof(fnum)); + controlSocket->SendDataOnly(&narg, sizeof(narg)); + if (narg != -1) { + for(int i = 0; i < narg; ++i) { + controlSocket->SendDataOnly(&arg[i].xmin, sizeof(int)); + controlSocket->SendDataOnly(&arg[i].xmax, sizeof(int)); + controlSocket->SendDataOnly(&arg[i].ymin, sizeof(int)); + controlSocket->SendDataOnly(&arg[i].ymax, sizeof(int)); } - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retvalsize,sizeof(retvalsize)); - nrec = 0; - - for(int i = 0; i < retvalsize; ++i) { - nrec += controlSocket->ReceiveDataOnly(&retval[i].xmin, sizeof(int)); - nrec += controlSocket->ReceiveDataOnly(&retval[i].xmax, sizeof(int)); - nrec += controlSocket->ReceiveDataOnly(&retval[i].ymin, sizeof(int)); - nrec += controlSocket->ReceiveDataOnly(&retval[i].ymax, sizeof(int)); - } - //nrec = controlSocket->ReceiveDataOnly(retval,retvalsize*sizeof(ROI)); - if (nrec!=(retvalsize*(int)sizeof(ROI))) { - ret=FAIL; - std::cout << " wrong size received: received " << nrec << - "but expected " << retvalsize*sizeof(ROI) << std::endl; - } - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); } - } + controlSocket->ReceiveDataOnly(&ret, sizeof(ret)); - //update client - if (ret==FAIL) { - setErrorMask((getErrorMask())|(COULDNOT_SET_ROI)); - } else { - for(int i=0;iroiLimits[i]=retval[i]; - thisDetector->nROI = retvalsize; - } + // handle ret + if (ret == FAIL) { + char mess[MAX_STR_LENGTH] = {0}; + setErrorMask((getErrorMask())|(COULDNOT_SET_ROI)); + controlSocket->ReceiveDataOnly(mess, MAX_STR_LENGTH); + FILE_LOG(logERROR) << "Detector " << detId << " returned error: " << mess; + } else { + controlSocket->ReceiveDataOnly(&nretval, sizeof(nretval)); + int nrec = 0; + for(int i = 0; i < nretval; ++i) { + nrec += controlSocket->ReceiveDataOnly(&retval[i].xmin, sizeof(int)); + nrec += controlSocket->ReceiveDataOnly(&retval[i].xmax, sizeof(int)); + nrec += controlSocket->ReceiveDataOnly(&retval[i].ymin, sizeof(int)); + nrec += controlSocket->ReceiveDataOnly(&retval[i].ymax, sizeof(int)); + } + thisDetector->nROI = nretval; + FILE_LOG(logDEBUG5) << "nRoi: " << nretval; + for (int i = 0; i < nretval; ++i) { + thisDetector->roiLimits[i] = retval[i]; + FILE_LOG(logDEBUG5) << "ROI [" << i << "] (" << + thisDetector->roiLimits[j].xmin << "," << + thisDetector->roiLimits[j].xmax << "," << + thisDetector->roiLimits[j].ymin << "," << + thisDetector->roiLimits[j].ymax << ")"; + } -#ifdef VERBOSE - for(int j=0;jnROI;++j) - std::cout<<"ROI [" <myDetectorType == GOTTHARD) { @@ -3747,332 +3562,240 @@ int slsDetector::sendROI(int n,ROI roiLimits[]) { } // update roi in receiver - if (ret == OK && thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - int fnum = F_RECEIVER_SET_ROI; + if (ret == OK && thisDetector->receiverOnlineFlag == ONLINE_FLAG) { + fnum = F_RECEIVER_SET_ROI; ret = FAIL; -#ifdef VERBOSE - std::cout << "Sending ROI to receiver " << thisDetector->nROI << std::endl; -#endif + narg = thisDetector->nROI; + arg = thisDetector->roiLimits; + FILE_LOG(logDEBUG5) << "Sending ROI to receiver " << thisDetector->nROI; + if (connectData() == OK) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->SendDataOnly(&thisDetector->nROI, sizeof(thisDetector->nROI)); - for(int i = 0; i < thisDetector->nROI; ++i) { - dataSocket->SendDataOnly(&thisDetector->roiLimits[i].xmin, sizeof(int)); - dataSocket->SendDataOnly(&thisDetector->roiLimits[i].xmax, sizeof(int)); - dataSocket->SendDataOnly(&thisDetector->roiLimits[i].ymin, sizeof(int)); - dataSocket->SendDataOnly(&thisDetector->roiLimits[i].ymax, sizeof(int)); + dataSocket->SendDataOnly(&fnum, sizeof(fnum)); + dataSocket->SendDataOnly(&narg, sizeof(narg)); + if (narg != -1) { + for(int i = 0; i < narg; ++i) { + dataSocket->SendDataOnly(&arg[i].xmin, sizeof(int)); + dataSocket->SendDataOnly(&arg[i].xmax, sizeof(int)); + dataSocket->SendDataOnly(&arg[i].ymin, sizeof(int)); + dataSocket->SendDataOnly(&arg[i].ymax, sizeof(int)); + } } - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + dataSocket->ReceiveDataOnly(&ret, sizeof(ret)); + + // handle ret + char mess[MAX_STR_LENGTH] = {0}; if (ret == FAIL) { - dataSocket->ReceiveDataOnly(mess,MAX_STR_LENGTH); setErrorMask((getErrorMask())|(COULDNOT_SET_ROI)); - FILE_LOG(logERROR, ("Receiver %d returned error: %s", detId, mess)); + dataSocket->ReceiveDataOnly(mess, MAX_STR_LENGTH); + FILE_LOG(logERROR) << "Receiver " << detId << " returned error: " << mess; } disconnectData(); + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } } - - return ret; } - - int slsDetector::writeAdcRegister(int addr, int val) { + int fnum = F_WRITE_ADC_REG; + int ret = FAIL; + uint32_t args[2] = {addr, val}; + FILE_LOG(logDEBUG5) << "Writing to ADC register 0x" << std::hex << + addr << "data: 0x" << std::hex << val << std::dec; - int retval=-1; - int fnum=F_WRITE_ADC_REG; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), NULL, 0); + disconnectControl(); - uint32_t arg[2]; - arg[0]=addr; - arg[1]=val; - - -#ifdef VERBOSE - std::cout<< std::endl; - FILE_LOG(logINFO) << "Writing to adc register "<< std::hex<onlineFlag==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)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } -#ifdef VERBOSE - FILE_LOG(logINFO) << "ADC Register returned "<< retval << std::endl; -#endif - if (ret==FAIL) { - FILE_LOG(logERROR) << "Write ADC to register failed " << std::endl; - setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + // handle ret + if (ret == FAIL) + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + else if (ret == FORCE_UPDATE) + ret = updateDetector(); } return retval; - } int slsDetector::activate(int const enable) { int fnum = F_ACTIVATE; - int fnum2 = F_RECEIVER_ACTIVATE; - int retval = -1; - int arg = enable; - char mess[MAX_STR_LENGTH]=""; int ret = FAIL; + int arg = enable; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting activate flag to " << arg; - if (thisDetector->myDetectorType != EIGER) { - FILE_LOG(logERROR) << "Not implemented for this detector" << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); - return -1; - } + // detector + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); - FILE_LOG(logDEBUG5) << - (!enable ? "Deactivating" : (enable == -1 ? "Getting activate" : "Activating")) << - " Detector" << std::endl; - if (thisDetector->onlineFlag==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(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->activated = retval; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); + } else { + FILE_LOG(logDEBUG5) << "Activate: " << retval; + thisDetector->activated = retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } -#ifdef VERBOSE - if (retval==1) - std::cout << "Detector Activated" << std::endl; - else if (retval==0) - std::cout << "Detector Deactivated" << std::endl; - else - std::cout << "Detector Activation unknown:" << retval << std::endl; -#endif - if (ret!=FAIL) { - int arg = thisDetector->activated; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - std::cout << "Activating/Deactivating Receiver: " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum2, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) + // receiver + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && ret == OK) { + fnum = F_RECEIVER_ACTIVATE; + ret = FAIL; + arg = thisDetector->activated; + retval = -1; + FILE_LOG(logDEBUG5) << "Setting activate flag " << arg << " to receiver"; + + if (connectData() == OK) { + ret=thisReceiver->Client_Send(fnum2, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); + } else if (ret == FORCE_UPDATE) + ret = updateReceiver(); } } -#ifdef VERBOSE - if (retval==1) - std::cout << "Receiver Activated" << std::endl; - else if (retval==0) - std::cout << "Receiver Deactivated" << std::endl; - else - std::cout << "Receiver Activation unknown:" << retval << std::endl; -#endif - - return thisDetector->activated; - } - int slsDetector::setDeactivatedRxrPaddingMode(int padding) { int fnum = F_RECEIVER_DEACTIVATED_PADDING_ENABLE; - int retval = -1; - int arg = padding; int ret = OK; + int arg = padding; + int retval = -1; + FILE_LOG(logDEBUG5) << "Deactivated Receiver Padding Enable: " << arg; - if (thisDetector->myDetectorType != EIGER) { - FILE_LOG(logERROR) << "Not implemented for this detector" << std::endl; - setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); - return -1; - } - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - std::cout << "Deactivated Receiver Padding Enable: " << arg << std::endl; -#endif - if (connectData() == OK) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG && connectData() == OK) { ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); - } - if (ret==FAIL) - setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); - else - thisDetector->receiver_deactivatedPaddingEnable = retval; - } + // handle ret + if (ret == FAIL) + setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); + else { + FILE_LOG(logDEBUG5) << "Deactivated Receiver Padding Enable:" << retval; + thisDetector->receiver_deactivatedPaddingEnable = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } + } return thisDetector->receiver_deactivatedPaddingEnable; } - - int slsDetector::getFlippedData(dimension d) { return thisDetector->flippedData[d]; } - int slsDetector::setFlippedData(dimension d, int value) { - int retval=-1; - int fnum=F_SET_FLIPPED_DATA_RECEIVER; - int ret=FAIL; - int args[2]={X,-1}; + int fnum = F_SET_FLIPPED_DATA_RECEIVER; + int ret = OK; + int args[2] = {(int)d, value}; + int retval = -1; - - if (thisDetector->myDetectorType!= EIGER) { - std::cout << "Flipped Data is not implemented in this detector" << std::endl; + // flipped across y + if (d == Y) { + FILE_LOG(logERROR) << "Flipped across Y axis is not implemented"; setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); return -1; } -#ifdef VERBOSE - std::cout << std::endl; - std::cout << "Setting/Getting flipped data across axis " << d <<" with value " - << value << std::endl; -#endif - if (value > -1) { - thisDetector->flippedData[d] = value; - args[1] = value; - } else - args[1] = thisDetector->flippedData[d]; + // replace get with shm value (write to shm right away as it is a det value, not rx value) + if (value > -1) + thisDetector->flippedData[d] = (value > 0) ? 1 : 0; + args[1] = thisDetector->flippedData[d]; + FILE_LOG(logDEBUG5) << "Setting flipped data across axis " << d << " with value: " << value; - args[0] = d; - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG && connectData() == OK) { ret=thisReceiver->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); - disconnectData(); - } - if ((args[1] != retval && args[1]>=0) || (ret==FAIL)) { - ret = FAIL; + // handle ret + if (ret == FAIL) setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); + else { + FILE_LOG(logDEBUG5) << "Flipped data:" << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - - if (ret==FORCE_UPDATE) - updateReceiver(); } - - return thisDetector->flippedData[d]; } - int slsDetector::setAllTrimbits(int val) { - int fnum=F_SET_ALL_TRIMBITS; + int fnum = F_SET_ALL_TRIMBITS; + int ret = FAIL; + int arg = val; int retval = -1; - int ret=OK; -#ifdef VERBOSE - FILE_LOG(logINFO) << "Setting all trimbits to "<< val << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&val,sizeof(val)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - char mess[MAX_STR_LENGTH]=""; - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET)); - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + FILE_LOG(logDEBUG5) << "Setting all trimbits to " << val; + + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "All trimbit value: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } -#ifdef VERBOSE - FILE_LOG(logINFO) << "All trimbits were set to "<< retval << std::endl; -#endif return retval; } - int slsDetector::enableGapPixels(int val) { - - if (val > 0 && thisDetector->myDetectorType!= EIGER) - val = -1; - if (val >= 0) { - val=(val>0)?1:0; + int fnum = F_ENABLE_GAPPIXELS_IN_RECEIVER; + int ret = OK; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending gap pixels enable to receiver: " << arg; - // send to receiver - int ret=OK; - int retval=-1; - int fnum=F_ENABLE_GAPPIXELS_IN_RECEIVER; - int arg=val; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if ((arg != retval) || (ret==FAIL)) { - ret = FAIL; + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG && connectData() == OK) { + ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) setErrorMask((getErrorMask())|(RECEIVER_ENABLE_GAPPIXELS_NOT_SET)); - } + else { + FILE_LOG(logDEBUG5) << "Gap pixels enable to receiver:" << retval; + thisDetector->gappixels = retval; - if (ret==FORCE_UPDATE) - updateReceiver(); - } - - - // update client - if (ret == OK) { - thisDetector->gappixels = val; - thisDetector->dataBytesInclGapPixels = 0; - - if (thisDetector->dynamicRange != 4) { - thisDetector->dataBytesInclGapPixels = - (thisDetector->nChip[X] * - thisDetector->nChan[X] + thisDetector->gappixels * - thisDetector->nGappixels[X]) * - (thisDetector->nChip[Y] * - thisDetector->nChan[Y] + thisDetector->gappixels * - thisDetector->nGappixels[Y]) * - thisDetector->dynamicRange/8; - // set data bytes for other detector ( for future use) - if (thisDetector->myDetectorType==JUNGFRAUCTB) - getTotalNumberOfChannels(); + // update databytes + thisDetector->dataBytesInclGapPixels = 0; + if (thisDetector->dynamicRange != 4) { + thisDetector->dataBytesInclGapPixels = + (thisDetector->nChip[X] * thisDetector->nChan[X] + + thisDetector->gappixels * thisDetector->nGappixels[X]) * + (thisDetector->nChip[Y] * thisDetector->nChan[Y] + + thisDetector->gappixels * thisDetector->nGappixels[Y]) * + thisDetector->dynamicRange / 8; + } + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } } } - return thisDetector->gappixels; } - int slsDetector::setTrimEn(int nen, int *en) { if (en) { - for (int ien=0; ientrimEnergies[ien]=en[ien]; thisDetector->nTrimEn=nen; } @@ -4082,421 +3805,326 @@ int slsDetector::setTrimEn(int nen, int *en) { int slsDetector::getTrimEn(int *en) { if (en) { - for (int ien=0; iennTrimEn; ien++) - en[ien]=thisDetector->trimEnergies[ien]; + for (int ien=0; iennTrimEn; ++ien) + en[ien] = thisDetector->trimEnergies[ien]; } return (thisDetector->nTrimEn); } +int slsDetector::pulsePixel(int n, int x, int y) { + int fnum = F_PULSE_PIXEL; + int ret = FAIL; + int args[3] = {n , x, y}; + FILE_LOG(logDEBUG5) << "Pulsing pixel " << n << " number of times at (" << + x << "," << y << ")"; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), NULL, 0); + disconnectControl(); -int slsDetector::pulsePixel(int n,int x,int y) { - int ret=FAIL; - int fnum=F_PULSE_PIXEL; - char mess[MAX_STR_LENGTH]=""; - int arg[3]; - arg[0] = n; arg[1] = x; arg[2] = y; - -#ifdef VERBOSE - std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times at (" << - x << "," << "y)" << std::endl << std::endl; -#endif - - if (thisDetector->onlineFlag==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(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_PULSE)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(COULD_NOT_PULSE)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } - return ret; } -int slsDetector::pulsePixelNMove(int n,int x,int y) { - int ret=FAIL; - int fnum=F_PULSE_PIXEL_AND_MOVE; - char mess[MAX_STR_LENGTH]=""; - int arg[3]; - arg[0] = n; arg[1] = x; arg[2] = y; +int slsDetector::pulsePixelNMove(int n, int x, int y) { + int fnum = F_PULSE_PIXEL_AND_MOVE; + int ret = FAIL; + int args[3] = {n, x, y}; + FILE_LOG(logDEBUG5) << "Pulsing pixel " << n << " number of times and move by delta (" << + x << "," << y << ")"; -#ifdef VERBOSE - std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times and move " - "by deltax:" << x << " deltay:" << y << std::endl << std::endl; -#endif + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), NULL, 0); + disconnectControl(); - if (thisDetector->onlineFlag==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(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_PULSE)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(COULD_NOT_PULSE)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } - return ret; } - int slsDetector::pulseChip(int n) { - int ret=FAIL; - int fnum=F_PULSE_CHIP; - char mess[MAX_STR_LENGTH]=""; + int fnum = F_PULSE_CHIP; + int ret = FAIL; + int arg = n; + FILE_LOG(logDEBUG5) << "Pulsing chip " << n << " number of times"; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + disconnectControl(); -#ifdef VERBOSE - std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times" << std::endl << std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&n,sizeof(n)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_PULSE)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(COULD_NOT_PULSE)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } - return ret; } - - int slsDetector::setThresholdTemperature(int val) { - - int retval = -1; int fnum = F_THRESHOLD_TEMP; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting threshold temperature to " << val; - int arg=val; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectStop() == OK) { + ret = thisDetectorStop->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectStop(); - -#ifdef VERBOSE - std::cout<< std::endl; - FILE_LOG(logINFO) << "Setting/Getting Threshold Temperature to "<< val << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(&arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -#ifdef VERBOSE - FILE_LOG(logINFO) << "Threshold Temperature returned "<< retval << std::endl; -#endif - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); - } - disconnectStop(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); + } else { + FILE_LOG(logDEBUG5) << "Threshold temperature: " << retval; + } // no updateDetector as it is stop server } - return retval; } - int slsDetector::setTemperatureControl(int val) { - - int retval = -1; int fnum = F_TEMP_CONTROL; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting temperature control to " << val; - int arg=val; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectStop() == OK) { + ret = thisDetectorStop->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectStop(); - -#ifdef VERBOSE - std::cout<< std::endl; - FILE_LOG(logINFO) << "Setting/Getting Threshold Temperature to "<< val << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(&arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -#ifdef VERBOSE - FILE_LOG(logINFO) << "Threshold Temperature returned "<< retval << std::endl; -#endif - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); - } - disconnectStop(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); + } else { + FILE_LOG(logDEBUG5) << "Temperature control: " << retval; + } // no updateDetector as it is stop server } - return retval; } - - int slsDetector::setTemperatureEvent(int val) { - - int retval = -1; int fnum = F_TEMP_EVENT; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting temperature event to " << val; - int arg=val; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectStop() == OK) { + ret = thisDetectorStop->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectStop(); - -#ifdef VERBOSE - std::cout<< std::endl; - FILE_LOG(logINFO) << "Setting/Getting Threshold Temperature to "<< val << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(&arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -#ifdef VERBOSE - FILE_LOG(logINFO) << "Threshold Temperature returned "<< retval << std::endl; -#endif - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); - } - disconnectStop(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); + } else { + FILE_LOG(logDEBUG5) << "Temperature event: " << retval; + } // no updateDetector as it is stop server } - return retval; } - int slsDetector::setStoragecellStart(int pos) { - int ret=FAIL; - int fnum=F_STORAGE_CELL_START; - char mess[MAX_STR_LENGTH] = {0}; - int retval=-1; + int fnum = F_STORAGE_CELL_START; + int ret = FAIL; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting storage cell start to " << val; -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending storage cell start index " << pos << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&pos,sizeof(pos)); - //check opening error - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(STORAGE_CELL_START)); - } else - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(STORAGE_CELL_START)); + } else { + FILE_LOG(logDEBUG5) << "Storage cell start: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } return retval; } - int slsDetector::programFPGA(std::string fname) { - int ret=FAIL; - int fnum=F_PROGRAM_FPGA; - char mess[MAX_STR_LENGTH]=""; - size_t filesize=0; + // only jungfrau implemented (client processing, so check now) + if (thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB) { + FILE_LOG(logERROR) << "Not implemented for this detector"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + FILE_LOG(logDEBUG5) << "Programming FPGA with file name:" << fname; + size_t filesize = 0; char* fpgasrc = NULL; - if (thisDetector->myDetectorType != JUNGFRAU && - thisDetector->myDetectorType != JUNGFRAUCTB) { - std::cout << "Not implemented for this detector" << std::endl; - return FAIL; - } - - //check if it exists - struct stat st; - if (stat(fname.c_str(),&st)) { - std::cout << "Programming file does not exist" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - - // open src - FILE* src = fopen(fname.c_str(),"rb"); - if (src == NULL) { - std::cout << "Could not open source file for programming: " << fname << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - - // create temp destination file - char destfname[] = "/tmp/Jungfrau_MCB.XXXXXX"; - int dst = mkstemp(destfname); // create temporary file and open it in r/w - if (dst == -1) { - std::cout << "Could not create destination file in /tmp for programming: " - << destfname << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - - // convert src to dst rawbin -#ifdef VERBOSE - std::cout << "Converting " << fname << " to " << destfname << std::endl; -#endif - int filepos,x,y,i; - // Remove header (0...11C) - for (filepos=0; filepos < 0x11C; ++filepos) - fgetc(src); - // Write 0x80 times 0xFF (0...7F) { - char c = 0xFF; - for (filepos=0; filepos < 0x80; ++filepos) - write(dst, &c, 1); - } - // Swap bits and write to file - for (filepos=0x80; filepos < 0x1000000; ++filepos) { - x = fgetc(src); - if (x < 0) break; - y=0; - for (i=0; i < 8; ++i) - y=y| ( (( x & (1<> i) << (7-i) ); // This swaps the bits - write(dst, &y, 1); - } - if (filepos < 0x1000000) { - std::cout << "Could not convert programming file. EOF before end of flash" - << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - if (fclose(src)) { - std::cout << "Could not close source file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - if (close(dst)) { - std::cout << "Could not close destination file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } -#ifdef VERBOSE - std::cout << "File has been converted to " << destfname << std::endl; -#endif - - //loading dst file to memory - FILE* fp = fopen(destfname,"r"); - if (fp == NULL) { - std::cout << "Could not open rawbin file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - if (fseek(fp,0,SEEK_END)) { - std::cout << "Seek error in rawbin file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - filesize = ftell(fp); - if (filesize <= 0) { - std::cout << "Could not get length of rawbin file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - rewind(fp); - fpgasrc = (char*)malloc(filesize+1); - if (fpgasrc == NULL) { - std::cout << "Could not allocate size of program" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } - if (fread(fpgasrc, sizeof(char), filesize, fp) != filesize) { - std::cout << "Could not read rawbin file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - if (fpgasrc != NULL) - free(fpgasrc); - return FAIL; + struct stat st; + if (stat(fname.c_str(),&st)) { + FILE_LOG(logERROR) << "Programming file does not exist"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } } - if (fclose(fp)) { - std::cout << "Could not close destination file after converting" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - if (fpgasrc != NULL) - free(fpgasrc); - return FAIL; - } - unlink(destfname); // delete temporary file -#ifdef VERBOSE - std::cout << "Successfully loaded the rawbin file to program memory" << std::endl; -#endif + { + // open src + FILE* src = fopen(fname.c_str(),"rb"); + if (src == NULL) { + FILE_LOG(logERROR) << "Could not open source file for programming: " << fname; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + // create temp destination file + char destfname[] = "/tmp/Jungfrau_MCB.XXXXXX"; + int dst = mkstemp(destfname); // create temporary file and open it in r/w + if (dst == -1) { + FILE_LOG(logERROR) << "Could not create destination file in /tmp for programming: " << destfname; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + + // convert src to dst rawbin + FILE_LOG(logDEBUG5) << "Converting " << fname << " to " << destfname; + { + int filepos, x, y, i; + // Remove header (0...11C) + for (filepos=0; filepos < 0x11C; ++filepos) + fgetc(src); + // Write 0x80 times 0xFF (0...7F) + { + char c = 0xFF; + for (filepos=0; filepos < 0x80; ++filepos) + write(dst, &c, 1); + } + // Swap bits and write to file + for (filepos = 0x80; filepos < 0x1000000; ++filepos) { + x = fgetc(src); + if (x < 0) break; + y=0; + for (i = 0; i < 8; ++i) + y=y| ( (( x & (1<> i) << (7-i) ); // This swaps the bits + write(dst, &y, 1); + } + if (filepos < 0x1000000) { + FILE_LOG(logERROR) << "Could not convert programming file. EOF before end of flash"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + } + if (fclose(src)) { + FILE_LOG(logERROR) << "Could not close source file"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + if (close(dst)) { + FILE_LOG(logERROR) << "Could not close destination file"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + FILE_LOG(logDEBUG5) << "File has been converted to " << destfname; + + //loading dst file to memory + FILE* fp = fopen(destfname,"r"); + if (fp == NULL) { + FILE_LOG(logERROR) << "Could not open rawbin file"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + if (fseek(fp, 0, SEEK_END)) { + FILE_LOG(logERROR) << "Seek error in rawbin file"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + filesize = ftell(fp); + if (filesize <= 0) { + FILE_LOG(logERROR) << "Could not get length of rawbin file"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + rewind(fp); + fpgasrc = (char*)malloc(filesize + 1); + if (fpgasrc == NULL) { + FILE_LOG(logERROR) << "Could not allocate size of program"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + if (fread(fpgasrc, sizeof(char), filesize, fp) != filesize) { + FILE_LOG(logERROR) << "Could not read rawbin file"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + if (fpgasrc != NULL) + free(fpgasrc); + return FAIL; + } + + if (fclose(fp)) { + FILE_LOG(logERROR) << "Could not close destination file after converting"; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + if (fpgasrc != NULL) + free(fpgasrc); + return FAIL; + } + unlink(destfname); // delete temporary file + FILE_LOG(logDEBUG5) << "Successfully loaded the rawbin file to program memory"; + } // send program from memory to detector -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending programming binary to detector " << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { + int fnum = F_PROGRAM_FPGA; + int ret = FAIL; + char mess[MAX_STR_LENGTH] = {0}; + FILE_LOG(logDEBUG5) << "Sending programming binary to detector"; + + if (thisDetector->onlineFlag == ONLINE_FLAG) { if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&filesize,sizeof(filesize)); - //check opening error + controlSocket->SendDataOnly(&fnum, sizeof(fnum)); + controlSocket->SendDataOnly(&filesize, sizeof(filesize)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; + // opening error + if (ret == FAIL) { + controlSocket->ReceiveDataOnly(mess, sizeof(mess)); + FILE_LOG(logERROR) << "Detector " << detId << " returned error: " << mess; setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); filesize = 0; } //erasing flash - if (ret!=FAIL) { - FILE_LOG(logINFO) << "This can take awhile. Please be patient..." << std::endl; - printf("Erasing Flash:%d%%\r",0); + if (ret != FAIL) { + FILE_LOG(logINFO) << "This can take awhile. Please be patient..."; + printf("Erasing Flash: %d%%\r", 0); std::cout << std::flush; //erasing takes 65 seconds, printing here (otherwise need threads //in server-unnecessary) - int count = 66; - while(count>0) { + const int ERASE_TIME = 65; + int count = ERASE_TIME + 1; + while(count > 0) { usleep(1 * 1000 * 1000); --count; - printf("Erasing Flash:%d%%\r",(int) (((double)(65-count)/65)*100)); + printf("Erasing Flash:%d%%\r", + (int) (((double)(ERASE_TIME - count) / ERASE_TIME) * 100)); std::cout << std::flush; } - std::cout< 0)) { unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb if (unitprogramsize > filesize) //less than 2mb unitprogramsize = filesize; -#ifdef VERBOSE - std::cout << "unitprogramsize:" << unitprogramsize << "\t filesize:" - << filesize << std::endl; -#endif - controlSocket->SendDataOnly(fpgasrc+currentPointer,unitprogramsize); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - filesize-=unitprogramsize; - currentPointer+=unitprogramsize; + FILE_LOG(logDEBUG5) << "unitprogramsize:" << unitprogramsize << + "\t filesize:" << filesize; + + controlSocket->SendDataOnly(fpgasrc + currentPointer, unitprogramsize); + controlSocket->ReceiveDataOnly(&ret, sizeof(ret)); + if (ret != FAIL) { + filesize -= unitprogramsize; + currentPointer += unitprogramsize; //print progress printf("Writing to Flash:%d%%\r", - (int) (((double)(totalsize-filesize)/totalsize)*100)); + (int) (((double)(totalsize - filesize) / totalsize) * 100)); std::cout << std::flush; } else { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; + FILE_LOG(logERROR) << "Detector returned error: " << mess; setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); } } - std::cout<ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; + controlSocket->ReceiveDataOnly(&ret, sizeof(ret)); + if (ret == FAIL) { + controlSocket->ReceiveDataOnly(mess, sizeof(mess)); + FILE_LOG(logERROR) << "Detector returned error: " << mess; setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); } } disconnectControl(); - if (ret==FORCE_UPDATE) + if (ret == FORCE_UPDATE) updateDetector(); } @@ -4555,22 +4182,22 @@ int slsDetector::programFPGA(std::string fname) { (strstr(mess,"not implemented") == NULL) && (strstr(mess,"locked") == NULL) && (strstr(mess,"-update") == NULL)) { - fnum=F_RESET_FPGA; - int stopret; + fnum = F_RESET_FPGA; + int stopret = FAIL; if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->ReceiveDataOnly(&stopret,sizeof(stopret)); + stopSocket->SendDataOnly(&fnum, sizeof(fnum)); + stopSocket->ReceiveDataOnly(&stopret, sizeof(stopret)); if (stopret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; + controlSocket->ReceiveDataOnly(mess, sizeof(mess)); + FILE_LOG(logERROR) << "Detector returned error: " << mess; setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); } - disconnectControl(); + disconnectStop(); } } } if (ret != FAIL) { - printf("You can now restart the detector servers in normal mode.\n"); + FILE_LOG(logINFO) << "You can now restart the detector servers in normal mode."; } //free resources @@ -4582,676 +4209,430 @@ int slsDetector::programFPGA(std::string fname) { int slsDetector::resetFPGA() { - int ret=FAIL; - int fnum=F_RESET_FPGA; - char mess[MAX_STR_LENGTH]=""; + int fnum = F_RESET_FPGA; + int ret = FAIL; + int arg = n; + FILE_LOG(logDEBUG5) << "Sending reset FPGA"; - if (thisDetector->myDetectorType != JUNGFRAU) { - std::cout << "Not implemented for this detector" << std::endl; - return FAIL; - } -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending reset to FPGA " << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - // control server - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(RESET_ERROR)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RESET_ERROR)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } return ret; - } - int slsDetector::powerChip(int ival) { - int ret=FAIL; - int fnum=F_POWER_CHIP; - char mess[MAX_STR_LENGTH]=""; - int retval=-1; + int fnum = F_POWER_CHIP; + int ret = FAIL; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting power chip to " << val; - if (thisDetector->myDetectorType != JUNGFRAU && - thisDetector->myDetectorType != JUNGFRAUCTB ) { - std::cout << "Not implemented for this detector" << std::endl; - return FAIL; - } -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending power on/off/get to the chip " << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&ival,sizeof(ival)); - //check opening error - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(POWER_CHIP)); - } else - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(POWER_CHIP)); + } else { + FILE_LOG(logDEBUG5) << "Power chip: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } return retval; - } int slsDetector::setAutoComparatorDisableMode(int ival) { - int ret=FAIL; - int fnum=F_AUTO_COMP_DISABLE; - char mess[MAX_STR_LENGTH]=""; - int retval=-1; + int fnum = F_AUTO_COMP_DISABLE; + int ret = FAIL; + int arg = val; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting auto comp disable mode to " << val; - if (thisDetector->myDetectorType != JUNGFRAU) { - std::cout << "Not implemented for this detector" << std::endl; - return FAIL; - } -#ifdef VERBOSE - FILE_LOG(logINFO) << "Enabling/disabling Auto comp disable mode " << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&ival,sizeof(ival)); - //check opening error - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(AUTO_COMP_DISABLE)); - } else - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(AUTO_COMP_DISABLE)); + } else { + FILE_LOG(logDEBUG5) << "Auto comp disable: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } return retval; - } -int slsDetector::getChanRegs(double* retval,bool fromDetector) { - int n=getTotalNumberOfChannels(); - if (fromDetector) { - getModule(); - } +int slsDetector::getChanRegs(double* retval) { + int n = getTotalNumberOfChannels(); + // update chanregs + sls_detector_module *myMod = getModule(); + deleteModule(myMod); //the original array has 0 initialized if (chanregs) { - for (int i=0; ionlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - //to exclude trimbits - if (!tb) { - module.nchan=0; - module.nchip=0; - } - sendModule(&module); - - //not included in module - if (gainval && (thisDetector->nGain)) - controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain); - if (offsetval && (thisDetector->nOffset)) - controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); - if (thisDetector->myDetectorType == EIGER) { - controlSocket->SendDataOnly(&iodelay,sizeof(iodelay)); - controlSocket->SendDataOnly(&tau,sizeof(tau)); - controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); - } - - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - if (strstr(mess,"default tau")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - ret = updateDetector(); - } + //to exclude trimbits + if (!tb) { + module.nchan = 0; + module.nchip = 0; } + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + controlSocket->SendDataOnly(&fnum, sizeof(fnum)); + sendModule(&module); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { + // handle ret + if (ret == FAIL) { + char mess[MAX_STR_LENGTH] = {0}; + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + FILE_LOG(logERROR) << "Detector " << detId << " returned error: " << mess; + if (strstr(mess,"default tau") != NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); + else + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + FILE_LOG(logDEBUG5) << "Set Module returned: " << retval; + + disconnectControl(); + if (ret == FORCE_UPDATE) + ret = updateDetector(); + } + + // update client structure + if (ret = OK) { if (detectorModules) { - if (tb) { - (detectorModules)->nchan=module.nchan; - (detectorModules)->nchip=module.nchip; - } - (detectorModules)->ndac=module.ndac; - (detectorModules)->nadc=module.nadc; - if (tb) { - thisDetector->nChips=module.nchip; - thisDetector->nChans=module.nchan/module.nchip; - } - thisDetector->nDacs=module.ndac; - thisDetector->nAdcs=module.nadc; - - if (thisDetector->myDetectorType != JUNGFRAU) { - if (tb) { - for (int ichip=0; ichipnChips; ++ichip) { - if (chipregs) - chipregs[ichip]= - module.chipregs[ichip]; - - if (chanregs) { - for (int i=0; inChans; ++i) { - chanregs[i+ichip* - thisDetector->nChans]= - module.chanregs[ichip*thisDetector->nChans+i]; - } - } + if (thisDetector->myDetectorType == EIGER && tb && chanregs) { + for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) { + for (int i = 0; i < thisDetector->nChans; ++i) { + chanregs[i + ichip * thisDetector->nChans] = + module.chanregs[ichip * thisDetector->nChans + i]; } } - if (adcs) { - for (int i=0; inAdcs; ++i) - adcs[i]=module.adcs[i]; - } } - + if (adcs) { + for (int i = 0; i < thisDetector->nAdcs; ++i) { + adcs[i] = module.adcs[i]; + } if (dacs) { - for (int i=0; inDacs; ++i) - dacs[i]=module.dacs[i]; + for (int i = 0; i < thisDetector->nDacs; ++i) + dacs[i] = module.dacs[i]; } - - (detectorModules)->gain=module.gain; - (detectorModules)->offset=module.offset; - (detectorModules)->serialnumber=module.serialnumber; - (detectorModules)->reg=module.reg; + (detectorModules)->serialnumber = module.serialnumber; + (detectorModules)->reg = module.reg; + (detectorModules)->iodelay = module.iodelay; + (detectorModules)->tau = module.tau; + (detectorModules)->eV = module.eV; } - - if ((thisDetector->nGain) && (gainval) && (gain)) { - for (int i=0; inGain; ++i) - gain[i]=gainval[i]; - } - - if ((thisDetector->nOffset) && (offsetval) && (offset)) { - for (int i=0; inOffset; ++i) - offset[i]=offsetval[i]; - } - if (e_eV != -1) thisDetector->currentThresholdEV = e_eV; } - -#ifdef VERBOSE - FILE_LOG(logINFO) << "Module register returned "<< retval << std::endl; -#endif - return ret; } - - - slsDetectorDefs::sls_detector_module *slsDetector::getModule() { + int fnum = F_GET_MODULE; + int ret = FAIL; + int arg = (int)isettings; + FILE_LOG(logDEBUG5) << "Getting module"; -#ifdef VERBOSE - std::cout << "slsDetector get module " << std::endl; -#endif + sls_detector_module *myMod = createModule(); - int fnum=F_GET_MODULE; - sls_detector_module *myMod=createModule(); + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); - int* gainval=0, *offsetval=0; - if (thisDetector->nGain) - gainval=new int[thisDetector->nGain]; - if (thisDetector->nOffset) - offsetval=new int[thisDetector->nOffset]; - - - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - // int n; - -#ifdef VERBOSE - FILE_LOG(logINFO) << "getting module " << std::endl; -#endif - - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - receiveModule(myMod); - - //extra gain and offset - eiger - if (thisDetector->nGain) - controlSocket->ReceiveDataOnly(gainval,sizeof(int)*thisDetector->nGain); - if (thisDetector->nOffset) - controlSocket->ReceiveDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + receiveModule(myMod); + if (ret == FORCE_UPDATE) + ret = updateDetector(); } + disconnectControl(); } - - if (ret!=FAIL) { + // update client structure + if (ret == OK) { if (detectorModules) { - (detectorModules)->nchan=myMod->nchan; - (detectorModules)->nchip=myMod->nchip; - (detectorModules)->ndac=myMod->ndac; - (detectorModules)->nadc=myMod->nadc; - thisDetector->nChips=myMod->nchip; - thisDetector->nChans=myMod->nchan/myMod->nchip; - thisDetector->nDacs=myMod->ndac; - thisDetector->nAdcs=myMod->nadc; - - if (thisDetector->myDetectorType != JUNGFRAU) { - for (int ichip=0; ichipnChips; ++ichip) { - if (chipregs) - chipregs[ichip]= - myMod->chipregs[ichip]; - - if (chanregs) { - for (int i=0; inChans; ++i) { - chanregs[i+ichip*thisDetector->nChans]= - myMod->chanregs[ichip*thisDetector->nChans+i]; - } + if (thisDetector->myDetectorType == EIGER && chanregs) { + for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) { + for (int i = 0; i < thisDetector->nChans; ++i) { + chanregs[i+ichip*thisDetector->nChans] = + myMod->chanregs[ichip*thisDetector->nChans+i]; } } - - if (adcs) { - for (int i=0; inAdcs; ++i) - adcs[i]=myMod->adcs[i]; - } } - + if (adcs) { + for (int i = 0; i < thisDetector->nAdcs; ++i) + adcs[i] = myMod->adcs[i]; + } if (dacs) { - for (int i=0; inDacs; ++i) { - dacs[i]=myMod->dacs[i]; + for (int i = 0; i < thisDetector->nDacs; ++i) { + dacs[i] = myMod->dacs[i]; } } - (detectorModules)->gain=myMod->gain; - (detectorModules)->offset=myMod->offset; - (detectorModules)->serialnumber=myMod->serialnumber; - (detectorModules)->reg=myMod->reg; - + (detectorModules)->serialnumber = myMod->serialnumber; + (detectorModules)->reg = myMod->reg; + (detectorModules)->iodelay = myMod->iodelay; + (detectorModules)->tau = myMod->tau; + (detectorModules)->eV = myMod->eV; } - - if ((thisDetector->nGain) && (gainval) && (gain)) { - for (int i=0; inGain; ++i) - gain[i+thisDetector->nGain]=gainval[i]; - } - - if ((thisDetector->nOffset) && (offsetval) && (offset)) { - for (int i=0; inOffset; ++i) - offset[i+thisDetector->nOffset]=offsetval[i]; - } - } else { deleteModule(myMod); - myMod=NULL; + myMod = NULL; } - - if (gainval) delete[]gainval; - if (offsetval) delete[]offsetval; - return myMod; } +int slsDetector::setRateCorrection(int64_t t) { + int fnum = F_SET_RATE_CORRECT; + int ret = FAIL; + int64_t arg = t; + FILE_LOG(logDEBUG5) << "Setting Rate Correction to " << arg; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + disconnectControl(); -int slsDetector::calibratePedestal(int frames) { - int ret=FAIL; - int retval=-1; - int fnum=F_CALIBRATE_PEDESTAL; - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Calibrating Pedestal " <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&frames,sizeof(frames)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } + // handle ret + if (ret == FAIL) { + if (strstr(mess,"default tau")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); + if (strstr(mess,"32")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); + else + setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); + } else if (ret == FORCE_UPDATE) + ret = updateDetector(); } - - return retval; + return ret; } - -int slsDetector::setRateCorrection(int t) { - - if (getDetectorsType() == EIGER) { - int fnum=F_SET_RATE_CORRECT; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - int64_t arg = t; - -#ifdef VERBOSE - FILE_LOG(logINFO) << "Setting Rate Correction to " << arg << std::endl; -#endif - if (thisDetector->onlineFlag==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(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - if (strstr(mess,"default tau")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); - if (strstr(mess,"32")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); - else - setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - return ret; //only success/fail - } - printf("unknown detector\n"); - return -1; -} - - - -int slsDetector::getRateCorrection() { - int fnum=F_GET_RATE_CORRECT; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; +int64_t slsDetector::getRateCorrection() { + int fnum = F_GET_RATE_CORRECT; + int ret = FAIL; int64_t retval = -1; -#ifdef VERBOSE - FILE_LOG(logINFO) << "Setting Rate Correction to " << arg << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + FILE_LOG(logDEBUG5) << "Getting rate correction"; + + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Rate correction: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } - return retval; } - - -int slsDetector::printReceiverConfiguration() { - std::cout << std::endl - << "#Detector " << detId << ":" << std::endl; - std::cout << "Detector IP:\t\t" << getNetworkParameter(DETECTOR_IP) << std::endl; - std::cout << "Detector MAC:\t\t" << getNetworkParameter(DETECTOR_MAC) << std::endl; - - std::cout << "Receiver Hostname:\t" << getNetworkParameter(RECEIVER_HOSTNAME) << std::endl; - std::cout << "Receiver UDP IP:\t" << getNetworkParameter(RECEIVER_UDP_IP) << std::endl; - std::cout << "Receiver UDP MAC:\t" << getNetworkParameter(RECEIVER_UDP_MAC) << std::endl; - std::cout << "Receiver UDP Port:\t" << getNetworkParameter(RECEIVER_UDP_PORT) << std::endl; - - if (thisDetector->myDetectorType == EIGER) - std::cout << "Receiver UDP Port2:\t" << getNetworkParameter(RECEIVER_UDP_PORT2) - << std::endl; - std::cout << std::endl; - - return OK; +void slsDetector::printReceiverConfiguration(int level) { + FILE_LOG(level) << "#Detector " << detId << ":\n" << + "Receiver Hostname:\t" << getNetworkParameter(RECEIVER_HOSTNAME) << + "Detector UDP IP (Source):\t\t" << getNetworkParameter(DETECTOR_IP) << + "Detector UDP MAC:\t\t" << getNetworkParameter(DETECTOR_MAC) << + "Receiver UDP IP:\t" << getNetworkParameter(RECEIVER_UDP_IP) << + "Receiver UDP MAC:\t" << getNetworkParameter(RECEIVER_UDP_MAC) << + "Receiver UDP Port:\t" << getNetworkParameter(RECEIVER_UDP_PORT) << + ((thisDetector->myDetectorType == EIGER) ? + ("Receiver UDP Port2:\t" << getNetworkParameter(RECEIVER_UDP_PORT2) << "\n") + : ("\n")); } - - - int slsDetector::setReceiverOnline(int off) { - if (off!=GET_ONLINE_FLAG) { + if (off != GET_ONLINE_FLAG) { // no receiver - if (!strcmp(thisDetector->receiver_hostname,"none")) + if (!strcmp(thisDetector->receiver_hostname, "none")) thisDetector->receiverOnlineFlag = OFFLINE_FLAG; else thisDetector->receiverOnlineFlag = off; - // check receiver online - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + // set online + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG) { setReceiverTCPSocket(); // error in connecting - if (thisDetector->receiverOnlineFlag==OFFLINE_FLAG) { - std::cout << "cannot connect to receiver" << std::endl; + if (thisDetector->receiverOnlineFlag == OFFLINE_FLAG) { + FILE_LOG(logERROR) << "Cannot connect to receiver"; setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); } } - } return thisDetector->receiverOnlineFlag; } - std::string slsDetector::checkReceiverOnline() { - std::string retval = ""; - //if it doesnt exits, create data socket + std::string retval; + //if it doesnt exit, create socket and call this function again if (!dataSocket) { - //this already sets the online/offline flag setReceiverTCPSocket(); - if (thisDetector->receiverOnlineFlag==OFFLINE_FLAG) + if (thisDetector->receiverOnlineFlag == OFFLINE_FLAG) return std::string(thisDetector->receiver_hostname); else - return std::string(""); + return retval; } //still cannot connect to socket, dataSocket=0 if (dataSocket) { if (connectData() == FAIL) { dataSocket->SetTimeOut(5); - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; + thisDetector->receiverOnlineFlag = OFFLINE_FLAG; delete dataSocket; - dataSocket=0; -#ifdef VERBOSE - FILE_LOG(logINFO) << "receiver offline!" << std::endl; -#endif + dataSocket = 0; + FILE_LOG(logDEBUG5) << "receiver " << detId << " offline!"; return std::string(thisDetector->receiver_hostname); } else { - thisDetector->receiverOnlineFlag=ONLINE_FLAG; + thisDetector->receiverOnlineFlag = ONLINE_FLAG; dataSocket->SetTimeOut(100); disconnectData(); -#ifdef VERBOSE - FILE_LOG(logINFO) << "receiver online!" << std::endl; -#endif - return std::string(""); + FILE_LOG(logDEBUG5) << "receiver " << detId << " online!"; } } return retval; } - - - int slsDetector::setReceiverTCPSocket(std::string const name, int const receiver_port) { + char thisName[MAX_STR_LENGTH] = {0}; + int thisRP = 0; + int ret = OK; - char thisName[MAX_STR_LENGTH]; - int thisRP; - int retval=OK; - - //if receiver ip given - if (strcmp(name.c_str(),"")!=0) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "setting receiver" << std::endl; -#endif - strcpy(thisName,name.c_str()); - strcpy(thisDetector->receiver_hostname,thisName); - if (dataSocket) { - delete dataSocket; - dataSocket=0; - } - } else + // rx_hostname + if (name.empty()) { strcpy(thisName,thisDetector->receiver_hostname); - - //if receiverTCPPort given - if (receiver_port>0) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "setting data port" << std::endl; -#endif - thisRP=receiver_port; - thisDetector->receiverTCPPort=thisRP; + } else { + FILE_LOG(logDEBUG5) << "Setting rx_hostname"; + strcpy(thisName, name.c_str()); + strcpy(thisDetector->receiver_hostname, thisName); if (dataSocket) { delete dataSocket; - dataSocket=0; + dataSocket = 0; } - } else - thisRP=thisDetector->receiverTCPPort; + } - //create data socket + // data port + if (receiver_port <= 0) { + thisRP = thisDetector->receiverTCPPort; + } else { + FILE_LOG(logDEBUG5) << "Setting data port"; + thisRP = receiver_port; + thisDetector->receiverTCPPort = thisRP; + if (dataSocket) { + delete dataSocket; + dataSocket = 0; + } + } + + // create data socket if (!dataSocket) { try { dataSocket = new MySocketTCP(thisName, thisRP); -#ifdef VERYVERBOSE - FILE_LOG(logINFO) << "Data socket connected " << - thisName << " " << thisRP << std::endl; -#endif + FILE_LOG(logDEBUG5) << "Data socket connected " << thisName << " " << thisRP; } catch(...) { -#ifdef VERBOSE - FILE_LOG(logERROR) << "Could not connect Data socket " << - thisName << " " << thisRP << std::endl; -#endif + FILE_LOG(logERROR) << "Could not connect Data socket " << thisName << " " << thisRP; dataSocket = 0; - retval = FAIL; + ret = FAIL; } } + if (ret == FAIL) { + thisDetector->receiverOnlineFlag = OFFLINE_FLAG; + FILE_LOG(logDEBUG5) << "Receiver offline"; + } - //check if it connects - if (retval!=FAIL) { + // check online and version compatibility + else { checkReceiverOnline(); thisReceiver->SetSocket(dataSocket); // check for version compatibility - switch (thisDetector->myDetectorType) { - case EIGER: - case JUNGFRAU: - case GOTTHARD: - if (thisDetector->receiverAPIVersion == 0) { - if (checkVersionCompatibility(DATA_PORT) == FAIL) - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; - } - break; - default: - break; + if (thisDetector->receiverAPIVersion == 0) { + if (checkVersionCompatibility(DATA_PORT) == FAIL) + thisDetector->receiverOnlineFlag = OFFLINE_FLAG; } - - } else { - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; -#ifdef VERBOSE - FILE_LOG(logINFO) << "offline!" << std::endl; -#endif } - return retval; + return ret; } - int slsDetector::lockReceiver(int lock) { - int fnum=F_LOCK_RECEIVER; + int fnum = F_LOCK_RECEIVER; int ret = FAIL; - int retval=-1; - int arg=lock; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting receiver server lock to " << lock; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &lock, sizeof(lock), &retval, sizeof(retval)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Locking or Unlocking Receiver " << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Receiver Lock: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - updateReceiver(); } - return retval; } - - - - std::string slsDetector::getReceiverLastClientIP() { - int fnum=F_GET_LAST_RECEIVER_CLIENT_IP; + int fnum = F_GET_LAST_RECEIVER_CLIENT_IP; int ret = FAIL; - char retval[INET_ADDRSTRLEN]=""; + char retval[INET_ADDRSTRLEN] = {0}; + FILE_LOG(logDEBUG5) << "Getting last client ip to receiver server"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Geting Last Client IP connected to Receiver " << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, retval, INET_ADDRSTRLEN); - disconnectData(); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Last client IP to receiver: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - updateReceiver(); } - return std::string(retval); } @@ -5259,33 +4640,34 @@ std::string slsDetector::getReceiverLastClientIP() { int slsDetector::exitReceiver() { int fnum = F_EXIT_RECEIVER; int ret = FAIL; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK) { - ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0); - disconnectData(); - } - } - if (ret == OK) { - std::cout << std::endl << "Shutting down the receiver" << std::endl << std::endl; + FILE_LOG(logDEBUG5) << "Sending exit command to receiver server"; + + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0); + disconnectData(); + // no ret handling as ret never fail + FILE_LOG(logINFO) << "Shutting down the receiver server"; } return ret; } + int slsDetector::execReceiverCommand(std::string cmd) { int fnum = F_EXEC_RECEIVER_COMMAND; int ret = FAIL; char arg[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; - - strcpy(arg,cmd.c_str()); + strcpy(arg, cmd.c_str()); FILE_LOG(logDEBUG5) << "Sending command to receiver " << arg; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval)); - disconnectData(); - } - if (ret != FAIL) { + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { FILE_LOG(logINFO) << "Receiver " << detId << " returned:\n" << retval; } } @@ -5293,94 +4675,91 @@ int slsDetector::execReceiverCommand(std::string cmd) { } - int slsDetector::updateReceiverNoWait() { - int n = 0,ind; - char path[MAX_STR_LENGTH]; - char lastClientIP[INET_ADDRSTRLEN]; + int n = 0, i32 = 0; + char cstring[MAX_STR_LENGTH] = {0}; + char lastClientIP[INET_ADDRSTRLEN] = {0}; - n += dataSocket->ReceiveDataOnly(lastClientIP,sizeof(lastClientIP)); -#ifdef VERBOSE - FILE_LOG(logINFO) << "Updating receiver last modified by " << lastClientIP << std::endl; -#endif + n += dataSocket->ReceiveDataOnly(lastClientIP, sizeof(lastClientIP)); + FILE_LOG(logDEBUG5) << "Updating receiver last modified by " << lastClientIP; // filepath - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_filePath, path); + n += dataSocket->ReceiveDataOnly(cstring, sizeof(cstring)); + strcpy(thisDetector->receiver_filePath, cstring); // filename - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_fileName, path); + n += dataSocket->ReceiveDataOnly(cstring, sizeof(cstring)); + strcpy(thisDetector->receiver_fileName, cstring); // index - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_fileIndex = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_fileIndex = i32; //file format - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_fileFormatType = (fileFormat)ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_fileFormatType = (fileFormat)i32; // frames per file - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_framesPerFile = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_framesPerFile = i32; // frame discard policy - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_frameDiscardMode = (frameDiscardPolicy)ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_frameDiscardMode = (frameDiscardPolicy)i32; // frame padding - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_framePadding = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_framePadding = i32; // file write enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_fileWriteEnable = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_fileWriteEnable = i32; // file overwrite enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_overWriteEnable = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_overWriteEnable = i32; // gap pixels - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->gappixels = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->gappixels = i32; // receiver read frequency - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_read_freq = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_read_freq = i32; // receiver streaming port - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_zmqport = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_zmqport = i32; // streaming source ip - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_zmqip, path); + n += dataSocket->ReceiveDataOnly(cstring, sizeof(cstring)); + strcpy(thisDetector->receiver_zmqip, cstring); // additional json header - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_additionalJsonHeader, path); + n += dataSocket->ReceiveDataOnly(cstring, sizeof(cstring)); + strcpy(thisDetector->receiver_additionalJsonHeader, cstring); // receiver streaming enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_upstream = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_upstream = i32; // activate - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->activated = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->activated = i32; // deactivated padding enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_deactivatedPaddingEnable = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_deactivatedPaddingEnable = i32; // silent mode - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_silentMode = ind; + n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); + thisDetector->receiver_silentMode = i32; - if (!n) printf("n: %d\n", n); + if (!n) + FILE_LOG(logERROR) << "Could not update receiver, received 0 bytes\n"; return OK; - } @@ -5388,94 +4767,91 @@ int slsDetector::updateReceiverNoWait() { int slsDetector::updateReceiver() { - int fnum=F_UPDATE_RECEIVER_CLIENT; - int ret=OK; - char mess[MAX_STR_LENGTH]=""; + int fnum = F_UPDATE_RECEIVER_CLIENT; + int ret = FAIL; + FILE_LOG(logDEBUG5) << "Sending update client to receiver server"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret == FAIL) { - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - else - updateReceiverNoWait(); - - //if ret is force update, do not update now as client is updating - //receiver currently - disconnectData(); - } + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0); + if (ret == FAIL) + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + else + updateReceiverNoWait(); + disconnectData(); } - return ret; } - void slsDetector::sendMultiDetectorSize() { - int fnum=F_SEND_RECEIVER_MULTIDETSIZE; + int fnum = F_SEND_RECEIVER_MULTIDETSIZE; int ret = FAIL; + int args[2] = thisDetector->multiSize; int retval = -1; + FILE_LOG(logDEBUG5) << "Sending multi detector size to Receiver (" << + thisDetector->multiSize[0] << "," << thisDetector->multiSize[1] << ")"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending multi detector size to Receiver (" << - thisDetector->multiSize[0] << "," - << thisDetector->multiSize[1] << ")" << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, thisDetector->multiSize, sizeof(thisDetector->multiSize), &retval, sizeof(retval)); - disconnectData(); - } - if ((ret==FAIL)) { - FILE_LOG(logERROR) << "Could not set position Id" << std::endl; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_MULTI_DET_SIZE_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver multi size returned: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } } + return retval; } void slsDetector::setDetectorId() { - int fnum=F_SEND_RECEIVER_DETPOSID; + int fnum = F_SEND_RECEIVER_DETPOSID; int ret = FAIL; - int retval = -1; int arg = detId; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending detector pos id to Receiver " << detId; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending detector pos id to Receiver " << detId << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if ((ret==FAIL) || (retval != arg)) { - FILE_LOG(logERROR) << "Could not set position Id" << std::endl; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_DET_POSID_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver Position Id returned: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } } + return retval; } void slsDetector::setDetectorHostname() { - int fnum=F_SEND_RECEIVER_DETHOSTNAME; + int fnum = F_SEND_RECEIVER_DETHOSTNAME; int ret = FAIL; - char retval[MAX_STR_LENGTH]=""; + char args[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + strcpy(args, thisDetector->hostname); + FILE_LOG(logDEBUG5) << "Sending detector hostname to Receiver " << args; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, args, sizeof(args), retvals, sizeof(retvals)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending detector hostname to Receiver " << - thisDetector->hostname << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, thisDetector->hostname, MAX_STR_LENGTH, retval, MAX_STR_LENGTH); - disconnectData(); - } - if ((ret==FAIL) || (strcmp(retval,thisDetector->hostname))) + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver set detector hostname: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } } } @@ -5485,39 +4861,33 @@ std::string slsDetector::getFilePath() { } - std::string slsDetector::setFilePath(std::string s) { + if (!s.empty()) { + int fnum = F_SET_RECEIVER_FILE_PATH; + int ret = FAIL; + char args[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + strcpy(args, s.c_str()); + FILE_LOG(logDEBUG5) << "Sending file path to Receiver " << args; - if (s.empty()) - return getFilePath(); - - - int fnum = F_SET_RECEIVER_FILE_PATH; - int ret = FAIL; - char arg[MAX_STR_LENGTH]=""; - char retval[MAX_STR_LENGTH] = ""; - - strcpy(arg,s.c_str()); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending file path to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval)); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, args, sizeof(args), retvals, sizeof(retvals)); disconnectData(); + + // handle ret + if (ret == FAIL) { + if (!s.empty()) { + FILE_LOG(logERROR) << "file path does not exist"; + setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST)); + } else + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver file path: " << retvals; + strcpy(thisDetector->receiver_filePath, retvals); + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } } - if (ret!=FAIL) { - strcpy(thisDetector->receiver_filePath,retval); - } - else { - if (!s.empty()) { - FILE_LOG(logERROR) << "file path does not exist" << std::endl; - setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST)); - } else - setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - } - if (ret==FORCE_UPDATE) - updateReceiver(); } return getFilePath(); } @@ -5527,65 +4897,58 @@ std::string slsDetector::getFileName() { return thisDetector->receiver_fileName; } + std::string slsDetector::setFileName(std::string s) { + if (!s.empty()) { + int fnum = F_SET_RECEIVER_FILE_NAME; + int ret = FAIL; + char args[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + strcpy(args, s.c_str()); + FILE_LOG(logDEBUG5) << "Sending file name to Receiver " << args; - if (s.empty()) - return getFileName(); - - - int fnum=F_SET_RECEIVER_FILE_NAME; - int ret = FAIL; - char arg[MAX_STR_LENGTH]=""; - char retval[MAX_STR_LENGTH]=""; - - strcpy(arg,s.c_str()); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending file name to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval)); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, args, sizeof(args), retvals, sizeof(retvals)); disconnectData(); - } - if (ret == FAIL) - setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else - strcpy(thisDetector->receiver_fileName,retval); - if (ret==FORCE_UPDATE) - updateReceiver(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver file name: " << retvals; + strcpy(thisDetector->receiver_fileName, retvals); + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } + } + } return getFileName(); } int slsDetector::setReceiverFramesPerFile(int f) { + if (f >= 0) { + int fnum = F_SET_RECEIVER_FRAMES_PER_FILE; + int ret = FAIL; + int arg = f; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting receiver frames per file to " << arg; - if (f < 0) - return thisDetector->receiver_framesPerFile; - - int fnum = F_SET_RECEIVER_FRAMES_PER_FILE; - int ret = FAIL; - int retval = -1; - int arg = f; - - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending frames per file to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); - } - if (ret == FAIL) - setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else - thisDetector->receiver_framesPerFile = retval; - if (ret==FORCE_UPDATE) - updateReceiver(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver frames per file: " << retval; + thisDetector->receiver_framesPerFile = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } + } + } return thisDetector->receiver_framesPerFile; } @@ -5593,92 +4956,92 @@ int slsDetector::setReceiverFramesPerFile(int f) { slsDetectorDefs::frameDiscardPolicy slsDetector::setReceiverFramesDiscardPolicy(frameDiscardPolicy f) { int fnum = F_RECEIVER_DISCARD_POLICY; int ret = FAIL; - int retval = -1; - int arg = f; + int arg = (int)f; + frameDiscardPolicy retval = (frameDiscardPolicy)-1; + FILE_LOG(logDEBUG5) << "Setting receiver frames discard policy to " << arg; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending frames discard policy to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else if (ret!=FAIL && retval > -1) { - thisDetector->receiver_frameDiscardMode = (frameDiscardPolicy)retval; + } else { + FILE_LOG(logDEBUG5) << "Receiver frames discard policy: " << retval; + thisDetector->receiver_frameDiscardMode = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - updateReceiver(); } return thisDetector->receiver_frameDiscardMode; } + int slsDetector::setReceiverPartialFramesPadding(int f) { int fnum = F_RECEIVER_PADDING_ENABLE; int ret = FAIL; - int retval = -1; int arg = f; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting receiver partial frames enable to " << arg; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending partial frames enable to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else if (ret!=FAIL && retval > -1) { - thisDetector->receiver_framePadding = (bool)retval; + } else { + FILE_LOG(logDEBUG5) << "Receiver partial frames enable: " << retval; + thisDetector->receiver_framePadding = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - updateReceiver(); } return thisDetector->receiver_framePadding; } + slsDetectorDefs::fileFormat slsDetector::setFileFormat(fileFormat f) { - if (f == GET_FILE_FORMAT) - return getFileFormat(); - int fnum=F_SET_RECEIVER_FILE_FORMAT; - int ret = FAIL; - int arg = f; - int retval = -1; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending file format to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + if (f != GET_FILE_FORMAT) { + int fnum = F_SET_RECEIVER_FILE_FORMAT; + int ret = FAIL; + int arg = f; + fileFormat retval = (fileFormat)-1; + FILE_LOG(logDEBUG5) << "Setting receiver file format to " << arg; + + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver file format: " << retval; + thisDetector->receiver_fileFormatType = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } } - if (ret == FAIL) - setErrorMask((getErrorMask())|(RECEIVER_FILE_FORMAT)); - else - thisDetector->receiver_fileFormatType = (fileFormat)retval; - if (ret==FORCE_UPDATE) - updateReceiver(); } return getFileFormat(); } - slsDetectorDefs::fileFormat slsDetector::getFileFormat() { return thisDetector->receiver_fileFormatType; } + int slsDetector::getFileIndex() { return thisDetector->receiver_fileIndex; } + int slsDetector::setFileIndex(int i) { if (i < 0) @@ -6443,7 +5806,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim( //Interpolate all trimbits if (tb) { - for (int i = 0; inchan; i++) + for (int i = 0; inchan; ++i) myMod->chanregs[i] = linearInterpolation(energy, e1, e2, a->chanregs[i], b->chanregs[i]); } return myMod; @@ -6453,7 +5816,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim( slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string fname, - int& iodelay, int& tau, sls_detector_module* myMod, int tb) { + sls_detector_module* myMod, int tb) { int nflag=0; @@ -6524,13 +5887,13 @@ slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string infile.open(myfname.c_str(),std::ifstream::binary); if (infile.is_open()) { infile.read((char*) myMod->dacs,sizeof(int)*(myMod->ndac)); - infile.read((char*)&iodelay,sizeof(iodelay)); - infile.read((char*)&tau,sizeof(tau)); + infile.read((char*)&myMod->iodelay,sizeof(myMod->iodelay)); + infile.read((char*)&myMod->tau,sizeof(myMod->tau)); #ifdef VERBOSE - for(int i=0;indac;i++) + for(int i=0;indac;++i) FILE_LOG(logINFO) << "dac " << i << ":" << myMod->dacs[i] << std::endl; - FILE_LOG(logINFO) << "iodelay:" << iodelay << std::endl; - FILE_LOG(logINFO) << "tau:" << tau << std::endl; + FILE_LOG(logINFO) << "iodelay:" << myMod->iodelay << std::endl; + FILE_LOG(logINFO) << "tau:" << myMod->tau << std::endl; #endif if (tb) { infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan)); @@ -6559,16 +5922,16 @@ slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string if (infile.is_open()) { while(infile.good()) { getline(infile,str); - iline++; + ++iline; #ifdef VERBOSE std::cout<< str << std::endl; #endif std::istringstream ssstr(str); ssstr >> sargname >> ival; - for (i=0;idacs[i]=ival; - idac++; + ++idac; #ifdef VERBOSE std::cout<< sargname << " dac nr. " << idac << " is " << ival << std::endl; #endif @@ -6612,8 +5975,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string } -int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod, - int iodelay, int tau) { +int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod) { std::ofstream outfile; @@ -6664,14 +6026,15 @@ int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod, if (outfile.is_open()) { iv = 1150; #ifdef VERBOSE - for(int i=0;i(&iodelay), sizeof(iodelay)); - outfile.write(reinterpret_cast(&tau), sizeof(tau)); + + outfile.write(reinterpret_cast(&mod.iodelay), sizeof(mod.iodelay)); + outfile.write(reinterpret_cast(&mod.tau), sizeof(mod.tau)); outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan)); outfile.close(); @@ -6686,7 +6049,7 @@ int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod, outfile.open(fname.c_str(), std::ios_base::out); if (outfile.is_open()) { - for (idac=0; idac0 otherwise */ - int setRateCorrection(int t=0); + int setRateCorrection(int64_t t = 0); /** * Get rate correction Eiger) * @returns 0 if rate correction disabled, > 0 otherwise */ - int getRateCorrection(); + int64_t getRateCorrection(); /** * Prints receiver configuration - * @returns OK or FAIL + * #param level print level */ - int printReceiverConfiguration(); + void printReceiverConfiguration(int level = logINFO); /** * Checks if receiver is online and set flag @@ -1824,28 +1789,21 @@ private: /** * reads a trim/settings file * @param fname name of the file to be read - * @param iodelay io delay (detector specific) - * @param tau tau (detector specific) * @param myMod pointer to the module structure which has to be set.
* If it is NULL a new module structure will be created * @param tb 1 to include trimbits, 0 to exclude (used for eiger) * @returns the pointer to myMod or NULL if reading the file failed */ - sls_detector_module* readSettingsFile(std::string fname, - int& iodelay, int& tau, - sls_detector_module* myMod=NULL, int tb=1); + sls_detector_module* readSettingsFile(std::string fname, sls_detector_module* myMod=NULL, int tb=1); /** * writes a trim/settings file * @param fname name of the file to be written * @param mod module structure which has to be written to file - * @param iodelay io delay (detector specific) - * @param tau tau (detector specific) * @returns OK or FAIL if the file could not be written */ - int writeSettingsFile(std::string fname, - sls_detector_module mod, int iodelay, int tau); + int writeSettingsFile(std::string fname, sls_detector_module mod); /** slsDetector Id or position in the detectors list */ @@ -1884,17 +1842,8 @@ private: /** pointer to adc valuse in shared memory */ int *adcs; - /** pointer to chip registers in shared memory */ - int *chipregs; - /** pointer to channal registers in shared memory */ int *chanregs; - - /** pointer to gain values in shared memory */ - int *gain; - - /** pointer to offset values in shared memory */ - int *offset; }; #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 3c57d5fe8..b28868d8c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -924,14 +924,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; ++i; - /*! \page settings - - pedestal [i] starts acquisition for i frames, calculates pedestal and writes back to fpga. Used in GOTTHARD only. Only put! \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName="pedestal"; // - descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; - ++i; - - /* pots */ /*! \page settings @@ -2725,16 +2717,16 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action, int d if (action==HELP_ACTION) { return helpRateCorr(action); } - int fval; + int64_t ival; char answer[1000]; myDet->setOnline(ONLINE_FLAG, detPos); if (action==PUT_ACTION) { - sscanf(args[1],"%d",&fval); - myDet->setRateCorrection(fval, detPos); + sscanf(args[1],"%lld",&ival); + myDet->setRateCorrection(ival, detPos); } - sprintf(answer,"%d",myDet->getRateCorrection(detPos)); + sprintf(answer,"%lld",myDet->getRateCorrection(detPos)); return string(answer); } @@ -3549,15 +3541,6 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action, int d } sprintf(ans,"%d",myDet->setAllTrimbits(-1, detPos)); return ans; - } else if (cmd=="pedestal") { - if (action==GET_ACTION) - return string("cannot get"); - if (sscanf(args[1],"%d",&val)){ - sprintf(ans,"%d",myDet->calibratePedestal(val, detPos)); - return string(ans); - }else - return string("cannot parse frame number")+cmd; - } return string("unknown settings command ")+cmd; @@ -3574,8 +3557,6 @@ string slsDetectorCommand::helpSettings(int action) { os << "thresholdnotb eV [sett]\n sets the detector threshold in eV without loading trimbits. If sett is provided for eiger, uses settings sett"<< 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 << "trimval i \n sets all the trimbits to i" << std::endl; - os << "pedestal i \n starts acquisition for i frames, calculates pedestal and writes back to fpga."<< std::endl; - } if (action==GET_ACTION || action==HELP_ACTION) { os << "settings \n gets the settings of the detector"<< std::endl; diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index b57176962..fc39c27a9 100644 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -55,7 +55,7 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { /* * Get detector hostname - * @return NULL or hostname or NULL if uninitialized (max of 1000 characters) + * @return hostname (max of 1000 characters) */ char *getDetectorHostname() const; @@ -80,13 +80,13 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { fileFormat getFileFormat() const; /** * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) - * @return NULL or file name prefix (max of 1000 characters) + * @return file name prefix */ char *getFileName() const; /** * Get File Path - * @return NULL or file path (max of 1000 characters) + * @return file path */ char *getFilePath() const; @@ -162,7 +162,7 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { /** * Get Ehernet Interface - * @ethernet interface. eg. eth0 or "" if listening to all (max of 1000 characters) + * @ethernet interface. eg. eth0 or "" if listening to all */ char *getEthernetInterface() const; diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index ff317a452..01fa3e584 100644 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -146,15 +146,7 @@ int slsReceiverImplementation::getDetectorPositionId() const{ char *slsReceiverImplementation::getDetectorHostname() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //not initialized - if(!strlen(detHostname)) - return NULL; - - char* output = new char[MAX_STR_LENGTH](); - strcpy(output,detHostname); - //freed by calling function - return output; + return detHostname; } int slsReceiverImplementation::getFlippedData(int axis) const{ @@ -177,28 +169,12 @@ slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const{ char *slsReceiverImplementation::getFileName() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //not initialized - if(!strlen(fileName)) - return NULL; - - char* output = new char[MAX_STR_LENGTH](); - strcpy(output,fileName); - //freed by calling function - return output; + return fileName; } char *slsReceiverImplementation::getFilePath() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //not initialized - if(!strlen(filePath)) - return NULL; - - char* output = new char[MAX_STR_LENGTH](); - strcpy(output,filePath); - //freed by calling function - return output; + return filePath; } uint64_t slsReceiverImplementation::getFileIndex() const{ @@ -296,11 +272,7 @@ uint32_t slsReceiverImplementation::getUDPPortNumber2() const{ char *slsReceiverImplementation::getEthernetInterface() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - char* output = new char[MAX_STR_LENGTH](); - strcpy(output,eth); - //freed by calling function - return output; + return eth; } @@ -397,21 +369,12 @@ uint32_t slsReceiverImplementation::getStreamingPort() const{ char *slsReceiverImplementation::getStreamingSourceIP() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - char* output = new char[MAX_STR_LENGTH](); - strcpy(output,streamingSrcIP); - //freed by calling function - return output; + return streamingSrcIP; } char *slsReceiverImplementation::getAdditionalJsonHeader() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - char* output = new char[MAX_STR_LENGTH](); - memset(output, 0, MAX_STR_LENGTH); - strcpy(output,additionalJsonHeader); - //freed by calling function - return output; + return additionalJsonHeader; } uint32_t slsReceiverImplementation::getUDPSocketBufferSize() const { diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 93f5dbfaa..655c58094 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -370,6 +370,7 @@ int slsReceiverTCPIPInterface::lock_receiver() { int slsReceiverTCPIPInterface::get_last_client_ip() { ret = OK; + memset(mess, 0, sizeof(mess)); return interface->Server_SendResult(true, ret,mySock->lastClientIP, sizeof(mySock->lastClientIP)); } @@ -446,97 +447,82 @@ int slsReceiverTCPIPInterface::update_client() { int slsReceiverTCPIPInterface::send_update() { int ind = -1; - char defaultVal[MAX_STR_LENGTH] = {0}; - char* path = NULL; + char path[MAX_STR_LENGTH] = {0}; int n = 0; n += mySock->SendDataOnly(mySock->lastClientIP,sizeof(mySock->lastClientIP)); // filepath path = receiver->getFilePath(); - if (path == NULL) - n += mySock->SendDataOnly(defaultVal,MAX_STR_LENGTH); - else { - n += mySock->SendDataOnly(path,MAX_STR_LENGTH); - delete[] path; - } + n += mySock->SendDataOnly(path, sizeof(path)); // filename path = receiver->getFileName(); - if(path == NULL) - n += mySock->SendDataOnly(defaultVal,MAX_STR_LENGTH); - else { - n += mySock->SendDataOnly(path,MAX_STR_LENGTH); - delete[] path; - } + n += mySock->SendDataOnly(path, sizeof(path)); // index ind=receiver->getFileIndex(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); //file format ind=(int)receiver->getFileFormat(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); //frames per file ind=(int)receiver->getFramesPerFile(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); //frame discard policy ind=(int)receiver->getFrameDiscardPolicy(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); //frame padding ind=(int)receiver->getFramePaddingEnable(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // file write enable ind=(int)receiver->getFileWriteEnable(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // file overwrite enable ind=(int)receiver->getOverwriteEnable(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // gap pixels ind=(int)receiver->getGapPixelsEnable(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // streaming frequency ind=(int)receiver->getStreamingFrequency(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // streaming port ind=(int)receiver->getStreamingPort(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // streaming source ip path = receiver->getStreamingSourceIP(); - mySock->SendDataOnly(path,MAX_STR_LENGTH); - if (path != NULL) - delete[] path; + n += mySock->SendDataOnly(path, sizeof(path)); // additional json header path = receiver->getAdditionalJsonHeader(); - mySock->SendDataOnly(path,MAX_STR_LENGTH); - if (path != NULL) - delete[] path; + n += mySock->SendDataOnly(path, sizeof(path)); // data streaming enable ind=(int)receiver->getDataStreamEnable(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // activate ind=(int)receiver->getActivate(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // deactivated padding enable ind=(int)receiver->getDeactivatedPadding(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); // silent mode ind=(int)receiver->getSilentMode(); - n += mySock->SendDataOnly(&ind,sizeof(ind)); + n += mySock->SendDataOnly(&ind, sizeof(ind)); if (!lockStatus) strcpy(mySock->lastClientIP,mySock->thisClientIP); @@ -617,7 +603,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ int slsReceiverTCPIPInterface::set_detector_hostname() { memset(mess, 0, sizeof(mess)); char hostname[MAX_STR_LENGTH] = {0}; - char* retval = NULL; + char retval[MAX_STR_LENGTH] = {0}; // get args, return if socket crashed, ret is fail if receiver is not null if (interface->Server_ReceiveArg(ret, mess, hostname,MAX_STR_LENGTH, true, receiver) == FAIL) @@ -633,20 +619,14 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } // get retval = receiver->getDetectorHostname(); - if(retval == NULL) { + if (strlen(retval)) { ret = FAIL; - cprintf(RED, "Could not set hostname to %s\n", hostname); + sprintf(mess, "hostname not set\n"); FILE_LOG(logERROR) << mess; } } - interface->Server_SendResult(true, ret, - retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess); - - if(retval != NULL) - delete[] retval; - - return ret; + return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } @@ -1048,7 +1028,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ int slsReceiverTCPIPInterface::set_file_dir() { memset(mess, 0, sizeof(mess)); char fPath[MAX_STR_LENGTH] = {0}; - char* retval=NULL; + char retval[MAX_STR_LENGTH] = {0}; // get args, return if socket crashed, ret is fail if receiver is not null if (interface->Server_ReceiveArg(ret, mess, fPath, sizeof(fPath), true, receiver) == FAIL) @@ -1062,22 +1042,15 @@ int slsReceiverTCPIPInterface::set_file_dir() { } // get retval = receiver->getFilePath(); - if (retval == NULL || (strlen(fPath) && strcasecmp(fPath, retval))) { + if ((!strlen(retval)) || (strlen(fPath) && strcasecmp(fPath, retval))) { ret = FAIL; strcpy(mess,"receiver file path does not exist\n"); FILE_LOG(logERROR) << mess; - } - if (retval != NULL) { + } else FILE_LOG(logDEBUG1) << "file path:" << retval; - } } - interface->Server_SendResult(true, ret, retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess); - - if(retval != NULL) - delete[] retval; - - return ret; + return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } @@ -1085,7 +1058,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { int slsReceiverTCPIPInterface::set_file_name() { memset(mess, 0, sizeof(mess)); char fName[MAX_STR_LENGTH] = {0}; - char* retval = NULL; + char retval[MAX_STR_LENGTH] = {0}; // get args, return if socket crashed, ret is fail if receiver is not null if (interface->Server_ReceiveArg(ret, mess, fName, sizeof(fName), true, receiver) == FAIL) @@ -1099,22 +1072,15 @@ int slsReceiverTCPIPInterface::set_file_name() { } // get retval = receiver->getFileName(); - if(retval == NULL) { + if (strlen(retval)) { ret = FAIL; strcpy(mess, "file name is empty\n"); FILE_LOG(logERROR) << mess; - } - if (retval != NULL) { + } else FILE_LOG(logDEBUG1) << "file name:" << retval; - } } - interface->Server_SendResult(true, ret, retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess); - - if(retval != NULL) - delete[] retval; - - return ret; + return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } @@ -1624,7 +1590,7 @@ int slsReceiverTCPIPInterface::set_streaming_port() { int slsReceiverTCPIPInterface::set_streaming_source_ip() { memset(mess, 0, sizeof(mess)); char arg[MAX_STR_LENGTH] = {0}; - char* retval=NULL; + char retval[MAX_STR_LENGTH] = {0}; // get args, return if socket crashed, ret is fail if receiver is not null if (interface->Server_ReceiveArg(ret, mess, arg, MAX_STR_LENGTH, true, receiver) == FAIL) @@ -1642,13 +1608,7 @@ int slsReceiverTCPIPInterface::set_streaming_source_ip() { FILE_LOG(logDEBUG1) << "streaming source ip:" << retval; } - interface->Server_SendResult(true, - ret, retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess); - - if(retval != NULL) - delete[] retval; - - return ret; + return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } @@ -1758,7 +1718,7 @@ int slsReceiverTCPIPInterface::restream_stop(){ int slsReceiverTCPIPInterface::set_additional_json_header() { memset(mess, 0, sizeof(mess)); char arg[MAX_STR_LENGTH] = {0}; - char* retval=NULL; + char retval[MAX_STR_LENGTH] = {0}; // get args, return if socket crashed, ret is fail if receiver is not null if (interface->Server_ReceiveArg(ret, mess, arg, sizeof(arg), true, receiver) == FAIL) @@ -1776,12 +1736,7 @@ int slsReceiverTCPIPInterface::set_additional_json_header() { FILE_LOG(logDEBUG1) << "additional json header:" << retval; } - interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); - - if (retval != NULL) - delete[] retval; - - return ret; + return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index fa7b9106a..aed49a260 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -240,16 +240,13 @@ public: int nchip; /**< is the number of chips on the module */ int ndac; /**< is the number of dacs on the module */ int nadc; /**< is the number of adcs on the module */ - int reg; /**< is the module register (e.g. dynamic range?) - \see moduleRegisterBit */ + int reg; /**< is the module register settings (gain level) */ + int iodelay; /**< iodelay */ + int tau; /**< tau */ + int eV; /**< threshold energy */ int *dacs; /**< is the pointer to the array of the dac values (in V) */ - int *adcs; /**< is the pointer to the array of the adc values (in V) FLAT_FIELD_CORRECTION*/ - int *chipregs; /**< is the pointer to the array of the chip registers - \see ::chipRegisterBit */ - int *chanregs; /**< is the pointer to the array of the channel registers - \see ::channelRegisterBit */ - double gain; /**< is the module gain (V/keV) */ - double offset; /**< is the module offset (V) */ + int *adcs; /**< is the pointer to the array of the adc values (in V) */ + int *chanregs; /**< is the pointer to the array of the channel registers */ } sls_detector_module; diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index 1ed9f1192..6ff0b521a 100644 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -45,7 +45,6 @@ enum detFuncs{ F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */ F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */ F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */ - F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */ F_ENABLE_TEN_GIGA, /**< enable 10Gbe */ F_SET_ALL_TRIMBITS, /** < set all trimbits to this value */ F_SET_CTB_PATTERN, /** < loads a pattern in the CTB */ @@ -160,7 +159,6 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_LOAD_IMAGE: return "F_LOAD_IMAGE"; case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK"; case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK"; - case F_CALIBRATE_PEDESTAL: return "F_CALIBRATE_PEDESTAL"; case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA"; case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS"; case F_SET_CTB_PATTERN: return "F_SET_CTB_PATTERN";