This commit is contained in:
bergamaschi 2016-02-12 11:09:47 +01:00
commit 75a75f3328
22 changed files with 5116 additions and 8991 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,6 @@
#include "sls_receiver_defs.h" #include "sls_receiver_defs.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include "MySocketTCP.h"
#include "utilities.h" #include "utilities.h"
#include "logger.h" #include "logger.h"
@ -26,376 +24,492 @@
class UDPInterface { 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: * 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 * set*() : anytime after initialize(), multiple times
* *
* startReceiver(): anytime after initialize(). Will fail if state already is 'running' * startReceiver(): anytime after initialize(). Will fail in TCPIP itself 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.
* *
* Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. * 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.
* Otherwise, sets status to transmitting when shutting down sockets
* then to run_finished when all data obtained
* then to idle when returning from this function
*
*
* 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(); * 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; * 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: 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 * Destructor
*/ */
virtual ~UDPInterface() {}; 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<string, string> config_map) = 0;
//***file parameters***
public:
/** /**
* Initialize the Receiver * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
@param detectorHostName detector hostname * @return NULL or pointer to file name prefix, must be released by calling function (max of 1000 characters)
* 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.
*/ */
virtual char *getFileName() const = 0; virtual char *getFileName() const = 0;
/** /**
* Returns File Path * Get File Path
* caller is responsible to deallocate the returned char array * @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; 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 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 getUDPPortNumber() const = 0;
/**
* Get Second UDP Port Number (eiger specific)
* @return second udp port number
*/
virtual uint32_t getUDPPortNumber2() 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 * Get Number of Frames expected by receiver from detector
* This is the number of frames to expect to receiver from the detector. * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented)
* The data receiver will change from running to idle when it got this number of frames * @return number of frames expected
*/ */
virtual int getNumberOfFrames() const = 0; virtual uint64_t getNumberOfFrames() const = 0;
/** /**
* Returns file write enable * Get Dynamic Range or Number of Bits Per Pixel
* 1: YES 0: NO * @return dynamic range that is 4, 8, 16 or 32
*/
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.
*/ */
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;
/**
* Get Fifo Depth
* @return fifo depth
*/
virtual uint32_t getFifoDepth() 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<string, string> 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 * Set File Path
@param c file path * Checks for file directory existence before setting file path
/returns file path * @param c file path (max of 1000 characters)
* checks the existence of the directory. returns NULL if directory does not exist or is not readable.
* caller is responsible to deallocate the returned char array.
*/ */
virtual char* setFilePath(const char c[]) = 0; virtual void setFilePath(const char c[]) = 0;
/** /**
* Returns the number of bits per pixel * Set File Index of acquisition
@param dr sets dynamic range * @param i file index of acquisition
/returns dynamic range
* returns -1 on failure
* FIXME: what are the allowd values - should we use an enum as argument?
*/ */
virtual int setDynamicRange(const int dr) = 0; virtual void setFileIndex(const uint64_t i) = 0;
/** /**
* Set scan tag * Set Scan Tag
@param tag scan tag * @param i scan tag //FIXME: needed? (unsigned integer?)
/returns scan tag (always non-negative)
* FIXME: valid range - only positive? 16bit ore 32bit?
* returns -1 on failure
*/ */
virtual int setScanTag(const int tag) = 0; virtual void setScanTag(const int i) = 0;
/** /**
* Sets number of frames * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name )
@param fnum number of frames * @param b true for frame index enable, else false
/returns number of frames
*/ */
virtual int setNumberOfFrames(const int fnum) = 0; virtual void setFrameIndexEnable(const bool b) = 0;
/** /**
* Set enable file write * Set File Write Enable
* @param i file write enable * @param b true for file write enable, else false
/returns file write enable
*/ */
virtual int setEnableFileWrite(const int i) = 0; virtual void setFileWriteEnable(const bool b) = 0;
/** /**
* Set enable file overwrite * Set File Overwrite Enable
* @param i file overwrite enable * @param b true for file overwrite enable, else false
/returns file overwrite enable
*/ */
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 * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard)
@param message is the error message if there is an error * @param b true for data compression enable, else false
/returns 0 on success or -1 on failure * @return OK or FAIL
*/ */
//FIXME: success == 0 or success == 1? virtual int setDataCompressionEnable(const bool b) = 0;
virtual int startReceiver(char *message=NULL) = 0; //FIXME: who allocates message[]?
//***connection parameters***
/**
* Set UDP Port Number
* @param i udp port number
*/
virtual void setUDPPortNumber(const uint32_t i) = 0;
/** /**
* Stops Receiver - stops listening for packets * Set Second UDP Port Number (eiger specific)
/returns success * @return second udp port number
* same as abort(). Always returns 0.
*/ */
virtual int stopReceiver() = 0; virtual void setUDPPortNumber2(const uint32_t i) = 0;
/**
* Set Ethernet Interface to listen to
* @param c ethernet inerface eg. eth0 (max of 1000 characters)
*/
virtual void setEthernetInterface(const char* c) = 0;
//***acquisition 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 the Frequency of Frames Sent to GUI
* @param i 0 for random frame requests, n for nth frame frequency
* @return OK or FAIL
*/
virtual int setFrameToGuiFrequency(const uint32_t i) = 0;
/**
* Set Acquisition Period
* @param i acquisition period
* @return OK or FAIL
*/
virtual int setAcquisitionPeriod(const uint64_t i) = 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 setNumberOfFrames(const uint64_t i) = 0;
/**
* Set Dynamic Range or Number of Bits Per Pixel
* @param i dynamic range that is 4, 8, 16 or 32
* @return OK or FAIL
*/
virtual int setDynamicRange(const uint32_t i) = 0;
/**
* Set Ten Giga Enable
* @param b true if 10Giga enabled, else false (1G enabled)
* @return OK or FAIL
*/
virtual int setTenGigaEnable(const bool b) = 0;
/**
* Set Fifo Depth
* @param i fifo depth value
* @return OK or FAIL
*/
virtual int setFifoDepth(const uint32_t i) = 0;
/*************************************************************************
* 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)
*/
virtual void resetAcquisitionCount() = 0;
/**
* 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 and deletes UDP Sockets
* @return OK or FAIL
*/
virtual int shutDownUDPSockets() = 0;
/**
* 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 startAcq start index of the acquisition
* @param startFrame start index of the scan
*/
virtual void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame)=0;
/** /**
* abort acquisition with minimum damage: close open files, cleanup. * abort acquisition with minimum damage: close open files, cleanup.
* does nothing if state already is 'idle' * does nothing if state already is 'idle'
*/ */
virtual void abort() = 0; virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough?
/*******************************************************************************************************************
**************************************** Added by Dhanya *********************************************************
*******************************************************************************************************************/
/** /**
* Set bottom to bot * Closes file / all files(if multiple files)
* @param bot = 1 if bottom * @param i thread index (if multiple files used eg. root files) -1 for all threads
*/ */
virtual void setBottom(int bot)= 0; virtual void closeFile(int i = -1) = 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;
/**
* Set UDP Port Number
*/
virtual void setUDPPortNo(int p) = 0;
/**
* Set UDP Port Number
*/
virtual void setUDPPortNo2(int p) = 0;
/**
* Set Ethernet Interface or IP to listen to
*/
virtual void setEthernetInterface(char* c) = 0;
/**
* Set short frame
* @param i if shortframe i=1
*/
virtual int setShortFrame(int i) = 0;
/**
* Set the variable to send every nth frame to gui
* or if 0,send frame only upon gui request
*/
virtual int setNFrameToGui(int i) = 0;
/**
* Resets the Total Frames Caught
* This is how the receiver differentiates between entire acquisitions
* Returns 0
*/
virtual void resetTotalFramesCaught() = 0;
/** enabl data compression, by saving only hits
/returns if failed
*/
virtual int enableDataCompression(bool enable) = 0;
/**
* enable 10Gbe
@param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out
\returns enable for 10Gbe
*/
virtual int enableTenGiga(int enable = -1) = 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 fnum frame number for eiger as it is not in the packet
* @param startAcquisitionIndex is the start index of the acquisition
* @param startFrameIndex is the start index of the scan
*/
virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0;
/** set status to transmitting and
* when fifo is empty later, sets status to run_finished
*/
virtual void startReadout() = 0;
/**
* shuts down the udp sockets
* \returns if success or fail
*/
virtual int shutDownUDPSockets() = 0;
/**
* Closes all files
* @param ithr thread index, -1 for all threads
*/
virtual void closeFile(int ithr = -1) = 0;
//***callback functions***
/** /**
* Call back for start acquisition * Call back for start acquisition
callback arguments are * callback arguments are
filepath * filepath
filename * filename
fileindex * fileindex
datasize * datasize
*
return value is * return value is
0 callback takes care of open,close,wrie file * 0 callback takes care of open,close,wrie file
1 callback writes file, we have to open, close it * 1 callback writes file, we have to open, close it
2 we open, close, write file, callback does not do anything * 2 we open, close, write file, callback does not do anything
*/ */
virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0; virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0;
/** /**
* Call back for acquisition finished * Call back for acquisition finished
callback argument is * callback argument is
total frames caught * total frames caught
*/ */
virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0;
/** /**
* Call back for raw data * Call back for raw data
args to raw data ready callback are * args to raw data ready callback are
framenum * framenum
datapointer * datapointer
datasize in bytes * datasize in bytes
file descriptor * file descriptor
guidatapointer (NULL, no data required) * guidatapointer (NULL, no data required)
*/ */
virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0;
protected: protected:
private: private:
}; };

