From 7a55ed9a74ffe6605ad54e5dbe915b2b5fa8ef53 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 5 Feb 2013 11:23:46 +0000 Subject: [PATCH] frame index now is set via the multi and sls and sent to receiver when frames/cycles is set, resetframescaught doesnt decide if frames needed, possible problem in acquire scans,gets #frames/cycles from detector,but needed git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@451 951219d9-93cf-4727-9268-0efd64621fa3 --- .../commonFiles/sls_detector_funcs.h | 4 +- .../slsDetectorServer_funcs.c | 15 ++--- .../slsDetector_firmware.c | 6 +- .../multiSlsDetector/multiSlsDetector.cpp | 24 ++++++- .../multiSlsDetector/multiSlsDetector.h | 9 ++- .../slsDetector/slsDetector.cpp | 43 ++++++++++-- slsDetectorSoftware/slsDetector/slsDetector.h | 11 +++- .../slsDetector/slsDetectorCommand.cpp | 9 +++ .../slsDetector/slsDetectorUtils.cpp | 9 ++- .../slsDetector/slsDetectorUtils.h | 3 +- .../slsReceiver/slsReceiverFunctionList.cpp | 38 +++++++---- .../slsReceiver/slsReceiverFunctionList.h | 13 ++-- .../slsReceiver/slsReceiver_funcs.cpp | 66 ++++++++++++++++--- .../slsReceiver/slsReceiver_funcs.h | 3 + 14 files changed, 196 insertions(+), 57 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index d5cbb83c2..73bf29d2a 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -128,7 +128,9 @@ enum { F_SETUP_UDP, /**< sets the receiver udp connection and returns receiver mac address */ - F_ENABLE_FILE_WRITE /**< sets the receiver file write */ + F_ENABLE_FILE_WRITE, /**< sets the receiver file write */ + + F_SET_FRAME_INDEX /**< sets the receiver frame index */ /* Always append functions hereafter!!! */ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c index e3c423028..77fd36862 100755 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c @@ -54,20 +54,17 @@ int init_detector(int b) { printf("This is a VIRTUAL detector\n"); #else mapCSP0(); - //only for control server if(b){ - - printf("fifo reset\n"); - fifoReset(); - printf("fifo test\n"); - fifoTest(); - printf("\ninitializing detector\n"); - //Aurora-Links - + printf("\ninitializing detector\n"); #endif #ifdef SLS_DETECTOR_FUNCTION_LIST initializeDetector(); + + + fifoReset(); + fifoTest(); + //testFpga(); //testRAM(); //setSettings(GET_SETTINGS,-1); diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c b/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c index 421e4ec59..1e7f52a2b 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c @@ -122,7 +122,7 @@ int fifoReset(){ u_int32_t mask = FIFOCNTRL_RESET_MASK; fifo_control_reg |= mask; - printf("CTRL Register bits: 0x%08x\n",fifo_control_reg); + //printf("CTRL Register bits: 0x%08x\n",fifo_control_reg); bus_w(FIFO_CNTRL_REG,fifo_control_reg); bus_w(FIFO_CNTRL_REG,fifo_control_reg); @@ -132,6 +132,8 @@ int fifoReset(){ fifo_control_reg &= (~mask); bus_w(FIFO_CNTRL_REG,fifo_control_reg); + printf("fifo has been reset\n\n"); + return OK; } @@ -142,7 +144,7 @@ int fifoTest(void){ int buffer_length = 256; int rec_buffer_length = 4096; - char cmd[] = "fpgatfemp"; + char cmd[] = "help"; unsigned int buffer[buffer_length]; unsigned int rec_buffer[rec_buffer_length]; unsigned int send_len; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index fed02dd2c..c2e048891 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3725,11 +3725,11 @@ int multiSlsDetector::getReceiverCurrentFrameIndex() { -int multiSlsDetector::resetFramesCaught(int index) { +int multiSlsDetector::resetFramesCaught() { int ret=-100, ret1; for (int i=0; inumberOfDetectors; i++){ if (detectors[i]){ - ret1=detectors[i]->resetFramesCaught(index); + ret1=detectors[i]->resetFramesCaught(); if (ret==-100) ret=ret1; else if (ret!=ret1) @@ -3849,3 +3849,23 @@ int multiSlsDetector::enableWriteToFile(int enable){ return ret; } + + + + +int multiSlsDetector::setFrameIndex(int index){ + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setFrameIndex(index); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; +} + diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 5b0beabfe..f520d66dc 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1089,9 +1089,8 @@ class multiSlsDetector : public slsDetectorUtils { /** * resets framescaught * @param index frames caught by receiver - * @param index if frame index is needed */ - int resetFramesCaught(int index=-1); + int resetFramesCaught(); /** * Reads a frame from receiver @@ -1124,6 +1123,12 @@ class multiSlsDetector : public slsDetectorUtils { */ int enableWriteToFile(int enable=-1); + /** + * set frame index to 0 or -1 + * @param index is the frame index + */ + int setFrameIndex(int index=-1); + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 8d4e58395..73dcc80f1 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -4557,6 +4557,10 @@ char* slsDetector::setReceiver(string receiverIP){ setFilePath(fileIO::getFilePath()); setFileName(fileIO::getFileName()); setFileIndex(fileIO::getFileIndex()); + if ((setTimer(FRAME_NUMBER,-1)*setTimer(CYCLES_NUMBER,-1))>1) + setFrameIndex(0); + else + setFrameIndex(-1); enableWriteToFile(parentDet->enableWriteToFileMask()); setUDPConnection(); } @@ -5837,17 +5841,15 @@ int slsDetector::getReceiverCurrentFrameIndex(){ -int slsDetector::resetFramesCaught(int index){ +int slsDetector::resetFramesCaught(){ int fnum=F_RESET_FRAMES_CAUGHT; int ret = FAIL; - int retval=-1; - int arg=index; if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { #ifdef VERBOSE - std::cout << "Reset Frames Caught by Receiver:" << arg << std::endl; + std::cout << "Reset Frames Caught by Receiver" << std::endl; #endif - ret=thisReceiver->sendInt(fnum,retval,arg); + ret=thisReceiver->executeFunction(fnum); if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -6058,3 +6060,34 @@ int slsDetector::enableWriteToFile(int enable){ return parentDet->enableWriteToFileMask(); } + + + + + +int slsDetector::setFrameIndex(int index){ + int fnum=F_SET_FRAME_INDEX; + int ret = FAIL; + int retval=-1; + int arg = index; + + if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ + fileIO::setFrameIndex(index); + } + + else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending frame index to receiver " << arg << std::endl; +#endif + ret=thisReceiver->sendInt(fnum,retval,arg); + if(ret!=FAIL) + fileIO::setFrameIndex(retval); + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + return fileIO::getFrameIndex(); +} + + + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index e849f8eb2..5897607f8 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1465,9 +1465,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** * resets framescaught * @param index frames caught by receiver - * @param index if frame index is needed */ - int resetFramesCaught(int index=-1); + int resetFramesCaught(); /** * Reads a frame from receiver @@ -1513,6 +1512,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int enableWriteToFile(int enable=-1); + /** + * set frame index to 0 or -1 + * @param index is the frame index + */ + int setFrameIndex(int index=-1); + + + int fillModuleMask(int *mM); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 1caa11105..40a54891d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -3187,6 +3187,15 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { else rval=ret; + //set frame index + if (index==FRAME_NUMBER || index==CYCLES_NUMBER ){ + if ((myDet->setTimer(FRAME_NUMBER,-1)*myDet->setTimer(CYCLES_NUMBER,-1))>1) + myDet->setFrameIndex(0); + else + myDet->setFrameIndex(-1); + } + + sprintf(answer,"%0.9f",rval); return string(answer); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index b081346ce..c3ba8b7ec 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -121,10 +121,8 @@ void slsDetectorUtils::acquire(int delflag){ //resets frames caught in receiver - if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1) - resetFramesCaught(1); - else - resetFramesCaught(0); + resetFramesCaught(); + if(setReceiverOnline()==OFFLINE_FLAG) *stoppedFlag=1; @@ -234,7 +232,8 @@ void slsDetectorUtils::acquire(int delflag){ } setCurrentFrameIndex(0); - if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1) { + //if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1) { + if ((setTimer(FRAME_NUMBER,-1)*setTimer(CYCLES_NUMBER,-1))>1){ setFrameIndex(0); } else { setFrameIndex(-1); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index f1b8f2fb5..242da2afa 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -625,9 +625,8 @@ virtual int getReceiverCurrentFrameIndex()=0; /** * resets framescaught * @param index frames caught by receiver - * @param index if frame index is needed */ -virtual int resetFramesCaught(int index=-1)=0; +virtual int resetFramesCaught()=0; /** * Reads a frame from receiver diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 1771c0eb3..131c588d7 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -31,7 +31,7 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): shortFileName(shortfname), shortFileNameIndex(0), fileIndex(0), - frameIndexNeeded(true), + frameIndexNeeded(0), framesCaught(0), startFrameIndex(-1), frameIndex(0), @@ -152,12 +152,10 @@ int slsReceiverFunctionList::setFileIndex(int i){ } -bool slsReceiverFunctionList::resetTotalFramesCaught(bool i){ - frameIndexNeeded = i; +void slsReceiverFunctionList::resetTotalFramesCaught(){ startAcquisitionIndex = -1; totalFramesCaught = 0; - return frameIndexNeeded; } @@ -170,7 +168,9 @@ int slsReceiverFunctionList::startReceiver(){ int err = 0; if(!listening_thread_running){ +#ifdef VERBOSE cout << "Starting new acquisition threadddd ...." << endl; +#endif listening_thread_running=1; @@ -183,8 +183,9 @@ int slsReceiverFunctionList::startReceiver(){ cout << "Cant create writing thread. Status:" << status << endl << endl; return FAIL; } +#ifdef VERBOSE cout << "Writing thread created successfully." << endl; - +#endif //error creating listenign thread err = 0; @@ -200,9 +201,14 @@ int slsReceiverFunctionList::startReceiver(){ } while(status!=RUNNING); +#ifdef VERBOSE cout << "Listening thread created successfully." << endl; +#endif + + cout << "Threads created successfully." << endl; } + return OK; } @@ -211,12 +217,14 @@ int slsReceiverFunctionList::startReceiver(){ int slsReceiverFunctionList::stopReceiver(){ -//#ifdef VERBOSE +#ifdef VERBOSE cout << "Stopping Receiver" << endl; -//#endif +#endif if(listening_thread_running){ +#ifdef VERBOSE cout << "Stopping new acquisition threadddd ...." << endl; +#endif //stop listening thread listening_thread_running=0; udpSocket->ShutDownSocket(); @@ -228,7 +236,7 @@ int slsReceiverFunctionList::stopReceiver(){ // if(fifo) delete fifo; //if(latestData) delete latestData;/**new*/ } - cout << "Status:" << status << endl; + cout << "Receiver Stoppped.\nStatus:" << status << endl; return OK; @@ -374,18 +382,17 @@ int slsReceiverFunctionList::startWriting(){ framesInFile=0; framesCaught=0; frameIndex=0; - if(sfilefd) sfilefd=0; - strcpy(savefilename,""); strcpy(actualfilename,""); cout << "Max Frames Per File:" << maxFramesPerFile << endl; cout << "Ready!" << endl; + if(enableFileWrite){ //create file name - if(!frameIndexNeeded) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); + if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex); //for sebastian @@ -398,6 +405,7 @@ int slsReceiverFunctionList::startWriting(){ } + while(listening_thread_running){ //when it reaches maxFramesPerFile,start writing new file @@ -406,7 +414,7 @@ int slsReceiverFunctionList::startWriting(){ if(enableFileWrite){ fclose(sfilefd); //create file name - if(!frameIndexNeeded) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); + if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex); //for sebastian if(!shortFileName) strcpy(actualfilename,savefilename); @@ -426,6 +434,8 @@ int slsReceiverFunctionList::startWriting(){ framesInFile = 0; } + + //actual writing from fifo if(!fifo->isEmpty()){ // dataWriteFrame = new dataStruct; @@ -487,14 +497,14 @@ char* slsReceiverFunctionList::readFrame(char* c){ guiRequiresData=0; //if no more data //if(guiRequiresData) // retun NULL; - //cout<<"latestdata:"<<(int)(*(int*)latestData)<ReceiveDataOnly(&index,sizeof(index)) < 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){//necessary??? + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + retval=slsReceiverList->setFrameIndexNeeded(index); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "frame index:" << retval << 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; +} + + + + + + + int slsReceiverFuncs::setup_udp(){ ret=OK; strcpy(mess,"could not set up udp connection"); @@ -606,18 +661,11 @@ int slsReceiverFuncs::get_frame_index(){ int slsReceiverFuncs::reset_frames_caught(){ ret=OK; - int retval=-1; int index=-1; strcpy(mess,"Could not reset frames caught\n"); - // receive arguments - if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0) {; - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { @@ -626,7 +674,7 @@ int slsReceiverFuncs::reset_frames_caught(){ ret=FAIL; } else - retval=slsReceiverList->resetTotalFramesCaught(index); + slsReceiverList->resetTotalFramesCaught(); } #endif @@ -639,7 +687,7 @@ int slsReceiverFuncs::reset_frames_caught(){ 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 5f02b1b6e..7ac8b512a 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -56,6 +56,9 @@ public: /** Set File index */ int set_file_index(); + /** Set Frame index */ + int set_frame_index(); + /** Start Receiver - starts listening to udp packets from detector */ int start_receiver();