diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index 2f5ff4153..7c8f501ad 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -14,23 +14,24 @@ INCLUDES?= -IcommonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP -Ius #EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/$(EPICS_HOST_ARCH) -Wl,-R/usr/local/epics/base/lib/$(EPICS_HOST_ARCH) -lca -lCom - -SRC_CLNT=slsDetectorAnalysis/fileIO.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/angularConversionStatic.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsDetectorAnalysis/postProcessingFuncs.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp #../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp - - LIBZMQDIR = ../slsReceiverSoftware/include LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq +SRC_CLNT=slsDetectorAnalysis/fileIO.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/angularConversionStatic.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsDetectorAnalysis/postProcessingFuncs.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp #../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp +DEPSINCLUDES = $(LIBZMQDIR)/sls_receiver_defs.h $(LIBZMQDIR)/sls_receiver_funcs.h $(LIBZMQDIR)/ansi.h commonFiles/sls_detector_defs.h commonFiles/sls_detector_funcs.h commonFiles/error_defs.h slsDetector/slsDetectorBase.h slsDetectorAnalysis/angCalLogClass.h slsDetectorAnalysis/angleConversionConstant.h slsDetectorAnalysis/badChannelCorrections.h slsDetectorAnalysis/detectorData.h slsDetectorAnalysis/enCalLogClass.h slsDetectorAnalysis/fileIOStatic.h slsDetectorAnalysis/movingStat.h slsDetectorAnalysis/runningStat.h slsDetectorAnalysis/single_photon_hit.h threadFiles/Global.h threadFiles/Task.h usersFunctions/angleFunction.h + + + $(info ) $(info #######################################) -$(info # Compiling slsDetectorSoftware #) +$(info # In slsDetectorSoftware Makefile #) $(info #######################################) $(info ) -OBJS = $(SRC_CLNT:.cpp=.o) +OBJS = $(SRC_CLNT:%.cpp=%.o) .PHONY: all intdoc doc htmldoc package clean @@ -67,15 +68,19 @@ gotthardVirtualServer: $(SRC_MYTHEN_SVC) cd gotthardDetectorServer && make -f Makefile.virtual DESTDIR=$(DESTDIR) - -%.o : %.cpp %.h Makefile +%.o : %.cpp %.h $(DEPSINCLUDES) Makefile $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -pthread -lrt $(LIBZMQ) $(FLAGS) -package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a +package: versioning $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a +versioning: + $(call colorecho,`./updateGitVersion.sh`) $(DESTDIR)/libSlsDetector.so: $(OBJS) + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling slsDetector Library #") + $(call colorecho,"#######################################") $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -pthread -lrt $(LIBZMQ) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) mv libSlsDetector.so $(DESTDIR) @@ -87,6 +92,9 @@ $(DESTDIR)/libSlsDetector.a: $(OBJS) clean: rm -rf $(DESTDIR)/libSlsDetector.a $(DESTDIR)/libSlsDetector.so core docs/* slsDetectorUsersDocs $(OBJS) cd + + + #------------------------------------------------------------------------------- diff --git a/slsDetectorSoftware/commonFiles/communication_funcs.c b/slsDetectorSoftware/commonFiles/communication_funcs.c index ab37c8996..e8238731a 100755 --- a/slsDetectorSoftware/commonFiles/communication_funcs.c +++ b/slsDetectorSoftware/commonFiles/communication_funcs.c @@ -550,6 +550,16 @@ int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveA myMod->chipregs=chipptr; myMod->chanregs=chanptr; +#ifdef EIGERD + //feature to exclude sending of trimbtis, nchips=0,nchans=0 in that case + if(myMod->nchip == 0 && myMod->nchan == 0) { + receiveAll=0; + nchipold=0; + nchanold=0; + } +#endif + + nChips=myMod->nchip; nchipdiff=nChips-nchipold; if (nchipold!=nChips) { diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index c353670c6..ac4787cff 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -43,7 +43,8 @@ using namespace std; #define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL #define RECEIVER_DET_POSID_NOT_SET 0x0000400000000000ULL #define RECEIVER_MULTI_DET_SIZE_NOT_SET 0x0000200000000000ULL - +#define PREPARE_ACQUISITION 0x0000100000000000ULL +#define CLEANUP_ACQUISITION 0x0000080000000000ULL // 0xFFFFFFF000000000ULL // 0x0000000FFFFFFFFFULL @@ -79,6 +80,7 @@ using namespace std; #define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL #define THRESHOLD_NOT_SET 0x0000000040000000ULL #define RECEIVER_FILE_FORMAT 0x0000000080000000ULL +#define RECEIVER_SUBF_TIME_NOT_SET 0x0000000100000000ULL // 0x0000000FFFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -145,6 +147,12 @@ public: if(slsErrorMask&RECEIVER_MULTI_DET_SIZE_NOT_SET) retval.append("Could not set multi detector size\n"); + if(slsErrorMask&PREPARE_ACQUISITION) + retval.append("Could not prepare acquisition in detector\n"); + + if(slsErrorMask&CLEANUP_ACQUISITION) + retval.append("Could not clean up after acquisition in detector\n"); + @@ -251,6 +259,9 @@ public: if(slsErrorMask&RECEIVER_FILE_FORMAT) retval.append("Could not set receiver file format\n"); + if(slsErrorMask&RECEIVER_SUBF_TIME_NOT_SET) + retval.append("Could not set sub exposure time in receiver.\n"); + //------------------------------------------------------ length of message diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 17470b6bf..386255bae 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -192,7 +192,8 @@ enum networkParameter { DETECTOR_TXN_DELAY_FRAME, /**< transmission delay of a whole frame for all the ports */ FLOW_CONTROL_10G, /**< flow control for 10GbE */ FLOW_CONTROL_WR_PTR, /**< memory write pointer for flow control */ - FLOW_CONTROL_RD_PTR /**< memory read pointer for flow control */ + FLOW_CONTROL_RD_PTR, /**< memory read pointer for flow control */ + RECEIVER_STREAMING_PORT /**< receiever streaming TCP(ZMQ) port */ }; /** diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.c b/slsDetectorSoftware/eigerDetectorServer/Beb.c index 417cf4b5a..2f2bb8fbd 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.c +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.c @@ -1115,7 +1115,7 @@ int Beb_GetBebFPGATemp() }else{ //read data ret = Beb_Read32(csp0base, FPGA_TEMP_OFFSET); - temperature = ((((float)(ret)/65536.0f)/0.00198421639f ) - 273.15f); // Static conversation, copied from xps sysmon standalone driver + temperature = ((((float)(ret)/65536.0f)/0.00198421639f ) - 273.15f)*1000; // Static conversation, copied from xps sysmon standalone driver //close file pointer Beb_close(fd,csp0base); } diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index 52244f1a0..76028a105 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -24,8 +24,7 @@ //GetDAQStatusRegister(512,current_mode_bits_from_fpga)){ unsigned int Module_ndacs = 16; -char Module_dac_names[16][10]= {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};; - +char Module_dac_names[16][10]={"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};; @@ -1894,6 +1893,9 @@ int Feb_Control_PrintCorrectedValues(){ } +//So if software says now 40.00 you neeed to convert to mdegrees 40000(call it A1) and then +//A1/65536/0.00198421639-273.15 + int Feb_Control_GetLeftFPGATemp(){ unsigned int temperature=0; if(Module_TopAddressIsValid(&modules[1])) @@ -1901,6 +1903,7 @@ int Feb_Control_GetLeftFPGATemp(){ else Feb_Interface_ReadRegister(Module_GetBottomLeftAddress (&modules[1]),FEB_REG_STATUS, &temperature); temperature = temperature >> 16; + temperature = ((((float)(temperature)/65536.0f)/0.00198421639f ) - 273.15f)*1000; // Static conversation, copied from xps sysmon standalone driver //division done in client to send int over network return (int)temperature; } @@ -1912,9 +1915,41 @@ int Feb_Control_GetRightFPGATemp(){ else Feb_Interface_ReadRegister(Module_GetBottomRightAddress (&modules[1]),FEB_REG_STATUS, &temperature); temperature = temperature >> 16; + temperature = ((((float)(temperature)/65536.0f)/0.00198421639f ) - 273.15f)*1000; // Static conversation, copied from xps sysmon standalone driver //division done in client to send int over network return (int)temperature; } +uint32_t Feb_Control_WriteRegister(uint32_t offset, uint32_t data) { + uint32_t value=0; + if(Module_TopAddressIsValid(&modules[1])){ + if(!Feb_Interface_WriteRegister(Module_GetTopRightAddress (&modules[1]),offset, data,0, 0)) { + cprintf(RED,"Could not read value. Value read:%d\n", value); + value = 0; + } + } else { + if(!Feb_Interface_WriteRegister(Module_GetBottomRightAddress (&modules[1]),offset, data,0, 0)) { + cprintf(RED,"Could not read value. Value read:%d\n", value); + value = 0; + } + } + return Feb_Control_ReadRegister(offset); +} + +uint32_t Feb_Control_ReadRegister(uint32_t offset) { + uint32_t value=0; + if(Module_TopAddressIsValid(&modules[1])){ + if(!Feb_Interface_ReadRegister(Module_GetTopRightAddress (&modules[1]),offset, &value)) { + cprintf(RED,"Could not read value. Value read:%d\n", value); + value = 0; + } + } else { + if(!Feb_Interface_ReadRegister(Module_GetBottomRightAddress (&modules[1]),offset, &value)) { + cprintf(RED,"Could not read value. Value read:%d\n", value); + value = 0; + } + } + return value; +} diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.h b/slsDetectorSoftware/eigerDetectorServer/FebControl.h index fb75c8a67..892d6b22c 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.h +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.h @@ -198,4 +198,6 @@ int Feb_Control_GetModuleNumber(); int Feb_Control_GetLeftFPGATemp(); int Feb_Control_GetRightFPGATemp(); + uint32_t Feb_Control_WriteRegister(uint32_t offset, uint32_t data); + uint32_t Feb_Control_ReadRegister(uint32_t offset); #endif diff --git a/slsDetectorSoftware/eigerDetectorServer/Makefile b/slsDetectorSoftware/eigerDetectorServer/Makefile index ccf582d27..9942dd3ef 100755 --- a/slsDetectorSoftware/eigerDetectorServer/Makefile +++ b/slsDetectorSoftware/eigerDetectorServer/Makefile @@ -12,13 +12,16 @@ SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c OBJS = $(SRC_CLNT:.c=.o) -all: clean $(PROGS) #hv9m_blackfin_server +all: clean versioning $(PROGS) #hv9m_blackfin_server boot: $(OBJS) -$(PROGS): - echo $(OBJS) +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` + +$(PROGS): $(OBJS) +# echo $(OBJS) mkdir -p $(DESTDIR) $(CC) -o $@ $(SRC_CLNT) $(CFLAGS) $(LDLIBS) mv $(PROGS) $(DESTDIR) @@ -32,3 +35,4 @@ hv9m_blackfin_server:9mhvserial_bf.c clean: rm -rf $(DESTDIR)/$(PROGS) *.o $(DESTDIR)/hv9m_blackfin_server + diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv3.0.0.16.1 b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv3.0.0.16.1 deleted file mode 100755 index fa32ba4bd..000000000 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv3.0.0.16.1 and /dev/null differ diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv3.0.0.16.6 b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv3.0.0.16.6 new file mode 100755 index 000000000..1d201568e Binary files /dev/null and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv3.0.0.16.6 differ diff --git a/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt b/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt index 8436a9742..5314965df 100644 --- a/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/eigerDetectorServer -URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer +URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: a5b59b47430913bb461b50da05b553874b33f39a -Revision: 287 -Branch: developer +Repsitory UUID: 2dfbd9016b501eca6ee2c00a08e49a3f7e7990d8 +Revision: 296 +Branch: 3.0-rc Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 1418 -Last Changed Date: 2017-06-22 14:32:24 +0200 +Last Changed Rev: 1457 +Last Changed Date: 2017-08-08 15:23:10.000000002 +0200 ./Makefile diff --git a/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h b/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h index 5ee503281..c01ec39e8 100644 --- a/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h +++ b/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h @@ -1,11 +1,11 @@ //#define SVNPATH "" -#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer" +#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "a5b59b47430913bb461b50da05b553874b33f39a" -//#define SVNREV 0x1418 +#define SVNREPUUID "2dfbd9016b501eca6ee2c00a08e49a3f7e7990d8" +//#define SVNREV 0x1457 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x1418 -#define SVNDATE 0x20170622 +#define SVNREV 0x1457 +#define SVNDATE 0x20170808 // diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index c05d9c6ef..9ab1467ab 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -30,6 +30,7 @@ dacs_t *detectorDacs=NULL; dacs_t *detectorAdcs=NULL; int eiger_highvoltage = 0; +int eiger_theo_highvoltage = 0; int eiger_iodelay = 0; int eiger_photonenergy = 0; int eiger_dynamicrange = 0; @@ -341,7 +342,14 @@ void setupDetector() { +/* advanced read/write reg */ +uint32_t writeRegister(uint32_t offset, uint32_t data) { + return Feb_Control_WriteRegister(offset, data); +} +uint32_t readRegister(uint32_t offset) { + return Feb_Control_ReadRegister(offset); +} /* set parameters - nmod, dr, roi */ @@ -542,25 +550,31 @@ int setModule(sls_detector_module myMod, int delay){ for(i=0;i HIGH_VOLTAGE_TOLERANCE) { + cprintf(BLUE, "High voltage still ramping: %d\n", eiger_highvoltage); + return eiger_highvoltage; + } + return eiger_theo_highvoltage; } - if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){ - cprintf(RED,"Warning: Could not read high voltage\n"); - return -3; - } - return eiger_highvoltage; + return SLAVE_HIGH_VOLTAGE_READ_VAL; } @@ -1211,11 +1236,13 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ destMod->serialnumber=srcMod->serialnumber; } - if ((srcMod->nchip)>(destMod->nchip)) { + //no trimbit feature + if (destMod->nchip && ((srcMod->nchip)>(destMod->nchip))) { printf("Number of chip of source is larger than number of chips of destination\n"); return FAIL; } - if ((srcMod->nchan)>(destMod->nchan)) { + //no trimbit feature + if (destMod->nchan && ((srcMod->nchan)>(destMod->nchan))) { printf("Number of channels of source is larger than number of channels of destination\n"); return FAIL; } @@ -1249,14 +1276,19 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ if (srcMod->offset>=0) destMod->offset=srcMod->offset; - for (ichip=0; ichip<(srcMod->nchip); ichip++) { - if (*((srcMod->chipregs)+ichip)>=0) - *((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip); - } - for (ichan=0; ichan<(srcMod->nchan); ichan++) { - if (*((srcMod->chanregs)+ichan)>=0) - *((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan); + if((destMod->nchip!=0) || (destMod->nchan!=0)) { + for (ichip=0; ichip<(srcMod->nchip); ichip++) { + if (*((srcMod->chipregs)+ichip)>=0) + *((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip); + } + for (ichan=0; ichan<(srcMod->nchan); ichan++) { + if (*((srcMod->chanregs)+ichan)>=0) + *((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan); + } } +#ifdef VERBOSE + else printf("Not Copying trimbits\n"); +#endif for (idac=0; idac<(srcMod->ndac); idac++) { if (*((srcMod->dacs)+idac)>=0) *((destMod->dacs)+idac)=*((srcMod->dacs)+idac); @@ -1277,8 +1309,8 @@ int calculateDataBytes(){ } -int getTotalNumberOfChannels(){return ((int)getNumberOfChannelsPerModule() * (int)getTotalNumberOfModules);} -int getTotalNumberOfChips(){return ((int)getNumberOfChipsPerModule * (int)getTotalNumberOfModules);} +int getTotalNumberOfChannels(){return ((int)getNumberOfChannelsPerModule() * (int)getTotalNumberOfModules());} +int getTotalNumberOfChips(){return ((int)getNumberOfChipsPerModule() * (int)getTotalNumberOfModules());} int getTotalNumberOfModules(){return NMOD;} int getNumberOfChannelsPerModule(){return ((int)getNumberOfChannelsPerChip() * (int)getTotalNumberOfChips());} int getNumberOfChipsPerModule(){return NCHIP;} diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h index 1847b84d0..836c3aa9a 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h @@ -84,6 +84,8 @@ enum NETWORKINDEX {TXN_LEFT, TXN_RIGHT, TXN_FRAME,FLOWCTRL_10G}; #define MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS (0x1FFFFFFF) /** 29 bit register for max subframe exposure value */ +#define SLAVE_HIGH_VOLTAGE_READ_VAL (-999) +#define HIGH_VOLTAGE_TOLERANCE (5) #endif /* SLSDETECTORSERVER_DEFS_H_ */ diff --git a/slsDetectorSoftware/eigerDetectorServer/updateGitVersion.sh b/slsDetectorSoftware/eigerDetectorServer/updateGitVersion.sh new file mode 100755 index 000000000..7c7a89269 --- /dev/null +++ b/slsDetectorSoftware/eigerDetectorServer/updateGitVersion.sh @@ -0,0 +1,32 @@ +SERVER=eigerDetectorServer +MAINDIR=slsDetectorsPackage +SPECDIR=slsDetectorSoftware/$SERVER +TMPFILE=gitInfoEigerTmp.h +INCLFILE=gitInfoEiger.h + +#evaluate the variables +EVALFILE=../../evalVersionVariables.sh +source $EVALFILE + + +#get modified date +#RDATE1='git log --pretty=format:"%ci" -1' +RDATE1="find ../slsDetectorServer . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|bin|.git|updateGitVersion|.o' | head -n 1" +RDATE=`eval $RDATE1` +NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}') +NEWDATE=${NEWDATE/#/0x} + + +#get old date from INCLFILE +OLDDATE=$(more $INCLFILE | grep '#define SVNDATE' | awk '{print $3}') + + +#update INCLFILE if changes +if [ "$OLDDATE" != "$NEWDATE" ]; then + echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt + cd ../../ + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi + + diff --git a/slsDetectorSoftware/gitInfo.txt b/slsDetectorSoftware/gitInfo.txt index d50018da7..f80b69fa5 100644 --- a/slsDetectorSoftware/gitInfo.txt +++ b/slsDetectorSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: a5b59b47430913bb461b50da05b553874b33f39a -Revision: 1418 -Branch: developer +Repsitory UUID: 2dfbd9016b501eca6ee2c00a08e49a3f7e7990d8 +Revision: 1452 +Branch: 3.0-rc Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 1418 -Last Changed Date: 2017-06-22 14:32:24 +0200 +Last Changed Rev: 1457 +Last Changed Date: 2017-08-09 11:36:51.000000002 +0200 ./multiSlsDetector/multiSlsDetector.cpp diff --git a/slsDetectorSoftware/gotthardDetectorServer/AD9257.h b/slsDetectorSoftware/gotthardDetectorServer/AD9257.h new file mode 120000 index 000000000..87b70e097 --- /dev/null +++ b/slsDetectorSoftware/gotthardDetectorServer/AD9257.h @@ -0,0 +1 @@ +../slsDetectorServer/AD9257.h \ No newline at end of file diff --git a/slsDetectorSoftware/gotthardDetectorServer/Makefile b/slsDetectorSoftware/gotthardDetectorServer/Makefile index a06a86180..a5f1667a6 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/Makefile +++ b/slsDetectorSoftware/gotthardDetectorServer/Makefile @@ -16,17 +16,20 @@ INSTMODE= 0777 BINS = testlib_sharedlibc -SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c +SRCS = server.c firmware_funcs.c server_funcs.c communication_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c OBJS = $(SRCS:%.c=%.o) -all: clean $(PROGS) +all: clean versioning $(PROGS) boot: $(OBJS) +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` + $(PROGS): $(OBJS) - echo $(OBJS) +# echo $(OBJS) $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) @@ -45,4 +48,3 @@ clean: - diff --git a/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix b/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix index 6fb7a6207..c0a4bcc55 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix +++ b/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix @@ -27,6 +27,7 @@ boot: $(OBJS) $(PROGS): $(OBJS) echo $(OBJS) + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) diff --git a/slsDetectorSoftware/gotthardDetectorServer/commonServerFunctions.h b/slsDetectorSoftware/gotthardDetectorServer/commonServerFunctions.h new file mode 120000 index 000000000..33bdd8d53 --- /dev/null +++ b/slsDetectorSoftware/gotthardDetectorServer/commonServerFunctions.h @@ -0,0 +1 @@ +../slsDetectorServer/commonServerFunctions.h \ No newline at end of file diff --git a/slsDetectorSoftware/gotthardDetectorServer/config.txt b/slsDetectorSoftware/gotthardDetectorServer/config.txt new file mode 100644 index 000000000..a3e58af5b --- /dev/null +++ b/slsDetectorSoftware/gotthardDetectorServer/config.txt @@ -0,0 +1,20 @@ +#masterflags (no_master, is_master, is_slave) +masterflags no_master + +#master default delay +masterdefaultdelay 70 + +#patternphase +patternphase 0 + +#adcphase +adcphase 0 + +#slave pattern phase +slavepatternphase 0 + +#slave adc phase +slaveadcphase 0 + +#rst to sw1 delay +rsttosw1delay 2 \ No newline at end of file diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c index 8366f8eb4..08ba5e901 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c @@ -4,6 +4,8 @@ #include "mcb_funcs.h" #include "registers_g.h" +#include "AD9257.h" // include "commonServerFunctions.h" + #ifdef SHAREDMEMORY #include "sharedmemory.h" #endif @@ -15,6 +17,7 @@ #include + //for memory mapping u_int64_t CSP0BASE; @@ -53,6 +56,16 @@ int masterMode=NO_MASTER, syncMode=NO_SYNCHRONIZATION, timingMode=AUTO_TIMING; enum externalSignalFlag signals[4]={EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF}; +//for the 25um detectors +int masterflags = NO_MASTER; +int masterdefaultdelay = 62; +int patternphase = 0; +int adcphase = 0; +int slavepatternphase = 0; +int slaveadcphase = 0; +int rsttosw1delay = 2; + + #ifdef MCB_FUNCS extern const int nChans; extern const int nChips; @@ -228,6 +241,134 @@ u_int32_t bus_r(u_int32_t offset) { } + +void setMasterSlaveConfiguration(){ + +/* + int masterflags = NO_MASTER; + int masterdefaultdelay = 62; + int patternphase = 0; + int adcphase = 0; + int slavepatternphase = 0; + int slaveadcphase = 0; + int sw1torstdelay = 2; +*/ +// global master default delay picked from config file + FILE* fd=fopen(CONFIG_FILE,"r"); + if(fd==NULL){ + cprintf(RED,"\nWarning: Could not open file\n"); + return; + } + cprintf(BLUE,"config file %s opened\n", CONFIG_FILE); + + char key[256]; + char value[256]; + char line[256]; + int ival=0; + u_int32_t val=0; + + while (fgets(line, sizeof(line), fd)) { + if(line[0] == '#') + continue; + sscanf(line, "%s %s\n", key, value); + if (!strcasecmp(key,"masterflags")) { + if (!strcasecmp(value,"is_master")) { + masterflags = IS_MASTER; + } + else if (!strcasecmp(value,"is_slave")) { + masterflags = IS_SLAVE; + } + else if (!strcasecmp(value,"no_master")){ + masterflags = NO_MASTER; + } + else { + cprintf(RED,"could not scan masterflags %s value from config file\n",value); + exit(EXIT_FAILURE); + } + } + else { + if(sscanf(value,"%d",&ival)<=0) { + cprintf(RED,"could not scan patternphase %s value from config file\n",value); + exit(EXIT_FAILURE); + } + + if (!strcasecmp(key,"masterdefaultdelay")) + masterdefaultdelay = ival; + else if (!strcasecmp(key,"patternphase")) + patternphase = ival; + else if (!strcasecmp(key,"adcphase")) + adcphase = ival; + else if (!strcasecmp(key,"slavepatternphase")) + slavepatternphase = ival; + else if (!strcasecmp(key,"slaveadcphase")) + slaveadcphase = ival; + else if (!strcasecmp(key,"rsttosw1delay")) + rsttosw1delay = ival; + else { + cprintf(RED,"could not scan parameter name %s from config file\n",key); + exit(EXIT_FAILURE); + } + } + + } + cprintf(BLUE, "masterflags: %d\n" + "masterdefaultdelay:%d\n" + "patternphase:%d\n" + "adcphase:%d\n" + "slavepatternphase:%d\n" + "slaveadcphase:%d\n" + "rsttosw1delay:%d\n", + masterflags, + masterdefaultdelay, + patternphase, + adcphase, + slavepatternphase, + slaveadcphase, + rsttosw1delay); + + + + if (masterflags == IS_MASTER) { + // set delay + setDelay(0); + + /* Set pattern phase for the master module */ + val=bus_r(MULTI_PURPOSE_REG); + val = (val & (~(PLL_CLK_SEL_MSK))) | PLL_CLK_SEL_MASTER_VAL; + bus_w(MULTI_PURPOSE_REG,val); + setPhaseShift(patternphase); + /* Set adc phase for the master module */ + val=bus_r(MULTI_PURPOSE_REG); + val = (val & (~(PLL_CLK_SEL_MSK))) | PLL_CLK_SEL_MASTER_ADC_VAL; + bus_w(MULTI_PURPOSE_REG,val); + setPhaseShift(adcphase); + /* Set pattern phase for the slave module */ + val=bus_r(MULTI_PURPOSE_REG); + val = (val & (~(PLL_CLK_SEL_MSK))) | PLL_CLK_SEL_SLAVE_VAL; + bus_w(MULTI_PURPOSE_REG,val); + setPhaseShift(slavepatternphase); + /* Set adc phase for the slave module */ + val=bus_r(MULTI_PURPOSE_REG); + val = (val & (~(PLL_CLK_SEL_MSK))) | PLL_CLK_SEL_SLAVE_ADC_VAL; + bus_w(MULTI_PURPOSE_REG,val); + setPhaseShift(slaveadcphase); + } + + + + if (masterflags == IS_MASTER || masterflags == IS_SLAVE) { + val=bus_r(MULTI_PURPOSE_REG); +//#ifdef VERBOSE + printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); +//#endif + val = (val & (~(RST_TO_SW1_DELAY_MSK))) | ((rsttosw1delay << RST_TO_SW1_DELAY_OFFSET) & (RST_TO_SW1_DELAY_MSK)); + bus_w(MULTI_PURPOSE_REG,val); + } + + fclose(fd); +} + + int setPhaseShiftOnce(){ u_int32_t addr, reg; int i; @@ -256,6 +397,31 @@ int setPhaseShiftOnce(){ } +int setPhaseShift(int numphaseshift){ + u_int32_t addr, reg; + int i; + addr=MULTI_PURPOSE_REG; + reg=bus_r(addr); +#ifdef VERBOSE + printf("Multipurpose reg:%x\n",reg); +#endif + + printf("\nImplementing phase shift of %d\n",numphaseshift); + for (i=0;i= 0.5){ + if(actualvalue > value) + value++; + else + value--; + } + } return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ); } @@ -909,7 +1083,14 @@ int64_t getGates(){ int64_t setPeriod(int64_t value){ /* time is in ns */ if (value!=-1) { - value*=(1E-9*CLK_FREQ); + double actualvalue = value*(1E-9*CLK_FREQ); + value*=(1E-9*CLK_FREQ); + if(fabs(actualvalue-value)>= 0.5){ + if(actualvalue > value) + value++; + else + value--; + } } @@ -924,9 +1105,26 @@ int64_t getPeriod(){ int64_t setDelay(int64_t value){ /* time is in ns */ if (value!=-1) { - value*=(1E-9*CLK_FREQ); + if (masterflags == IS_MASTER) { + value += masterdefaultdelay; + cprintf(BLUE,"Actual delay for master: %lld\n", (long long int) value); + } + double actualvalue = value*(1E-9*CLK_FREQ); + value*=(1E-9*CLK_FREQ); + if(fabs(actualvalue-value)>= 0.5){ + if(actualvalue > value) + value++; + else + value--; + } } - return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ); + int64_t retval = set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ); + if (masterflags == IS_MASTER) { + cprintf(BLUE,"Actual delay read from master: %lld\n", (long long int) retval); + retval -= masterdefaultdelay; + } + + return retval; } int64_t getDelay(){ @@ -1255,7 +1453,7 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d tse_conf *tse_conf_regs; long int sum = 0; long int checksum; - int count,val; + int count; unsigned short *addr; mac_conf_regs=(mac_conf*)(CSP0BASE+offset*2); @@ -1265,35 +1463,40 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d printf("***Configuring MAC*** \n"); #endif + if(ival) - bus_w(addrr,(RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset) + bus_w(addrr, bus_r(addrr) | (RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset) else - bus_w(addrr,RESET_BIT); //0x080,reset mac (reset) - val=bus_r(addrr); + bus_w(addrr, bus_r(addrr) | RESET_BIT); //0x080,reset mac (reset) + #ifdef VERBOSE - printf("Value read from Multi-purpose Reg:%x\n",val); + printf("Value read from Multi-purpose Reg:%x\n",bus_r(addrr)); #endif // if(val!=0x080) return -1; usleep(500000); + + bus_w(addrr, bus_r(addrr) &(~ RESET_BIT));/* release reset */ if(ival) - bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak) + bus_w(addrr, bus_r(addrr) | (ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak) else - bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x840,write shadow regs(enet reset,write bak) - val=bus_r(addrr); + bus_w(addrr, bus_r(addrr) | (ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x840,write shadow regs(enet reset,write bak) + #ifdef VERBOSE - printf("Value read from Multi-purpose Reg:%x\n",val); + printf("Value read from Multi-purpose Reg:%x\n",bus_r(addrr)); #endif // if(val!=0x840) return -1; + bus_w(addrr, bus_r(addrr) &(~WRITE_BACK_BIT));/* release write_back */ + if(ival) - bus_w(addrr,(ENET_RESETN_BIT|DIGITAL_TEST_BIT)); //0x800,nreset phy(enet reset) + bus_w(addrr, bus_r(addrr) | (ENET_RESETN_BIT|DIGITAL_TEST_BIT)); //0x800,nreset phy(enet reset) else - bus_w(addrr,ENET_RESETN_BIT); //0x800,nreset phy(enet reset) - val=bus_r(addrr); + bus_w(addrr, bus_r(addrr) | ENET_RESETN_BIT); //0x800,nreset phy(enet reset) + #ifdef VERBOSE - printf("Value read from Multi-purpose Reg:%x\n",val); + printf("Value read from Multi-purpose Reg:%x\n",bus_r(addrr)); #endif // if(val!=0x800) return -1; @@ -1398,26 +1601,26 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d if(ival) - bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x2840,write shadow regs.. + bus_w(addrr, bus_r(addrr) | (INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x2840,write shadow regs.. else - bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x2840,write shadow regs.. + bus_w(addrr, bus_r(addrr) | (INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x2840,write shadow regs.. - val=bus_r(addrr); #ifdef VERBOSE - printf("Value read from Multi-purpose Reg:%x\n",val); + printf("Value read from Multi-purpose Reg:%x\n",bus_r(addrr)); #endif // if(val!=0x2840) return -1; usleep(100000); - if(ival) - bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT|DIGITAL_TEST_BIT)); //0x2820,write shadow regs.. - else - bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT)); //0x2820,write shadow regs.. + bus_w(addrr, bus_r(addrr) &(~WRITE_BACK_BIT)); + + if(ival) + bus_w(addrr, bus_r(addrr) | (INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT|DIGITAL_TEST_BIT)); //0x2820,write shadow regs.. + else + bus_w(addrr, bus_r(addrr) | (INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT)); //0x2820,write shadow regs.. - val=bus_r(addrr); #ifdef VERBOSE - printf("Value read from Multi-purpose Reg:%x\n",val); + printf("Value read from Multi-purpose Reg:%x\n",bus_r(addrr)); #endif // if(val!=0x2820) return -1; @@ -1814,7 +2017,9 @@ int allocateRAM() { } -int prepareADC(){ + + +int configureADC(){ printf("Preparing ADC\n"); u_int32_t valw,codata,csmask; int i,j,cdx,ddx; @@ -1834,26 +2039,26 @@ int prepareADC(){ // start point valw=0xff; - bus_w(ADC_WRITE_REG,(valw)); + bus_w(ADC_SPI_REG,(valw)); //chip sel bar down valw=((0xffffffff&(~csmask))); - bus_w(ADC_WRITE_REG,valw); + bus_w(ADC_SPI_REG,valw); for (i=0;i<24;i++) { //cldwn valw=valw&(~(0x1<>(23-i))&0x1)<>(23-i))&0x1)<>(23-i))&0x1)<>(23-i))&0x1)<>(23-i))&0x1)<>(23-i))&0x1)<>(23-i))&0x1)< gitInfo.txt + cd ../../ + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi \ No newline at end of file diff --git a/slsDetectorSoftware/jctbDetectorServer/Makefile.ctb b/slsDetectorSoftware/jctbDetectorServer/Makefile.ctb index 52b5bb8df..788977390 100644 --- a/slsDetectorSoftware/jctbDetectorServer/Makefile.ctb +++ b/slsDetectorSoftware/jctbDetectorServer/Makefile.ctb @@ -22,12 +22,15 @@ OBJS = $(SRCS:%.c=%.o) -all: clean $(PROGS) +all: clean versioning $(PROGS) test: clean jungfrauADCTEst boot: $(OBJS) +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` + jungfrauDetectorServerTest: $(OBJS) echo $(OBJS) $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) diff --git a/slsDetectorSoftware/jctbDetectorServer/updateGitVersion.sh b/slsDetectorSoftware/jctbDetectorServer/updateGitVersion.sh new file mode 100755 index 000000000..476546726 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/updateGitVersion.sh @@ -0,0 +1,31 @@ +SERVER=jctbDetectorServer +MAINDIR=slsDetectorsPackage +SPECDIR=slsDetectorSoftware/$SERVER +TMPFILE=gitInfoMoenchTmp.h +INCLFILE=gitInfoMoench.h + + +#evaluate the variables +EVALFILE=../../evalVersionVariables.sh +source $EVALFILE + + +#get modified date +#RDATE1='git log --pretty=format:"%ci" -1' +RDATE1="find . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|.git|updateGitVersion|.o' | head -n 1" +RDATE=`eval $RDATE1` +NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}') +NEWDATE=${NEWDATE/#/0x} + + +#get old date from INCLFILE +OLDDATE=$(more $INCLFILE | grep '#define SVNDATE' | awk '{print $3}') + + +#update INCLFILE if changes +if [ "$OLDDATE" != "$NEWDATE" ]; then + echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt + cd ../../ + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi \ No newline at end of file diff --git a/slsDetectorSoftware/jungfrauDetectorServer/Makefile b/slsDetectorSoftware/jungfrauDetectorServer/Makefile index 8ff6779c8..a1c89973e 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/Makefile +++ b/slsDetectorSoftware/jungfrauDetectorServer/Makefile @@ -10,12 +10,15 @@ INSTMODE = 0777 SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c OBJS = $(SRC_CLNT:.c=.o) -all: clean $(PROGS) +all: clean versioning $(PROGS) boot: $(OBJS) +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` + $(PROGS): $(OBJS) - echo $(OBJS) +# echo $(OBJS) mkdir -p $(DESTDIR) $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) mv $(PROGS) $(DESTDIR) @@ -24,3 +27,5 @@ $(PROGS): $(OBJS) clean: rm -rf $(DESTDIR)/$(PROGS) *.o + + \ No newline at end of file diff --git a/slsDetectorSoftware/jungfrauDetectorServer/RegisterDefs.h b/slsDetectorSoftware/jungfrauDetectorServer/RegisterDefs.h index e38a02c38..45a9761dc 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/RegisterDefs.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/RegisterDefs.h @@ -83,7 +83,13 @@ #define GET_PERIOD_MSB_REG (0x19 << 11) /** Get Temperature Carlos, incorrectl as get gates */ -#define GET_TEMPERATURE_TMP112_REG (0x1c << 11) // in 10ths of millidegrees of TMP112 +#define GET_TEMPERATURE_TMP112_REG (0x1c << 11) // (after multiplying by 625) in 10ths of millidegrees of TMP112 + +#define TEMPERATURE_POLARITY_BIT (15) +#define TEMPERATURE_POLARITY_MSK (0x00000001 << TEMPERATURE_POLARITY_BIT) +#define TEMPERATURE_VALUE_BIT (0) +#define TEMPERATURE_VALUE_MSK (0x00007FFF << TEMPERATURE_VALUE_BIT) + /* Get Frames from Start 64 bit register (frames from start Run Control) */ #define FRAMES_FROM_START_PG_LSB_REG (0x24 << 11) diff --git a/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServerv3.0.0.2 b/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServerv3.0.0.5 similarity index 54% rename from slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServerv3.0.0.2 rename to slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServerv3.0.0.5 index bb5878c24..0e633eb8f 100755 Binary files a/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServerv3.0.0.2 and b/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServerv3.0.0.5 differ diff --git a/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt b/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt index 4ee462b60..24e407864 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/jungfrauDetectorServer -URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer +URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 49f4f7295411e3dbcf00fd93ca821eb95e13771c -Revision: 80 +Repsitory UUID: 9f1b82c18ab0893d65bfadeb646b8ea244614632 +Revision: 88 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 1411 -Last Changed Date: 2017-06-14 11:40:35 +0200 +Last Changed Rev: 1443 +Last Changed Date: 2017-07-10 10:40:23.000000002 +0200 ./Makefile diff --git a/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h b/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h index 48f27fbfe..3f01d08bf 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h @@ -1,11 +1,11 @@ //#define SVNPATH "" -#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer" +#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "49f4f7295411e3dbcf00fd93ca821eb95e13771c" -//#define SVNREV 0x1411 +#define SVNREPUUID "9f1b82c18ab0893d65bfadeb646b8ea244614632" +//#define SVNREV 0x1443 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x1411 -#define SVNDATE 0x20170614 +#define SVNREV 0x1443 +#define SVNDATE 0x20170710 // diff --git a/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c index c7570da17..839a86e63 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -25,11 +25,11 @@ int32_t clkPhase[2] = {0, 0}; /* basic tests */ -void checkFirmwareCompatibility(){ +void checkFirmwareCompatibility() { defineGPIOpins(); resetFPGA(); - if ((mapCSP0() == FAIL) || (checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL) ) { + if ((mapCSP0() == FAIL) || (checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL)) { cprintf(BG_RED, "Dangerous to continue. Goodbye!\n"); exit(EXIT_FAILURE); } @@ -838,34 +838,25 @@ void setDAC(enum DACINDEX ind, int val, int imod, int mV, int retval[]){ int getADC(enum ADCINDEX ind, int imod){ - char tempnames[2][40]={"VRs/FPGAs Temperature", "ADCs/ASICs Temperature"}; printf("Getting Temperature for %s\n",tempnames[ind]); u_int32_t addr = GET_TEMPERATURE_TMP112_REG; - int retval = -1; -/* - u_int32_t val = 0; - { - int i; - for(i = 0; i < 10; i++) { - switch((int)ind){ + uint32_t regvalue = bus_r(addr); + uint32_t value = regvalue & TEMPERATURE_VALUE_MSK; + double retval = value; - case TEMP_FPGA: - val = (val<<1) + ((bus_r(addr) & (2)) >> 1); - break; - case TEMP_ADC: - val= (val<<1) + (bus_r(addr) & (1)); - break; - } - } + // negative + if (regvalue & TEMPERATURE_POLARITY_MSK) { + // 2s complement + int ret = (~value) + 1; + // attach negative sign + ret = 0 - value; + retval = ret; } - // or just read it - retval = ((int)val) / 4.0; - - printf("Temperature %s: %d °C\n",tempnames[ind],retval);*/ - printf("\nReal Temperature %s: %d °C\n",tempnames[ind],bus_r(addr)); - + // conversion + retval *= 625.0/10.0; + printf("\nReal Temperature %s: %f °C\n",tempnames[ind],retval/1000.00); return retval; } @@ -1303,8 +1294,8 @@ int calculateDataBytes(){ return DATA_BYTES; } -int getTotalNumberOfChannels(){return ((int)getNumberOfChannelsPerModule() * (int)getTotalNumberOfModules);} -int getTotalNumberOfChips(){return ((int)getNumberOfChipsPerModule * (int)getTotalNumberOfModules);} +int getTotalNumberOfChannels(){return ((int)getNumberOfChannelsPerModule() * (int)getTotalNumberOfModules());} +int getTotalNumberOfChips(){return ((int)getNumberOfChipsPerModule() * (int)getTotalNumberOfModules());} int getTotalNumberOfModules(){return NMOD;} int getNumberOfChannelsPerModule(){return ((int)getNumberOfChannelsPerChip() * (int)getTotalNumberOfChips());} int getNumberOfChipsPerModule(){return NCHIP;} diff --git a/slsDetectorSoftware/jungfrauDetectorServer/updateGitVersion.sh b/slsDetectorSoftware/jungfrauDetectorServer/updateGitVersion.sh new file mode 100755 index 000000000..238c47eb6 --- /dev/null +++ b/slsDetectorSoftware/jungfrauDetectorServer/updateGitVersion.sh @@ -0,0 +1,31 @@ +SERVER=jungfrauDetectorServer +MAINDIR=slsDetectorsPackage +SPECDIR=slsDetectorSoftware/$SERVER +TMPFILE=gitInfoJungfrauTmp.h +INCLFILE=gitInfoJungfrau.h + + +#evaluate the variables +EVALFILE=../../evalVersionVariables.sh +source $EVALFILE + + +#get modified date +#RDATE1='git log --pretty=format:"%ci" -1' +RDATE1="find ../slsDetectorServer . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|bin|.git|updateGitVersion|.o' | head -n 1" +RDATE=`eval $RDATE1` +NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}') +NEWDATE=${NEWDATE/#/0x} + + +#get old date from INCLFILE +OLDDATE=$(more $INCLFILE | grep '#define SVNDATE' | awk '{print $3}') + + +#update INCLFILE if changes +if [ "$OLDDATE" != "$NEWDATE" ]; then + echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt + cd ../../ + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi \ No newline at end of file diff --git a/slsDetectorSoftware/moenchDetectorServer/Makefile b/slsDetectorSoftware/moenchDetectorServer/Makefile index b067de322..490d4761b 100755 --- a/slsDetectorSoftware/moenchDetectorServer/Makefile +++ b/slsDetectorSoftware/moenchDetectorServer/Makefile @@ -21,10 +21,13 @@ OBJS = $(SRCS:%.c=%.o) -all: clean $(PROGS) +all: clean versioning $(PROGS) boot: $(OBJS) +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` + $(PROGS): $(OBJS) echo $(OBJS) $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) @@ -40,7 +43,7 @@ romfs: clean: rm -rf $(PROGS) *.o *.gdb - + diff --git a/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt b/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt index 2fc4e3520..178eb0fa1 100644 --- a/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/moenchDetectorServer -URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/moenchDetectorServer +URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 8aceb5d4b0ca6bd95a11b53e7a799b463b92d51b -Revision: 80 +Repsitory UUID: 9f1b82c18ab0893d65bfadeb646b8ea244614632 +Revision: 83 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 334 -Last Changed Date: 2016-08-12 11:08:03 +0200 +Last Changed Rev: 1443 +Last Changed Date: 2017-07-10 11:03:27.000000002 +0200 ./Makefile diff --git a/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h b/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h index 13579414d..3f01d08bf 100644 --- a/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h +++ b/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h @@ -1,11 +1,11 @@ //#define SVNPATH "" -#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/moenchDetectorServer" +#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "8aceb5d4b0ca6bd95a11b53e7a799b463b92d51b" -//#define SVNREV 0x334 +#define SVNREPUUID "9f1b82c18ab0893d65bfadeb646b8ea244614632" +//#define SVNREV 0x1443 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x334 -#define SVNDATE 0x20160812 +#define SVNREV 0x1443 +#define SVNDATE 0x20170710 // diff --git a/slsDetectorSoftware/moenchDetectorServer/updateGitVersion.sh b/slsDetectorSoftware/moenchDetectorServer/updateGitVersion.sh new file mode 100755 index 000000000..3ad0a2b06 --- /dev/null +++ b/slsDetectorSoftware/moenchDetectorServer/updateGitVersion.sh @@ -0,0 +1,31 @@ +SERVER=moenchDetectorServer +MAINDIR=slsDetectorsPackage +SPECDIR=slsDetectorSoftware/$SERVER +TMPFILE=gitInfoMoenchTmp.h +INCLFILE=gitInfoMoench.h + + +#evaluate the variables +EVALFILE=../../evalVersionVariables.sh +source $EVALFILE + + +#get modified date +#RDATE1='git log --pretty=format:"%ci" -1' +RDATE1="find . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|.git|updateGitVersion|.o' | head -n 1" +RDATE=`eval $RDATE1` +NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}') +NEWDATE=${NEWDATE/#/0x} + + +#get old date from INCLFILE +OLDDATE=$(more $INCLFILE | grep '#define SVNDATE' | awk '{print $3}') + + +#update INCLFILE if changes +if [ "$OLDDATE" != "$NEWDATE" ]; then + echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt + cd ../../ + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi \ No newline at end of file diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 813e9b975..000b7c82d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1168,7 +1168,7 @@ int multiSlsDetector::getThresholdEnergy(int pos) { } -int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings) { +int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings, int tb) { int posmin, posmax; int ret=-100; @@ -1189,8 +1189,8 @@ int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings ise for(int idet=posmin; idet(&slsDetector::setThresholdEnergy, - detectors[idet],e_eV,-1,isettings,iret[idet])); + Task* task = new Task(new func4_t(&slsDetector::setThresholdEnergy, + detectors[idet],e_eV,-1,isettings,tb,iret[idet])); threadpool->add_task(task); } } @@ -1359,75 +1359,219 @@ int multiSlsDetector::getChanRegs(double* retval,bool fromDetector){ /* Communication to server */ +int multiSlsDetector::prepareAcquisition(){ + + int i=0; + int ret=OK; + int posmin=0, posmax=thisMultiDetector->numberOfDetectors; + + if(!threadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return FAIL; + }else{ + int* iret[posmax-posmin]; + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::prepareAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->prepareAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; + + i=thisMultiDetector->masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->cleanupAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::cleanupAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; i++) { - if (i!=thisMultiDetector->masterPosition) - if (detectors[i]) { - ret=detectors[i]->startAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<masterPosition; - if (thisMultiDetector->masterPosition>=0) { - if (detectors[i]) { - ret=detectors[i]->startAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; + + if(!threadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return FAIL; + }else{ + int* iret[posmax-posmin]; + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::startAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->startAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; + i=thisMultiDetector->masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->stopAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition; - if (thisMultiDetector->masterPosition>=0) { - if (detectors[i]) { - ret=detectors[i]->stopAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; i++) { - if (detectors[i]) { - ret=detectors[i]->stopAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<masterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::stopAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<onlineFlag==ONLINE_FLAG) { - - startAndReadAllNoWait(); + + if(getDetectorsType() == EIGER) { + if (prepareAcquisition() == FAIL) + return NULL; + } + startAndReadAllNoWait(); while ((retval=getDataFromDetector())){ i++; @@ -2971,13 +3119,12 @@ int multiSlsDetector::getAngularConversion(int &direction, angleConversionCons dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) { dacs_t ret = -100; - if(!threadpool){ - cout << "Error in creating threadpool. Exiting" << endl; - return -1; - }else{ + + // single + { int id=-1, im=-1; - int posmin=0, posmax=thisMultiDetector->numberOfDetectors; if (decodeNMod(imod, id, im)>=0) { + posmin=id; posmax=id+1; } @@ -3007,50 +3154,108 @@ dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) { }else ret=-1; if(detectors[idet]->getErrorMask()) setErrorMask(getErrorMask()|(1<numberOfDetectors; + dacs_t* iret[posmax-posmin]; + + for(int idet=posmin; idet(&slsDetector::setDAC, + detectors[idet],val, idac, mV, imod, iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetgetErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { + if(detectors[id]){ + ret = detectors[id]->getADC(idac, im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; - if (decodeNMod(imod, id, im)>=0) { - posmin=id; - posmax=id+1; - } - //return storage values - dacs_t* iret[posmax-posmin]; - for(int idet=posmin; idet(&slsDetector::getADC, - detectors[idet],idac, im, iret[idet])); - threadpool->add_task(task); - } - } - threadpool->startExecuting(); - threadpool->wait_for_tasks_to_complete(); - for(int idet=posmin; idetgetErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; + dacs_t* iret[posmax-posmin]; + + for(int idet=posmin; idet(&slsDetector::getADC, + detectors[idet],idac, imod, iret[idet])); + threadpool->add_task(task); } } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetgetErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { dmi=id; - dma=dma+1; + dma=id+1; } for (int idet=dmi; idetnumberOfDetectors]; for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ + if (p == RECEIVER_STREAMING_PORT) + s.append("multi\0"); sret[idet]=new string("error"); Task* task = new Task(new func2_t (&slsDetector::setNetworkParameter, detectors[idet],p,s,sret[idet])); @@ -3458,7 +3672,11 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s){ } } - +/* + //enable data streaming if it was on + if (p == RECEIVER_STREAMING_PORT && prev_streaming) + enableDataStreamingFromReceiver(1); +*/ return getNetworkParameter(p); } @@ -4044,51 +4262,55 @@ int multiSlsDetector::digitalTest(digitalTestMode mode, int imod) { int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod) { - int id, im, ret=100; + int ret=100; - if (decodeNMod(imod, id, im)>=0) { - if (detectors[id]) { - ret = detectors[id]->executeTrimming(mode, par1, par2, im); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<=0) { + if (detectors[id]) { + ret = detectors[id]->executeTrimming(mode, par1, par2, im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors]; - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - iret[idet]= new int(-1); - Task* task = new Task(new func4_t (&slsDetector::executeTrimming, - detectors[idet],mode,par1,par2,imod,iret[idet])); - threadpool->add_task(task); - } - } - threadpool->startExecuting(); - threadpool->wait_for_tasks_to_complete(); - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - if(iret[idet] != NULL){ - if (ret==-100) - ret=*iret[idet]; - else if (ret!=*iret[idet]) - ret=-1; - delete iret[idet]; - }else ret=-1; - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors]; + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + iret[idet]= new int(-1); + Task* task = new Task(new func4_t (&slsDetector::executeTrimming, + detectors[idet],mode,par1,par2,imod,iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + if(iret[idet] != NULL){ + if (ret==-100) + ret=*iret[idet]; + else if (ret!=*iret[idet]) + ret=-1; + delete iret[idet]; + }else ret=-1; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { - if (detectors[id]) { - ret = detectors[id]->loadSettingsFile(fname, im); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<=0) { + if(detectors[id]){ + ret = detectors[id]->loadSettingsFile(fname, im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors]; - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - iret[idet]= new int(OK); - Task* task = new Task(new func2_t (&slsDetector::loadSettingsFile, - detectors[idet],fname,imod,iret[idet])); - threadpool->add_task(task); - } - } - threadpool->startExecuting(); - threadpool->wait_for_tasks_to_complete(); - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - if(iret[idet] != NULL){ - if(*iret[idet] != OK) - ret = FAIL; - delete iret[idet]; - }else ret = FAIL; - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors]; + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + iret[idet]= new int(OK); + Task* task = new Task(new func2_t (&slsDetector::loadSettingsFile, + detectors[idet],fname,imod,iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { - if (detectors[id]) { - ret = detectors[id]->saveSettingsFile(fname, im); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { - if (detectors[idet]) { - ret=detectors[idet]->saveSettingsFile(fname, imod); - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<=0) { + if (detectors[id]) { + ret = detectors[id]->saveSettingsFile(fname, im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->saveSettingsFile(fname, imod); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { - if (detectors[id]) { - ret=detectors[id]->setAllTrimbits(val,im); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<=0) { + if(detectors[id]){ + ret = detectors[id]->setAllTrimbits(val,im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors]; - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - iret[idet]= new int(-1); - Task* task = new Task(new func2_t (&slsDetector::setAllTrimbits, - detectors[idet],val,imod,iret[idet])); - threadpool->add_task(task); - } - } - threadpool->startExecuting(); - threadpool->wait_for_tasks_to_complete(); - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - if(iret[idet] != NULL){ - if (ret==-100) - ret=*iret[idet]; - else if (ret!=*iret[idet]) - ret=-1; - delete iret[idet]; - }else ret=-1; - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors]; + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + iret[idet]= new int(-1); + Task* task = new Task(new func2_t (&slsDetector::setAllTrimbits, + detectors[idet],val,imod,iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + if(iret[idet] != NULL){ + if (ret==-100) + ret=*iret[idet]; + else if (ret!=*iret[idet]) + ret=-1; + delete iret[idet]; + }else ret=-1; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { - if (detectors[id]) { - ret = detectors[id]->loadCalibrationFile(fname, im); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<=0) { + if(detectors[id]){ + ret = detectors[id]->loadCalibrationFile(fname, im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors]; - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - iret[idet]= new int(OK); - Task* task = new Task(new func2_t (&slsDetector::loadCalibrationFile, - detectors[idet],fname,imod,iret[idet])); - threadpool->add_task(task); - } - } - threadpool->startExecuting(); - threadpool->wait_for_tasks_to_complete(); - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - if(iret[idet] != NULL){ - if(*iret[idet] != OK) - ret = FAIL; - delete iret[idet]; - }else ret = FAIL; - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors]; + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + iret[idet]= new int(OK); + Task* task = new Task(new func2_t (&slsDetector::loadCalibrationFile, + detectors[idet],fname,imod,iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<=0) { - if (detectors[id]) { - ret = detectors[id]->saveCalibrationFile(fname, im); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { - if (detectors[idet]) { - ret=detectors[idet]->saveCalibrationFile(fname, imod); - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<=0) { + if (detectors[id]) { + ret = detectors[id]->saveCalibrationFile(fname, im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->saveCalibrationFile(fname, imod); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<getReceiverStreamingPort().c_str(),"%d",&portnum); + if (portnum == 0) { + portnum = DEFAULT_ZMQ_PORTNO + + (i/numSocketsPerDetector)*numSocketsPerDetector + (i%numSocketsPerDetector); // *num and /num is not same cuz its integers + }else{ + portnum += (i%numSocketsPerDetector); + } + zmqSocket[i] = new ZmqSocket(detectors[i/numSocketsPerDetector]->getReceiver().c_str(), portnum); if (zmqSocket[i]->IsError()) { cprintf(RED, "Error: Could not create Zmq socket on port %d\n", portnum); @@ -5669,12 +5903,14 @@ int multiSlsDetector::setReceiverReadTimer(int time_in_ms){ return ret; } +int multiSlsDetector::getStreamingSocketsCreatedInClient() { + return dataSocketsStarted; +} -// only called from gui or that wants zmq data packets int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ if(enable >= 0){ - if(dataSocketsStarted != enable){ + /*if(dataSocketsStarted != enable){*/ //destroy data threads if(dataSocketsStarted) createReceivingDataSockets(true); @@ -5689,7 +5925,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ return -1; } } - } + /*}*/ } @@ -6035,6 +6271,11 @@ int multiSlsDetector::pulseChip(int n) { void multiSlsDetector::setAcquiringFlag(bool b){ thisMultiDetector->acquiringFlag = b; + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + detectors[idet]->setAcquiringFlag(b); + } + } } bool multiSlsDetector::getAcquiringFlag(){ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 22d582151..3a095a20d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -462,9 +462,10 @@ class multiSlsDetector : public slsDetectorUtils { \param e_eV threshold in eV \param imod module number (-1 all) \param isettings ev. change settings + \param tb 1 to include trimbits, 0 to exclude \returns current threshold value for imod in ev (-1 failed) */ - int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS); + int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS,int tb=1); /** get detector settings @@ -521,10 +522,10 @@ class multiSlsDetector : public slsDetectorUtils { int powerChip(int ival= -1); /** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */ - int loadSettingsFile(string fname, int nmod=0); + int loadSettingsFile(string fname, int nmod=-1); /** gets the modules settings/trimbits and writes them to file - file name extension is automatically generated! */ - int saveSettingsFile(string fname, int nmod=0); + int saveSettingsFile(string fname, int nmod=-1); /** sets all the trimbits to a particular value @@ -536,10 +537,10 @@ class multiSlsDetector : public slsDetectorUtils { /** loads the modules calibration data reading from a file - file name extension is automatically generated! */ - int loadCalibrationFile(string fname, int nmod=0); + int loadCalibrationFile(string fname, int nmod=-1); /** gets the modules calibration data and writes them to file - file name extension is automatically generated! */ - int saveCalibrationFile(string fname, int nmod=0); + int saveCalibrationFile(string fname, int nmod=-1); @@ -560,7 +561,17 @@ class multiSlsDetector : public slsDetectorUtils { // Acquisition functions + /** + prepares detector for acquisition + \returns OK if all detectors are properly started, FAIL otherwise + */ + int prepareAcquisition(); + /** + prepares detector for acquisition + \returns OK if all detectors are properly started, FAIL otherwise + */ + int cleanupAcquisition(); /** start detector acquisition (master is started as last) @@ -928,7 +939,7 @@ class multiSlsDetector : public slsDetectorUtils { \param val value (in V) \param index DAC index \param imod module number (if -1 alla modules) - \returns current DAC value + \returns current DAC value (temperature for eiger and jungfrau in millidegrees) */ dacs_t getADC(dacIndex index, int imod=-1); /** @@ -1318,6 +1329,13 @@ class multiSlsDetector : public slsDetectorUtils { */ int setReceiverReadTimer(int time_in_ms=500); + + /** + * Get Streaming sockets created in client from reciever + /returns 1 if sockets created, else 0 + */ + int getStreamingSocketsCreatedInClient(); + /** Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming diff --git a/slsDetectorSoftware/mythenDetectorServer/Makefile b/slsDetectorSoftware/mythenDetectorServer/Makefile index 99c2e4354..da0c0f291 100755 --- a/slsDetectorSoftware/mythenDetectorServer/Makefile +++ b/slsDetectorSoftware/mythenDetectorServer/Makefile @@ -21,11 +21,15 @@ CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DDACS_INT $(VFLAGS) LDLIBS+= -lm -mythen: clean $(PROGS) -all: $(PROGS) +mythen: clean versioning $(PROGS) +all: versioning $(PROGS) boot: $(OBJS) +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` + + $(PROGS): $(OBJS) echo $(OBJS) $(CC) $(LDFLAGS) $^ $(LDLIBS) $(CFLAGS) -o $@ @@ -39,3 +43,4 @@ clean: depend: makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null + \ No newline at end of file diff --git a/slsDetectorSoftware/mythenDetectorServer/Makefile.dum b/slsDetectorSoftware/mythenDetectorServer/Makefile.dum index 59a15e28e..4656a39bf 100644 --- a/slsDetectorSoftware/mythenDetectorServer/Makefile.dum +++ b/slsDetectorSoftware/mythenDetectorServer/Makefile.dum @@ -18,7 +18,7 @@ CFLAGS+= -Wall -DC_ONLY -DVERBOSE LDLIBS+= -lm -all: $(PROGS) +all: versioning $(PROGS) boot: $(OBJS) @@ -35,3 +35,6 @@ clean: depend: makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null + +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` \ No newline at end of file diff --git a/slsDetectorSoftware/mythenDetectorServer/Makefile.picasso b/slsDetectorSoftware/mythenDetectorServer/Makefile.picasso index 11e3645fd..48d204135 100644 --- a/slsDetectorSoftware/mythenDetectorServer/Makefile.picasso +++ b/slsDetectorSoftware/mythenDetectorServer/Makefile.picasso @@ -21,8 +21,8 @@ CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE -DVERYVERBOSE -DPICASSOD LDLIBS+= -lm picasso: $(PICASSO) -mythen: $(PROGS) -all: $(PROGS) $(PICASSO) +mythen: versioning $(PROGS) +all: versioning $(PROGS) $(PICASSO) boot: $(OBJS) @@ -44,3 +44,6 @@ clean: depend: makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null + +versioning: + @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` \ No newline at end of file diff --git a/slsDetectorSoftware/mythenDetectorServer/updateGitVersion.sh b/slsDetectorSoftware/mythenDetectorServer/updateGitVersion.sh new file mode 100755 index 000000000..6889e628d --- /dev/null +++ b/slsDetectorSoftware/mythenDetectorServer/updateGitVersion.sh @@ -0,0 +1,31 @@ +SERVER=mythenDetectorServer +MAINDIR=slsDetectorsPackage +SPECDIR=slsDetectorSoftware/$SERVER +TMPFILE=gitInfoMythenTmp.h +INCLFILE=gitInfoMythen.h + + +#evaluate the variables +EVALFILE=../../evalVersionVariables.sh +source $EVALFILE + + +#get modified date +#RDATE1='git log --pretty=format:"%ci" -1' +RDATE1="find ../slsDetectorServer . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|bin|.git|updateGitVersion|.o' | head -n 1" +RDATE=`eval $RDATE1` +NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}') +NEWDATE=${NEWDATE/#/0x} + + +#get old date from INCLFILE +OLDDATE=$(more $INCLFILE | grep '#define SVNDATE' | awk '{print $3}') + + +#update INCLFILE if changes +if [ "$OLDDATE" != "$NEWDATE" ]; then + echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt + cd ../../ + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetector/gitInfoLib.h b/slsDetectorSoftware/slsDetector/gitInfoLib.h index 82b2c7cbb..1b50b021d 100644 --- a/slsDetectorSoftware/slsDetector/gitInfoLib.h +++ b/slsDetectorSoftware/slsDetector/gitInfoLib.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" //#define SVNREPPATH "" -#define SVNREPUUIDLIB "a5b59b47430913bb461b50da05b553874b33f39a" -//#define SVNREV 0x1418 +#define SVNREPUUIDLIB "2dfbd9016b501eca6ee2c00a08e49a3f7e7990d8" +//#define SVNREV 0x1457 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTHLIB "Dhanya_Maliakal" -#define SVNREVLIB 0x1418 -#define SVNDATELIB 0x20170622 +#define SVNREVLIB 0x1457 +#define SVNDATELIB 0x20170809 // diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index edb5543d1..38ab1e404 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -26,9 +26,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) { #ifdef VERBOSE cout << "init shm"<< endl; #endif - switch(type) { + switch(type) { case MYTHEN: - nch=128; // complete mythen system + nch=128; // complete mythen system nm=24; nc=10; nd=6; // dacs+adcs @@ -777,6 +777,7 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->acquiringFlag = false; thisDetector->flippedData[0] = 0; thisDetector->flippedData[1] = 0; + thisDetector->zmqport = 0; for (int ia=0; iaactionScript[ia],"none"); @@ -1674,7 +1675,7 @@ int slsDetector::setDetectorType(detectorType const type){ //receiver - if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG)) { + if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG) && (arg != GENERIC)) { retval = FAIL; if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE @@ -2981,7 +2982,7 @@ int slsDetector::setModule(int reg, int imod){ }; -int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval){ +int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval, int tb){ int fnum=F_SET_MODULE; int retval; @@ -2998,6 +2999,11 @@ int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int if (thisDetector->onlineFlag==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 @@ -3031,23 +3037,29 @@ int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int if (ret!=FAIL) { if (detectorModules) { if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { - (detectorModules+imod)->nchan=module.nchan; - (detectorModules+imod)->nchip=module.nchip; + if(tb) { + (detectorModules+imod)->nchan=module.nchan; + (detectorModules+imod)->nchip=module.nchip; + } (detectorModules+imod)->ndac=module.ndac; (detectorModules+imod)->nadc=module.nadc; - thisDetector->nChips=module.nchip; - thisDetector->nChans=module.nchan/module.nchip; + if(tb) { + thisDetector->nChips=module.nchip; + thisDetector->nChans=module.nchan/module.nchip; + } thisDetector->nDacs=module.ndac; thisDetector->nAdcs=module.nadc; if(thisDetector->myDetectorType != JUNGFRAU){ - for (int ichip=0; ichipnChips; ichip++) { - if (chipregs) - chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip]; + if(tb) { + for (int ichip=0; ichipnChips; ichip++) { + if (chipregs) + chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip]; - if (chanregs) { - for (int i=0; inChans; i++) { - chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i]; + if (chanregs) { + for (int i=0; inChans; i++) { + chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i]; + } } } } @@ -3278,11 +3290,11 @@ int slsDetector::getThresholdEnergy(int imod){ return thisDetector->currentThresholdEV; }; -int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){ +int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings, int tb){ //currently only for eiger if (thisDetector->myDetectorType == EIGER) { - setThresholdEnergyAndSettings(e_eV,isettings); + setThresholdEnergyAndSettings(e_eV,isettings,tb); return thisDetector->currentThresholdEV; } @@ -3323,7 +3335,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti -int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings) { +int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb) { //if settings provided, use that, else use the shared memory variable detectorSettings is = ((isettings != GET_SETTINGS) ? isettings: thisDetector->currentSettings); @@ -3389,7 +3401,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti #endif //read the files myMod=createModule(); - if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) { + if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod, tb)) { if(myMod)deleteModule(myMod); return FAIL; } @@ -3424,13 +3436,13 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti 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,thisDetector->myDetectorType, iodelay1, tau1, myMod1)) { + if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, iodelay1, tau1, myMod1, tb)) { setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); deleteModule(myMod1); deleteModule(myMod2); return FAIL; } - if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2)) { + if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2, tb)) { setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); deleteModule(myMod1); deleteModule(myMod2); @@ -3446,14 +3458,14 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti iodelay = iodelay1; //interpolate module - myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2); + myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2, tb); if (myMod == NULL) { printf("Could not interpolate, different dac values in files\n"); setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); } //interpolate tau tau = linearInterpolation(e_eV, trim1, trim2, tau1, tau2); - printf("new tau:%d\n",tau); + //printf("new tau:%d\n",tau); deleteModule(myMod1); deleteModule(myMod2); @@ -3462,7 +3474,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti myMod->module=0; myMod->reg=thisDetector->currentSettings; - setModule(*myMod, iodelay, tau, e_eV, 0, 0); + setModule(*myMod, iodelay, tau, e_eV, 0, 0, tb); deleteModule(myMod); if (getSettings(-1) != is){ std::cout << "Could not set settings in detector" << endl; @@ -3965,6 +3977,62 @@ int slsDetector::updateDetector() { // Acquisition functions /* change these funcs accepting also ok/fail */ + +int slsDetector::prepareAcquisition() { + int fnum = F_PREPARE_ACQUISITION; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Preparing Detector for Acquisition" << std::endl; +#endif + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(PREPARE_ACQUISITION)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + }else + std::cout << "cannot connect to detector" << endl; + + return ret; +} + +int slsDetector::cleanupAcquisition() { + int fnum = F_CLEANUP_ACQUISITION; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Cleaning up Detector after Acquisition " << std::endl; +#endif + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(CLEANUP_ACQUISITION)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + }else + std::cout << "cannot connect to detector" << endl; + + return ret; + +} + int slsDetector::startAcquisition(){ @@ -4247,6 +4315,10 @@ int* slsDetector::startAndReadAll(){ int i=0; #endif //#endif + if(thisDetector->myDetectorType == EIGER) { + if (prepareAcquisition() == FAIL) + return NULL; + } startAndReadAllNoWait(); //#ifdef VERBOSE // std::cout<< "started" << std::endl; @@ -4439,7 +4511,8 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ //send acquisiton period/frame number to receiver - if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)||(index==ACQUISITION_TIME)){ + if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)||(index==ACQUISITION_TIME) || (index==SUBFRAME_ACQUISITION_TIME)){ + string timername = getTimerType(index); if(ret != FAIL){ int64_t args[2]; retval = -1; @@ -4448,25 +4521,21 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ - //set #frames, #cycles + //set #frames * #cycles if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){ + timername.assign("(Number of Frames) * (Number of cycles)"); #ifdef VERBOSE - std::cout << "Setting/Getting number of frames*cycles " << index <<" to/from receiver " << args[1] << std::endl; + std::cout << "Setting/Getting " << timername << " " << index <<" to/from receiver " << args[1] << std::endl; #endif if(thisDetector->timerValue[CYCLES_NUMBER]==0) args[1] = thisDetector->timerValue[FRAME_NUMBER]; else args[1] = thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]; } - //set period/exptime - else{ #ifdef VERBOSE - if(index==ACQUISITION_TIME) - std::cout << "Setting/Getting acquisition time " << index << " to/from receiver " << args[1] << std::endl; - else - std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl; + // set period/exptime/subexptime + else std::cout << "Setting/Getting " << timername << " " << index << " to/from receiver " << args[1] << std::endl; #endif - } char mess[MAX_STR_LENGTH]=""; if (connectData() == OK){ @@ -4475,18 +4544,23 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ } if((args[1] != retval)|| (ret==FAIL)){ ret = FAIL; - if(index==ACQUISITION_TIME){ - if(strstr(mess,"receiver not idle")==NULL) - cout << "ERROR:Acquisition Time in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; - setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET)); - }else if(index==FRAME_PERIOD){ - if(strstr(mess,"receiver not idle")==NULL) - cout << "ERROR:Acquisition Period in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; - setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); - }else{ - if(strstr(mess,"receiver not idle")==NULL) - cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; - setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); + cout << "ERROR: " << timername << " in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; + + if(strstr(mess,"receiver is not idle")==NULL) { + switch(index) { + case ACQUISITION_TIME: + setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET)); + break; + case FRAME_PERIOD: + setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); + break; + case SUBFRAME_ACQUISITION_TIME: + setErrorMask((getErrorMask())|(RECEIVER_SUBF_TIME_NOT_SET)); + break; + default: + setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); + break; + } } } if(ret==FORCE_UPDATE) @@ -5827,7 +5901,6 @@ int slsDetector::exitServer(){ string slsDetector::setNetworkParameter(networkParameter index, string value) { int i; - switch (index) { case DETECTOR_MAC: return setDetectorMAC(value); @@ -5845,19 +5918,22 @@ string slsDetector::setNetworkParameter(networkParameter index, string value) { return getReceiverUDPPort(); case RECEIVER_UDP_PORT2: sscanf(value.c_str(),"%d",&i); - if(thisDetector->myDetectorType == EIGER) + if(thisDetector->myDetectorType == EIGER) { setReceiverUDPPort2(i); - else - setReceiverUDPPort(i); - if(thisDetector->myDetectorType == EIGER) return getReceiverUDPPort2(); - return getReceiverUDPPort(); + } else { + setReceiverUDPPort(i); + return getReceiverUDPPort(); + } case DETECTOR_TXN_DELAY_LEFT: case DETECTOR_TXN_DELAY_RIGHT: case DETECTOR_TXN_DELAY_FRAME: case FLOW_CONTROL_10G: sscanf(value.c_str(),"%d",&i); return setDetectorNetworkParameter(index, i); + case RECEIVER_STREAMING_PORT: + setReceiverStreamingPort(value); + return getReceiverStreamingPort(); default: return (char*)("unknown network parameter"); } @@ -5867,34 +5943,29 @@ string slsDetector::setNetworkParameter(networkParameter index, string value) { string slsDetector::getNetworkParameter(networkParameter index) { - + ostringstream ss;string s; switch (index) { case DETECTOR_MAC: return getDetectorMAC(); - break; case DETECTOR_IP: return getDetectorIP(); - break; case RECEIVER_HOSTNAME: return getReceiver(); - break; case RECEIVER_UDP_IP: return getReceiverUDPIP(); - break; case RECEIVER_UDP_MAC: return getReceiverUDPMAC(); - break; case RECEIVER_UDP_PORT: return getReceiverUDPPort(); - break; case RECEIVER_UDP_PORT2: return getReceiverUDPPort2(); - break; case DETECTOR_TXN_DELAY_LEFT: case DETECTOR_TXN_DELAY_RIGHT: case DETECTOR_TXN_DELAY_FRAME: case FLOW_CONTROL_10G: return setDetectorNetworkParameter(index, -1); + case RECEIVER_STREAMING_PORT: + return getReceiverStreamingPort(); default: return (char*)("unknown network parameter"); } @@ -5974,6 +6045,7 @@ string slsDetector::setReceiver(string receiverIP){ std::cout << "file path:" << fileIO::getFilePath() << endl; std::cout << "file name:" << fileIO::getFileName() << endl; std::cout << "file index:" << fileIO::getFileIndex() << endl; + std::cout << "file format:" << fileIO::getFileFormat() << endl; pthread_mutex_lock(&ms); std::cout << "write enable:" << parentDet->enableWriteToFileMask() << endl; std::cout << "overwrite enable:" << parentDet->enableOverwriteMask() << endl; @@ -5981,8 +6053,12 @@ string slsDetector::setReceiver(string receiverIP){ std::cout << "frame index needed:" << ((thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER])>1) << endl; std::cout << "frame period:" << thisDetector->timerValue[FRAME_PERIOD] << endl; std::cout << "frame number:" << thisDetector->timerValue[FRAME_NUMBER] << endl; + std::cout << "sub exp time:" << thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME] << endl; std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl; + std::cout << "flippeddatax:" << thisDetector->flippedData[d] << endl; std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl; + std::cout << "streaming port:" << thisDetector->zmqport << endl; + //std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl; /** enable compresison, */ #endif @@ -5991,6 +6067,8 @@ string slsDetector::setReceiver(string receiverIP){ sendMultiDetectorSize(); setDetectorId(); setDetectorHostname(); + setUDPConnection(); + setFilePath(fileIO::getFilePath()); setFileName(fileIO::getFileName()); setFileIndex(fileIO::getFileIndex()); @@ -6003,6 +6081,7 @@ string slsDetector::setReceiver(string receiverIP){ imask = parentDet->enableOverwriteMask(); pthread_mutex_unlock(&ms); overwriteFile(imask); + if ((thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER])>1) setFrameIndex(0); else @@ -6011,19 +6090,30 @@ string slsDetector::setReceiver(string receiverIP){ setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]); setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); setTimer(ACQUISITION_TIME,thisDetector->timerValue[ACQUISITION_TIME]); + setTimer(SUBFRAME_ACQUISITION_TIME,thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]); setDynamicRange(thisDetector->dynamicRange); if(thisDetector->myDetectorType == EIGER){ setFlippedData(X,-1); activate(-1); } - //std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl; - //parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1)); - //set scan tag - setUDPConnection(); + if(thisDetector->myDetectorType == EIGER) enableTenGigabitEthernet(thisDetector->tenGigaEnable); - //datastreamenable - //fifodepth + + // data streaming + setReceiverStreamingPort(getReceiverStreamingPort()); + int clientSockets = parentDet->getStreamingSocketsCreatedInClient(); + int recSockets = enableDataStreamingFromReceiver(-1); + if(clientSockets != recSockets) { + pthread_mutex_lock(&ms); + if(clientSockets) + printf("Enabling Data Streaming\n"); + else + printf("Disabling Data Streaming\n"); + // push client state to receiver + parentDet->enableDataStreamingFromReceiver(clientSockets); + pthread_mutex_unlock(&ms); + } } } @@ -6122,6 +6212,42 @@ int slsDetector::setReceiverUDPPort2(int udpport){ } +int slsDetector::setReceiverStreamingPort(string port) { + int defaultport = 0; + int numsockets = (thisDetector->myDetectorType == EIGER) ? 2:1; + int arg = 0; + + //multi command, calculate individual ports + size_t found = port.find("multi"); + if(found != string::npos) { + port.erase(found,5); + sscanf(port.c_str(),"%d",&defaultport); + arg = defaultport + (posId * numsockets); + } + else + sscanf(port.c_str(),"%d",&arg); + + // send to receiver + int fnum=F_SET_RECEIVER_STREAMING_PORT; + int ret = FAIL; + int retval=-1; + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending receiver streaming port to receiver " << arg << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + } + if(ret!=FAIL) + thisDetector->zmqport = retval; + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + return thisDetector->zmqport; +} + string slsDetector::setDetectorNetworkParameter(networkParameter index, int delay){ int fnum = F_SET_NETWORK_PARAMETER; int ret = FAIL; @@ -7794,6 +7920,7 @@ int slsDetector::startReceiver(){ } } + //let detector prepare anyway even if receiver didnt work (for those not using the receiver) if((thisDetector->myDetectorType != JUNGFRAU) ) { int ret1 = detectorSendToReceiver(true); @@ -7813,7 +7940,7 @@ int slsDetector::stopReceiver(){ char mess[MAX_STR_LENGTH] = ""; if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU) - detectorSendToReceiver(false); + cleanupAcquisition(); // reset (send data to receiver) for these detectors, so back to CPU (dont care about ok/fail at this point) if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE @@ -7859,37 +7986,6 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){ } -int slsDetector::detectorSendToReceiver(bool set){ - int fnum; - if(set) fnum=F_PREPARE_ACQUISITION; - else fnum=F_CLEANUP_ACQUISITION; - int ret = FAIL; - char mess[MAX_STR_LENGTH]=""; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - std::cout << "Setting detector to send packets via client to: " << set << std::endl; -#endif - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - }else - std::cout << "cannot connect to detector" << endl; - - return ret; -} - - - - @@ -8098,21 +8194,46 @@ int slsDetector::updateReceiverNoWait() { cout << "Updating receiver last modified by " << lastClientIP << std::endl; #endif - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - pthread_mutex_lock(&ms); - fileIO::setFileIndex(ind); - pthread_mutex_unlock(&ms); - + // filepath n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); pthread_mutex_lock(&ms); fileIO::setFilePath(path); pthread_mutex_unlock(&ms); + // filename n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); pthread_mutex_lock(&ms); fileIO::setFileName(path); pthread_mutex_unlock(&ms); + // index + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + fileIO::setFileIndex(ind); + pthread_mutex_unlock(&ms); + + //file format + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + fileIO::setFileFormat(ind); + pthread_mutex_unlock(&ms); + + // file write enable + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + parentDet->enableWriteToFileMask(ind); + pthread_mutex_unlock(&ms); + + // file overwrite enable + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + parentDet->enableOverwriteMask(ind); + pthread_mutex_unlock(&ms); + + // streaming port + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + thisDetector->zmqport = ind; + if (!n) printf("n: %d\n", n); return OK; @@ -8132,12 +8253,14 @@ int slsDetector::updateReceiver() { if (connectData() == OK){ dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - updateReceiverNoWait(); - else{ + if (ret == FAIL) { dataSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Receiver returned error: " << mess << std::endl; } + else + updateReceiverNoWait(); + + //if ret is force update, do not update now as client is updating receiver currently disconnectData(); } } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index eca4863b5..d6005448b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -269,7 +269,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { bool acquiringFlag; /** flipped data across x or y axis */ int flippedData[2]; - + /** tcp port between receiver and gui (only data) */ + int zmqport; } sharedSlsDetector; @@ -886,7 +887,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { set dacs value \param index ADC index \param imod module number - \returns current ADC value + \returns current ADC value (temperature for eiger and jungfrau in millidegrees) */ dacs_t getADC(dacIndex index, int imod=0); @@ -965,10 +966,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion { \param e_eV threashold in eV (detector specific) \param gainval pointer to extra gain values \param offsetval pointer to extra offset values + \param tb 1 to include trimbits, 0 to exclude (used for eiger) \returns current register value \sa ::sls_detector_module */ - int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0); + int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0, int tb=1); //virtual int setModule(sls_detector_module module); /** @@ -999,17 +1001,19 @@ class slsDetector : public slsDetectorUtils, public energyConversion { \param e_eV threshold in eV \param imod module number (-1 all) \param isettings ev. change settings + \param tb 1 to include trimbits, 0 to exclude \returns current threshold value for imod in ev (-1 failed) */ - int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS); + int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS, int tb=1); /** set threshold energy \param e_eV threshold in eV \param isettings ev. change settings + \param tb 1 to include trimbits, 0 to exclude \returns OK if successful, else FAIL */ - int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings); + int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb=1); /** get detector settings @@ -1059,6 +1063,17 @@ class slsDetector : public slsDetectorUtils, public energyConversion { // Acquisition functions + /** + prepares detector for acquisition + \returns OK/FAIL + */ + int prepareAcquisition(); + + /** + prepares detector for acquisition + \returns OK/FAIL + */ + int cleanupAcquisition(); /** start detector acquisition @@ -1610,10 +1625,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ runStatus startReceiverReadout(); - /** Sets(false) or Resets(true) the CPU bit in detector - \returns OK or FAIL - */ - int detectorSendToReceiver(bool set); /** gets the status of the listening mode of receiver \returns status @@ -1717,6 +1728,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { string getReceiverUDPPort() {ostringstream ss; ss << thisDetector->receiverUDPPort; string s = ss.str(); return s;}; /** returns the receiver UDP2 for Eiger IP address \sa sharedSlsDetector */ string getReceiverUDPPort2() {ostringstream ss; ss << thisDetector->receiverUDPPort2; string s = ss.str(); return s;}; + /** returns the zmq port \sa sharedSlsDetector */ + string getReceiverStreamingPort() {ostringstream ss; ss << thisDetector->zmqport; string s = ss.str(); return s;}; /** validates the format of detector MAC address and sets it \sa sharedSlsDetector */ string setDetectorMAC(string detectorMAC); @@ -1732,6 +1745,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int setReceiverUDPPort(int udpport); /** sets the receiver udp port2 for Eiger \sa sharedSlsDetector */ int setReceiverUDPPort2(int udpport); + /** sets the zmq port in client and receiver (includes "multi" at the end if it should calculate individual ports \sa sharedSlsDetector */ + int setReceiverStreamingPort(string port); /** sets the transmission delay for left or right port or for an entire frame*/ string setDetectorNetworkParameter(networkParameter index, int delay); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.h b/slsDetectorSoftware/slsDetector/slsDetectorActions.h index a034e6bf0..b0b7dfe56 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.h @@ -207,7 +207,7 @@ class slsDetectorActions : public virtual slsDetectorBase /* *\/ */ /* virtual detectorType getDetectorsType(int pos=-1)=0; */ - virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0; + virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS, int tb=1)=0; virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index e29e17a30..e9d5e71f6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -429,7 +429,7 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef virtual externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE)=0; int setTimingMode(int i=-1){return slsDetectorUsers::getTimingMode( externalCommunicationType( setExternalCommunicationMode(externalCommunicationType( slsDetectorUsers::getTimingMode(i) ) ) ) );}; - virtual int setThresholdEnergy(int e_eV, int imod, detectorSettings isettings=GET_SETTINGS)=0; + virtual int setThresholdEnergy(int e_eV, int imod, detectorSettings isettings=GET_SETTINGS, int tb=1)=0; int setThresholdEnergy(int e_eV){return setThresholdEnergy(e_eV,-1);}; @@ -751,6 +751,30 @@ virtual void readFrameFromReceiver()=0; default: return string("unknown"); \ }}; + /** returns string from timer index + \param s can be FRAME_NUMBER,ACQUISITION_TIME,FRAME_PERIOD, DELAY_AFTER_TRIGGER,GATES_NUMBER,PROBES_NUMBER, CYCLES_NUMBER, ACTUAL_TIME,MEASUREMENT_TIME, PROGRESS,MEASUREMENTS_NUMBER,FRAMES_FROM_START,FRAMES_FROM_START_PG,SAMPLES_JCTB,SUBFRAME_ACQUISITION_TIME + \returns string frame_number,acquisition_time,frame_period, delay_after_trigger,gates_number,probes_number, cycles_number, actual_time,measurement_time, progress,measurements_number,frames_from_start,frames_from_start_pg,samples_jctb,subframe_acquisition_time + */ + static string getTimerType(timerIndex t){ \ + switch (t) { \ + case FRAME_NUMBER: return string("frame_number"); \ + case ACQUISITION_TIME: return string("acquisition_time"); \ + case FRAME_PERIOD: return string("frame_period"); \ + case DELAY_AFTER_TRIGGER: return string("delay_after_trigger"); \ + case GATES_NUMBER: return string("gates_number"); \ + case PROBES_NUMBER: return string("probes_number"); \ + case CYCLES_NUMBER: return string("cycles_number"); \ + case ACTUAL_TIME: return string("actual_time"); \ + case MEASUREMENT_TIME: return string("measurement_time"); \ + case PROGRESS: return string("progress"); \ + case MEASUREMENTS_NUMBER: return string("measurements_number"); \ + case FRAMES_FROM_START: return string("frames_from_start"); \ + case FRAMES_FROM_START_PG: return string("frames_from_start_pg"); \ + case SAMPLES_JCTB: return string("samples_jctb"); \ + case SUBFRAME_ACQUISITION_TIME: return string("subframe_acquisition_time"); \ + default: return string("unknown"); \ + }}; + }; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 230666be6..ef7bb80c6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -37,6 +37,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus; i++; + descrToFuncMap[i].m_pFuncName="busy"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus; + i++; + descrToFuncMap[i].m_pFuncName="datastream"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDataStream; i++; @@ -386,6 +390,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; i++; + descrToFuncMap[i].m_pFuncName="zmqport"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; + i++; + + descrToFuncMap[i].m_pFuncName="configuremac"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfigureMac; i++; @@ -564,6 +573,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; i++; + descrToFuncMap[i].m_pFuncName="thresholdnotb"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; + descrToFuncMap[i].m_pFuncName="trimbits"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; i++; @@ -1320,7 +1333,7 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); if (myDet->setReceiverOnline(ONLINE_FLAG) == ONLINE_FLAG) { - //if it was not off + // command line: must be off, if receiver on or there was -1, then if (myDet->enableDataStreamingFromReceiver(-1) != 0){ //switch it off, if error if (myDet->enableDataStreamingFromReceiver(0) != 0) { @@ -1431,20 +1444,33 @@ string slsDetectorCommand::cmdStatus(int narg, char *args[], int action) { #ifdef VERBOSE cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); #endif - myDet->setOnline(ONLINE_FLAG); - if (action==PUT_ACTION) { - //myDet->setThreadedProcessing(0); - if (string(args[1])=="start") - myDet->startAcquisition(); - else if (string(args[1])=="stop") - myDet->stopAcquisition(); - else - return string("unknown action"); - } else if (action==HELP_ACTION) { - return helpStatus(narg,args,HELP_ACTION); + + if (action==HELP_ACTION) + return helpStatus(narg,args,action); + + if (cmd=="status") { + myDet->setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { + //myDet->setThreadedProcessing(0); + if (string(args[1])=="start") + myDet->startAcquisition(); + else if (string(args[1])=="stop") + myDet->stopAcquisition(); + else + return string("unknown action"); + } + runStatus s=myDet->getRunStatus(); + return myDet->runStatusType(s); } - runStatus s=myDet->getRunStatus(); - return myDet->runStatusType(s); + else if (cmd=="busy") { + if (action==PUT_ACTION) { + return string ("cannot put"); + } + char answer[100]; + sprintf(answer,"%d", myDet->getAcquiringFlag()); + return string(answer); + } + else return string("cannot scan command ")+string(cmd); } @@ -1453,8 +1479,10 @@ string slsDetectorCommand::cmdStatus(int narg, char *args[], int action) { string slsDetectorCommand::helpStatus(int narg, char *args[], int action) { ostringstream os; - if (action==GET_ACTION || action==HELP_ACTION) + if (action==GET_ACTION || action==HELP_ACTION) { os << string("status \t gets the detector status - can be: running, error, transmitting, finished, waiting or idle\n"); + os << string("busy \t gets the status of acquire- can be: 0 or 1. 0 for idle, 1 for running\n"); + } if (action==PUT_ACTION || action==HELP_ACTION) os << string("status \t controls the detector acquisition - can be start or stop \n"); return os.str(); @@ -2932,6 +2960,12 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio if (!(sscanf(args[1],"%d",&i))) return ("cannot parse argument") + string(args[1]); } + }else if (cmd=="zmqport") { + t=RECEIVER_STREAMING_PORT; + if (action==PUT_ACTION){ + if (!(sscanf(args[1],"%d",&i))) + return ("cannot parse argument") + string(args[1]); + } }else return ("unknown network parameter")+cmd; if (action==PUT_ACTION) @@ -2957,6 +2991,7 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti os << "txndelay_right port \n sets detector transmission delay of the right port"<< std::endl; os << "txndelay_frame port \n sets detector transmission delay of the entire frame"<< std::endl; os << "flowcontrol_10g port \n sets flow control for 10g for eiger"<< std::endl; + os << "zmqport port \n sets zmq port (data from receiver to client); setting via multidetector command calculates port for individual detectors"<< std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "detectormac \n gets detector mac "<< std::endl; @@ -2969,6 +3004,7 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti os << "txndelay_right \n gets detector transmission delay of the right port"<< std::endl; os << "txndelay_frame \n gets detector transmission delay of the entire frame"<< std::endl; os << "flowcontrol_10g \n gets flow control for 10g for eiger"<< std::endl; + os << "zmqport \n gets zmq port (data from receiver to client)"<< std::endl; } return os.str(); @@ -3326,9 +3362,9 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { return string("unknown detector size ")+cmd; if (cmd=="roimask") - sprintf(ans,"%x",ret); + sprintf(ans,"0x%x",ret); else - sprintf(ans,"%d",ret); + sprintf(ans,"0x%d",ret); return string(ans); @@ -3390,10 +3426,10 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) { return myDet->getDetectorSettings(myDet->getSettings()); } else if (cmd=="threshold") { if (action==PUT_ACTION) { - detectorType type = myDet->getDetectorsType(); if (!sscanf(args[1],"%d",&val)) { return string("invalid threshold value"); } + detectorType type = myDet->getDetectorsType(); if (type != EIGER || (type == EIGER && narg<=2)) { myDet->setThresholdEnergy(val); } else { @@ -3405,6 +3441,25 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) { } sprintf(ans,"%d",myDet->getThresholdEnergy()); return string(ans); + } else if (cmd=="thresholdnotb") { + if (action==PUT_ACTION) { + if (!sscanf(args[1],"%d",&val)) { + return string("invalid threshold value"); + } + detectorType type = myDet->getDetectorsType(); + if (type != EIGER) + return string("not implemented for this detector"); + if (narg<=2) { + myDet->setThresholdEnergy(val, -1, GET_SETTINGS, 0); + } else { + detectorSettings sett= myDet->getDetectorSettings(string(args[2])); + if(sett == -1) + return string("invalid settings value"); + myDet->setThresholdEnergy(val, -1, sett, 0); + } + } + sprintf(ans,"%d",myDet->getThresholdEnergy()); + return string(ans); } else if (cmd=="trimbits") { if (narg>=2) { string sval=string(args[1]); @@ -3487,7 +3542,8 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) { if (action==PUT_ACTION || action==HELP_ACTION) { os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain" "lownoise, dynamichg0,fixgain1,fixgain2,forceswitchg1, forceswitchg2"<< std::endl; - os << "threshold eV\n sets the detector threshold in eV"<< std::endl; + os << "threshold eV [sett]\n sets the detector threshold in eV. If sett is provided for eiger, uses settings sett"<< std::endl; + 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 << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl; os << "trimval i \n sets all the trimbits to i" << std::endl; @@ -3497,6 +3553,7 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) { if (action==GET_ACTION || action==HELP_ACTION) { os << "settings \n gets the settings of the detector"<< std::endl; os << "threshold V\n gets the detector threshold"<< std::endl; + os << "thresholdnotb V\n gets the detector threshold"<< std::endl; os << "trimbits [fname]\n returns the trimfile loaded on the detector. If fname is specified the trimbits are saved to file. If no extension is specified, the serial number of each module will be attached."<< std::endl; os << "trimval \n returns the value all trimbits are set to. If they are different, returns -1." << std::endl; } @@ -3532,7 +3589,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } @@ -3546,7 +3603,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } else return string("undefined module number"); @@ -3556,7 +3613,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } if (cmd.find("modulenumber")!=string::npos) { @@ -3566,7 +3623,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } else return string("undefined module number"); @@ -3577,7 +3634,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } @@ -3586,7 +3643,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } @@ -3596,7 +3653,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { if (retval < 0) sprintf(answer, "%d", -1); else - sprintf(answer,"%lx", retval); + sprintf(answer,"0x%lx", retval); return string(answer); } return string("unknown id mode ")+cmd; @@ -3635,7 +3692,7 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action) { if (cmd=="bustest"){ if (action==PUT_ACTION) return string("cannot set ")+cmd; - sprintf(answer,"%x",myDet->digitalTest(DETECTOR_BUS_TEST)); + sprintf(answer,"0x%x",myDet->digitalTest(DETECTOR_BUS_TEST)); return string(answer); } @@ -3644,7 +3701,7 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action) { return string("cannot set ")+cmd; int ival=-1; if (sscanf(args[0],"digitest:%d",&ival)) { - sprintf(answer,"%x",myDet->digitalTest(CHIP_TEST, ival)); + sprintf(answer,"0x%x",myDet->digitalTest(CHIP_TEST, ival)); return string(answer); } else return string("undefined module number"); @@ -3656,7 +3713,7 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action) { int ival=-1; if (sscanf(args[1],"%d",&ival)) { if((ival==0)||(ival==1)){ - sprintf(answer,"%x",myDet->digitalTest(DIGITAL_BIT_TEST,ival)); + sprintf(answer,"0x%x",myDet->digitalTest(DIGITAL_BIT_TEST,ival)); return string(answer); } else @@ -3729,13 +3786,13 @@ string slsDetectorCommand::cmdRegister(int narg, char *args[], int action) { ; else return string("Could not scan value (hexadecimal fomat) ")+string(args[2]); - sprintf(answer,"%x",myDet->writeRegister(addr,val)); + sprintf(answer,"0x%x",myDet->writeRegister(addr,val)); } else if (cmd=="adcreg") { if (sscanf(args[2],"%x",&val)) ; else return string("Could not scan value (hexadecimal fomat) ")+string(args[2]); - sprintf(answer,"%x",myDet->writeAdcRegister(addr,val)); + sprintf(answer,"0x%x",myDet->writeAdcRegister(addr,val)); } else { if (sscanf(args[2],"%d",&n)) @@ -3747,9 +3804,9 @@ string slsDetectorCommand::cmdRegister(int narg, char *args[], int action) { return string("Bit number out of range")+string(args[2]); if (cmd=="setbit") - sprintf(answer,"%x",myDet->writeRegister(addr,myDet->readRegister(addr)| 1<writeRegister(addr,myDet->readRegister(addr)| 1<writeRegister(addr,myDet->readRegister(addr) & ~(1<writeRegister(addr,myDet->readRegister(addr) & ~(1<readRegister(addr)); + sprintf(answer,"0x%x",myDet->readRegister(addr)); } @@ -3807,7 +3864,7 @@ string slsDetectorCommand::helpRegister(int narg, char *args[], int action) { ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) { - os << "reg addr val \n writes the register addr with the value val"<< std::endl; + os << "reg addr val \n writes the register addr with the value val (hexadecimal format)"<< std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "reg addr \n reads the register addr"<< std::endl; @@ -4179,7 +4236,7 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); #ifdef DACS_INT - if (myDet->getDetectorsType() == EIGER) + if (myDet->getDetectorsType() == EIGER || myDet->getDetectorsType() == JUNGFRAU) sprintf(answer,"%.2f",(double)myDet->getADC(adc)/1000.00); else sprintf(answer,"%d",myDet->getADC(adc)); #else @@ -4305,7 +4362,7 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { myDet->setReceiverOnline(ONLINE_FLAG); ret=myDet->setTimer(index,t); - if (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER) + if ((ret!=-1) && (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER)) rval=(double)ret*1E-9; else rval=ret; @@ -4318,8 +4375,10 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { myDet->setFrameIndex(-1); } - - sprintf(answer,"%0.9f",rval); + if (index==FRAME_NUMBER || index==GATES_NUMBER || index==PROBES_NUMBER || index==CYCLES_NUMBER || index==MEASUREMENTS_NUMBER) + sprintf(answer,"%d",(int)rval); + else + sprintf(answer,"%0.9f",rval); return string(answer); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index c47b43980..c259f10af 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -42,11 +42,7 @@ slsDetectorUtils::slsDetectorUtils() { int slsDetectorUtils::acquire(int delflag){ - struct timespec begin,end; - clock_gettime(CLOCK_REALTIME, &begin); - - - //ensure acquire isnt started multiple times by same client + //ensure acquire isnt started multiple times by same client if(getAcquiringFlag() == false) setAcquiringFlag(true); else{ @@ -54,6 +50,9 @@ int slsDetectorUtils::acquire(int delflag){ return FAIL; } + struct timespec begin,end; + clock_gettime(CLOCK_REALTIME, &begin); + //not in the loop for real time acqusition yet, //in the real time acquisition loop, processing thread will wait for a post each time sem_init(&sem_newRTAcquisition,1,0); @@ -509,8 +508,9 @@ int slsDetectorUtils::acquire(int delflag){ sem_destroy(&sem_newRTAcquisition); clock_gettime(CLOCK_REALTIME, &end); +#ifdef VERBOSE cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl; - +#endif return OK; } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 82b78032d..655c77d78 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -421,7 +421,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { // double* convertAngles(){return convertAngles(currentPosition);}; // virtual double* convertAngles(double pos)=0; - virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0; + virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS, int tb=1)=0; virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0; virtual double getRateCorrectionTau()=0; @@ -555,7 +555,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { \param imod module number \returns current ADC value */ - virtual dacs_t getADC(dacIndex index, int imod=0)=0; + virtual dacs_t getADC(dacIndex index, int imod=-1)=0; /** get the maximum size of the detector diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp index 57eee451b..9afe150f1 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp @@ -138,7 +138,7 @@ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset) -slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2){ +slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2, int tb){ // only implemented for eiger currently (in terms of which dacs) if(myDetectorType != EIGER) { printf("Interpolation of Trim values not implemented for this detector!\n"); @@ -168,8 +168,10 @@ slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detector } //Interpolate all trimbits - for (int i = 0; inchan; i++) - myMod->chanregs[i] = linearInterpolation(energy, e1, e2, a->chanregs[i], b->chanregs[i]); + if(tb) { + for (int i = 0; inchan; i++) + myMod->chanregs[i] = linearInterpolation(energy, e1, e2, a->chanregs[i], b->chanregs[i]); + } return myMod; } @@ -180,7 +182,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detector /* I/O */ -slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod){ +slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod, int tb){ @@ -372,19 +374,21 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac)); infile.read((char*)&iodelay,sizeof(iodelay)); infile.read((char*)&tau,sizeof(tau)); - infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan)); #ifdef VERBOSE for(int i=0;indac;i++) std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl; std::cout << "iodelay:" << iodelay << std::endl; std::cout << "tau:" << tau << std::endl; #endif - if(infile.eof()){ - cout<chanregs,sizeof(int)*(myMod->nchan)); + if(infile.eof()){ + cout< 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(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod=NULL); + sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod=NULL, int tb=1); /** writes a trim/settings file diff --git a/slsDetectorSoftware/slsDetectorClient/Makefile b/slsDetectorSoftware/slsDetectorClient/Makefile index 63a49637a..44ccbf7e4 100644 --- a/slsDetectorSoftware/slsDetectorClient/Makefile +++ b/slsDetectorSoftware/slsDetectorClient/Makefile @@ -1,96 +1,98 @@ +include ../../Makefile.include + CFLAGS= -DC_ONLY #FLAGS=-DVERBOSE #ASM=$(shell echo "/lib/modules/`uname -r`/build/include") -#INCLUDES= -I../slsDetectorSoftware/commonFiles -I../slsDetectorSoftware/slsDetector -I ../slsDetectorSoftware/MySocketTCP -I../slsDetectorSoftware/usersFunctions -I../slsDetectorSoftware/multiSlsDetector -I../slsDetectorSoftware/slsDetectorAnalysis -I../slsDetectorSoftware/slsReceiverInterface -I$(ASM) -#LDFLAG= - - - -INCLUDES?= -I../commonFiles -I../slsDetector -I ../MySocketTCP -I../usersFunctions -I../multiSlsDetector -I../slsDetectorAnalysis -I../slsReceiverInterface -I$(shell echo "/lib/modules/`uname -r`/build/include") - - -LIBDIR?=../ -LIBS?= -L$(LIBDIR) -lSlsDetector - -LDFLAG= -L/usr/lib64/ -pthread - - -DESTDIR ?= bin -DOCDIR ?= $(PWD)/docs - +INCLUDES?= -I../commonFiles -I../slsDetector -I ../MySocketTCP -I../usersFunctions -I../multiSlsDetector -I../slsDetectorAnalysis -I../slsReceiverInterface -I ../../slsReceiverSoftware/include -I$(shell echo "/lib/modules/`uname -r`/build/include") +DESTDIR ?= ../../bin BIN=$(DESTDIR) - +LIBS?= -L$(DESTDIR) -lSlsDetector +LIBRARYDIR?=../ +LDFLAG= -L/usr/lib64/ -pthread +DOCDIR ?= $(PWD)/docs SRC_CLNT=sls_detector_client.cpp -clients: $(DESTDIR)/sls_detector_put $(DESTDIR)/sls_detector_get $(DESTDIR)/sls_detector_acquire $(DESTDIR)/sls_detector_help - echo $(LIBS) -static_clients: $(DESTDIR)/ssls_detector_put $(DESTDIR)/ssls_detector_get $(DESTDIR)/ssls_detector_acquire $(DESTDIR)/ssls_detector_help +$(info ) +$(info #######################################) +$(info # In slsDetectorclient Makefile #) +$(info #######################################) +$(info ) all: clients - echo $(LIBS) nonstatic: clients +clients: builddir lib $(DESTDIR)/sls_detector_put $(DESTDIR)/sls_detector_get $(DESTDIR)/sls_detector_acquire $(DESTDIR)/sls_detector_help +static_clients: builddir lib $(DESTDIR)/ssls_detector_put $(DESTDIR)/ssls_detector_get $(DESTDIR)/ssls_detector_acquire $(DESTDIR)/ssls_detector_help -lib: - cd ../ && $(MAKE) DESTDIR=$(LIBDIR) - - - -$(DESTDIR)/ssls_detector_put: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) +builddir: +# echo $(LIBS) +# echo $(LDFLAG) mkdir -p $(BIN) + +lib: +# echo $(LIBDIR) + cd $(LIBRARYDIR) && $(MAKE) DESTDIR=$(DESTDIR) TABSPACE='$(TABSPACE)' + @echo "" + @echo "#######################################" + @echo "# Back in slsDetectorClient Makefile #" + @echo "#######################################" + @echo "" + +$(DESTDIR)/ssls_detector_put: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling ssls_detector_put #") + $(call colorecho,"#######################################") $(CXX) -static -o $(BIN)/ssls_detector_put $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DPUT $(LIBS) $(LDFLAG) -$(DESTDIR)/ssls_detector_get: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/ssls_detector_get: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling ssls_detector_get #") + $(call colorecho,"#######################################") $(CXX) -static -o $(BIN)/ssls_detector_get $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DGET $(LIBS) $(LDFLAG) -$(DESTDIR)/ssls_detector_acquire: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/ssls_detector_acquire: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling ssls_detector_acquire #") + $(call colorecho,"#######################################") $(CXX) -static -o $(BIN)/ssls_detector_acquire $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DREADOUT $(LIBS) $(LDFLAG) -$(DESTDIR)/ssls_detector_help: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/ssls_detector_help: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling ssls_detector_help #") + $(call colorecho,"#######################################") $(CXX) -static -o $(BIN)/ssls_detector_help $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DHELP $(LIBS) $(LDFLAG) -$(DESTDIR)/sls_detector_put: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/sls_detector_put: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling sls_detector_put #") + $(call colorecho,"#######################################") $(CXX) -o $(BIN)/sls_detector_put $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DPUT $(LIBS) $(LDFLAG) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) -$(DESTDIR)/sls_detector_get: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/sls_detector_get: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling sls_detector_get #") + $(call colorecho,"#######################################") $(CXX) -o $(BIN)/sls_detector_get $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DGET $(LIBS) $(LDFLAG) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) -$(DESTDIR)/sls_detector_acquire: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/sls_detector_acquire: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling sls_detector_acquire #") + $(call colorecho,"#######################################") $(CXX) -o $(BIN)/sls_detector_acquire $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DREADOUT $(LIBS) $(LDFLAG) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) -$(DESTDIR)/sls_detector_help: $(SRC_CLNT) lib - echo $(LIBS) - echo $(LDFLAG) - mkdir -p $(BIN) +$(DESTDIR)/sls_detector_help: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + $(call colorecho,"#######################################") + $(call colorecho,"# Compiling sls_detector_help #") + $(call colorecho,"#######################################") $(CXX) -o $(BIN)/sls_detector_help $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DHELP $(LIBS) $(LDFLAG) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) @@ -107,6 +109,3 @@ clean: install: clients - - - diff --git a/slsDetectorSoftware/slsDetectorServer/commonServerFunctions.h b/slsDetectorSoftware/slsDetectorServer/commonServerFunctions.h index c9f49bbdf..e201bef17 100755 --- a/slsDetectorSoftware/slsDetectorServer/commonServerFunctions.h +++ b/slsDetectorSoftware/slsDetectorServer/commonServerFunctions.h @@ -1,7 +1,9 @@ #ifndef COMMON_SERVER_FUNCTIONS_H #define COMMON_SERVER_FUNCTIONS_H +#ifndef GOTTHARDD //gotthard already had bus_w etc defined in its firmware_funcs.c (not yet made with common files) #include "blackfin.h" +#endif /* global variables */ void serializeToSPI(u_int32_t addr, u_int32_t val, u_int16_t csmask, int numbitstosend, u_int16_t clkmask, u_int16_t digoutmask, int digofset) { diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 14a08a07d..145af32fa 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -59,6 +59,9 @@ void setupDetector(); #ifndef EIGERD extern u_int32_t writeRegister(u_int32_t offset, u_int32_t data); // blackfin.h extern u_int32_t readRegister(u_int32_t offset); // blackfin.h +#else +uint32_t writeRegister(uint32_t offset, uint32_t data); +uint32_t readRegister(uint32_t offset); #endif diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index 2b1894494..7e7ef4e65 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -11,7 +11,6 @@ // Global variables - extern int lockStatus; extern char lastClientIP[INET_ADDRSTRLEN]; extern char thisClientIP[INET_ADDRSTRLEN]; @@ -1060,7 +1059,7 @@ int set_dac(int file_des) { if((ind == HV_POT) || (ind == HV_NEW)) { retval[0] = setHighVoltage(val); #ifdef EIGERD - if(retval[0] < 0){ + if ((retval[0] != SLAVE_HIGH_VOLTAGE_READ_VAL) && (retval[0] < 0)) { ret = FAIL; if(retval[0] == -1) sprintf(mess, "Setting high voltage failed.Bad value %d. The range is from 0 to 200 V.\n",val); @@ -1243,15 +1242,6 @@ int write_register(int file_des) { int retval=-1; sprintf(mess,"write to register failed\n"); -#ifdef EIGERD - //to receive any arguments - while (n > 0) - n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); - ret = FAIL; - sprintf(mess,"Function (Write Register) is not implemented for this detector\n"); - cprintf(RED, "Warning: %s", mess); -#else - // receive arguments int arg[2]={-1,-1}; n = receiveData(file_des,arg,sizeof(arg),INT32); @@ -1283,7 +1273,6 @@ int write_register(int file_des) { #endif if (ret==OK && differentClients) ret=FORCE_UPDATE; -#endif // ret could be swapped during sendData ret1 = ret; @@ -1311,15 +1300,6 @@ int read_register(int file_des) { int retval=-1; sprintf(mess,"read register failed\n"); -#ifdef EIGERD - //to receive any arguments - while (n > 0) - n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); - ret = FAIL; - sprintf(mess,"Function (Read Register) is not implemented for this detector\n"); - cprintf(RED, "Warning: %s", mess); -#else - // receive arguments int arg=0; n = receiveData(file_des,&arg,sizeof(arg),INT32); @@ -1338,7 +1318,6 @@ int read_register(int file_des) { #endif if (ret==OK && differentClients) ret=FORCE_UPDATE; -#endif // ret could be swapped during sendData ret1 = ret; diff --git a/slsDetectorSoftware/threadFiles/Task.h b/slsDetectorSoftware/threadFiles/Task.h index ac33aa23b..5aff13284 100644 --- a/slsDetectorSoftware/threadFiles/Task.h +++ b/slsDetectorSoftware/threadFiles/Task.h @@ -129,8 +129,8 @@ public: Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0),m13(0),m14(0),m15(0){}; /* Return: void, Param: none */ Task(func00_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t),m13(0),m14(0),m15(0){}; - /* Return: int, Param: int,int,detectorSettings */ - Task(func3_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(t),m14(0),m15(0){}; + /* Return: int, Param: int,int,detectorSettings,int */ + Task(func4_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(t),m14(0),m15(0){}; /* Return: dacs_t, Param: dacs_t, dacIndex, int, int */ Task(func4_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0),m14(t),m15(0){}; /* Return: dacs_t, Param: dacIndex, int */ @@ -185,8 +185,8 @@ private: func2_t * m11; /* Return: void, Param: none */ func00_t * m12; - /* Return: int, Param: int,int,detectorSettings */ - func3_t * m13; + /* Return: int, Param: int,int,detectorSettings,int */ + func4_t * m13; /* Return: dacs_t, Param: dacs_t, dacIndex, int, int */ func4_t * m14; /* Return: dacs_t, Param: dacIndex, int */ diff --git a/slsDetectorSoftware/updateGitVersion.sh b/slsDetectorSoftware/updateGitVersion.sh new file mode 100755 index 000000000..8a0f17dec --- /dev/null +++ b/slsDetectorSoftware/updateGitVersion.sh @@ -0,0 +1,28 @@ +MAINDIR=slsDetectorsPackage +SPECDIR=slsDetectorSoftware +TMPFILE=slsDetector/gitInfoLibTmp.h +INCLFILE=slsDetector/gitInfoLib.h +WD=$PWD + +#evaluate the variables +EVALFILE=../evalVersionVariables.sh +source $EVALFILE + +#get modified date +#RDATE1='git log --pretty=format:"%ci" -1' +RDATE1="find . -not -path '*DetectorServer/*' -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|build|.git|updateGitVersion' | head -n 1" +RDATE=`eval $RDATE1` +NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}') +NEWDATE=${NEWDATE/#/0x} + +#get old date from INCLFILE +OLDDATE=$(more $INCLFILE | grep '#define SVNDATE' | awk '{print $3}') + + +#update INCLFILE if changes +if [ "$OLDDATE" != "$NEWDATE" ]; then + echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt + cd .. + ./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE + cd $WD +fi \ No newline at end of file