View File

@ -7,36 +7,21 @@
***********************************************/ ***********************************************/
#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 "UDPBaseImplementation.h" #include "UDPBaseImplementation.h"
#ifdef MYROOT1
#include <TTree.h>
#include <TFile.h>
#endif
#include "RestHelper.h" #include "RestHelper.h"
#include <string.h> #include <string.h>
#include <pthread.h>
#include <stdio.h> #include <stdio.h>
#include <semaphore.h>
/** /**
* @short does all the functions for a receiver, set/get parameters, start/stop etc. * @short does all the functions for a receiver, set/get parameters, start/stop etc.
*/ */
class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation { class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation {
public:
public: /*************************************************************************
* Constructor & Destructor **********************************************
*************************************************************************/
/** /**
* Constructor * Constructor
*/ */
@ -49,787 +34,116 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI
protected: protected:
void initialize_REST();
/*************************************************************************
* Getters ***************************************************************
* They access local cache of configuration or detector parameters *******
*************************************************************************/
/**
* Get Rest State
*/
int get_rest_state(RestHelper * rest, string *rest_state); int get_rest_state(RestHelper * rest, string *rest_state);
/*************************************************************************
* Setters ***************************************************************
* They modify the local cache of configuration or detector parameters ***
*************************************************************************/
/**
* Initialize REST
*/
void initialize_REST();
public: public:
/*************************************************************************
* Getters ***************************************************************
* They access local cache of configuration or detector parameters *******
*************************************************************************/
/*************************************************************************
* Setters ***************************************************************
* They modify the local cache of configuration or detector parameters ***
*************************************************************************/
/**
* Overridden method
* Configure command line parameters
* @param config_map mapping of config parameters passed from command line arguments
*/
void configure(map<string, string> config_map); void configure(map<string, string> config_map);
/**
* delete and free member parameters /*************************************************************************
*/ * Behavioral functions***************************************************
void deleteMembers(); * They may modify the status of the receiver ****************************
*************************************************************************/
/** /**
* initialize member parameters * Overridden method
* Start Listening for Packets by activating all configuration settings to receiver
* When this function returns, it has status RUNNING(upon SUCCESS) or IDLE (upon failure)
* @param c error message if FAIL
* @return OK or FAIL
*/ */
//void initializeMembers(); int startReceiver(char *c=NULL);
/** /**
* Set detector hostname * Overridden method
* @param c hostname * Stop Listening for Packets
* Calls startReadout(), which stops listening and sets status to Transmitting
* When it has read every frame in buffer, the status changes to Run_Finished
* When this function returns, receiver has status IDLE
* Pre: status is running, semaphores have been instantiated,
* Post: udp sockets shut down, status is idle, semaphores destroyed
*/ */
//void initialize(const char *detectorHostName); void stopReceiver();
/* Returns detector hostname
/returns hostname
* caller needs to deallocate the returned char array.
* if uninitialized, it must return NULL
*/
//char *getDetectorHostname() const;
/** /**
* Set receiver type * Overridden method
* @param det detector type * Stop Listening to Packets
* Returns success or FAIL * and sets status to Transmitting
*/ * Next step would be to get all data and stop receiver completely and return with idle state
//int setDetectorType(detectorType det); * Pre: status is running, udp sockets have been initialized, stop receiver initiated
* Post:udp sockets closed, status is transmitting,
//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 Ethernet Interface or IP to listen to
*/
void setEthernetInterface(char* c);
/**
* Set UDP Port Number
*/
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;
/**
* set frame number if a positive number
*/
//int32_t setNumberOfFrames(int32_t fnum);
/**
* Returns scan tag
*/
//int getScanTag() const;
/**
* set scan tag if its is a positive number
*/
//int32_t setScanTag(int32_t stag);
/**
* Returns the number of bits per pixel
*/
//int getDynamicRange() const;
/**
* set dynamic range if its is a positive number
*/
int32_t setDynamicRange(int32_t dr);
/**
* Set short frame
* @param i if shortframe i=1
*/
int setShortFrame(int i);
/**
* Set the variable to send every nth frame to gui
* or if 0,send frame only upon gui request
*/
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);
/**
* enable 10Gbe
@param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out
\returns enable for 10Gbe
*/
int enableTenGiga(int enable = -1);
//other functions
/**
* Returns the buffer-current frame read by receiver
* @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet
* @param startAcquisitionIndex is the start index of the acquisition
* @param startFrameIndex is the start index of the scan
*/
void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex);
/**
* Closes all files
* @param ithr thread index
*/
void closeFile(int ithr = -1);
/**
* Starts Receiver - starts to listen for packets
* @param message is the error message if there is an error
* Returns success
*/
int startReceiver(char message[]);
/**
* Stops Receiver - stops listening for packets
* Returns success
*/
int stopReceiver();
/** set status to transmitting and
* when fifo is empty later, sets status to run_finished
*/ */
void startReadout(); void startReadout();
/** /**
* shuts down the udp sockets * Overridden method
* \returns if success or fail * Shuts down and deletes UDP Sockets
* TCPIPInterface can also call this in case of illegal shutdown of receiver
* @return OK or FAIL
*/ */
int shutDownUDPSockets(); int shutDownUDPSockets();
/**
* Overridden method
* 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 startAcq start index of the acquisition
* @param startFrame start index of the scan
*/
void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame);
/**
* Overridden method
* Closes file / all files(data compression involves multiple files)
* TCPIPInterface can also call this in case of illegal shutdown of receiver
* @param i thread index valid for datacompression using root files, -1 for all threads
*/
void closeFile(int i = -1);
private: private:
/*
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
*/
void deleteFilter();
/**
* Constructs the filter for single photon data
*/
void setupFilter();
/**
* set up fifo according to the new numjobsperthread
*/
void setupFifoStructure ();
/**
* Copy frames to gui
* uses semaphore for nth frame mode
*/
void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL);
/**
* 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()
*
*/
int startListening();
/**
* Thread started which writes packets to file.
* Called by startReceiver()
*
*/
int startWriting();
/**
* 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
*/
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 npackets number of packets from the fifo
* @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[], int &npackets, char* data, int xmax, int ymax, int &nf);
/** structure of an eiger image header*/
typedef struct
{
unsigned char header_before[20];
unsigned char fnum[4];
unsigned char header_after[24];
} eiger_image_header;
/** structure of an eiger image header*/
typedef struct
{
unsigned char num1[4];
unsigned char num2[4];
} eiger_packet_header;
/** 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;
/** detector type */
//detectorType myDetectorType;
/** detector hostname */
//char detHostname[MAX_STR_LENGTH];
/** status of receiver */
//runStatus status;
/** UDP Socket between Receiver and Detector */
//genericSocket* udpSocket[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*/
//char fileName[MAX_STR_LENGTH];
/** File Path */
//char filePath[MAX_STR_LENGTH];
/** File Index */
//int fileIndex;
/** scan tag */
//int scanTag;
/** 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) */
//int packetsCaught;
/** Total packets caught for an entire acquisition (including all scans) */
//int totalPacketsCaught;
/** Pckets currently in current file, starts new file when it reaches max */
//int packetsInFile;
/** Frame index at start of an entire acquisition (including all scans) */
//uint32_t startAcquisitionIndex;
/** Actual current frame index of an entire acquisition (including all scans) */
//uint32_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 */
//uint32_t 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;
/** oen buffer size */
//int onePacketSize;
/** 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;
/** temporary number for eiger frame number as its not included in the packet */
//uint32_t guiFrameNumber;
/** 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<char>* fifo[MAX_NUM_LISTENING_THREADS];
/** circular fifo to store addresses of data already written and ready to be resued*/
//CircularFifo<char>* fifoFree[MAX_NUM_LISTENING_THREADS];
/** Receiver buffer */
//char *buffer[MAX_NUM_LISTENING_THREADS];
/** number of writer threads */
//intt 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;
//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<uint16_t> *singlePhotonDet[MAX_NUM_WRITER_THREADS];
//slsReceiverData<uint16_t> *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
/**
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
*/
int (*startAcquisitionCallBack)(char*, char*,int, int, void*);
void *pStartAcquisition;
/**
args to acquisition finished callback
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)
*/
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;
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;};
//REST specific
bool isInitialized; bool isInitialized;
RestHelper * rest ; RestHelper * rest ;
int rest_port; // receiver backend port int rest_port; // receiver backend port
string rest_hostname; // receiver hostname string rest_hostname; // receiver hostname
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,18 @@
#define RED "\x1b[31m" #define RED "\x1b[31m"
#define GREEN "\x1b[32m" #define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m" #define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m" #define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m" #define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m" #define CYAN "\x1b[36m"
#define BG_RED "\x1b[41m" #define GRAY "\x1b[37m"
#define BG_GREEN "\x1b[42m" #define BG_RED "\x1b[41m"
#define BG_YELLOW "\x1b[43m" #define BG_GREEN "\x1b[42m"
#define BG_BLUE "\x1b[44m" #define BG_YELLOW "\x1b[43m"
#define BG_MAGENTA "\x1b[45m" #define BG_BLUE "\x1b[44m"
#define BG_CYAN "\x1b[46m" #define BG_MAGENTA "\x1b[45m"
#define RESET "\x1b[0m" #define BG_CYAN "\x1b[46m"
#define BOLD "\x1b[1m" #define RESET "\x1b[0m"
#define BOLD "\x1b[1m"
#define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__) #define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__)

