From 28d2d64f51ee59e687a7ac7f5beb22e94243b8ea Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 26 Feb 2013 10:19:05 +0000 Subject: [PATCH] defined a default and register call back function to write receiver data git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@473 951219d9-93cf-4727-9268-0efd64621fa3 --- .../eigerDetectorServer/sls_detector_defs.h | 18 +++++++ .../slsDetector/slsDetectorUsers.h | 7 ++- slsDetectorSoftware/slsReceiver/Makefile | 6 +-- .../slsReceiver/slsReceiverFunctionList.cpp | 51 ++++++++++++------- .../slsReceiver/slsReceiverFunctionList.h | 10 +++- .../usersFunctions/usersFunctions.cpp | 13 +++++ .../usersFunctions/usersFunctions.h | 2 + 7 files changed, 83 insertions(+), 24 deletions(-) diff --git a/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h b/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h index 2e214d1e7..ea17080b0 100755 --- a/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h @@ -60,6 +60,16 @@ $Revision: 464 $ /** get flag form most functions */ #define GET_FLAG -1 +#ifdef MYROOT + +/** @short class containing all the structures, constants and enum definitions */ +class slsDetectorDefs { + + public: + + slsDetectorDefs(){}; + +#endif enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS}; @@ -526,11 +536,19 @@ enum angleConversionParameter { //} angleConversionConstant; +#ifdef __cplusplus + protected: +#endif + + #ifndef MYROOT #include "sls_detector_funcs.h" #endif +#ifdef __cplusplus +}; +#endif ; #endif ; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index a0e1e76b2..9e5f1794f 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -399,7 +399,12 @@ class slsDetectorUsers void registerRawDataCallback(int( *userCallback)(double* p, int n, void*), void *pArg); - + /** + @short register callback for writing receiver data - if the rawDataCallback is registered, no receiver data writing will be carried on automatically by the software - the receiver data are deleted by the software + \param userCallback function for writing the receiver data - p is the pointer to the data, n is the number of bytes to write + */ + + void registerWriteReceiverDataCallback(int( *userCallback)(char* p, int n, void*), void *pArg); /** @short function to initalize a set of measurements (reset binning if angular conversion, reset summing otherwise) - can be overcome by the user's functions thanks to the virtual property diff --git a/slsDetectorSoftware/slsReceiver/Makefile b/slsDetectorSoftware/slsReceiver/Makefile index eb0ab68ca..fa8e2d23f 100644 --- a/slsDetectorSoftware/slsReceiver/Makefile +++ b/slsDetectorSoftware/slsReceiver/Makefile @@ -1,9 +1,9 @@ CC = g++ - CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD + CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DTESTWRITE LDLIBS += -lm -lstdc++ -lpthread -INCLUDES = -I ../MySocketTCP -I ../commonFiles -I . -SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp +INCLUDES = -I ../MySocketTCP -I ../commonFiles -I ../usersFunctions -I ../slsDetectorAnalysis -I . +SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp ../usersFunctions/usersFunctions.cpp PROGS = slsReceiver DESTDIR ?= bin diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 131c588d7..730f5b13f 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -7,7 +7,9 @@ #include "slsReceiverFunctionList.h" - +#ifdef TESTWRITE +#include "usersFunctions.h" +#endif #include // SIGINT #include // stat @@ -49,7 +51,9 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): bufferSize(BUFFER_SIZE), packetsPerFrame(2), guiRequiresData(0), - currframenum(0) + currframenum(0), + writeReceiverData(0), + pwriteReceiverDataArg(0) { strcpy(savefilename,""); strcpy(actualfilename,""); @@ -67,21 +71,19 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): mem0=(char*)malloc(4096*FIFO_SIZE); if (mem0==NULL) { - cout<<"++++++++++++++++++++++ COULD NON ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; + cout<<"++++++++++++++++++++++ COULD NOT 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; - - - - +#ifdef TESTWRITE + //to test write receiver data call back + registerWriteReceiverDataCallback(&defaultWriteReceiverDataFunc, NULL); +#endif } @@ -386,7 +388,11 @@ int slsReceiverFunctionList::startWriting(){ strcpy(savefilename,""); strcpy(actualfilename,""); - cout << "Max Frames Per File:" << maxFramesPerFile << endl; + if (!writeReceiverData) + cout << "Max Frames Per File:" << maxFramesPerFile << endl; + else + cout << "Note: Writing Data has been defined exernally" << endl; + cout << "Ready!" << endl; @@ -400,8 +406,10 @@ int slsReceiverFunctionList::startWriting(){ else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0); //start writing - sfilefd = fopen((const char *) (actualfilename), "w"); - cout << "Saving to " << actualfilename << endl; + if (!writeReceiverData){ + sfilefd = fopen((const char *) (actualfilename), "w"); + cout << "Saving to " << actualfilename << endl; + } } @@ -409,7 +417,7 @@ int slsReceiverFunctionList::startWriting(){ while(listening_thread_running){ //when it reaches maxFramesPerFile,start writing new file - if (framesInFile == maxFramesPerFile) { + if ((!writeReceiverData)&& (framesInFile == maxFramesPerFile)) { if(enableFileWrite){ fclose(sfilefd); @@ -428,7 +436,7 @@ int slsReceiverFunctionList::startWriting(){ //currframenum=(int)(*((int*)latestData)); cout << "packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t" "framenum " << currframenum << "\t\t" - "p " << prevframenum << " sleep:" << sleepnumber << endl; + "p " << prevframenum << endl; prevframenum=currframenum; framesInFile = 0; @@ -449,8 +457,12 @@ int slsReceiverFunctionList::startWriting(){ guiRequiresData=0; } //cout<<"write index:"<<(int)(*(int*)latestData)<buffer, 1, dataWriteFrame->rc, sfilefd); + if(enableFileWrite){ + if (writeReceiverData) + writeReceiverData(dataWriteFrame->buffer,dataWriteFrame->rc, pwriteReceiverDataArg); + else + fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd); + } framesInFile++; ///ANNA?!?!??! // delete [] dataWriteFrame->buffer; @@ -458,9 +470,10 @@ int slsReceiverFunctionList::startWriting(){ } delete dataWriteFrame; } - else{sleepnumber++;sleepnumber++;sleepnumber++;//cout<<"fifo empty, usleep"<