diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index cbc4f386c..29d9dd009 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -8,25 +8,9 @@ #include "sls_receiver_defs.h" -#include "receiver_defs.h" -#include "genericSocket.h" -#include "circularFifo.h" -#include "singlePhotonDetector.h" -#include "slsReceiverData.h" -#include "moenchCommonMode.h" - #include "UDPInterface.h" - -#ifdef MYROOT1 -#include -#include -#endif - - #include -#include #include -#include /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -35,6 +19,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface { public: + + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ /** * Constructor */ @@ -45,800 +34,538 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ virtual ~UDPBaseImplementation(); - void configure(map config_map); + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ - /** - * delete and free member parameters - */ - void deleteMembers(); - - /** - * initialize member parameters - */ - void initializeMembers(); - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - int setDetectorType(detectorType det); - - /** - * Set bottom to bot - * @param bot = 1 if bottom - */ - void setBottom(int bot); - - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - uint32_t getStartAcquisitionIndex(); - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - uint32_t getAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - bool getAcquistionStarted(); - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - int getFramesCaught(); - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - int getTotalFramesCaught(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - void resetTotalFramesCaught(); - - - - - //file parameters - /** - * Returns File Path - */ - char* getFilePath() const; - - /** - * Set File Path - * @param c file path - */ - char* setFilePath(const char c[]); - - /** - * Returns File Name - */ - char* getFileName() const; - - /** - * Set File Name (without frame index, file index and extension) - * @param c file name - */ - char* setFileName(const char c[]); - - /** - * Returns File Index - */ - int getFileIndex(); - - /** - * Set File Index - * @param i file index - */ - int setFileIndex(int i); - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - int setFrameIndexNeeded(int i); - - /** - * Set enable file write - * @param i file write enable - * Returns file write enable - */ - int setEnableFileWrite(int i); - - /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write - */ - int setEnableOverwrite(int i); - - /** - * Returns file write enable - * 1: YES 0: NO - */ - int getEnableFileWrite() const; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - int getEnableOverwrite() const; - -//other parameters - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; - - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - - /** - * Set detector hostname - * @param c hostname - */ - void initialize(const char *detectorHostName); - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL + //**initial parameters*** + /* + * Get detector hostname + * @return NULL or hostname or NULL if uninitialized (max of 1000 characters) */ char *getDetectorHostname() const; + + //***file parameters*** /** - * Set Ethernet Interface or IP to listen to + * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * @return NULL or file name prefix (max of 1000 characters) */ - void setEthernetInterface(char* c); + char *getFileName() const; /** - * Set UDP Port Number + * Get File Path + * @return NULL or file path (max of 1000 characters) */ - void setUDPPortNo(int p); - void setUDPPortNo2(int p); - - /* - * 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 - */ - int getNumberOfFrames() const; + char *getFilePath() const; /** - * set frame number if a positive number + * Get File Index + * @return file index of acquisition */ - int32_t setNumberOfFrames(int32_t fnum); + uint64_t getFileIndex() const; /** - * Returns scan tag + * Get Scan Tag + * @return scan tag //FIXME: needed? (unsigned integer?) */ int getScanTag() const; /** - * set scan tag if its is a positive number + * Get if Frame Index is enabled (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @return true if frame index needed, else false */ - int32_t setScanTag(int32_t stag); + bool getFrameIndexEnable() const; /** - * Returns the number of bits per pixel + * Get File Write Enable + * @return true if file write enabled, else false */ - int getDynamicRange() const; + bool getFileWriteEnable() const; /** - * set dynamic range if its is a positive number + * Get File Over Write Enable + * @return true if file over write enabled, else false */ - int32_t setDynamicRange(int32_t dr); + bool getOverwriteEnable() const; /** - * Set short frame - * @param i if shortframe i=1 + * Get data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @return true if data compression enabled, else false */ - int setShortFrame(int i); + bool getDataCompressionEnable() const; + + + //***acquisition count parameters*** + /** + * Get Total Frames Caught for an entire acquisition (including all scans) + * @return total number of frames caught for entire acquisition + */ + uint64_t getTotalFramesCaught() const; /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan */ - int setNFrameToGui(int i); - - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - - /** get data compression, by saving only hits - */ - bool getDataCompression(); - - /** enabl data compression, by saving only hits - /returns if failed - */ - int enableDataCompression(bool enable); + uint64_t getFramesCaught() const; /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Get Current Frame Index Caught for an entire acquisition (including all scans) + * @return current frame index (represents all scans too) */ - int enableTenGiga(int enable = -1); + int64_t getAcquisitionIndex() const; - -//other functions + //***connection parameters*** + /** + * Get UDP Port Number + * @return udp port number + */ + uint32_t getUDPPortNo() const; /** - * 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 startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * Get Second UDP Port Number (eiger specific) + * @return second udp port number */ - void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + uint32_t getUDPPortNo2() const; /** - * Closes all files - * @param ithr thread index + * Get Ehernet Interface + * @ethernet interface. eg. eth0 or "" if listening to all (max of 1000 characters) */ - void closeFile(int ithr = -1); + char *getEthernetInterface() const; + + + //***acquisition parameters*** + /** + * Get Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @return index of adc enabled, else -1 if all enabled + */ + int getShortFrameEnable() const; /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success + * Get the Frequency of Frames Sent to GUI + * @return 0 for random frame requests, n for nth frame frequency */ - int startReceiver(char message[]); + uint32_t getFrameToGuiFrequency() const; /** - * Stops Receiver - stops listening for packets - * Returns success + * Get Acquisition Period + * @return acquisition period */ - int stopReceiver(); + uint64_t getAcquisitionPeriod() const; - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + /* + * Get Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @return number of frames expected + */ + uint64_t getNumberOfFrames() const; + + /** + * Get Dynamic Range or Number of Bits Per Pixel + * @return dynamic range that is 4, 8, 16 or 32 + */ + uint32_t getDynamicRange() const; + + /** + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) + */ + bool getTenGigaEnable() const; + + //***receiver status*** + /** + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is listening or not + */ + slsReceiverDefs::runStatus getStatus() const; + + + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** + /** + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments + */ + void configure(map config_map); + + /** + * Set Bottom Enable (eiger specific, should be moved to configure, and later from client via TCPIP) + * @param b is true for bottom enabled or false for bottom disabled + */ + void setBottomEnable(const bool b); + + + //***file parameters*** + /** + * Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * Does not check for file existence since it is created only at startReceiver + * @param c file name (max of 1000 characters) + */ + void setFileName(const char c[]); + + /** + * Set File Path + * Checks for file directory existence before setting file path, + * If it doesn't exist, it will set it blank + * @param c file path (max of 1000 characters) + */ + void setFilePath(const char c[]); + + /** + * Set File Index of acquisition + * @param i file index of acquisition + */ + void setFileIndex(const uint64_t i); + + /** + * Set Scan Tag + * @param i scan tag //FIXME: needed? (unsigned integer?) + */ + void setScanTag(const int i); + + /** + * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @param b true for frame index enable, else false + */ + void setFrameIndexEnable(const bool b); + + /** + * Set File Write Enable + * @param b true for file write enable, else false + */ + void setFileWriteEnable(const bool b); + + /** + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false + */ + void setOverwriteEnable(const bool b); + + /** + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false + */ + void setDataCompressionEnable(const bool b); + + + + //***connection parameters*** + /** + * Set UDP Port Number + * @param i udp port number + */ + void setUDPPortNo(const uint32_t i); + + /** + * Set Second UDP Port Number (eiger specific) + * @return second udp port number + */ + void setUDPPortNo2(const uint32_t i); + + /** + * Set Ethernet Interface to listen to + * @param c ethernet inerface eg. eth0 (max of 1000 characters) + */ + void setEthernetInterface(const char* c); + + + //***connection parameters*** + /** + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled + */ + void setShortFrameEnable(const int i); + + /** + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency + */ + void setFrameToGuiFrequency(const uint32_t i); + + /** + * Set Acquisition Period + * @param i acquisition period + */ + void setAcquisitionPeriod(const uint64_t i); + + /** + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @param i number of frames expected + */ + void setNumberOfFrames(const uint64_t i); + + /** + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 + */ + void setDynamicRange(const uint32_t i); + + /** + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) + */ + void setTenGigaEnable(const bool b); + + + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + //***initial functions*** + /** + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL + */ + int setDetectorType(const slsReceiverDefs::detectorType d); + + /** + * Sets detector hostname (and corresponding detector variables in derived REST class) + * It is second function called by the client when connecting to receiver. + * you can call this function only once. //FIXME: is this still valid, this implemented in derived REST class? + * @param c detector hostname + */ + void initialize(const char *c); + + + //***acquisition functions*** + /** + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) + */ + void resetAcquisitionCount(); + + /** + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL + */ + int startReceiver(char *c=NULL); + + /** + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished + */ + void stopReceiver(); + + /** + * Stop Listening to Packets + * and sets status to Transmitting */ void startReadout(); /** * shuts down the udp sockets - * \returns if success or fail + * \returns OK or FAIL */ int shutDownUDPSockets(); -protected: - - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ /** - * Deletes all the filter objects for single photon data + * Get 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 startAcquisitionIndex start index of the acquisition + * @param startFrameIndex start index of the scan */ - void deleteFilter(); + void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex); /** - * Constructs the filter for single photon data + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' */ - void setupFilter(); + void abort(); //FIXME: needed, isnt stopReceiver enough? /** - * set up fifo according to the new numjobsperthread + * Closes all files + * @param i thread index, -1 for all threads */ - void setupFifoStructure (); + void closeFile(int i = -1); - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], char* buf=NULL); + //***callback functions*** /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); - - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize * + * return value is the action which decides what the user and default responsibilities to save data are + * 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 */ - int startListening(); + void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); /** - * Thread started which writes packets to file. - * Called by startReceiver() - * + * Call back for acquisition finished + * callback argument is + * total frames caught */ - int startWriting(); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number + * Call back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); - - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - */ - void startFrameIndices(int ithread); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - - /** - * When acquisition is over, this is called - * @param ithread listening thread number - * @param wbuffer writer buffer - */ - void stopWriting(int ithread, char* wbuffer[]); - - - /** - * data compression for each fifo output - * @param ithread listening thread number - * @param wbuffer writer buffer - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); + void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); + - //// Could be done more fine-grained... TODO - // private: protected: - /** structure of an eiger packet*/ - typedef struct - { + //**detector parameters*** + /** + * structure of an eiger packet header + * subframenum subframe number for 32 bit mode (already written by firmware) + * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) + * portnum 0 for the first port and 1 for the second port (written by software to file) + * dynamicrange dynamic range or bits per pixel (written by software to file) + */ + typedef struct { unsigned char subframenum[4]; unsigned char missingpacket[2]; unsigned char portnum[1]; unsigned char dynamicrange[1]; } eiger_packet_header_t; - - typedef struct - { + /** + * structure of an eiger packet footer + * framenum 48 bit frame number (already written by firmware) + * packetnum packet number (already written by firmware) + */ + typedef struct { unsigned char framenum[6]; unsigned char packetnum[2]; } eiger_packet_footer_t; - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** missing packet identifier value */ - const static uint16_t missingPacketValue = 0xFFFF; - /** detector type */ detectorType myDetectorType; - /** detector hostname */ char detHostname[MAX_STR_LENGTH]; + /** Number of Packets per Frame*/ + uint64_t packetsPerFrame; + /** Acquisition Period */ + int64_t acquisitionPeriod; + /** Frame Number */ + int64_t numberOfFrames; + /** Dynamic Range */ + uint32_t dynamicRange; + /** Ten Giga Enable*/ + bool tengigaEnable; + /** Bottom Half Module Enable */ + bool bottomEnable; - /** status of receiver */ + //***receiver parameters*** + /** Maximum Number of Listening Threads/ UDP Ports */ + const static int MAX_NUM_LISTENING_THREADS = 2; + /** Receiver Status */ runStatus status; - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + //***connection parameters*** + /** Ethernet Interface */ + char eth[MAX_STR_LENGTH]; + /** Server UDP Port Number*/ + uint32_t udpPortNum[MAX_NUM_LISTENING_THREADS]; - /** Server UDP Port*/ - int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - char *eth; - - /** max packets per file **/ - int maxPacketsPerFile; - - /** File write enable */ - int enableFileWrite; - - /** File over write enable */ - int overwrite; - - /** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ + //***file parameters*** + /** File Name without frame index, file index and extension (_d0_f000000000000_8.raw)*/ char fileName[MAX_STR_LENGTH]; - /** File Path */ char filePath[MAX_STR_LENGTH]; - /** File Index */ - int fileIndex; - - /** scan tag */ + uint64_t fileIndex; + /** Scan Tag */ int scanTag; + /** Frame Index Enable */ + bool frameIndexEnable; + /** File Write enable */ + bool fileWriteEnable; + /** Overwrite enable */ + bool overwriteEnable; + /** Data Compression Enable - save only hits */ + bool dataCompressionEnable; - /** if frame index required in file name */ - int frameIndexNeeded; - - /* Acquisition started */ - bool acqStarted; - - /* Measurement started */ - bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - uint32_t packetsCaught; - + //***acquisition count parameters*** /** Total packets caught for an entire acquisition (including all scans) */ - uint32_t totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - uint32_t packetsInFile; - - /** Number of missing packets in acquisition*/ - uint32_t numTotMissingPackets; - - /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - uint32_t numTotMissingPacketsInFile; - - /** Number of missing packets per buffer*/ - uint32_t numMissingPackets; - - /** Frame index at start of an entire acquisition (including all scans) */ - uint32_t startAcquisitionIndex; + uint64_t totalPacketsCaught; + /** Frames Caught for each real time acquisition (eg. for each scan) */ + uint64_t packetsCaught; + //***acquisition indices parameters*** /** Actual current frame index of an entire acquisition (including all scans) */ - uint32_t acquisitionIndex; + uint64_t acquisitionIndex; - /** number of packets per frame*/ - int packetsPerFrame; - - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - - /** acquisition period */ - int64_t acquisitionPeriod; - - /** frame number */ - int32_t numberOfFrames; - - /** dynamic range */ - int dynamicRange; - - /** short frames */ - int shortFrame; - - /** current frame number */ - uint32_t currframenum; - - /** Previous Frame number from buffer */ - int prevframenum; - - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** one buffer size */ - int onePacketSize; - - /** one buffer size */ - int oneDataSize; - - /** latest data */ - char* latestData; - - /** gui data ready */ - int guiDataReady; - - /** points to the data to send to gui */ - char* guiData; - - /** points to the filename to send to gui */ - char* guiFileName; - - /** send every nth frame to gui or only upon gui request*/ - int nFrameToGui; - - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** datacompression - save only hits */ - bool dataCompression; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - /** 10Gbe enable*/ - int tengigaEnable; - - /** footer offset is different for 1g and 10g*/ - int footer_offset; - - // TODO: not properly sure where to put these... - /** structure of an eiger image header*/ - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - - /** File Descriptor */ - FILE *sfilefd; - - //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif + //***acquisition parameters*** + /* Short Frame Enable or index of adc enabled, else -1 if all enabled (gotthard specific) TODO: move to setROI */ + int shortFrameEnable; + /** Frequency of Frames sent to GUI */ + uint32_t FrameToGuiFrequency; + //***callback parameters*** /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ + * function being called 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 + */ int (*startAcquisitionCallBack)(char*, char*,int, int, void*); void *pStartAcquisition; /** - args to acquisition finished callback - total frames caught - - */ + * function being called back for acquisition finished + * callback argument is + * total frames caught + */ void (*acquisitionFinishedCallBack)(int, void*); void *pAcquisitionFinished; /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ + * function being called back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); void *pRawDataReady; - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; - /** true if bottom half module for eiger */ - bool bottom; +private: -public: - - - /** - 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 - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; }; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index c1d30ec0b..2e89b59be 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -26,375 +26,471 @@ class UDPInterface { - /* abstract class that defines the UDP interface of an sls detector data receiver. + /* abstract class that defines the UDP interface of an sls detector data receiver. * - * Use the factory method UDPInterface::create() to get an instance: + * Use the factory method UDPInterface::create() to get an instance: + * + * UDPInterface *udp_interface = UDPInterface::create() * - * UDPInterface *udp_interface = UDPInterface::create() * * supported sequence of method-calls: * - * initialize() : once and only once after create() + * initialize() : once and only once after create() //FIXME: only once functionality implemented in the derived REST class, so not mention here? + * + * get*() : anytime after initialize(), multiples times * - * get*() : anytime after initialize(), multiples times * set*() : anytime after initialize(), multiple times * - * startReceiver(): anytime after initialize(). Will fail if state already is 'running' - * - * abort(), - * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. - * - * getStatus() returns the actual state of the data receiver - running or idle. All other - * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * startReceiver(): anytime after initialize(). Will fail if state already is 'running': * * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. * - * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: + * abort(), //FIXME: needed? + * + * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * + * getStatus() returns the actual state of the data receiver - idle, running or error, enum defined in include/sls_receiver_defs.h + * + * + * + * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * + * set methods return nothing, use get methods to validate a set method success + * + * get-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: * * char *c = receiver->getFileName(); - * .... + * Or + * FIXME: so that the pointers are not shared external to the class, do the following way in the calling method? + * char *c = new char[MAX_STR_LENGTH]; + * strcpy(c,receiver->getFileName()); + * .... + * * delete[] c; * - * always: 1:YES 0:NO for int as bool-like arguments + * All pointers passed in externally will be allocated and freed by the calling function + * + * OK and FAIL are defined in include/sls_receiver_defs.h for functions implementing behavior * */ public: + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + /** + * Constructor + * Only non virtual function implemented in this class + * Factory create method to create a standard or REST object + * @param [in] receiver_type type can be standard or REST + * @return a UDPInterface reference to object depending on receiver type + */ + static UDPInterface *create(string receiver_type = "standard"); + /** * Destructor */ virtual ~UDPInterface() {}; - /** - * Factory create method + + + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + + //**initial parameters*** + /* + * Get detector hostname + * @return hostname or NULL if uninitialized, must be released by calling function (max of 1000 characters) */ - static UDPInterface *create(string receiver_type = "standard"); + virtual char *getDetectorHostname() const = 0; - virtual void configure(map config_map) = 0; - - public: - + //***file parameters*** /** - * 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) = 0; - - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - virtual char *getDetectorHostname() const = 0; - - /** - * Returns status of receiver: idle, running or error - */ - virtual slsReceiverDefs::runStatus getStatus() const = 0; - - /** - * Returns File Name - * caller is responsible to deallocate the returned char array. + * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * @return NULL or pointer to file name prefix, must be released by calling function (max of 1000 characters) */ virtual char *getFileName() const = 0; - /** - * Returns File Path - * caller is responsible to deallocate the returned char array + * Get File Path + * @return NULL or pointer to file path, must be released by calling function (max of 1000 characters) */ - virtual char *getFilePath() const = 0; //FIXME: Does the caller need to free() the returned pointer? - + virtual char *getFilePath() const = 0; /** - * Returns the number of bits per pixel + * Get File Index + * @return NULL or file index of acquisition */ - virtual int getDynamicRange() const = 0; + virtual uint64_t getFileIndex() const = 0; /** - * Returns scan tag + * Get Scan Tag + * @return scan tag //FIXME: needed? (unsigned integer?) */ virtual int getScanTag() const = 0; + /** + * Get if Frame Index is enabled (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @return true if frame index needed, else false + */ + virtual bool getFrameIndexEnable() const = 0; + + /** + * Get File Write Enable + * @return true if file write enabled, else false + */ + virtual bool getFileWriteEnable() const = 0; + + /** + * Get File Over Write Enable + * @return true if file over write enabled, else false + */ + virtual bool getOverwriteEnable() const = 0; + + /** + * Get data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @return true if data compression enabled, else false + */ + virtual bool getDataCompressionEnable() const = 0; + + + //***acquisition count parameters*** + /** + * Get Total Frames Caught for an entire acquisition (including all scans) + * @return total number of frames caught for entire acquisition + */ + virtual uint64_t getTotalFramesCaught() const = 0; + + /** + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan + */ + virtual uint64_t getFramesCaught() const = 0; + + /** + * Get Current Frame Index Caught for an entire acquisition (including all scans) + * @return current frame index (represents all scans too) or -1 if no packets caught + */ + virtual int64_t getAcquisitionIndex() const = 0; + + + //***connection parameters*** + /** + * Get UDP Port Number + * @return udp port number + */ + virtual uint32_t getUDPPortNo() const = 0; + + /** + * Get Second UDP Port Number (eiger specific) + * @return second udp port number + */ + virtual uint32_t getUDPPortNo2() const = 0; + + /** + * Get Ehernet Interface + * @return ethernet interface. eg. eth0 (max of 1000 characters) + */ + virtual char *getEthernetInterface() const = 0; + + + //***acquisition parameters*** + /** + * Get Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @return index of adc enabled, else -1 if all enabled + */ + virtual int getShortFrameEnable() const = 0; + + /** + * Get the Frequency of Frames Sent to GUI + * @return 0 for random frame requests, n for nth frame frequency + */ + virtual uint32_t getFrameToGuiFrequency() const = 0; + + /** + * Get Acquisition Period + * @return acquisition period + */ + virtual uint64_t getAcquisitionPeriod() const = 0; + /* - * 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 + * Get Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @return number of frames expected */ - virtual int getNumberOfFrames() const = 0; + virtual uint64_t getNumberOfFrames() const = 0; /** - * Returns file write enable - * 1: YES 0: NO - */ - virtual int getEnableFileWrite() const = 0; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - virtual int getEnableOverwrite() const = 0; - - /** - * 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. + * Get Dynamic Range or Number of Bits Per Pixel + * @return dynamic range that is 4, 8, 16 or 32 */ - virtual char* setFileName(const char c[]) = 0; + virtual uint32_t getDynamicRange() const = 0; + + /** + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) + */ + virtual bool getTenGigaEnable() const = 0; + + //***receiver status*** + /** + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is listening or not + */ + virtual slsReceiverDefs::runStatus getStatus() const = 0; + + + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** + /** + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments + */ + virtual void configure(map config_map) = 0; + + /** + * Set Bottom Enable (eiger specific, should be moved to configure, and later from client via TCPIP) + * @param b is true for bottom enabled or false for bottom disabled + */ + virtual void setBottomEnable(const bool b)= 0; + + + //***file parameters*** + /** + * Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * Does not check for file existence since it is created only at startReceiver + * @param c file name (max of 1000 characters) + */ + virtual void setFileName(const char c[]) = 0; /** * 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. + * Checks for file directory existence before setting file path + * @param c file path (max of 1000 characters) */ - virtual char* setFilePath(const char c[]) = 0; + virtual void setFilePath(const char c[]) = 0; /** - * 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? + * Set File Index of acquisition + * @param i file index of acquisition */ - virtual int setDynamicRange(const int dr) = 0; - + virtual void setFileIndex(const uint64_t i) = 0; /** - * 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 + * Set Scan Tag + * @param i scan tag //FIXME: needed? (unsigned integer?) */ - virtual int setScanTag(const int tag) = 0; + virtual void setScanTag(const int i) = 0; /** - * Sets number of frames - @param fnum number of frames - /returns number of frames + * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @param b true for frame index enable, else false */ - virtual int setNumberOfFrames(const int fnum) = 0; + virtual void setFrameIndexEnable(const bool b) = 0; /** - * Set enable file write - * @param i file write enable - /returns file write enable + * Set File Write Enable + * @param b true for file write enable, else false */ - virtual int setEnableFileWrite(const int i) = 0; + virtual void setFileWriteEnable(const bool b) = 0; /** - * Set enable file overwrite - * @param i file overwrite enable - /returns file overwrite enable + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false */ - virtual int setEnableOverwrite(const int i) = 0; + virtual void setOverwriteEnable(const bool b) = 0; /** - * 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 + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false */ - //FIXME: success == 0 or success == 1? - virtual int startReceiver(char *message=NULL) = 0; //FIXME: who allocates message[]? - - /** - * Stops Receiver - stops listening for packets - /returns success - * same as abort(). Always returns 0. - */ - virtual int stopReceiver() = 0; - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - virtual void abort() = 0; + virtual void setDataCompressionEnable(const bool b) = 0; - -/******************************************************************************************************************* - **************************************** Added by Dhanya ********************************************************* - *******************************************************************************************************************/ - - /** - * Set bottom to bot - * @param bot = 1 if bottom - */ - virtual void setBottom(int bot)= 0; - - /** - * Returns File Index - */ - virtual int getFileIndex() = 0; - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - virtual int getTotalFramesCaught() = 0; - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - virtual int getFramesCaught() = 0; - - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - virtual uint32_t getStartAcquisitionIndex()=0; - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - virtual uint32_t getAcquisitionIndex() = 0; - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - virtual uint32_t getStartFrameIndex() = 0; - - /** get data compression, by saving only hits - */ - virtual bool getDataCompression() = 0; - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - virtual int setDetectorType(slsReceiverDefs::detectorType det) = 0; - - /** - * Set File Index - * @param i file index - */ - virtual int setFileIndex(int i) = 0; - - /** set acquisition period if a positive number - */ - virtual int64_t setAcquisitionPeriod(int64_t index) = 0; - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - virtual int setFrameIndexNeeded(int i) = 0; - + //***connection parameters*** /** * Set UDP Port Number + * @param i udp port number */ - virtual void setUDPPortNo(int p) = 0; + virtual void setUDPPortNo(const uint32_t i) = 0; /** - * Set UDP Port Number + * Set Second UDP Port Number (eiger specific) + * @return second udp port number */ - virtual void setUDPPortNo2(int p) = 0; + virtual void setUDPPortNo2(const uint32_t i) = 0; /** - * Set Ethernet Interface or IP to listen to + * Set Ethernet Interface to listen to + * @param c ethernet inerface eg. eth0 (max of 1000 characters) */ - virtual void setEthernetInterface(char* c) = 0; + virtual void setEthernetInterface(const char* c) = 0; + + + //***connection parameters*** + /** + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled + */ + virtual void setShortFrameEnable(const int i) = 0; /** - * Set short frame - * @param i if shortframe i=1 + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency */ - virtual int setShortFrame(int i) = 0; + virtual void setFrameToGuiFrequency(const uint32_t i) = 0; /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request + * Set Acquisition Period + * @param i acquisition period */ - virtual int setNFrameToGui(int i) = 0; + virtual void setAcquisitionPeriod(const uint64_t i) = 0; /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @param i number of frames expected */ - virtual void resetTotalFramesCaught() = 0; - - /** enabl data compression, by saving only hits - /returns if failed - */ - virtual int enableDataCompression(bool enable) = 0; + virtual void setNumberOfFrames(const uint64_t i) = 0; /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 */ - virtual int enableTenGiga(int enable = -1) = 0; + virtual void setDynamicRange(const uint32_t i) = 0; /** - * 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 startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) */ - virtual void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; + virtual void setTenGigaEnable(const bool b) = 0; - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + //***initial functions*** + /** + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL + */ + virtual int setDetectorType(const slsReceiverDefs::detectorType d) = 0; + + /** + * Sets detector hostname (and corresponding detector variables in derived REST class) + * It is second function called by the client when connecting to receiver. + * you can call this function only once. //FIXME: is this still valid, this implemented in derived REST class? + * @param c detector hostname + */ + virtual void initialize(const char *c) = 0; + + + //***acquisition functions*** + /** + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) + */ + void resetAcquisitionCount(); + + /** + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL + */ + virtual int startReceiver(char *c=NULL) = 0; + + /** + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished + */ + virtual void stopReceiver() = 0; + + /** + * Stop Listening to Packets + * and sets status to Transmitting */ virtual void startReadout() = 0; /** * shuts down the udp sockets - * \returns if success or fail + * \returns OK or FAIL */ virtual int shutDownUDPSockets() = 0; /** - * Closes all files - * @param ithr thread index, -1 for all threads + * Get 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 startAcquisitionIndex start index of the acquisition + * @param startFrameIndex start index of the scan */ - virtual void closeFile(int ithr = -1) = 0; + virtual void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex)=0; /** - * Call back for start acquisition - callback arguments are - filepath - filename - fileindex - datasize + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough? - 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) = 0; + /** + * Closes all files + * @param i thread index, -1 for all threads + */ + virtual void closeFile(int i = -1) = 0; + + + //***callback functions*** + /** + * 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*,uint64_t, uint32_t, void*),void *arg) = 0; /** * Call back for acquisition finished - callback argument is - total frames caught - */ - virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; + * callback argument is + * total frames caught + */ + virtual void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) = 0; /** * 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) = 0; - + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ + virtual void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg) = 0; + + protected: - private: }; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 2916ee6b9..04bd7000e 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -24,6 +24,7 @@ #endif + #include #include #include @@ -199,7 +200,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Set detector hostname * @param c hostname */ - void initialize(const char *detectorHostName); + void setDetectorHostname(const char *detectorHostName); /* Returns detector hostname /returns hostname @@ -484,6 +485,224 @@ private: void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); + + + + + + + + + + + + + + + + + + + + + + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** missing packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** Frame Index at start of an entire acquisition (including all scans) */ + uint64_t startAcquisitionIndex; + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /* Measurement started */ + bool measurementStarted; + /* Acquisition started */ + bool acqStarted; + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Pckets currently in current file, starts new file when it reaches max */ + uint32_t packetsInFile; + + /** Number of missing packets in acquisition*/ + uint32_t numTotMissingPackets; + + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + uint32_t numTotMissingPacketsInFile; + + /** Number of missing packets per buffer*/ + uint32_t numMissingPackets; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + /** Current Frame Number */ + uint64_t currframenum; + + /** Previous Frame number from buffer */ + int prevframenum; + + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ + int bufferSize; + + /** one buffer size */ + int onePacketSize; + + /** one buffer size */ + int oneDataSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + + /** Receiver buffer */ + char *buffer[MAX_NUM_LISTENING_THREADS]; + + /** number of writer threads */ + int numListeningThreads; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current listening thread index*/ + int currentListeningThreadIndex; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllListeningThreads; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + + + /** footer offset is different for 1g and 10g*/ + int footer_offset; + + // TODO: not properly sure where to put these... + /** structure of an eiger image header*/ + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 682c52980..e16060865 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +//#ifdef SLS_RECEIVER_UDP_FUNCTIONS /********************************************//** * @file UDPBaseImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -23,178 +23,204 @@ #include #include -//#include "utilities.h" - using namespace std; +/************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ UDPBaseImplementation::UDPBaseImplementation(){ -} + //**detector parameters*** + strcpy(detHostname,""); + packetsPerFrame = 0; + acquisitionPeriod = 0; + numberOfFrames = 0; + dynamicRange = 16; + tengigaEnable = false; + bottomEnable = false; + //***receiver parameters*** + status = IDLE; -UDPBaseImplementation::~UDPBaseImplementation(){} + //***connection parameters*** + strcpy(eth,""); + for(int i=0;i config_map){ - FILE_LOG(logWARNING) << __AT__ << "doing nothing..."; + //***acquisition count parameters*** + totalPacketsCaught = 0; + packetsCaught = 0; + + //***acquisition indices parameters*** + acquisitionIndex = 0; + + //***acquisition parameters*** + shortFrameEnable = -1; + FrameToGuiFrequency = 0; + + //***callback parameters*** + startAcquisitionCallBack = NULL; + pStartAcquisition = NULL; + acquisitionFinishedCallBack = NULL; + pAcquisitionFinished = NULL; + rawDataReadyCallBack = NULL; + pRawDataReady = NULL; }; +UDPBaseImplementation::~UDPBaseImplementation(){}; -void UDPBaseImplementation::deleteMembers(){ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; + +/************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + +/**initial parameters***/ +char *UDPBaseImplementation::getDetectorHostname() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //not initialized + if(!strlen(detHostname)) + return NULL; + + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,detHostname); + //freed by calling function + return output; } -void UDPBaseImplementation::initializeMembers(){ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; +/***file parameters***/ +char *UDPBaseImplementation::getFileName() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //not initialized + if(!strlen(fileName)) + return NULL; + + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,fileName); + //freed by calling function + return output; } +char *UDPBaseImplementation::getFilePath() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -int UDPBaseImplementation::setDetectorType(detectorType det){ - cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; - cout << "Setting Receiver Type " << endl; + //not initialized + if(!strlen(filePath)) + return NULL; - deleteMembers(); - initializeMembers(); - - myDetectorType = det; - - switch(myDetectorType){ - case GOTTHARD: - cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl; - break; - case MOENCH: - cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl; - break; - case EIGER: - cout << endl << "***** This is a EIGER Receiver *****" << endl << endl; - break; - default: - cout << endl << "***** Unknown Receiver *****" << endl << endl; - return FAIL; - break; - } - /* - //moench variables - if(myDetectorType == GOTTHARD){ - fifosize = GOTTHARD_FIFO_SIZE; - packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; - onePacketSize = GOTTHARD_ONE_PACKET_SIZE; - frameSize = GOTTHARD_BUFFER_SIZE; - bufferSize = GOTTHARD_BUFFER_SIZE; - maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; - packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; - }else if(myDetectorType == MOENCH){ - fifosize = MOENCH_FIFO_SIZE; - packetsPerFrame = MOENCH_PACKETS_PER_FRAME; - onePacketSize = MOENCH_ONE_PACKET_SIZE; - frameSize = MOENCH_BUFFER_SIZE; - bufferSize = MOENCH_BUFFER_SIZE; - maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - frameIndexMask = MOENCH_FRAME_INDEX_MASK; - frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; - packetIndexMask = MOENCH_PACKET_INDEX_MASK; - } - else if(myDetectorType == EIGER){ - fifosize = EIGER_FIFO_SIZE; - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - frameIndexMask = EIGER_FRAME_INDEX_MASK; - frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; - packetIndexMask = EIGER_PACKET_INDEX_MASK; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - if(thread_started) - createListeningThreads(true); - - numListeningThreads = MAX_NUM_LISTENING_THREADS; - } - latestData = new char[frameSize]; - - - setupFifoStructure(); - - if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; - exit (-1); - } - - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - exit (-1); - } - - setThreadPriorities(); - - cout << "Ready..." << endl; - - return OK; - */ - return OK; + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,filePath); + //freed by calling function + return output; } +uint32_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} +int UDPBaseImplementation::getScanTag() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return scanTag;} -void UDPBaseImplementation::setBottom(int bot){bottom=bot;}; +bool UDPBaseImplementation::getFrameIndexEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return frameIndexEnable;} -/*Frame indices and numbers caught*/ +bool UDPBaseImplementation::getFileWriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileWriteEnable;} -bool UDPBaseImplementation::getAcquistionStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return acqStarted;}; +bool UDPBaseImplementation::getOverwriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return overwriteEnable;} -bool UDPBaseImplementation::getMeasurementStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return measurementStarted;}; +bool UDPBaseImplementation::getDataCompressionEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dataCompressionEnable;} -int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (packetsCaught/packetsPerFrame);} +/***acquisition count parameters***/ +uint64_t UDPBaseImplementation::getTotalFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (totalPacketsCaught/packetsPerFrame);} -int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);} +uint64_t UDPBaseImplementation::getFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (packetsCaught/packetsPerFrame);} -uint32_t UDPBaseImplementation::getStartAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startAcquisitionIndex;} +int64_t UDPBaseImplementation::getAcquisitionIndex() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;} - -uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(!packetsCaught) - frameIndex=-1; - else - frameIndex = currframenum - startFrameIndex; - return frameIndex; -} - - -uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(!totalPacketsCaught) - acquisitionIndex=-1; - else - acquisitionIndex = currframenum - startAcquisitionIndex; - //cout<<"acquisitionIndex:"< config_map){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } -inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - FILE_LOG(logDEBUG) << __AT__ << "called"; +void UDPBaseImplementation::setBottomEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + bottomEnable = b; + FILE_LOG(logINFO) << "Bottom Enable:" << bottomEnable; +} + + +/***file parameters***/ +void UDPBaseImplementation::setFileName(const char c[]){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + if(strlen(c)) + strcpy(fileName, c); + FILE_LOG(logINFO) << "File name:" << fileName; +} + +void UDPBaseImplementation::setFilePath(const char c[]){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + if(strlen(c)){ //check if filepath exists struct stat st; @@ -204,1484 +230,209 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEB strcpy(filePath,""); FILE_LOG(logWARNING) << "FilePath does not exist:" << filePath; } + strcpy(filePath, c); } - FILE_LOG(logDEBUG) << __AT__ << getFilePath(); -#ifdef VERBOSE - cout << getFilePath() << " " << filePath << endl; -#endif - return getFilePath(); + FILE_LOG(logINFO) << "File path:" << filePath; +} + +void UDPBaseImplementation::setFileIndex(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + fileIndex = i; + FILE_LOG(logINFO) << "File Index:" << fileIndex; +} + +//FIXME: needed? +void UDPBaseImplementation::setScanTag(const int i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + scanTag = i; + FILE_LOG(logINFO) << "Scan Tag:" << scanTag; + +} + +void UDPBaseImplementation::setFrameIndexEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + frameIndexEnable = b; + FILE_LOG(logINFO) << "Frame Index Enable:" << frameIndexEnable; +} + +void UDPBaseImplementation::setFileWriteEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + fileWriteEnable = b; + FILE_LOG(logINFO) << "File Write Enable:" << fileWriteEnable; +} + +void UDPBaseImplementation::setOverwriteEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + overwriteEnable = b; + FILE_LOG(logINFO) << "Overwrite Enable:" << overwriteEnable; +} + +void UDPBaseImplementation::setDataCompressionEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + dataCompressionEnable = b; + FILE_LOG(logINFO) << "Data Compression Enable:" << dataCompressionEnable; } -char* UDPBaseImplementation::getFileName() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - return (char*)fileName; +/***connection parameters***/ +void UDPBaseImplementation::setUDPPortNo(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + udpPortNum[0] = i; + FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } -inline char* UDPBaseImplementation::setFileName(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - +void UDPBaseImplementation::setUDPPortNo2(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + udpPortNum[1] = i; + FILE_LOG(logINFO) << "udpPortNum[1]:" << udpPortNum[1]; +} + +void UDPBaseImplementation::setEthernetInterface(const char* c){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + strcpy(eth, c); + FILE_LOG(logINFO) << "Ethernet Interface:" << eth; +} + + +/***connection parameters***/ +void UDPBaseImplementation::setShortFrameEnable(const int i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + shortFrameEnable = i; + FILE_LOG(logINFO) << "Short Frame Enable:" << shortFrameEnable; +} + +void UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + FrameToGuiFrequency = i; + FILE_LOG(logINFO) << "Frame To Gui Frequency:" << FrameToGuiFrequency; +} + +void UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + acquisitionPeriod = i; + FILE_LOG(logINFO) << "Acquisition Period:" << acquisitionPeriod; +} + +void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + numberOfFrames = i; + FILE_LOG(logINFO) << "Number of Frames:" << numberOfFrames; +} + +void UDPBaseImplementation::setDynamicRange(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + dynamicRange = i; + FILE_LOG(logINFO) << "Dynamic Range:" << dynamicRange; +} + +void UDPBaseImplementation::setTenGigaEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + tengigaEnable = b; + FILE_LOG(logINFO) << "Ten Giga Enable:" << tengigaEnable; +} + + + +/************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + +/***initial functions***/ +int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + myDetectorType = d; + FILE_LOG(logINFO) << "Detector Type:" << slsDetectorBase::getDetectorType(d); + return OK; +} + +void UDPBaseImplementation::initialize(const char *c){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + if(strlen(c)) - strcpy(fileName,c); - - return getFileName(); + strcpy(detHostname, c); + FILE_LOG(logINFO) << "Detector Hostname:" << detHostname; } -int UDPBaseImplementation::getFileIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return fileIndex; +/***acquisition functions***/ +void UDPBaseImplementation::resetAcquisitionCount(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + totalPacketsCaught = 0; + FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught << endl; } -int UDPBaseImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - if(i>=0) - fileIndex = i; - return getFileIndex(); -} - - -int UDPBaseImplementation::setFrameIndexNeeded(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - frameIndexNeeded = i; - return frameIndexNeeded; -} - - -int UDPBaseImplementation::getEnableFileWrite() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - -return enableFileWrite; -} - -int UDPBaseImplementation::setEnableFileWrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - enableFileWrite=i; - return getEnableFileWrite(); -} - -int UDPBaseImplementation::getEnableOverwrite() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - - return overwrite; -} - -int UDPBaseImplementation::setEnableOverwrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - overwrite=i; - return getEnableOverwrite(); -} - - - - - -/*other parameters*/ - -slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ - return status; -} - - -void UDPBaseImplementation::initialize(const char *detectorHostName){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(strlen(detectorHostName)) - strcpy(detHostname,detectorHostName); -} - - -char *UDPBaseImplementation::getDetectorHostname() const{ - return (char*)detHostname; -} - -void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - strcpy(eth,c); -} - - -void UDPBaseImplementation::setUDPPortNo(int p){ - server_port[0] = p; -} - - -void UDPBaseImplementation::setUDPPortNo2(int p){ - server_port[1] = p; -} - - -int UDPBaseImplementation::getNumberOfFrames() const { - return numberOfFrames; -} - - -int32_t UDPBaseImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(fnum >= 0) - numberOfFrames = fnum; - - return getNumberOfFrames(); -} - - -int UDPBaseImplementation::getScanTag() const{ - return scanTag; -} - - -int32_t UDPBaseImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(stag >= 0) - scanTag = stag; - - return getScanTag(); -} - - -int UDPBaseImplementation::getDynamicRange() const{ - return dynamicRange; -} - -int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Setting Dynamic Range" << endl; - - int olddr = dynamicRange; - if(dr >= 0){ - dynamicRange = dr; - - if(myDetectorType == EIGER){ - - - if(!tengigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - - if(olddr != dr){ - - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;i=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} - - - -int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} - - -bool UDPBaseImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return dataCompression;} - -int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"ERROR: Could not create writer threads\n"); - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - +int UDPBaseImplementation::startReceiver(char *c=NULL){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; return OK; } +void UDPBaseImplementation::stopReceiver(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +void UDPBaseImplementation::startReadout(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +int UDPBaseImplementation::shutDownUDPSockets(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +void UDPBaseImplementation::readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +//FIXME: needed, isnt stopReceiver enough? +void UDPBaseImplementation::abort(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} - - - - - - -/*other functions*/ - - -void UDPBaseImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - cmSub=NULL; - - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); +void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ + acquisitionFinishedCallBack=func; + pAcquisitionFinished=arg; +} +void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ + rawDataReadyCallBack=func; + pRawDataReady=arg; } - -//LEO: it is not clear to me.. -void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - -} - - - - - - - -/** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw,uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //point to gui data - if (guiData == NULL){ - guiData = latestData; - } - - //copy data and filename - strcpy(c,guiFileName); - startAcquisitionIndex = getStartAcquisitionIndex(); - startFrameIndex = getStartFrameIndex(); - - - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - if((nFrameToGui) && (writerthreads_mask)){ - //release after getting data - sem_post(&smp); - } - } -} - - - - - - -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - -} - - - - - -int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //if eth is mistaken with ip address - if (strchr(eth,'.')!=NULL) - strcpy(eth,""); - - shutDownUDPSockets(); - - //if no eth, listen to all - if(!strlen(eth)){ - cout<<"warning:eth is empty.listening to all"<getErrorStatus(); - if(iret){ -#ifdef VERBOSE - cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n",server_port[i], iret); -#endif - return FAIL; - } - } - - return OK; -} - - - - - - - -int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - return OK; -} - - - - - -int UDPBaseImplementation::createListeningThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"< DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not creat dsdasdserwe file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } - */ - FILE_LOG(logDEBUG) << __AT__ << "exited"; - -} - - - - - -int UDPBaseImplementation::startReceiver(char message[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - - -// #ifdef VERBOSE - cout << "Starting Receiver" << endl; //#endif - - - //reset listening thread variables - measurementStarted = false; - //should be set to zero as its added to get next start frame indices for scans for eiger - if(!acqStarted) currframenum = 0; - startFrameIndex = 0; - - for(int i = 0; i < numListeningThreads; ++i) - totalListeningFrameCount[i] = 0; - - //udp socket - if(createUDPSockets() == FAIL){ - strcpy(message,"Could not create UDP Socket(s).\n"); - cout << endl << message << endl; - return FAIL; - } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - - - if(setupWriter() == FAIL){ - //stop udp socket - shutDownUDPSockets(); - - sprintf(message,"Could not create file %s.\n",savefilename); - return FAIL; - } - cout << "Successfully created file(s)" << endl; - - //done to give the gui some proper name instead of always the last file name - if(dataCompression) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); - - //initialize semaphore - sem_init(&smp,1,0); - - //status - pthread_mutex_lock(&status_mutex); - status = RUNNING; - for(i=0;istartListening(); - - return this_pointer; -} - - - -void* UDPBaseImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - ((UDPBaseImplementation*)this_pointer)->startWriting(); - return this_pointer; -} - - - - - - -int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cout << "In startListening() " << endl; -#endif - - thread_started = 1; - - int total; - int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - int imageheader = 0; - if(myDetectorType==EIGER) - imageheader = EIGER_IMAGE_HEADER_SIZE; - - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; -#endif - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - - - while((1<pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; -#endif - - - //receive - if(udpSocket[ithread] == NULL){ - rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; - } - //normal listening - else if(!carryonBufferSize){ - - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - - } - //the remaining packets from previous buffer - else{ -#ifdef VERYDEBUG - cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; - cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - -#ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif - - - - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - - //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; -#endif - - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - break; - default: - - break; - - } - - - // cout<<"*********** "<fnum)<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; -#endif - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - } - - return OK; -} - - - - - - - - - - - - - -int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - return OK; -} - - - - -void UDPBaseImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - -} - - - -void UDPBaseImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " starting"; -int i; - -#ifdef VERYVERBOSE - cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); - exit(-1); - } - //push the last buffer into fifo - if(rc > 0){ - pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << pc << endl; -#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; -#endif - } - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; -#ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif - } - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - cout<<"packetsPerFrame:"<*flist[fnum])(); if (ret==FAIL) - cout << "Error executing the function = " << fnum << endl; + cprintf(RED, "Error executing the function = %d\n",fnum); return ret; } @@ -358,7 +358,7 @@ void slsReceiverTCPIPInterface::staticCloseFile(int p){ int slsReceiverTCPIPInterface::set_detector_type(){ ret=OK; - int retval=FAIL; + detectorType retval=GENERIC; detectorType dr; strcpy(mess,"Could not set detector type range\n"); @@ -377,20 +377,35 @@ int slsReceiverTCPIPInterface::set_detector_type(){ ret=FAIL; } else{ - myDetectorType = dr; + + switch(dr){ + case GOTTHARD: + case PROPIX: + case MOENCH: + case EIGER: + case JUNGFRAUCTB: + case JUNGFRAU: + break; + default: + sprintf(mess,"Unknown detector type: %d\n", dr); + ret = FAIL; + break; + if(ret != FAIL){ #ifndef REST - receiverBase = UDPInterface::create("standard"); - receiverBase->setBottom(bottom); + receiverBase = UDPInterface::create("standard"); + receiverBase->setBottomEnable(bottom); #endif - ret=receiverBase->setDetectorType(dr); - retval = myDetectorType; + myDetectorType = dr; + ret=receiverBase->setDetectorType(myDetectorType); + retval = myDetectorType; + } + } } - } //#ifdef VERBOSE if(ret!=FAIL) cout << "detector type" << dr << endl; else - cout << mess << endl; + cprintf(RED, "%s\n", mess); //#endif #endif @@ -417,7 +432,8 @@ int slsReceiverTCPIPInterface::set_detector_type(){ int slsReceiverTCPIPInterface::set_file_name() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval[MAX_STR_LENGTH] = NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char fName[MAX_STR_LENGTH]; strcpy(mess,"Could not set file name"); @@ -439,8 +455,12 @@ int slsReceiverTCPIPInterface::set_file_name() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - strcpy(retval,receiverBase->setFileName(fName)); + else{ + receiverBase->setFileName(fName); + retval = receiveBase->getFileName(); + if(retval == NULL) + ret = FAIL; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -457,9 +477,15 @@ int slsReceiverTCPIPInterface::set_file_name() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -472,7 +498,8 @@ int slsReceiverTCPIPInterface::set_file_name() { int slsReceiverTCPIPInterface::set_file_dir() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval=NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char fPath[MAX_STR_LENGTH]; strcpy(mess,"Could not set file path\n"); @@ -498,13 +525,12 @@ int slsReceiverTCPIPInterface::set_file_dir() { ret=FAIL; } else{ - strcpy(retval,receiverBase->setFilePath(fPath)); - // if file path doesnt exist - if(strlen(fPath)) - if (strcmp(retval,fPath)){ - strcpy(mess,"receiver file path does not exist\n"); - ret=FAIL; - } + receiverBase->setFilePath(fPath); + retval = receiveBase->getFilePath(); + if(reval == NULL){ + ret = FAIL; + strcpy(mess,"receiver file path does not exist\n"); + } } } @@ -523,9 +549,15 @@ int slsReceiverTCPIPInterface::set_file_dir() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -560,8 +592,13 @@ int slsReceiverTCPIPInterface::set_file_index() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - retval=receiverBase->setFileIndex(index); + else{ + if(index >= 0) + receiverBase->setFileIndex(index); + retval=receiverBase->getFileIndex(); + if(index>=0 && retval!=index) + ret = FAIL; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -578,8 +615,10 @@ int slsReceiverTCPIPInterface::set_file_index() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -617,8 +656,22 @@ int slsReceiverTCPIPInterface::set_frame_index() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - retval=receiverBase->setFrameIndexNeeded(index); + else{ + //client sets to 0, but for receiver it is just an enable + //client uses this value for other detectors not using receiver, + //so implement the interface here + + switch(index){ + case -1: index=0; break; + default: index=1; break; //value is 0 + } + receiverBase->setFrameIndexEnable(index); + retval=receiverBase->getFrameIndexEnable(); + switch(retval){ + case 0: retval=-1; break; + case 1: retval=0; break; + } + } } #ifdef VERBOSE if(ret!=FAIL) @@ -635,8 +688,10 @@ int slsReceiverTCPIPInterface::set_frame_index() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -652,7 +707,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { int slsReceiverTCPIPInterface::setup_udp(){ ret=OK; strcpy(mess,"could not set up udp connection"); - char retval[MAX_STR_LENGTH]=""; + char retval[MAX_STR_LENGTH] = ""; char args[3][MAX_STR_LENGTH]; string temp; @@ -705,8 +760,8 @@ int slsReceiverTCPIPInterface::setup_udp(){ } FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; receiverBase->setEthernetInterface(eth); - cout << eth << endl; + //get mac address from ethernet interface if (ret != FAIL) temp = genericSocket::nameToMac(eth); @@ -715,7 +770,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ ret = FAIL; strcpy(mess,"failed to get mac adddress to listen to\n"); - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); } else{ strcpy(retval,temp.c_str()); @@ -733,8 +788,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(retval,MAX_STR_LENGTH); //return ok/fail @@ -749,8 +806,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ int slsReceiverTCPIPInterface::start_receiver(){ ret=OK; ret=OK; - enum runStatus s; - char cstatus[15]; + enum runStatus s = ERROR; strcpy(mess,"Could not start receiver\n"); // execute action if the arguments correctly arrived @@ -771,22 +827,13 @@ int slsReceiverTCPIPInterface::start_receiver(){ } else { s = receiverBase->getStatus(); - switch (s) { - case ERROR: strcpy(cstatus,"error"); break; - case WAITING: strcpy(cstatus,"waiting"); break; - case RUNNING: strcpy(cstatus,"running"); break; - case TRANSMITTING: strcpy(cstatus,"data"); break; - case RUN_FINISHED: strcpy(cstatus,"finished"); break; - default: strcpy(cstatus,"idle"); break; - } if(s == IDLE) ret=receiverBase->startReceiver(mess); else{ - sprintf(mess,"Cannot start Receiver as it is in %s state\n",cstatus); + sprintf(mess,"Cannot start Receiver as it is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); ret=FAIL; } } - #endif if(ret==OK && socket->differentClients){ @@ -797,6 +844,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -808,7 +856,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ int slsReceiverTCPIPInterface::stop_receiver(){ ret=OK; - + enum runStatus s = ERROR; strcpy(mess,"Could not stop receiver\n"); // execute action if the arguments correctly arrived @@ -821,8 +869,17 @@ int slsReceiverTCPIPInterface::stop_receiver(){ strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else if(receiverBase->getStatus()!=IDLE) - ret=receiverBase->stopReceiver(); + else{ + if(receiverBase->getStatus()!=IDLE) + receiverBase->stopReceiver(); + s = receiverBase->getStatus(); + if(s==IDLE) + ret = OK; + else{ + sprintf(mess,"Could not stop receiver. It is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + ret = FAIL; + } + } #endif if(ret==OK && socket->differentClients){ @@ -832,8 +889,10 @@ int slsReceiverTCPIPInterface::stop_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } //return ok/fail return ret; @@ -860,8 +919,10 @@ int slsReceiverTCPIPInterface::get_status(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -888,8 +949,10 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -918,8 +981,10 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -946,7 +1011,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ ret=FAIL; } else - receiverBase->resetTotalFramesCaught(); + receiverBase->resetAcquisitionCount(); } #endif @@ -957,9 +1022,10 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - + } //return ok/fail return ret; @@ -1006,7 +1072,8 @@ int slsReceiverTCPIPInterface::set_short_frame() { ret=FAIL; } else{ - retval=receiverBase->setShortFrame(index); + receiverBase->setShortFrameEnable(index); + retval = receiverBase->getShortFrameEnable(); shortFrame = retval; if(shortFrame==-1) packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME; @@ -1023,8 +1090,10 @@ int slsReceiverTCPIPInterface::set_short_frame() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1088,7 +1157,6 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; - /*startIndex=receiverBase->getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1203,7 +1271,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1277,7 +1345,6 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1385,7 +1452,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1453,7 +1520,6 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1540,7 +1606,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1802,7 +1868,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1855,8 +1921,13 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ ret = FAIL; strcpy(mess,"cannot set up receiver mode when receiver is running\n"); }*/ - else - retval=receiverBase->setNFrameToGui(index); + else{ + if(index >= 0) + receiverBase->setFrameToGuiFrequency(index); + retval=receiverBase->getFrameToGuiFrequency(); + if(index>=0 && retval!=index) + ret = FAIL; + } } #endif @@ -1868,8 +1939,10 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1907,9 +1980,9 @@ int slsReceiverTCPIPInterface::enable_file_write(){ } else{ if(enable >= 0) - receiverBase->setEnableFileWrite(enable); - retval=receiverBase->getEnableFileWrite(); - if((enable!=-1)&&(enable!=retval)) + receiverBase->setFileWriteEnable(enable); + retval=receiverBase->getFileWriteEnable(); + if(enable>=0 && enable!=retval) ret=FAIL; } } @@ -1922,8 +1995,10 @@ int slsReceiverTCPIPInterface::enable_file_write(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1991,8 +2066,10 @@ int slsReceiverTCPIPInterface::start_readout(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -2029,10 +2106,17 @@ int slsReceiverTCPIPInterface::set_timer() { ret=FAIL; } else{ - if(index[0] == slsReceiverDefs::FRAME_PERIOD) - retval=receiverBase->setAcquisitionPeriod(index[1]); - else - retval=receiverBase->setNumberOfFrames(index[1]); + if(index[0] == slsReceiverDefs::FRAME_PERIOD){ + if(index[1]>=0) + receiverBase->setAcquisitionPeriod(index[1]); + retval=receiverBase->getAcquisitionPeriod(); + }else{ + if(index[1]>=0) + receiverBase->setNumberOfFrames(index[1]); + retval=receiverBase->getNumberOfFrames(); + } + if(index[1]>=0 && retval!=index[1]) + ret = FAIL; } } #ifdef VERBOSE @@ -2053,8 +2137,10 @@ int slsReceiverTCPIPInterface::set_timer() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2095,15 +2181,21 @@ int slsReceiverTCPIPInterface::enable_compression() { strcpy(mess,"Cannot enable/disable compression while status is running\n"); ret=FAIL; } - else - ret = receiverBase->enableDataCompression(enable); + else{ + if(enable >= 0) + receiverBase->setDataCompressionEnable(enable); + } } if (receiverBase == NULL){ strcpy(mess,"Receiver not set up\n"); ret=FAIL; - }else - retval=receiverBase->getDataCompression(); + }else{ + retval = receiverBase->getDataCompressionEnable(); + if(enable >= 0 && retval != enable) + ret = FAIL; + } + } #endif @@ -2114,8 +2206,10 @@ int slsReceiverTCPIPInterface::enable_compression() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2127,7 +2221,8 @@ int slsReceiverTCPIPInterface::enable_compression() { int slsReceiverTCPIPInterface::set_detector_hostname() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval = NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char hostname[MAX_STR_LENGTH]=""; strcpy(mess,"Could not set detector hostname"); @@ -2151,7 +2246,10 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } else{ receiverBase->initialize(hostname); - strcpy(retval,receiverBase->getDetectorHostname()); + retval = receiverBase->getDetectorHostname(); + if(retval == NULL){ + ret = FAIL; + } } } #ifdef VERBOSE @@ -2169,9 +2267,14 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval!=NULL) delete[] retval; //return ok/fail return ret; @@ -2203,14 +2306,14 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if ((dr>0) && (myDetectorType == EIGER)){ + else if (dr>0) { switch(dr){ case 4: case 8: case 16: case 32:break; default: - sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + sprintf(mess,"This dynamic range does not exist: %d\n",dr); cprintf(RED,"%s", mess); ret=FAIL; break; @@ -2221,14 +2324,19 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; }else{ - if(dr > 0) receiverBase->setDynamicRange(dr); + if(dr > 0) + receiverBase->setDynamicRange(dr); retval = receiverBase->getDynamicRange(); - dynamicrange = retval; - if(myDetectorType == EIGER){ - if(!tenGigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + if(dr > 0 && retval != dr) + ret = FAIL; + else{ + dynamicrange = retval; + if(myDetectorType == EIGER){ + if(!tenGigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + } } } } @@ -2248,8 +2356,10 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2288,8 +2398,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { } else{ if(index >= 0) - receiverBase->setEnableOverwrite(index); - retval=receiverBase->getEnableOverwrite(); + receiverBase->setOverwriteEnable(index); + retval=receiverBase->getOverwriteEnable(); + if(index >=0 && retval != index) + ret = FAIL; } } #ifdef VERBOSE @@ -2307,8 +2419,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2346,8 +2460,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { ret=FAIL; } else{ - retval=receiverBase->enableTenGiga(val); - if((val!=-1) && (val != retval)) + if(val >= 0) + receiverBase->setDataCompressionEnable(val); + retval=receiverBase->getDataCompressionEnable(); + if((val >= 0) && (val != retval)) ret = FAIL; else tenGigaEnable = retval; @@ -2368,8 +2484,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2436,8 +2554,10 @@ int slsReceiverTCPIPInterface::lock_receiver() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } else socket->SendDataOnly(&lockStatus,sizeof(lockStatus)); @@ -2509,9 +2629,10 @@ int slsReceiverTCPIPInterface::set_port() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); - } else { + }else { socket->SendDataOnly(&p_number,sizeof(p_number)); if(sd>=0){ socket->Disconnect(); @@ -2550,7 +2671,8 @@ int slsReceiverTCPIPInterface::get_last_client_ip() { int slsReceiverTCPIPInterface::send_update() { ret=OK; int ind; - char path[MAX_STR_LENGTH]; + char defaultVal[MAX_STR_LENGTH]=""; + char* path = NULL; socket->SendDataOnly(socket->lastClientIP,sizeof(socket->lastClientIP)); @@ -2564,17 +2686,26 @@ int slsReceiverTCPIPInterface::send_update() { //filepath #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,receiverBase->getFilePath()); + path = receiverBase->getFilePath(); #endif - socket->SendDataOnly(path,MAX_STR_LENGTH); + if(path == NULL) + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + else{ + socket->SendDataOnly(path,MAX_STR_LENGTH); + delete[] path; + } //filename #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,receiverBase->getFileName()); + path = receiverBase->getFileName(); #endif - socket->SendDataOnly(path,MAX_STR_LENGTH); - + if(path == NULL) + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + else{ + socket->SendDataOnly(path,MAX_STR_LENGTH); + delete[] path; + } if (lockStatus==0) { strcpy(socket->lastClientIP,socket->thisClientIP); @@ -2597,7 +2728,8 @@ int slsReceiverTCPIPInterface::update_client() { ret=FAIL; } socket->SendDataOnly(&ret,sizeof(ret)); - if(ret == FAIL){ + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); return ret; } @@ -2616,7 +2748,7 @@ int slsReceiverTCPIPInterface::exit_server() { socket->SendDataOnly(&ret,sizeof(ret)); strcpy(mess,"closing server"); socket->SendDataOnly(mess,sizeof(mess)); - cout << mess << endl; + cprintf(RED,"%s\n",mess); return ret; }