View File

@ -78,7 +78,11 @@ int CircularFifo<Element>::getSemValue()
template<typename Element> template<typename Element>
bool CircularFifo<Element>::push(Element*& item_) bool CircularFifo<Element>::push(Element*& item_)
{ {
int nextTail = increment(tail);
//cout<<"*head:"<<head<<endl;
//cout<<"*tail before"<<tail<<endl;
unsigned int nextTail = increment(tail);
//cout<<"*next tail"<<nextTail<<endl;
if(nextTail != head) if(nextTail != head)
{ {
array[tail] = item_; array[tail] = item_;
@ -99,12 +103,15 @@ bool CircularFifo<Element>::push(Element*& item_)
template<typename Element> template<typename Element>
bool CircularFifo<Element>::pop(Element*& item_) bool CircularFifo<Element>::pop(Element*& item_)
{ {
// if(head == tail) //cout<<"-tail:"<<tail<<endl;
// return false; // empty queue //cout<<"-head before:"<<head<<endl;
//if(head == tail)
// return false; // empty queue
sem_wait(&free_mutex); sem_wait(&free_mutex);
item_ = array[head]; item_ = array[head];
head = increment(head); head = increment(head);
//cout<<"-head after:"<<head<<endl;
return true; return true;
} }

View File

@ -93,19 +93,7 @@ enum communicationProtocol{
UDP /**< UDP */ UDP /**< UDP */
}; };
typedef struct
{
unsigned char header_before[20];
unsigned char fnum[4];
unsigned char header_after[24];
} eiger_image_header;
typedef struct
{
unsigned char header_before[19];
unsigned char fnum[4];
unsigned char header_after[25];
} eiger_image_header32;
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) :
// portno(port_number), // portno(port_number),
@ -123,6 +111,12 @@ typedef struct
// serverAddress = {0}; // serverAddress = {0};
// clientAddress = {0}; // clientAddress = {0};
// strcpy(hostname,host_ip_or_name); // strcpy(hostname,host_ip_or_name);
strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1");
strcpy(dummyClientIP,"dummy");
differentClients = 0;
struct hostent *hostInfo = gethostbyname(host_ip_or_name); struct hostent *hostInfo = gethostbyname(host_ip_or_name);
if (hostInfo == NULL){ if (hostInfo == NULL){
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
@ -177,16 +171,17 @@ typedef struct
nsent(0), nsent(0),
total_sent(0) total_sent(0)
{ {
//memset(&serverAddress, 0, sizeof(sockaddr_in));
// memset(&clientAddress, 0, sizeof(sockaddr_in));
// serverAddress = {0};
// clientAddress = {0};
/* // you can specify an IP address: */
/* */
/* // you can specify an IP address: */
/* // or you can let it automatically select one: */ /* // or you can let it automatically select one: */
/* myaddr.sin_addr.s_addr = INADDR_ANY; */ /* myaddr.sin_addr.s_addr = INADDR_ANY; */
strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1");
strcpy(dummyClientIP,"dummy");
differentClients = 0;
if(serverAddress.sin_port == htons(port_number)){ if(serverAddress.sin_port == htons(port_number)){
socketDescriptor = -10; socketDescriptor = -10;
return; return;
@ -582,45 +577,43 @@ typedef struct
int ReceiveDataOnly(void* buf,int length=0){ int ReceiveDataOnly(void* buf,int length=0){
if (buf==NULL) return -1;
total_sent=0; if (buf==NULL) return -1;
switch(protocol) {
case TCP:
if (file_des<0) return -1;
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
nsent = read(file_des,(char*)buf+total_sent,nsending);
if(!nsent) break;
length-=nsent;
total_sent+=nsent;
}
break;
case UDP:
if (socketDescriptor<0) return -1;
/*
cout <<"******listening inside genericsocket"<<endl;
for(int i=0;i<10000;i++){
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,5000, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
cout<<i<<":"<<nsent<<"\t\t";
}
exit(-1);
*/
//if length given, listens to length, else listens for packetsize till length is reached total_sent=0;
if(length){
/*int k = 0;*/
while(length>0){ switch(protocol) {
nsending = (length>packet_size) ? packet_size:length; case TCP:
if (file_des<0) return -1;
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
nsent = read(file_des,(char*)buf+total_sent,nsending);
if(!nsent) break;
length-=nsent;
total_sent+=nsent;
}
/* if (total_sent>0)
strcpy(thisClientIP,dummyClientIP);
if (strcmp(lastClientIP,thisClientIP))
differentClients=1;
else
differentClients=0;
break;
case UDP:
if (socketDescriptor<0) return -1;
//if length given, listens to length, else listens for packetsize till length is reached
if(length){
/*int k = 0;*/
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
/*
//created for debugging on 11.05.2015 //created for debugging on 11.05.2015
nsending=5000; nsending=5000;
nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
@ -636,44 +629,32 @@ typedef struct
} }
else else
k++; k++;
*/ */
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
if(!nsent) break;
length-=nsent;
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); total_sent+=nsent;
if(!nsent) break; }
if(nsent == 16) { }
//cout << "."; //listens to only 1 packet
continue; else{
} //normal
length-=nsent; nsending=packet_size;
total_sent+=nsent; nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
} //nsent = 1040;
} total_sent+=nsent;
//listens to only 1 packet }
else{ break;
//normal default:
nsending=packet_size; ;
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); }
total_sent+=nsent;
}
break;
default:
;
}
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
cout << "sent "<< total_sent << " Bytes" << endl; cout << "sent "<< total_sent << " Bytes" << endl;
#endif #endif
if (total_sent>0)
strcpy(thisClientIP,dummyClientIP);
if (strcmp(lastClientIP,thisClientIP))
differentClients=1;
else
differentClients=0;
return total_sent; return total_sent;
} }
@ -729,21 +710,12 @@ typedef struct
protected: protected:
communicationProtocol protocol; communicationProtocol protocol;
int is_a_server; int is_a_server;
int socketDescriptor; int socketDescriptor;
int file_des; int file_des;
int packet_size; int packet_size;
struct sockaddr_in clientAddress, serverAddress; struct sockaddr_in clientAddress, serverAddress;
socklen_t clientAddress_length; socklen_t clientAddress_length;
char dummyClientIP[INET_ADDRSTRLEN]; char dummyClientIP[INET_ADDRSTRLEN];

View File

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <ansi.h>
#ifdef VERBOSE #ifdef VERBOSE
#define FILELOG_MAX_LEVEL logDEBUG #define FILELOG_MAX_LEVEL logDEBUG
@ -14,6 +15,10 @@
#define FILELOG_MAX_LEVEL logDEBUG4 #define FILELOG_MAX_LEVEL logDEBUG4
#endif #endif
#ifdef FIFODEBUG
#define FILELOG_MAX_LEVEL logDEBUG5
#endif
#ifndef FILELOG_MAX_LEVEL #ifndef FILELOG_MAX_LEVEL
#define FILELOG_MAX_LEVEL logINFO #define FILELOG_MAX_LEVEL logINFO
#endif #endif
@ -23,6 +28,12 @@
#define TOSTRING(x) STRINGIFY(x) #define TOSTRING(x) STRINGIFY(x)
#define MYCONCAT(x,y) #define MYCONCAT(x,y)
#define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ") #define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ")
#define __SHORT_FORM_OF_FILE__ \
(strrchr(__FILE__,'/') \
? strrchr(__FILE__,'/')+1 \
: __FILE__ \
)
#define __SHORT_AT__ string(__SHORT_FORM_OF_FILE__) + string("::") + string(__func__) + string("(): ")
//":" TOSTRING(__LINE__) //":" TOSTRING(__LINE__)
@ -34,7 +45,7 @@ void error(const char *location, const char *msg){
inline std::string NowTime(); inline std::string NowTime();
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
template <typename T> class Log{ template <typename T> class Log{
public: public:
@ -46,6 +57,7 @@ template <typename T> class Log{
static TLogLevel FromString(const std::string& level); static TLogLevel FromString(const std::string& level);
protected: protected:
std::ostringstream os; std::ostringstream os;
TLogLevel lev;
private: private:
Log(const Log&); Log(const Log&);
Log& operator =(const Log&); Log& operator =(const Log&);
@ -56,6 +68,7 @@ class Output2FILE {
public: public:
static FILE*& Stream(); static FILE*& Stream();
static void Output(const std::string& msg); static void Output(const std::string& msg);
static void Output(const std::string& msg, TLogLevel level);
}; };
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
@ -73,10 +86,17 @@ public:
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {}; class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
//typedef Log<Output2FILE> FILELog; //typedef Log<Output2FILE> FILELog;
#ifdef REST
#define FILE_LOG(level) \ #define FILE_LOG(level) \
if (level > FILELOG_MAX_LEVEL) ; \ if (level > FILELOG_MAX_LEVEL) ; \
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
else FILELog().Get(level) else FILELog().Get(level)
#else
#define FILE_LOG(level) \
if (level > FILELOG_MAX_LEVEL) ; \
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
else FILELog().Get(level)
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
@ -120,10 +140,11 @@ inline std::string NowTime()
#endif //WIN32 #endif //WIN32
template <typename T> Log<T>::Log(){} template <typename T> Log<T>::Log():lev(logDEBUG){}
template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level) template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
{ {
lev = level;
os << "- " << NowTime(); os << "- " << NowTime();
os << " " << ToString(level) << ": "; os << " " << ToString(level) << ": ";
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t'); os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
@ -133,24 +154,30 @@ template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
template <typename T> Log<T>::~Log() template <typename T> Log<T>::~Log()
{ {
os << std::endl; os << std::endl;
#ifdef REST
T::Output( os.str()); T::Output( os.str());
#else
T::Output( os.str(),lev);
#endif
} }
template <typename T> TLogLevel& Log<T>::ReportingLevel() template <typename T> TLogLevel& Log<T>::ReportingLevel()
{ {
static TLogLevel reportingLevel = logDEBUG4; static TLogLevel reportingLevel = logDEBUG5;
return reportingLevel; return reportingLevel;
} }
template <typename T> std::string Log<T>::ToString(TLogLevel level) template <typename T> std::string Log<T>::ToString(TLogLevel level)
{ {
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
return buffer[level]; return buffer[level];
} }
template <typename T> template <typename T>
TLogLevel Log<T>::FromString(const std::string& level) TLogLevel Log<T>::FromString(const std::string& level)
{ {
if (level == "DEBUG5")
return logDEBUG5;
if (level == "DEBUG4") if (level == "DEBUG4")
return logDEBUG4; return logDEBUG4;
if (level == "DEBUG3") if (level == "DEBUG3")
@ -187,6 +214,20 @@ inline void Output2FILE::Output(const std::string& msg)
fflush(pStream); fflush(pStream);
} }
inline void Output2FILE::Output(const std::string& msg, TLogLevel level)
{
FILE* pStream = Stream();
if (!pStream)
return;
switch(level){
case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break;
case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break;
case logINFO: cprintf(GRAY,"%s",msg.c_str()); break;
default: fprintf(pStream,"%s",msg.c_str()); break;
}
fflush(pStream);
}
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL) # if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport) # define FILELOG_DECLSPEC __declspec (dllexport)

View File

@ -14,7 +14,7 @@
#define BUF_SIZE (16*1024*1024) //16mb #define BUF_SIZE (16*1024*1024) //16mb
#define SAMPLE_TIME_IN_NS 100000000//100ms #define SAMPLE_TIME_IN_NS 100000000//100ms
#define MAX_JOBS_PER_THREAD 1000 #define MAX_JOBS_PER_THREAD 1000
#define HEADER_SIZE_NUM_TOT_PACKETS 2 #define HEADER_SIZE_NUM_TOT_PACKETS 4
#define HEADER_SIZE_NUM_FRAMES 2 #define HEADER_SIZE_NUM_FRAMES 2
#define HEADER_SIZE_NUM_PACKETS 1 #define HEADER_SIZE_NUM_PACKETS 1
@ -27,8 +27,9 @@
/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ /*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/
#define GOTTHARD_PACKETS_PER_FRAME 2 #define GOTTHARD_PACKETS_PER_FRAME 2
#define GOTTHARD_ONE_PACKET_SIZE 1286 #define GOTTHARD_ONE_PACKET_SIZE 1286
#define GOTTHARD_ONE_DATA_SIZE 1280
#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 #define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2
#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2 #define GOTTHARD_DATA_BYTES (GOTTHARD_ONE_DATA_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1280*2
#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE #define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE
#define GOTTHARD_FRAME_INDEX_OFFSET 1 #define GOTTHARD_FRAME_INDEX_OFFSET 1
@ -39,7 +40,7 @@
#define GOTTHARD_SHORT_PACKETS_PER_FRAME 1 #define GOTTHARD_SHORT_PACKETS_PER_FRAME 1
#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518 #define GOTTHARD_SHORT_ONE_PACKET_SIZE 518
#define GOTTHARD_SHORT_BUFFER_SIZE 518 #define GOTTHARD_SHORT_BUFFER_SIZE 518
#define GOTTHARD_SHORT_DATABYTES 512 #define GOTTHARD_SHORT_DATABYTES 512
#define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF #define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF
@ -75,8 +76,9 @@
/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/
#define MOENCH_PACKETS_PER_FRAME 40 #define MOENCH_PACKETS_PER_FRAME 40
#define MOENCH_ONE_PACKET_SIZE 1286 #define MOENCH_ONE_PACKET_SIZE 1286
#define MOENCH_ONE_DATA_SIZE 1280
#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 #define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40 #define MOENCH_DATA_BYTES (MOENCH_ONE_DATA_SIZE*MOENCH_PACKETS_PER_FRAME) //1280*40
#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 #define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00
#define MOENCH_FRAME_INDEX_OFFSET 8 #define MOENCH_FRAME_INDEX_OFFSET 8
@ -120,7 +122,7 @@
#define EIGER_MAX_PORTS 2 #define EIGER_MAX_PORTS 2
#define EIGER_HEADER_LENGTH 48 #define EIGER_HEADER_LENGTH 48
#define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000 #define EIGER_FIFO_SIZE 100
/*#define EIGER_ALIGNED_FRAME_SIZE 65536*/ /*#define EIGER_ALIGNED_FRAME_SIZE 65536*/
#define EIGER_ONE_GIGA_CONSTANT 16 #define EIGER_ONE_GIGA_CONSTANT 16
#define EIGER_TEN_GIGA_CONSTANT 4 #define EIGER_TEN_GIGA_CONSTANT 4
@ -129,10 +131,11 @@
#define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024 #define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024
#define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112 #define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112
#define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096 #define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096
#define EIGER_PACKET_HEADER_SIZE 8
//#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode //#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode
//#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode //#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode
#define EIGER_FRAME_INDEX_MASK 0xFFFF #define EIGER_FRAME_INDEX_MASK 0xFFFFFFFF //32 bit for now
#define EIGER_FRAME_INDEX_OFFSET 0 #define EIGER_FRAME_INDEX_OFFSET 0
#define EIGER_PACKET_INDEX_MASK 0x0 #define EIGER_PACKET_INDEX_MASK 0x0

View File

@ -8,7 +8,6 @@
#include "slsReceiverTCPIPInterface.h" #include "slsReceiverTCPIPInterface.h"
#include "UDPInterface.h" #include "UDPInterface.h"
//#include "UDPBaseImplementation.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include "MySocketTCP.h" #include "MySocketTCP.h"

View File

@ -54,9 +54,6 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
/** Close all threaded Files and exit */ /** Close all threaded Files and exit */
void closeFile(int p); void closeFile(int p);
/** Static function to call closeFile */
static void staticCloseFile(int p);
/** gets version */ /** gets version */
int64_t getReceiverVersion(); int64_t getReceiverVersion();
@ -210,6 +207,9 @@ private:
/** enable 10Gbe */ /** enable 10Gbe */
int enable_tengiga(); int enable_tengiga();
/** set fifo depth */
int set_fifo_depth();
//General Functions //General Functions
/** Locks Receiver */ /** Locks Receiver */
int lock_receiver(); int lock_receiver();

View File

@ -83,8 +83,8 @@ public:
void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg);
// made static to close thread files with ctrl+c //receiver object
static slsReceiver* receiver; slsReceiver* receiver;
}; };

View File

@ -8,8 +8,12 @@
#endif #endif
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
#include <string>
#endif
#include "ansi.h" #include "ansi.h"
typedef double double32_t; typedef double double32_t;
typedef float float32_t; typedef float float32_t;
typedef int int32_t; typedef int int32_t;
@ -19,8 +23,8 @@ typedef int int32_t;
#define MAX_FRAMES_PER_FILE 20000 #define MAX_FRAMES_PER_FILE 20000
#define SHORT_MAX_FRAMES_PER_FILE 100000 #define SHORT_MAX_FRAMES_PER_FILE 100000
#define MOENCH_MAX_FRAMES_PER_FILE 1000 #define MOENCH_MAX_FRAMES_PER_FILE 1000
#define EIGER_MAX_FRAMES_PER_FILE 20000 #define EIGER_MAX_FRAMES_PER_FILE 2000
#define JFCTB_MAX_FRAMES_PER_FILE 100000 #define JFCTB_MAX_FRAMES_PER_FILE 100000
/** /**
@ -110,7 +114,67 @@ public:
RUNNING /**< acquisition running, no data in memory */ RUNNING /**< acquisition running, no data in memory */
}; };
#ifdef __cplusplus
/** returns string from enabled/disabled
\param b true or false
\returns string enabled, disabled
*/
static std::string stringEnable(bool b){\
if(b) return std::string("enabled"); \
else return std::string("disabled"); \
};
/** returns detector type string from detector type index
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown
\returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, MÖNCH, GENERIC
*/
static std::string getDetectorType(detectorType t){ \
switch (t) { \
case MYTHEN: return std::string("Mythen"); \
case PILATUS: return std::string("Pilatus"); \
case EIGER: return std::string("Eiger"); \
case GOTTHARD: return std::string("Gotthard"); \
case AGIPD: return std::string("Agipd"); \
case MOENCH: return std::string("Moench"); \
case JUNGFRAU: return std::string("Jungfrau"); \
case JUNGFRAUCTB: return std::string("JungfrauCTB"); \
case PROPIX: return std::string("Propix"); \
default: return std::string("Unknown"); \
}};
/** returns detector type index from detector type string
\param type can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC
\returns Mythen, Pilatus, Eiger, Gotthard, Agipd, Mönch, Unknown
*/
static detectorType getDetectorType(std::string const type){\
if (type=="Mythen") return MYTHEN; \
if (type=="Pilatus") return PILATUS; \
if (type=="Eiger") return EIGER; \
if (type=="Gotthard") return GOTTHARD; \
if (type=="Agipd") return AGIPD; \
if (type=="Moench") return MOENCH; \
if (type=="Jungfrau") return JUNGFRAU; \
if (type=="JungfrauCTB") return JUNGFRAUCTB; \
if (type=="Propix") return PROPIX; \
return GENERIC; \
};
/** returns string from run status index
\param s can be ERROR, WAITING, RUNNING, TRANSMITTING, RUN_FINISHED
\returns string error, waiting, running, data, finished
*/
static std::string runStatusType(runStatus s){\
switch (s) { \
case ERROR: return std::string("error"); \
case WAITING: return std::string("waiting"); \
case RUNNING: return std::string("running"); \
case TRANSMITTING: return std::string("data"); \
case RUN_FINISHED: return std::string("finished"); \
default: return std::string("idle"); \
}};
#endif
#ifdef __cplusplus #ifdef __cplusplus
protected: protected:

View File

@ -48,7 +48,8 @@ enum {
F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */ F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */
F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */ F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */
F_ENABLE_RECEIVER_TEN_GIGA /**< enable 10Gbe in receiver */ F_ENABLE_RECEIVER_TEN_GIGA, /**< enable 10Gbe in receiver */
F_SET_RECEIVER_FIFO_DEPTH /**< set receiver fifo depth */
/* Always append functions hereafter!!! */ /* Always append functions hereafter!!! */
}; };

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,11 @@
***********************************************/ ***********************************************/
#include <string.h>
#include <iostream> #include <iostream>
#include <string.h>
using namespace std; using namespace std;
#include "UDPInterface.h" #include "UDPInterface.h"
#include "UDPBaseImplementation.h" #include "UDPBaseImplementation.h"
#include "UDPStandardImplementation.h" #include "UDPStandardImplementation.h"
@ -20,11 +20,10 @@ using namespace std;
using namespace std; using namespace std;
// TODO: I do not really like passing a bottom-top boolean to the constructor...
UDPInterface * UDPInterface::create(string receiver_type){ UDPInterface * UDPInterface::create(string receiver_type){
if (receiver_type == "standard"){ if (receiver_type == "standard"){
cout << "Starting " << receiver_type << endl; FILE_LOG(logINFO) << "Starting " << receiver_type;
return new UDPStandardImplementation(); return new UDPStandardImplementation();
} }
#ifdef REST #ifdef REST

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -6,25 +6,38 @@
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include <signal.h> //SIGINT
#include "utilities.h" #include "utilities.h"
#include "logger.h" #include "logger.h"
using namespace std; using namespace std;
slsReceiverUsers *receiver;
void deleteReceiver(slsReceiverUsers* r){
if(r){delete r;r=0;}
}
void closeFile(int p){
deleteReceiver(receiver);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
//Catch signal SIGINT to close files properly
signal(SIGINT,closeFile);
int ret = slsReceiverDefs::OK; int ret = slsReceiverDefs::OK;
receiver = new slsReceiverUsers(argc, argv, ret);
slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); if(ret==slsReceiverDefs::FAIL){
deleteReceiver(receiver);
if(ret==slsReceiverDefs::FAIL)
return -1; return -1;
}
//register callbacks //register callbacks
/** /**
callback arguments are callback arguments are
filepath filepath
@ -37,10 +50,8 @@ int main(int argc, char *argv[]) {
1 callback writes file, we have to open, close it 1 callback writes file, we have to open, close it
2 we open, close, write file, callback does not do anything 2 we open, close, write file, callback does not do anything
registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg);
*/ */
//receiver->registerCallBackStartAcquisition(func,arg); //receiver->registerCallBackStartAcquisition(func,arg);
@ -49,43 +60,36 @@ int main(int argc, char *argv[]) {
total farmes caught total farmes caught
registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg);
*/ */
//receiver->registerCallBackAcquisitionFinished(func,arg); //receiver->registerCallBackAcquisitionFinished(func,arg);
/** /**
args to raw data ready callback are args to raw data ready callback are
framenum framenum
datapointer datapointer
file descriptor file descriptor
guidatapointer (NULL, no data required) guidatapointer (NULL, no data required)
NEVER DELETE THE DATA POINTER NEVER DELETE THE DATA POINTER
REMEMBER THAT THE CALLBACK IS BLOCKING REMEMBER THAT THE CALLBACK IS BLOCKING
registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg);
*/ */
//receiver->registerCallBackRawDataReady(func,arg); //receiver->registerCallBackRawDataReady(func,arg);
//start tcp server thread //start tcp server thread
if(user->start() == slsReceiverDefs::OK){ if(receiver->start() == slsReceiverDefs::OK){
cout << "DONE!" << endl; FILE_LOG(logDEBUG1) << "DONE!" << endl;
string str; string str;
cin>>str; cin>>str;
//wait and look for an exit keyword //wait and look for an exit keyword
while(str.find("exit") == string::npos) while(str.find("exit") == string::npos)
cin>>str; cin>>str;
//stop tcp server thread, stop udp socket //stop tcp server thread, stop udp socket
user->stop(); receiver->stop();
} }
delete user; deleteReceiver(receiver);
cout << "Goodbye!" << endl; cout << "Goodbye!" << endl;
return 0; return 0;
} }

