From 5b2a896ed3b815162f4a54f9bd1b81f582e42064 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Fri, 28 Nov 2014 14:28:56 +0100 Subject: [PATCH 01/18] to return if it catches only 16 bytes or less than expected, but compensates for first frame being only 266240 for eiger --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6c92bf98e..5822a11ca 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1647,6 +1647,7 @@ int UDPStandardImplementation::startListening(){ stopListening(ithread,rc,packetcount,total); continue; } + /* //start indices for each start of scan/acquisition - eiger does it before if((!measurementStarted) && (rc > 0) && (!ithread)) @@ -2004,7 +2005,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ -void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){ +void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){cout << "Stop Listening" << endl; FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -2019,7 +2020,9 @@ int i; exit(-1); } //push the last buffer into fifo - if((myDetectorType != EIGER) && (rc > 0)){ //for eiger throw away incomplete frames + if((myDetectorType == EIGER) && (rc < 266240) )//for eiger throw away incomplete frames + fifoFree[ithread]->push(buffer[ithread]); + else if(rc > 0){cout<< ithread << " last rc:"<push(buffer[ithread]);//for all detectors too. why was this not there? for rc=0? + } //push dummy buffer to all writer threads From 6787c2e1e0f9c3ced0adc8e7ce731d51cc29f195 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 1 Dec 2014 17:18:26 +0100 Subject: [PATCH 02/18] got rid of unnecessary usleep before transmitting in receiver --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 5822a11ca..0ac51c321 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1521,10 +1521,10 @@ void UDPStandardImplementation::startReadout(){ //#endif //wait so that all packets which take time has arrived - usleep(50000); + usleep(5000); /********************************************/ - usleep(2000000); + //usleep(2000000); pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); From 52d3140a3aa19b68ea6e9560f8848090d0164f03 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 2 Dec 2014 10:12:00 +0100 Subject: [PATCH 03/18] a version of receiver for gemma with bottom --- .../include/UDPStandardImplementation.h | 2 +- .../src/UDPStandardImplementation.cpp | 20 +++++++++++++++++-- slsReceiverSoftware/src/slsReceiver.cpp | 13 +++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 6b5c0c0c4..dca52e6a4 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -47,7 +47,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ virtual ~UDPStandardImplementation(); - + void configure(map config_map); /** * delete and free member parameters diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0ac51c321..cb8d66c25 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -91,6 +91,22 @@ UDPStandardImplementation::UDPStandardImplementation() } +void UDPStandardImplementation::configure(map config_map){ + FILE_LOG(logWARNING) << __AT__ << " called"; + + map::const_iterator pos; + pos = config_map.find("mode"); + if (pos != config_map.end() ){ + int b; + if(!sscanf(pos->second.c_str(), "%d", &b)){ + cout << "Warning: Could not parse mode. Assuming top mode." << endl; + b = 0; + } + bottom = b!= 0; + cout << "bottom:"<< bottom << endl; + } +}; + void UDPStandardImplementation::initializeMembers(){ myDetectorType = GENERIC; maxPacketsPerFile = 0; @@ -945,12 +961,12 @@ int UDPStandardImplementation::createUDPSockets(){ port[1] = server_port[1]; /** eiger specific */ - /* + if(bottom){ port[0] = server_port[1]; port[1] = server_port[0]; } - */ + //if eth is mistaken with ip address if (strchr(eth,'.')!=NULL) strcpy(eth,""); diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 595a39868..6ffc2fdf9 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -65,6 +65,13 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ switch(c){ + case 'm': + int b; + sscanf(optarg, "%d", &b); + bottom = b != 0; + configuration_map["mode"] = optarg; + break; + case 'f': fname = optarg; //cout << long_options[option_index].name << " " << optarg << endl; @@ -86,7 +93,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ string help_message = """\nSLS Receiver Server\n\n"""; help_message += """usage: slsReceiver --config config_fname [--rx_tcpport port]\n\n"""; help_message += """\t--config:\t configuration filename for SLS Detector receiver\n"""; - help_message += """\t--mode:\t ???\n"""; + help_message += """\t--mode:\t 1 for bottom and 0 for top\n"""; help_message += """\t--rx_tcpport:\t TCP Communication Port with the client. Default: 1954.\n\n"""; help_message += """\t--rest_hostname:\t Receiver hostname:port. It applies only to REST receivers, and indicates the hostname of the REST backend. Default: localhost:8081.\n\n"""; @@ -120,10 +127,10 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } if (success==OK){ - FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << endl; + FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << " with mode " << bottom << endl; udp_interface = UDPInterface::create(udp_interface_type); udp_interface->configure(configuration_map); - tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); + tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no, bottom); //tcp ip interface } } From dc4e74087dea563df969849754d820cd6bba2b9c Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 8 Dec 2014 09:16:19 +0100 Subject: [PATCH 04/18] makefile crash if files dont exist in make clean, fixed --- slsReceiverSoftware/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 2a6303f93..c445eaa8c 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -79,8 +79,9 @@ mysocket_test: clean: buildclean make testclean - rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so - rm $(PROGS) + if test -e $(DESTDIR)/libSlsReceiver.a; then rm $(DESTDIR)/libSlsReceiver.a;fi + if test -e $(DESTDIR)/libSlsReceiver.so; then rm $(DESTDIR)/libSlsReceiver.so;fi + if test -e $(PROGS); then rm $(PROGS);fi builddir: if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi From f79f3cf0217417819b8e7a9293375f16da76d7a6 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 8 Dec 2014 09:17:56 +0100 Subject: [PATCH 05/18] makefile crash if files dont exist in make clean, fixed --- slsReceiverSoftware/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 2a6303f93..c445eaa8c 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -79,8 +79,9 @@ mysocket_test: clean: buildclean make testclean - rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so - rm $(PROGS) + if test -e $(DESTDIR)/libSlsReceiver.a; then rm $(DESTDIR)/libSlsReceiver.a;fi + if test -e $(DESTDIR)/libSlsReceiver.so; then rm $(DESTDIR)/libSlsReceiver.so;fi + if test -e $(PROGS); then rm $(PROGS);fi builddir: if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi From 169c0a43cef9bcf1176315f475cf6eee6d363f92 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 8 Dec 2014 10:25:42 +0100 Subject: [PATCH 06/18] updating version numbers --- slsReceiverSoftware/gitInfo.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 410c414c3..d680dad1d 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8 -Revision: 22 -Branch: master -Last Changed Author: Anna_Bergamaschi -Last Changed Rev: 22 -Last Changed Date: 2014-10-15 09:22:40 +0200 +Repsitory UUID: 879c5e2ee129acfd70aba4ae6fab829cc5409350 +Revision: 67 +Branch: gemma +Last Changed Author: Maliakal_Dhanya +Last Changed Rev: 67 +Last Changed Date: 2014-12-08 09:17:56 +0100 From 76c9d2c61bd839d5126ac2400a2463a73ef760d5 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 14 Jan 2015 10:48:36 +0100 Subject: [PATCH 07/18] lot of couts and some pre and post --- .../src/UDPStandardImplementation.cpp | 118 ++++++++++-------- 1 file changed, 69 insertions(+), 49 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cb8d66c25..ca8715eda 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -864,8 +864,10 @@ void UDPStandardImplementation::setupFifoStructure(){ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data - if (guiData == NULL) + if (guiData == NULL){ guiData = latestData; + cout <<"gui data not null anymore" << endl; + } //copy data and filename strcpy(c,guiFileName); @@ -873,22 +875,22 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui fstartind = getStartFrameIndex(); //could not get gui data - if(!guiDataReady){ + if(!guiDataReady){cout<<"gui data not ready"<ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + cout<<"value:"<fnum)<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif +//#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; +//#endif } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif +//#endif //last dummy packet @@ -1890,8 +1910,8 @@ int loop; } - if(myDetectorType == EIGER) { - copyFrameToGui(wbuf,currframenum); + if(myDetectorType == EIGER) {cout<<"gonna copy frame"<push(wbuf[i])); #ifdef VERYDEBUG @@ -2001,7 +2021,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startAcquisitionIndex=startFrameIndex; currframenum = startAcquisitionIndex; acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread])); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif +//#endif } //reset mask and exit loop @@ -2108,9 +2128,9 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; int i,j; -#ifdef VERYDEBUG - cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; -#endif +//#ifdef VERYDEBUG + cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[0] << endl; +//#endif //free fifo for(i=0;i Date: Fri, 30 Jan 2015 10:58:30 +0100 Subject: [PATCH 08/18] unnecessary long wait in receiver --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ca8715eda..145ad5ca0 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1495,7 +1495,7 @@ int UDPStandardImplementation::startReceiver(char message[]){ for(i=0; i < numWriterThreads; ++i) sem_post(&writersmp[i]); - usleep(5000000); + //usleep(5000000); cout << "Receiver Started.\nStatus:" << status << endl; return OK; From f30833a4608e69e542b0a60e1213b1e331338e35 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 30 Jan 2015 15:03:35 +0100 Subject: [PATCH 09/18] got rid of unnecessary printouts in receiver --- slsReceiverSoftware/src/UDPBaseImplementation.cpp | 2 ++ slsReceiverSoftware/src/UDPStandardImplementation.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index de09ae694..1c6b1a976 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -203,7 +203,9 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEB } } FILE_LOG(logDEBUG) << __AT__ << getFilePath(); +#ifdef VERBOSE cout << getFilePath() << " " << filePath << endl; +#endif return getFilePath(); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0ac51c321..16b9de1f4 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1298,8 +1298,9 @@ int UDPStandardImplementation::createNewFile(){ else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); - +#ifdef VERBOSE cout << filePath << " + " << fileName << endl; +#endif //if filewrite and we are allowed to write if(enableFileWrite && cbAction > DO_NOTHING){ @@ -1632,9 +1633,9 @@ int UDPStandardImplementation::startListening(){ expected = maxBufferSize - carryonBufferSize; } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -//#endif +#endif //start indices for each start of scan/acquisition - eiger does it before From 7fd12f97b4b08b3192ecd4b8436a23d8360d76e7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 30 Jan 2015 16:49:30 +0100 Subject: [PATCH 10/18] some unnecessary printouts --- .../src/UDPBaseImplementation.cpp | 2 + .../src/UDPStandardImplementation.cpp | 48 +++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index de09ae694..1c6b1a976 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -203,7 +203,9 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEB } } FILE_LOG(logDEBUG) << __AT__ << getFilePath(); +#ifdef VERBOSE cout << getFilePath() << " " << filePath << endl; +#endif return getFilePath(); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 145ad5ca0..29843ff94 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -866,7 +866,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //point to gui data if (guiData == NULL){ guiData = latestData; - cout <<"gui data not null anymore" << endl; + //cout <<"gui data not null anymore" << endl; } //copy data and filename @@ -875,22 +875,26 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui fstartind = getStartFrameIndex(); //could not get gui data - if(!guiDataReady){cout<<"gui data not ready"< DO_NOTHING){ @@ -1645,7 +1653,7 @@ int UDPStandardImplementation::startListening(){ /* if(!ithread){*/ rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - cout<<"value:"<fnum)<fnum)<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); //#ifdef VERYDEBUG @@ -1855,11 +1863,11 @@ int loop; //#endif } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -//#endif +#endif //last dummy packet @@ -1910,8 +1918,10 @@ int loop; } - if(myDetectorType == EIGER) {cout<<"gonna copy frame"<push(wbuf[i])); #ifdef VERYDEBUG @@ -2080,9 +2090,9 @@ int i; cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; #endif while(!fifo[ithread]->push(buffer[ithread])); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -//#endif +#endif } //reset mask and exit loop @@ -2128,9 +2138,9 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; int i,j; -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[0] << endl; -//#endif +#endif //free fifo for(i=0;i Date: Wed, 4 Feb 2015 16:11:13 +0100 Subject: [PATCH 11/18] some code refraction to get rid of memeory leakage --- slsReceiverSoftware/include/genericSocket.h | 1 - .../src/UDPBaseImplementation.cpp | 7 ++-- .../src/UDPStandardImplementation.cpp | 40 +++++++++++-------- slsReceiverSoftware/src/main.cpp | 1 + .../src/slsReceiverTCPIPInterface.cpp | 11 ++--- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index a798a0fef..bbe119439 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -103,7 +103,6 @@ enum communicationProtocol{ nsent(0), total_sent(0)// sender (client): where to? ip { - // strcpy(hostname,host_ip_or_name); struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 1c6b1a976..7641a5a1e 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1328,8 +1328,8 @@ int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " s thread_started = 1; - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + int total; + int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; int imageheader = 0; @@ -1534,9 +1534,8 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i,j; + int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; -int loop; while(1){ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 16b9de1f4..a2ddd6e39 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -67,7 +67,6 @@ UDPStandardImplementation::UDPStandardImplementation() rawDataReadyCallBack = NULL; pRawDataReady = NULL; - initializeMembers(); //mutex pthread_mutex_init(&dataReadyMutex,NULL); @@ -75,6 +74,8 @@ UDPStandardImplementation::UDPStandardImplementation() pthread_mutex_init(&progress_mutex,NULL); pthread_mutex_init(&write_mutex,NULL); + initializeMembers(); + //to increase socket receiver buffer size and max length of input queue by changing kernel settings if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; @@ -1567,8 +1568,8 @@ int UDPStandardImplementation::startListening(){ thread_started = 1; - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + int total; + int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; int imageheader = 0; @@ -1750,6 +1751,8 @@ int UDPStandardImplementation::startListening(){ if(tempchar) {delete [] tempchar;tempchar = NULL;} pthread_exit(NULL); } + + if(tempchar) {delete [] tempchar;tempchar = NULL;} } return OK; @@ -1782,9 +1785,8 @@ int UDPStandardImplementation::startWriting(){ char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i,j; + int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; -int loop; while(1){ @@ -1792,17 +1794,17 @@ int loop; nf = 0; packetsPerThread = packetsPerFrame/numListeningThreads; if(myDetectorType == MOENCH){ - xmax = MOENCH_PIXELS_IN_ONE_ROW-1; - ymax = MOENCH_PIXELS_IN_ONE_ROW-1; - }else{ - if(shortFrame == -1){ + xmax = MOENCH_PIXELS_IN_ONE_ROW-1; + ymax = MOENCH_PIXELS_IN_ONE_ROW-1; + }else{ + if(shortFrame == -1){ xmax = GOTTHARD_PIXELS_IN_ROW-1; ymax = GOTTHARD_PIXELS_IN_COL-1; - }else{ - xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; - ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; - } + }else{ + xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; + ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; } + } @@ -1880,7 +1882,7 @@ int loop; for(i=0;ipush(wbuf[i])); #ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; + cout << ithread << ":" << i << " fifo freed:" << (void*)wbuf[i] << endl; #endif } @@ -1888,10 +1890,12 @@ int loop; } else{ //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); + if((packetsPerFrame * numpackets) == bufferSize){ + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; + cout << ithread << " finished copying" << endl; #endif + }//else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuf[0])); #ifdef VERYVERBOSE cout<<"buf freed:"<<(void*)wbuf[0]<push(buffer[ithread]); - else if(rc > 0){cout<< ithread << " last rc:"< 0){ pc = (rc/onePacketSize); #ifdef VERYDEBUG + cout << ithread << " last rc:"<stop(); } + delete user; cout << "Goodbye!" << endl; return 0; } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 20c95a051..b1fe40aca 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -26,7 +26,8 @@ using namespace std; slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { - if(socket) delete socket; + if(socket) {delete socket; socket=NULL;} + if(receiverBase) {delete receiverBase; receiverBase=NULL;} closeFile(0); } @@ -1221,8 +1222,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } //all adc else{ - //ignore if half frame is missing - if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){ + /*//ignore if half frame is missing + if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/ //should be same frame if (index == index2){ @@ -1239,11 +1240,11 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } }else cout << "different frames caught. frame1:"<< hex << index << ":"< Date: Tue, 10 Feb 2015 12:21:31 +0100 Subject: [PATCH 12/18] initializing variables and copying ot gui only full frames --- slsReceiverSoftware/include/genericSocket.h | 9 ++++++++- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index bbe119439..d6a102201 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -103,6 +103,10 @@ enum communicationProtocol{ nsent(0), total_sent(0)// sender (client): where to? ip { + memset(&serverAddress, 0, sizeof(sockaddr_in)); + memset(&clientAddress, 0, sizeof(sockaddr_in)); + // serverAddress = {0}; + // clientAddress = {0}; // strcpy(hostname,host_ip_or_name); struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ @@ -158,7 +162,10 @@ enum communicationProtocol{ nsent(0), total_sent(0) { - + memset(&serverAddress, 0, sizeof(sockaddr_in)); + memset(&clientAddress, 0, sizeof(sockaddr_in)); + // serverAddress = {0}; + // clientAddress = {0}; /* // you can specify an IP address: */ /* */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index a2ddd6e39..d97adf49a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1890,7 +1890,7 @@ int UDPStandardImplementation::startWriting(){ } else{ //copy to gui - if((packetsPerFrame * numpackets) == bufferSize){ + if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; From 1e55577fc2125a2a53f61625d862bdf04c0fa750 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 10 Feb 2015 16:54:39 +0100 Subject: [PATCH 13/18] no change --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b74f9c6cf..9f1b765fd 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1676,9 +1676,9 @@ int UDPStandardImplementation::startListening(){ expected = maxBufferSize - carryonBufferSize; } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif +//#endif //start indices for each start of scan/acquisition - eiger does it before From 6d8fcaa4230594f096985e3153008bf0dcc058e3 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 13 Feb 2015 11:58:36 +0100 Subject: [PATCH 14/18] debugging output change --- slsReceiverSoftware/include/genericSocket.h | 8 ++++---- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index d6a102201..a10e07649 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -103,8 +103,8 @@ enum communicationProtocol{ nsent(0), total_sent(0)// sender (client): where to? ip { - memset(&serverAddress, 0, sizeof(sockaddr_in)); - memset(&clientAddress, 0, sizeof(sockaddr_in)); + //memset(&serverAddress, 0, sizeof(sockaddr_in)); + //memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; // clientAddress = {0}; // strcpy(hostname,host_ip_or_name); @@ -162,8 +162,8 @@ enum communicationProtocol{ nsent(0), total_sent(0) { - memset(&serverAddress, 0, sizeof(sockaddr_in)); - memset(&clientAddress, 0, sizeof(sockaddr_in)); + //memset(&serverAddress, 0, sizeof(sockaddr_in)); + // memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; // clientAddress = {0}; /* // you can specify an IP address: */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 9f1b765fd..e7ee3fe22 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1564,7 +1564,7 @@ void UDPStandardImplementation::startReadout(){ //wait so that all packets which take time has arrived usleep(5000); /********************************************/ - //usleep(10000000); + //usleep(1000000); //usleep(2000000); pthread_mutex_lock(&status_mutex); @@ -1860,9 +1860,9 @@ int UDPStandardImplementation::startWriting(){ //cout<<"writer gonna pop from fifo:"<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; -//#endif +#endif } #ifdef VERYDEBUG @@ -2109,9 +2109,9 @@ int i; #endif pthread_mutex_unlock(&(status_mutex)); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; -//#endif +#endif //waiting for all listening threads to be done, to print final count of frames listened to if(ithread == 0){ From 651a13f811fd7c814bdc46918e409be7464f7f1d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 23 Feb 2015 15:25:06 +0100 Subject: [PATCH 15/18] so that gui can reread the same frame from receiver, guidataready is set to zero only once --- .../src/UDPStandardImplementation.cpp | 63 +++++++++++++------ .../src/slsReceiverTCPIPInterface.cpp | 18 +++--- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index e7ee3fe22..05e195208 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -867,7 +867,9 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //point to gui data if (guiData == NULL){ guiData = latestData; - //cout <<"gui data not null anymore" << endl; +#ifdef VERY_VERY_DEBUG + cout <<"gui data not null anymore" << endl; +#endif } //copy data and filename @@ -877,25 +879,33 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ - //cout<<"gui data not ready"<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); #ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; + cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; #endif } @@ -1874,10 +1887,15 @@ int UDPStandardImplementation::startWriting(){ //last dummy packet if(numpackets == 0xFFFF){ +#ifdef VERYDEBUG + cout << "LAST dummy packet" << endl; +#endif stopWriting(ithread,wbuf); continue; } - +#ifdef VERYDEBUG + else cout <<"NOT a dummy packet"< 0){ for(i=0;ipush(wbuf[i])); #ifdef VERYDEBUG @@ -2056,7 +2081,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ -void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){cout << "Stop Listening" << endl; +void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " called"; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index b1fe40aca..d98a7ddd7 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1336,9 +1336,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ if (raw == NULL){ arg = -1; -#ifdef VERBOSE +//#ifdef VERBOSE cout<<"data not ready for gui yet"< Date: Tue, 24 Feb 2015 16:19:33 +0100 Subject: [PATCH 16/18] moved start of frame to after stoplistening, for eiger to ignore incomplete frames --- .../src/UDPBaseImplementation.cpp | 1 + .../src/UDPStandardImplementation.cpp | 61 ++++++++++++------- .../src/slsReceiverTCPIPInterface.cpp | 12 ++-- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 7641a5a1e..9c6c26460 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -171,6 +171,7 @@ uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __A acquisitionIndex=-1; else acquisitionIndex = currframenum - startAcquisitionIndex; + //cout<<"acquisitionIndex:"< 0) && (!ithread)) startFrameIndices(ithread); - +*/ //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ @@ -1703,11 +1703,11 @@ int UDPStandardImplementation::startListening(){ continue; } -/* - //start indices for each start of scan/acquisition - eiger does it before +///* + //start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); -*/ +//*/ //reset packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; @@ -1884,17 +1884,16 @@ int UDPStandardImplementation::startWriting(){ cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; #endif - //last dummy packet if(numpackets == 0xFFFF){ #ifdef VERYDEBUG - cout << "LAST dummy packet" << endl; + cout << "**LAST dummy packet" << endl; #endif stopWriting(ithread,wbuf); continue; } #ifdef VERYDEBUG - else cout <<"NOT a dummy packet"<push(buffer[ithread]); exit(-1); } + //push the last buffer into fifo - if((myDetectorType == EIGER) && (rc < 266240) )//for eiger throw away incomplete frames - fifoFree[ithread]->push(buffer[ithread]); - else if(rc > 0){ - pc = (rc/onePacketSize); + if(rc > 0){ + //eiger (incomplete frames) - throw away + if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){ + if(rc == 266240) + cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl; + cout << ithread << "Discarding incomplete frame" << endl; + fifoFree[ithread]->push(buffer[ithread]); + } + //eiger (complete frames) + other detectors + else{ + pc = (rc/onePacketSize); #ifdef VERYDEBUG - cout << ithread << " last rc:"<push(buffer[ithread])); + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); #ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; + cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; #endif + } } + //free buffer + else{ + cout << ithread << "Discarding empty frame" << endl; + fifoFree[ithread]->push(buffer[ithread]); + } + //push dummy buffer to all writer threads @@ -2279,8 +2293,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num packetsInFile += packetsToSave; packetsCaught += packetsToSave; totalPacketsCaught += packetsToSave; - - +#ifdef VERYDEBUG + cout << "/totalPacketsCaught:" << dec << totalPacketsCaught <= maxPacketsPerFile){ //for packet loss diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index d98a7ddd7..8b0d52195 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1336,9 +1336,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ if (raw == NULL){ arg = -1; -//#ifdef VERBOSE +#ifdef VERBOSE cout<<"data not ready for gui yet"< Date: Wed, 25 Feb 2015 10:34:57 +0100 Subject: [PATCH 17/18] moved startframeindice to before stop listening for gotthard --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3fbba8a7e..7f8429d2f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1699,12 +1699,17 @@ int UDPStandardImplementation::startListening(){ //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ + if(myDetectorType != EIGER){ + //start indices for each start of scan/acquisition - this should be done earlier for normal detectors + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); + } stopListening(ithread,rc,packetcount,total); continue; } ///* - //start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames + //eiger - start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); //*/ From 2f824695313242f29d40f6d89f4f8eaeab7685c2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 5 Mar 2015 15:21:12 +0100 Subject: [PATCH 18/18] fifo debug with color done --- slsReceiverSoftware/include/ansi.h | 59 ++++++++++ .../include/sls_receiver_defs.h | 2 +- .../src/UDPBaseImplementation.cpp | 8 +- .../src/UDPStandardImplementation.cpp | 103 ++++++++++-------- 4 files changed, 124 insertions(+), 48 deletions(-) create mode 100644 slsReceiverSoftware/include/ansi.h diff --git a/slsReceiverSoftware/include/ansi.h b/slsReceiverSoftware/include/ansi.h new file mode 100644 index 000000000..1a24d403e --- /dev/null +++ b/slsReceiverSoftware/include/ansi.h @@ -0,0 +1,59 @@ +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define BLUE "\x1b[34m" +#define MAGENTA "\x1b[35m" +#define CYAN "\x1b[36m" +#define BG_RED "\x1b[41m" +#define BG_GREEN "\x1b[42m" +#define BG_YELLOW "\x1b[43m" +#define BG_BLUE "\x1b[44m" +#define BG_MAGENTA "\x1b[45m" +#define BG_CYAN "\x1b[46m" +#define RESET "\x1b[0m" +#define BOLD "\x1b[1m" + +#define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__) + +/* + +Code examples + +example 1 (a snippet): + + +#ifdef MARTIN + cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base); + for (i=0; i < buffer_len/4; i++) + cprintf(BLUE, "%.8X ",*(((unsigned *) buffer)+i)); + printf("\n"); +#endif + +#ifdef MARTIN + cprintf(CYAN, "LL Read - If: %X - Data: ",ll->ll_fifo_base); +#endif + + + +example 2: + +int main() +{ + int i=1; + printf("Normal %i\n", i); + cprintf(RED, "Red\n"); + cprintf(GREEN, "Green\n"); + cprintf(YELLOW, "Yellow\n"); + cprintf(BLUE, "Blue\n"); + cprintf(MAGENTA, "Mangenta %i\n", i); + cprintf(CYAN, "Cyan %i\n", i); + cprintf(BOLD, "White %i\n", i); + cprintf(RED BOLD, "Red %i\n", i); + cprintf(GREEN BOLD, "Green\n"); + cprintf(YELLOW BOLD, "Yellow\n"); + cprintf(BLUE BOLD, "Blue\n"); + cprintf(MAGENTA BOLD, "Mangenta %i\n", i); + cprintf(CYAN BOLD, "Cyan %i\n", i); +} + +*/ diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 7f39ff05d..7e3af64c2 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -8,7 +8,7 @@ #endif #include - +#include "ansi.h" typedef double double32_t; typedef float float32_t; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 9c6c26460..f12890aa2 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -374,12 +374,12 @@ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) < setupFifoStructure(); if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; + cprintf(BG_RED,"ERROR: Could not create listening thread\n"); exit (-1); } if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); exit (-1); } @@ -475,7 +475,7 @@ int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG numWriterThreads = 1; if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); return FAIL; } setThreadPriorities(); @@ -763,7 +763,7 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " iret = udpSocket[i]->getErrorStatus(); if(iret){ #ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; + cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n",server_port[i], iret); #endif return FAIL; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7f8429d2f..6f454ab57 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -322,12 +322,12 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD setupFifoStructure(); if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; + cprintf(BG_RED,"ERROR: Could not create listening thread\n"); exit (-1); } if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); exit (-1); } @@ -585,12 +585,12 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEB setupFifoStructure(); if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; + cprintf(BG_RED,"ERROR: Could not create listening thread\n"); exit (-1); } if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); exit (-1); } @@ -691,7 +691,7 @@ int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(log numWriterThreads = 1; if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); return FAIL; } setThreadPriorities(); @@ -830,6 +830,9 @@ void UDPStandardImplementation::setupFifoStructure(){ if(fifoFree[i]){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); +#ifdef FIFO_DEBUG + //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); +#endif delete fifoFree[i]; } if(fifo[i]) delete fifo[i]; @@ -849,6 +852,9 @@ void UDPStandardImplementation::setupFifoStructure(){ //push the addresses into freed fifoFree and writingFifoFree while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { fifoFree[i]->push(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); +#endif buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } } @@ -1017,7 +1023,7 @@ int UDPStandardImplementation::createUDPSockets(){ cout << "UDP port opened at port " << port[i] << endl; else{ #ifdef VERBOSE - cout << "Could not create UDP socket on port " << port[i] << " error:" << iret << endl; + cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); #endif return FAIL; } @@ -1349,11 +1355,11 @@ int UDPStandardImplementation::createNewFile(){ //open file if(!overwrite){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; + cprintf(BG_RED,"Error: Could not create new file %s\n",savefilename); return FAIL; } }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; + cprintf(BG_RED,"Error: Could not create file %s\n",savefilename); return FAIL; } //setting buffer @@ -1650,8 +1656,8 @@ int UDPStandardImplementation::startListening(){ #endif //pop fifoFree[ithread]->pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif @@ -1687,9 +1693,9 @@ int UDPStandardImplementation::startListening(){ expected = maxBufferSize - carryonBufferSize; } -#ifdef VERYDEBUG +//#ifdef VERDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif +//#endif /* //start indices for each start of scan/acquisition - eiger does it before @@ -1796,8 +1802,9 @@ int UDPStandardImplementation::startListening(){ cout<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; +#ifdef FIFO_DEBUG + //if(!ithread) + cprintf(RED, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif } @@ -1877,29 +1884,27 @@ int UDPStandardImplementation::startWriting(){ cout << "writer gonna pop from fifo:" << i << endl; #endif fifo[i]->pop(wbuf[i]); +#ifdef FIFO_DEBUG + cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); +#endif numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); #ifdef VERYDEBUG cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; #endif } -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif //last dummy packet if(numpackets == 0xFFFF){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << "**LAST dummy packet" << endl; -#endif +//#endif stopWriting(ithread,wbuf); continue; } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG else cout <<"**NOT a dummy packet"<push(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i << " fifo freed:" << (void*)wbuf[i] << endl; +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); #endif } @@ -1971,8 +1976,8 @@ int UDPStandardImplementation::startWriting(){ #endif }//else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif exit(-1); } @@ -2108,6 +2116,9 @@ int i; cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl; cout << ithread << "Discarding incomplete frame" << endl; fifoFree[ithread]->push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif } //eiger (complete frames) + other detectors else{ @@ -2119,8 +2130,8 @@ int i; (*((uint16_t*)(buffer[ithread]))) = pc; totalListeningFrameCount[ithread] += pc; while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; +#ifdef FIFO_DEBUG + cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } } @@ -2128,6 +2139,9 @@ int i; else{ cout << ithread << "Discarding empty frame" << endl; fifoFree[ithread]->push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); +#endif } @@ -2135,13 +2149,16 @@ int i; //push dummy buffer to all writer threads for(i=0;ipop(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; #ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; + cout << ithread << " dummy buffer num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; +#ifdef FIFO_DEBUG + cprintf(RED,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } @@ -2195,8 +2212,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif } @@ -2233,9 +2250,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ status = RUN_FINISHED; pthread_mutex_unlock(&(status_mutex)); //report - cout << "Status: Run Finished" << endl; - cout << "Total Packets Caught:" << dec << totalPacketsCaught << endl; - cout << "Total Frames Caught:"<< dec << (totalPacketsCaught/packetsPerFrame) << endl; + + cprintf(GREEN, "Status: Run Finished\n"); + cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); + cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); //acquisition end if (acquisitionFinishedCallBack) acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished); @@ -2442,16 +2460,15 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer remainingsize -= ((buff + ndata) - data); data = buff + ndata; if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]<