diff --git a/slsDetectorSoftware/slsReceiver/Makefile b/slsDetectorSoftware/slsReceiver/Makefile index 926199703..eb0ab68ca 100644 --- a/slsDetectorSoftware/slsReceiver/Makefile +++ b/slsDetectorSoftware/slsReceiver/Makefile @@ -1,6 +1,6 @@ CC = g++ -CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD -LDLIBS += -lm -lstdc++ -lpthread + CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD +LDLIBS += -lm -lstdc++ -lpthread INCLUDES = -I ../MySocketTCP -I ../commonFiles -I . SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 97b8415b9..cb64565e7 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -47,7 +47,9 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): fifo(NULL), shortFrame(-1), bufferSize(BUFFER_SIZE), - packetsPerFrame(2) + packetsPerFrame(2), + guiRequiresData(0), + currframenum(0) { strcpy(savefilename,""); strcpy(actualfilename,""); @@ -55,6 +57,30 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): strcpy(fileName,"run"); eth = new char[MAX_STR_LENGTH]; strcpy(eth,""); + // dataWriteFrame = new dataStruct; + latestData = new char[bufferSize]; + + + fifofree = new CircularFifo(); + + fifo = new CircularFifo(); + + mem0=(char*)malloc(4096*FIFO_SIZE); + if (mem0==NULL) { + cout<<"++++++++++++++++++++++ COULD NON ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; + } + buffer=mem0; + while (buffer<(mem0+4096*(FIFO_SIZE-1))) { + fifofree->push(buffer); + buffer+=4096; + } + // cout<<"DEFAULT BUFFER SIZE IS "<< BUFFER_SIZE << endl; + + + // buffer=mem0; + + + } @@ -77,7 +103,7 @@ int slsReceiverFunctionList::getFrameIndex(){ if(startFrameIndex==-1) frameIndex=0; else if(framesCaught) - frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/packetsPerFrame; + frameIndex=(currframenum - startFrameIndex)/packetsPerFrame; return frameIndex; } @@ -87,7 +113,7 @@ int slsReceiverFunctionList::getAcquisitionIndex(){ if(startAcquisitionIndex==-1) acquisitionIndex=0; else if(framesCaught) - acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/packetsPerFrame; + acquisitionIndex=(currframenum - startAcquisitionIndex)/packetsPerFrame; return acquisitionIndex; } @@ -147,14 +173,13 @@ int slsReceiverFunctionList::startReceiver(){ cout << "Starting new acquisition threadddd ...." << endl; listening_thread_running=1; - fifo = new CircularFifo(); //error creating writing thread err = pthread_create(&writing_thread, NULL,startWritingThread, (void*) this); if(err){ listening_thread_running=0; status = IDLE; - if(fifo) delete fifo; + // if(fifo) delete fifo; cout << "Cant create writing thread. Status:" << status << endl << endl; return FAIL; } @@ -169,7 +194,7 @@ int slsReceiverFunctionList::startReceiver(){ status = IDLE; //stop writing thread pthread_join(writing_thread,NULL); - if(fifo) delete fifo; + // if(fifo) delete fifo; cout << endl << "Cant create listening thread. Status:" << status << endl << endl; return FAIL; } @@ -200,7 +225,7 @@ int slsReceiverFunctionList::stopReceiver(){ //stop writing thread pthread_join(writing_thread,NULL); - if(fifo) delete fifo; + // if(fifo) delete fifo; //if(latestData) delete latestData;/**new*/ } cout << "Status:" << status << endl; @@ -228,7 +253,7 @@ void* slsReceiverFunctionList::startListeningThread(void* this_pointer){ int slsReceiverFunctionList::startListening(){ #ifdef VERYVERBOSE - cout << "In startListening()\n"); +i cout << "In startListening()\n"); #endif // Variable and structure definitions int rc; @@ -246,13 +271,13 @@ int slsReceiverFunctionList::startListening(){ - if(!strlen(eth)){ + //if(!strlen(eth)){ cout<<"warning:eth is empty.listening to all"<getErrorStatus()){ #ifdef VERBOSE @@ -265,10 +290,11 @@ int slsReceiverFunctionList::startListening(){ while (listening_thread_running) { status = RUNNING; + if (!fifofree->isEmpty()) { + fifofree->pop(buffer); - buffer = new char[bufferSize]; //receiver 2 half frames - rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer)); + rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer)); if( rc < 0) cerr << "recvfrom() failed" << endl; @@ -282,6 +308,7 @@ int slsReceiverFunctionList::startListening(){ //start of acquisition if(startAcquisitionIndex==-1){ startAcquisitionIndex=startFrameIndex; + currframenum =startAcquisitionIndex; cout<<"startAcquisitionIndex:"<push(dataReadFrame); } - } + + + } + } } } while (listening_thread_running); listening_thread_running=0; @@ -337,21 +367,20 @@ int slsReceiverFunctionList::startWriting(){ cout << "In startWriting()" <isEmpty()){ - - dataWriteFrame = new dataStruct; + // dataWriteFrame = new dataStruct; if(fifo->pop(dataWriteFrame)){ //cout<<"write buffer:"<buffer,bufferSize); + currframenum = (int)(*((int*)dataWriteFrame->buffer)); + if(guiRequiresData){ + memcpy(latestData,dataWriteFrame->buffer,bufferSize); + guiRequiresData=0; + } //cout<<"write index:"<<(int)(*(int*)latestData)<buffer, 1, dataWriteFrame->rc, sfilefd); framesInFile++; - delete dataWriteFrame->buffer; - delete dataWriteFrame; - + ///ANNA?!?!??! + // delete [] dataWriteFrame->buffer; + fifofree->push(dataWriteFrame->buffer); } + delete dataWriteFrame; } + else{sleepnumber++;sleepnumber++;sleepnumber++;//cout<<"fifo empty, usleep"<* fifo; + /** circular fifo to read and write data*/ + CircularFifo* fifofree; /** short frames */ int shortFrame; @@ -275,13 +283,21 @@ private: /** number of packets per frame*/ int packetsPerFrame; + + /** gui wants data */ + int guiRequiresData; + /** current frame number */ + int currframenum; public: /** File Descriptor */ static FILE *sfilefd; /** if the listening thread is running*/ static int listening_thread_running; + + + dataStruct *dataWriteFrame; }; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index 456f06d35..ac8cd6d58 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -781,6 +781,12 @@ int slsReceiverFuncs::read_frame(){ socket->SendDataOnly(retval,DATA_BYTES); } //return ok/fail + + ///ADDED BY ANNA?!?!?!? + delete [] retval; + delete [] origVal; + + return ret; }