View File

@ -29,6 +29,9 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
* @return * @return
*/ */
udp_interface = NULL;
tcpipInterface = NULL;
//creating base receiver //creating base receiver
map<string, string> configuration_map; map<string, string> configuration_map;
int tcpip_port_no = 1954; int tcpip_port_no = 1954;
@ -55,7 +58,8 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
}; };
/* getopt_long stores the option index here. */ /* getopt_long stores the option index here. */
int option_index = 0; int option_index = 0;
int c; int c=0;
optind = 1;
while ( c != -1 ){ while ( c != -1 ){
c = getopt_long (argc, argv, "mbfhtr", long_options, &option_index); c = getopt_long (argc, argv, "mbfhtr", long_options, &option_index);
@ -162,7 +166,7 @@ void slsReceiver::closeFile(int p) {
int64_t slsReceiver::getReceiverVersion(){ int64_t slsReceiver::getReceiverVersion(){
tcpipInterface->getReceiverVersion(); return tcpipInterface->getReceiverVersion();
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,47 +1,45 @@
#include "slsReceiverUsers.h" #include "slsReceiverUsers.h"
#include "slsReceiver.h" #include "slsReceiver.h"
slsReceiver* slsReceiverUsers::receiver(NULL);
slsReceiverUsers::slsReceiverUsers(int argc, char *argv[], int &success) { slsReceiverUsers::slsReceiverUsers(int argc, char *argv[], int &success) {
slsReceiverUsers::receiver=new slsReceiver(argc, argv, success); receiver=new slsReceiver(argc, argv, success);
} }
slsReceiverUsers::~slsReceiverUsers() { slsReceiverUsers::~slsReceiverUsers() {
delete slsReceiverUsers::receiver; delete receiver;
} }
int slsReceiverUsers::start() { int slsReceiverUsers::start() {
return slsReceiverUsers::receiver->start(); return receiver->start();
} }
void slsReceiverUsers::stop() { void slsReceiverUsers::stop() {
slsReceiverUsers::receiver->stop(); receiver->stop();
} }
void slsReceiverUsers::closeFile(int p) { void slsReceiverUsers::closeFile(int p) {
slsReceiverUsers::receiver->closeFile(p); receiver->closeFile(p);
} }
int64_t slsReceiverUsers::getReceiverVersion(){ int64_t slsReceiverUsers::getReceiverVersion(){
slsReceiverUsers::receiver->getReceiverVersion(); return receiver->getReceiverVersion();
} }
void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){
slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); receiver->registerCallBackStartAcquisition(func,arg);
} }
void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){
slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); receiver->registerCallBackAcquisitionFinished(func,arg);
} }
void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){
slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); receiver->registerCallBackRawDataReady(func,arg);
} }