diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 8fe6bc361..f7a30909c 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -1,6 +1,7 @@ include ../Makefile.include DESTDIR ?= ../bin +LIBDIR ?= ../bin DOCDIR ?= docs SRCDIR = src INCDIR = include @@ -22,7 +23,7 @@ INCLUDES?= $(INCLUDESRXR) -I include/ -I ../slsDetectorCalibration LIBZMQDIR = include LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq -#-Iinclude -I../slsDetectorCalibration -I$(ASM) + SRC_CLNT = MySocketTCP.cpp ThreadObject.cpp Listener.cpp DataProcessor.cpp DataStreamer.cpp Fifo.cpp File.cpp BinaryFile.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp DEPSINCLUDES = $(INCDIR)/ansi.h $(INCDIR)/sls_receiver_defs.h $(INCDIR)/sls_receiver_funcs.h $(INCDIR)/GeneralData.h $(INCDIR)/circularFifo.h $(INCDIR)/genericSocket.h $(INCDIR)/logger.h $(INCDIR)/receiver_defs.h $(INCDIR)/UDPInterface.h $(INCDIR)/utilities.h $(INCDIR)/ZmqSocket.h $(INCDIR)/BinaryFileStatic.h $(INCDIR)/HDF5FileStatic.h @@ -38,7 +39,6 @@ endif MAIN_SRC = main.cpp -DUMMY_MAIN_SRC = dummyMain.cpp OBJS=$(SRC_CLNT:%.cpp=$(BUILDDIR)/%.o) @@ -90,7 +90,7 @@ $(DESTDIR)/slsReceiver: $(SRCDIR)/$(MAIN_SRC) $(DESTDIR)/libSlsReceiver.so $(D $(call colorecho,"#######################################") $(call colorecho,"# Compiling slsReceiver #") $(call colorecho,"#######################################") - $(CXX) -o $@ $(SRCDIR)/$(MAIN_SRC) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC $(LIBZMQ) -lrt + $(CXX) -o $@ $(SRCDIR)/$(MAIN_SRC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(LIBS) $(LDFLAGRXR) -fPIC $(LIBZMQ) -lrt #$(EIGERFLAGS) @@ -98,17 +98,10 @@ $(DESTDIR)/dummyReceiver: $(SRCDIR)/$(DUMMY_MAIN_SRC) $(DESTDIR)/libSlsReceiver $(call colorecho,"#######################################") $(call colorecho,"# Compiling Dummy slsReceiver #") $(call colorecho,"#######################################") - $(CXX) -o $@ $(SRCDIR)/$(DUMMY_MAIN_SRC) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC $(LIBZMQ) -lrt + $(CXX) -o $@ $(SRCDIR)/$(DUMMY_MAIN_SRC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(LIBS) $(LDFLAGRXR) -fPIC $(LIBZMQ) -lrt #$(EIGERFLAGS) -# Stand-alone Mysocket tests -mysocket_test: - g++ -o $(TESTDIR)/MySocketTCP.o -c $(SRCDIR)/MySocketTCP.cpp -I include - g++ -o $(TESTDIR)/rec $(TESTDIR)/MySocketTCP.o $(TESTDIR)/rec.cxx -I include - g++ -o $(TESTDIR)/send $(TESTDIR)/MySocketTCP.o $(TESTDIR)/send.cxx -I include - - clean: buildclean make testclean if test -e $(DESTDIR)/libSlsReceiver.a; then rm $(DESTDIR)/libSlsReceiver.a;fi diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 0cb5b10ab..e7cc9c3ff 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: 7d45ac53d7d92a4817002e7aed7297d5ddfd0f73 -Revision: 596 +Repsitory UUID: edef347a62cd0239115c76101154d94814c6916b +Revision: 597 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 601 -Last Changed Date: 2017-06-28 18:18:30 +0200 +Last Changed Rev: 602 +Last Changed Date: 2017-06-29 17:10:28 +0200 diff --git a/slsReceiverSoftware/include/BinaryFileStatic.h b/slsReceiverSoftware/include/BinaryFileStatic.h index b9b963e84..8e1c14569 100644 --- a/slsReceiverSoftware/include/BinaryFileStatic.h +++ b/slsReceiverSoftware/include/BinaryFileStatic.h @@ -117,12 +117,12 @@ class BinaryFileStatic { { if(!owenable){ if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ - cprintf(RED,"Error in creating binary master file %s\n",fname.c_str()); + bprintf(RED,"Error in creating binary master file %s\n",fname.c_str()); fd = 0; return 1; } }else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){ - cprintf(RED,"Error in creating binary master file %s\n",fname.c_str()); + bprintf(RED,"Error in creating binary master file %s\n",fname.c_str()); fd = 0; return 1; } @@ -166,7 +166,7 @@ class BinaryFileStatic { (long long int)acquisitionPeriod, ctime(&t)); if (strlen(message) > MAX_STR_LENGTH) { - cprintf(BG_RED,"Master File Size %d is greater than max str size %d\n", + bprintf(BG_RED,"Master File Size %d is greater than max str size %d\n", (int)strlen(message), MAX_STR_LENGTH); return 1; } diff --git a/slsReceiverSoftware/include/File.h b/slsReceiverSoftware/include/File.h index 6443de344..8092376bf 100644 --- a/slsReceiverSoftware/include/File.h +++ b/slsReceiverSoftware/include/File.h @@ -107,7 +107,7 @@ class File : private virtual slsReceiverDefs { * @returns OK or FAIL */ virtual int CreateFile(uint64_t fnum){ - cprintf(RED,"This is a generic function CreateFile that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function CreateFile that should be overloaded by a derived class\n"); return OK; } @@ -115,14 +115,14 @@ class File : private virtual slsReceiverDefs { * Close Current File */ virtual void CloseCurrentFile() { - cprintf(RED,"This is a generic function CloseCurrentFile that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function CloseCurrentFile that should be overloaded by a derived class\n"); } /** * Close Files */ virtual void CloseAllFiles() { - cprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); } /** @@ -133,7 +133,7 @@ class File : private virtual slsReceiverDefs { * @param OK or FAIL */ virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) { - cprintf(RED,"This is a generic function WriteToFile that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function WriteToFile that should be overloaded by a derived class\n"); return FAIL; } @@ -149,7 +149,7 @@ class File : private virtual slsReceiverDefs { */ virtual int CreateMasterFile(bool en, uint32_t size, uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) { - cprintf(RED,"This is a generic function CreateMasterFile that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function CreateMasterFile that should be overloaded by a derived class\n"); return OK; } @@ -160,7 +160,7 @@ class File : private virtual slsReceiverDefs { * @param ny number of pixels in y direction */ virtual void SetNumberofPixels(uint32_t nx, uint32_t ny) { - cprintf(RED,"This is a generic function SetNumberofPixels that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function SetNumberofPixels that should be overloaded by a derived class\n"); } /** @@ -168,7 +168,7 @@ class File : private virtual slsReceiverDefs { * @param numf number of images caught */ virtual void EndofAcquisition(uint64_t numf) { - cprintf(RED,"This is a generic function EndofAcquisition that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function EndofAcquisition that should be overloaded by a derived class\n"); } protected: diff --git a/slsReceiverSoftware/include/GeneralData.h b/slsReceiverSoftware/include/GeneralData.h index c445ed4d8..c276ffe17 100644 --- a/slsReceiverSoftware/include/GeneralData.h +++ b/slsReceiverSoftware/include/GeneralData.h @@ -151,7 +151,7 @@ public: * @param tgEnable true if 10GbE is enabled, else false */ virtual void SetDynamicRange(int dr, bool tgEnable) { - cprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); }; /** @@ -160,58 +160,35 @@ public: * @param dr dynamic range */ virtual void SetTenGigaEnable(bool tgEnable, int dr) { - cprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); + bprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); }; /** * Print all variables */ virtual void Print() const { - std::string temp = slsReceiverDefs::getDetectorType(myDetectorType); - printf("\n\nDetector Data Variables:\n"); - printf( "myDetectorType:%s\n" - "Pixels X: %u\n" - "Pixels Y: %u\n" - "Empty Header: %u\n" - "Header Size in Packet: %u\n" - "Data Size: %u\n" - "Packet Size: %u\n" - "Packets per Frame: %u\n" - "Image Size: %u\n" - "Frame Index Mask: 0x%llx\n" - "Frame Index Offset: %u\n" - "Packet Index Mask: 0x%x\n" - "Packet Index Offset: %u\n" - "Max Frames Per File: %u\n" - "Fifo Buffer Header Size: %u\n" - "Default Fifo Depth: %u\n" - "Threads Per Receiver: %u\n" - "Header Packet Size: %u\n" - "Streamer Pixels X: %u\n" - "Streamer Pixels Y: %u\n" - "Streamer Image Size: %u\n" - - ,temp.c_str(),//.c_str() modifies, using temp string for thread safety - nPixelsX, - nPixelsY, - emptyHeader, - headerSizeinPacket, - dataSize, - packetSize, - packetsPerFrame, - imageSize, - (long long int)frameIndexMask, - frameIndexOffset, - packetIndexMask, - packetIndexOffset, - maxFramesPerFile, - fifoBufferHeaderSize, - defaultFifoDepth, - threadsPerReceiver, - headerPacketSize, - nPixelsX_Streamer, - nPixelsY_Streamer, - imageSize_Streamer); + FILE_LOG(logDEBUG) << "\n\nDetector Data Variables:"; + FILE_LOG(logDEBUG) << "myDetectorType: " << slsReceiverDefs::getDetectorType(myDetectorType); + FILE_LOG(logDEBUG) << "Pixels X: " << nPixelsX; + FILE_LOG(logDEBUG) << "Pixels Y: " << nPixelsY; + FILE_LOG(logDEBUG) << "Empty Header: " << emptyHeader; + FILE_LOG(logDEBUG) << "Header Size in Packet: " << headerSizeinPacket; + FILE_LOG(logDEBUG) << "Data Size: " << dataSize; + FILE_LOG(logDEBUG) << "Packet Size: " << packetSize; + FILE_LOG(logDEBUG) << "Packets per Frame: " << packetsPerFrame; + FILE_LOG(logDEBUG) << "Image Size: " << imageSize; + FILE_LOG(logDEBUG) << "Frame Index Mask: " << frameIndexMask; + FILE_LOG(logDEBUG) << "Frame Index Offset: " << frameIndexOffset; + FILE_LOG(logDEBUG) << "Packet Index Mask: " << packetIndexMask; + FILE_LOG(logDEBUG) << "Packet Index Offset: " << packetIndexOffset; + FILE_LOG(logDEBUG) << "Max Frames Per File: " << maxFramesPerFile; + FILE_LOG(logDEBUG) << "Fifo Buffer Header Size: " << fifoBufferHeaderSize; + FILE_LOG(logDEBUG) << "Default Fifo Depth: " << defaultFifoDepth; + FILE_LOG(logDEBUG) << "Threads Per Receiver: " << threadsPerReceiver; + FILE_LOG(logDEBUG) << "Header Packet Size: " << headerPacketSize; + FILE_LOG(logDEBUG) << "Streamer Pixels X: " << nPixelsX_Streamer; + FILE_LOG(logDEBUG) << "Streamer Pixels Y: " << nPixelsY_Streamer; + FILE_LOG(logDEBUG) << "Streamer Image Size: " << imageSize_Streamer; }; }; @@ -365,7 +342,7 @@ class Moench02Data : public GeneralData { */ void Print() const { GeneralData::Print(); - printf("Bytes Per Adc: %d\n",bytesPerAdc); + FILE_LOG(logINFO) << "Bytes Per Adc: " << bytesPerAdc; } }; @@ -427,7 +404,7 @@ class JCTBData : public GeneralData { */ void Print() const { GeneralData::Print(); - printf("Bytes Per Adc: %d\n",bytesPerAdc); + FILE_LOG(logINFO) << "Bytes Per Adc: " << bytesPerAdc; } }; diff --git a/slsReceiverSoftware/include/HDF5FileStatic.h b/slsReceiverSoftware/include/HDF5FileStatic.h index ba8d7ba62..0a13429bd 100644 --- a/slsReceiverSoftware/include/HDF5FileStatic.h +++ b/slsReceiverSoftware/include/HDF5FileStatic.h @@ -110,7 +110,7 @@ public: fd = 0; } } catch(Exception error) { - cprintf(RED,"Error in closing HDF5 handles of index %d\n", ind); + bprintf(RED,"Error in closing HDF5 handles of index %d\n", ind); error.printError(); } } @@ -128,7 +128,7 @@ public: fd = 0; } } catch(Exception error) { - cprintf(RED,"Error in closing master HDF5 handles\n"); + bprintf(RED,"Error in closing master HDF5 handles\n"); error.printError(); } } @@ -142,7 +142,7 @@ public: { if(fd) { if (H5Fclose(fd) < 0 ) - cprintf(RED,"Error in closing virtual HDF5 handles\n"); + bprintf(RED,"Error in closing virtual HDF5 handles\n"); fd = 0; } } @@ -175,7 +175,7 @@ public: memspace.close(); } catch(Exception error){ - cprintf(RED,"Error in writing to file in object %d\n",ind); + bprintf(RED,"Error in writing to file in object %d\n",ind); error.printError(); return 1; } @@ -211,7 +211,7 @@ public: dset_para[12]->write(&header->version, ParameterDataTypes[12], memspace, *dspace_para); } catch(Exception error){ - cprintf(RED,"Error in writing parameters to file in object %d\n",ind); + bprintf(RED,"Error in writing parameters to file in object %d\n",ind); error.printError(); return 1; } @@ -319,7 +319,7 @@ public: fd->close(); } catch(Exception error) { - cprintf(RED,"Error in creating master HDF5 handles\n"); + bprintf(RED,"Error in creating master HDF5 handles\n"); error.printError(); return 1; } @@ -403,7 +403,7 @@ public: dset_para[i] = new DataSet(fd->createDataSet(ParameterNames[i], ParameterDataTypes[i], *dspace_para)); } catch(Exception error){ - cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind); + bprintf(RED,"Error in creating HDF5 handles in object %d\n",ind); error.printError(); fd->close(); return 1; @@ -449,7 +449,7 @@ public: { //virtual names string virtualFileName = CreateVirtualFileName(fpath, fnameprefix, findex); - printf("Virtual File: %s\n", virtualFileName.c_str()); + FILE_LOG(logINFO) << "Virtual File: " << virtualFileName; //file hid_t dfal = H5Pcreate (H5P_FILE_ACCESS); @@ -519,12 +519,12 @@ public: //setect hyperslabs if (H5Sselect_hyperslab (vdsDataspace, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) { - cprintf(RED,"could not select hyperslab\n"); + bprintf(RED,"could not select hyperslab\n"); error = true; break; } if (H5Sselect_hyperslab (vdsDataspace_para, H5S_SELECT_SET, offset_para, NULL, count_para, NULL) < 0) { - cprintf(RED,"could not select hyperslab for parameters\n"); + bprintf(RED,"could not select hyperslab for parameters\n"); error = true; break; } @@ -551,14 +551,14 @@ public: //mapping if (H5Pset_virtual(dcpl, vdsDataspace, srcFileName.c_str(), srcDatasetName.c_str(), srcDataspace) < 0) { - cprintf(RED,"could not set mapping for paramter 1\n"); + bprintf(RED,"could not set mapping for paramter 1\n"); error = true; break; } for (int k = 0; k < NumberofParameters; ++k) { if (H5Pset_virtual(dcpl_para[k], vdsDataspace_para, srcFileName.c_str(), ParameterNames[k], srcDataspace_para) < 0) { - cprintf(RED,"could not set mapping for paramter %d\n", k); + bprintf(RED,"could not set mapping for paramter %d\n", k); error = true; break; } @@ -631,39 +631,30 @@ public: data_out = (T*)malloc(sizeof(T)*(nDimx*nDimy*nDimz)); break; default: - cprintf(RED,"invalid rank. Options: 2 or 3\n"); + bprintf(RED,"invalid rank. Options: 2 or 3\n"); return 0; } if (datatype == PredType::STD_U16LE) { - printf("datatype:16\n"); + FILE_LOG(logINFO) << "datatype:16"; } else if (datatype == PredType::STD_U32LE) { - printf("datatype:32\n"); + FILE_LOG(logINFO) << "datatype:32"; } else if (datatype == PredType::STD_U64LE) { - printf("datatype:64\n"); + FILE_LOG(logINFO) << "datatype:64"; } else if (datatype == PredType::STD_U8LE) { - printf("datatype:8\n"); + FILE_LOG(logINFO) << "datatype:8"; } else { - cprintf(RED, "unknown datatype\n"); + FILE_LOG(logERROR) << "unknown datatype"; return 1; } - printf("owenable:%d\n" - "oldFileName:%s\n" - "oldDatasetName:%s\n" - "newFileName:%s\n" - "newDatasetName:%s\n" - "rank:%d\n" - "nDimx:%llu\n" - "nDimy:%u\n" - "nDimz:%u\n", - owenable?1:0, - oldFileName.c_str(), - oldDatasetName.c_str(), - newFileName.c_str(), - newDatasetName.c_str(), - rank, - (long long unsigned int)nDimx, - nDimy, - nDimz); + FILE_LOG(logINFO) << "owenable:" << owenable?1:0 << endl + << "oldFileName:" << oldFileName << endl + << "oldDatasetName:" << oldDatasetName << endl + << "newFileName:" << newFileName << endl + << "newDatasetName:" << newDatasetName << endl + << "rank:" << rank << endl + << "nDimx:" << nDimx << endl + << "nDimy:" << nDimy << endl + << "nDimz:" << nDimz; H5File* oldfd; H5File* newfd; @@ -697,7 +688,7 @@ public: newfd->close(); oldfd->close(); } catch(Exception error){ - cprintf(RED,"Error in copying virtual files\n"); + bprintf(RED,"Error in copying virtual files\n"); error.printError(); free(data_out); oldfd->close(); @@ -781,7 +772,7 @@ public: * @returns 1 for fail */ static int CloseFileOnError(hid_t& fd, const string msg) { - cprintf(RED, "%s", msg.c_str()); + bprintf(RED, "%s", msg.c_str()); if(fd > 0) H5Fclose(fd); fd = 0; @@ -804,7 +795,7 @@ public: else if (dtype == PredType::STD_U64LE) return H5T_STD_U64LE; else { - cprintf(RED, "Invalid Data type\n"); + bprintf(RED, "Invalid Data type\n"); return H5T_STD_U64LE; } } diff --git a/slsReceiverSoftware/include/ZmqSocket.h b/slsReceiverSoftware/include/ZmqSocket.h index 7fdb51c51..580dd50f0 100644 --- a/slsReceiverSoftware/include/ZmqSocket.h +++ b/slsReceiverSoftware/include/ZmqSocket.h @@ -243,7 +243,7 @@ public: detType, version); #ifdef VERBOSE //if(!index) - printf("%d Streamer: buf:%s\n", index, buf); + FILE_LOG(logINFO) << index << ": Streamer: buf:" << buf; #endif if(zmq_send (socketDescriptor, buf, length, dummy?0:ZMQ_SNDMORE) < 0) { diff --git a/slsReceiverSoftware/include/ansi.h b/slsReceiverSoftware/include/ansi.h index c28be61d4..bf76b4403 100644 --- a/slsReceiverSoftware/include/ansi.h +++ b/slsReceiverSoftware/include/ansi.h @@ -6,6 +6,8 @@ #define CYAN "\x1b[36m" #define GRAY "\x1b[37m" #define DARKGRAY "\x1b[30m" + +#define BG_BLACK "\x1b[48;5;232m" #define BG_RED "\x1b[41m" #define BG_GREEN "\x1b[42m" #define BG_YELLOW "\x1b[43m" @@ -15,8 +17,10 @@ #define RESET "\x1b[0m" #define BOLD "\x1b[1m" +//on background black +#define bprintf(code, format, ...) printf(code BG_BLACK format RESET, ##__VA_ARGS__) +//normal printout #define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__) - /* Code examples diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index a44d6d111..ab00444c9 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -70,11 +70,8 @@ int CircularFifo::getSemValue() template bool CircularFifo::push(Element*& item_) { - - //cout<<"*head:"<::push(Element*& item_) template bool CircularFifo::pop(Element*& item_) { - //cout<<"-tail:"<getFileName(); - * .... - * delete[] c; - * - * always: 1:YES 0:NO for int as bool-like arguments - * - */ - - public: - - /** - * Destructor - */ - dummyUDPInterface() : UDPInterface(), dynamicRange(16), scanTag(1000), nFrames(100), fWrite(1), fOverwrite(1), fIndex(0), fCaught(0), totfCaught(0), startAcqIndex(0), startFrameIndex(0), acqIndex(0), dataCompression(false), period(0), type(slsReceiverDefs::GENERIC), framesNeeded(100), udpPort1(1900), udpPort2(1901), shortFrame(0), nFramesToGui(0), e10G(0) {strcpy(detHostname,"none"); strcpy(fName,"run"); strcpy(fPath,"/scratch/"); strcpy(eth,"eth0"); cout << "New dummy UDP Interface" << endl; - - - - -}; - - ~dummyUDPInterface() {cout << "Destroying dummy UDP Interface" << endl;}; - - - void del(){cout << "Destroying dummy UDP Interface" << endl;}; - - virtual void configure(map config_map) {}; - /** - * Initialize the Receiver - @param detectorHostName detector hostname - * you can call this function only once. You must call it before you call startReceiver() for the first time. - */ - virtual void initialize(const char *detectorHostName){ cout << "set detector hostname to" << detHostname << endl; strcpy(detHostname,detectorHostName);}; - - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - virtual char *getDetectorHostname() const { cout << "get detector hostname " << detHostname << endl; return (char*) detHostname;}; - - /** - * Returns status of receiver: idle, running or error - */ - virtual slsReceiverDefs::runStatus getStatus() const { cout << "get dsummy status IDLE " << endl; return slsReceiverDefs::IDLE;};; - - /** - * Returns File Name - * caller is responsible to deallocate the returned char array. - */ - virtual char *getFileName() const { cout << "get file name " << fName << endl; return (char*) fName;}; - - - /** - * Returns File Path - * caller is responsible to deallocate the returned char array - */ - virtual char *getFilePath() const { cout << "get file path " << fPath << endl; return (char*) fPath;};; - - - /** - * Returns the number of bits per pixel - */ - virtual int getDynamicRange() const { cout << "get dynamic range " << dynamicRange << endl; return dynamicRange;};; - - /** - * Returns scan tag - */ - virtual int getScanTag() const { cout << "get scan tag " << scanTag << endl; return scanTag;}; - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - virtual int getNumberOfFrames() const { cout << "get number of frames " << nFrames << endl; return nFrames;}; - - /** - * Returns file write enable - * 1: YES 0: NO - */ - virtual int getEnableFileWrite() const { cout << "get enable file write " << fWrite << endl; return fWrite;}; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - virtual int getEnableOverwrite() const { cout << "get enable file overwrite " << fOverwrite << endl; return fOverwrite;}; - - /** - * Set File Name (without frame index, file index and extension) - @param c file name - /returns file name - * returns NULL on failure (like bad file name) - * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. - * caller is responsible to deallocate the returned char array. - */ - virtual char* setFileName(const char c[]) { strcpy(fName,c); cout << "set file name " << fName << endl; return fName; }; - - /** - * Set File Path - @param c file path - /returns file path - * checks the existence of the directory. returns NULL if directory does not exist or is not readable. - * caller is responsible to deallocate the returned char array. - */ - virtual char* setFilePath(const char c[]) { strcpy(fPath,c); cout << "set file path " << fPath << endl; return fPath; }; - - /** - * Returns the number of bits per pixel - @param dr sets dynamic range - /returns dynamic range - * returns -1 on failure - * FIXME: what are the allowd values - should we use an enum as argument? - */ - virtual int setDynamicRange(const int dr) {dynamicRange=dr; cout << "set dynamic range " << dynamicRange << endl; return dynamicRange; }; - - - /** - * Set scan tag - @param tag scan tag - /returns scan tag (always non-negative) - * FIXME: valid range - only positive? 16bit ore 32bit? - * returns -1 on failure - */ - virtual int setScanTag(const int tag) {scanTag=tag; cout << "set scan tag " << scanTag << endl; return scanTag; }; - - - /** - * Sets number of frames - @param fnum number of frames - /returns number of frames - */ - virtual int setNumberOfFrames(const int fnum) {nFrames=fnum; cout << "set number of frames " << nFrames << endl; return nFrames; }; - - - /** - * Set enable file write - * @param i file write enable - /returns file write enable - */ - virtual int setEnableFileWrite(const int i) {fWrite=i; cout << "set enable file write " << fWrite << endl; return fWrite; }; - - - /** - * Set enable file overwrite - * @param i file overwrite enable - /returns file overwrite enable - */ - virtual int setEnableOverwrite(const int i) {fOverwrite=i; cout << "set enable file overwrite " << fOverwrite << endl; return fOverwrite; }; - - - /** - * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets - @param message is the error message if there is an error - /returns 0 on success or -1 on failure - */ - //FIXME: success == 0 or success == 1? - virtual int startReceiver(char *message=NULL) {cout << "dummy start receiver" << endl; - char buff[8225]; - buff[8224]='\0'; - int ip=0; - int ib; - genericSocket *udpSocket= new genericSocket(50004,genericSocket::UDP,8224); - while((ib=udpSocket->ReceiveDataOnly(buff,8224))>0) { - cout << "*** "<< ib <<" ************************** " << ip++ << endl; - cout << buff << endl; - cout << "*****************************" << endl << endl<< endl ; - } -return 0;}; - - /** - * Stops Receiver - stops listening for packets - /returns success - * same as abort(). Always returns 0. - */ - virtual int stopReceiver() {cout << "dummy stop receiver" << endl; return 0;}; - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - virtual void abort() {cout << "Aborting receiver" << endl; }; - - - -/******************************************************************************************************************* - **************************************** Added by Dhanya ********************************************************* - *******************************************************************************************************************/ - - /** - * Returns File Index - */ - virtual int getFileIndex() {cout << "get file index " << fIndex << endl; return fIndex;}; - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - virtual int getTotalFramesCaught() {cout << "get total frames caught " << totfCaught << endl ; return totfCaught;}; - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - virtual int getFramesCaught() {cout << "get frames caught " << fCaught << endl; return fCaught;}; - - - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - virtual uint32_t getStartAcquisitionIndex(){ cout << "get start acquisition index " << startAcqIndex << endl; return startAcqIndex; }; - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - virtual uint32_t getAcquisitionIndex(){ cout << "get acquisition index " << acqIndex << endl; return acqIndex; }; - - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - virtual uint32_t getStartFrameIndex() { cout << "get start frame index " << startFrameIndex << endl; return startFrameIndex; }; - - - /** get data compression, by saving only hits - */ - virtual bool getDataCompression() { cout << "get data compression " << dataCompression << endl; return dataCompression;}; - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - virtual int setDetectorType(slsReceiverDefs::detectorType det) {type=det; cout << "set detector type " << det << endl; return slsReceiverDefs::OK;}; - - /** - * Set File Index - * @param i file index - */ - virtual int setFileIndex(int i) {fIndex=i; cout << "get file index " << fIndex << endl; return fIndex;}; - - /** set acquisition period if a positive number - */ - virtual int64_t setAcquisitionPeriod(int64_t index) {if (index>=0) {period=index; cout << "set period " << period << endl;} else { cout << "get period " << period << endl;} return period;}; - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - virtual int setFrameIndexNeeded(int i) {framesNeeded=i; cout << "set frame index needed " << period << endl; return framesNeeded;}; - - /** - * Set UDP Port Number - */ - virtual void setUDPPortNo(int p){udpPort1=p; cout << "set UDP port 1 " << udpPort1 << endl; }; - - - /** - * Set UDP Port Number - */ - virtual void setUDPPortNo2(int p) {udpPort2=p; cout << "set UDP port 2 " << udpPort2 << endl; }; - - /** - * Set Ethernet Interface or IP to listen to - */ - virtual void setEthernetInterface(char* c){strcpy(eth,c); cout << "set eth " << c;}; - - /** - * Set short frame - * @param i if shortframe i=1 - */ - virtual int setShortFrame(int i){shortFrame=i; cout << " set short frame" << shortFrame << endl; return shortFrame;}; - - /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request - */ - virtual int setNFrameToGui(int i) {nFramesToGui=i; cout << "set nframes to gui " << nFramesToGui << endl; return nFramesToGui;}; - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - virtual void resetTotalFramesCaught() {totfCaught=0; cout << "total frames caugh reset " << totfCaught << endl;}; - - /** enabl data compression, by saving only hits - /returns if failed - */ - virtual int enableDataCompression(bool enable) {dataCompression=enable; cout << "set data compression " << dataCompression<< endl; return dataCompression;}; - - /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe - */ - virtual int enableTenGiga(int enable = -1) {if (enable>=0) {e10G=enable; cout << "set 10Gb "<< e10G << endl;} else cout << "get 10Gb "<< e10G << endl; return e10G;}; - - /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan - */ - virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){cout << "dummy read frame" << endl; }; - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished - */ - virtual void startReadout(){cout << "dummy start readout" << endl; }; - - /** - * shuts down the udp sockets - * \returns if success or fail - */ - virtual int shutDownUDPSockets(){cout << "dummy shut down udp sockets" << endl; return slsReceiverDefs::OK;}; - - /** - * Closes all files - * @param ithr thread index, -1 for all threads - */ - virtual void closeFile(int ithr = -1){cout << "dummy close file" << ithr << endl; }; - - /** - * Call back for start acquisition - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){cout << "dummy register callback start acquisition" << endl; }; - - /** - * Call back for acquisition finished - callback argument is - total frames caught - */ - virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){cout << "dummy register callback acquisition finished" << endl; }; - - /** - * Call back for raw data - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ -virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){cout << "dummy register callback get raw data" << endl; }; - - protected: - - private: - char detHostname[1000]; - char fName[10000]; - char fPath[10000]; - int dynamicRange; - int scanTag; - int nFrames; - int fWrite; - int fOverwrite; - - int fIndex; - int fCaught; -int totfCaught; -int startAcqIndex; -int startFrameIndex; -int acqIndex; -bool dataCompression; - int64_t period; - slsReceiverDefs::detectorType type; - int framesNeeded; - int udpPort1; - int udpPort2; - char eth[1000]; - int shortFrame; - int nFramesToGui; - int e10G; -}; - diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index fd4c8da75..0250f91dd 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -313,7 +313,7 @@ enum communicationProtocol{ /** @short etablishes connection; disconnect should always follow \returns 1 if error */ - int Connect(){//cout<<"connect"<0) return file_des; if (protocol==UDP) return -1; @@ -458,7 +458,6 @@ enum communicationProtocol{ if (ts<=0) return -1; - //cout << "socketdescriptor "<< socketDescriptor << endl; struct timeval tout; tout.tv_sec = 0; tout.tv_usec = 0; @@ -612,7 +611,7 @@ enum communicationProtocol{ continue; if(nsent != nsending){ if(nsent && (nsent != -1)) - cprintf(RED,"Incomplete Packet size %d\n",nsent); + bprintf(RED,"Incomplete Packet size %d\n",nsent); break; } length-=nsent; @@ -625,7 +624,7 @@ enum communicationProtocol{ nsending=packet_size; while(1){ #ifdef VERYVERBOSE - cprintf(BLUE,"%d gonna listen\n", portno); fflush(stdout); + bprintf(BLUE,"%d gonna listen\n", portno); fflush(stdout); #endif nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); //break out of loop only if read one packets size or read didnt work (cuz of shutdown) @@ -633,7 +632,7 @@ enum communicationProtocol{ break; //incomplete packets or header packets ignored and read buffer again if(nsent != packet_size && nsent != header_packet_size) - cprintf(RED,"Incomplete Packet size %d\n",nsent); + bprintf(RED,"Incomplete Packet size %d\n",nsent); } //nsent = 1040; total_sent+=nsent; diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 699b3cd33..38af1f1eb 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "7d45ac53d7d92a4817002e7aed7297d5ddfd0f73" -//#define SVNREV 0x601 +#define SVNREPUUID "edef347a62cd0239115c76101154d94814c6916b" +//#define SVNREV 0x602 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x601 -#define SVNDATE 0x20170628 +#define SVNREV 0x602 +#define SVNDATE 0x20170629 // diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index 61b3141a7..8331a19e6 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -32,13 +32,8 @@ ) #define __SHORT_AT__ string(__SHORT_FORM_OF_FILE__) + string("::") + string(__func__) + string("(): ") -//":" TOSTRING(__LINE__) -/* -void error(const char *location, const char *msg){ - printf("Error at %s: %s\n", location, msg); -} -*/ + inline std::string NowTime(); @@ -223,10 +218,10 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level) return; bool out = true; switch(level){ - case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break; - case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break; - case logINFO: cprintf(GRAY,"%s",msg.c_str()); break; - // case logINFO: cprintf(DARKGRAY BOLD,"%s",msg.c_str());break; + case logERROR: bprintf(RED BOLD,"%s",msg.c_str()); break; + case logWARNING: bprintf(YELLOW BOLD,"%s",msg.c_str()); break; + case logINFO: bprintf(GRAY,"%s",msg.c_str()); break; + // case logINFO: bprintf(DARKGRAY BOLD,"%s",msg.c_str());break; default: fprintf(pStream,"%s",msg.c_str()); out = false; break; } fflush(out ? stdout : pStream); diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index fdc304b60..9e18522b9 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -35,8 +35,8 @@ BinaryFile::~BinaryFile() { void BinaryFile::PrintMembers() { File::PrintMembers(); - printf("Max Frames Per File: %d\n",maxFramesPerFile); - printf("Number of Frames in File: %d\n",numFramesInFile); + FILE_LOG(logINFO) << "Max Frames Per File: " << maxFramesPerFile; + FILE_LOG(logINFO) << "Number of Frames in File: " << numFramesInFile; } slsReceiverDefs::fileFormat BinaryFile::GetFileType() { @@ -61,14 +61,14 @@ int BinaryFile::CreateFile(uint64_t fnum) { //first file, print entrire path if (loss == -1) - printf("[%u]: Binary File created: %s\n", *udpPortNumber, currentFileName.c_str()); + FILE_LOG(logINFO) << "[" << *udpPortNumber << "]: Binary File created: " << currentFileName; //other files else { if (loss) - cprintf(RED,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", + bprintf(RED,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", *udpPortNumber,loss, fifo->GetMaxLevelForFifoBound() , basename(currentFileName.c_str())); else - cprintf(GREEN,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", + bprintf(GREEN,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", *udpPortNumber,loss, fifo->GetMaxLevelForFifoBound(), basename(currentFileName.c_str())); } @@ -94,7 +94,7 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_ numActualPacketsInFile += nump; if (BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize) return OK; - cprintf(RED,"%d Error: Write to file failed for image number %lld\n", index, (long long int)fnum); + bprintf(RED,"%d Error: Write to file failed for image number %lld\n", index, (long long int)fnum); return FAIL; } @@ -107,7 +107,7 @@ int BinaryFile::CreateMasterFile(bool en, uint32_t size, if (master && (*detIndex==0)) { masterFileName = BinaryFileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); - printf("Master File: %s\n", masterFileName.c_str()); + FILE_LOG(logINFO) << "Master File: " << masterFileName; return BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName, *overWriteEnable, *dynamicRange, en, size, nx, ny, *numImages, at, ap, BINARY_WRITER_VERSION); diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index b6d62e9c0..13d83ca4e 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -168,7 +168,7 @@ void DataProcessor::RecordFirstIndices(uint64_t fnum) { } #ifdef VERBOSE - cprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n", + bprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n", index, (long long int)firstAcquisitionIndex, (long long int)firstMeasurementIndex); #endif } @@ -270,13 +270,13 @@ void DataProcessor::ThreadExecution() { char* buffer=0; fifo->PopAddress(buffer); #ifdef FIFODEBUG - if (!index) cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); + if (!index) bprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); #endif //check dummy uint32_t numBytes = (uint32_t)(*((uint32_t*)buffer)); #ifdef VERBOSE - if (!index) cprintf(BLUE,"DataProcessor %d, Numbytes:%u\n", index,numBytes); + if (!index) bprintf(BLUE,"DataProcessor %d, Numbytes:%u\n", index,numBytes); #endif if (numBytes == DUMMY_PACKET_VALUE) { StopProcessing(buffer); @@ -297,7 +297,7 @@ void DataProcessor::ThreadExecution() { void DataProcessor::StopProcessing(char* buf) { #ifdef VERBOSE if (!index) - cprintf(RED,"DataProcessing %d: Dummy\n", index); + bprintf(RED,"DataProcessing %d: Dummy\n", index); #endif //stream or free if (*dataStreamEnable) @@ -308,7 +308,7 @@ void DataProcessor::StopProcessing(char* buf) { file->CloseCurrentFile(); StopRunning(); #ifdef VERBOSE - printf("%d: Processing Completed\n", index); + FILE_LOG(logINFO) << index << ": Processing Completed"; #endif } @@ -326,12 +326,12 @@ void DataProcessor::ProcessAnImage(char* buf) { #ifdef VERBOSE if (!index) - cprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum); + bprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum); #endif if (!measurementStartedFlag) { #ifdef VERBOSE - if (!index) cprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum); + if (!index) bprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum); #endif RecordFirstIndices(fnum); } diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 29436023b..8b5be959c 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -135,7 +135,7 @@ void DataStreamer::RecordFirstIndices(uint64_t fnum) { } #ifdef VERBOSE - cprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n", + bprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n", index, (long long int)firstAcquisitionIndex, (long long int)firstMeasurementIndex); #endif } @@ -166,10 +166,10 @@ int DataStreamer::CreateZmqSockets(int* dindex, int* nunits) { zmqSocket = new ZmqSocket(portnum); if (zmqSocket->IsError()) { - cprintf(RED, "Error: Could not create Zmq socket on port %d for Streamer %d\n", portnum, index); + bprintf(RED, "Error: Could not create Zmq socket on port %d for Streamer %d\n", portnum, index); return FAIL; } - printf("%d Streamer: Zmq Server started at %s\n",index, zmqSocket->GetZmqServerAddress()); + FILE_LOG(logINFO) << index << " Streamer: Zmq Server started at " << zmqSocket->GetZmqServerAddress(); return OK; } @@ -186,13 +186,13 @@ void DataStreamer::ThreadExecution() { char* buffer=0; fifo->PopAddressToStream(buffer); #ifdef FIFODEBUG - if (!index) cprintf(BLUE,"DataStreamer %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); + if (!index) bprintf(BLUE,"DataStreamer %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); #endif //check dummy uint32_t numBytes = (uint32_t)(*((uint32_t*)buffer)); #ifdef VERBOSE - cprintf(GREEN,"DataStreamer %d, Numbytes:%u\n", index,numBytes); + bprintf(GREEN,"DataStreamer %d, Numbytes:%u\n", index,numBytes); #endif if (numBytes == DUMMY_PACKET_VALUE) { StopProcessing(buffer); @@ -211,17 +211,17 @@ void DataStreamer::ThreadExecution() { void DataStreamer::StopProcessing(char* buf) { #ifdef VERBOSE if (!index) - cprintf(RED,"DataStreamer %d: Dummy\n", index); + bprintf(RED,"DataStreamer %d: Dummy\n", index); #endif sls_detector_header* header = (sls_detector_header*) (buf); //send dummy header and data if (!SendHeader(header, true)) - cprintf(RED,"Error: Could not send zmq dummy header for streamer %d\n", index); + bprintf(RED,"Error: Could not send zmq dummy header for streamer %d\n", index); fifo->FreeAddress(buf); StopRunning(); #ifdef VERBOSE - printf("%d: Streaming Completed\n", index); + FILE_LOG(logINFO) << index << ": Streaming Completed"; #endif } @@ -231,12 +231,12 @@ void DataStreamer::ProcessAnImage(char* buf) { sls_detector_header* header = (sls_detector_header*) (buf); uint64_t fnum = header->frameNumber; #ifdef VERBOSE - cprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index,fnum); + bprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index,fnum); #endif if (!measurementStartedFlag) { #ifdef VERBOSE - if (!index) cprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index, fnum); + if (!index) bprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index, fnum); #endif RecordFirstIndices(fnum); //restart timer @@ -255,20 +255,20 @@ void DataStreamer::ProcessAnImage(char* buf) { } if (!SendHeader(header)) - cprintf(RED,"Error: Could not send zmq header for fnum %lld and streamer %d\n", + bprintf(RED,"Error: Could not send zmq header for fnum %lld and streamer %d\n", (long long int) fnum, index); //shortframe gotthard - data sending if (completeBuffer) { memcpy(completeBuffer + ((generalData->imageSize)**shortFrameEnable), buf + sizeof(sls_detector_header), generalData->imageSize); if (!zmqSocket->SendData(completeBuffer, generalData->imageSize_Streamer)) - cprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", + bprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", (long long int) fnum, index); } //normal - data sending else { if (!zmqSocket->SendData(buf + sizeof(sls_detector_header), generalData->imageSize)) - cprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", + bprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", (long long int) fnum, index); } } @@ -279,7 +279,7 @@ bool DataStreamer::CheckTimer() { struct timespec end; clock_gettime(CLOCK_REALTIME, &end); #ifdef VERBOSE - cprintf(BLUE,"%d Timer elapsed time:%f seconds\n", index, ( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0); + bprintf(BLUE,"%d Timer elapsed time:%f seconds\n", index, ( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0); #endif //still less than streaming timer, keep waiting if((( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0) < (*streamingTimerInMs/1000)) diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index bc1f9f217..d95cb6f27 100644 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -29,7 +29,7 @@ Fifo::Fifo(uint32_t fifoItemSize, uint32_t fifoDepth, bool &success): Fifo::~Fifo() { FILE_LOG (logDEBUG) << __AT__ << " called"; - //cprintf(BLUE,"Fifo Object %d: Goodbye\n", index); + //bprintf(BLUE,"Fifo Object %d: Goodbye\n", index); DestroyFifos(); NumberofFifoClassObjects--; } @@ -59,7 +59,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize, uint32_t fifoDepth) { while (buffer < (memory + fifoItemSize * (fifoDepth-1))) { //sprintf(buffer,"memory"); #ifdef FIFODEBUG - cprintf(MAGENTA,"Fifofree %d: value:%d, pop 0x%p\n", index, fifoFree->getSemValue(), (void*)(buffer)); + bprintf(MAGENTA,"Fifofree %d: value:%d, pop 0x%p\n", index, fifoFree->getSemValue(), (void*)(buffer)); #endif FreeAddress(buffer); buffer += fifoItemSize; diff --git a/slsReceiverSoftware/src/File.cpp b/slsReceiverSoftware/src/File.cpp index f559ab6ee..177f33bb8 100644 --- a/slsReceiverSoftware/src/File.cpp +++ b/slsReceiverSoftware/src/File.cpp @@ -43,43 +43,25 @@ string File::GetCurrentFileName() { } void File::PrintMembers() { - printf("\nGeneral Writer Variables:" - "Index: %d\n" - "Max Frames Per File: %u\n" - "Packets per Frame: %u\n" - "Number of Detectors in x dir: %d\n" - "Number of Detectors in y dir: %d\n" - "File Name Prefix: %s\n" - "File Path: %s\n" - "File Index: %lu\n" - "Frame Index Enable: %d\n" - "Over Write Enable: %d\n" + FILE_LOG(logINFO) << "\nGeneral Writer Variables:" << endl + << "Index: " << index << endl + << "Max Frames Per File: " << maxFramesPerFile << endl + << "Packets per Frame: " << *packetsPerFrame << endl + << "Number of Detectors in x dir: " << numDetX << endl + << "Number of Detectors in y dir: " << numDetY << endl + << "File Name Prefix: " << fileNamePrefix << endl + << "File Path: " << filePath << endl + << "File Index: " << *fileIndex << endl + << "Frame Index Enable: " << *frameIndexEnable << endl + << "Over Write Enable: " << *overWriteEnable << endl - "Detector Index: %d\n" - "Number of Units Per Detector: %d\n" - "Number of Images in Acquisition: %lu\n" - "Dynamic Range: %u\n" - "UDP Port number: %u\n" - "Master File Name: %s\n" - "Current File Name: %s\n", - index, - maxFramesPerFile, - *packetsPerFrame, - numDetX, - numDetY, - fileNamePrefix, - filePath, - *fileIndex, - (int)*frameIndexEnable, - (int)*overWriteEnable, - - *detIndex, - *numUnitsPerDetector, - *numImages, - *dynamicRange, - *udpPortNumber, - masterFileName.c_str(), - currentFileName.c_str()); + << "Detector Index: " << *detIndex << endl + << "Number of Units Per Detector: " << *numUnitsPerDetector << endl + << "Number of Images in Acquisition: " << *numImages << endl + << "Dynamic Range: " << *dynamicRange << endl + << "UDP Port number: " << *udpPortNumber << endl + << "Master File Name: " << masterFileName << endl + << "Current File Name: " << currentFileName; } diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index 5aca5038f..01daf3946 100644 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -53,13 +53,13 @@ void HDF5File::PrintMembers() { File::PrintMembers(); UpdateDataType(); if (datatype == PredType::STD_U8LE) { - printf("Data Type: 4 or 8\n"); + FILE_LOG(logINFO) << "Data Type: 4 or 8"; } else if (datatype == PredType::STD_U16LE) { - printf("Data Type: 16\n"); + FILE_LOG(logINFO) << "Data Type: 16"; } else if (datatype == PredType::STD_U32LE) { - printf("Data Type: 32\n"); + FILE_LOG(logINFO) << "Data Type: 32"; } else { - cprintf(BG_RED,"unknown data type\n"); + FILE_LOG(logERROR) << BG_RED,"unknown data type"; } } @@ -112,18 +112,18 @@ int HDF5File::CreateFile(uint64_t fnum) { } pthread_mutex_unlock(&Mutex); if (dataspace == NULL) - cprintf(RED,"Got nothing!\n"); + bprintf(RED,"Got nothing!\n"); //first file, print entrire path if (loss == -1) - printf("[%u]: HDF5 File created: %s\n", *udpPortNumber, currentFileName.c_str()); + FILE_LOG(logINFO) << *udpPortNumber << ": HDF5 File created: " << currentFileName; //other files else { if (loss) - cprintf(RED,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", + bprintf(RED,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", *udpPortNumber,loss, fifo->GetMaxLevelForFifoBound() , basename(currentFileName.c_str())); else - cprintf(GREEN,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", + bprintf(GREEN,"[%u]: Packet_Loss:%lu Fifo_Max_Level:%d \tNew_File:%s\n", *udpPortNumber,loss, fifo->GetMaxLevelForFifoBound(), basename(currentFileName.c_str())); } @@ -172,7 +172,7 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t } } pthread_mutex_unlock(&Mutex); - cprintf(RED,"%d Error: Write to file failed\n", index); + bprintf(RED,"%d Error: Write to file failed\n", index); return FAIL; } @@ -187,7 +187,7 @@ int HDF5File::CreateMasterFile(bool en, uint32_t size, if (master && (*detIndex==0)) { virtualfd = 0; masterFileName = HDF5FileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); - printf("Master File: %s\n", masterFileName.c_str()); + FILE_LOG(logINFO) << "Master File: " << masterFileName; pthread_mutex_lock(&Mutex); int ret = HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName, *overWriteEnable, *dynamicRange, en, size, nx, ny, *numImages, at, ap, HDF5_WRITER_VERSION); diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 75783fa5d..8280624bb 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -177,7 +177,7 @@ void Listener::RecordFirstIndices(uint64_t fnum) { acquisitionStartedFlag = true; firstAcquisitionIndex = fnum; } - if (!index) cprintf(BLUE,"%d First Acquisition Index:%lu\n" + if (!index) bprintf(BLUE,"%d First Acquisition Index:%lu\n" "%d First Measurement Index:%lu\n", index, firstAcquisitionIndex, index, firstMeasurementIndex); @@ -219,7 +219,7 @@ int Listener::CreateUDPSockets() { generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize); int iret = udpSocket->getErrorStatus(); if(!iret){ - cout << index << ": UDP port opened at port " << *udpPortNumber << endl; + FILE_LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber; }else{ FILE_LOG(logERROR) << "Could not create UDP socket on port " << *udpPortNumber << " error: " << iret; return FAIL; @@ -247,7 +247,7 @@ void Listener::ThreadExecution() { fifo->GetNewAddress(buffer); #ifdef FIFODEBUG - if (!index) cprintf(GREEN,"Listener %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); + if (!index) bprintf(GREEN,"Listener %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); #endif //udpsocket doesnt exist @@ -275,7 +275,7 @@ void Listener::ThreadExecution() { //error check, (should not be here) if not transmitting yet (previous if) rc should be > 0 if (rc <= 0) { - //cprintf(BG_RED,"Error:(Weird Early self shut down), UDP Sockets not shut down, but received nothing\n"); + //bprintf(BG_RED,"Error:(Weird Early self shut down), UDP Sockets not shut down, but received nothing\n"); StopListening(buffer); return; } @@ -297,8 +297,8 @@ void Listener::StopListening(char* buf) { fifo->PushAddress(buf); StopRunning(); #ifdef VERBOSE - cprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught); - printf("%d: Listening Completed\n", index); + bprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught); + bprintf(GREEN,"%d: Listening Completed\n", index); #endif } @@ -327,7 +327,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { //look for carry over if (carryOverFlag) { - cprintf(RED,"%d carry flag\n",index); + bprintf(RED,"%d carry flag\n",index); //check if its the current image packet // -------------------------- new header ---------------------------------------------------------------------- if (standardheader) { @@ -343,7 +343,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { //------------------------------------------------------------------------------------------------------------ if (fnum != currentFrameIndex) { if (fnum < currentFrameIndex) { - cprintf(BG_RED,"Error:(Weird), With carry flag: Frame number %lu less than current frame number %lu\n", fnum, currentFrameIndex); + bprintf(BG_RED,"Error:(Weird), With carry flag: Frame number %lu less than current frame number %lu\n", fnum, currentFrameIndex); return 0; } new_header->packetNumber = numpackets; @@ -426,7 +426,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { #ifdef VERBOSE //if (!index) - cprintf(GREEN,"Listening %d: currentfindex:%lu, fnum:%lu, pnum:%u numpackets:%u\n", + bprintf(GREEN,"Listening %d: currentfindex:%lu, fnum:%lu, pnum:%u numpackets:%u\n", index,currentFrameIndex, fnum, pnum, numpackets); #endif if (!measurementStartedFlag) @@ -436,7 +436,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { //future packet by looking at image number (all other detectors) if (fnum != currentFrameIndex) { - //cprintf(RED,"setting carry over flag to true\n"); + //bprintf(RED,"setting carry over flag to true\n"); carryOverFlag = true; memcpy(carryOverPacket,listeningPacket, generalData->packetSize); diff --git a/slsReceiverSoftware/src/ThreadObject.cpp b/slsReceiverSoftware/src/ThreadObject.cpp index ff44026e4..08a7fc4e2 100644 --- a/slsReceiverSoftware/src/ThreadObject.cpp +++ b/slsReceiverSoftware/src/ThreadObject.cpp @@ -87,7 +87,7 @@ void ThreadObject::RunningThread() { sem_wait(&semaphore); if(killThread) { - cprintf(BLUE,"%s Thread %d: Goodbye\n",GetType().c_str(),index); + bprintf(BLUE,"%s Thread %d: Goodbye\n",GetType().c_str(),index); pthread_exit(NULL); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b4fc0bdfc..9cfbf1bdd 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -133,7 +133,7 @@ void UDPStandardImplementation::setFileFormat(const fileFormat f){ int UDPStandardImplementation::setShortFrameEnable(const int i) { if (myDetectorType != GOTTHARD) { - cprintf(RED, "Error: Can not set short frame for this detector\n"); + bprintf(RED, "Error: Can not set short frame for this detector\n"); return FAIL; } @@ -203,9 +203,9 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) { } if (DataStreamer::GetErrorMask() || error) { if (DataStreamer::GetErrorMask()) - cprintf(BG_RED,"Error: Could not create data callback threads\n"); + bprintf(BG_RED,"Error: Could not create data callback threads\n"); else - cprintf(BG_RED,"Error: Could not create zmq sockets\n"); + bprintf(BG_RED,"Error: Could not create zmq sockets\n"); for (vector::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it) delete(*it); dataStreamer.clear(); @@ -319,7 +319,7 @@ int UDPStandardImplementation::setFifoDepth(const uint32_t i) { if (SetupFifoStructure() == FAIL) return FAIL; } - FILE_LOG (logINFO) << "Fifo Depth: " << i << endl; + FILE_LOG (logINFO) << "Fifo Depth: " << i; return OK; } @@ -428,7 +428,7 @@ void UDPStandardImplementation::resetAcquisitionCount() { int UDPStandardImplementation::startReceiver(char *c) { - cout << endl << endl; + bprintf(GRAY,"\n"); FILE_LOG(logINFO) << "Starting Receiver"; ResetParametersforNewMeasurement(); @@ -445,7 +445,7 @@ int UDPStandardImplementation::startReceiver(char *c) { startAcquisitionCallBack(filePath, fileName, fileIndex, (generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize), pStartAcquisition); if (rawDataReadyCallBack != NULL) { - cout << "Data Write has been defined externally" << endl; + FILE_LOG(logINFO) << "Data Write has been defined externally"; } } @@ -457,9 +457,9 @@ int UDPStandardImplementation::startReceiver(char *c) { return FAIL; } } else - cout << "File Write Disabled" << endl; + FILE_LOG(logINFO) << "File Write Disabled"; - cout << "Ready ..." << endl; + FILE_LOG(logINFO) << "Ready ..."; //status pthread_mutex_lock(&statusMutex); @@ -517,19 +517,19 @@ void UDPStandardImplementation::stopReceiver(){ uint64_t missingpackets = numberOfFrames*generalData->packetsPerFrame-listener[i]->GetPacketsCaught(); if (missingpackets) { - cprintf(RED, "\n[Port %d]\n",udpPortNum[i]); - cprintf(RED, "Missing Packets\t\t: %lld\n",(long long int)missingpackets); - cprintf(RED, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught()); - cprintf(RED, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught()); + bprintf(RED, "\n[Port %d]\n",udpPortNum[i]); + bprintf(RED, "Missing Packets\t\t: %lld\n",(long long int)missingpackets); + bprintf(RED, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught()); + bprintf(RED, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught()); }else{ - cprintf(GREEN, "\n[Port %d]\n",udpPortNum[i]); - cprintf(GREEN, "Missing Packets\t\t: %lld\n",(long long int)missingpackets); - cprintf(GREEN, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught()); - cprintf(GREEN, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught()); + bprintf(GREEN, "\n[Port %d]\n",udpPortNum[i]); + bprintf(GREEN, "Missing Packets\t\t: %lld\n",(long long int)missingpackets); + bprintf(GREEN, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught()); + bprintf(GREEN, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught()); } } if(!activated) - cprintf(RED,"Note: Deactivated Receiver\n"); + bprintf(RED,"Note: Deactivated Receiver\n"); //callback if (acquisitionFinishedCallBack) acquisitionFinishedCallBack((tot/numThreads), pAcquisitionFinished); @@ -563,7 +563,7 @@ void UDPStandardImplementation::startReadout(){ //wait as long as there is change from prev totalP, while(prev != totalP){ #ifdef VERY_VERBOSE - cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d\n", + bprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d\n", prev,totalP); #endif @@ -576,7 +576,7 @@ void UDPStandardImplementation::startReadout(){ for (vector::const_iterator it = listener.begin(); it != listener.end(); ++it) totalP += (*it)->GetPacketsCaught(); #ifdef VERY_VERBOSE - cprintf(MAGENTA,"\tupdated: totalP:%d\n",totalP); + bprintf(MAGENTA,"\tupdated: totalP:%d\n",totalP); #endif } } @@ -703,7 +703,7 @@ int UDPStandardImplementation::SetupFifoStructure() { //must be > 0 and < max jobs numberofJobs = ((i < 1) ? 1 : ((i > MAX_JOBS_PER_THREAD) ? MAX_JOBS_PER_THREAD : i)); } - FILE_LOG (logINFO) << "Number of Jobs Per Thread:" << numberofJobs << endl; + FILE_LOG (logINFO) << "Number of Jobs Per Thread:" << numberofJobs; uint32_t oldfifodepth = fifoDepth; //reduce fifo depth if numberofJobsPerBuffer > 1 (to save memory) @@ -731,7 +731,7 @@ int UDPStandardImplementation::SetupFifoStructure() { (generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize), fifoDepth, success)); if (!success) { - cprintf(BG_RED,"Error: Could not allocate memory for fifo structure of index %d\n", i); + bprintf(BG_RED,"Error: Could not allocate memory for fifo structure of index %d\n", i); for (vector::const_iterator it = fifo.begin(); it != fifo.end(); ++it) delete(*it); fifo.clear(); diff --git a/slsReceiverSoftware/src/dummyMain.cpp b/slsReceiverSoftware/src/dummyMain.cpp deleted file mode 100644 index 3f4e9bb2d..000000000 --- a/slsReceiverSoftware/src/dummyMain.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* A simple server in the internet domain using TCP - The port number is passed as an argument */ - -#include "sls_receiver_defs.h" -#include "dummyUDPInterface.h" -#include "slsReceiverTCPIPInterface.h" - -#include -#include - - -using namespace std; - - -int main(int argc, char *argv[]) { - int success; - int tcpip_port_no; - bool bottom = false; - cout << "CCCCCC" << endl; - dummyUDPInterface *udp=new dummyUDPInterface(); -// slsReceiverTCPIPInterface *tcpipInterface = new slsReceiverTCPIPInterface(success, udp, tcpip_port_no, bottom); - - - - -// if(tcpipInterface->start() == slsReceiverDefs::OK){ -// cout << "DONE!" << endl; -// string str; -// cin>>str; -// //wait and look for an exit keyword -// while(str.find("exit") == string::npos) -// cin>>str; -// //stop tcp server thread, stop udp socket -// tcpipInterface->stop(); -// } - -// if (tcpipInterface) -// delete tcpipInterface; - - udp->startReceiver(); - if(udp) - delete udp; - return 0; - - - -} - diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 328acec3a..163923a27 100644 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -25,23 +25,23 @@ void closeFile(int p){ /* int startAcquisitionCallBack(char* filePath, char* fileName, int fileIndex, int bufferSize, void* context) { - cout << "#### startAcquisitionCallBack ####" << endl; - cout << "* filePath: " << filePath << endl; - cout << "* fileName: " << fileName << endl; - cout << "* fileIndex: " << fileIndex << endl; - cout << "* bufferSize: " << bufferSize << endl; + FILE_LOG(logINFO) << "#### startAcquisitionCallBack ####"; + FILE_LOG(logINFO) << "* filePath: " << filePath; + FILE_LOG(logINFO) << "* fileName: " << fileName; + FILE_LOG(logINFO) << "* fileIndex: " << fileIndex; + FILE_LOG(logINFO) << "* bufferSize: " << bufferSize; return 1; } void acquisitionFinishedCallBack(int totalFramesCaught, void* context) { - cout << "#### acquisitionFinishedCallBack ####" << endl; - cout << "* totalFramesCaught: " << totalFramesCaught << endl; + FILE_LOG(logINFO) << "#### acquisitionFinishedCallBack ####"; + FILE_LOG(logINFO) << "* totalFramesCaught: " << totalFramesCaught; } void rawDataReadyCallBack(int currFrameNum, char* dataPointer, int dataSize, FILE* file, char* guiDataPointer, void* context) { - cout << "#### rawDataReadyCallBack ####" << endl; - cout << "* currFrameNum: " << currFrameNum << endl; - cout << "* dataSize: " << dataSize << endl; + FILE_LOG(logINFO) << "#### rawDataReadyCallBack ####"; + FILE_LOG(logINFO) << "* currFrameNum: " << currFrameNum; + FILE_LOG(logINFO) << "* dataSize: " << dataSize; } */ @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) { //start tcp server thread if(receiver->start() == slsReceiverDefs::OK){ - FILE_LOG(logDEBUG1) << "DONE!" << endl; + FILE_LOG(logDEBUG1) << "DONE!"; string str; cin>>str; //wait and look for an exit keyword @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) { } deleteReceiver(receiver); - cout << "Goodbye!" << endl; + FILE_LOG(logINFO) << "Goodbye!"; return 0; } diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 4a28ab8e1..b5c3bcd57 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -18,7 +18,7 @@ using namespace std; -slsReceiver::slsReceiver(int argc, char *argv[], int &success){ +slsReceiver::slsReceiver(int argc, char *argv[], int &success) { /** * Constructor method to start up a Receiver server. Reads configuration file, options, and @@ -70,7 +70,9 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ case 'f': fname = optarg; - //cout << long_options[option_index].name << " " << optarg << endl; +#ifdef VERYVERBOSE + FILE_LOG(logDEBUG) << long_options[option_index].name << " " << optarg << endl; +#endif break; case 'b': @@ -94,7 +96,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ help_message += """\t--type:\t Type of the receiver. Possible arguments are: standard, REST. Default: standard.\n\n"""; - cout << help_message << endl; + FILE_LOG(logINFO) << help_message << endl; break; } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 4e210be95..d200894d2 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -70,7 +70,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* strcpy(mess,"dummy message"); function_table(); #ifdef VERYVERBOSE - cout << "Function table assigned." << endl; + FILE_LOG(logINFO) << "Function table assigned."; #endif } } @@ -89,7 +89,7 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ if (p_number<1024) { sprintf(mess,"Too low port number %d\n", p_number); - cout << mess << endl; + bprintf(RED,"%s",mess); } else { oldsocket=mySock; @@ -101,10 +101,9 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ strcpy(mySock->lastClientIP,oldsocket->lastClientIP); delete oldsocket; } else { - cout << "Could not bind port " << p_number << endl; + FILE_LOG(logERROR) << "Could not bind port " << p_number; if (sd==-10) { - - cout << "Port "<< p_number << " already set" << endl; + FILE_LOG(logINFO) << "Port "<< p_number << " already set"; } else { delete mySock; mySock=oldsocket; @@ -123,27 +122,26 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ int slsReceiverTCPIPInterface::start(){ - FILE_LOG(logDEBUG) << "Creating TCP Server Thread" << endl; + FILE_LOG(logDEBUG) << "Creating TCP Server Thread"; killTCPServerThread = 0; if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){ - cout << "Could not create TCP Server thread" << endl; + FILE_LOG(logERROR) << "Could not create TCP Server thread"; return FAIL; } //#ifdef VERYVERBOSE - FILE_LOG(logDEBUG) << "TCP Server thread created successfully." << endl; + FILE_LOG(logDEBUG) << "TCP Server thread created successfully."; //#endif return OK; } void slsReceiverTCPIPInterface::stop(){ - cout << "Shutting down UDP Socket" << endl; + FILE_LOG(logINFO) << "Shutting down UDP Socket"; killTCPServerThread = 1; if(mySock) mySock->ShutDownSocket(); - cout<<"Socket closed"<Connect()>=0){ #ifdef VERY_VERBOSE - cout << "Conenction accepted" << endl; + FILE_LOG(logDEBUG5) << "Conenction accepted"; #endif v = decode_function(); #ifdef VERY_VERBOSE - cout << "function executed" << endl; + FILE_LOG(logDEBUG5) << "function executed"; #endif mySock->Disconnect(); #ifdef VERY_VERBOSE - cout << "connection closed" << endl; + FILE_LOG(logDEBUG5) << "connection closed"; #endif } //if tcp command was to exit server if(v==GOODBYE){ - cout << "Shutting down UDP Socket" << endl; + FILE_LOG(logINFO) << "Shutting down UDP Socket"; if(receiverBase){ receiverBase->shutDownUDPSockets(); - cout << "Closing Files... " << endl; + FILE_LOG(logINFO) << "Closing Files... "; receiverBase->closeFiles(); } @@ -269,7 +267,7 @@ int slsReceiverTCPIPInterface::function_table(){ #ifdef VERYVERBOSE for (int i=0;iReceiveDataOnly(&fnum,sizeof(fnum)); if (n <= 0) { #ifdef VERYVERBOSE - cout << "ERROR reading from socket " << n << ", " << fnum << endl; + FILE_LOG(logDEBUG1) << "ERROR reading from socket " << n << ", " << fnum; #endif return FAIL; } #ifdef VERYVERBOSE else - cout << "size of data received " << n <numberOfFunctions-1) @@ -306,7 +304,7 @@ int slsReceiverTCPIPInterface::decode_function(){ //calling function (this->*flist[fnum])(); if (ret==FAIL) - cprintf(RED, "Error executing the function = %d\n",fnum); + bprintf(RED, "Error executing the function = %d\n",fnum); return ret; } @@ -320,7 +318,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){ ret=FAIL; sprintf(mess,"Unrecognized Function\n"); - cout << mess << endl; + FILE_LOG(logERROR) << mess; mySock->SendDataOnly(&ret,sizeof(ret)); mySock->SendDataOnly(mess,sizeof(mess)); @@ -358,7 +356,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ } else if((receiverBase)&&(receiverBase->getStatus()!= IDLE)){ strcpy(mess,"Can not set detector type while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -399,7 +397,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ if(ret!=FAIL) FILE_LOG(logDEBUG) << "detector type " << dr; else - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); //#endif #endif @@ -451,7 +449,7 @@ int slsReceiverTCPIPInterface::set_file_name() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set file name while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -463,9 +461,9 @@ int slsReceiverTCPIPInterface::set_file_name() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "file name:" << retval << endl; + FILE_LOG(logDEBUG1) << "file name:" << retval; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -478,7 +476,7 @@ int slsReceiverTCPIPInterface::set_file_name() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } if(retval == NULL) @@ -524,7 +522,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set file path while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -539,9 +537,9 @@ int slsReceiverTCPIPInterface::set_file_dir() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "file path:" << retval << endl; + FILE_LOG(logDEBUG1) << "file path:" << retval; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -553,7 +551,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } if(retval == NULL) @@ -598,7 +596,7 @@ int slsReceiverTCPIPInterface::set_file_index() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set file index while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -611,9 +609,9 @@ int slsReceiverTCPIPInterface::set_file_index() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "file index:" << retval << endl; + FILE_LOG(logDEBUG1) << "file index:" << retval; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -625,7 +623,7 @@ int slsReceiverTCPIPInterface::set_file_index() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -667,7 +665,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set frame index while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -689,9 +687,9 @@ int slsReceiverTCPIPInterface::set_frame_index() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "frame index:" << retval << endl; + FILE_LOG(logDEBUG1) << "frame index:" << retval; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -703,7 +701,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -749,7 +747,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set up udp while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -844,7 +842,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ ret=receiverBase->startReceiver(mess); else{ sprintf(mess,"Cannot start Receiver as it is in %s state\n",runStatusType(s).c_str()); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; } } @@ -858,7 +856,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "Error:%s\n", mess); + bprintf(RED, "Error:%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -892,7 +890,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ ret = OK; else{ sprintf(mess,"Could not stop receiver. It is in %s state\n",runStatusType(s).c_str()); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } } @@ -906,7 +904,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -937,7 +935,7 @@ int slsReceiverTCPIPInterface::get_status(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } retval = (runStatus(s)); @@ -968,7 +966,7 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1000,7 +998,7 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1045,7 +1043,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -1091,7 +1089,7 @@ int slsReceiverTCPIPInterface::set_short_frame() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Cannot set short frame while status is running\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; } else{ @@ -1109,7 +1107,7 @@ int slsReceiverTCPIPInterface::set_short_frame() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1203,7 +1201,7 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set receiver frequency mode while receiver not idle\n"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); ret = FAIL; } else{ @@ -1211,13 +1209,13 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ ret = receiverBase->setFrameToGuiFrequency(index); if(ret == FAIL){ strcpy(mess, "Could not allocate memory for listening fifo\n"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); } } retval=receiverBase->getFrameToGuiFrequency(); if(index>=0 && retval!=index){ strcpy(mess,"Could not set frame to gui frequency"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); ret = FAIL; } } @@ -1233,7 +1231,7 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1273,7 +1271,7 @@ int slsReceiverTCPIPInterface::set_read_receiver_timer(){ } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set receiver frequency mode while receiver not idle\n"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); ret = FAIL; } else{ @@ -1283,7 +1281,7 @@ int slsReceiverTCPIPInterface::set_read_receiver_timer(){ retval=receiverBase->getFrameToGuiTimer(); if(index>=0 && retval!=index){ strcpy(mess,"Could not set datastream timer"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); ret = FAIL; } } @@ -1299,7 +1297,7 @@ int slsReceiverTCPIPInterface::set_read_receiver_timer(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1337,7 +1335,7 @@ int slsReceiverTCPIPInterface::set_data_stream_enable(){ } else if((index >= 0) && (receiverBase->getStatus()!= IDLE)){ strcpy(mess,"Can not set data stream enable while receiver not idle\n"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); ret = FAIL; } else{ @@ -1346,7 +1344,7 @@ int slsReceiverTCPIPInterface::set_data_stream_enable(){ retval=receiverBase->getDataStreamEnable(); if(index>=0 && retval!=index){ strcpy(mess,"Could not set data stream enable"); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); ret = FAIL; } } @@ -1362,7 +1360,7 @@ int slsReceiverTCPIPInterface::set_data_stream_enable(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1401,7 +1399,7 @@ int slsReceiverTCPIPInterface::enable_file_write(){ } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set file write mode while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -1422,7 +1420,7 @@ int slsReceiverTCPIPInterface::enable_file_write(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1466,7 +1464,7 @@ int64_t slsReceiverTCPIPInterface::getReceiverVersion(){ -int slsReceiverTCPIPInterface::start_readout(){cprintf(BLUE,"In start readout!\n"); +int slsReceiverTCPIPInterface::start_readout(){bprintf(BLUE,"In start readout!\n"); ret=OK; enum runStatus retval; @@ -1498,7 +1496,7 @@ int slsReceiverTCPIPInterface::start_readout(){cprintf(BLUE,"In start readout!\n // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1538,7 +1536,7 @@ int slsReceiverTCPIPInterface::set_timer() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set timer while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -1568,13 +1566,13 @@ int slsReceiverTCPIPInterface::set_timer() { #ifdef VERYVERBOSE if(ret!=FAIL){ if(index[0] == ACQUISITION_TIME) - cout << "acquisition time:" << retval << endl; + FILE_LOG(logDEBUG1) << "acquisition time:" << retval; else if(index[0] == FRAME_PERIOD) - cout << "acquisition period:" << retval << endl; + FILE_LOG(logDEBUG1) << "acquisition period:" << retval else - cout << "frame number:" << retval << endl; + FILE_LOG(logDEBUG1) << "frame number:" << retval; }else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -1586,7 +1584,7 @@ int slsReceiverTCPIPInterface::set_timer() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1627,7 +1625,7 @@ int slsReceiverTCPIPInterface::enable_compression() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Cannot enable/disable compression while status is running\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; } else{ @@ -1658,7 +1656,7 @@ int slsReceiverTCPIPInterface::enable_compression() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1697,7 +1695,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set detector hostname while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -1710,9 +1708,9 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "hostname:" << retval << endl; + FILE_LOG(logDEBUG1) << "hostname:" << retval; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -1724,7 +1722,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } if(retval == NULL) @@ -1772,7 +1770,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { case 32:break; default: sprintf(mess,"This dynamic range does not exist: %d\n",dr); - cprintf(RED,"%s", mess); + bprintf(RED,"%s", mess); ret=FAIL; break; } @@ -1784,7 +1782,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set dynamic range while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -1801,9 +1799,9 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "dynamic range" << dr << endl; + FILE_LOG(logDEBUG1) << "dynamic range" << dr; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -1815,7 +1813,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1856,7 +1854,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set overwrite mode while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -1869,9 +1867,9 @@ int slsReceiverTCPIPInterface::enable_overwrite() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "overwrite:" << retval << endl; + FILE_LOG(logDEBUG1) << "overwrite:" << retval; else - cout << mess << endl; + FILE_LOG(logERROR) << mess; #endif #endif @@ -1883,7 +1881,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1924,7 +1922,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set up 1Giga/10Giga mode while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -1939,9 +1937,9 @@ int slsReceiverTCPIPInterface::enable_tengiga() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "10Gbe:" << val << endl; + FILE_LOG(logDEBUG1) << "10Gbe:" << val; else - cout << mess << endl; + FILE_LOG(logDEBUG1) << mess; #endif #endif @@ -1953,7 +1951,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -1994,7 +1992,7 @@ int slsReceiverTCPIPInterface::set_fifo_depth() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Cannot set/get fifo depth while status is running\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; } else{ @@ -2025,7 +2023,7 @@ int slsReceiverTCPIPInterface::set_fifo_depth() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -2048,7 +2046,7 @@ int slsReceiverTCPIPInterface::set_activate() { // receive arguments if(mySock->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){ strcpy(mess,"Error reading from socket\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } @@ -2064,11 +2062,11 @@ int slsReceiverTCPIPInterface::set_activate() { if(ret!=FAIL){ if (receiverBase == NULL){ strcpy(mess,SET_RECEIVER_ERR_MESSAGE); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; }else if(receiverBase->getStatus()==RUNNING){ strcpy(mess,"Cannot activate/deactivate while status is running\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; }else{ if(enable != -1) @@ -2077,7 +2075,7 @@ int slsReceiverTCPIPInterface::set_activate() { if(enable >= 0 && retval != enable){ sprintf(mess,"Tried to set activate to %d, but returned %d\n",enable,retval); ret = FAIL; - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); } } } @@ -2085,9 +2083,9 @@ int slsReceiverTCPIPInterface::set_activate() { #endif #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "Activate: " << retval << endl; + FILE_LOG(logDEBUG1) << "Activate: " << retval; else - cout << mess << endl; + FILE_LOG(logDEBUG1) << mess; #endif @@ -2099,7 +2097,7 @@ int slsReceiverTCPIPInterface::set_activate() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -2138,7 +2136,7 @@ int slsReceiverTCPIPInterface::set_flipped_data(){ } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set flipped data while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -2149,9 +2147,9 @@ int slsReceiverTCPIPInterface::set_flipped_data(){ } #ifdef VERYVERBOSE if(ret!=FAIL){ - cout << "Flipped Data:" << retval << endl; + FILE_LOG(logDEBUG1) << "Flipped Data:" << retval; }else - cout << mess << endl; + FILE_LOG(logDEBUG1) << mess; #endif #endif @@ -2163,7 +2161,7 @@ int slsReceiverTCPIPInterface::set_flipped_data(){ // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -2185,7 +2183,7 @@ int slsReceiverTCPIPInterface::set_file_format() { // receive arguments if(mySock->ReceiveDataOnly(&f,sizeof(f)) < 0 ){ strcpy(mess,"Error reading from socket\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } @@ -2201,11 +2199,11 @@ int slsReceiverTCPIPInterface::set_file_format() { if(ret!=FAIL){ if (receiverBase == NULL){ strcpy(mess,SET_RECEIVER_ERR_MESSAGE); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; }else if(receiverBase->getStatus()==RUNNING && (f>=0)){ strcpy(mess,"Cannot set file format while status is running\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret=FAIL; }else{ if(f != -1) @@ -2214,7 +2212,7 @@ int slsReceiverTCPIPInterface::set_file_format() { if(f >= 0 && retval != f){ sprintf(mess,"Tried to set file format to %d, but returned %d\n",f,retval); ret = FAIL; - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); } } } @@ -2222,9 +2220,9 @@ int slsReceiverTCPIPInterface::set_file_format() { #endif #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "File Format: " << retval << endl; + FILE_LOG(logDEBUG1) << "File Format: " << retval; else - cout << mess << endl; + FILE_LOG(logDEBUG1) << mess; #endif @@ -2236,7 +2234,7 @@ int slsReceiverTCPIPInterface::set_file_format() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -2274,7 +2272,7 @@ int slsReceiverTCPIPInterface::set_detector_posid() { } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set position file id while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -2287,9 +2285,9 @@ int slsReceiverTCPIPInterface::set_detector_posid() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "Position Id:" << retval << endl; + FILE_LOG(logDEBUG1) << "Position Id:" << retval; else - cout << mess << endl; + FILE_LOG(logDEBUG1) << mess; #endif #endif @@ -2301,7 +2299,7 @@ int slsReceiverTCPIPInterface::set_detector_posid() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -2340,11 +2338,11 @@ int slsReceiverTCPIPInterface::set_multi_detector_size() { else if (receiverBase == NULL){ strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; - cprintf(RED, "%s", mess); + bprintf(RED, "%s", mess); } else if(receiverBase->getStatus()!= IDLE){ strcpy(mess,"Can not set position file id while receiver not idle\n"); - cprintf(RED,"%s",mess); + bprintf(RED,"%s",mess); ret = FAIL; } else{ @@ -2354,9 +2352,9 @@ int slsReceiverTCPIPInterface::set_multi_detector_size() { } #ifdef VERYVERBOSE if(ret!=FAIL) - cout << "Multi Detector Size:" << retval << endl; + FILE_LOG(logDEBUG1) << "Multi Detector Size:" << retval; else - cout << mess << endl; + FILE_LOG(logDEBUG1) << mess; #endif #endif @@ -2368,7 +2366,7 @@ int slsReceiverTCPIPInterface::set_multi_detector_size() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + bprintf(RED, "%s\n", mess); mySock->SendDataOnly(mess,sizeof(mess)); } mySock->SendDataOnly(&retval,sizeof(retval)); @@ -2410,7 +2408,7 @@ int slsReceiverTCPIPInterface::lock_receiver() { // receive arguments if(mySock->ReceiveDataOnly(&lock,sizeof(lock)) < 0 ){ sprintf(mess,"Error reading from socket\n"); - cout << "Error reading from socket (lock)" << endl; + FILE_LOG(logERROR) << "Error reading from socket (lock)"; ret=FAIL; } // execute action if the arguments correctly arrived @@ -2432,7 +2430,7 @@ int slsReceiverTCPIPInterface::lock_receiver() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); } else @@ -2459,13 +2457,12 @@ int slsReceiverTCPIPInterface::set_port() { // receive arguments if(mySock->ReceiveDataOnly(&p_type,sizeof(p_type)) < 0 ){ strcpy(mess,"Error reading from socket\n"); - cout << mess << endl; + FILE_LOG(logERROR) << mess; ret=FAIL; } - if(mySock->ReceiveDataOnly(&p_number,sizeof(p_number)) < 0 ){ strcpy(mess,"Error reading from socket\n"); - cout << mess << endl; + FILE_LOG(logERROR) << mess; ret=FAIL; } @@ -2478,10 +2475,10 @@ int slsReceiverTCPIPInterface::set_port() { else { if (p_number<1024) { sprintf(mess,"Too low port number %d\n", p_number); - cout << mess << endl; + FILE_LOG(logERROR) << mess; ret=FAIL; } - cout << "set port " << p_type << " to " << p_number <lastClientIP); mySocket = new MySocketTCP(p_number); } @@ -2495,10 +2492,10 @@ int slsReceiverTCPIPInterface::set_port() { } else { ret=FAIL; sprintf(mess,"Could not bind port %d\n", p_number); - cout << mess << endl; + FILE_LOG(logERROR) << mess; if (sd==-10) { sprintf(mess,"Port %d already set\n", p_number); - cout << mess << endl; + FILE_LOG(logERROR) << mess; } } } @@ -2507,7 +2504,7 @@ int slsReceiverTCPIPInterface::set_port() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); }else { mySock->SendDataOnly(&p_number,sizeof(p_number)); @@ -2606,7 +2603,7 @@ int slsReceiverTCPIPInterface::update_client() { } mySock->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); mySock->SendDataOnly(mess,sizeof(mess)); return ret; } @@ -2625,7 +2622,7 @@ int slsReceiverTCPIPInterface::exit_server() { mySock->SendDataOnly(&ret,sizeof(ret)); strcpy(mess,"closing server"); mySock->SendDataOnly(mess,sizeof(mess)); - cprintf(RED,"%s\n",mess); + bprintf(RED,"%s\n",mess); return ret; } @@ -2648,7 +2645,7 @@ int slsReceiverTCPIPInterface::exec_command() { // execute action if the arguments correctly arrived if (ret==OK) { #ifdef VERYVERBOSE - cout << "executing command " << cmd << endl; + FILE_LOG(logDEBUG5) << "executing command " << cmd; #endif if (lockStatus==0 || mySock->differentClients==0) sysret=system(cmd); diff --git a/slsReceiverSoftware/src/utilities.cpp b/slsReceiverSoftware/src/utilities.cpp index afb5a6c65..e73e5a6c4 100644 --- a/slsReceiverSoftware/src/utilities.cpp +++ b/slsReceiverSoftware/src/utilities.cpp @@ -54,9 +54,9 @@ int read_config_file(string fname, int *tcpip_port_no, map * con if(sstr.good()) { sstr >> sargname; if(sscanf(sargname.c_str(),"%d",tcpip_port_no)) - cout<<"dataport:"< -#include "MySocketTCP.h" - -using namespace std; - -int main(){ - - char data[50000]; - int length=50000; - - unsigned short int portnum = 1952; - MySocketTCP* sock = new MySocketTCP(portnum); - - cout<<"\tReceived :"<ReceiveDataAndKeepConnection(data,23000)<ReceiveData(data,32200)<ReceiveData(data,33300)<ReceiveData(data,30000)<ReceiveData(data,3222)< -#include "MySocketTCP.h" - -using namespace std; - -int main(int argc, char *argv[]){ - - if(argc!=2){ - cout<<"Usage: send ip_addess/hostName"<SendDataAndKeepConnection(data,2000)<SendData(data,2200)<SendData(data,1200)<SendData(data,25000)<SendData(data,222)<