From d0d7eac5532fbbd1805b64a7a625b7700ffdcf52 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Fri, 23 Nov 2012 16:15:26 +0000 Subject: [PATCH] fixed gui expecting more databytes from receiver, cuz of probes changing databytes git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@359 951219d9-93cf-4727-9268-0efd64621fa3 --- .../MySocketTCP/genericSocket.h | 6 ++- .../slsDetector/slsDetector.cpp | 38 +++++++++++-------- .../slsReceiver/slsReceiver.cpp | 23 ++++++++--- .../slsReceiver/slsReceiverFunctionList.cpp | 16 +------- .../slsReceiver/slsReceiverFunctionList.h | 12 ++++-- .../slsReceiver/slsReceiver_funcs.cpp | 35 +++++++++++------ .../slsReceiver/slsReceiver_funcs.h | 9 +++-- 7 files changed, 83 insertions(+), 56 deletions(-) diff --git a/slsDetectorSoftware/MySocketTCP/genericSocket.h b/slsDetectorSoftware/MySocketTCP/genericSocket.h index 9836e986a..6201c11e4 100644 --- a/slsDetectorSoftware/MySocketTCP/genericSocket.h +++ b/slsDetectorSoftware/MySocketTCP/genericSocket.h @@ -189,7 +189,7 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){ - cerr << "Can not bind socket "<timerValue[MEASUREMENTS_NUMBER]=1; thisDetector->timerValue[CYCLES_NUMBER]=1; + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8; + + if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0) + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; + } - if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0) - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - else - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8; /** set trimDsdir, calDir to default to home directory*/ strcpy(thisDetector->settingsDir,getenv("HOME")); strcpy(thisDetector->calDir,getenv("HOME")); @@ -1338,11 +1340,13 @@ int slsDetector::setNumberOfModules(int n, dimension d){ if (dr==24) dr=32; - if (thisDetector->timerValue[PROBES_NUMBER]==0) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8; - } else { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - } + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8; + + if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->timerValue[PROBES_NUMBER]!=0) + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; + } + #ifdef VERBOSE std::cout<< "Data size is " << thisDetector->dataBytes << std::endl; @@ -3824,12 +3828,15 @@ int slsDetector::setDynamicRange(int n){ if (ret!=FAIL && retval>0) { /* checking the number of probes to chose the data size */ - if (thisDetector->timerValue[PROBES_NUMBER]==0) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; - } else { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - } - + + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; + + if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->timerValue[PROBES_NUMBER]!=0) + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; + } + + if (retval==32) thisDetector->dynamicRange=24; else @@ -5654,7 +5661,6 @@ int slsDetector::resetFramesCaught(int index){ int* slsDetector::readFrameFromReceiver(char* fName, int &fIndex){ - //cout<<"databytes:"<dataBytes<<" headerlength:"<dataBytes+HEADERLENGTH)/sizeof(int);//2572/ int* retval=new int[nel]; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver.cpp index 7e6997f87..0d8160edc 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver.cpp @@ -5,15 +5,24 @@ #include "MySocketTCP.h" #include "slsReceiver_funcs.h" + +#include //SIGINT + #include using namespace std; +//static MySocketTCP *mysocket = NULL; +void closeFile(int p){cout<<"in closefile in receiver"<Disconnect(); + exit(0); +} int main(int argc, char *argv[]) { int ret = slsDetectorDefs::OK; - MySocketTCP *socket = NULL; + MySocketTCP *mysocket = NULL; string fname = ""; bool shortfname = false; @@ -33,11 +42,15 @@ int main(int argc, char *argv[]) //reads config file, creates socket, assigns function table - slsReceiverFuncs *receiver = new slsReceiverFuncs(socket,fname,ret, shortfname); + slsReceiverFuncs *receiver = new slsReceiverFuncs(mysocket,fname,ret, shortfname); if(ret==slsDetectorDefs::FAIL) return -1; + //Catch signal SIGINT to close files properly + signal(SIGINT,closeFile); + + #ifdef VERBOSE cout << "Function table assigned." << endl; #endif @@ -51,7 +64,7 @@ int main(int argc, char *argv[]) #ifdef VERY_VERBOSE cout << "Waiting for client call" << endl; #endif - if(socket->Connect()>=0){ + if(mysocket->Connect()>=0){ #ifdef VERY_VERBOSE cout << "Conenction accepted" << endl; #endif @@ -59,14 +72,14 @@ int main(int argc, char *argv[]) #ifdef VERY_VERBOSE cout << "function executed" << endl; #endif - socket->Disconnect(); + mysocket->Disconnect(); #ifdef VERY_VERBOSE cout << "connection closed" << endl; #endif } } - delete socket; + delete mysocket; cout << "Goodbye!" << endl; return 0; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 9712b2ca8..ada7e73d1 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -106,18 +106,6 @@ bool slsReceiverFunctionList::resetTotalFramesCaught(bool i){ -void slsReceiverFunctionList::closeFile(int p){ - if(listening_thread_running){ - cout << "Closing file and Exiting." << endl; - fclose(sfilefd); - } - //exit(0); -} - - - - - int slsReceiverFunctionList::startReceiver(){ #ifdef VERBOSE cout << "Starting Receiver" << endl; @@ -188,9 +176,6 @@ int slsReceiverFunctionList::startListening(){ frameIndex=0; shortFileNameIndex=1; - //Catch signal SIGINT to close files properly - signal(SIGINT,closeFile); - //create file name if(!frameIndexNeeded) @@ -280,6 +265,7 @@ int slsReceiverFunctionList::startListening(){ //close file fclose(sfilefd); #ifdef VERBOSE + cout << "listening_thread_running:" << listening_thread_running << endl; cout << "sfield:" << (int)sfilefd << endl; #endif diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index 1a8a844e3..675602166 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -104,7 +104,7 @@ public: /** * Close File */ - static void closeFile(int p); + //static void closeFile(int p); /** * Starts Receiver - starts to listen for packets @@ -186,7 +186,7 @@ private: int framesInFile; /** if the listening thread is running*/ - static int listening_thread_running; + //static int listening_thread_running; /** thread listening to packets */ pthread_t listening_thread; @@ -195,7 +195,7 @@ private: runStatus status; /** File Descriptor */ - static FILE *sfilefd; + //static FILE *sfilefd; /** Receiver buffer */ char buffer[BUFFER_SIZE]; @@ -206,6 +206,12 @@ private: /** Server UDP Port*/ int server_port; +public: + /** File Descriptor */ + static FILE *sfilefd; + + /** if the listening thread is running*/ + static int listening_thread_running; }; /* diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index 9decc2384..e05015b2f 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -6,7 +6,6 @@ #include "slsReceiver_funcs.h" #include "slsReceiverFunctionList.h" -//#include //SIGINT #include #include @@ -17,7 +16,8 @@ using namespace std; - +int slsReceiverFuncs::file_des(-1); +int slsReceiverFuncs::socketDescriptor(-1); slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname): socket(mySocket), @@ -97,8 +97,9 @@ slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int function_table(); slsReceiverList = new slsReceiverFunctionList(shortfname); - //Catch signal SIGINT to close files properly - //signal(SIGINT,closeFile); + + file_des=socket->getFileDes(); + socketDescriptor=socket->getsocketDescriptor(); success = OK; } @@ -174,7 +175,6 @@ int slsReceiverFuncs::decode_function(){ if (ret==FAIL) cout << "Error executing the function = " << fnum << endl; - return ret; } @@ -198,12 +198,22 @@ int slsReceiverFuncs::M_nofunc(){ -/* void slsReceiverFuncs::closeFile(int p){ - //if(socket) - slsReceiverFunctionList::closeFile(); + char *buf; + char buffer[1]; + + + if(slsReceiverFunctionList::listening_thread_running) + fclose(slsReceiverFunctionList::sfilefd); + + + close(file_des); + shutdown(socketDescriptor,SHUT_RDWR); + close(socketDescriptor); + } -*/ + + int slsReceiverFuncs::set_file_name() { @@ -588,9 +598,9 @@ int slsReceiverFuncs::read_frame(){ int count=0; do{ if(count>0){ - cout << endl << "unmatching: index:" << index <<" index2:" << index2 << endl; + cout << endl << "unmatching/wrong order: index:" << index <<" index2:" << index2 << endl; if(count>10){ - strcpy(mess,"unmatching index. could not read frame.\n"); + strcpy(mess,"unmatching index/wrong order. could not read frame.\n"); ret=FAIL; break; } @@ -601,7 +611,7 @@ int slsReceiverFuncs::read_frame(){ index2= (int)(*((int*)retval2)); count++; - }while((index%2)==(index2%2)); + }while(((index%2)==(index2%2))||(index+1!=index2)); fIndex=((int)(*((int*)retval)) - startIndex)/2; arg[0]=fIndex-1; @@ -750,6 +760,7 @@ int slsReceiverFuncs::set_port() { socket->Disconnect(); delete socket; socket = mySocket; + file_des=socket->getFileDes(); } } diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h index 5eaeef2c9..17ce24392 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -42,7 +42,7 @@ public: int M_nofunc(); /** Close File */ - //static void closeFile(int p); + static void closeFile(int p); /** Set File name without frame index, file index and extension */ int set_file_name(); @@ -96,11 +96,11 @@ public: /** Execute command */ int exec_command(); -private: +//private: /** Socket */ MySocketTCP*& socket; - +private: /** slsReceiverFunctionList object */ slsReceiverFunctionList *slsReceiverList; @@ -119,6 +119,9 @@ private: /** Lock Status if server locked to a client */ int lockStatus; + static int file_des; + static int socketDescriptor; + };