diff --git a/slsDetectorSoftware/.gitignore b/slsDetectorSoftware/.gitignore new file mode 100644 index 000000000..825dda897 --- /dev/null +++ b/slsDetectorSoftware/.gitignore @@ -0,0 +1,4 @@ +*.o +*~ +#*# +.project diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt new file mode 100644 index 000000000..69f395cc9 --- /dev/null +++ b/slsDetectorSoftware/CMakeLists.txt @@ -0,0 +1,76 @@ +set(SOURCES + multiSlsDetector/multiSlsDetector.cpp + slsDetector/slsDetectorUsers.cpp + slsDetector/slsDetectorUtils.cpp + slsDetector/slsDetectorCommand.cpp + slsDetector/slsDetectorActions.cpp + slsDetector/slsDetector.cpp + slsDetectorAnalysis/angularConversion.cpp + slsDetectorAnalysis/angularConversionStatic.cpp + slsDetectorAnalysis/energyConversion.cpp + slsDetectorAnalysis/fileIO.cpp + slsDetectorAnalysis/postProcessing.cpp + slsDetectorAnalysis/postProcessingFuncs.cpp + slsReceiverInterface/receiverInterface.cpp + threadFiles/CondVar.cpp + threadFiles/Mutex.cpp + threadFiles/ThreadPool.cpp + usersFunctions/usersFunctions.cpp +) + +set(HEADERS +) + +include_directories( +commonFiles +multiSlsDetector +slsDetector +slsDetectorUtils +slsDetectorCommand +slsDetectorAnalysis +slsReceiverInterface +threadFiles +usersFunctions +../slsReceiverSoftware/include +../slsReceiverSoftware/MySocketTCP +) + +add_definitions( + -DDACS_INT +) + +add_library(zmq STATIC IMPORTED ) + +set_target_properties(zmq PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../slsReceiverSoftware/include/libzmq.a +) + +add_library(slsDetectorStatic STATIC + ${SOURCES} + ${HEADERS} +) +set_target_properties(slsDetectorStatic PROPERTIES + ARCHIVE_OUTPUT_NAME SlsDetector + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) + +add_library(slsDetectorShared SHARED + ${SOURCES} + ${HEADERS} +) +set_target_properties(slsDetectorShared PROPERTIES + LIBRARY_OUTPUT_NAME SlsDetector + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) + +add_subdirectory(slsDetectorClient) + +if(DOXYGEN_FOUND) + add_custom_target(doc + ${DOXYGEN_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/slsDetectorUsers.doxy + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Generating API documentation with Doxygen" VERBATIM + ) +endif() + diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile new file mode 100644 index 000000000..850edef3f --- /dev/null +++ b/slsDetectorSoftware/Makefile @@ -0,0 +1,82 @@ +include ../Makefile.include + +DESTDIR ?= ../bin +LIBDIR ?= $(DESTDIR) + + +CFLAGS= -g -DC_ONLY -fPIC +#FLAGS+= #-DVERBOSE -DVERYVERBOSE + +DFLAGS= -g -DDACS_INT + +INCLUDES?= -IcommonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis -IslsReceiverInterface -I../slsReceiverSoftware/include -IthreadFiles -I$(ASM) + +#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 + +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 # In slsDetectorSoftware Makefile #) +$(info #######################################) +$(info ) + + + + +OBJS = $(SRC_CLNT:%.cpp=%.o) + +.PHONY: all package clean + +all: package $(SRC_CLNT) + +mythenVirtualServer: $(SRC_MYTHEN_SVC) + cd mythenDetectorServer && make -f Makefile.virtual DESTDIR=$(DESTDIR) + +gotthardVirtualServer: $(SRC_MYTHEN_SVC) + cd gotthardDetectorServer && make -f Makefile.virtual DESTDIR=$(DESTDIR) + + +%.o : %.cpp %.h $(DEPSINCLUDES) Makefile + $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -pthread -lrt $(LIBZMQ) $(FLAGS) + + +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) + +$(DESTDIR)/libSlsDetector.a: $(OBJS) + ar rcs libSlsDetector.a $(OBJS) + mv libSlsDetector.a $(DESTDIR) + +clean: + rm -rf $(DESTDIR)/libSlsDetector.a $(DESTDIR)/libSlsDetector.so core $(OBJS) + cd + + + + +#------------------------------------------------------------------------------- + +install: package + +install_inc: + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + cp -P slsDetector/slsDetectorUsers.h slsDetectorAnalysis/detectorData.h $(DESTDIR) + + diff --git a/slsDetectorSoftware/Makefile.Standalone b/slsDetectorSoftware/Makefile.Standalone new file mode 100644 index 000000000..d9a7c0868 --- /dev/null +++ b/slsDetectorSoftware/Makefile.Standalone @@ -0,0 +1,68 @@ +CFLAGS= -DC_ONLY +#FLAGS= -DVERBOSE -DVERYVERBOSE +INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis + +#EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom +CC=gcc +CXX=g++ + +SRC_CLNT= slsDetectorAnalysis/FileIO_Standalone.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/AngularConversion_Standalone.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessingFileIO_Standalone.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp + +OBJS = $(SRC_CLNT:.cpp=.o) + +HEADERS = $(SRC_CLNT:.cpp=.h) commonFiles/sls_detector_defs.h slsDetectorAnalysis/detectorData.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorUsers.h multiSlsDetector/multiSlsDetectorCommand.h + + + +SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c mythenDetectorServer/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c + +all: package $(SRC_CLNT) + echo "compiling all" + +doc: $(SRC_H) $(SRC_CLNT) + doxygen doxy.config + + + +mythenServer: $(SRC_MYTHEN_SVC) + $(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -DVIRTUAL -lm -D MCB_FUNCS -DC_ONLY -DVERBOSE + mv a.out mythenServer + + +picassoServer: $(SRC_MYTHEN_SVC) + $(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -DMCB_FUNCS -DPICASSOD -DC_ONLY + mv a.out picassoServer + + + + + +%.o : %.cpp %.h + $(CXX) -Wall -o $@ -c $< $(INCLUDES) $(FLAGS) $(EPICSFLAGS) + + +package: $(OBJS) + $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS) + ar rcs libSlsDetector.a $(OBJS) + +clean: + rm -rf libSlsDetector.a libSlsDetector.so core docs/* $(OBJS) + + +#------------------------------------------------------------------------------- +lib: package + + +# added install target, HBl +install_lib: lib + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + cp -P libSlsDetector.so $(DESTDIR) + +install_inc: + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + cp -P $(HEADERS) $(DESTDIR) + + +install_doc: doc + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + cp -Pr docs/* $(DESTDIR) diff --git a/slsDetectorSoftware/Makefile.x04sa b/slsDetectorSoftware/Makefile.x04sa new file mode 100644 index 000000000..59755550f --- /dev/null +++ b/slsDetectorSoftware/Makefile.x04sa @@ -0,0 +1,87 @@ +CFLAGS= -DC_ONLY -fPIC +#FLAGS+= #-DVERBOSE -DVERYVERBOSE + +DFLAGS= -DDACS_INT -DTHIS_PATH='"$(shell pwd)"' -DSLS_RECEIVER_FUNCTION_LIST + +#ASM=$(shell echo "/lib/modules/`uname -r`/build/include") + +INCLUDES?= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis -IslsReceiverInterface -IslsReceiver -I$(ASM) + +EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom +CC=g++ + + +SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.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 slsDetector/slsDetectorUsers.cpp slsDetectorAnalysis/postProcessingFuncs.cpp slsReceiverInterface/receiverInterface.cpp slsReceiver/slsReceiverFunctionList.cpp slsReceiver/slsReceiver_funcs.cpp slsReceiver/slsReceiverUsers.cpp + +OBJS = $(SRC_CLNT:.cpp=.o) + +HEADERS = $(SRC_CLNT:.cpp=.h) commonFiles/sls_detector_defs.h slsDetectorAnalysis/detectorData.h slsDetector/slsDetectorBase.h multiSlsDetector/multiSlsDetectorCommand.h slsDetectorAnalysis/enCalLogClass.h slsDetectorAnalysis/angCalLogClass.h slsDetectorAnalysis/angleConversionConstant.h usersFunctions/angleFunction.h slsReceiverInterface/receiverInterface.h slsDetector/svnInfoLib.h slsReceiver/circularFifo.h slsReceiver/slsReceiver_funcs.h slsReceiver/svnInfoReceiverTmp.h slsReceiver/receiver_defs.h slsReceiver/slsReceiverFunctionList.h slsReceiver/slsReceiverUsers.h slsReceiver/svnInfoReceiver.h + + + +DESTDIR ?= bin +DOCDIR ?= docs + + +all: package $(SRC_CLNT) + echo "compiling all" + +intdoc: $(SRC_H) $(SRC_CLNT) + doxygen doxy.config + +doc: $(DOCDIR)/pdf/slsDetectorUsersDocs.pdf + +$(DOCDIR)/pdf/slsDetectorUsersDocs.pdf: slsDetectorUsersDocs + cd slsDetectorUsersDocs/latex && make + $(shell test -d $(DOCDIR) || mkdir -p $(DOCDIR)) + $(shell test -d $(DOCDIR)/pdf || mkdir -p $(DOCDIR)/pdf) + cp slsDetectorUsersDocs/latex/refman.pdf $(DOCDIR)/pdf/slsDetectorUsersDocs.pdf + + +htmldoc: $(DOCDIR)/html/slsDetectorUsersDocs + +$(DOCDIR)/html/slsDetectorUsersDocs: slsDetectorUsersDocs + $(shell test -d $(DOCDIR) || mkdir -p $(DOCDIR)) + $(shell test -d $(DOCDIR)/html || mkdir -p $(DOCDIR)/html) + $(shell test -d $(DOCDIR)/html/slsDetectorUsersDocs && rm -r $(DOCDIR)/html/slsDetectorUsersDocs) + cp -r slsDetectorUsersDocs/html $(DOCDIR)/html/slsDetectorUsersDocs + +slsDetectorUsersDocs: slsDetectorUsers.doxy slsDetector/slsDetectorUsers.h slsDetector/slsDetectorUsers.cpp slsDetectorAnalysis/detectorData.h + doxygen slsDetectorUsers.doxy + + +mythenVirtualServer: $(SRC_MYTHEN_SVC) + cd mythenDetectorServer && make -f Makefile.virtual DESTDIR=$(DESTDIR) + +gotthardVirtualServer: $(SRC_MYTHEN_SVC) + cd gotthardDetectorServer && make -f Makefile.virtual DESTDIR=$(DESTDIR) + + + +%.o : %.cpp %.h Makefile + $(CXX) -Wall -o $@ -c $< $(INCLUDES) $(DFLAGS) $(FLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ + +package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a + +$(DESTDIR)/libSlsDetector.so: $(OBJS) + $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64/ + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + mv libSlsDetector.so $(DESTDIR) + +$(DESTDIR)/libSlsDetector.a: $(OBJS) + ar rcs libSlsDetector.a $(OBJS) + mv libSlsDetector.a $(DESTDIR) + +clean: + rm -rf libSlsDetector.a libSlsDetector.so core docs/* slsDetectorUsersDocs $(OBJS) + + +#------------------------------------------------------------------------------- + +install: package + +install_inc: + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + cp -P slsDetector/slsDetectorUsers.h slsDetectorAnalysis/detectorData.h $(DESTDIR) slsReceiver/slsReceiverUsers.h + + diff --git a/slsDetectorSoftware/README b/slsDetectorSoftware/README new file mode 100644 index 000000000..b1cfea7a7 --- /dev/null +++ b/slsDetectorSoftware/README @@ -0,0 +1,19 @@ +This subversion repository contains + +Common directories +Please inform Anna or Dhanya if you make modifications to these directories +- MySocketTCP : socket class +- commonFiles : header file common to server and client +- slsDetector : base class with all main detector functionalities (client side) + + +Mythen specific directories +Please inform Anna if you make modifications to these directories +- mythenDetector : mythen specific funcs (mainly files I/O and angular conversion) +- mythenDetectorServer : mythen server (for etrax compiler) +- firmware lib might be added in the future + +Other Detector specific directories +Please inform Dhanya if you make modifications to these directories + +make doc diff --git a/slsDetectorSoftware/commonFiles/communication_funcs.c b/slsDetectorSoftware/commonFiles/communication_funcs.c new file mode 100755 index 000000000..caa58a8c4 --- /dev/null +++ b/slsDetectorSoftware/commonFiles/communication_funcs.c @@ -0,0 +1,690 @@ + + +#include "communication_funcs.h" +//#include +#include /* for TCP_NODELAY */ +#include +#include +#include +#include + +#include +char lastClientIP[INET_ADDRSTRLEN]; +char thisClientIP[INET_ADDRSTRLEN]; +int lockStatus; +int differentClients; + +//int socketDescriptor, file_des; +const int send_rec_max_size=SEND_REC_MAX_SIZE; +extern int errno; + + +char dummyClientIP[INET_ADDRSTRLEN]; + + +fd_set readset, tempset; +int isock=0, maxfd; + + +int myport=-1; + +//struct sockaddr_in address; +//#define VERBOSE + + +int bindSocket(unsigned short int port_number) { + int i; + + struct sockaddr_in addressS; + int socketDescriptor; + //int file_des; + + //file_des= -1; + + + + + + + + + + + if (myport==port_number) + return -10; + + + + + + socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp + + //socketDescriptor = socket(PF_INET, SOCK_STREAM, 0); + + + + if (socketDescriptor < 0) { + printf("Can not create socket\n"); + } else { + + i = 1; + setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)); + // setsockopt(socketDescriptor, IPPROTO_TCP, TCP_NODELAY, (char *) &i, sizeof(i)); + // TCP_CORK + + // Set some fields in the serverAddress structure. + addressS.sin_family = AF_INET; + addressS.sin_addr.s_addr = htonl(INADDR_ANY); + addressS.sin_port = htons(port_number); + + // memset(&address.sin_addr, 0, sizeof(address.sin_addr)); + + + if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){ + + printf("Can not create socket\n"); + + socketDescriptor=-1; + } else { + if (listen(socketDescriptor, 5)==0) { + + if (isock==0) { + FD_ZERO(&readset); + } + + + FD_SET(socketDescriptor, &readset); + isock++; + maxfd = socketDescriptor; + printf ("%d port %d fd %d\n",isock, port_number,socketDescriptor); + myport=port_number; + } else + printf("error on listen"); + } + } + + + + //int getrlimit(int resource, struct rlimit *rlim); + + + + return socketDescriptor; + +} + + + + + +int getServerError(int socketDescriptor) +{ + if (socketDescriptor<0) return 1; + else return 0; +}; + + +int acceptConnection(int socketDescriptor) { + + + int j; + + + struct sockaddr_in addressC; + int file_des=-1; + struct timeval tv; + int result; + + + //socklen_t address_length; + socklen_t address_length=sizeof(struct sockaddr_in); + + if (socketDescriptor<0) + return -1; + + memcpy(&tempset, &readset, sizeof(tempset)); + tv.tv_sec = 10000000; + tv.tv_usec = 0; + result = select(maxfd + 1, &tempset, NULL, NULL, &tv); + + if (result == 0) { + printf("select() timed out!\n"); + } else if (result < 0 && errno != EINTR) { + printf("Error in select(): %s\n", strerror(errno)); + } else if (result > 0) { +#ifdef VERBOSE + printf("select returned!\n"); +#endif + for (j=0; j=0) + close(file_des); + FD_CLR(file_des, &readset); +} + +void exitServer(int socketDescriptor) { + if (socketDescriptor>=0) + close(socketDescriptor); +#ifdef VERY_VERBOSE + printf("Closing server\n"); +#endif + FD_CLR(socketDescriptor, &readset); + socketDescriptor=-1; + isock--; +} + + + + +void swapData(void* val,int length,intType itype){ + int i; + int16_t* c= (int16_t*)val; + int32_t* a= (int32_t*)val; + int64_t* b= (int64_t*)val; + for(i=0; length > 0; i++){ + switch(itype){ + case INT16: + c[i] = ((c[i] & 0x00FF) << 8) | ((c[i] & 0xFF00) >> 8); + length -= sizeof(int16_t); + break; + case INT32: + a[i]=((a[i] << 8) & 0xFF00FF00) | ((a[i] >> 8) & 0xFF00FF ); + a[i]=(a[i] << 16) | ((a[i] >> 16) & 0xFFFF); + length -= sizeof(int32_t); + break; + case INT64: + b[i] = ((b[i] << 8) & 0xFF00FF00FF00FF00ULL ) | ((b[i] >> 8) & 0x00FF00FF00FF00FFULL ); + b[i] = ((b[i] << 16) & 0xFFFF0000FFFF0000ULL ) | ((b[i] >> 16) & 0x0000FFFF0000FFFFULL ); + b[i] = (b[i] << 32) | ((b[i] >> 32) & 0xFFFFFFFFULL); + length -= sizeof(int64_t); + break; + default: + length = 0; + break; + } + } +} + +int sendData(int file_des, void* buf,int length, intType itype){ +#ifndef PCCOMPILE +#ifdef EIGERD + swapData(buf, length, itype); +#endif +#endif + return sendDataOnly(file_des, buf, length); +} + + +int receiveData(int file_des, void* buf,int length, intType itype){ + int ret = receiveDataOnly(file_des, buf, length); +#ifndef PCCOMPILE +#ifdef EIGERD + if (ret >= 0) swapData(buf, length, itype); +#endif +#endif + return ret; +} + + + int sendDataOnly(int file_des, void* buf,int length) { + int ret = write(file_des, buf, length); //value of -1 is other end socket crash as sigpipe is ignored + if (ret < 0) cprintf(BG_RED, "Error writing to socket. Possible socket crash\n"); + return ret; +} + + + int receiveDataOnly(int file_des, void* buf,int length) { + + int total_received=0; + int nreceiving; + int nreceived; + if (file_des<0) return -1; +#ifdef VERY_VERBOSE + printf("want to receive %d Bytes\n", length); +#endif + + while(length > 0) { + nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; + nreceived = read(file_des,(char*)buf+total_received,nreceiving); + if(!nreceived){ + if(!total_received) { + return -1; //to handle it + } + break; + } + length-=nreceived; + total_received+=nreceived; + } + + if (total_received>0) + strcpy(thisClientIP,dummyClientIP); + + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + + return total_received; +} + + + + + + + + + + + + + + + +int sendChannel(int file_des, sls_detector_channel *myChan) { + int ts=0; + //sendDataOnly(file_des,myChan, sizeof(sls_detector_channel)); + ts+=sendData(file_des,&(myChan->chan),sizeof(myChan->chan),INT32); + ts+=sendData(file_des,&(myChan->chip),sizeof(myChan->chip),INT32); + ts+=sendData(file_des,&(myChan->module),sizeof(myChan->module),INT32); + ts+=sendData(file_des,&(myChan->reg),sizeof(myChan->reg),INT64); + return ts; +} + +int sendChip(int file_des, sls_detector_chip *myChip) { + int ts=0; + //ts+=sendDataOnly(file_des,myChip,sizeof(sls_detector_chip)); + ts+=sendData(file_des,&(myChip->chip),sizeof(myChip->chip),INT32); + ts+=sendData(file_des,&(myChip->module),sizeof(myChip->module),INT32); + ts+=sendData(file_des,&(myChip->nchan),sizeof(myChip->nchan),INT32); + ts+=sendData(file_des,&(myChip->reg),sizeof(myChip->reg),INT32); + ts+=sendData(file_des,(myChip->chanregs),sizeof(myChip->chanregs),INT32); + ts+=sendData(file_des,myChip->chanregs,myChip->nchan*sizeof(int),INT32); + return ts; +} + + +int sendModule(int file_des, sls_detector_module *myMod) { + return sendModuleGeneral(file_des, myMod, 1); +} + + +int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) { + int ts=0; +#ifdef VERBOSE + int idac; +#endif + int nChips=myMod->nchip; + int nChans=myMod->nchan; + int nAdcs=myMod->nadc; + int nDacs=myMod->ndac; + //ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module)); + ts+=sendData(file_des,&(myMod->module),sizeof(myMod->module),INT32); + ts+=sendData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32); + ts+=sendData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32); + ts+=sendData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32); + ts+=sendData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32); + ts+=sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32); + ts+=sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32); + ts+=sendData(file_des,myMod->dacs,sizeof(myMod->ndac),OTHER); + if(sendAll){ + ts+=sendData(file_des,myMod->adcs,sizeof(myMod->nadc),OTHER); + }else{ + uint32_t k = 0; + ts+=sendData(file_des,&k,sizeof(k),OTHER); + } + + /*some detectors dont require sending all trimbits etc.*/ + if(sendAll){ + ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER); + ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER); + } + ts+=sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER); + ts+=sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER); + +#ifdef VERBOSE + printf("module %d of size %d sent\n",myMod->module, ts); +#endif + ts+= sendData(file_des,myMod->dacs,sizeof(dacs_t)*nDacs,INT32); +#ifdef VERBOSE + printf("dacs %d of size %d sent\n",myMod->module, ts); + for (idac=0; idac< nDacs; idac++) + printf("dac %d is %d\n",idac,(int)myMod->dacs[idac]); +#endif + if(sendAll) + ts+= sendData(file_des,myMod->adcs,sizeof(dacs_t)*nAdcs,INT32); + else { + uint32_t k = 0; + ts+= sendData(file_des,&k,sizeof(k),INT32); + } + +#ifdef VERBOSE + printf("adcs %d of size %d sent\n",myMod->module, ts); +#endif + + /*some detectors dont require sending all trimbits etc.*/ + if(sendAll){ + ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32); +#ifdef VERBOSE + printf("chips %d of size %d sent\n",myMod->module, ts); +#endif + ts+=sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32); +#ifdef VERBOSE + printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan); +#endif + } + +#ifdef VERBOSE + printf("module %d of size %d sent register %x\n",myMod->module, ts, myMod->reg); +#endif + return ts; +} + +int receiveChannel(int file_des, sls_detector_channel *myChan) { + int ts=0; + //receiveDataOnly(file_des,myChan,sizeof(sls_detector_channel)); + ts+=receiveData(file_des,&(myChan->chan),sizeof(myChan->chan),INT32); + ts+=receiveData(file_des,&(myChan->chip),sizeof(myChan->chip),INT32); + ts+=receiveData(file_des,&(myChan->module),sizeof(myChan->module),INT32); + ts+=receiveData(file_des,&(myChan->reg),sizeof(myChan->reg),INT32); + return ts; +} + +int receiveChip(int file_des, sls_detector_chip* myChip) { + + int *ptr=myChip->chanregs; + int ts=0; + int nChans, nchanold=myChip->nchan, chdiff; + + //ts+= receiveDataOnly(file_des,myChip,sizeof(sls_detector_chip)); + ts+=receiveData(file_des,&(myChip->chip),sizeof(myChip->chip),INT32); + ts+=receiveData(file_des,&(myChip->module),sizeof(myChip->module),INT32); + ts+=receiveData(file_des,&(myChip->nchan),sizeof(myChip->nchan),INT32); + ts+=receiveData(file_des,&(myChip->reg),sizeof(myChip->reg),INT32); + ts+=receiveData(file_des,(myChip->chanregs),sizeof(myChip->chanregs),INT32); + + myChip->chanregs=ptr; + nChans=myChip->nchan; + chdiff=nChans-nchanold; + if (nchanold!=nChans) { + printf("wrong number of channels received!\n"); + } + + +#ifdef VERBOSE + printf("chip structure received\n"); + printf("now receiving %d channels\n", nChans); +#endif + + if (chdiff<=0) + ts+=receiveData(file_des,myChip->chanregs, sizeof(int)*nChans,INT32); + else { + ptr=(int*)malloc(chdiff*sizeof(int)); + myChip->nchan=nchanold; + ts+=receiveData(file_des,myChip->chanregs, sizeof(int)*nchanold,INT32); + ts+=receiveData(file_des,ptr, sizeof(int)*chdiff,INT32); + free(ptr); + return FAIL; + } + +#ifdef VERBOSE + printf("chip's channels received\n"); +#endif + return ts; +} + + +int receiveModule(int file_des, sls_detector_module* myMod) { + return receiveModuleGeneral(file_des,myMod,1); +} + +int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll) { + int ts=0; + dacs_t *dacptr=myMod->dacs; + dacs_t *adcptr=myMod->adcs; + int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs; + int nChips, nchipold=myMod->nchip, nchipdiff; + int nChans, nchanold=myMod->nchan, nchandiff; + int nDacs, ndold=myMod->ndac, ndacdiff; + int nAdcs, naold=myMod->nadc, nadcdiff; +#ifdef VERBOSE + int id=0; +#endif + // ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module)); + ts+=receiveData(file_des,&(myMod->module),sizeof(myMod->module),INT32); + ts+=receiveData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32); + ts+=receiveData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32); + ts+=receiveData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32); + ts+=receiveData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32); + ts+=receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32); + ts+=receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32); + ts+=receiveData(file_des,myMod->dacs,sizeof(myMod->ndac),INT32); + if(receiveAll){ // temporary fix + ts+=receiveData(file_des,myMod->adcs,sizeof(myMod->nadc),INT32); + }else { + uint32_t k;ts+=receiveData(file_des,&k,sizeof(k),INT32);//nadc is 0 + } + + /*some detectors dont require sending all trimbits etc.*/ + if(receiveAll){ + ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32); + ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32); + } + ts+=receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER); + ts+=receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER); + + myMod->dacs=dacptr; + myMod->adcs=adcptr; + 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) { + printf("received wrong number of chips\n"); + } +#ifdef VERBOSE + else + printf("received %d chips\n",nChips); +#endif + + nChans=myMod->nchan; + nchandiff=nChans-nchanold; + if (nchanold!=nChans) { + printf("received wrong number of channels\n"); + } +#ifdef VERBOSE + else + printf("received %d chans\n",nChans); +#endif + + + nDacs=myMod->ndac; + ndacdiff=nDacs-ndold; + if (ndold!=nDacs) { + printf("received wrong number of dacs\n"); + } +#ifdef VERBOSE + else + printf("received %d dacs\n",nDacs); +#endif + + nAdcs=myMod->nadc; + nadcdiff=nAdcs-naold; + if (naold!=nAdcs) { + printf("received wrong number of adcs\n"); + } +#ifdef VERBOSE + else + printf("received %d adcs\n",nAdcs); +#endif + if (ndacdiff<=0) { + ts+=receiveData(file_des,myMod->dacs, sizeof(dacs_t)*nDacs,INT32); +#ifdef VERBOSE + printf("dacs received\n"); + int id; + for (id=0; iddacs[id]); + + +#endif + } else { + dacptr=(dacs_t*)malloc(ndacdiff*sizeof(dacs_t)); + myMod->ndac=ndold; + ts+=receiveData(file_des,myMod->dacs, sizeof(dacs_t)*ndold,INT32); + ts+=receiveData(file_des,dacptr, sizeof(dacs_t)*ndacdiff,INT32); + free(dacptr); + return FAIL; + } + + if (nadcdiff<=0) { + ts+=receiveData(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs,INT32); +#ifdef VERBOSE + printf("adcs received\n"); +#endif + } else { + adcptr=(dacs_t*)malloc(nadcdiff*sizeof(dacs_t)); + myMod->nadc=naold; + ts+=receiveData(file_des,myMod->adcs, sizeof(dacs_t)*naold,INT32); + ts+=receiveData(file_des,adcptr, sizeof(dacs_t)*nadcdiff,INT32); + free(adcptr); + return FAIL; + } + + + /*some detectors dont require sending all trimbits etc.*/ + if(receiveAll){ + + if (nchipdiff<=0) { + ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32); +#ifdef VERBOSE + printf("chips received\n"); +#endif + } else { + chipptr=(int*)malloc(nchipdiff*sizeof(int)); + myMod->nchip=nchipold; + ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32); + ts+=receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32); + free(chipptr); + return FAIL; + } + + if (nchandiff<=0) { + ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32); +#ifdef VERBOSE + printf("chans received\n"); +#endif + } else { + chanptr=(int*)malloc(nchandiff*sizeof(int)); + myMod->nchan=nchanold; + ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32); + ts+=receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32); + free(chanptr); + return FAIL; + } + } +#ifdef VERBOSE + printf("received module %d of size %d register %x\n",myMod->module,ts,myMod->reg); +#endif + + return ts; +} diff --git a/slsDetectorSoftware/commonFiles/communication_funcs.h b/slsDetectorSoftware/commonFiles/communication_funcs.h new file mode 100755 index 000000000..e4e3fac27 --- /dev/null +++ b/slsDetectorSoftware/commonFiles/communication_funcs.h @@ -0,0 +1,51 @@ +#ifndef COMMUNICATION_FUNCS_H +#define COMMUNICATION_FUNCS_H + +#define SEND_REC_MAX_SIZE 4096 +#define DEFAULT_PORTNO 1952 +#include +#include + + +#include +#include +#include +#include + +#include "sls_detector_defs.h" + + + +typedef enum{ + INT16, + INT32, + INT64, + OTHER +}intType; + + + + +int bindSocket(unsigned short int port_number); +int acceptConnection(int socketDescriptor); +void closeConnection(int file_Des); +void exitServer(int socketDescriptor); + +void swapData(void* val,int length,intType itype); +int sendData(int file_des, void* buf,int length, intType itype); +int receiveData(int file_des, void* buf,int length, intType itype); +int sendDataOnly(int file_des, void* buf,int length); +int receiveDataOnly(int file_des, void* buf,int length); + + +int getServerError(int socketDescriptor); +int sendChannel(int file_des, sls_detector_channel *myChan); +int sendChip(int file_des, sls_detector_chip *myChip); +int sendModule(int file_des, sls_detector_module *myMod); +int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll); +int receiveChannel(int file_des, sls_detector_channel *myChan); +int receiveChip(int file_des, sls_detector_chip* myChip); +int receiveModule(int file_des, sls_detector_module* myMod); +int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll); + +#endif diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h new file mode 100644 index 000000000..98d3a8fc3 --- /dev/null +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -0,0 +1,335 @@ +/* + * error_defs.h + * + * Created on: Jan 18, 2013 + * Author: l_maliakal_d + */ + +#ifndef ERROR_DEFS_H_ +#define ERROR_DEFS_H_ + +#include "ansi.h" +#include "sls_detector_defs.h" + +#include +#include +#include +#include +using namespace std; + +/** Error flags */ +/*Assumption: Only upto 63 detectors */ + +// multi errors +// 0xFFF0000000000000ULL +#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL +#define MULTI_HAVE_DIFFERENT_VALUES 0x4000000000000000ULL + +// sls errors +#define CRITICAL_ERROR_MASK 0xFFFFFFF + +// 0xFFFFFFF000000000ULL +#define CANNOT_CONNECT_TO_DETECTOR 0x4000000000000000ULL +#define CANNOT_CONNECT_TO_RECEIVER 0x2000000000000000ULL +#define COULDNOT_SET_CONTROL_PORT 0x1000000000000000ULL +#define COULDNOT_SET_STOP_PORT 0x0800000000000000ULL +#define COULDNOT_SET_DATA_PORT 0x0400000000000000ULL +#define FILE_PATH_DOES_NOT_EXIST 0x0200000000000000ULL +#define COULDNOT_CREATE_UDP_SOCKET 0x0100000000000000ULL +#define COULDNOT_CREATE_FILE 0x0080000000000000ULL +#define COULDNOT_ENABLE_COMPRESSION 0x0040000000000000ULL +#define RECEIVER_DET_HOSTNAME_NOT_SET 0x0020000000000000ULL +#define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0010000000000000ULL +#define DETECTOR_TEN_GIGA 0x0008000000000000ULL +#define DETECTOR_ACTIVATE 0x0004000000000000ULL +#define COULD_NOT_CONFIGURE_MAC 0x0002000000000000ULL +#define COULDNOT_START_RECEIVER 0x0001000000000000ULL // default error like starting threads +#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 +#define REGISER_WRITE_READ 0x0000040000000000ULL +// 0xFFFFFFF000000000ULL + +// 0x0000000FFFFFFFFFULL +#define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000001ULL +#define COULDNOT_SET_ROI 0x0000000000000002ULL +#define RECEIVER_READ_FREQUENCY 0x0000000000000004ULL +#define SETTINGS_NOT_SET 0x0000000000000008ULL +#define SETTINGS_FILE_NOT_OPEN 0x0000000000000010ULL +#define DETECTOR_TIMER_VALUE_NOT_SET 0x0000000000000020ULL +#define RECEIVER_ACQ_PERIOD_NOT_SET 0x0000000000000040ULL +#define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000080ULL +#define RECEIVER_DYNAMIC_RANGE 0x0000000000000100ULL +#define RECEIVER_TEN_GIGA 0x0000000000000200ULL +#define ALLTIMBITS_NOT_SET 0x0000000000000400ULL +#define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000000800ULL +#define COULD_NOT_SET_READOUT_FLAGS 0x0000000000001000ULL +#define COULD_NOT_SET_FIFO_DEPTH 0x0000000000002000ULL +#define COULD_NOT_SET_COUNTER_BIT 0x0000000000004000ULL +#define COULD_NOT_PULSE_PIXEL 0x0000000000008000ULL +#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000010000ULL +#define COULD_NOT_PULSE_CHIP 0x0000000000020000ULL +#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000040000ULL +#define DETECTOR_NETWORK_PARAMETER 0x0000000000080000ULL +#define RATE_CORRECTION_NOT_32or16BIT 0x0000000000100000ULL +#define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000000200000ULL +#define PROGRAMMING_ERROR 0x0000000000400000ULL +#define RECEIVER_ACTIVATE 0x0000000000800000ULL +#define DATA_STREAMING 0x0000000001000000ULL +#define RESET_ERROR 0x0000000002000000ULL +#define POWER_CHIP 0x0000000004000000ULL +#define RECEIVER_READ_TIMER 0x0000000008000000ULL +#define RECEIVER_ACQ_TIME_NOT_SET 0x0000000010000000ULL +#define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL +#define THRESHOLD_NOT_SET 0x0000000040000000ULL +#define RECEIVER_FILE_FORMAT 0x0000000080000000ULL +#define RECEIVER_SILENT_MODE_NOT_SET 0x0000000100000000ULL +#define RECEIVER_TIMER_NOT_SET 0x0000000200000000ULL +#define RECEIVER_ENABLE_GAPPIXELS_NOT_SET 0x0000000400000000ULL +#define RESTREAM_STOP_FROM_RECEIVER 0x0000000800000000ULL +// 0x0000000FFFFFFFFFULL + +/** @short class returning all error messages for error mask */ +class errorDefs { + + +public: + + /** Constructor */ + errorDefs():errorMask(0){ + strcpy(notAddedList,""); + }; + + /** Gets the error message + * param errorMask error mask + /returns error message from error mask + */ + static string getErrorMessage(int64_t slsErrorMask){ + + string retval = ""; + + if(slsErrorMask&CANNOT_CONNECT_TO_DETECTOR) + retval.append("Cannot connect to Detector\n"); + + if(slsErrorMask&CANNOT_CONNECT_TO_RECEIVER) + retval.append("Cannot connect to Receiver\n"); + + if(slsErrorMask&COULDNOT_SET_CONTROL_PORT) + retval.append("Could not set control port\n"); + + if(slsErrorMask&COULDNOT_SET_STOP_PORT) + retval.append("Could not set stop port\n"); + + if(slsErrorMask&COULDNOT_SET_DATA_PORT) + retval.append("Could not set receiver port\n"); + + if(slsErrorMask&FILE_PATH_DOES_NOT_EXIST) + retval.append("Path to Output Directory does not exist\n"); + + if(slsErrorMask&COULDNOT_CREATE_UDP_SOCKET) + retval.append("Could not create UDP socket to start receiver\n"); + + if(slsErrorMask&COULDNOT_CREATE_FILE) + retval.append("Could not create file to start receiver.\nCheck permissions of output directory or the overwrite flag\n"); + + if(slsErrorMask&COULDNOT_ENABLE_COMPRESSION) + retval.append("Could not enable/disable data compression in receiver.\nThread creation failed or recompile code with MYROOT1 flag.\n"); + + if(slsErrorMask&RECEIVER_DET_HOSTNAME_NOT_SET) + retval.append("Could not send the detector hostname to the receiver.\n"); + + if(slsErrorMask&RECEIVER_DET_HOSTTYPE_NOT_SET) + retval.append("Could not send the detector type to the receiver.\n"); + + if(slsErrorMask&DETECTOR_TEN_GIGA) + retval.append("Could not enable/disable 10GbE in the detector.\n"); + + if(slsErrorMask&DETECTOR_ACTIVATE) + retval.append("Could not activate/deactivate detector\n"); + + if(slsErrorMask&RECEIVER_DET_POSID_NOT_SET) + retval.append("Could not set detector position id\n"); + + 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"); + + if(slsErrorMask®ISER_WRITE_READ) + retval.append("Could not read/write register in detector\n"); + + + + if(slsErrorMask&COULD_NOT_CONFIGURE_MAC) + retval.append("Could not configure mac\n"); + + if(slsErrorMask&COULDNOT_SET_NETWORK_PARAMETER) + retval.append("Could not set network parameter. Should be valid and in proper format\n"); + + if(slsErrorMask&COULDNOT_SET_ROI) + retval.append("Could not set the exact region of interest. Verify ROI set by detector.\n"); + + if(slsErrorMask&RECEIVER_READ_FREQUENCY) + retval.append("Could not set receiver read frequency.\n"); + + if(slsErrorMask&SETTINGS_NOT_SET) + retval.append("Could not set settings.\n"); + + if(slsErrorMask&SETTINGS_FILE_NOT_OPEN) + retval.append("Could not open settings file. Verify if it exists.\n"); + + if(slsErrorMask&COULDNOT_START_RECEIVER) + retval.append("Could not start receiver.\n"); + + if(slsErrorMask&COULDNOT_STOP_RECEIVER) + retval.append("Could not stop receiver.\n"); + + if(slsErrorMask&DETECTOR_TIMER_VALUE_NOT_SET) + retval.append("Could not set one of timer values in detector.\n"); + + if(slsErrorMask&RECEIVER_ACQ_PERIOD_NOT_SET) + retval.append("Could not set acquisition period in receiver.\n"); + + if(slsErrorMask&RECEIVER_FRAME_NUM_NOT_SET) + retval.append("Could not set frame number in receiver.\n"); + + if(slsErrorMask&RECEIVER_DYNAMIC_RANGE) + retval.append("Could not set dynamic range in receiver.\n"); + + if(slsErrorMask&RECEIVER_TEN_GIGA) + retval.append("Could not enable/disable 10GbE in the receiver.\n"); + + if(slsErrorMask&ALLTIMBITS_NOT_SET) + retval.append("Could not set all trimbits to value.\n"); + + if(slsErrorMask&COULD_NOT_SET_SPEED_PARAMETERS) + retval.append("Could not set the speed parameter value\n"); + + if(slsErrorMask&COULD_NOT_SET_READOUT_FLAGS) + retval.append("Could not set the readout flag\n"); + + if(slsErrorMask&COULD_NOT_SET_FIFO_DEPTH) + retval.append("Could not set receiver fifo depth\n"); + + if(slsErrorMask&COULD_NOT_SET_COUNTER_BIT) + retval.append("Could not set/reset counter bit\n"); + + if(slsErrorMask&COULD_NOT_PULSE_PIXEL) + retval.append("Could not pulse pixel\n"); + + if(slsErrorMask&COULD_NOT_PULSE_PIXEL_NMOVE) + retval.append("Could not pulse pixel and move\n"); + + if(slsErrorMask&COULD_NOT_PULSE_CHIP) + retval.append("Could not pulse chip\n"); + + if(slsErrorMask&COULD_NOT_SET_RATE_CORRECTION) + retval.append("Could not set rate correction\n"); + + if(slsErrorMask&DETECTOR_NETWORK_PARAMETER) + retval.append("Could not set/get detector network parameter\n"); + + if(slsErrorMask&RATE_CORRECTION_NOT_32or16BIT) + retval.append("Rate correction Deactivated, must be in 32 or 16 bit mode\n"); + + if(slsErrorMask&RATE_CORRECTION_NO_TAU_PROVIDED) + retval.append("Rate correction Deactivated. No default tau provided in file\n"); + + if(slsErrorMask&PROGRAMMING_ERROR) + retval.append("Could not program FPGA\n"); + + if(slsErrorMask&RECEIVER_ACTIVATE) + retval.append("Could not activate/deactivate receiver\n"); + + if(slsErrorMask&DATA_STREAMING) + retval.append("Could not enable/disable Data Streaming\n"); + + if(slsErrorMask&RESET_ERROR) + retval.append("Could not reset the FPGA\n"); + + if(slsErrorMask&POWER_CHIP) + retval.append("Could not power on/off/get the chip\n"); + + if(slsErrorMask&RECEIVER_READ_TIMER) + retval.append("Could not set receiver read timer\n"); + + if(slsErrorMask&RECEIVER_FLIPPED_DATA_NOT_SET) + retval.append("Could not set receiver flipped data/bottom\n"); + + if(slsErrorMask&THRESHOLD_NOT_SET) + retval.append("Could not set threshold\n"); + + if(slsErrorMask&RECEIVER_FILE_FORMAT) + retval.append("Could not set receiver file format\n"); + + if(slsErrorMask&RECEIVER_TIMER_NOT_SET) + retval.append("Could not set timer in receiver.\n"); + + if(slsErrorMask&RECEIVER_SILENT_MODE_NOT_SET) + retval.append("Could not set silent mode in receiver.\n"); + + if(slsErrorMask&RECEIVER_ENABLE_GAPPIXELS_NOT_SET) + retval.append("Could not enable/disable gap pixels in receiver.\n"); + + if(slsErrorMask&RESTREAM_STOP_FROM_RECEIVER) + retval.append("Could not restream stop from receiver.\n"); + + + + + //------------------------------------------------------ length of message + + + return retval; + + } + + + /** Sets multi error mask + @param multi error mask to be set to + /returns multi error mask + */ + int64_t setErrorMask(int64_t i){errorMask=i;return getErrorMask();}; + + /**returns multi error mask */ + int64_t getErrorMask(){return errorMask;}; + + /** Clears error mask + /returns error mask + */ + int64_t clearErrorMask(){errorMask=0;return errorMask;}; + + /** Gets the not added detector list + /returns list + */ + char* getNotAddedList(){return notAddedList;}; + + /** Append the detector to not added detector list + * @param name append to the list + /returns list + */ + void appendNotAddedList(const char* name){strcat(notAddedList,name);strcat(notAddedList,"+");}; + + /** Clears not added detector list + /returns error mask + */ + void clearNotAddedList(){strcpy(notAddedList,"");}; + + +protected: + + /** Error Mask */ + int64_t errorMask; + + /** Detectors Not added List */ + char notAddedList[MAX_STR_LENGTH]; + +}; + +#endif /* ERROR_DEFS_H_ */ diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h new file mode 100755 index 000000000..b0d960f62 --- /dev/null +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -0,0 +1,590 @@ +#ifndef SLS_DETECTOR_DEFS_H +#define SLS_DETECTOR_DEFS_H + + +#ifdef __CINT__ +#define MYROOT +#define __cplusplus +#endif + +//#include +#include "sls_receiver_defs.h" + +/** default maximum string length */ +#define MAX_SCAN_STEPS 2000 +/** maxmimum number of modules per controller*/ +#define MAXMODS 24 +/** maxmimum number of detectors ina multidetector structure*/ +#define MAXDET 100 +/** header length for data :gotthard*/ +#define HEADERLENGTH 12 + +/** maximum rois */ +#define MAX_ROIS 100 + +/** maximum unit size of program sent to detector */ +#define MAX_FPGAPROGRAMSIZE (2 * 1024 *1024) + + + +#define MAX_SCAN_LEVELS 2 + +typedef char mystring[MAX_STR_LENGTH]; +typedef double mysteps[MAX_SCAN_STEPS]; + + + +#ifndef DACS_FLOAT +typedef int dacs_t; +#else +typedef float dacs_t; +#endif + +#define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee" +#define DEFAULT_DET_IP "129.129.202.46" + + +/** + \file sls_detector_defs.h +This file contains all the basic definitions common to the slsDetector class +and to the server programs running on the detector + + + * @author Anna Bergamaschi + * @version 0.1alpha (any string) + * @see slsDetector + +$Revision: 824 $ + +*/ + + +/** get flag form most functions */ +#define GET_FLAG -1 + + +#ifdef __cplusplus + +/** @short class containing all the structures, constants and enum definitions */ +class slsDetectorDefs: public virtual slsReceiverDefs{ + public: + + slsDetectorDefs(){}; + +#endif + + + enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS}; + + + +/** + @short structure for a detector channel + + should not be used by unexperienced users + + \see ::channelRegisterBit +*/ + typedef struct { + int chan; /**< is the channel number */ + int chip; /**< is the chip number */ + int module; /**< is the module number */ + int64_t reg; /**< is the is the channel register (e.g. trimbits, calibration enable, comparator enable...) */ + } sls_detector_channel; + + /** + @short structure for a detector chip + + should not be used by unexperienced users + \see ::chipRegisterBit ::channelRegisterBit +*/ + typedef struct { + int chip; /**< is the chip number */ + int module; /**< is the module number */ + int nchan; /**< is the number of channels in the chip */ + int reg; /**