From 1b2aba80a5ba8a09653c98f8efa43f1ff1306c62 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Mon, 7 Apr 2014 14:08:07 +0000 Subject: [PATCH] got rid of parameters such as compression and det type in receiver, theymust be sent from client to receiver git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@817 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/commonFiles/error_defs.h | 3 + .../slsDetector/slsDetector.cpp | 79 ++++- .../slsReceiver/slsReceiverFunctionList.cpp | 332 +++++++++++------- .../slsReceiver/slsReceiverFunctionList.h | 21 +- .../slsReceiver/slsReceiver_funcs.cpp | 155 ++++---- .../slsReceiver/slsReceiver_funcs.h | 3 + 6 files changed, 354 insertions(+), 239 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index b0696901c..0f7c9608a 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -31,6 +31,7 @@ using namespace std; #define COULDNOT_CREATE_FILE 0x0100000000000000ULL #define COULDNOT_ENABLE_COMPRESSION 0x0080000000000000ULL #define RECEIVER_DET_HOSTNAME_NOT_SET 0x0040000000000000ULL +#define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0020000000000000ULL @@ -94,6 +95,8 @@ public: 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"); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 53dbc45cf..2abe57aa9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -303,6 +303,25 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int cout << "Cannot connect to server " << name << " over port " << cport << endl; } + +/* + //receiver + if((t != GENERIC) && (setReceiverOnline()==ONLINE_FLAG)) { + int k; + retval = FAIL; + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending detector type to Receiver " << (int)thisDetector->myDetectorType << std::endl; +#endif + if (connectData() == OK) + retval=thisReceiver->sendInt(fnum,k,(int)t); + if(retval==FAIL){ + cout << "ERROR: Could not send detector type to receiver" << endl; + setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); + } + } + } +*/ delete s; return t; @@ -1365,6 +1384,24 @@ int slsDetector::setDetectorType(detectorType const type){ thisDetector->myDetectorType=retType; + //receiver + if((retType != GENERIC) && (setReceiverOnline()==ONLINE_FLAG)) { + retval = FAIL; + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending detector type to Receiver " << (int)thisDetector->myDetectorType << std::endl; +#endif + if (connectData() == OK) + retval=thisReceiver->sendInt(fnum,arg,(int)thisDetector->myDetectorType); + if(retval==FAIL){ + cout << "ERROR: Could not send detector type to receiver" << endl; + setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); + } + } + } + + + return retType; }; @@ -4878,8 +4915,10 @@ char* slsDetector::setReceiver(string receiverIP){ strcpy(thisDetector->receiver_hostname,receiverIP.c_str()); if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ -#ifdef VERBOSE +//#ifdef VERBOSE std::cout << "Setting up receiver with" << endl; + std::cout << "detector type:" << slsDetectorBase::getDetectorType(thisDetector->myDetectorType) << endl; + std::cout << "detector hostname:" << thisDetector->hostname << endl; std::cout << "file path:" << fileIO::getFilePath() << endl; std::cout << "file name:" << fileIO::getFileName() << endl; std::cout << "file index:" << fileIO::getFileIndex() << endl; @@ -4889,27 +4928,28 @@ char* slsDetector::setReceiver(string receiverIP){ std::cout << "frame period:" << thisDetector->timerValue[FRAME_PERIOD] << endl; std::cout << "frame number:" << thisDetector->timerValue[FRAME_NUMBER] << endl; std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl; - -#endif - if(thisDetector->myDetectorType == EIGER) +/** enable compresison, */ +//#endif + if(setDetectorType()!= GENERIC){ setDetectorHostname(); - setFilePath(fileIO::getFilePath()); - setFileName(fileIO::getFileName()); - setFileIndex(fileIO::getFileIndex()); - enableWriteToFile(parentDet->enableWriteToFileMask()); - overwriteFile(parentDet->enableOverwriteMask()); + setFilePath(fileIO::getFilePath()); + setFileName(fileIO::getFileName()); + setFileIndex(fileIO::getFileIndex()); + enableWriteToFile(parentDet->enableWriteToFileMask()); + overwriteFile(parentDet->enableOverwriteMask()); - if ((thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER])>1) - setFrameIndex(0); - else - setFrameIndex(-1); + if ((thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER])>1) + setFrameIndex(0); + else + setFrameIndex(-1); - setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]); - setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); - setDynamicRange(thisDetector->dynamicRange); - //set scan tag - if(thisDetector->myDetectorType != EIGER){ - setUDPConnection(); + setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]); + setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); + setDynamicRange(thisDetector->dynamicRange); + //set scan tag + if(thisDetector->myDetectorType != EIGER){ + setUDPConnection(); + } } } @@ -6630,3 +6670,4 @@ void slsDetector::setDetectorHostname(){ setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); } } + diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 84a1cb8cc..4af8e1e86 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -29,122 +29,39 @@ using namespace std; -slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): - receiver(NULL), - myDetectorType(det), - status(IDLE), - udpSocket(NULL), - server_port(DEFAULT_UDP_PORTNO), - eth(NULL), - maxPacketsPerFile(0), - enableFileWrite(1), - overwrite(1), - fileIndex(0), - scanTag(0), - frameIndexNeeded(0), - acqStarted(false), - measurementStarted(false), - startFrameIndex(0), - frameIndex(0), - packetsCaught(0), - totalPacketsCaught(0), - packetsInFile(0), - startAcquisitionIndex(0), - acquisitionIndex(0), - packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), - frameIndexMask(GOTTHARD_FRAME_INDEX_MASK), - packetIndexMask(GOTTHARD_PACKET_INDEX_MASK), - frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET), - acquisitionPeriod(SAMPLE_TIME_IN_NS), - numberOfFrames(0), - dynamicRange(0), - shortFrame(-1), - currframenum(0), - prevframenum(0), - bufferSize(GOTTHARD_BUFFER_SIZE), - latestData(NULL), - guiDataReady(0), - guiData(NULL), - guiFileName(NULL), - nFrameToGui(0), - fifosize(GOTTHARD_FIFO_SIZE), - numJobsPerThread(-1), - mem0(NULL), - dataCompression(false), - fifo(NULL), - fifoFree(NULL), - buffer(NULL), - numWriterThreads(1), - thread_started(0), - currentWriterThreadIndex(-1), - totalListeningFrameCount(0), - writerthreads_mask(0x0), - listening_thread_running(0), - killListeningThread(0), - killAllWritingThreads(0), - sfilefd(NULL), - startAcquisitionCallBack(NULL), - pStartAcquisition(NULL), - acquisitionFinishedCallBack(NULL), - pAcquisitionFinished(NULL), - rawDataReadyCallBack(NULL), - pRawDataReady(NULL), - cbAction(DO_EVERYTHING){ +slsReceiverFunctionList::slsReceiverFunctionList(): + receiver(NULL), + server_port(DEFAULT_UDP_PORTNO), + thread_started(0), + udpSocket(NULL), + eth(NULL), + latestData(NULL), + guiFileName(NULL), + mem0(NULL), + fifo(NULL), + fifoFree(NULL){ - maxPacketsPerFile = MAX_FRAMES_PER_FILE * packetsPerFrame; - - - //moench variables - if(myDetectorType == MOENCH){ - fifosize = MOENCH_FIFO_SIZE; - bufferSize = MOENCH_BUFFER_SIZE; - packetsPerFrame = MOENCH_PACKETS_PER_FRAME; - maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - frameIndexMask = MOENCH_FRAME_INDEX_MASK; - frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; - packetIndexMask = MOENCH_PACKET_INDEX_MASK; - } - - else if(myDetectorType == EIGER){ - receiver = EigerReceiver::create(); - } - - //variable initialization - onePacketSize = bufferSize/packetsPerFrame; - eth = new char[MAX_STR_LENGTH]; - guiFileName = new char[MAX_STR_LENGTH]; - latestData = new char[bufferSize]; - strcpy(eth,""); - strcpy(guiFileName,""); - strcpy(latestData,""); - strcpy(savefilename,""); - strcpy(filePath,""); - - strcpy(fileName,"run"); - if(myDetectorType == EIGER) - receiver->setFileName(fileName); - - cmSub = NULL; for(int i=0;i /proc/sys/net/core/rmem_max")) cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; @@ -158,13 +75,184 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.netdev_max_backlog=250000 */ +} - //threads + +slsReceiverFunctionList::~slsReceiverFunctionList(){ + createListeningThreads(true); + createWriterThreads(true); + deleteMembers(); +} + + + + +void slsReceiverFunctionList::deleteMembers(){ + //kill threads + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + + for(int i=0;isetFileName(fileName); + } + + onePacketSize = bufferSize/packetsPerFrame; + latestData = new char[bufferSize]; + + + setupFifoStructure(); + if(createListeningThreads() == FAIL){ cout << "ERROR: Could not create listening thread" << endl; exit (-1); @@ -176,30 +264,12 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): } setThreadPriorities(); + + return OK; } -slsReceiverFunctionList::~slsReceiverFunctionList(){ - createListeningThreads(true); - createWriterThreads(true); - for(int i=0;igetDetectorHostname()== NULL) - receiver->initialize(c); + if(myDetectorType == EIGER){ + if(receiver->getDetectorHostname()== NULL) + receiver->initialize(c); + }else + strcpy(detHostname,c); } - return receiver->getDetectorHostname(); + + if(myDetectorType == EIGER) + return receiver->getDetectorHostname(); + else + return detHostname; } @@ -722,6 +799,8 @@ int slsReceiverFunctionList::createUDPSocket(){ if (strchr(eth,'.')!=NULL) strcpy(eth,""); + if(udpSocket){delete udpSocket; udpSocket = NULL;} + //if no eth, listen to all if(!strlen(eth)){ cout<<"warning:eth is empty.listening to all"<> sargname; - if(!strcasecmp(sargname.c_str(),"gotthard")) - slsReceiverFuncs::myDetectorType = GOTTHARD; - else if(!strcasecmp(sargname.c_str(),"moench")) - slsReceiverFuncs::myDetectorType = MOENCH; - else if(!strcasecmp(sargname.c_str(),"eiger")) - slsReceiverFuncs::myDetectorType = EIGER; - else{ - cout << "could not decode detector type in config file.\nOptions are:\ngotthard\nmoench.\n\nExiting." << endl; - success=FAIL; - } - } - } - //compression - else if(sargname=="compression"){ - if(sstr.good()) { - sstr >> sargname; - if((!strcasecmp(sargname.c_str(),"yes"))||(!strcasecmp(sargname.c_str(),"y"))) - dcompr = true; - } - } } } infile.close(); @@ -137,33 +112,12 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): - //parse command line for type etc.. more priority + //parse command line for port etc.. more priority if(success == OK){ for(int iarg=1;iargenableDataCompression(dcompr); - -#ifdef VERBOSE - cout << "Function table assigned." << endl; -#endif file_des=socket->getFileDes(); socketDescriptor=socket->getsocketDescriptor(); @@ -300,6 +215,8 @@ int slsReceiverFuncs::function_table(){ for (int i=0;iReceiveDataOnly(&dr,sizeof(dr)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_FUNCTION_LIST + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else{ + myDetectorType = dr; + ret=slsReceiverList->setDetectorType(dr); + retval = myDetectorType; + } + } +//#ifdef VERBOSE + if(ret!=FAIL) + cout << "detector type" << dr << endl; + else + cout << mess << endl; +//#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h index 5f68e5054..b7f2bef04 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -93,6 +93,9 @@ public: /** Unrecognized Function */ int M_nofunc(); + /** Set detector type */ + int set_detector_type(); + /** Set File name without frame index, file index and extension */ int set_file_name();