From 72e0d7e168ef92c0b8e9aae4dc4450108835c617 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 6 Jun 2019 08:07:40 +0200 Subject: [PATCH] clang format on receiver TCP and Implementation --- .../include/slsReceiverImplementation.h | 1582 +++++------ .../include/slsReceiverTCPIPInterface.h | 509 ++-- .../src/slsReceiverImplementation.cpp | 2305 +++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 1873 +++++++------- 4 files changed, 3162 insertions(+), 3107 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index 576d692a7..e6954ee80 100755 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -1,15 +1,19 @@ #pragma once -/********************************************//** - * @file slsReceiverImplementation.h - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - ***********************************************/ +/********************************************/ /** + * @file + *slsReceiverImplementation.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. + * @short does all the functions for a receiver, set/get parameters, start/stop + * etc. */ // #include "sls_detector_defs.h" -#include "receiver_defs.h" -#include "logger.h" #include "container_utils.h" +#include "logger.h" +#include "receiver_defs.h" class GeneralData; class Listener; class DataProcessor; @@ -18,333 +22,330 @@ class Fifo; class slsDetectorDefs; #include -#include #include +#include -class slsReceiverImplementation: private virtual slsDetectorDefs { - public: +class slsReceiverImplementation : private virtual slsDetectorDefs { + public: + //*** cosntructor & destructor *** + /** + * Constructor + */ + slsReceiverImplementation(); + /** + * Destructor + */ + virtual ~slsReceiverImplementation(); - //*** cosntructor & destructor *** - /** - * Constructor - */ - slsReceiverImplementation(); + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ - /** - * Destructor - */ - virtual ~slsReceiverImplementation(); + //**initial parameters*** + /* + * Get multi detector size + * @return pointer to array of multi detector size in every dimension + */ + int *getMultiDetectorSize() const; + /* + * Get detector position id + * @return detector position id + */ + int getDetectorPositionId() const; - /************************************************************************* - * Getters *************************************************************** - * They access local cache of configuration or detector parameters ******* - *************************************************************************/ + /* + * Get detector hostname + * @return hostname (max of 1000 characters) + */ + std::string getDetectorHostname() const; - //**initial parameters*** - /* - * Get multi detector size - * @return pointer to array of multi detector size in every dimension - */ - int* getMultiDetectorSize() const; + /* + * Get flipped data across 'axis' + * @return if data is flipped across 'axis' + */ + int getFlippedData(int axis = 0) const; - /* - * Get detector position id - * @return detector position id - */ - int getDetectorPositionId() const; + /** + * Get Gap Pixels Enable (eiger specific) + * @return true if gap pixels enabled, else false + */ + bool getGapPixelsEnable() const; - /* - * Get detector hostname - * @return hostname (max of 1000 characters) - */ - std::string getDetectorHostname() const; + /** + * Get readout flags (Eiger, chiptestboard, moench) + * @return readout flags + */ + readOutFlags getReadOutFlags() const; - /* - * Get flipped data across 'axis' - * @return if data is flipped across 'axis' - */ - int getFlippedData(int axis=0) const; + //***file parameters*** + /** + * Get File Format + * @return file format + */ + fileFormat getFileFormat() const; + /** + * Get File Name Prefix (without frame index, file index and extension + * (_d0_f000000000000_8.raw)) + * @return file name prefix + */ + std::string getFileName() const; - /** - * Get Gap Pixels Enable (eiger specific) - * @return true if gap pixels enabled, else false - */ - bool getGapPixelsEnable() const; + /** + * Get File Path + * @return file path + */ + std::string getFilePath() const; - /** - * Get readout flags (Eiger, chiptestboard, moench) - * @return readout flags - */ - readOutFlags getReadOutFlags() const; + /** + * Get File Index + * @return file index of acquisition + */ + uint64_t getFileIndex() const; + /** + * Get Frames per File (0 means infinite) + * @return Frames per File + */ + uint32_t getFramesPerFile() const; - //***file parameters*** - /** - * Get File Format - * @return file format - */ - fileFormat getFileFormat() const; - /** - * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) - * @return file name prefix - */ - std::string getFileName() const; + /** + * Get Frame Discard Policy + * @return Frame Discard Policy + */ + frameDiscardPolicy getFrameDiscardPolicy() const; - /** - * Get File Path - * @return file path - */ - std::string getFilePath() const; + /** + * Get Partial Frame Padding Enable + * @return Partial Frame Padding Enable + */ + bool getFramePaddingEnable() const; - /** - * Get File Index - * @return file index of acquisition - */ - uint64_t getFileIndex() const; + /** + * Get File Write Enable + * @return true if file write enabled, else false + */ + bool getFileWriteEnable() const; - /** - * Get Frames per File (0 means infinite) - * @return Frames per File - */ - uint32_t getFramesPerFile() const; + /** + * Get Master File Write Enable + * @return true if Master file write enabled, else false + */ + bool getMasterFileWriteEnable() const; - /** - * Get Frame Discard Policy - * @return Frame Discard Policy - */ - frameDiscardPolicy getFrameDiscardPolicy() const; + /** + * Get File Over Write Enable + * @return true if file over write enabled, else false + */ + bool getOverwriteEnable() const; - /** - * Get Partial Frame Padding Enable - * @return Partial Frame Padding Enable - */ - bool getFramePaddingEnable() 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; - /** - * Get File Write Enable - * @return true if file write enabled, else false - */ - bool getFileWriteEnable() const; + /** + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan + */ + uint64_t getFramesCaught() const; - /** - * Get Master File Write Enable - * @return true if Master file write enabled, else false - */ - bool getMasterFileWriteEnable() const; + /** + * Get Current Frame Index for an entire acquisition (including all scans) + * @return 0 if no frames have been caught, else average of all current + * frame index + */ + uint64_t getAcquisitionIndex() const; - /** - * Get File Over Write Enable - * @return true if file over write enabled, else false - */ - bool getOverwriteEnable() const; + //***connection parameters*** + /** + * Get UDP Port Number + * @return udp port number + */ + uint32_t getUDPPortNumber() const; + /** + * Get Second UDP Port Number (eiger/jungfrau specific) + * @return second udp port number + */ + uint32_t getUDPPortNumber2() 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; + /** + * Get Ehernet Interface + * @return ethernet interface. eg. eth0 or "" if listening to all + */ + std::string getEthernetInterface() const; - /** - * Get Frames Caught for each real time acquisition (eg. for each scan) - * @return number of frames caught for each scan - */ - uint64_t getFramesCaught() const; + /** + * Get Ehernet Interface 2 (jungfrau specific) + * @return ethernet interface 2. eg. eth0 or "" if listening to all + */ + std::string getEthernetInterface2() const; - /** - * Get Current Frame Index for an entire acquisition (including all scans) - * @return 0 if no frames have been caught, else average of all current frame index - */ - uint64_t getAcquisitionIndex() const; + /** + * Get number of UDP Interfaces (jungfrau specific) + * @return number of udp interfaces. Options (1-2) + */ + int getNumberofUDPInterfaces() const; + //***acquisition parameters*** + /** + * Get ROI + * @return index of adc enabled, else -1 if all enabled + */ + std::vector getROI() const; - //***connection parameters*** - /** - * Get UDP Port Number - * @return udp port number - */ - uint32_t getUDPPortNumber() const; + /** + * Get ADC Enable Mask + * @return ADC Enable Mask + */ + uint32_t getADCEnableMask() const; - /** - * Get Second UDP Port Number (eiger/jungfrau specific) - * @return second udp port number - */ - uint32_t getUDPPortNumber2() const; + /** + * Get the streaming frequency + * @return 0 for timer, n for nth frame frequency + */ + uint32_t getStreamingFrequency() const; - /** - * Get Ehernet Interface - * @return ethernet interface. eg. eth0 or "" if listening to all - */ - std::string getEthernetInterface() const; + /** + * Gets the timer between frames streamed when frequency is set to 0 + * @return timer between frames streamed + */ + uint32_t getStreamingTimer() const; - /** - * Get Ehernet Interface 2 (jungfrau specific) - * @return ethernet interface 2. eg. eth0 or "" if listening to all - */ - std::string getEthernetInterface2() const; + /** + * Get the data stream enable + * @return data stream enable + */ + bool getDataStreamEnable() const; - /** - * Get number of UDP Interfaces (jungfrau specific) - * @return number of udp interfaces. Options (1-2) - */ - int getNumberofUDPInterfaces() const; + /** + * Get Acquisition Period + * @return acquisition period + */ + uint64_t getAcquisitionPeriod() const; + /** + * Get Acquisition Time + * @return acquisition time + */ + uint64_t getAcquisitionTime() const; - //***acquisition parameters*** - /** - * Get ROI - * @return index of adc enabled, else -1 if all enabled - */ - std::vector getROI() const; + /** + * Get Sub Exposure Time + * @return Sub Exposure Time + */ + uint64_t getSubExpTime() const; - /** - * Get ADC Enable Mask - * @return ADC Enable Mask - */ - uint32_t getADCEnableMask() const; + /** + * Get Sub Period + * @return Sub Period + */ + uint64_t getSubPeriod() const; - /** - * Get the streaming frequency - * @return 0 for timer, n for nth frame frequency - */ - uint32_t getStreamingFrequency() const; + /* + * 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; - /** - * Gets the timer between frames streamed when frequency is set to 0 - * @return timer between frames streamed - */ - uint32_t getStreamingTimer() const; + /* + * Get Number of Analog Samples expected by receiver from detector (for chip + * test board and moench only) + * @return number of Analog samples expected + */ + uint64_t getNumberofAnalogSamples() const; - /** - * Get the data stream enable - * @return data stream enable - */ - bool getDataStreamEnable() const; + /* + * Get Number of Digital Samples expected by receiver from detector (for + * chip test board and moench only) + * @return number of Digital samples expected + */ + uint64_t getNumberofDigitalSamples() 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 Acquisition Period - * @return acquisition period - */ - uint64_t getAcquisitionPeriod() const; + /** + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) + */ + bool getTenGigaEnable() const; - /** - * Get Acquisition Time - * @return acquisition time - */ - uint64_t getAcquisitionTime() const; + /** + * Get Fifo Depth + * @return fifo depth + */ + uint32_t getFifoDepth() const; - /** - * Get Sub Exposure Time - * @return Sub Exposure Time - */ - uint64_t getSubExpTime() const; + //***receiver status*** + /** + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is + * listening or not + */ + runStatus getStatus() const; - /** - * Get Sub Period - * @return Sub Period - */ - uint64_t getSubPeriod() const; + /** + * Get Silent Mode + * @return silent mode + */ + bool getSilentMode() const; - /* - * 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 CTB digital bits enable list + * @returns digital bits enable list + */ + std::vector getDbitList() const; - /* - * Get Number of Analog Samples expected by receiver from detector (for chip test board and moench only) - * @return number of Analog samples expected - */ - uint64_t getNumberofAnalogSamples() const; + /** + * Get CTB digital bits offset + * @returns digital bits offset + */ + int getDbitOffset() const; - /* - * Get Number of Digital Samples expected by receiver from detector (for chip test board and moench only) - * @return number of Digital samples expected - */ - uint64_t getNumberofDigitalSamples() const; + /** + * Get activate + * If deactivated, receiver will create dummy data if deactivated padding is + * enabled (as it will receive nothing from detector) + * @return false for deactivated, true for activated + */ + bool getActivate() 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 deactivated padding enable + * If enabled, receiver will create dummy packets (0xFF), else it will + * create nothing (as it will receive nothing from detector) + * @return 0 for disabled, 1 for enabled + */ + bool getDeactivatedPadding() const; - /** - * Get Ten Giga Enable - * @return true if 10Giga enabled, else false (1G enabled) - */ - bool getTenGigaEnable() const; + /** + * Get Streaming Port + * @return streaming port + */ + uint32_t getStreamingPort() const; - /** - * Get Fifo Depth - * @return fifo depth - */ - uint32_t getFifoDepth() const; - - - //***receiver status*** - /** - * Get Listening Status of Receiver - * @return can be idle, listening or error depending on if the receiver is listening or not - */ - runStatus getStatus() const; - - /** - * Get Silent Mode - * @return silent mode - */ - bool getSilentMode() const; - - /** - * Get CTB digital bits enable list - * @returns digital bits enable list - */ - std::vector getDbitList() const; - - /** - * Get CTB digital bits offset - * @returns digital bits offset - */ - int getDbitOffset() const; - - /** - * Get activate - * If deactivated, receiver will create dummy data if deactivated padding is enabled - * (as it will receive nothing from detector) - * @return false for deactivated, true for activated - */ - bool getActivate() const; - - /** - * Get deactivated padding enable - * If enabled, receiver will create dummy packets (0xFF), else it will create nothing - * (as it will receive nothing from detector) - * @return 0 for disabled, 1 for enabled - */ - bool getDeactivatedPadding() const; - - /** - * Get Streaming Port - * @return streaming port - */ - uint32_t getStreamingPort() const; - - /** - * Get streaming source ip - * @return streaming source ip - */ - std::string getStreamingSourceIP() const; + /** + * Get streaming source ip + * @return streaming source ip + */ + std::string getStreamingSourceIP() const; /** * Get additional json header * @return additional json header */ - std::string getAdditionalJsonHeader() const; + std::string getAdditionalJsonHeader() const; /** (not saved in client shared memory) * Get UDP Socket Buffer Size @@ -352,147 +353,146 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { */ int64_t getUDPSocketBufferSize() const; - /** (not saved in client shared memory) * Get actual UDP Socket Buffer Size * @return actual UDP Socket Buffer Size */ int64_t getActualUDPSocketBufferSize() const; - /************************************************************************* - * Setters *************************************************************** - * They modify the local cache of configuration or detector parameters *** - *************************************************************************/ + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ - //**initial parameters*** - /** - * Sets detector hostname - * @param c detector hostname - */ - void setDetectorHostname(const char *c); + //**initial parameters*** + /** + * Sets detector hostname + * @param c detector hostname + */ + void setDetectorHostname(const char *c); - /* - * Set multi detector size - * @param pointer to array of multi detector size in every dimension - */ - void setMultiDetectorSize(const int* size); + /* + * Set multi detector size + * @param pointer to array of multi detector size in every dimension + */ + void setMultiDetectorSize(const int *size); - /* - * Get flipped data across 'axis' - * @return if data is flipped across 'axis' - */ - void setFlippedData(int axis=0, int enable=-1); + /* + * Get flipped data across 'axis' + * @return if data is flipped across 'axis' + */ + void setFlippedData(int axis = 0, int enable = -1); - /** - * Set Gap Pixels Enable (eiger specific) - * @param b true for gap pixels enable, else false - * @return OK or FAIL - */ - int setGapPixelsEnable(const bool b); + /** + * Set Gap Pixels Enable (eiger specific) + * @param b true for gap pixels enable, else false + * @return OK or FAIL + */ + int setGapPixelsEnable(const bool b); - /** - * Set readout flags (eiger, chiptestboard, moench) - * @param f readout flag - * @return OK or FAIL - */ - int setReadOutFlags(const readOutFlags f); + /** + * Set readout flags (eiger, chiptestboard, moench) + * @param f readout flag + * @return OK or FAIL + */ + int setReadOutFlags(const readOutFlags f); + //***file parameters*** + /** + * Set File Format + * @param f fileformat binary or hdf5 + */ + void setFileFormat(slsDetectorDefs::fileFormat f); - //***file parameters*** - /** - * Set File Format - * @param f fileformat binary or hdf5 - */ - void setFileFormat(slsDetectorDefs::fileFormat f); + /** + * 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 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 exists, it sets it + * @param c file path (max of 1000 characters) + */ + void setFilePath(const char c[]); - /** - * Set File Path - * Checks for file directory existence before setting file path, - * If it exists, it sets it - * @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 File Index of acquisition - * @param i file index of acquisition - */ - void setFileIndex(const uint64_t i); + /** + * Set Frames per File (0 means infinite) + * @param i Frames per File + */ + void setFramesPerFile(const uint32_t i); - /** - * Set Frames per File (0 means infinite) - * @param i Frames per File - */ - void setFramesPerFile(const uint32_t i); + /** + * Set Frame Discard Policy + * @param i Frame Discard Policy + */ + void setFrameDiscardPolicy(const frameDiscardPolicy i); - /** - * Set Frame Discard Policy - * @param i Frame Discard Policy - */ - void setFrameDiscardPolicy(const frameDiscardPolicy i); + /** + * Set Partial Frame Padding Enable + * @param i Partial Frame Padding Enable + */ + void setFramePaddingEnable(const bool i); - /** - * Set Partial Frame Padding Enable - * @param i Partial Frame Padding Enable - */ - void setFramePaddingEnable(const bool i); + /** + * Set File Write Enable + * @param b true for file write enable, else false + */ + void setFileWriteEnable(const bool b); - /** - * Set File Write Enable - * @param b true for file write enable, else false - */ - void setFileWriteEnable(const bool b); + /** + * Set Master File Write Enable + * @param b true for Master file write enable, else false + */ + void setMasterFileWriteEnable(const bool b); - /** - * Set Master File Write Enable - * @param b true for Master file write enable, else false - */ - void setMasterFileWriteEnable(const bool b); + /** + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false + */ + void setOverwriteEnable(const bool b); - /** - * Set File Overwrite Enable - * @param b true for file overwrite enable, else false - */ - void setOverwriteEnable(const bool b); + //***connection parameters*** + /** + * Set UDP Port Number + * @param i udp port number + */ + void setUDPPortNumber(const uint32_t i); - //***connection parameters*** - /** - * Set UDP Port Number - * @param i udp port number - */ - void setUDPPortNumber(const uint32_t i); + /** + * Set Second UDP Port Number (eiger/jungfrau specific) + * @return second udp port number + */ + void setUDPPortNumber2(const uint32_t i); - /** - * Set Second UDP Port Number (eiger/jungfrau specific) - * @return second udp port number - */ - void setUDPPortNumber2(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); - /** - * Set Ethernet Interface to listen to - * @param c ethernet inerface eg. eth0 (max of 1000 characters) - */ - void setEthernetInterface(const char* c); + /** + * Set second Ethernet Interface to listen to (jungfrau specific) + * @param c second ethernet inerface eg. eth0 (max of 1000 characters) + */ + void setEthernetInterface2(const char *c); - /** - * Set second Ethernet Interface to listen to (jungfrau specific) - * @param c second ethernet inerface eg. eth0 (max of 1000 characters) - */ - void setEthernetInterface2(const char* c); - - /** - * Set number of UDP Interfaces (jungfrau specific) - * @param n number of udp interfaces. Options (1-2) - * @return OK or FAIL for fifo structure creation - */ - int setNumberofUDPInterfaces(const int n); + /** + * Set number of UDP Interfaces (jungfrau specific) + * @param n number of udp interfaces. Options (1-2) + * @return OK or FAIL for fifo structure creation + */ + int setNumberofUDPInterfaces(const int n); /** (not saved in client shared memory) * Set UDP Socket Buffer Size @@ -501,20 +501,19 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { */ int setUDPSocketBufferSize(const int64_t s); - - //***acquisition parameters*** - /** - * Set ROI - * @param i ROI - * @return OK or FAIL - */ + //***acquisition parameters*** + /** + * Set ROI + * @param i ROI + * @return OK or FAIL + */ int setROI(const std::vector new_roi); - /** - * Set ADC Enable Mask - * @param mask ADC Enable Mask - * @return OK or FAIL - */ + /** + * Set ADC Enable Mask + * @param mask ADC Enable Mask + * @return OK or FAIL + */ int setADCEnableMask(const uint32_t mask); /** @@ -551,218 +550,225 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { /** * Set additional json header */ - void setAdditionalJsonHeader(const char* c); + void setAdditionalJsonHeader(const char *c); - /** - * Set Acquisition Period - * @param i acquisition period - * @return OK or FAIL - */ - int setAcquisitionPeriod(const uint64_t i); + /** + * Set Acquisition Period + * @param i acquisition period + * @return OK or FAIL + */ + int setAcquisitionPeriod(const uint64_t i); - /** - * Set Acquisition Time - * @param i acquisition time - * @return OK or FAIL - */ - int setAcquisitionTime(const uint64_t i); + /** + * Set Acquisition Time + * @param i acquisition time + * @return OK or FAIL + */ + int setAcquisitionTime(const uint64_t i); - /** - * Set Sub Exposure Time - * @param i Sub Exposure Time - * @return OK or FAIL - */ - void setSubExpTime(const uint64_t i); + /** + * Set Sub Exposure Time + * @param i Sub Exposure Time + * @return OK or FAIL + */ + void setSubExpTime(const uint64_t i); - /** - * Set Sub Period - * @param i Period - * @return OK or FAIL - */ - void setSubPeriod(const uint64_t i); + /** + * Set Sub Period + * @param i Period + * @return OK or FAIL + */ + void setSubPeriod(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 - * @param i number of frames expected - */ - void setNumberOfFrames(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 + * @param i number of frames expected + */ + void setNumberOfFrames(const uint64_t i); - /** - * Set Number of Analog Samples expected by receiver from detector - * @param i number of Analog Samples expected - * @return OK or FAIL - */ - int setNumberofAnalogSamples(const uint64_t i); + /** + * Set Number of Analog Samples expected by receiver from detector + * @param i number of Analog Samples expected + * @return OK or FAIL + */ + int setNumberofAnalogSamples(const uint64_t i); - /** - * Set Number of Digital Samples expected by receiver from detector - * @param i number of Digital Samples expected - * @return OK or FAIL - */ - int setNumberofDigitalSamples(const uint64_t i); + /** + * Set Number of Digital Samples expected by receiver from detector + * @param i number of Digital Samples expected + * @return OK or FAIL + */ + int setNumberofDigitalSamples(const uint64_t i); - /** - * Set Dynamic Range or Number of Bits Per Pixel - * @param i dynamic range that is 4, 8, 16 or 32 - * @return OK or FAIL - */ - int setDynamicRange(const uint32_t i); + /** + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL + */ + int setDynamicRange(const uint32_t i); - /** - * Set Ten Giga Enable - * @param b true if 10GbE enabled, else false (1G enabled) - * @return OK or FAIL - */ - int setTenGigaEnable(const bool b); + /** + * Set Ten Giga Enable + * @param b true if 10GbE enabled, else false (1G enabled) + * @return OK or FAIL + */ + int setTenGigaEnable(const bool b); - /** - * Set Fifo Depth - * @param i fifo depth value - * @return OK or FAIL - */ - int setFifoDepth(const uint32_t i); + /** + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + int setFifoDepth(const uint32_t i); + //***receiver parameters*** + /** + * Activate / Deactivate Receiver + * If deactivated, receiver will create dummy data if deactivated padding is + * enabled (as it will receive nothing from detector) + * @param enable enable + * @return false for disabled, true for enabled + */ + bool setActivate(const bool enable); - //***receiver parameters*** - /** - * Activate / Deactivate Receiver - * If deactivated, receiver will create dummy data if deactivated padding is enabled - * (as it will receive nothing from detector) - * @param enable enable - * @return false for disabled, true for enabled - */ - bool setActivate(const bool enable); + /** + * Set deactivated padding enable + * If enabled, receiver will create dummy packets (0xFF), else it will + * create nothing (as it will receive nothing from detector) + * @param enable enable + * @return false for disabled, true for enabled + */ + bool setDeactivatedPadding(const bool enable); - /** - * Set deactivated padding enable - * If enabled, receiver will create dummy packets (0xFF), else it will create nothing - * (as it will receive nothing from detector) - * @param enable enable - * @return false for disabled, true for enabled - */ - bool setDeactivatedPadding(const bool enable); + /** + * Set Silent Mode + * @param i silent mode. true sets, false unsets + */ + void setSilentMode(const bool i); - /** - * Set Silent Mode - * @param i silent mode. true sets, false unsets - */ - void setSilentMode(const bool i); + /** + * Set CTB digital bits enable list + * @param v digital bits enable list + */ + void setDbitList(const std::vector v); - /** - * Set CTB digital bits enable list - * @param v digital bits enable list - */ - void setDbitList(const std::vector v); + /** + * Set CTB digital bits offset + * @param s digital bits offset + */ + void setDbitOffset(const int s); - /** - * Set CTB digital bits offset - * @param s digital bits offset - */ - void setDbitOffset(const int s); + /************************************************************************* + * 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 detectorType d); - /************************************************************************* - * Behavioral functions*************************************************** - * They may modify the status of the receiver **************************** - *************************************************************************/ + /** + * Set detector position id and construct filewriter + * @param id position id + */ + void setDetectorPositionId(const int id); - //***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 detectorType d); + //***acquisition functions*** + /** + * Reset acquisition parameters such as total frames caught for an entire + * acquisition (including all scans) + */ + void resetAcquisitionCount(); - /** - * Set detector position id and construct filewriter - * @param id position id - */ - void setDetectorPositionId(const int id); + /** + * 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 + */ + int startReceiver(char *c = NULL); - //***acquisition functions*** - /** - * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) - */ - void resetAcquisitionCount(); + /** + * 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 stopReceiver(); - /** - * 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 - */ - int startReceiver(char *c=NULL); + /** + * Stop Listening to Packets + * and sets status to Transmitting + * Next step would be to get all data and stop receiver completely and + * return with idle state Pre: status is running, udp sockets have been + * initialized, stop receiver initiated Post:udp sockets closed, status is + * transmitting + */ + void startReadout(); - /** - * 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 stopReceiver(); + /** + * Shuts down and deletes UDP Sockets + * also called in case of illegal shutdown of receiver + */ + void shutDownUDPSockets(); - /** - * Stop Listening to Packets - * and sets status to Transmitting - * Next step would be to get all data and stop receiver completely and return with idle state - * Pre: status is running, udp sockets have been initialized, stop receiver initiated - * Post:udp sockets closed, status is transmitting - */ - void startReadout(); + /** + * Closes file / all files(data compression involves multiple files) + */ + void closeFiles(); - /** - * Shuts down and deletes UDP Sockets - * also called in case of illegal shutdown of receiver - */ - void shutDownUDPSockets(); + /** + * Restream stop dummy packet from receiver + * @return OK or FAIL + */ + int restreamStop(); - /** - * Closes file / all files(data compression involves multiple files) - */ - void closeFiles(); + //***callback functions*** + /** + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is insignificant at the moment + * we write depending on file write enable + * users get data to write depending on call backs registered + */ + void registerCallBackStartAcquisition(int (*func)(char *, char *, uint64_t, + uint32_t, void *), + void *arg); - /** - * Restream stop dummy packet from receiver - * @return OK or FAIL - */ - int restreamStop(); + /** + * Call back for acquisition finished + * callback argument is + * total frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void *), + void *arg); - //***callback functions*** - /** - * Call back for start acquisition - * callback arguments are - * filepath - * filename - * fileindex - * datasize - * - * return value is insignificant at the moment - * we write depending on file write enable - * users get data to write depending on call backs registered - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg); - - /** - * Call back for acquisition finished - * callback argument is - * total frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); - - /** - * Call back for raw data - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * dataSize in bytes is the size of the data in bytes. - */ - void registerCallBackRawDataReady(void (*func)(char* , - char*, uint32_t, void*),void *arg); + /** + * Call back for raw data + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * dataSize in bytes is the size of the data in bytes. + */ + void registerCallBackRawDataReady(void (*func)(char *, char *, uint32_t, + void *), + void *arg); /** * Call back for raw data (modified) @@ -770,233 +776,229 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { * sls_receiver_header frame metadata * dataPointer is the pointer to the data * revDatasize is the reference of data size in bytes. - * Can be modified to the new size to be written/streamed. (only smaller value). + * Can be modified to the new size to be written/streamed. (only smaller + * value). */ - void registerCallBackRawDataModifyReady(void (*func)(char* , - char*, uint32_t &,void*),void *arg); - -private: + void registerCallBackRawDataModifyReady(void (*func)(char *, char *, + uint32_t &, void *), + void *arg); + private: /** - * Delete and free member parameters - */ + * Delete and free member parameters + */ void DeleteMembers(); - /** - * Initialize member parameters - */ - void InitializeMembers(); + /** + * Initialize member parameters + */ + void InitializeMembers(); - /** - * Sets local network parameters, but requires permissions - */ - void SetLocalNetworkParameters(); + /** + * Sets local network parameters, but requires permissions + */ + void SetLocalNetworkParameters(); - /** - * Set Thread Priorities - */ - void SetThreadPriorities(); + /** + * Set Thread Priorities + */ + void SetThreadPriorities(); - /** - * Set up the Fifo Structure for processing buffers - * between listening and dataprocessor threads - * @return OK or FAIL - */ - int SetupFifoStructure(); + /** + * Set up the Fifo Structure for processing buffers + * between listening and dataprocessor threads + * @return OK or FAIL + */ + int SetupFifoStructure(); - /** - * Reset parameters for new measurement (eg. for each scan) - */ - void ResetParametersforNewMeasurement(); + /** + * Reset parameters for new measurement (eg. for each scan) + */ + void ResetParametersforNewMeasurement(); - /** - * Creates UDP Sockets - * @return OK or FAIL - */ - int CreateUDPSockets(); + /** + * Creates UDP Sockets + * @return OK or FAIL + */ + int CreateUDPSockets(); - /** - * Creates the first file - * also does the startAcquisitionCallBack - * @return OK or FAIL - */ - int SetupWriter(); + /** + * Creates the first file + * also does the startAcquisitionCallBack + * @return OK or FAIL + */ + int SetupWriter(); - /** - * Start Running - * Set running mask and post semaphore of the threads - * to start the inner loop in execution thread - */ - void StartRunning(); + /** + * Start Running + * Set running mask and post semaphore of the threads + * to start the inner loop in execution thread + */ + void StartRunning(); + /************************************************************************* + * Class Members ********************************************************* + *************************************************************************/ + //**detector parameters*** + /** detector type */ + detectorType myDetectorType; + /** Number of Detectors in each dimension direction */ + int numDet[MAX_DIMENSIONS]; + /*Detector Readout ID*/ + int detID; + /** detector hostname */ + char detHostname[MAX_STR_LENGTH]; + /** Acquisition Period */ + uint64_t acquisitionPeriod; + /** Acquisition Time */ + uint64_t acquisitionTime; + /** Sub Exposure Time */ + uint64_t subExpTime; + /** Sub Period */ + uint64_t subPeriod; + /** Frame Number */ + uint64_t numberOfFrames; + /** Analog Samples Number */ + uint64_t numberOfAnalogSamples; + /** Digital Samples Number */ + uint64_t numberOfDigitalSamples; + /** Dynamic Range */ + uint32_t dynamicRange; + /** Ten Giga Enable*/ + bool tengigaEnable; + /** Fifo Depth */ + uint32_t fifoDepth; + /** enable for flipping data across both axes */ + int flippedData[2]; + /** gap pixels enable */ + bool gapPixelsEnable; + /** readout flags*/ + readOutFlags readoutFlags; + //*** receiver parameters *** + /** Number of Threads */ + int numThreads; + /** Maximum Number of Listening Threads/ UDP Ports */ + const static int MAX_NUMBER_OF_LISTENING_THREADS = 2; + /** Receiver Status */ + runStatus status; + /** Activated/Deactivated */ + bool activated; + /** Deactivated padding enable */ + bool deactivatedPaddingEnable; + /** frame discard policy */ + frameDiscardPolicy frameDiscardMode; + /** frame padding */ + bool framePadding; + /** silent mode */ + bool silentMode; + /** ctb digital bits enabled list (empty: all enabled) */ + std::vector ctbDbitList; + /** ctb digital bit offset in bytes */ + int ctbDbitOffset; + /* analog data bytes */ + int ctbAnalogDataBytes; - /************************************************************************* - * Class Members ********************************************************* - *************************************************************************/ - //**detector parameters*** - /** detector type */ - detectorType myDetectorType; - /** Number of Detectors in each dimension direction */ - int numDet[MAX_DIMENSIONS]; - /*Detector Readout ID*/ - int detID; - /** detector hostname */ - char detHostname[MAX_STR_LENGTH]; - /** Acquisition Period */ - uint64_t acquisitionPeriod; - /** Acquisition Time */ - uint64_t acquisitionTime; - /** Sub Exposure Time */ - uint64_t subExpTime; - /** Sub Period */ - uint64_t subPeriod; - /** Frame Number */ - uint64_t numberOfFrames; - /** Analog Samples Number */ - uint64_t numberOfAnalogSamples; - /** Digital Samples Number */ - uint64_t numberOfDigitalSamples; - /** Dynamic Range */ - uint32_t dynamicRange; - /** Ten Giga Enable*/ - bool tengigaEnable; - /** Fifo Depth */ - uint32_t fifoDepth; - /** enable for flipping data across both axes */ - int flippedData[2]; - /** gap pixels enable */ - bool gapPixelsEnable; - /** readout flags*/ - readOutFlags readoutFlags; - - //*** receiver parameters *** - /** Number of Threads */ - int numThreads; - /** Maximum Number of Listening Threads/ UDP Ports */ - const static int MAX_NUMBER_OF_LISTENING_THREADS = 2; - /** Receiver Status */ - runStatus status; - /** Activated/Deactivated */ - bool activated; - /** Deactivated padding enable */ - bool deactivatedPaddingEnable; - /** frame discard policy */ - frameDiscardPolicy frameDiscardMode; - /** frame padding */ - bool framePadding; - /** silent mode */ - bool silentMode; - /** ctb digital bits enabled list (empty: all enabled) */ - std::vector ctbDbitList; - /** ctb digital bit offset in bytes */ - int ctbDbitOffset; - /* analog data bytes */ - int ctbAnalogDataBytes; - - //***connection parameters*** - /** Number of UDP Interfaces */ - int numUDPInterfaces; - /** Ethernet Interface */ - char eth[MAX_NUMBER_OF_LISTENING_THREADS][MAX_STR_LENGTH]; - /** Server UDP Port Number*/ - uint32_t udpPortNum[MAX_NUMBER_OF_LISTENING_THREADS]; - /** udp socket buffer size */ - int64_t udpSocketBufferSize; + //***connection parameters*** + /** Number of UDP Interfaces */ + int numUDPInterfaces; + /** Ethernet Interface */ + char eth[MAX_NUMBER_OF_LISTENING_THREADS][MAX_STR_LENGTH]; + /** Server UDP Port Number*/ + uint32_t udpPortNum[MAX_NUMBER_OF_LISTENING_THREADS]; + /** udp socket buffer size */ + int64_t udpSocketBufferSize; /** actual UDP Socket Buffer Size (halved due to kernel bookkeeping) */ int64_t actualUDPSocketBufferSize; //***file parameters*** - /** File format */ - fileFormat fileFormatType; - /** 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 */ - uint64_t fileIndex; - /** Frames per file (0 means infinite) */ - uint32_t framesPerFile; - /** File Write enable */ - bool fileWriteEnable; - /** MasterFile Write enable */ - bool masterFileWriteEnable; - /** Overwrite enable */ - bool overwriteEnable; + /** File format */ + fileFormat fileFormatType; + /** 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 */ + uint64_t fileIndex; + /** Frames per file (0 means infinite) */ + uint32_t framesPerFile; + /** File Write enable */ + bool fileWriteEnable; + /** MasterFile Write enable */ + bool masterFileWriteEnable; + /** Overwrite enable */ + bool overwriteEnable; - //***acquisition parameters*** - /* ROI */ - std::vector roi; - /** ADC Enable Mask */ - uint32_t adcEnableMask; - /** streaming frequency */ - uint32_t streamingFrequency; - /** Streaming timer when frequency is 0 */ - uint32_t streamingTimerInMs; - /** Data Stream Enable from Receiver */ - bool dataStreamEnable; - /** streaming port */ - uint32_t streamingPort; - /** streaming port */ - char streamingSrcIP[MAX_STR_LENGTH]; - /** additional json header */ - char additionalJsonHeader[MAX_STR_LENGTH]; + //***acquisition parameters*** + /* ROI */ + std::vector roi; + /** ADC Enable Mask */ + uint32_t adcEnableMask; + /** streaming frequency */ + uint32_t streamingFrequency; + /** Streaming timer when frequency is 0 */ + uint32_t streamingTimerInMs; + /** Data Stream Enable from Receiver */ + bool dataStreamEnable; + /** streaming port */ + uint32_t streamingPort; + /** streaming port */ + char streamingSrcIP[MAX_STR_LENGTH]; + /** additional json header */ + char additionalJsonHeader[MAX_STR_LENGTH]; - //** class objects *** - /** General Data Properties */ - GeneralData* generalData; - /** Listener Objects that listen to UDP and push into fifo */ - std::vector> listener; - /** DataProcessor Objects that pull from fifo and process data */ - std::vector> dataProcessor; - /** DataStreamer Objects that stream data via ZMQ */ - std::vector> dataStreamer; - /** Fifo Structure to store addresses of memory writes */ - std::vector> fifo; + //** class objects *** + /** General Data Properties */ + GeneralData *generalData; + /** Listener Objects that listen to UDP and push into fifo */ + std::vector> listener; + /** DataProcessor Objects that pull from fifo and process data */ + std::vector> dataProcessor; + /** DataStreamer Objects that stream data via ZMQ */ + std::vector> dataStreamer; + /** Fifo Structure to store addresses of memory writes */ + std::vector> fifo; - //***callback parameters*** - /** - * Call back for start acquisition - * callback arguments are - * filepath - * filename - * fileindex - * datasize - * - * return value is insignificant at the moment - * we write depending on file write enable - * users get data to write depending on call backs registered - */ - int (*startAcquisitionCallBack)(char*, char*, uint64_t, uint32_t, void*); - void *pStartAcquisition; - /** - * Call back for acquisition finished - * callback argument is - * total frames caught - */ - void (*acquisitionFinishedCallBack)(uint64_t, void*); - void *pAcquisitionFinished; - /** - * Call back for raw data - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * dataSize in bytes is the size of the data in bytes. - */ - void (*rawDataReadyCallBack)(char* , - char*, uint32_t, void*); + //***callback parameters*** + /** + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is insignificant at the moment + * we write depending on file write enable + * users get data to write depending on call backs registered + */ + int (*startAcquisitionCallBack)(char *, char *, uint64_t, uint32_t, void *); + void *pStartAcquisition; + /** + * Call back for acquisition finished + * callback argument is + * total frames caught + */ + void (*acquisitionFinishedCallBack)(uint64_t, void *); + void *pAcquisitionFinished; + /** + * Call back for raw data + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * dataSize in bytes is the size of the data in bytes. + */ + void (*rawDataReadyCallBack)(char *, char *, uint32_t, void *); /** * Call back for raw data (modified) * args to raw data ready callback are * sls_receiver_header frame metadata * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * revDatasize is the reference of data size in bytes. Can be modified to + * the new size to be written/streamed. (only smaller value). */ - void (*rawDataModifyReadyCallBack)(char* , - char*, uint32_t &, void*); - - void *pRawDataReady; - + void (*rawDataModifyReadyCallBack)(char *, char *, uint32_t &, void *); + void *pRawDataReady; }; - diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 5c217c148..50717b9a0 100755 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -1,85 +1,87 @@ #pragma once -/********************************************//** - * @file slsReceiverTCPIPInterface.h - * @short interface between receiver and client - ***********************************************/ +/********************************************/ /** + * @file + *slsReceiverTCPIPInterface.h + * @short interface between + *receiver and client + ***********************************************/ - -#include "sls_detector_defs.h" #include "receiver_defs.h" +#include "sls_detector_defs.h" class MySocketTCP; class ServerInterface; -#include "slsReceiverImplementation.h" #include "ServerSocket.h" - +#include "slsReceiverImplementation.h" /** *@short interface between receiver and client */ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { - private: - enum numberMode {DEC, HEX}; - - public: + private: + enum numberMode { DEC, HEX }; - /** Destructor */ - virtual ~slsReceiverTCPIPInterface(); + public: + /** Destructor */ + virtual ~slsReceiverTCPIPInterface(); - /** - * Constructor - * reads config file, creates socket, assigns function table - * throws an exception in case of failure to construct - * @param pn port number (defaults to default port number) - */ + /** + * Constructor + * reads config file, creates socket, assigns function table + * throws an exception in case of failure to construct + * @param pn port number (defaults to default port number) + */ - slsReceiverTCPIPInterface(int pn=-1); + slsReceiverTCPIPInterface(int pn = -1); - /** - * Starts listening on the TCP port for client comminication - \returns OK or FAIL - */ - int start(); + /** + * Starts listening on the TCP port for client comminication + \returns OK or FAIL + */ + int start(); - /** stop listening on the TCP & UDP port for client comminication */ - void stop(); + /** stop listening on the TCP & UDP port for client comminication */ + void stop(); + /** gets version */ + int64_t getReceiverVersion(); - /** gets version */ - int64_t getReceiverVersion(); + //***callback functions*** + /** + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is insignificant at the moment + * we write depending on file write enable + * users get data to write depending on call backs registered + */ + void registerCallBackStartAcquisition(int (*func)(char *, char *, uint64_t, + uint32_t, void *), + void *arg); - //***callback functions*** - /** - * Call back for start acquisition - * callback arguments are - * filepath - * filename - * fileindex - * datasize - * - * return value is insignificant at the moment - * we write depending on file write enable - * users get data to write depending on call backs registered - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg); + /** + * Call back for acquisition finished + * callback argument is + * total frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void *), + void *arg); - /** - * Call back for acquisition finished - * callback argument is - * total frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); - - /** - * Call back for raw data - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * dataSize in bytes is the size of the data in bytes. - */ - void registerCallBackRawDataReady(void (*func)(char* , - char*, uint32_t, void*),void *arg); + /** + * Call back for raw data + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * dataSize in bytes is the size of the data in bytes. + */ + void registerCallBackRawDataReady(void (*func)(char *, char *, uint32_t, + void *), + void *arg); /** * Call back for raw data (modified) @@ -87,169 +89,168 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { * sls_receiver_header frame metadata * dataPointer is the pointer to the data * revDatasize is the reference of data size in bytes. - * Can be modified to the new size to be written/streamed. (only smaller value). + * Can be modified to the new size to be written/streamed. (only smaller + * value). */ - void registerCallBackRawDataModifyReady(void (*func)(char* , - char*, uint32_t &,void*),void *arg); + void registerCallBackRawDataModifyReady(void (*func)(char *, char *, + uint32_t &, void *), + void *arg); + private: + /** + * Static function - Thread started which is a TCP server + * Called by start() + * @param this_pointer pointer to this object + */ + static void *startTCPServerThread(void *this_pointer); - private: + /** + * Thread started which is a TCP server + * Called by start() + */ + void startTCPServer(); - /** - * Static function - Thread started which is a TCP server - * Called by start() - * @param this_pointer pointer to this object - */ - static void* startTCPServerThread(void *this_pointer); + /** assigns functions to the fnum enum */ + int function_table(); + /** Decodes Function */ + int decode_function(sls::ServerInterface2 &socket); - /** - * Thread started which is a TCP server - * Called by start() - */ - void startTCPServer(); + /** function not implemented for specific detector */ + void functionNotImplemented(); - /** assigns functions to the fnum enum */ - int function_table(); + /** mode not implemented for specific detector */ + void modeNotImplemented(std::string modename, int mode); - /** Decodes Function */ - int decode_function(sls::ServerInterface2 &socket); + /** validate and set error */ + template + void validate(T arg, T retval, std::string modename, numberMode hex); - /** function not implemented for specific detector */ - void functionNotImplemented(); + /** Execute command */ + int exec_command(sls::ServerInterface2 &socket); - /** mode not implemented for specific detector */ - void modeNotImplemented(std::string modename, int mode); + /** Exit Receiver Server */ + int exit_server(sls::ServerInterface2 &socket); - /** validate and set error */ - template - void validate(T arg, T retval, std::string modename, numberMode hex); + /** Locks Receiver */ + int lock_receiver(sls::ServerInterface2 &socket); - /** Execute command */ - int exec_command(sls::ServerInterface2 &socket); + /** Get Last Client IP*/ + int get_last_client_ip(sls::ServerInterface2 &socket); - /** Exit Receiver Server */ - int exit_server(sls::ServerInterface2 &socket); + /** Set port */ + int set_port(sls::ServerInterface2 &socket); - /** Locks Receiver */ - int lock_receiver(sls::ServerInterface2 &socket); + /** Updates Client if different clients connect */ + int update_client(sls::ServerInterface2 &socket); - /** Get Last Client IP*/ - int get_last_client_ip(sls::ServerInterface2 &socket); + /** Sends the updated parameters to client */ + int send_update(sls::ServerInterface2 &socket); - /** Set port */ - int set_port(sls::ServerInterface2 &socket); + /** get version, calls get_version */ + int get_id(sls::ServerInterface2 &socket); - /** Updates Client if different clients connect */ - int update_client(sls::ServerInterface2 &socket); + /** Set detector type */ + int set_detector_type(sls::ServerInterface2 &socket); - /** Sends the updated parameters to client */ - int send_update(sls::ServerInterface2 &socket); + /** set detector hostname */ + int set_detector_hostname(sls::ServerInterface2 &socket); - /** get version, calls get_version */ - int get_id(sls::ServerInterface2 &socket); + /** set roi */ + int set_roi(sls::ServerInterface2 &socket); - /** Set detector type */ - int set_detector_type(sls::ServerInterface2 &socket); + /** Set up UDP Details */ + int setup_udp(sls::ServerInterface2 &socket); - /** set detector hostname */ - int set_detector_hostname(sls::ServerInterface2 &socket); + /** set acquisition period, frame number etc */ + int set_timer(sls::ServerInterface2 &socket); - /** set roi */ - int set_roi(sls::ServerInterface2 &socket); + /** set dynamic range */ + int set_dynamic_range(sls::ServerInterface2 &socket); - /** Set up UDP Details */ - int setup_udp(sls::ServerInterface2 &socket); + /** Sets the receiver streaming frequency */ + int set_streaming_frequency(sls::ServerInterface2 &socket); - /** set acquisition period, frame number etc */ - int set_timer(sls::ServerInterface2 &socket); + /** Gets receiver status */ + int get_status(sls::ServerInterface2 &socket); - /** set dynamic range */ - int set_dynamic_range(sls::ServerInterface2 &socket); + /** Start Receiver - starts listening to udp packets from detector */ + int start_receiver(sls::ServerInterface2 &socket); - /** Sets the receiver streaming frequency */ - int set_streaming_frequency(sls::ServerInterface2 &socket); + /** Stop Receiver - stops listening to udp packets from detector*/ + int stop_receiver(sls::ServerInterface2 &socket); - /** Gets receiver status */ - int get_status(sls::ServerInterface2 &socket); + /** Set File path */ + int set_file_dir(sls::ServerInterface2 &socket); - /** Start Receiver - starts listening to udp packets from detector */ - int start_receiver(sls::ServerInterface2 &socket); + /** Set File name without frame index, file index and extension */ + int set_file_name(sls::ServerInterface2 &socket); - /** Stop Receiver - stops listening to udp packets from detector*/ - int stop_receiver(sls::ServerInterface2 &socket); + /** Set File index */ + int set_file_index(sls::ServerInterface2 &socket); - /** Set File path */ - int set_file_dir(sls::ServerInterface2 &socket); + /** Gets frame index for each acquisition */ + int get_frame_index(sls::ServerInterface2 &socket); - /** Set File name without frame index, file index and extension */ - int set_file_name(sls::ServerInterface2 &socket); + /** Gets Total Frames Caught */ + int get_frames_caught(sls::ServerInterface2 &socket); - /** Set File index */ - int set_file_index(sls::ServerInterface2 &socket); + /** Resets Total Frames Caught */ + int reset_frames_caught(sls::ServerInterface2 &socket); - /** Gets frame index for each acquisition */ - int get_frame_index(sls::ServerInterface2 &socket); + /** Enable File Write*/ + int enable_file_write(sls::ServerInterface2 &socket); - /** Gets Total Frames Caught */ - int get_frames_caught(sls::ServerInterface2 &socket); + /** Enable Master File Write */ + int enable_master_file_write(sls::ServerInterface2 &socket); - /** Resets Total Frames Caught */ - int reset_frames_caught(sls::ServerInterface2 &socket); + /** enable compression */ + int enable_compression(sls::ServerInterface2 &socket); - /** Enable File Write*/ - int enable_file_write(sls::ServerInterface2 &socket); + /** enable overwrite */ + int enable_overwrite(sls::ServerInterface2 &socket); - /** Enable Master File Write */ - int enable_master_file_write(sls::ServerInterface2 &socket); + /** enable 10Gbe */ + int enable_tengiga(sls::ServerInterface2 &socket); - /** enable compression */ - int enable_compression(sls::ServerInterface2 &socket); + /** set fifo depth */ + int set_fifo_depth(sls::ServerInterface2 &socket); - /** enable overwrite */ - int enable_overwrite(sls::ServerInterface2 &socket); + /** activate/ deactivate */ + int set_activate(sls::ServerInterface2 &socket); - /** enable 10Gbe */ - int enable_tengiga(sls::ServerInterface2 &socket); + /* Set the data stream enable */ + int set_data_stream_enable(sls::ServerInterface2 &socket); - /** set fifo depth */ - int set_fifo_depth(sls::ServerInterface2 &socket); + /** Sets the steadming timer when frequency is set to 0 */ + int set_streaming_timer(sls::ServerInterface2 &socket); - /** activate/ deactivate */ - int set_activate(sls::ServerInterface2 &socket); + /** enable flipped data */ + int set_flipped_data(sls::ServerInterface2 &socket); - /* Set the data stream enable */ - int set_data_stream_enable(sls::ServerInterface2 &socket); + /** set file format */ + int set_file_format(sls::ServerInterface2 &socket); - /** Sets the steadming timer when frequency is set to 0 */ - int set_streaming_timer(sls::ServerInterface2 &socket); + /** set position id */ + int set_detector_posid(sls::ServerInterface2 &socket); - /** enable flipped data */ - int set_flipped_data(sls::ServerInterface2 &socket); + /** set multi detector size */ + int set_multi_detector_size(sls::ServerInterface2 &socket); - /** set file format */ - int set_file_format(sls::ServerInterface2 &socket); + /** set streaming port */ + int set_streaming_port(sls::ServerInterface2 &socket); - /** set position id */ - int set_detector_posid(sls::ServerInterface2 &socket); + /** set streaming source ip */ + int set_streaming_source_ip(sls::ServerInterface2 &socket); - /** set multi detector size */ - int set_multi_detector_size(sls::ServerInterface2 &socket); + /** set silent mode */ + int set_silent_mode(sls::ServerInterface2 &socket); - /** set streaming port */ - int set_streaming_port(sls::ServerInterface2 &socket); + /** enable gap pixels */ + int enable_gap_pixels(sls::ServerInterface2 &socket); - /** set streaming source ip */ - int set_streaming_source_ip(sls::ServerInterface2 &socket); - - /** set silent mode */ - int set_silent_mode(sls::ServerInterface2 &socket); - - /** enable gap pixels */ - int enable_gap_pixels(sls::ServerInterface2 &socket); - - /** restream stop packet */ - int restream_stop(sls::ServerInterface2 &socket); + /** restream stop packet */ + int restream_stop(sls::ServerInterface2 &socket); /** set additional json header */ int set_additional_json_header(sls::ServerInterface2 &socket); @@ -281,114 +282,112 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { /** set readout flags */ int set_readout_flags(sls::ServerInterface2 &socket); - /** set adc mask */ - int set_adc_mask(sls::ServerInterface2 &socket); + /** set adc mask */ + int set_adc_mask(sls::ServerInterface2 &socket); - /** set receiver dbit list */ - int set_dbit_list(sls::ServerInterface2 &socket); + /** set receiver dbit list */ + int set_dbit_list(sls::ServerInterface2 &socket); - /** get receiver dbit list */ - int get_dbit_list(sls::ServerInterface2 &socket); + /** get receiver dbit list */ + int get_dbit_list(sls::ServerInterface2 &socket); - /** set dbit offset */ - int set_dbit_offset(sls::ServerInterface2 &socket); + /** set dbit offset */ + int set_dbit_offset(sls::ServerInterface2 &socket); - /** detector type */ - detectorType myDetectorType; + /** detector type */ + detectorType myDetectorType; - /** slsReceiverBase object */ - std::unique_ptr receiver{nullptr}; + /** slsReceiverBase object */ + std::unique_ptr receiver{nullptr}; - /** Function List */ - int (slsReceiverTCPIPInterface::*flist[NUM_REC_FUNCTIONS])(sls::ServerInterface2& socket); + /** Function List */ + int (slsReceiverTCPIPInterface::*flist[NUM_REC_FUNCTIONS])( + sls::ServerInterface2 &socket); - /** Message */ - char mess[MAX_STR_LENGTH]{}; + /** Message */ + char mess[MAX_STR_LENGTH]{}; - /** success/failure */ - int ret{OK}; + /** success/failure */ + int ret{OK}; - /** function index */ - int fnum{-1}; + /** function index */ + int fnum{-1}; - /** Lock Status if server locked to a client */ - int lockStatus{0}; + /** Lock Status if server locked to a client */ + int lockStatus{0}; - /** kill tcp server thread */ - int killTCPServerThread{0}; + /** kill tcp server thread */ + int killTCPServerThread{0}; - /** thread for TCP server */ - pthread_t TCPServer_thread; + /** thread for TCP server */ + pthread_t TCPServer_thread; - /** tcp thread created flag*/ - bool tcpThreadCreated{false}; + /** tcp thread created flag*/ + bool tcpThreadCreated{false}; - /** port number */ - int portNumber; + /** port number */ + int portNumber; - //***callback parameters*** - /** - * Call back for start acquisition - * callback arguments are - * filepath - * filename - * fileindex - * datasize - * - * return value is insignificant at the moment - * we write depending on file write enable - * users get data to write depending on call backs registered - */ - int (*startAcquisitionCallBack)(char*, char*, uint64_t, uint32_t, void*) = nullptr; - void *pStartAcquisition{nullptr}; + //***callback parameters*** + /** + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is insignificant at the moment + * we write depending on file write enable + * users get data to write depending on call backs registered + */ + int (*startAcquisitionCallBack)(char *, char *, uint64_t, uint32_t, + void *) = nullptr; + void *pStartAcquisition{nullptr}; - /** - * Call back for acquisition finished - * callback argument is - * total frames caught - */ - void (*acquisitionFinishedCallBack)(uint64_t, void*) = nullptr; - void *pAcquisitionFinished{nullptr}; + /** + * Call back for acquisition finished + * callback argument is + * total frames caught + */ + void (*acquisitionFinishedCallBack)(uint64_t, void *) = nullptr; + void *pAcquisitionFinished{nullptr}; - - /** - * Call back for raw data - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * dataSize in bytes is the size of the data in bytes. - */ - void (*rawDataReadyCallBack)(char* , - char*, uint32_t, void*) = nullptr; + /** + * Call back for raw data + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * dataSize in bytes is the size of the data in bytes. + */ + void (*rawDataReadyCallBack)(char *, char *, uint32_t, void *) = nullptr; /** * Call back for raw data (modified) * args to raw data ready callback are * sls_receiver_header frame metadata * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * revDatasize is the reference of data size in bytes. Can be modified to + * the new size to be written/streamed. (only smaller value). */ - void (*rawDataModifyReadyCallBack)(char* , - char*, uint32_t &, void*) = nullptr; + void (*rawDataModifyReadyCallBack)(char *, char *, uint32_t &, + void *) = nullptr; - void *pRawDataReady{nullptr}; + void *pRawDataReady{nullptr}; + protected: + std::unique_ptr server{nullptr}; + private: + void VerifyLock(); + void VerifyIdle(sls::ServerInterface2 &socket); -protected: - - - std::unique_ptr server{nullptr}; - - private: - void VerifyLock(); - void VerifyIdle(sls::ServerInterface2& socket); - - slsReceiverImplementation* impl(){ - if (receiver!=nullptr){ - return receiver.get(); - }else{ - throw sls::SocketError("Receiver not set up. Please use rx_hostname first.\n"); - } - } + slsReceiverImplementation *impl() { + if (receiver != nullptr) { + return receiver.get(); + } else { + throw sls::SocketError( + "Receiver not set up. Please use rx_hostname first.\n"); + } + } }; diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index 9a9ff9707..7248cfdd5 100755 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -1,8 +1,10 @@ -/********************************************//** - * @file slsReceiverImplementation.cpp - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - ***********************************************/ - +/********************************************/ /** + * @file + *slsReceiverImplementation.cpp + * @short does all the functions + *for a receiver, set/get + *parameters, start/stop etc. + ***********************************************/ #include "slsReceiverImplementation.h" #include "DataProcessor.h" @@ -10,120 +12,116 @@ #include "Fifo.h" #include "GeneralData.h" #include "Listener.h" -#include "ZmqSocket.h" //just for the zmq port define +#include "ZmqSocket.h" //just for the zmq port define -#include //eperm -#include //system +#include //eperm +#include //system #include -#include //strcpy +#include //strcpy #include #include -#include // stat - +#include // stat /** cosntructor & destructor */ slsReceiverImplementation::slsReceiverImplementation() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - InitializeMembers(); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + InitializeMembers(); } - slsReceiverImplementation::~slsReceiverImplementation() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - DeleteMembers(); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + DeleteMembers(); } - void slsReceiverImplementation::DeleteMembers() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if (generalData) { - delete generalData; - generalData=nullptr; - } + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + if (generalData) { + delete generalData; + generalData = nullptr; + } - listener.clear(); - dataProcessor.clear(); - dataStreamer.clear(); - fifo.clear(); - ctbDbitList.clear(); + listener.clear(); + dataProcessor.clear(); + dataStreamer.clear(); + fifo.clear(); + ctbDbitList.clear(); } - void slsReceiverImplementation::InitializeMembers() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - //**detector parameters*** - myDetectorType = GENERIC; - for (int i = 0; i < MAX_DIMENSIONS; ++i) - numDet[i] = 0; - detID = 0; - strcpy(detHostname,""); - acquisitionPeriod = SAMPLE_TIME_IN_NS; - acquisitionTime = 0; - subExpTime = 0; - subPeriod = 0; - numberOfFrames = 0; - numberOfAnalogSamples = 0; - numberOfDigitalSamples = 0; - dynamicRange = 16; - tengigaEnable = false; - fifoDepth = 0; - flippedData[0] = 0; - flippedData[1] = 0; - gapPixelsEnable = false; - readoutFlags = GET_READOUT_FLAGS; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + //**detector parameters*** + myDetectorType = GENERIC; + for (int i = 0; i < MAX_DIMENSIONS; ++i) + numDet[i] = 0; + detID = 0; + strcpy(detHostname, ""); + acquisitionPeriod = SAMPLE_TIME_IN_NS; + acquisitionTime = 0; + subExpTime = 0; + subPeriod = 0; + numberOfFrames = 0; + numberOfAnalogSamples = 0; + numberOfDigitalSamples = 0; + dynamicRange = 16; + tengigaEnable = false; + fifoDepth = 0; + flippedData[0] = 0; + flippedData[1] = 0; + gapPixelsEnable = false; + readoutFlags = GET_READOUT_FLAGS; - //*** receiver parameters *** - numThreads = 1; - status = IDLE; - activated = true; - deactivatedPaddingEnable = true; - frameDiscardMode = NO_DISCARD; - framePadding = false; - silentMode = false; - ctbDbitOffset = 0; - ctbAnalogDataBytes = 0; + //*** receiver parameters *** + numThreads = 1; + status = IDLE; + activated = true; + deactivatedPaddingEnable = true; + frameDiscardMode = NO_DISCARD; + framePadding = false; + silentMode = false; + ctbDbitOffset = 0; + ctbAnalogDataBytes = 0; - //***connection parameters*** - numUDPInterfaces = 1; - for(int i=0;i 1) return -1; - return flippedData[axis]; +int slsReceiverImplementation::getFlippedData(int axis) const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + if (axis < 0 || axis > 1) + return -1; + return flippedData[axis]; } bool slsReceiverImplementation::getGapPixelsEnable() const { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return gapPixelsEnable; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return gapPixelsEnable; } -slsDetectorDefs::readOutFlags slsReceiverImplementation::getReadOutFlags() const { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return readoutFlags; +slsDetectorDefs::readOutFlags +slsReceiverImplementation::getReadOutFlags() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return readoutFlags; } - /***file parameters***/ -slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return fileFormatType; +slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return fileFormatType; } - -std::string slsReceiverImplementation::getFileName() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return std::string(fileName); +std::string slsReceiverImplementation::getFileName() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return std::string(fileName); } -std::string slsReceiverImplementation::getFilePath() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return std::string(filePath); +std::string slsReceiverImplementation::getFilePath() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return std::string(filePath); } -uint64_t slsReceiverImplementation::getFileIndex() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return fileIndex; +uint64_t slsReceiverImplementation::getFileIndex() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return fileIndex; } -uint32_t slsReceiverImplementation::getFramesPerFile() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return framesPerFile; +uint32_t slsReceiverImplementation::getFramesPerFile() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return framesPerFile; } -slsDetectorDefs::frameDiscardPolicy slsReceiverImplementation::getFrameDiscardPolicy() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return frameDiscardMode; +slsDetectorDefs::frameDiscardPolicy +slsReceiverImplementation::getFrameDiscardPolicy() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return frameDiscardMode; } -bool slsReceiverImplementation::getFramePaddingEnable() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return framePadding; +bool slsReceiverImplementation::getFramePaddingEnable() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return framePadding; } - -bool slsReceiverImplementation::getFileWriteEnable() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return fileWriteEnable; +bool slsReceiverImplementation::getFileWriteEnable() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return fileWriteEnable; } -bool slsReceiverImplementation::getMasterFileWriteEnable() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return masterFileWriteEnable; +bool slsReceiverImplementation::getMasterFileWriteEnable() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return masterFileWriteEnable; } -bool slsReceiverImplementation::getOverwriteEnable() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return overwriteEnable; +bool slsReceiverImplementation::getOverwriteEnable() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return overwriteEnable; } - /***acquisition count parameters***/ uint64_t slsReceiverImplementation::getTotalFramesCaught() const { - uint64_t sum = 0; - uint32_t flagsum = 0; + uint64_t sum = 0; + uint32_t flagsum = 0; - for (const auto& it : dataProcessor) { - flagsum += it->GetMeasurementStartedFlag(); - sum += it->GetNumTotalFramesCaught(); - } - //no data processed - if (flagsum != dataProcessor.size()) - return 0; - - return (sum/dataProcessor.size()); + for (const auto &it : dataProcessor) { + flagsum += it->GetMeasurementStartedFlag(); + sum += it->GetNumTotalFramesCaught(); + } + // no data processed + if (flagsum != dataProcessor.size()) + return 0; + + return (sum / dataProcessor.size()); } uint64_t slsReceiverImplementation::getFramesCaught() const { - uint64_t sum = 0; - uint32_t flagsum = 0; + uint64_t sum = 0; + uint32_t flagsum = 0; - for (const auto& it : dataProcessor) { - flagsum += it->GetMeasurementStartedFlag(); - sum += it->GetNumFramesCaught(); - } - //no data processed - if (flagsum != dataProcessor.size()) - return 0; + for (const auto &it : dataProcessor) { + flagsum += it->GetMeasurementStartedFlag(); + sum += it->GetNumFramesCaught(); + } + // no data processed + if (flagsum != dataProcessor.size()) + return 0; - return (sum/dataProcessor.size()); + return (sum / dataProcessor.size()); } uint64_t slsReceiverImplementation::getAcquisitionIndex() const { - uint64_t sum = 0; - uint32_t flagsum = 0; + uint64_t sum = 0; + uint32_t flagsum = 0; - for (const auto& it : dataProcessor) { - flagsum += it->GetMeasurementStartedFlag(); - sum += it->GetActualProcessedAcquisitionIndex(); - } - //no data processed - if (flagsum != dataProcessor.size()) - return 0; + for (const auto &it : dataProcessor) { + flagsum += it->GetMeasurementStartedFlag(); + sum += it->GetActualProcessedAcquisitionIndex(); + } + // no data processed + if (flagsum != dataProcessor.size()) + return 0; - return (sum/dataProcessor.size()); + return (sum / dataProcessor.size()); } - - - /***connection parameters***/ -uint32_t slsReceiverImplementation::getUDPPortNumber() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return udpPortNum[0]; +uint32_t slsReceiverImplementation::getUDPPortNumber() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return udpPortNum[0]; } -uint32_t slsReceiverImplementation::getUDPPortNumber2() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return udpPortNum[1]; +uint32_t slsReceiverImplementation::getUDPPortNumber2() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return udpPortNum[1]; } -std::string slsReceiverImplementation::getEthernetInterface() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return std::string(eth[0]); +std::string slsReceiverImplementation::getEthernetInterface() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return std::string(eth[0]); } -std::string slsReceiverImplementation::getEthernetInterface2() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return std::string(eth[1]); +std::string slsReceiverImplementation::getEthernetInterface2() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return std::string(eth[1]); } -int slsReceiverImplementation::getNumberofUDPInterfaces() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return numUDPInterfaces; +int slsReceiverImplementation::getNumberofUDPInterfaces() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return numUDPInterfaces; } - /***acquisition parameters***/ -std::vector slsReceiverImplementation::getROI() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return roi; +std::vector slsReceiverImplementation::getROI() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return roi; } -uint32_t slsReceiverImplementation::getADCEnableMask() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return adcEnableMask; +uint32_t slsReceiverImplementation::getADCEnableMask() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return adcEnableMask; } -uint32_t slsReceiverImplementation::getStreamingFrequency() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return streamingFrequency; +uint32_t slsReceiverImplementation::getStreamingFrequency() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return streamingFrequency; } -uint32_t slsReceiverImplementation::getStreamingTimer() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return streamingTimerInMs; +uint32_t slsReceiverImplementation::getStreamingTimer() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return streamingTimerInMs; } -bool slsReceiverImplementation::getDataStreamEnable() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return dataStreamEnable; +bool slsReceiverImplementation::getDataStreamEnable() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return dataStreamEnable; } -uint64_t slsReceiverImplementation::getAcquisitionPeriod() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return acquisitionPeriod; +uint64_t slsReceiverImplementation::getAcquisitionPeriod() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return acquisitionPeriod; } -uint64_t slsReceiverImplementation::getAcquisitionTime() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return acquisitionTime; +uint64_t slsReceiverImplementation::getAcquisitionTime() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return acquisitionTime; } -uint64_t slsReceiverImplementation::getSubExpTime() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return subExpTime; +uint64_t slsReceiverImplementation::getSubExpTime() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return subExpTime; } -uint64_t slsReceiverImplementation::getSubPeriod() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return subPeriod; +uint64_t slsReceiverImplementation::getSubPeriod() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return subPeriod; } -uint64_t slsReceiverImplementation::getNumberOfFrames() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return numberOfFrames; +uint64_t slsReceiverImplementation::getNumberOfFrames() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return numberOfFrames; } -uint64_t slsReceiverImplementation::getNumberofAnalogSamples() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return numberOfAnalogSamples; +uint64_t slsReceiverImplementation::getNumberofAnalogSamples() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return numberOfAnalogSamples; } -uint64_t slsReceiverImplementation::getNumberofDigitalSamples() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return numberOfDigitalSamples; +uint64_t slsReceiverImplementation::getNumberofDigitalSamples() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return numberOfDigitalSamples; } -uint32_t slsReceiverImplementation::getDynamicRange() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return dynamicRange;} - -bool slsReceiverImplementation::getTenGigaEnable() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return tengigaEnable; +uint32_t slsReceiverImplementation::getDynamicRange() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return dynamicRange; } -uint32_t slsReceiverImplementation::getFifoDepth() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return fifoDepth; +bool slsReceiverImplementation::getTenGigaEnable() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return tengigaEnable; +} + +uint32_t slsReceiverImplementation::getFifoDepth() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return fifoDepth; } /***receiver status***/ -slsDetectorDefs::runStatus slsReceiverImplementation::getStatus() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return status; +slsDetectorDefs::runStatus slsReceiverImplementation::getStatus() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return status; } -bool slsReceiverImplementation::getSilentMode() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return silentMode; +bool slsReceiverImplementation::getSilentMode() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return silentMode; } -std::vector slsReceiverImplementation::getDbitList() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return ctbDbitList; +std::vector slsReceiverImplementation::getDbitList() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return ctbDbitList; } -int slsReceiverImplementation::getDbitOffset() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return ctbDbitOffset; +int slsReceiverImplementation::getDbitOffset() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return ctbDbitOffset; } -bool slsReceiverImplementation::getActivate() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return activated; +bool slsReceiverImplementation::getActivate() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return activated; } -bool slsReceiverImplementation::getDeactivatedPadding() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return deactivatedPaddingEnable; +bool slsReceiverImplementation::getDeactivatedPadding() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return deactivatedPaddingEnable; } -uint32_t slsReceiverImplementation::getStreamingPort() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return streamingPort; +uint32_t slsReceiverImplementation::getStreamingPort() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return streamingPort; } -std::string slsReceiverImplementation::getStreamingSourceIP() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return std::string(streamingSrcIP); +std::string slsReceiverImplementation::getStreamingSourceIP() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return std::string(streamingSrcIP); } -std::string slsReceiverImplementation::getAdditionalJsonHeader() const{ - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return std::string(additionalJsonHeader); +std::string slsReceiverImplementation::getAdditionalJsonHeader() const { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return std::string(additionalJsonHeader); } int64_t slsReceiverImplementation::getUDPSocketBufferSize() const { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return udpSocketBufferSize; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return udpSocketBufferSize; } int64_t slsReceiverImplementation::getActualUDPSocketBufferSize() const { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return actualUDPSocketBufferSize; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return actualUDPSocketBufferSize; } - /************************************************************************* * Setters *************************************************************** * They modify the local cache of configuration or detector parameters *** @@ -434,1163 +427,1199 @@ int64_t slsReceiverImplementation::getActualUDPSocketBufferSize() const { /**initial parameters***/ void slsReceiverImplementation::setDetectorHostname(const char *c) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if(strlen(c)) - strcpy(detHostname, c); - FILE_LOG(logINFO) << "Detector Hostname: " << detHostname; + if (strlen(c)) + strcpy(detHostname, c); + FILE_LOG(logINFO) << "Detector Hostname: " << detHostname; } - -void slsReceiverImplementation::setMultiDetectorSize(const int* size) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - std::string log_message = "Detector Size (ports): ("; - for (int i = 0; i < MAX_DIMENSIONS; ++i) { - // x dir (colums) each udp port - if (myDetectorType == EIGER && i == X) - numDet[i] = size[i] * 2; - // y dir (rows) each udp port - else if (numUDPInterfaces == 2 && i == Y) - numDet[i] = size[i] * 2; - else - numDet[i] = size[i]; - log_message += std::to_string(numDet[i]); - if (i < MAX_DIMENSIONS-1 ) - log_message += ", "; - } - log_message += ")"; - FILE_LOG(logINFO) << log_message; +void slsReceiverImplementation::setMultiDetectorSize(const int *size) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + std::string log_message = "Detector Size (ports): ("; + for (int i = 0; i < MAX_DIMENSIONS; ++i) { + // x dir (colums) each udp port + if (myDetectorType == EIGER && i == X) + numDet[i] = size[i] * 2; + // y dir (rows) each udp port + else if (numUDPInterfaces == 2 && i == Y) + numDet[i] = size[i] * 2; + else + numDet[i] = size[i]; + log_message += std::to_string(numDet[i]); + if (i < MAX_DIMENSIONS - 1) + log_message += ", "; + } + log_message += ")"; + FILE_LOG(logINFO) << log_message; } - void slsReceiverImplementation::setFlippedData(int axis, int enable) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if(axis<0 || axis>1) - return; - flippedData[axis] = enable==0?0:1; - FILE_LOG(logINFO) << "Flipped Data: " << flippedData[0] << " , " << flippedData[1]; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + if (axis < 0 || axis > 1) + return; + flippedData[axis] = enable == 0 ? 0 : 1; + FILE_LOG(logINFO) << "Flipped Data: " << flippedData[0] << " , " + << flippedData[1]; } - int slsReceiverImplementation::setGapPixelsEnable(const bool b) { - if (gapPixelsEnable != b) { - gapPixelsEnable = b; + if (gapPixelsEnable != b) { + gapPixelsEnable = b; - // side effects - generalData->SetGapPixelsEnable(b, dynamicRange); - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } - FILE_LOG(logINFO) << "Gap Pixels Enable: " << gapPixelsEnable; - return OK; + // side effects + generalData->SetGapPixelsEnable(b, dynamicRange); + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } + FILE_LOG(logINFO) << "Gap Pixels Enable: " << gapPixelsEnable; + return OK; } - int slsReceiverImplementation::setReadOutFlags(const readOutFlags f) { - if (readoutFlags != f) { - readoutFlags = f; + if (readoutFlags != f) { + readoutFlags = f; - // side effects - if (myDetectorType == CHIPTESTBOARD) { - ctbAnalogDataBytes = generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable, readoutFlags); - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } - } - std::string flag; - if (f == NORMAL_READOUT) - flag = "normal(analog, no digital)"; - else if (f & STORE_IN_RAM) - flag.append("storeinram "); - if (f & TOT_MODE) - flag.append("tot "); - if (f & CONTINOUS_RO) - flag.append("continous "); - if (f & PARALLEL) - flag.append("parallel "); - if (f & NONPARALLEL) - flag.append("nonparallel "); - if (f & SAFE) - flag.append("safe "); - if (f & DIGITAL_ONLY) - flag.append("digital "); - if (f & ANALOG_AND_DIGITAL) - flag.append("analog_digital "); - if (f & SHOW_OVERFLOW) - flag.append("overflow "); - if (f & NOOVERFLOW) - flag.append("nooverflow "); + // side effects + if (myDetectorType == CHIPTESTBOARD) { + ctbAnalogDataBytes = generalData->setImageSize( + adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, + tengigaEnable, readoutFlags); + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } + } + std::string flag; + if (f == NORMAL_READOUT) + flag = "normal(analog, no digital)"; + else if (f & STORE_IN_RAM) + flag.append("storeinram "); + if (f & TOT_MODE) + flag.append("tot "); + if (f & CONTINOUS_RO) + flag.append("continous "); + if (f & PARALLEL) + flag.append("parallel "); + if (f & NONPARALLEL) + flag.append("nonparallel "); + if (f & SAFE) + flag.append("safe "); + if (f & DIGITAL_ONLY) + flag.append("digital "); + if (f & ANALOG_AND_DIGITAL) + flag.append("analog_digital "); + if (f & SHOW_OVERFLOW) + flag.append("overflow "); + if (f & NOOVERFLOW) + flag.append("nooverflow "); - FILE_LOG(logINFO) << "ReadoutFlags: " << flag; - if (myDetectorType == CHIPTESTBOARD) { - FILE_LOG (logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); - } - return OK; + FILE_LOG(logINFO) << "ReadoutFlags: " << flag; + if (myDetectorType == CHIPTESTBOARD) { + FILE_LOG(logINFO) << "Packets per Frame: " + << (generalData->packetsPerFrame); + } + return OK; } - void slsReceiverImplementation::setFileFormat(const fileFormat f) { - switch(f) { + switch (f) { #ifdef HDF5C - case HDF5: - fileFormatType = HDF5; - break; + case HDF5: + fileFormatType = HDF5; + break; #endif - default: - fileFormatType = BINARY; - break; - } + default: + fileFormatType = BINARY; + break; + } - for(const auto& it : dataProcessor) - it->SetFileFormat(f); + for (const auto &it : dataProcessor) + it->SetFileFormat(f); - FILE_LOG(logINFO) << "File Format: " << getFileFormatType(fileFormatType); + FILE_LOG(logINFO) << "File Format: " << getFileFormatType(fileFormatType); } - void slsReceiverImplementation::setFileName(const char c[]) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if(strlen(c)) - strcpy(fileName, c); - FILE_LOG(logINFO) << "File name: " << fileName; + if (strlen(c)) + strcpy(fileName, c); + FILE_LOG(logINFO) << "File name: " << fileName; } - void slsReceiverImplementation::setFilePath(const char c[]) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - - if(strlen(c)) { - //check if filepath exists - struct stat st; - if(stat(c,&st) == 0) - strcpy(filePath,c); - else - FILE_LOG(logERROR) << "FilePath does not exist: " << c; - } - FILE_LOG(logINFO) << "File path: " << filePath; + if (strlen(c)) { + // check if filepath exists + struct stat st; + if (stat(c, &st) == 0) + strcpy(filePath, c); + else + FILE_LOG(logERROR) << "FilePath does not exist: " << c; + } + FILE_LOG(logINFO) << "File path: " << filePath; } - void slsReceiverImplementation::setFileIndex(const uint64_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - fileIndex = i; - FILE_LOG(logINFO) << "File Index: " << fileIndex; + fileIndex = i; + FILE_LOG(logINFO) << "File Index: " << fileIndex; } - void slsReceiverImplementation::setFramesPerFile(const uint32_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - framesPerFile = i; - FILE_LOG(logINFO) << "Frames per file: " << framesPerFile; + framesPerFile = i; + FILE_LOG(logINFO) << "Frames per file: " << framesPerFile; } +void slsReceiverImplementation::setFrameDiscardPolicy( + const frameDiscardPolicy i) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; -void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + if (i >= 0 && i < NUM_DISCARD_POLICIES) + frameDiscardMode = i; - if (i >= 0 && i < NUM_DISCARD_POLICIES) - frameDiscardMode = i; - - FILE_LOG(logINFO) << "Frame Discard Policy: " << getFrameDiscardPolicyType(frameDiscardMode); + FILE_LOG(logINFO) << "Frame Discard Policy: " + << getFrameDiscardPolicyType(frameDiscardMode); } - void slsReceiverImplementation::setFramePaddingEnable(const bool i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - framePadding = i; - FILE_LOG(logINFO) << "Frame Padding: " << framePadding; + framePadding = i; + FILE_LOG(logINFO) << "Frame Padding: " << framePadding; } - void slsReceiverImplementation::setFileWriteEnable(const bool b) { - if (fileWriteEnable != b) { - fileWriteEnable = b; - for (unsigned int i = 0; i < dataProcessor.size(); ++i) { - dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet, - &framesPerFile, fileName, filePath, &fileIndex, &overwriteEnable, - &detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i], - generalData); - } - } + if (fileWriteEnable != b) { + fileWriteEnable = b; + for (unsigned int i = 0; i < dataProcessor.size(); ++i) { + dataProcessor[i]->SetupFileWriter( + fileWriteEnable, (int *)numDet, &framesPerFile, fileName, + filePath, &fileIndex, &overwriteEnable, &detID, &numThreads, + &numberOfFrames, &dynamicRange, &udpPortNum[i], generalData); + } + } - FILE_LOG(logINFO) << "File Write Enable: " << stringEnable(fileWriteEnable); + FILE_LOG(logINFO) << "File Write Enable: " << stringEnable(fileWriteEnable); } void slsReceiverImplementation::setMasterFileWriteEnable(const bool b) { - masterFileWriteEnable = b; + masterFileWriteEnable = b; - FILE_LOG(logINFO) << "Master File Write Enable: " << stringEnable(masterFileWriteEnable); + FILE_LOG(logINFO) << "Master File Write Enable: " + << stringEnable(masterFileWriteEnable); } - void slsReceiverImplementation::setOverwriteEnable(const bool b) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - overwriteEnable = b; - FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable); + overwriteEnable = b; + FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable); } - /***connection parameters***/ void slsReceiverImplementation::setUDPPortNumber(const uint32_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - udpPortNum[0] = i; - FILE_LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0]; + udpPortNum[0] = i; + FILE_LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0]; } void slsReceiverImplementation::setUDPPortNumber2(const uint32_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - udpPortNum[1] = i; - FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1]; + udpPortNum[1] = i; + FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1]; } -void slsReceiverImplementation::setEthernetInterface(const char* c) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; +void slsReceiverImplementation::setEthernetInterface(const char *c) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - strcpy(eth[0], c); - FILE_LOG(logINFO) << "Ethernet Interface: " << eth[0]; + strcpy(eth[0], c); + FILE_LOG(logINFO) << "Ethernet Interface: " << eth[0]; } -void slsReceiverImplementation::setEthernetInterface2(const char* c) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; +void slsReceiverImplementation::setEthernetInterface2(const char *c) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - strcpy(eth[1], c); - FILE_LOG(logINFO) << "Ethernet Interface 2: " << eth[1]; + strcpy(eth[1], c); + FILE_LOG(logINFO) << "Ethernet Interface 2: " << eth[1]; } int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if (numUDPInterfaces != n) { + if (numUDPInterfaces != n) { - // reduce number of detectors in y dir (rows) if it had 2 interfaces before - if (numUDPInterfaces == 2) - numDet[Y] /= 2; + // reduce number of detectors in y dir (rows) if it had 2 interfaces + // before + if (numUDPInterfaces == 2) + numDet[Y] /= 2; - numUDPInterfaces = n; + numUDPInterfaces = n; - // clear all threads and fifos - listener.clear(); - dataProcessor.clear(); - dataStreamer.clear(); - fifo.clear(); + // clear all threads and fifos + listener.clear(); + dataProcessor.clear(); + dataStreamer.clear(); + fifo.clear(); - // set local variables - generalData->SetNumberofInterfaces(n); - numThreads = generalData->threadsPerReceiver; - udpSocketBufferSize = generalData->defaultUdpSocketBufferSize; + // set local variables + generalData->SetNumberofInterfaces(n); + numThreads = generalData->threadsPerReceiver; + udpSocketBufferSize = generalData->defaultUdpSocketBufferSize; - // fifo - if (SetupFifoStructure() == FAIL) - return FAIL; + // fifo + if (SetupFifoStructure() == FAIL) + return FAIL; - //create threads - for ( int i = 0; i < numThreads; ++i ) { - // listener and dataprocessor threads - try { - auto fifo_ptr = fifo[i].get(); - listener.push_back(sls::make_unique(i, myDetectorType, fifo_ptr, &status, - &udpPortNum[i], eth[i], &numberOfFrames, &dynamicRange, - &udpSocketBufferSize, &actualUDPSocketBufferSize, &framesPerFile, - &frameDiscardMode, &activated, &deactivatedPaddingEnable, &silentMode)); - listener[i]->SetGeneralData(generalData); + // create threads + for (int i = 0; i < numThreads; ++i) { + // listener and dataprocessor threads + try { + auto fifo_ptr = fifo[i].get(); + listener.push_back(sls::make_unique( + i, myDetectorType, fifo_ptr, &status, &udpPortNum[i], + eth[i], &numberOfFrames, &dynamicRange, + &udpSocketBufferSize, &actualUDPSocketBufferSize, + &framesPerFile, &frameDiscardMode, &activated, + &deactivatedPaddingEnable, &silentMode)); + listener[i]->SetGeneralData(generalData); - dataProcessor.push_back(sls::make_unique(i, myDetectorType, fifo_ptr, &fileFormatType, - fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, - &dynamicRange, &streamingFrequency, &streamingTimerInMs, - &framePadding, &activated, &deactivatedPaddingEnable, &silentMode, - &ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes)); - dataProcessor[i]->SetGeneralData(generalData); - } - catch (...) { - FILE_LOG(logERROR) << "Could not create listener/dataprocessor threads (index:" << i << ")"; - listener.clear(); - dataProcessor.clear(); - return FAIL; - } - // streamer threads - if (dataStreamEnable) { - try { + dataProcessor.push_back(sls::make_unique( + i, myDetectorType, fifo_ptr, &fileFormatType, + fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, + &gapPixelsEnable, &dynamicRange, &streamingFrequency, + &streamingTimerInMs, &framePadding, &activated, + &deactivatedPaddingEnable, &silentMode, &ctbDbitList, + &ctbDbitOffset, &ctbAnalogDataBytes)); + dataProcessor[i]->SetGeneralData(generalData); + } catch (...) { + FILE_LOG(logERROR) + << "Could not create listener/dataprocessor threads (index:" + << i << ")"; + listener.clear(); + dataProcessor.clear(); + return FAIL; + } + // streamer threads + if (dataStreamEnable) { + try { - dataStreamer.push_back(sls::make_unique(i, fifo[i].get(), &dynamicRange, - &roi, &fileIndex, flippedData, additionalJsonHeader)); - dataStreamer[i]->SetGeneralData(generalData); - dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort, streamingSrcIP); + dataStreamer.push_back(sls::make_unique( + i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, + flippedData, additionalJsonHeader)); + dataStreamer[i]->SetGeneralData(generalData); + dataStreamer[i]->CreateZmqSockets( + &numThreads, streamingPort, streamingSrcIP); - } catch(...) { - FILE_LOG(logERROR) << "Could not create datastreamer threads (index:" << i << ")"; - if (dataStreamEnable) { - dataStreamer.clear(); - dataStreamEnable = false; - } - return FAIL; - } - } - } + } catch (...) { + FILE_LOG(logERROR) + << "Could not create datastreamer threads (index:" << i + << ")"; + if (dataStreamEnable) { + dataStreamer.clear(); + dataStreamEnable = false; + } + return FAIL; + } + } + } - SetThreadPriorities(); + SetThreadPriorities(); - // update (from 1 to 2 interface) & also for printout - setMultiDetectorSize(numDet); - // update row and column in dataprocessor - setDetectorPositionId(detID); + // update (from 1 to 2 interface) & also for printout + setMultiDetectorSize(numDet); + // update row and column in dataprocessor + setDetectorPositionId(detID); - // update call backs - if(rawDataReadyCallBack) { - for (const auto& it : dataProcessor) - it->registerCallBackRawDataReady(rawDataReadyCallBack,pRawDataReady); - } - if(rawDataModifyReadyCallBack) { - for (const auto& it : dataProcessor) - it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); - } + // update call backs + if (rawDataReadyCallBack) { + for (const auto &it : dataProcessor) + it->registerCallBackRawDataReady(rawDataReadyCallBack, + pRawDataReady); + } + if (rawDataModifyReadyCallBack) { + for (const auto &it : dataProcessor) + it->registerCallBackRawDataModifyReady( + rawDataModifyReadyCallBack, pRawDataReady); + } - // test socket buffer size with current set up - if (setUDPSocketBufferSize(0) == FAIL) { - return FAIL; - } - } + // test socket buffer size with current set up + if (setUDPSocketBufferSize(0) == FAIL) { + return FAIL; + } + } - FILE_LOG(logINFO) << "Number of Interfaces: " << numUDPInterfaces; - return OK; + FILE_LOG(logINFO) << "Number of Interfaces: " << numUDPInterfaces; + return OK; } int slsReceiverImplementation::setUDPSocketBufferSize(const int64_t s) { - int64_t size = (s == 0) ? udpSocketBufferSize : s; - size_t listSize = listener.size(); + int64_t size = (s == 0) ? udpSocketBufferSize : s; + size_t listSize = listener.size(); - if (myDetectorType == JUNGFRAU && (int)listSize != numUDPInterfaces) { - FILE_LOG(logERROR) << "Number of Interfaces " << numUDPInterfaces << " do not match listener size " << listSize; - return FAIL; - } + if (myDetectorType == JUNGFRAU && (int)listSize != numUDPInterfaces) { + FILE_LOG(logERROR) << "Number of Interfaces " << numUDPInterfaces + << " do not match listener size " << listSize; + return FAIL; + } - for (unsigned int i = 0; i < listSize; ++i) { - if (listener[i]->CreateDummySocketForUDPSocketBufferSize(size) == FAIL) - return FAIL; - } + for (unsigned int i = 0; i < listSize; ++i) { + if (listener[i]->CreateDummySocketForUDPSocketBufferSize(size) == FAIL) + return FAIL; + } - return OK; + return OK; } - /***acquisition parameters***/ -int slsReceiverImplementation::setROI(const std::vector new_roi) { - bool change = false; +int slsReceiverImplementation::setROI( + const std::vector new_roi) { + bool change = false; if (roi.size() != new_roi.size()) - change = true; - else { - for (size_t i = 0; i != new_roi.size(); ++i) { - if ((roi[i].xmin != new_roi[i].xmin) || - (roi[i].xmax != new_roi[i].xmax) || - (roi[i].ymin != new_roi[i].ymin) || - (roi[i].xmax != new_roi[i].xmax)) { - change = true; - break; - } - } - } - - if (change) { - roi = new_roi; - switch (myDetectorType) { - case GOTTHARD: - generalData->SetROI(new_roi); - framesPerFile = generalData->maxFramesPerFile; + change = true; + else { + for (size_t i = 0; i != new_roi.size(); ++i) { + if ((roi[i].xmin != new_roi[i].xmin) || + (roi[i].xmax != new_roi[i].xmax) || + (roi[i].ymin != new_roi[i].ymin) || + (roi[i].xmax != new_roi[i].xmax)) { + change = true; break; - default: - break; - } - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } + } + } + } + if (change) { + roi = new_roi; + switch (myDetectorType) { + case GOTTHARD: + generalData->SetROI(new_roi); + framesPerFile = generalData->maxFramesPerFile; + break; + default: + break; + } + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } - std::stringstream sstm; - sstm << "ROI: "; - if (!roi.size()) - sstm << "0"; - else { - for (size_t i = 0; i < roi.size(); ++i) { - sstm << "( " << - roi[i].xmin << ", " << - roi[i].xmax << ", " << - roi[i].ymin << ", " << - roi[i].ymax << " )"; - } - } - std::string message = sstm.str(); - FILE_LOG(logINFO) << message; - FILE_LOG (logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); - return OK; + std::stringstream sstm; + sstm << "ROI: "; + if (!roi.size()) + sstm << "0"; + else { + for (size_t i = 0; i < roi.size(); ++i) { + sstm << "( " << roi[i].xmin << ", " << roi[i].xmax << ", " + << roi[i].ymin << ", " << roi[i].ymax << " )"; + } + } + std::string message = sstm.str(); + FILE_LOG(logINFO) << message; + FILE_LOG(logINFO) << "Packets per Frame: " + << (generalData->packetsPerFrame); + return OK; } int slsReceiverImplementation::setADCEnableMask(uint32_t mask) { - if (adcEnableMask != mask) { - adcEnableMask = mask; + if (adcEnableMask != mask) { + adcEnableMask = mask; - switch (myDetectorType) { - case MOENCH: - generalData->setImageSize(mask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable); - break; - case CHIPTESTBOARD: - ctbAnalogDataBytes = generalData->setImageSize(mask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable, readoutFlags); - break; - default: - break; - } - - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } + switch (myDetectorType) { + case MOENCH: + generalData->setImageSize(mask, numberOfAnalogSamples, + numberOfDigitalSamples, tengigaEnable); + break; + case CHIPTESTBOARD: + ctbAnalogDataBytes = generalData->setImageSize( + mask, numberOfAnalogSamples, numberOfDigitalSamples, + tengigaEnable, readoutFlags); + break; + default: + break; + } - FILE_LOG(logINFO) << "ADC Enable Mask: 0x" << std::hex << adcEnableMask << std::dec; - FILE_LOG (logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); - return OK; + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } + + FILE_LOG(logINFO) << "ADC Enable Mask: 0x" << std::hex << adcEnableMask + << std::dec; + FILE_LOG(logINFO) << "Packets per Frame: " + << (generalData->packetsPerFrame); + return OK; } - int slsReceiverImplementation::setStreamingFrequency(const uint32_t freq) { - if (streamingFrequency != freq) { - streamingFrequency = freq; - } - FILE_LOG(logINFO) << "Streaming Frequency: " << streamingFrequency; - return OK; + if (streamingFrequency != freq) { + streamingFrequency = freq; + } + FILE_LOG(logINFO) << "Streaming Frequency: " << streamingFrequency; + return OK; } void slsReceiverImplementation::setStreamingTimer(const uint32_t time_in_ms) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - streamingTimerInMs = time_in_ms; - FILE_LOG(logINFO) << "Streamer Timer: " << streamingTimerInMs; + streamingTimerInMs = time_in_ms; + FILE_LOG(logINFO) << "Streamer Timer: " << streamingTimerInMs; } - int slsReceiverImplementation::setDataStreamEnable(const bool enable) { - if (dataStreamEnable != enable) { - dataStreamEnable = enable; + if (dataStreamEnable != enable) { + dataStreamEnable = enable; - //data sockets have to be created again as the client ones are - dataStreamer.clear(); + // data sockets have to be created again as the client ones are + dataStreamer.clear(); - if (enable) { - for ( int i = 0; i < numThreads; ++i ) { - try { - dataStreamer.push_back(sls::make_unique(i, fifo[i].get(), &dynamicRange, - &roi, &fileIndex, flippedData, additionalJsonHeader)); - dataStreamer[i]->SetGeneralData(generalData); - dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort, streamingSrcIP); - } - catch(...) { - dataStreamer.clear(); - dataStreamEnable = false; - return FAIL; - } - } - SetThreadPriorities(); - } - } - FILE_LOG(logINFO) << "Data Send to Gui: " << dataStreamEnable; - return OK; + if (enable) { + for (int i = 0; i < numThreads; ++i) { + try { + dataStreamer.push_back(sls::make_unique( + i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, + flippedData, additionalJsonHeader)); + dataStreamer[i]->SetGeneralData(generalData); + dataStreamer[i]->CreateZmqSockets( + &numThreads, streamingPort, streamingSrcIP); + } catch (...) { + dataStreamer.clear(); + dataStreamEnable = false; + return FAIL; + } + } + SetThreadPriorities(); + } + } + FILE_LOG(logINFO) << "Data Send to Gui: " << dataStreamEnable; + return OK; } - void slsReceiverImplementation::setStreamingPort(const uint32_t i) { - streamingPort = i; + streamingPort = i; - FILE_LOG(logINFO) << "Streaming Port: " << streamingPort; + FILE_LOG(logINFO) << "Streaming Port: " << streamingPort; } - void slsReceiverImplementation::setStreamingSourceIP(const char c[]) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - strcpy(streamingSrcIP, c); - FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + strcpy(streamingSrcIP, c); + FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP; } - void slsReceiverImplementation::setAdditionalJsonHeader(const char c[]) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - strcpy(additionalJsonHeader, c); - FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + strcpy(additionalJsonHeader, c); + FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader; } - int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - acquisitionPeriod = i; - FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s"; + acquisitionPeriod = i; + FILE_LOG(logINFO) << "Acquisition Period: " + << (double)acquisitionPeriod / (1E9) << "s"; - return OK; + return OK; } int slsReceiverImplementation::setAcquisitionTime(const uint64_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - acquisitionTime = i; - FILE_LOG(logINFO) << "Acquisition Time: " << (double)acquisitionTime/(1E9) << "s"; + acquisitionTime = i; + FILE_LOG(logINFO) << "Acquisition Time: " << (double)acquisitionTime / (1E9) + << "s"; - return OK; + return OK; } void slsReceiverImplementation::setSubExpTime(const uint64_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - subExpTime = i; - FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subExpTime/(1E9) << "s"; + subExpTime = i; + FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subExpTime / (1E9) + << "s"; } void slsReceiverImplementation::setSubPeriod(const uint64_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - subPeriod = i; - FILE_LOG(logINFO) << "Sub Exposure Period: " << (double)subPeriod/(1E9) << "s"; + subPeriod = i; + FILE_LOG(logINFO) << "Sub Exposure Period: " << (double)subPeriod / (1E9) + << "s"; } void slsReceiverImplementation::setNumberOfFrames(const uint64_t i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - numberOfFrames = i; - FILE_LOG(logINFO) << "Number of Frames: " << numberOfFrames; + numberOfFrames = i; + FILE_LOG(logINFO) << "Number of Frames: " << numberOfFrames; } - int slsReceiverImplementation::setNumberofAnalogSamples(const uint64_t i) { - if (numberOfAnalogSamples != i) { - numberOfAnalogSamples = i; + if (numberOfAnalogSamples != i) { + numberOfAnalogSamples = i; - if(myDetectorType == MOENCH) { - generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable); - } else if(myDetectorType == CHIPTESTBOARD) { - ctbAnalogDataBytes = generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable, readoutFlags); - } - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } - FILE_LOG (logINFO) << "Number of Analog Samples: " << numberOfAnalogSamples; - FILE_LOG (logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); - return OK; + if (myDetectorType == MOENCH) { + generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, + numberOfDigitalSamples, tengigaEnable); + } else if (myDetectorType == CHIPTESTBOARD) { + ctbAnalogDataBytes = generalData->setImageSize( + adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, + tengigaEnable, readoutFlags); + } + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } + FILE_LOG(logINFO) << "Number of Analog Samples: " << numberOfAnalogSamples; + FILE_LOG(logINFO) << "Packets per Frame: " + << (generalData->packetsPerFrame); + return OK; } - int slsReceiverImplementation::setNumberofDigitalSamples(const uint64_t i) { - if (numberOfDigitalSamples != i) { - numberOfDigitalSamples = i; + if (numberOfDigitalSamples != i) { + numberOfDigitalSamples = i; - if(myDetectorType == MOENCH) { - generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable); - } else if(myDetectorType == CHIPTESTBOARD) { - ctbAnalogDataBytes = generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable, readoutFlags); - } - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } - FILE_LOG (logINFO) << "Number of Digital Samples: " << numberOfDigitalSamples; - FILE_LOG (logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); - return OK; + if (myDetectorType == MOENCH) { + generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, + numberOfDigitalSamples, tengigaEnable); + } else if (myDetectorType == CHIPTESTBOARD) { + ctbAnalogDataBytes = generalData->setImageSize( + adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, + tengigaEnable, readoutFlags); + } + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } + FILE_LOG(logINFO) << "Number of Digital Samples: " + << numberOfDigitalSamples; + FILE_LOG(logINFO) << "Packets per Frame: " + << (generalData->packetsPerFrame); + return OK; } - int slsReceiverImplementation::setDynamicRange(const uint32_t i) { - // only eiger - if (dynamicRange != i) { - dynamicRange = i; - generalData->SetDynamicRange(i,tengigaEnable); - generalData->SetGapPixelsEnable(gapPixelsEnable, dynamicRange); - // to update npixelsx, npixelsy in file writer - for (const auto& it : dataProcessor) - it->SetPixelDimension(); - if (SetupFifoStructure() == FAIL) - return FAIL; - } - FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange; - return OK; + // only eiger + if (dynamicRange != i) { + dynamicRange = i; + generalData->SetDynamicRange(i, tengigaEnable); + generalData->SetGapPixelsEnable(gapPixelsEnable, dynamicRange); + // to update npixelsx, npixelsy in file writer + for (const auto &it : dataProcessor) + it->SetPixelDimension(); + if (SetupFifoStructure() == FAIL) + return FAIL; + } + FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange; + return OK; } - int slsReceiverImplementation::setTenGigaEnable(const bool b) { - if (tengigaEnable != b) { - tengigaEnable = b; - //side effects - switch(myDetectorType) { - case EIGER: - generalData->SetTenGigaEnable(b,dynamicRange); - break; - case MOENCH: - generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable); - break; - case CHIPTESTBOARD: - ctbAnalogDataBytes = generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, tengigaEnable, readoutFlags); - break; - default: - break; - } + if (tengigaEnable != b) { + tengigaEnable = b; + // side effects + switch (myDetectorType) { + case EIGER: + generalData->SetTenGigaEnable(b, dynamicRange); + break; + case MOENCH: + generalData->setImageSize(adcEnableMask, numberOfAnalogSamples, + numberOfDigitalSamples, tengigaEnable); + break; + case CHIPTESTBOARD: + ctbAnalogDataBytes = generalData->setImageSize( + adcEnableMask, numberOfAnalogSamples, numberOfDigitalSamples, + tengigaEnable, readoutFlags); + break; + default: + break; + } - if (SetupFifoStructure() == FAIL) - return FAIL; - } - FILE_LOG(logINFO) << "Ten Giga: " << stringEnable(tengigaEnable); - FILE_LOG (logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); - return OK; + if (SetupFifoStructure() == FAIL) + return FAIL; + } + FILE_LOG(logINFO) << "Ten Giga: " << stringEnable(tengigaEnable); + FILE_LOG(logINFO) << "Packets per Frame: " + << (generalData->packetsPerFrame); + return OK; } - int slsReceiverImplementation::setFifoDepth(const uint32_t i) { - if (fifoDepth != i) { - fifoDepth = i; - if (SetupFifoStructure() == FAIL) - throw sls::RuntimeError("Failed to setup fifo structure"); - } - FILE_LOG(logINFO) << "Fifo Depth: " << i; - return OK; + if (fifoDepth != i) { + fifoDepth = i; + if (SetupFifoStructure() == FAIL) + throw sls::RuntimeError("Failed to setup fifo structure"); + } + FILE_LOG(logINFO) << "Fifo Depth: " << i; + return OK; } - /***receiver parameters***/ bool slsReceiverImplementation::setActivate(bool enable) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - activated = enable; - FILE_LOG(logINFO) << "Activation: " << stringEnable(activated); - return activated; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + activated = enable; + FILE_LOG(logINFO) << "Activation: " << stringEnable(activated); + return activated; } - bool slsReceiverImplementation::setDeactivatedPadding(bool enable) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - deactivatedPaddingEnable = enable; - FILE_LOG(logINFO) << "Deactivated Padding Enable: " << stringEnable(deactivatedPaddingEnable); - return deactivatedPaddingEnable; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + deactivatedPaddingEnable = enable; + FILE_LOG(logINFO) << "Deactivated Padding Enable: " + << stringEnable(deactivatedPaddingEnable); + return deactivatedPaddingEnable; } void slsReceiverImplementation::setSilentMode(const bool i) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - silentMode = i; - FILE_LOG(logINFO) << "Silent Mode: " << i; + silentMode = i; + FILE_LOG(logINFO) << "Silent Mode: " << i; } -void slsReceiverImplementation::setDbitList(const std::vector v) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - ctbDbitList = v; +void slsReceiverImplementation::setDbitList(const std::vector v) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + ctbDbitList = v; } void slsReceiverImplementation::setDbitOffset(const int s) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - ctbDbitOffset = s; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + ctbDbitOffset = s; } - - /************************************************************************* * Behavioral functions*************************************************** * They may modify the status of the receiver **************************** *************************************************************************/ - /***initial functions***/ int slsReceiverImplementation::setDetectorType(const detectorType d) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - DeleteMembers(); - InitializeMembers(); - myDetectorType = d; - switch(myDetectorType) { - case GOTTHARD: - case EIGER: - case JUNGFRAU: - case CHIPTESTBOARD: - case MOENCH: - FILE_LOG(logINFO) << " ***** " << detectorTypeToString(d) << " Receiver *****"; - break; - default: - FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; - return FAIL; - } + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + DeleteMembers(); + InitializeMembers(); + myDetectorType = d; + switch (myDetectorType) { + case GOTTHARD: + case EIGER: + case JUNGFRAU: + case CHIPTESTBOARD: + case MOENCH: + FILE_LOG(logINFO) << " ***** " << detectorTypeToString(d) + << " Receiver *****"; + break; + default: + FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; + return FAIL; + } + // set detector specific variables + switch (myDetectorType) { + case GOTTHARD: + generalData = new GotthardData(); + break; + case EIGER: + generalData = new EigerData(); + break; + case JUNGFRAU: + generalData = new JungfrauData(); + break; + case CHIPTESTBOARD: + generalData = new ChipTestBoardData(); + break; + case MOENCH: + generalData = new MoenchData(); + break; + default: + break; + } + numThreads = generalData->threadsPerReceiver; + fifoDepth = generalData->defaultFifoDepth; + udpSocketBufferSize = generalData->defaultUdpSocketBufferSize; + framesPerFile = generalData->maxFramesPerFile; - //set detector specific variables - switch(myDetectorType) { - case GOTTHARD: generalData = new GotthardData(); break; - case EIGER: generalData = new EigerData(); break; - case JUNGFRAU: generalData = new JungfrauData(); break; - case CHIPTESTBOARD: generalData = new ChipTestBoardData(); break; - case MOENCH: generalData = new MoenchData(); break; - default: break; - } - numThreads = generalData->threadsPerReceiver; - fifoDepth = generalData->defaultFifoDepth; - udpSocketBufferSize = generalData->defaultUdpSocketBufferSize; - framesPerFile = generalData->maxFramesPerFile; + SetLocalNetworkParameters(); + if (SetupFifoStructure() == FAIL) { + FILE_LOG(logERROR) << "Could not allocate memory for fifo structure"; + return FAIL; + } - SetLocalNetworkParameters(); - if (SetupFifoStructure() == FAIL) { - FILE_LOG(logERROR) << "Could not allocate memory for fifo structure"; - return FAIL; - } + // create threads + for (int i = 0; i < numThreads; ++i) { - //create threads - for ( int i = 0; i < numThreads; ++i ) { + try { + auto fifo_ptr = fifo[i].get(); + listener.push_back(sls::make_unique( + i, myDetectorType, fifo_ptr, &status, &udpPortNum[i], eth[i], + &numberOfFrames, &dynamicRange, &udpSocketBufferSize, + &actualUDPSocketBufferSize, &framesPerFile, &frameDiscardMode, + &activated, &deactivatedPaddingEnable, &silentMode)); + dataProcessor.push_back(sls::make_unique( + i, myDetectorType, fifo_ptr, &fileFormatType, fileWriteEnable, + &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, + &dynamicRange, &streamingFrequency, &streamingTimerInMs, + &framePadding, &activated, &deactivatedPaddingEnable, + &silentMode, &ctbDbitList, &ctbDbitOffset, + &ctbAnalogDataBytes)); + } catch (...) { + FILE_LOG(logERROR) + << "Could not create listener/dataprocessor threads (index:" + << i << ")"; + listener.clear(); + dataProcessor.clear(); + return FAIL; + } + } - try { - auto fifo_ptr = fifo[i].get(); - listener.push_back(sls::make_unique(i, myDetectorType, fifo_ptr, &status, - &udpPortNum[i], eth[i], &numberOfFrames, &dynamicRange, - &udpSocketBufferSize, &actualUDPSocketBufferSize, &framesPerFile, - &frameDiscardMode, &activated, &deactivatedPaddingEnable, &silentMode)); - dataProcessor.push_back(sls::make_unique(i, myDetectorType, fifo_ptr, &fileFormatType, - fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, - &dynamicRange, &streamingFrequency, &streamingTimerInMs, - &framePadding, &activated, &deactivatedPaddingEnable, &silentMode, - &ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes)); - } - catch (...) { - FILE_LOG(logERROR) << "Could not create listener/dataprocessor threads (index:" << i << ")"; - listener.clear(); - dataProcessor.clear(); - return FAIL; - } - } + // set up writer and callbacks - //set up writer and callbacks + for (const auto &it : listener) + it->SetGeneralData(generalData); + for (const auto &it : dataProcessor) + it->SetGeneralData(generalData); + SetThreadPriorities(); - for (const auto& it : listener) - it->SetGeneralData(generalData); - for (const auto& it : dataProcessor) - it->SetGeneralData(generalData); - SetThreadPriorities(); - - FILE_LOG(logDEBUG) << " Detector type set to " << detectorTypeToString(d); - return OK; + FILE_LOG(logDEBUG) << " Detector type set to " << detectorTypeToString(d); + return OK; } - - - void slsReceiverImplementation::setDetectorPositionId(const int id) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - detID = id; - FILE_LOG(logINFO) << "Detector Position Id:" << detID; - for (unsigned int i = 0; i < dataProcessor.size(); ++i) { - dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet, - &framesPerFile, fileName, filePath, &fileIndex, &overwriteEnable, - &detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i], - generalData); - } - assert(numDet[1] != 0); - for (unsigned int i = 0; i < listener.size(); ++i) { - uint16_t row = 0, col = 0; - row = (detID % numDet[1]) * ((numUDPInterfaces == 2) ? 2 : 1); // row - col = (detID / numDet[1]) * ((myDetectorType == EIGER) ? 2 : 1) + i; // col for horiz. udp ports - listener[i]->SetHardCodedPosition(row, col); - } + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + detID = id; + FILE_LOG(logINFO) << "Detector Position Id:" << detID; + for (unsigned int i = 0; i < dataProcessor.size(); ++i) { + dataProcessor[i]->SetupFileWriter( + fileWriteEnable, (int *)numDet, &framesPerFile, fileName, filePath, + &fileIndex, &overwriteEnable, &detID, &numThreads, &numberOfFrames, + &dynamicRange, &udpPortNum[i], generalData); + } + assert(numDet[1] != 0); + for (unsigned int i = 0; i < listener.size(); ++i) { + uint16_t row = 0, col = 0; + row = (detID % numDet[1]) * ((numUDPInterfaces == 2) ? 2 : 1); // row + col = (detID / numDet[1]) * ((myDetectorType == EIGER) ? 2 : 1) + + i; // col for horiz. udp ports + listener[i]->SetHardCodedPosition(row, col); + } } - /***acquisition functions***/ void slsReceiverImplementation::resetAcquisitionCount() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - for (const auto& it : listener) - it->ResetParametersforNewAcquisition(); - for (const auto& it : dataProcessor) - it->ResetParametersforNewAcquisition(); - for (const auto& it: dataStreamer) - it->ResetParametersforNewAcquisition(); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + for (const auto &it : listener) + it->ResetParametersforNewAcquisition(); + for (const auto &it : dataProcessor) + it->ResetParametersforNewAcquisition(); + for (const auto &it : dataStreamer) + it->ResetParametersforNewAcquisition(); - FILE_LOG(logINFO) << "Acquisition Count has been reset"; + FILE_LOG(logINFO) << "Acquisition Count has been reset"; } - - int slsReceiverImplementation::startReceiver(char *c) { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - FILE_LOG(logINFO) << "Starting Receiver"; - ResetParametersforNewMeasurement(); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logINFO) << "Starting Receiver"; + ResetParametersforNewMeasurement(); - //listener - if (CreateUDPSockets() == FAIL) { - strcpy(c,"Could not create UDP Socket(s)."); - FILE_LOG(logERROR) << c; - return FAIL; - } + // listener + if (CreateUDPSockets() == FAIL) { + strcpy(c, "Could not create UDP Socket(s)."); + FILE_LOG(logERROR) << c; + return FAIL; + } - //callbacks - if (startAcquisitionCallBack) { - startAcquisitionCallBack(filePath, fileName, fileIndex, - (generalData->imageSize) + (generalData->fifoBufferHeaderSize), pStartAcquisition); - if (rawDataReadyCallBack != nullptr) { - FILE_LOG(logINFO) << "Data Write has been defined externally"; - } - } + // callbacks + if (startAcquisitionCallBack) { + startAcquisitionCallBack(filePath, fileName, fileIndex, + (generalData->imageSize) + + (generalData->fifoBufferHeaderSize), + pStartAcquisition); + if (rawDataReadyCallBack != nullptr) { + FILE_LOG(logINFO) << "Data Write has been defined externally"; + } + } - //processor->writer - if (fileWriteEnable) { - if (SetupWriter() == FAIL) { - strcpy(c,"Could not create file.\n"); - FILE_LOG(logERROR) << c; - return FAIL; - } - } else - FILE_LOG(logINFO) << "File Write Disabled"; + // processor->writer + if (fileWriteEnable) { + if (SetupWriter() == FAIL) { + strcpy(c, "Could not create file.\n"); + FILE_LOG(logERROR) << c; + return FAIL; + } + } else + FILE_LOG(logINFO) << "File Write Disabled"; - FILE_LOG(logINFO) << "Ready ..."; + FILE_LOG(logINFO) << "Ready ..."; - //status - status = RUNNING; + // status + status = RUNNING; - //Let Threads continue to be ready for acquisition - StartRunning(); + // Let Threads continue to be ready for acquisition + StartRunning(); - FILE_LOG(logINFO) << "Receiver Started"; - FILE_LOG(logINFO) << "Status: " << runStatusType(status); - return OK; + FILE_LOG(logINFO) << "Receiver Started"; + FILE_LOG(logINFO) << "Status: " << runStatusType(status); + return OK; } - - void slsReceiverImplementation::stopReceiver() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - FILE_LOG(logINFO) << "Stopping Receiver"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logINFO) << "Stopping Receiver"; - //set status to transmitting - startReadout(); + // set status to transmitting + startReadout(); - //wait for the processes (Listener and DataProcessor) to be done - bool running = true; - while(running) { - running = false; - for (const auto& it : listener) - if (it->IsRunning()) - running = true; - - for (const auto& it : dataProcessor) - if (it->IsRunning()) - running = true; - usleep(5000); - } - - - //create virtual file - if (fileWriteEnable && fileFormatType == HDF5) { - uint64_t maxIndexCaught = 0; - bool anycaught = false; - for (const auto& it : dataProcessor) { - maxIndexCaught = std::max(maxIndexCaught, it->GetProcessedMeasurementIndex()); - if(it->GetMeasurementStartedFlag()) - anycaught = true; - } - //to create virtual file & set files/acquisition to 0 (only hdf5 at the moment) - dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught); - } - - //wait for the processes (DataStreamer) to be done - running = true; - while(running) { + // wait for the processes (Listener and DataProcessor) to be done + bool running = true; + while (running) { running = false; - for (const auto& it : dataStreamer) - if (it->IsRunning()) - running = true; + for (const auto &it : listener) + if (it->IsRunning()) + running = true; + + for (const auto &it : dataProcessor) + if (it->IsRunning()) + running = true; usleep(5000); } - status = RUN_FINISHED; - FILE_LOG(logINFO) << "Status: " << runStatusType(status); + // create virtual file + if (fileWriteEnable && fileFormatType == HDF5) { + uint64_t maxIndexCaught = 0; + bool anycaught = false; + for (const auto &it : dataProcessor) { + maxIndexCaught = + std::max(maxIndexCaught, it->GetProcessedMeasurementIndex()); + if (it->GetMeasurementStartedFlag()) + anycaught = true; + } + // to create virtual file & set files/acquisition to 0 (only hdf5 at the + // moment) + dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught); + } + // wait for the processes (DataStreamer) to be done + running = true; + while (running) { + running = false; + for (const auto &it : dataStreamer) + if (it->IsRunning()) + running = true; + usleep(5000); + } - { //statistics - uint64_t tot = 0; - for (int i = 0; i < numThreads; i++) { - tot += dataProcessor[i]->GetNumFramesCaught(); + status = RUN_FINISHED; + FILE_LOG(logINFO) << "Status: " << runStatusType(status); - int64_t missingpackets = numberOfFrames*generalData->packetsPerFrame-listener[i]->GetPacketsCaught(); - TLogLevel lev = (((int64_t)missingpackets) > 0) ? logINFORED : logINFOGREEN; - FILE_LOG(lev) << - // udp port number could be the second if selected interface is 2 for jungfrau - "Summary of Port " << udpPortNum[i] << - "\n\tMissing Packets\t\t: " << missingpackets << - "\n\tComplete Frames\t\t: " << dataProcessor[i]->GetNumFramesCaught() << - "\n\tLast Frame Caught\t: " << listener[i]->GetLastFrameIndexCaught(); - } - if(!activated) { - FILE_LOG(logINFORED) << "Deactivated Receiver"; - } - //callback - if (acquisitionFinishedCallBack) - acquisitionFinishedCallBack((tot/numThreads), pAcquisitionFinished); - } + { // statistics + uint64_t tot = 0; + for (int i = 0; i < numThreads; i++) { + tot += dataProcessor[i]->GetNumFramesCaught(); - //change status - status = IDLE; + int64_t missingpackets = + numberOfFrames * generalData->packetsPerFrame - + listener[i]->GetPacketsCaught(); + TLogLevel lev = + (((int64_t)missingpackets) > 0) ? logINFORED : logINFOGREEN; + FILE_LOG(lev) << + // udp port number could be the second if selected interface is + // 2 for jungfrau + "Summary of Port " << udpPortNum[i] + << "\n\tMissing Packets\t\t: " << missingpackets + << "\n\tComplete Frames\t\t: " + << dataProcessor[i]->GetNumFramesCaught() + << "\n\tLast Frame Caught\t: " + << listener[i]->GetLastFrameIndexCaught(); + } + if (!activated) { + FILE_LOG(logINFORED) << "Deactivated Receiver"; + } + // callback + if (acquisitionFinishedCallBack) + acquisitionFinishedCallBack((tot / numThreads), + pAcquisitionFinished); + } - FILE_LOG(logINFO) << "Receiver Stopped"; - FILE_LOG(logINFO) << "Status: " << runStatusType(status); + // change status + status = IDLE; + + FILE_LOG(logINFO) << "Receiver Stopped"; + FILE_LOG(logINFO) << "Status: " << runStatusType(status); } - - void slsReceiverImplementation::startReadout() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if(status == RUNNING) { - // wait for incoming delayed packets - int totalPacketsReceived = 0; - int previousValue=-1; - for(const auto& it : listener) - totalPacketsReceived += it->GetPacketsCaught(); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + if (status == RUNNING) { + // wait for incoming delayed packets + int totalPacketsReceived = 0; + int previousValue = -1; + for (const auto &it : listener) + totalPacketsReceived += it->GetPacketsCaught(); - //wait for all packets - const int numPacketsToReceive = numberOfFrames * generalData->packetsPerFrame * listener.size(); - if(totalPacketsReceived != numPacketsToReceive) { - while(totalPacketsReceived != previousValue) { - FILE_LOG(logDEBUG3) << "waiting for all packets, previousValue:" << previousValue << - " totalPacketsReceived: " << totalPacketsReceived; - usleep(5*1000);/* TODO! Need to find optimal time **/ - previousValue = totalPacketsReceived; - totalPacketsReceived = 0; - for(const auto& it : listener) - totalPacketsReceived += it->GetPacketsCaught(); + // wait for all packets + const int numPacketsToReceive = + numberOfFrames * generalData->packetsPerFrame * listener.size(); + if (totalPacketsReceived != numPacketsToReceive) { + while (totalPacketsReceived != previousValue) { + FILE_LOG(logDEBUG3) + << "waiting for all packets, previousValue:" + << previousValue + << " totalPacketsReceived: " << totalPacketsReceived; + usleep(5 * 1000); /* TODO! Need to find optimal time **/ + previousValue = totalPacketsReceived; + totalPacketsReceived = 0; + for (const auto &it : listener) + totalPacketsReceived += it->GetPacketsCaught(); - FILE_LOG(logDEBUG3) << "\tupdated: totalPacketsReceived:" << totalPacketsReceived; - } - } - status = TRANSMITTING; - FILE_LOG(logINFO) << "Status: Transmitting"; - } - //shut down udp sockets to make listeners push dummy (end) packets for processors - shutDownUDPSockets(); + FILE_LOG(logDEBUG3) << "\tupdated: totalPacketsReceived:" + << totalPacketsReceived; + } + } + status = TRANSMITTING; + FILE_LOG(logINFO) << "Status: Transmitting"; + } + // shut down udp sockets to make listeners push dummy (end) packets for + // processors + shutDownUDPSockets(); } - void slsReceiverImplementation::shutDownUDPSockets() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - for (const auto& it : listener) - it->ShutDownUDPSocket(); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + for (const auto &it : listener) + it->ShutDownUDPSocket(); } - - void slsReceiverImplementation::closeFiles() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - uint64_t maxIndexCaught = 0; - bool anycaught = false; - for (const auto& it : dataProcessor) { - it->CloseFiles(); - maxIndexCaught = std::max(maxIndexCaught, it->GetProcessedMeasurementIndex()); - if(it->GetMeasurementStartedFlag()) - anycaught = true; - } - //to create virtual file & set files/acquisition to 0 (only hdf5 at the moment) - dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught); + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + uint64_t maxIndexCaught = 0; + bool anycaught = false; + for (const auto &it : dataProcessor) { + it->CloseFiles(); + maxIndexCaught = + std::max(maxIndexCaught, it->GetProcessedMeasurementIndex()); + if (it->GetMeasurementStartedFlag()) + anycaught = true; + } + // to create virtual file & set files/acquisition to 0 (only hdf5 at the + // moment) + dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught); } - int slsReceiverImplementation::restreamStop() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - bool ret = OK; - for (const auto& it : dataStreamer) { - if (it->RestreamStop() == FAIL) - ret = FAIL; - } - // if fail, prints in datastreamer - if (ret == OK) { - FILE_LOG(logINFO) << "Restreaming Dummy Header via ZMQ successful"; - } + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + bool ret = OK; + for (const auto &it : dataStreamer) { + if (it->RestreamStop() == FAIL) + ret = FAIL; + } + // if fail, prints in datastreamer + if (ret == OK) { + FILE_LOG(logINFO) << "Restreaming Dummy Header via ZMQ successful"; + } - return ret; + return ret; } - - /***callback functions***/ -void slsReceiverImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg) { - startAcquisitionCallBack=func; - pStartAcquisition=arg; +void slsReceiverImplementation::registerCallBackStartAcquisition( + int (*func)(char *, char *, uint64_t, uint32_t, void *), void *arg) { + startAcquisitionCallBack = func; + pStartAcquisition = arg; } -void slsReceiverImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) { - acquisitionFinishedCallBack=func; - pAcquisitionFinished=arg; +void slsReceiverImplementation::registerCallBackAcquisitionFinished( + void (*func)(uint64_t, void *), void *arg) { + acquisitionFinishedCallBack = func; + pAcquisitionFinished = arg; } -void slsReceiverImplementation::registerCallBackRawDataReady(void (*func)(char* , - char*, uint32_t, void*),void *arg) { - rawDataReadyCallBack=func; - pRawDataReady=arg; - for (const auto& it : dataProcessor) - it->registerCallBackRawDataReady(rawDataReadyCallBack,pRawDataReady); +void slsReceiverImplementation::registerCallBackRawDataReady( + void (*func)(char *, char *, uint32_t, void *), void *arg) { + rawDataReadyCallBack = func; + pRawDataReady = arg; + for (const auto &it : dataProcessor) + it->registerCallBackRawDataReady(rawDataReadyCallBack, pRawDataReady); } -void slsReceiverImplementation::registerCallBackRawDataModifyReady(void (*func)(char* , - char*, uint32_t&, void*),void *arg) { - rawDataModifyReadyCallBack=func; - pRawDataReady=arg; - for (const auto& it : dataProcessor) - it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); +void slsReceiverImplementation::registerCallBackRawDataModifyReady( + void (*func)(char *, char *, uint32_t &, void *), void *arg) { + rawDataModifyReadyCallBack = func; + pRawDataReady = arg; + for (const auto &it : dataProcessor) + it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack, + pRawDataReady); } - void slsReceiverImplementation::SetLocalNetworkParameters() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - // to increase Max length of input packet queue - int max_back_log; - const char *proc_file_name = "/proc/sys/net/core/netdev_max_backlog"; - { - std::ifstream proc_file(proc_file_name); - proc_file >> max_back_log; - } + // to increase Max length of input packet queue + int max_back_log; + const char *proc_file_name = "/proc/sys/net/core/netdev_max_backlog"; + { + std::ifstream proc_file(proc_file_name); + proc_file >> max_back_log; + } - if (max_back_log < MAX_SOCKET_INPUT_PACKET_QUEUE) { - std::ofstream proc_file(proc_file_name); - if (proc_file.good()) { - proc_file << MAX_SOCKET_INPUT_PACKET_QUEUE << std::endl; - FILE_LOG(logINFOBLUE) << "Max length of input packet queue " - "[/proc/sys/net/core/netdev_max_backlog] modified to " << - MAX_SOCKET_INPUT_PACKET_QUEUE; - } else { - FILE_LOG(logWARNING) << "Could not change max length of " - "input packet queue [net.core.netdev_max_backlog]. (No Root Privileges?)"; - } - } + if (max_back_log < MAX_SOCKET_INPUT_PACKET_QUEUE) { + std::ofstream proc_file(proc_file_name); + if (proc_file.good()) { + proc_file << MAX_SOCKET_INPUT_PACKET_QUEUE << std::endl; + FILE_LOG(logINFOBLUE) + << "Max length of input packet queue " + "[/proc/sys/net/core/netdev_max_backlog] modified to " + << MAX_SOCKET_INPUT_PACKET_QUEUE; + } else { + FILE_LOG(logWARNING) + << "Could not change max length of " + "input packet queue [net.core.netdev_max_backlog]. (No Root " + "Privileges?)"; + } + } } - - void slsReceiverImplementation::SetThreadPriorities() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - for (const auto& it : listener) { - if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) { - FILE_LOG(logWARNING) << "Could not prioritize listener threads. (No Root Privileges?)"; - return; - } - } - std::ostringstream osfn; - osfn << "Priorities set - " - "Listener:" << LISTENER_PRIORITY; + for (const auto &it : listener) { + if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) { + FILE_LOG(logWARNING) << "Could not prioritize listener threads. " + "(No Root Privileges?)"; + return; + } + } + std::ostringstream osfn; + osfn << "Priorities set - " + "Listener:" + << LISTENER_PRIORITY; - FILE_LOG(logINFO) << osfn.str(); + FILE_LOG(logINFO) << osfn.str(); } - int slsReceiverImplementation::SetupFifoStructure() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - fifo.clear(); - for ( int i = 0; i < numThreads; ++i ) { + fifo.clear(); + for (int i = 0; i < numThreads; ++i) { - //create fifo structure - try { - fifo.push_back(sls::make_unique(i, - (generalData->imageSize) + (generalData->fifoBufferHeaderSize), - fifoDepth)); - } catch (...) { - FILE_LOG(logERROR) << "Could not allocate memory for fifo structure of index " << i; + // create fifo structure + try { + fifo.push_back(sls::make_unique( + i, + (generalData->imageSize) + (generalData->fifoBufferHeaderSize), + fifoDepth)); + } catch (...) { + FILE_LOG(logERROR) + << "Could not allocate memory for fifo structure of index " + << i; fifo.clear(); return FAIL; - } - //set the listener & dataprocessor threads to point to the right fifo - if(listener.size())listener[i]->SetFifo(fifo[i].get()); - if(dataProcessor.size())dataProcessor[i]->SetFifo(fifo[i].get()); - if(dataStreamer.size())dataStreamer[i]->SetFifo(fifo[i].get()); - } + } + // set the listener & dataprocessor threads to point to the right fifo + if (listener.size()) + listener[i]->SetFifo(fifo[i].get()); + if (dataProcessor.size()) + dataProcessor[i]->SetFifo(fifo[i].get()); + if (dataStreamer.size()) + dataStreamer[i]->SetFifo(fifo[i].get()); + } - FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " << ( ((generalData->imageSize) + (generalData->fifoBufferHeaderSize)) * fifoDepth) << " bytes" ; - FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed"; - return OK; + FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " + << (((generalData->imageSize) + + (generalData->fifoBufferHeaderSize)) * + fifoDepth) + << " bytes"; + FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed"; + return OK; } - - void slsReceiverImplementation::ResetParametersforNewMeasurement() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - for (const auto& it : listener) - it->ResetParametersforNewMeasurement(); - for (const auto& it : dataProcessor) - it->ResetParametersforNewMeasurement(); + for (const auto &it : listener) + it->ResetParametersforNewMeasurement(); + for (const auto &it : dataProcessor) + it->ResetParametersforNewMeasurement(); - if (dataStreamEnable) { - char fnametostream[MAX_STR_LENGTH*2]; - snprintf(fnametostream, MAX_STR_LENGTH*2, "%s/%s", filePath, fileName); - for (const auto& it : dataStreamer) - it->ResetParametersforNewMeasurement(fnametostream); - } + if (dataStreamEnable) { + char fnametostream[MAX_STR_LENGTH * 2]; + snprintf(fnametostream, MAX_STR_LENGTH * 2, "%s/%s", filePath, + fileName); + for (const auto &it : dataStreamer) + it->ResetParametersforNewMeasurement(fnametostream); + } } - - int slsReceiverImplementation::CreateUDPSockets() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - bool error = false; + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + bool error = false; - for (unsigned int i = 0; i < listener.size(); ++i) { - if (listener[i]->CreateUDPSockets() == FAIL) { - error = true; - break; - } - } + for (unsigned int i = 0; i < listener.size(); ++i) { + if (listener[i]->CreateUDPSockets() == FAIL) { + error = true; + break; + } + } + if (error) { + shutDownUDPSockets(); + return FAIL; + } - if (error) { - shutDownUDPSockets(); - return FAIL; - } - - FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; - return OK; + FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; + return OK; } - int slsReceiverImplementation::SetupWriter() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - bool error = false; - for (unsigned int i = 0; i < dataProcessor.size(); ++i) - if (dataProcessor[i]->CreateNewFile(tengigaEnable, - numberOfFrames, acquisitionTime, subExpTime, subPeriod, acquisitionPeriod) == FAIL) { - error = true; - break; - } - if (error) { - shutDownUDPSockets(); - closeFiles(); - return FAIL; - } + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + bool error = false; + for (unsigned int i = 0; i < dataProcessor.size(); ++i) + if (dataProcessor[i]->CreateNewFile( + tengigaEnable, numberOfFrames, acquisitionTime, subExpTime, + subPeriod, acquisitionPeriod) == FAIL) { + error = true; + break; + } + if (error) { + shutDownUDPSockets(); + closeFiles(); + return FAIL; + } - return OK; + return OK; } - void slsReceiverImplementation::StartRunning() { - FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - //set running mask and post semaphore to start the inner loop in execution thread - for (const auto& it : listener) { - it->StartRunning(); - it->Continue(); - } - for (const auto& it : dataProcessor) { - it->StartRunning(); - it->Continue(); - } - for (const auto& it : dataStreamer) { - it->StartRunning(); - it->Continue(); - } + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + // set running mask and post semaphore to start the inner loop in execution + // thread + for (const auto &it : listener) { + it->StartRunning(); + it->Continue(); + } + for (const auto &it : dataProcessor) { + it->StartRunning(); + it->Continue(); + } + for (const auto &it : dataStreamer) { + it->StartRunning(); + it->Continue(); + } } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index dafb49f7d..8bd59b27a 100755 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1,18 +1,19 @@ -/********************************************//** - * @file slsReceiverTCPIPInterface.cpp - * @short interface between receiver and client - ***********************************************/ - +/********************************************/ /** + * @file + *slsReceiverTCPIPInterface.cpp + * @short interface between + *receiver and client + ***********************************************/ +#include "slsReceiverTCPIPInterface.h" #include "FixedCapacityContainer.h" #include "ServerSocket.h" #include "slsReceiver.h" #include "slsReceiverImplementation.h" -#include "slsReceiverTCPIPInterface.h" #include "slsReceiverUsers.h" -#include "versionAPI.h" -#include "string_utils.h" #include "sls_detector_exceptions.h" +#include "string_utils.h" +#include "versionAPI.h" #include #include @@ -24,104 +25,97 @@ #include #include -using sls::SocketError; using sls::RuntimeError; +using sls::SocketError; using Interface = sls::ServerInterface2; -slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { - stop(); +slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { stop(); } + +slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int pn) + : myDetectorType(GOTTHARD), portNumber(pn > 0 ? pn : DEFAULT_PORTNO + 2) { + function_table(); } -slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int pn): - myDetectorType(GOTTHARD), - portNumber(pn > 0 ? pn : DEFAULT_PORTNO + 2) -{ - function_table(); +int slsReceiverTCPIPInterface::start() { + FILE_LOG(logDEBUG) << "Creating TCP Server Thread"; + killTCPServerThread = 0; + if (pthread_create(&TCPServer_thread, nullptr, startTCPServerThread, + (void *)this)) { + FILE_LOG(logERROR) << "Could not create TCP Server thread"; + return FAIL; + } + tcpThreadCreated = true; + FILE_LOG(logDEBUG) << "TCP Server thread created successfully."; + return OK; } - -int slsReceiverTCPIPInterface::start(){ - FILE_LOG(logDEBUG) << "Creating TCP Server Thread"; - killTCPServerThread = 0; - if(pthread_create(&TCPServer_thread, nullptr,startTCPServerThread, (void*) this)){ - FILE_LOG(logERROR) << "Could not create TCP Server thread"; - return FAIL; - } - tcpThreadCreated = true; - FILE_LOG(logDEBUG) << "TCP Server thread created successfully."; - return OK; +void slsReceiverTCPIPInterface::stop() { + if (tcpThreadCreated) { + FILE_LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber; + killTCPServerThread = 1; + if (server) + server->shutDownSocket(); + FILE_LOG(logDEBUG) << "TCP Socket closed on port " << portNumber; + pthread_join(TCPServer_thread, nullptr); + tcpThreadCreated = false; + killTCPServerThread = 0; + FILE_LOG(logDEBUG) << "Exiting TCP Server Thread on port " + << portNumber; + } } - -void slsReceiverTCPIPInterface::stop(){ - if (tcpThreadCreated) { - FILE_LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber; - killTCPServerThread = 1; - if(server) - server->shutDownSocket(); - FILE_LOG(logDEBUG) << "TCP Socket closed on port " << portNumber; - pthread_join(TCPServer_thread, nullptr); - tcpThreadCreated = false; - killTCPServerThread = 0; - FILE_LOG(logDEBUG) << "Exiting TCP Server Thread on port " << portNumber; - } -} - - - -int64_t slsReceiverTCPIPInterface::getReceiverVersion(){ - return APIRECEIVER; -} +int64_t slsReceiverTCPIPInterface::getReceiverVersion() { return APIRECEIVER; } /***callback functions***/ -void slsReceiverTCPIPInterface::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){ - startAcquisitionCallBack=func; - pStartAcquisition=arg; +void slsReceiverTCPIPInterface::registerCallBackStartAcquisition( + int (*func)(char *, char *, uint64_t, uint32_t, void *), void *arg) { + startAcquisitionCallBack = func; + pStartAcquisition = arg; } -void slsReceiverTCPIPInterface::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ - acquisitionFinishedCallBack=func; - pAcquisitionFinished=arg; +void slsReceiverTCPIPInterface::registerCallBackAcquisitionFinished( + void (*func)(uint64_t, void *), void *arg) { + acquisitionFinishedCallBack = func; + pAcquisitionFinished = arg; } -void slsReceiverTCPIPInterface::registerCallBackRawDataReady(void (*func)(char* , - char*, uint32_t, void*),void *arg){ - rawDataReadyCallBack=func; - pRawDataReady=arg; +void slsReceiverTCPIPInterface::registerCallBackRawDataReady( + void (*func)(char *, char *, uint32_t, void *), void *arg) { + rawDataReadyCallBack = func; + pRawDataReady = arg; } -void slsReceiverTCPIPInterface::registerCallBackRawDataModifyReady(void (*func)(char* , - char*, uint32_t &,void*),void *arg){ - rawDataModifyReadyCallBack=func; - pRawDataReady=arg; +void slsReceiverTCPIPInterface::registerCallBackRawDataModifyReady( + void (*func)(char *, char *, uint32_t &, void *), void *arg) { + rawDataModifyReadyCallBack = func; + pRawDataReady = arg; } -void* slsReceiverTCPIPInterface::startTCPServerThread(void *this_pointer){ - ((slsReceiverTCPIPInterface*)this_pointer)->startTCPServer(); - return this_pointer; +void *slsReceiverTCPIPInterface::startTCPServerThread(void *this_pointer) { + ((slsReceiverTCPIPInterface *)this_pointer)->startTCPServer(); + return this_pointer; } void slsReceiverTCPIPInterface::startTCPServer() { - FILE_LOG(logINFOBLUE) << "Created [ TCP server Tid: " - << syscall(SYS_gettid) << "]"; + FILE_LOG(logINFOBLUE) << "Created [ TCP server Tid: " << syscall(SYS_gettid) + << "]"; FILE_LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber << '\n'; server = sls::make_unique(portNumber); while (true) { - FILE_LOG(logDEBUG1) << "Start accept loop"; + FILE_LOG(logDEBUG1) << "Start accept loop"; try { auto socket = server->accept(); - try{ - VerifyLock(); - ret = decode_function(socket); - }catch(const RuntimeError& e){ - //We had an error needs to be sent to client - int r = FAIL; - strcpy(mess, e.what()); - socket.write(&r, sizeof(r)); - socket.write(mess, sizeof(mess)); - } - + try { + VerifyLock(); + ret = decode_function(socket); + } catch (const RuntimeError &e) { + // We had an error needs to be sent to client + int r = FAIL; + strcpy(mess, e.what()); + socket.write(&r, sizeof(r)); + socket.write(mess, sizeof(mess)); + } // if tcp command was to exit server if (ret == GOODBYE) { @@ -134,9 +128,9 @@ void slsReceiverTCPIPInterface::startTCPServer() { << "]"; pthread_exit(nullptr); } - }catch(const RuntimeError& e){ - std::cout << "Accept failed\n"; - } + } catch (const RuntimeError &e) { + std::cout << "Accept failed\n"; + } // if user entered exit if (killTCPServerThread) { @@ -151,7 +145,7 @@ void slsReceiverTCPIPInterface::startTCPServer() { } } } - +// clang-format off int slsReceiverTCPIPInterface::function_table(){ flist[F_EXEC_RECEIVER_COMMAND] = &slsReceiverTCPIPInterface::exec_command; flist[F_EXIT_RECEIVER] = &slsReceiverTCPIPInterface::exit_server; @@ -215,54 +209,57 @@ int slsReceiverTCPIPInterface::function_table(){ return OK; } - +// clang-format on int slsReceiverTCPIPInterface::decode_function(Interface &socket) { ret = FAIL; - socket.receiveArg(fnum); + socket.receiveArg(fnum); if (fnum <= NUM_DET_FUNCTIONS || fnum >= NUM_REC_FUNCTIONS) { - throw RuntimeError("Unrecognized Function enum " + - std::to_string(fnum) + "\n"); + throw RuntimeError("Unrecognized Function enum " + + std::to_string(fnum) + "\n"); } else { FILE_LOG(logDEBUG1) << "calling function fnum: " << fnum << " (" << getFunctionNameFromEnum((enum detFuncs)fnum) << ") located at " << flist[fnum]; ret = (this->*flist[fnum])(socket); - FILE_LOG(logDEBUG1) - << "Function " << getFunctionNameFromEnum((enum detFuncs)fnum) - << " finished"; + FILE_LOG(logDEBUG1) + << "Function " << getFunctionNameFromEnum((enum detFuncs)fnum) + << " finished"; } return ret; } void slsReceiverTCPIPInterface::functionNotImplemented() { - char message[MAX_STR_LENGTH]; - sprintf(message, "Function (%s) is not implemented for this detector\n", - getFunctionNameFromEnum((enum detFuncs)fnum)); - throw RuntimeError(mess); + char message[MAX_STR_LENGTH]; + sprintf(message, "Function (%s) is not implemented for this detector\n", + getFunctionNameFromEnum((enum detFuncs)fnum)); + throw RuntimeError(mess); } -void slsReceiverTCPIPInterface::modeNotImplemented(std::string modename, int mode) { - char message[MAX_STR_LENGTH]; - sprintf(message, "%s (%d) is not implemented for this detector\n", modename.c_str(), mode); - throw RuntimeError(message); +void slsReceiverTCPIPInterface::modeNotImplemented(std::string modename, + int mode) { + char message[MAX_STR_LENGTH]; + sprintf(message, "%s (%d) is not implemented for this detector\n", + modename.c_str(), mode); + throw RuntimeError(message); } template -void slsReceiverTCPIPInterface::validate(T arg, T retval, std::string modename, numberMode hex) { - if (ret == OK && arg != -1 && retval != arg) { - if (hex) - sprintf(mess, "Could not %s. Set 0x%x, but read 0x%x\n", - modename.c_str(), (unsigned int) arg, (unsigned int) retval); - else - sprintf(mess, "Could not %s. Set %d, but read %d\n", - modename.c_str(), (unsigned int) arg, (unsigned int) retval); - throw RuntimeError(mess); - } +void slsReceiverTCPIPInterface::validate(T arg, T retval, std::string modename, + numberMode hex) { + if (ret == OK && arg != -1 && retval != arg) { + if (hex) + sprintf(mess, "Could not %s. Set 0x%x, but read 0x%x\n", + modename.c_str(), (unsigned int)arg, (unsigned int)retval); + else + sprintf(mess, "Could not %s. Set %d, but read %d\n", + modename.c_str(), (unsigned int)arg, (unsigned int)retval); + throw RuntimeError(mess); + } } void slsReceiverTCPIPInterface::VerifyLock() { if (lockStatus && server->getThisClient() != server->getLockedBy()) { - throw sls::SocketError("Receiver locked\n"); + throw sls::SocketError("Receiver locked\n"); } } @@ -270,36 +267,36 @@ void slsReceiverTCPIPInterface::VerifyIdle(Interface &socket) { if (impl()->getStatus() != IDLE) { sprintf(mess, "Can not execute %s when receiver is not idle\n", getFunctionNameFromEnum((enum detFuncs)fnum)); - throw sls::SocketError(mess); + throw sls::SocketError(mess); } } int slsReceiverTCPIPInterface::exec_command(Interface &socket) { - char cmd[MAX_STR_LENGTH]{}; - char retval[MAX_STR_LENGTH]{}; - socket.receiveArg(cmd); - FILE_LOG(logINFO) << "Executing command (" << cmd << ")"; - const size_t tempsize = 256; - std::array temp; - std::string sresult; - std::shared_ptr pipe(popen(cmd, "r"), pclose); - if (!pipe) { - throw RuntimeError("Executing Command failed\n"); - } else { - while (!feof(pipe.get())) { - if (fgets(temp.data(), tempsize, pipe.get()) != nullptr) - sresult += temp.data(); - } - strncpy(retval, sresult.c_str(), MAX_STR_LENGTH); - FILE_LOG(logINFO) << "Result of cmd (" << cmd << "):\n" << retval; - } - return socket.sendResult(retval); + char cmd[MAX_STR_LENGTH]{}; + char retval[MAX_STR_LENGTH]{}; + socket.receiveArg(cmd); + FILE_LOG(logINFO) << "Executing command (" << cmd << ")"; + const size_t tempsize = 256; + std::array temp; + std::string sresult; + std::shared_ptr pipe(popen(cmd, "r"), pclose); + if (!pipe) { + throw RuntimeError("Executing Command failed\n"); + } else { + while (!feof(pipe.get())) { + if (fgets(temp.data(), tempsize, pipe.get()) != nullptr) + sresult += temp.data(); + } + strncpy(retval, sresult.c_str(), MAX_STR_LENGTH); + FILE_LOG(logINFO) << "Result of cmd (" << cmd << "):\n" << retval; + } + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::exit_server(Interface &socket) { - FILE_LOG(logINFO) << "Closing server"; - socket.sendData(OK); - return GOODBYE; + FILE_LOG(logINFO) << "Closing server"; + socket.sendData(OK); + return GOODBYE; } int slsReceiverTCPIPInterface::lock_receiver(Interface &socket) { @@ -310,107 +307,106 @@ int slsReceiverTCPIPInterface::lock_receiver(Interface &socket) { lockStatus = lock; lock ? server->setLockedBy(server->getThisClient()) : server->setLockedBy(sls::IpAddr{}); - } else{ - throw RuntimeError("Receiver locked\n"); - } + } else { + throw RuntimeError("Receiver locked\n"); + } } return socket.sendResult(lockStatus); } int slsReceiverTCPIPInterface::get_last_client_ip(Interface &socket) { - ret = OK; - memset(mess, 0, sizeof(mess)); - char ip[INET_ADDRSTRLEN]{}; - sls::strcpy_safe(ip, server->getLastClient().str().c_str()); - return socket.sendResult(ret, &ip, sizeof(ip)); + ret = OK; + memset(mess, 0, sizeof(mess)); + char ip[INET_ADDRSTRLEN]{}; + sls::strcpy_safe(ip, server->getLastClient().str().c_str()); + return socket.sendResult(ret, &ip, sizeof(ip)); } - int slsReceiverTCPIPInterface::set_port(Interface &socket) { - auto p_number = socket.receive(); - if (p_number < 1024) - throw RuntimeError("Port Number: " + std::to_string(p_number)+ " is too low (<1024)"); - - FILE_LOG(logINFO) << "set port to " << p_number <(p_number); - new_server->setLockedBy(server->getLockedBy()); - new_server->setLastClient(server->getThisClient()); - server = std::move(new_server); - socket.sendResult(p_number); - return OK; + auto p_number = socket.receive(); + if (p_number < 1024) + throw RuntimeError("Port Number: " + std::to_string(p_number) + + " is too low (<1024)"); + + FILE_LOG(logINFO) << "set port to " << p_number << std::endl; + auto new_server = sls::make_unique(p_number); + new_server->setLockedBy(server->getLockedBy()); + new_server->setLastClient(server->getThisClient()); + server = std::move(new_server); + socket.sendResult(p_number); + return OK; } int slsReceiverTCPIPInterface::update_client(Interface &socket) { - if(receiver == nullptr) - throw sls::SocketError("Receiver not set up. Please use rx_hostname first.\n"); - socket.sendData(OK); - return send_update(socket); + if (receiver == nullptr) + throw sls::SocketError( + "Receiver not set up. Please use rx_hostname first.\n"); + socket.sendData(OK); + return send_update(socket); } - - int slsReceiverTCPIPInterface::send_update(Interface &socket) { - int n = 0; - int i32 = -1; - char cstring[MAX_STR_LENGTH]{}; + int n = 0; + int i32 = -1; + char cstring[MAX_STR_LENGTH]{}; - char ip[INET_ADDRSTRLEN]{}; - sls::strcpy_safe(ip, server->getLastClient().str().c_str()); - n += socket.sendData(ip,sizeof(ip)); + char ip[INET_ADDRSTRLEN]{}; + sls::strcpy_safe(ip, server->getLastClient().str().c_str()); + n += socket.sendData(ip, sizeof(ip)); - // filepath - strcpy(cstring, receiver->getFilePath().c_str()); + // filepath + strcpy(cstring, receiver->getFilePath().c_str()); n += socket.sendData(cstring, sizeof(cstring)); - // filename + // filename strcpy(cstring, receiver->getFileName().c_str()); n += socket.sendData(cstring, sizeof(cstring)); - // index - i32=receiver->getFileIndex(); - n += socket.sendData(&i32, sizeof(i32)); + // index + i32 = receiver->getFileIndex(); + n += socket.sendData(&i32, sizeof(i32)); - //file format - i32=(int)receiver->getFileFormat(); - n += socket.sendData(&i32, sizeof(i32)); + // file format + i32 = (int)receiver->getFileFormat(); + n += socket.sendData(&i32, sizeof(i32)); - //frames per file - i32=(int)receiver->getFramesPerFile(); - n += socket.sendData(&i32, sizeof(i32)); + // frames per file + i32 = (int)receiver->getFramesPerFile(); + n += socket.sendData(&i32, sizeof(i32)); - //frame discard policy - i32=(int)receiver->getFrameDiscardPolicy(); - n += socket.sendData(&i32, sizeof(i32)); + // frame discard policy + i32 = (int)receiver->getFrameDiscardPolicy(); + n += socket.sendData(&i32, sizeof(i32)); - //frame padding - i32=(int)receiver->getFramePaddingEnable(); - n += socket.sendData(&i32, sizeof(i32)); + // frame padding + i32 = (int)receiver->getFramePaddingEnable(); + n += socket.sendData(&i32, sizeof(i32)); - // file write enable - i32=(int)receiver->getFileWriteEnable(); - n += socket.sendData(&i32, sizeof(i32)); + // file write enable + i32 = (int)receiver->getFileWriteEnable(); + n += socket.sendData(&i32, sizeof(i32)); - // master file write enable - i32=(int)receiver->getMasterFileWriteEnable(); - n += socket.sendData(&i32, sizeof(i32)); + // master file write enable + i32 = (int)receiver->getMasterFileWriteEnable(); + n += socket.sendData(&i32, sizeof(i32)); - // file overwrite enable - i32=(int)receiver->getOverwriteEnable(); - n += socket.sendData(&i32, sizeof(i32)); + // file overwrite enable + i32 = (int)receiver->getOverwriteEnable(); + n += socket.sendData(&i32, sizeof(i32)); - // gap pixels - i32=(int)receiver->getGapPixelsEnable(); - n += socket.sendData(&i32, sizeof(i32)); + // gap pixels + i32 = (int)receiver->getGapPixelsEnable(); + n += socket.sendData(&i32, sizeof(i32)); - // streaming frequency - i32=(int)receiver->getStreamingFrequency(); - n += socket.sendData(&i32, sizeof(i32)); + // streaming frequency + i32 = (int)receiver->getStreamingFrequency(); + n += socket.sendData(&i32, sizeof(i32)); - // streaming port - i32=(int)receiver->getStreamingPort(); - n += socket.sendData(&i32, sizeof(i32)); + // streaming port + i32 = (int)receiver->getStreamingPort(); + n += socket.sendData(&i32, sizeof(i32)); - // streaming source ip + // streaming source ip strcpy(cstring, receiver->getStreamingSourceIP().c_str()); n += socket.sendData(cstring, sizeof(cstring)); @@ -418,893 +414,922 @@ int slsReceiverTCPIPInterface::send_update(Interface &socket) { strcpy(cstring, receiver->getAdditionalJsonHeader().c_str()); n += socket.sendData(cstring, sizeof(cstring)); - // data streaming enable - i32=(int)receiver->getDataStreamEnable(); - n += socket.sendData(&i32, sizeof(i32)); + // data streaming enable + i32 = (int)receiver->getDataStreamEnable(); + n += socket.sendData(&i32, sizeof(i32)); - // activate - i32=(int)receiver->getActivate(); - n += socket.sendData(&i32, sizeof(i32)); + // activate + i32 = (int)receiver->getActivate(); + n += socket.sendData(&i32, sizeof(i32)); - // deactivated padding enable - i32=(int)receiver->getDeactivatedPadding(); - n += socket.sendData(&i32, sizeof(i32)); + // deactivated padding enable + i32 = (int)receiver->getDeactivatedPadding(); + n += socket.sendData(&i32, sizeof(i32)); - // silent mode - i32=(int)receiver->getSilentMode(); - n += socket.sendData(&i32, sizeof(i32)); + // silent mode + i32 = (int)receiver->getSilentMode(); + n += socket.sendData(&i32, sizeof(i32)); - // dbit list - { - std::vector list = receiver->getDbitList(); - int retvalsize = list.size(); - int retval[retvalsize]; - std::copy(std::begin(list), std::end(list), retval); - socket.sendData(&retvalsize, sizeof(retvalsize)); - socket.sendData(retval, sizeof(retval)); - } + // dbit list + { + std::vector list = receiver->getDbitList(); + int retvalsize = list.size(); + int retval[retvalsize]; + std::copy(std::begin(list), std::end(list), retval); + socket.sendData(&retvalsize, sizeof(retvalsize)); + socket.sendData(retval, sizeof(retval)); + } - // dbit offset - i32=receiver->getDbitOffset(); - n += socket.sendData(&i32, sizeof(i32)); + // dbit offset + i32 = receiver->getDbitOffset(); + n += socket.sendData(&i32, sizeof(i32)); - return OK; + return OK; } -int slsReceiverTCPIPInterface::get_id(Interface &socket){ - return socket.sendResult(getReceiverVersion()); +int slsReceiverTCPIPInterface::get_id(Interface &socket) { + return socket.sendResult(getReceiverVersion()); } -int slsReceiverTCPIPInterface::set_detector_type(Interface &socket){ - auto arg = socket.receive(); - // set - if (arg >= 0) { - // if object exists, verify unlocked and idle, else only verify lock (connecting first time) - if (receiver != nullptr){ - VerifyIdle(socket); - } - switch(arg) { - case GOTTHARD: - case EIGER: - case CHIPTESTBOARD: - case MOENCH: - case JUNGFRAU: - break; - default: - throw RuntimeError("Unknown detector type: " + std::to_string(arg)); - break; - } - - if(receiver == nullptr){ - receiver = sls::make_unique(); - } - myDetectorType = arg; - if (impl()->setDetectorType(myDetectorType) == FAIL){ - throw RuntimeError("Could not set detector type"); - } +int slsReceiverTCPIPInterface::set_detector_type(Interface &socket) { + auto arg = socket.receive(); + // set + if (arg >= 0) { + // if object exists, verify unlocked and idle, else only verify lock + // (connecting first time) + if (receiver != nullptr) { + VerifyIdle(socket); + } + switch (arg) { + case GOTTHARD: + case EIGER: + case CHIPTESTBOARD: + case MOENCH: + case JUNGFRAU: + break; + default: + throw RuntimeError("Unknown detector type: " + std::to_string(arg)); + break; + } - // callbacks after (in setdetectortype, the object is reinitialized) - if(startAcquisitionCallBack) - impl()->registerCallBackStartAcquisition(startAcquisitionCallBack,pStartAcquisition); - if(acquisitionFinishedCallBack) - impl()->registerCallBackAcquisitionFinished(acquisitionFinishedCallBack,pAcquisitionFinished); - if(rawDataReadyCallBack) - impl()->registerCallBackRawDataReady(rawDataReadyCallBack,pRawDataReady); - if(rawDataModifyReadyCallBack) - impl()->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); - - } - return socket.sendResult(myDetectorType); + if (receiver == nullptr) { + receiver = sls::make_unique(); + } + myDetectorType = arg; + if (impl()->setDetectorType(myDetectorType) == FAIL) { + throw RuntimeError("Could not set detector type"); + } + + // callbacks after (in setdetectortype, the object is reinitialized) + if (startAcquisitionCallBack) + impl()->registerCallBackStartAcquisition(startAcquisitionCallBack, + pStartAcquisition); + if (acquisitionFinishedCallBack) + impl()->registerCallBackAcquisitionFinished( + acquisitionFinishedCallBack, pAcquisitionFinished); + if (rawDataReadyCallBack) + impl()->registerCallBackRawDataReady(rawDataReadyCallBack, + pRawDataReady); + if (rawDataModifyReadyCallBack) + impl()->registerCallBackRawDataModifyReady( + rawDataModifyReadyCallBack, pRawDataReady); + } + return socket.sendResult(myDetectorType); } int slsReceiverTCPIPInterface::set_detector_hostname(Interface &socket) { - char hostname[MAX_STR_LENGTH]{}; - char retval[MAX_STR_LENGTH]{}; - socket.receiveArg(hostname); + char hostname[MAX_STR_LENGTH]{}; + char retval[MAX_STR_LENGTH]{}; + socket.receiveArg(hostname); - if (strlen(hostname)) { - VerifyIdle(socket); - impl()->setDetectorHostname(hostname); - } - auto s = impl()->getDetectorHostname(); - strcpy(retval, s.c_str()); - if (s.empty()) { - throw RuntimeError("Hostname not set"); - } - return socket.sendResult(retval); + if (strlen(hostname)) { + VerifyIdle(socket); + impl()->setDetectorHostname(hostname); + } + auto s = impl()->getDetectorHostname(); + strcpy(retval, s.c_str()); + if (s.empty()) { + throw RuntimeError("Hostname not set"); + } + return socket.sendResult(retval); } - int slsReceiverTCPIPInterface::set_roi(Interface &socket) { - static_assert(sizeof(ROI) == 4*sizeof(int), "ROI not packed"); - auto narg = socket.receive(); - std::vector arg; - for (int iloop = 0; iloop < narg; ++iloop) { - ROI temp{}; - socket.receiveArg(temp); - arg.push_back(temp); - } - FILE_LOG(logDEBUG1) << "Set ROI narg: " << narg; - for (int iloop = 0; iloop < narg; ++iloop) { - FILE_LOG(logDEBUG1) << "(" << arg[iloop].xmin << ", " << - arg[iloop].xmax << ", " << arg[iloop].ymin << ", " << - arg[iloop].ymax << ")"; - } + static_assert(sizeof(ROI) == 4 * sizeof(int), "ROI not packed"); + auto narg = socket.receive(); + std::vector arg; + for (int iloop = 0; iloop < narg; ++iloop) { + ROI temp{}; + socket.receiveArg(temp); + arg.push_back(temp); + } + FILE_LOG(logDEBUG1) << "Set ROI narg: " << narg; + for (int iloop = 0; iloop < narg; ++iloop) { + FILE_LOG(logDEBUG1) + << "(" << arg[iloop].xmin << ", " << arg[iloop].xmax << ", " + << arg[iloop].ymin << ", " << arg[iloop].ymax << ")"; + } - if (myDetectorType == EIGER || myDetectorType == JUNGFRAU) - functionNotImplemented(); + if (myDetectorType == EIGER || myDetectorType == JUNGFRAU) + functionNotImplemented(); - VerifyIdle(socket); - if (impl()->setROI(arg) == FAIL) - throw RuntimeError("Could not set ROI"); - return socket.sendData(OK); + VerifyIdle(socket); + if (impl()->setROI(arg) == FAIL) + throw RuntimeError("Could not set ROI"); + return socket.sendData(OK); } -int slsReceiverTCPIPInterface::setup_udp(Interface &socket){ - ret = OK; - char args[5][MAX_STR_LENGTH]{}; - char retvals[2][MAX_STR_LENGTH]{}; - socket.receiveArg(args); - VerifyIdle(socket); +int slsReceiverTCPIPInterface::setup_udp(Interface &socket) { + ret = OK; + char args[5][MAX_STR_LENGTH]{}; + char retvals[2][MAX_STR_LENGTH]{}; + socket.receiveArg(args); + VerifyIdle(socket); - //setup interfaces count - int numInterfaces = atoi(args[0]) > 1 ? 2 : 1; - char* ip1 = args[1]; - char* ip2 = args[2]; - uint32_t port1 = atoi(args[3]); - uint32_t port2 = atoi(args[4]); + // setup interfaces count + int numInterfaces = atoi(args[0]) > 1 ? 2 : 1; + char *ip1 = args[1]; + char *ip2 = args[2]; + uint32_t port1 = atoi(args[3]); + uint32_t port2 = atoi(args[4]); - // 1st interface - impl()->setUDPPortNumber(port1); - if (myDetectorType == EIGER) { - impl()->setUDPPortNumber2(port2); - } - FILE_LOG(logINFO) << "Receiver UDP IP: " << ip1; - // get eth - std::string temp = sls::IpToInterfaceName(ip1); - if (temp == "none"){ - throw RuntimeError("Failed to get ethernet interface or IP"); - } else { - char eth[MAX_STR_LENGTH]{}; - strcpy(eth, temp.c_str()); - // if there is a dot in eth name - if (strchr(eth, '.') != nullptr) { - strcpy(eth, ""); - sprintf(mess, "Failed to get ethernet interface from IP. Got %s\n", temp.c_str()); - FILE_LOG(logERROR) << mess; - } - impl()->setEthernetInterface(eth); - if (myDetectorType == EIGER) { - impl()->setEthernetInterface2(eth); - } - //get mac address - if (ret != FAIL) { - temp = sls::InterfaceNameToMac(eth).str(); - if (temp=="00:00:00:00:00:00") { - throw RuntimeError("failed to get mac adddress to listen to\n"); - } else { - strcpy(retvals[0],temp.c_str()); - FILE_LOG(logINFO) << "Receiver MAC Address: " << retvals[0]; - } - } - } + // 1st interface + impl()->setUDPPortNumber(port1); + if (myDetectorType == EIGER) { + impl()->setUDPPortNumber2(port2); + } + FILE_LOG(logINFO) << "Receiver UDP IP: " << ip1; + // get eth + std::string temp = sls::IpToInterfaceName(ip1); + if (temp == "none") { + throw RuntimeError("Failed to get ethernet interface or IP"); + } else { + char eth[MAX_STR_LENGTH]{}; + strcpy(eth, temp.c_str()); + // if there is a dot in eth name + if (strchr(eth, '.') != nullptr) { + strcpy(eth, ""); + sprintf(mess, "Failed to get ethernet interface from IP. Got %s\n", + temp.c_str()); + FILE_LOG(logERROR) << mess; + } + impl()->setEthernetInterface(eth); + if (myDetectorType == EIGER) { + impl()->setEthernetInterface2(eth); + } + // get mac address + if (ret != FAIL) { + temp = sls::InterfaceNameToMac(eth).str(); + if (temp == "00:00:00:00:00:00") { + throw RuntimeError("failed to get mac adddress to listen to\n"); + } else { + strcpy(retvals[0], temp.c_str()); + FILE_LOG(logINFO) << "Receiver MAC Address: " << retvals[0]; + } + } + } - // 2nd interface - if (myDetectorType == JUNGFRAU && numInterfaces == 2) { - impl()->setUDPPortNumber2(port2); - FILE_LOG(logINFO) << "Receiver UDP IP 2: " << ip2; - // get eth - temp = sls::IpToInterfaceName(ip2); - if (temp == "none"){ - throw RuntimeError("Failed to get 2nd ethernet interface or IP"); - } else { - char eth[MAX_STR_LENGTH] = {""}; - memset(eth, 0, MAX_STR_LENGTH); - strcpy(eth, temp.c_str()); - // if there is a dot in eth name - if (strchr(eth, '.') != nullptr) { - strcpy(eth, ""); - sprintf(mess, "Failed to get 2nd ethernet interface from IP. Got %s\n", temp.c_str()); - FILE_LOG(logERROR) << mess; - } - impl()->setEthernetInterface2(eth); + // 2nd interface + if (myDetectorType == JUNGFRAU && numInterfaces == 2) { + impl()->setUDPPortNumber2(port2); + FILE_LOG(logINFO) << "Receiver UDP IP 2: " << ip2; + // get eth + temp = sls::IpToInterfaceName(ip2); + if (temp == "none") { + throw RuntimeError("Failed to get 2nd ethernet interface or IP"); + } else { + char eth[MAX_STR_LENGTH] = {""}; + memset(eth, 0, MAX_STR_LENGTH); + strcpy(eth, temp.c_str()); + // if there is a dot in eth name + if (strchr(eth, '.') != nullptr) { + strcpy(eth, ""); + sprintf( + mess, + "Failed to get 2nd ethernet interface from IP. Got %s\n", + temp.c_str()); + FILE_LOG(logERROR) << mess; + } + impl()->setEthernetInterface2(eth); - //get mac address - if (ret != FAIL) { - temp = sls::InterfaceNameToMac(eth).str(); - if (temp=="00:00:00:00:00:00") { - throw RuntimeError("failed to get 2nd mac adddress to listen to"); - FILE_LOG(logERROR) << mess; - } else { - strcpy(retvals[1],temp.c_str()); - FILE_LOG(logINFO) << "Receiver MAC Address 2: " << retvals[1]; - } - } - } - } + // get mac address + if (ret != FAIL) { + temp = sls::InterfaceNameToMac(eth).str(); + if (temp == "00:00:00:00:00:00") { + throw RuntimeError( + "failed to get 2nd mac adddress to listen to"); + FILE_LOG(logERROR) << mess; + } else { + strcpy(retvals[1], temp.c_str()); + FILE_LOG(logINFO) + << "Receiver MAC Address 2: " << retvals[1]; + } + } + } + } - // set the number of udp interfaces (changes number of threads and many others) - if (myDetectorType == JUNGFRAU && impl()->setNumberofUDPInterfaces(numInterfaces) == FAIL) { - throw RuntimeError("Failed to set number of interfaces"); - } - return socket.sendResult(ret, retvals, sizeof(retvals), mess); + // set the number of udp interfaces (changes number of threads and many + // others) + if (myDetectorType == JUNGFRAU && + impl()->setNumberofUDPInterfaces(numInterfaces) == FAIL) { + throw RuntimeError("Failed to set number of interfaces"); + } + return socket.sendResult(ret, retvals, sizeof(retvals), mess); } int slsReceiverTCPIPInterface::set_timer(Interface &socket) { - memset(mess, 0, sizeof(mess)); - int64_t index[2] = {-1, -1}; - int64_t retval = -1; - socket.receiveArg(index); - if (index[1] >= 0) { - FILE_LOG(logDEBUG1) << "Setting timer index " << index[0] << " to " << index[1]; - switch (index[0]) { - case ACQUISITION_TIME: - ret = impl()->setAcquisitionTime(index[1]); - break; - case FRAME_PERIOD: - ret = impl()->setAcquisitionPeriod(index[1]); - break; - case FRAME_NUMBER: - case CYCLES_NUMBER: - case STORAGE_CELL_NUMBER: - impl()->setNumberOfFrames(index[1]); - break; - case SUBFRAME_ACQUISITION_TIME: - impl()->setSubExpTime(index[1]); - break; - case SUBFRAME_DEADTIME: - impl()->setSubPeriod(index[1] + impl()->getSubExpTime()); - break; - case ANALOG_SAMPLES: - if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { - modeNotImplemented("(Analog Samples) Timer index", (int)index[0]); - break; - } - impl()->setNumberofAnalogSamples(index[1]); - break; - case DIGITAL_SAMPLES: - if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { - modeNotImplemented("(Digital Samples) Timer index", (int)index[0]); - break; - } - impl()->setNumberofDigitalSamples(index[1]); - break; - default: - modeNotImplemented("Timer index", (int)index[0]); - break; - } - - } - // get - switch (index[0]) { - case ACQUISITION_TIME: - retval=impl()->getAcquisitionTime(); - break; - case FRAME_PERIOD: - retval=impl()->getAcquisitionPeriod(); - break; - case FRAME_NUMBER: - case CYCLES_NUMBER: - case STORAGE_CELL_NUMBER: - retval=impl()->getNumberOfFrames(); - break; - case SUBFRAME_ACQUISITION_TIME: - retval=impl()->getSubExpTime(); - break; - case SUBFRAME_DEADTIME: - retval=(impl()->getSubPeriod() - impl()->getSubExpTime()); - break; - case ANALOG_SAMPLES: - if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { - sprintf(mess,"This timer mode (%lld) does not exist for this receiver type\n", (long long int)index[0]); - throw RuntimeError(mess); - } - retval=impl()->getNumberofAnalogSamples(); - break; - case DIGITAL_SAMPLES: - if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { - sprintf(mess,"This timer mode (%lld) does not exist for this receiver type\n", (long long int)index[0]); - throw RuntimeError(mess); - } - retval=impl()->getNumberofDigitalSamples(); - break; - default: - modeNotImplemented("Timer index", (int)index[0]); - break; - } - validate((int)index[1], (int)retval, std::string("set timer"), DEC); - FILE_LOG(logDEBUG1) << slsDetectorDefs::getTimerType((timerIndex)(index[0])) << ":" << retval; - return socket.sendResult(retval); + memset(mess, 0, sizeof(mess)); + int64_t index[2] = {-1, -1}; + int64_t retval = -1; + socket.receiveArg(index); + if (index[1] >= 0) { + FILE_LOG(logDEBUG1) + << "Setting timer index " << index[0] << " to " << index[1]; + switch (index[0]) { + case ACQUISITION_TIME: + ret = impl()->setAcquisitionTime(index[1]); + break; + case FRAME_PERIOD: + ret = impl()->setAcquisitionPeriod(index[1]); + break; + case FRAME_NUMBER: + case CYCLES_NUMBER: + case STORAGE_CELL_NUMBER: + impl()->setNumberOfFrames(index[1]); + break; + case SUBFRAME_ACQUISITION_TIME: + impl()->setSubExpTime(index[1]); + break; + case SUBFRAME_DEADTIME: + impl()->setSubPeriod(index[1] + impl()->getSubExpTime()); + break; + case ANALOG_SAMPLES: + if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { + modeNotImplemented("(Analog Samples) Timer index", + (int)index[0]); + break; + } + impl()->setNumberofAnalogSamples(index[1]); + break; + case DIGITAL_SAMPLES: + if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { + modeNotImplemented("(Digital Samples) Timer index", + (int)index[0]); + break; + } + impl()->setNumberofDigitalSamples(index[1]); + break; + default: + modeNotImplemented("Timer index", (int)index[0]); + break; + } + } + // get + switch (index[0]) { + case ACQUISITION_TIME: + retval = impl()->getAcquisitionTime(); + break; + case FRAME_PERIOD: + retval = impl()->getAcquisitionPeriod(); + break; + case FRAME_NUMBER: + case CYCLES_NUMBER: + case STORAGE_CELL_NUMBER: + retval = impl()->getNumberOfFrames(); + break; + case SUBFRAME_ACQUISITION_TIME: + retval = impl()->getSubExpTime(); + break; + case SUBFRAME_DEADTIME: + retval = (impl()->getSubPeriod() - impl()->getSubExpTime()); + break; + case ANALOG_SAMPLES: + if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { + sprintf(mess, + "This timer mode (%lld) does not exist for this receiver " + "type\n", + (long long int)index[0]); + throw RuntimeError(mess); + } + retval = impl()->getNumberofAnalogSamples(); + break; + case DIGITAL_SAMPLES: + if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) { + sprintf(mess, + "This timer mode (%lld) does not exist for this receiver " + "type\n", + (long long int)index[0]); + throw RuntimeError(mess); + } + retval = impl()->getNumberofDigitalSamples(); + break; + default: + modeNotImplemented("Timer index", (int)index[0]); + break; + } + validate((int)index[1], (int)retval, std::string("set timer"), DEC); + FILE_LOG(logDEBUG1) << slsDetectorDefs::getTimerType((timerIndex)(index[0])) + << ":" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_dynamic_range(Interface &socket) { - auto dr = socket.receive(); - if (dr >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting dynamic range: " << dr; - bool exists = false; - switch (dr) { - case 16: - exists = true; - break; - case 4: - case 8: - case 32: - if (myDetectorType == EIGER) - exists = true; - break; - default: - break; - } - if (!exists) { - modeNotImplemented("Dynamic range", dr); - } - else { - ret = impl()->setDynamicRange(dr); - if(ret == FAIL) { - throw RuntimeError("Could not allocate memory for fifo or could not start listening/writing threads"); - } - } - - } - int retval = impl()->getDynamicRange(); - validate(dr, retval, std::string("set dynamic range"), DEC); - FILE_LOG(logDEBUG1) << "dynamic range: " << retval; - return socket.sendResult(retval); + auto dr = socket.receive(); + if (dr >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting dynamic range: " << dr; + bool exists = false; + switch (dr) { + case 16: + exists = true; + break; + case 4: + case 8: + case 32: + if (myDetectorType == EIGER) + exists = true; + break; + default: + break; + } + if (!exists) { + modeNotImplemented("Dynamic range", dr); + } else { + ret = impl()->setDynamicRange(dr); + if (ret == FAIL) { + throw RuntimeError("Could not allocate memory for fifo or " + "could not start listening/writing threads"); + } + } + } + int retval = impl()->getDynamicRange(); + validate(dr, retval, std::string("set dynamic range"), DEC); + FILE_LOG(logDEBUG1) << "dynamic range: " << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_streaming_frequency(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting streaming frequency: " << index; - ret = impl()->setStreamingFrequency(index); - if(ret == FAIL) { - throw RuntimeError("Could not allocate memory for listening fifo"); - } - } - int retval = impl()->getStreamingFrequency(); - validate(index, retval, std::string("set streaming frequency"), DEC); - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting streaming frequency: " << index; + ret = impl()->setStreamingFrequency(index); + if (ret == FAIL) { + throw RuntimeError("Could not allocate memory for listening fifo"); + } + } + int retval = impl()->getStreamingFrequency(); + validate(index, retval, std::string("set streaming frequency"), DEC); + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::get_status(Interface &socket){ - auto retval = impl()->getStatus(); - FILE_LOG(logDEBUG1) << "Status:" << runStatusType(retval); - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::get_status(Interface &socket) { + auto retval = impl()->getStatus(); + FILE_LOG(logDEBUG1) << "Status:" << runStatusType(retval); + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::start_receiver(Interface &socket){ - runStatus status = impl()->getStatus(); - if (status != IDLE) { - throw RuntimeError("Cannot start Receiver as it is: " +runStatusType(status)); - }else { - FILE_LOG(logDEBUG1) << "Starting Receiver"; - ret = impl()->startReceiver(mess); - if (ret == FAIL) { - throw RuntimeError(mess); - } - } - return socket.sendData(OK); +int slsReceiverTCPIPInterface::start_receiver(Interface &socket) { + runStatus status = impl()->getStatus(); + if (status != IDLE) { + throw RuntimeError("Cannot start Receiver as it is: " + + runStatusType(status)); + } else { + FILE_LOG(logDEBUG1) << "Starting Receiver"; + ret = impl()->startReceiver(mess); + if (ret == FAIL) { + throw RuntimeError(mess); + } + } + return socket.sendData(OK); } -int slsReceiverTCPIPInterface::stop_receiver(Interface &socket){ - if(impl()->getStatus() != IDLE) { - FILE_LOG(logDEBUG1) << "Stopping Receiver"; - impl()->stopReceiver(); - } - auto s = impl()->getStatus(); - if (s != IDLE) - throw RuntimeError("Could not stop receiver. It as it is: " + runStatusType(s)); +int slsReceiverTCPIPInterface::stop_receiver(Interface &socket) { + if (impl()->getStatus() != IDLE) { + FILE_LOG(logDEBUG1) << "Stopping Receiver"; + impl()->stopReceiver(); + } + auto s = impl()->getStatus(); + if (s != IDLE) + throw RuntimeError("Could not stop receiver. It as it is: " + + runStatusType(s)); - return socket.sendData(OK); + return socket.sendData(OK); } int slsReceiverTCPIPInterface::set_file_dir(Interface &socket) { - char fPath[MAX_STR_LENGTH]{}; + char fPath[MAX_STR_LENGTH]{}; char retval[MAX_STR_LENGTH]{}; - socket.receiveArg(fPath); + socket.receiveArg(fPath); + + if (strlen(fPath)) { + FILE_LOG(logDEBUG1) << "Setting file path: " << fPath; + impl()->setFilePath(fPath); + } + std::string s = impl()->getFilePath(); + strcpy(retval, s.c_str()); + if ((!s.length()) || (strlen(fPath) && strcasecmp(fPath, retval))) + throw RuntimeError("Receiver file path does not exist"); + else + FILE_LOG(logDEBUG1) << "file path:" << retval; - if (strlen(fPath)) { - FILE_LOG(logDEBUG1) << "Setting file path: " << fPath; - impl()->setFilePath(fPath); - } - std::string s = impl()->getFilePath(); - strcpy(retval, s.c_str()); - if ((!s.length()) || (strlen(fPath) && strcasecmp(fPath, retval))) - throw RuntimeError("Receiver file path does not exist"); - else - FILE_LOG(logDEBUG1) << "file path:" << retval; - return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_file_name(Interface &socket) { - char fName[MAX_STR_LENGTH]{}; + char fName[MAX_STR_LENGTH]{}; char retval[MAX_STR_LENGTH]{}; - socket.receiveArg(fName); - if (strlen(fName)) { - FILE_LOG(logDEBUG1) << "Setting file name: " << fName; - impl()->setFileName(fName); - } - std::string s = impl()->getFileName(); - if (s.empty()) - throw RuntimeError("file name is empty"); + socket.receiveArg(fName); + if (strlen(fName)) { + FILE_LOG(logDEBUG1) << "Setting file name: " << fName; + impl()->setFileName(fName); + } + std::string s = impl()->getFileName(); + if (s.empty()) + throw RuntimeError("file name is empty"); - strcpy(retval, s.c_str()); - FILE_LOG(logDEBUG1) << "file name:" << retval; - return socket.sendResult(retval); + strcpy(retval, s.c_str()); + FILE_LOG(logDEBUG1) << "file name:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_file_index(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting file index: " << index; - impl()->setFileIndex(index); - } - int retval = impl()->getFileIndex(); - validate(index, retval, std::string("set file index"), DEC); - FILE_LOG(logDEBUG1) << "file index:" << retval; - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting file index: " << index; + impl()->setFileIndex(index); + } + int retval = impl()->getFileIndex(); + validate(index, retval, std::string("set file index"), DEC); + FILE_LOG(logDEBUG1) << "file index:" << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::get_frame_index(Interface &socket){ - uint64_t retval = impl()->getAcquisitionIndex(); - FILE_LOG(logDEBUG1) << "frame index:" << retval; - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::get_frame_index(Interface &socket) { + uint64_t retval = impl()->getAcquisitionIndex(); + FILE_LOG(logDEBUG1) << "frame index:" << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::get_frames_caught(Interface &socket){ - int retval = impl()->getTotalFramesCaught(); - FILE_LOG(logDEBUG1) << "frames caught:" << retval; - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::get_frames_caught(Interface &socket) { + int retval = impl()->getTotalFramesCaught(); + FILE_LOG(logDEBUG1) << "frames caught:" << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::reset_frames_caught(Interface &socket){ - FILE_LOG(logDEBUG1) << "Reset frames caught"; - impl()->resetAcquisitionCount(); - return socket.sendData(OK); +int slsReceiverTCPIPInterface::reset_frames_caught(Interface &socket) { + FILE_LOG(logDEBUG1) << "Reset frames caught"; + impl()->resetAcquisitionCount(); + return socket.sendData(OK); } -int slsReceiverTCPIPInterface::enable_file_write(Interface &socket){ - auto enable = socket.receive(); - if (enable >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting File write enable:" << enable; - impl()->setFileWriteEnable(enable); - } - int retval = impl()->getFileWriteEnable(); - validate(enable, retval, std::string("set file write enable"), DEC); - FILE_LOG(logDEBUG1) << "file write enable:" << retval; - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::enable_file_write(Interface &socket) { + auto enable = socket.receive(); + if (enable >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting File write enable:" << enable; + impl()->setFileWriteEnable(enable); + } + int retval = impl()->getFileWriteEnable(); + validate(enable, retval, std::string("set file write enable"), DEC); + FILE_LOG(logDEBUG1) << "file write enable:" << retval; + return socket.sendResult(retval); } - -int slsReceiverTCPIPInterface::enable_master_file_write(Interface &socket){ - auto enable = socket.receive(); - if (enable >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting Master File write enable:" << enable; - impl()->setMasterFileWriteEnable(enable); - } - int retval = impl()->getMasterFileWriteEnable(); - validate(enable, retval, std::string("set master file write enable"), DEC); - FILE_LOG(logDEBUG1) << "master file write enable:" << retval; - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::enable_master_file_write(Interface &socket) { + auto enable = socket.receive(); + if (enable >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting Master File write enable:" << enable; + impl()->setMasterFileWriteEnable(enable); + } + int retval = impl()->getMasterFileWriteEnable(); + validate(enable, retval, std::string("set master file write enable"), DEC); + FILE_LOG(logDEBUG1) << "master file write enable:" << retval; + return socket.sendResult(retval); } - int slsReceiverTCPIPInterface::enable_overwrite(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting File overwrite enable:" << index; - impl()->setOverwriteEnable(index); - } - int retval = impl()->getOverwriteEnable(); - validate(index, retval, std::string("set file overwrite enable"), DEC); - FILE_LOG(logDEBUG1) << "file overwrite enable:" << retval; - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting File overwrite enable:" << index; + impl()->setOverwriteEnable(index); + } + int retval = impl()->getOverwriteEnable(); + validate(index, retval, std::string("set file overwrite enable"), DEC); + FILE_LOG(logDEBUG1) << "file overwrite enable:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::enable_tengiga(Interface &socket) { - auto val = socket.receive(); - if (myDetectorType != EIGER && myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) - functionNotImplemented(); + auto val = socket.receive(); + if (myDetectorType != EIGER && myDetectorType != CHIPTESTBOARD && + myDetectorType != MOENCH) + functionNotImplemented(); - if (val >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting 10GbE:" << val; - ret = impl()->setTenGigaEnable(val); - - } - int retval = impl()->getTenGigaEnable(); - validate(val, retval, std::string("set 10GbE"), DEC); - FILE_LOG(logDEBUG1) << "10Gbe:" << retval; - return socket.sendResult(retval); + if (val >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting 10GbE:" << val; + ret = impl()->setTenGigaEnable(val); + } + int retval = impl()->getTenGigaEnable(); + validate(val, retval, std::string("set 10GbE"), DEC); + FILE_LOG(logDEBUG1) << "10Gbe:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_fifo_depth(Interface &socket) { - auto value = socket.receive(); - if (value >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting fifo depth:" << value; - impl()->setFifoDepth(value); - } - int retval = impl()->getFifoDepth(); - validate(value, retval, std::string("set fifo depth"), DEC); - FILE_LOG(logDEBUG1) << "fifo depth:" << retval; - return socket.sendResult(retval); + auto value = socket.receive(); + if (value >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting fifo depth:" << value; + impl()->setFifoDepth(value); + } + int retval = impl()->getFifoDepth(); + validate(value, retval, std::string("set fifo depth"), DEC); + FILE_LOG(logDEBUG1) << "fifo depth:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_activate(Interface &socket) { - auto enable = socket.receive(); - if (myDetectorType != EIGER) - functionNotImplemented(); + auto enable = socket.receive(); + if (myDetectorType != EIGER) + functionNotImplemented(); - if (enable >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting activate:" << enable; - impl()->setActivate(enable > 0 ? true : false); - } - auto retval = static_cast(impl()->getActivate()); - validate(enable, retval, std::string("set activate"), DEC); - FILE_LOG(logDEBUG1) << "Activate: " << retval; - return socket.sendResult(retval); + if (enable >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting activate:" << enable; + impl()->setActivate(enable > 0 ? true : false); + } + auto retval = static_cast(impl()->getActivate()); + validate(enable, retval, std::string("set activate"), DEC); + FILE_LOG(logDEBUG1) << "Activate: " << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::set_data_stream_enable(Interface &socket){ - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting data stream enable:" << index; - ret = impl()->setDataStreamEnable(index); - } - int retval = impl()->getDataStreamEnable(); - validate(index, retval, std::string("set data stream enable"), DEC); - FILE_LOG(logDEBUG1) << "data streaming enable:" << retval; - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::set_data_stream_enable(Interface &socket) { + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting data stream enable:" << index; + ret = impl()->setDataStreamEnable(index); + } + int retval = impl()->getDataStreamEnable(); + validate(index, retval, std::string("set data stream enable"), DEC); + FILE_LOG(logDEBUG1) << "data streaming enable:" << retval; + return socket.sendResult(retval); } - - -int slsReceiverTCPIPInterface::set_streaming_timer(Interface &socket){ - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting streaming timer:" << index; - impl()->setStreamingTimer(index); - } - int retval=impl()->getStreamingTimer(); - validate(index, retval, std::string("set data stream timer"), DEC); - FILE_LOG(logDEBUG1) << "Streaming timer:" << retval; - return socket.sendResult(retval); +int slsReceiverTCPIPInterface::set_streaming_timer(Interface &socket) { + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting streaming timer:" << index; + impl()->setStreamingTimer(index); + } + int retval = impl()->getStreamingTimer(); + validate(index, retval, std::string("set data stream timer"), DEC); + FILE_LOG(logDEBUG1) << "Streaming timer:" << retval; + return socket.sendResult(retval); } +int slsReceiverTCPIPInterface::set_flipped_data(Interface &socket) { + // TODO! Why 2 args? + memset(mess, 0, sizeof(mess)); + int args[2]{0, -1}; + socket.receiveArg(args); + if (myDetectorType != EIGER) + functionNotImplemented(); -int slsReceiverTCPIPInterface::set_flipped_data(Interface &socket){ - //TODO! Why 2 args? - memset(mess, 0, sizeof(mess)); - int args[2]{0,-1}; - socket.receiveArg(args); - - if (myDetectorType != EIGER) - functionNotImplemented(); - - if (args[1] >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting flipped data:" << args[1]; - impl()->setFlippedData(args[0],args[1]); - } - int retval = impl()->getFlippedData(args[0]); - validate(args[1], retval, std::string("set flipped data"), DEC); - FILE_LOG(logDEBUG1) << "Flipped Data:" << retval; - return socket.sendResult(retval); + if (args[1] >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting flipped data:" << args[1]; + impl()->setFlippedData(args[0], args[1]); + } + int retval = impl()->getFlippedData(args[0]); + validate(args[1], retval, std::string("set flipped data"), DEC); + FILE_LOG(logDEBUG1) << "Flipped Data:" << retval; + return socket.sendResult(retval); } - - int slsReceiverTCPIPInterface::set_file_format(Interface &socket) { - fileFormat f = GET_FILE_FORMAT; - socket.receiveArg(f); - if (f >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting file format:" << f; - impl()->setFileFormat(f); - } - auto retval = impl()->getFileFormat(); - validate(f, retval, std::string("set file format"), DEC); - FILE_LOG(logDEBUG1) << "File Format: " << retval; - return socket.sendResult(retval); + fileFormat f = GET_FILE_FORMAT; + socket.receiveArg(f); + if (f >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting file format:" << f; + impl()->setFileFormat(f); + } + auto retval = impl()->getFileFormat(); + validate(f, retval, std::string("set file format"), DEC); + FILE_LOG(logDEBUG1) << "File Format: " << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_detector_posid(Interface &socket) { - auto arg = socket.receive(); - if (arg >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting detector position id:" << arg; - impl()->setDetectorPositionId(arg); - } - auto retval = impl()->getDetectorPositionId(); - validate(arg, retval, std::string("set detector position id"), DEC); - FILE_LOG(logDEBUG1) << "Position Id:" << retval; - return socket.sendResult(retval); + auto arg = socket.receive(); + if (arg >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting detector position id:" << arg; + impl()->setDetectorPositionId(arg); + } + auto retval = impl()->getDetectorPositionId(); + validate(arg, retval, std::string("set detector position id"), DEC); + FILE_LOG(logDEBUG1) << "Position Id:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_multi_detector_size(Interface &socket) { - int arg[]{-1, -1}; - socket.receiveArg(arg); - if((arg[0] > 0) && (arg[1] > 0)) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting multi detector size:" << arg[0] << "," << arg[1]; - impl()->setMultiDetectorSize(arg); - - } - int* temp = impl()->getMultiDetectorSize(); //TODO! return by value! - int retval = temp[0]*temp[1]; - FILE_LOG(logDEBUG1) << "Multi Detector Size:" << retval; - return socket.sendResult(retval); + int arg[]{-1, -1}; + socket.receiveArg(arg); + if ((arg[0] > 0) && (arg[1] > 0)) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) + << "Setting multi detector size:" << arg[0] << "," << arg[1]; + impl()->setMultiDetectorSize(arg); + } + int *temp = impl()->getMultiDetectorSize(); // TODO! return by value! + int retval = temp[0] * temp[1]; + FILE_LOG(logDEBUG1) << "Multi Detector Size:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_streaming_port(Interface &socket) { - auto port = socket.receive(); - if (port >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting streaming port:" << port; - impl()->setStreamingPort(port); - } - int retval = impl()->getStreamingPort(); - validate(port, retval, std::string("set streaming port"), DEC); - FILE_LOG(logDEBUG1) << "streaming port:" << retval; - return socket.sendResult(retval); + auto port = socket.receive(); + if (port >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting streaming port:" << port; + impl()->setStreamingPort(port); + } + int retval = impl()->getStreamingPort(); + validate(port, retval, std::string("set streaming port"), DEC); + FILE_LOG(logDEBUG1) << "streaming port:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_streaming_source_ip(Interface &socket) { - char arg[MAX_STR_LENGTH]{}; + char arg[MAX_STR_LENGTH]{}; char retval[MAX_STR_LENGTH]{}; - socket.receiveArg(arg); - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting streaming source ip:" << arg; - impl()->setStreamingSourceIP(arg); - strcpy(retval, impl()->getStreamingSourceIP().c_str()); - FILE_LOG(logDEBUG1) << "streaming source ip:" << retval; - return socket.sendResult(retval); + socket.receiveArg(arg); + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting streaming source ip:" << arg; + impl()->setStreamingSourceIP(arg); + strcpy(retval, impl()->getStreamingSourceIP().c_str()); + FILE_LOG(logDEBUG1) << "streaming source ip:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_silent_mode(Interface &socket) { - auto value = socket.receive(); - if (value >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting silent mode:" << value; - impl()->setSilentMode(value); - } - auto retval = static_cast(impl()->getSilentMode()); - validate(value, retval, std::string("set silent mode"), DEC); - FILE_LOG(logDEBUG1) << "silent mode:" << retval; - return socket.sendResult(retval); + auto value = socket.receive(); + if (value >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting silent mode:" << value; + impl()->setSilentMode(value); + } + auto retval = static_cast(impl()->getSilentMode()); + validate(value, retval, std::string("set silent mode"), DEC); + FILE_LOG(logDEBUG1) << "silent mode:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::enable_gap_pixels(Interface &socket) { - auto enable = socket.receive(); - if (myDetectorType != EIGER) - functionNotImplemented(); + auto enable = socket.receive(); + if (myDetectorType != EIGER) + functionNotImplemented(); - if (enable >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting gap pixels enable:" << enable; - impl()->setGapPixelsEnable(enable); - } - int retval = impl()->getGapPixelsEnable(); - validate(enable, retval, std::string("set gap pixels enable"), DEC); - FILE_LOG(logDEBUG1) << "Gap Pixels Enable: " << retval; - return socket.sendResult(retval); + if (enable >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting gap pixels enable:" << enable; + impl()->setGapPixelsEnable(enable); + } + int retval = impl()->getGapPixelsEnable(); + validate(enable, retval, std::string("set gap pixels enable"), DEC); + FILE_LOG(logDEBUG1) << "Gap Pixels Enable: " << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::restream_stop(Interface &socket){ - VerifyIdle(socket); - if (impl()->getDataStreamEnable() == false) { - throw RuntimeError("Could not restream stop packet as data Streaming is disabled"); - } else { - FILE_LOG(logDEBUG1) << "Restreaming stop"; - ret = impl()->restreamStop(); - if (ret == FAIL) - throw RuntimeError("Could not restream stop packet"); - } - return socket.sendData(OK); +int slsReceiverTCPIPInterface::restream_stop(Interface &socket) { + VerifyIdle(socket); + if (impl()->getDataStreamEnable() == false) { + throw RuntimeError( + "Could not restream stop packet as data Streaming is disabled"); + } else { + FILE_LOG(logDEBUG1) << "Restreaming stop"; + ret = impl()->restreamStop(); + if (ret == FAIL) + throw RuntimeError("Could not restream stop packet"); + } + return socket.sendData(OK); } int slsReceiverTCPIPInterface::set_additional_json_header(Interface &socket) { memset(mess, 0, sizeof(mess)); char arg[MAX_STR_LENGTH]{}; char retval[MAX_STR_LENGTH]{}; - socket.receiveArg(arg); - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting additional json header: " << arg; - impl()->setAdditionalJsonHeader(arg); - strcpy(retval, impl()->getAdditionalJsonHeader().c_str()); - FILE_LOG(logDEBUG1) << "additional json header:" << retval; - return socket.sendResult(retval); + socket.receiveArg(arg); + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting additional json header: " << arg; + impl()->setAdditionalJsonHeader(arg); + strcpy(retval, impl()->getAdditionalJsonHeader().c_str()); + FILE_LOG(logDEBUG1) << "additional json header:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::get_additional_json_header(Interface &socket) { char retval[MAX_STR_LENGTH]{}; - strcpy(retval, impl()->getAdditionalJsonHeader().c_str()); - FILE_LOG(logDEBUG1) << "additional json header:" << retval; - return socket.sendResult(retval); + strcpy(retval, impl()->getAdditionalJsonHeader().c_str()); + FILE_LOG(logDEBUG1) << "additional json header:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_udp_socket_buffer_size(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting UDP Socket Buffer size: " << index; - if (impl()->setUDPSocketBufferSize(index) == FAIL) { - throw RuntimeError("Could not create dummy UDP Socket to test buffer size"); - } - } - int64_t retval = impl()->getUDPSocketBufferSize(); - if (index != 0) - validate(index, retval, std::string("set udp socket buffer size (No CAP_NET_ADMIN privileges?)"), DEC); - FILE_LOG(logDEBUG1) << "UDP Socket Buffer Size:" << retval; - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting UDP Socket Buffer size: " << index; + if (impl()->setUDPSocketBufferSize(index) == FAIL) { + throw RuntimeError( + "Could not create dummy UDP Socket to test buffer size"); + } + } + int64_t retval = impl()->getUDPSocketBufferSize(); + if (index != 0) + validate( + index, retval, + std::string( + "set udp socket buffer size (No CAP_NET_ADMIN privileges?)"), + DEC); + FILE_LOG(logDEBUG1) << "UDP Socket Buffer Size:" << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size(Interface &socket){ - auto size = impl()->getActualUDPSocketBufferSize(); - FILE_LOG(logDEBUG1) << "Actual UDP socket size :" << size; - return socket.sendResult(size); +int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size( + Interface &socket) { + auto size = impl()->getActualUDPSocketBufferSize(); + FILE_LOG(logDEBUG1) << "Actual UDP socket size :" << size; + return socket.sendResult(size); } int slsReceiverTCPIPInterface::set_frames_per_file(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting frames per file: " << index; - impl()->setFramesPerFile(index); - } - auto retval = static_cast(impl()->getFramesPerFile()); - validate(index, retval, std::string("set frames per file"), DEC); - FILE_LOG(logDEBUG1) << "frames per file:" << retval; - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting frames per file: " << index; + impl()->setFramesPerFile(index); + } + auto retval = static_cast(impl()->getFramesPerFile()); + validate(index, retval, std::string("set frames per file"), DEC); + FILE_LOG(logDEBUG1) << "frames per file:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::check_version_compatibility(Interface &socket) { - auto arg = socket.receive(); - FILE_LOG(logDEBUG1) << "Checking versioning compatibility with value " << arg; - int64_t client_requiredVersion = arg; - int64_t rx_apiVersion = APIRECEIVER; - int64_t rx_version = getReceiverVersion(); + auto arg = socket.receive(); + FILE_LOG(logDEBUG1) << "Checking versioning compatibility with value " + << arg; + int64_t client_requiredVersion = arg; + int64_t rx_apiVersion = APIRECEIVER; + int64_t rx_version = getReceiverVersion(); - if (rx_apiVersion > client_requiredVersion) { - // old client - ret = FAIL; - sprintf(mess,"This client is incompatible.\n" - "Client's receiver API Version: (0x%llx). Receiver API Version: (0x%llx).\n" - "Incompatible, update client!\n", - (long long unsigned int)client_requiredVersion, - (long long unsigned int)rx_apiVersion); - throw RuntimeError(mess); - }else if (client_requiredVersion > rx_version) { - // old software - ret = FAIL; - sprintf(mess,"This receiver is incompatible.\n" - "Receiver Version: (0x%llx). Client's receiver API Version: (0x%llx).\n" - "Incompatible, update receiver!\n", - (long long unsigned int)rx_version, - (long long unsigned int)client_requiredVersion); - throw RuntimeError(mess); - } - else{ - FILE_LOG(logINFO) << "Compatibility with Client: Successful"; - } - return socket.sendData(OK); + if (rx_apiVersion > client_requiredVersion) { + // old client + ret = FAIL; + sprintf(mess, + "This client is incompatible.\n" + "Client's receiver API Version: (0x%llx). Receiver API " + "Version: (0x%llx).\n" + "Incompatible, update client!\n", + (long long unsigned int)client_requiredVersion, + (long long unsigned int)rx_apiVersion); + throw RuntimeError(mess); + } else if (client_requiredVersion > rx_version) { + // old software + ret = FAIL; + sprintf(mess, + "This receiver is incompatible.\n" + "Receiver Version: (0x%llx). Client's receiver API Version: " + "(0x%llx).\n" + "Incompatible, update receiver!\n", + (long long unsigned int)rx_version, + (long long unsigned int)client_requiredVersion); + throw RuntimeError(mess); + } else { + FILE_LOG(logINFO) << "Compatibility with Client: Successful"; + } + return socket.sendData(OK); } int slsReceiverTCPIPInterface::set_discard_policy(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting frames discard policy: " << index; - impl()->setFrameDiscardPolicy((frameDiscardPolicy)index); - } - int retval = impl()->getFrameDiscardPolicy(); - validate(index, retval, std::string("set discard policy"), DEC); - FILE_LOG(logDEBUG1) << "frame discard policy:" << retval; - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting frames discard policy: " << index; + impl()->setFrameDiscardPolicy((frameDiscardPolicy)index); + } + int retval = impl()->getFrameDiscardPolicy(); + validate(index, retval, std::string("set discard policy"), DEC); + FILE_LOG(logDEBUG1) << "frame discard policy:" << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_padding_enable(Interface &socket) { - auto index = socket.receive(); - if (index >= 0) { - VerifyIdle(socket); - index = (index == 0) ? 0 : 1; - FILE_LOG(logDEBUG1) << "Setting frames padding enable: " << index; - impl()->setFramePaddingEnable(index); - } - auto retval = static_cast(impl()->getFramePaddingEnable()); - validate(index, retval, std::string("set frame padding enable"), DEC); - FILE_LOG(logDEBUG1) << "Frame Padding Enable:" << retval; - return socket.sendResult(retval); + auto index = socket.receive(); + if (index >= 0) { + VerifyIdle(socket); + index = (index == 0) ? 0 : 1; + FILE_LOG(logDEBUG1) << "Setting frames padding enable: " << index; + impl()->setFramePaddingEnable(index); + } + auto retval = static_cast(impl()->getFramePaddingEnable()); + validate(index, retval, std::string("set frame padding enable"), DEC); + FILE_LOG(logDEBUG1) << "Frame Padding Enable:" << retval; + return socket.sendResult(retval); } -int slsReceiverTCPIPInterface::set_deactivated_padding_enable(Interface &socket) { - auto enable = socket.receive(); - if (myDetectorType != EIGER) - functionNotImplemented(); +int slsReceiverTCPIPInterface::set_deactivated_padding_enable( + Interface &socket) { + auto enable = socket.receive(); + if (myDetectorType != EIGER) + functionNotImplemented(); - if (enable >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting deactivated padding enable: " << enable; - impl()->setDeactivatedPadding(enable > 0 ? true : false); - } - auto retval = static_cast(impl()->getDeactivatedPadding()); - validate(enable, retval, std::string("set deactivated padding enable"), DEC); - FILE_LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval; - return socket.sendResult(retval); + if (enable >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting deactivated padding enable: " << enable; + impl()->setDeactivatedPadding(enable > 0 ? true : false); + } + auto retval = static_cast(impl()->getDeactivatedPadding()); + validate(enable, retval, std::string("set deactivated padding enable"), + DEC); + FILE_LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_readout_flags(Interface &socket) { - auto arg = socket.receive(); + auto arg = socket.receive(); - if (myDetectorType == JUNGFRAU || myDetectorType == GOTTHARD || myDetectorType == MOENCH) - functionNotImplemented(); + if (myDetectorType == JUNGFRAU || myDetectorType == GOTTHARD || + myDetectorType == MOENCH) + functionNotImplemented(); - if (arg >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting readout flag: " << arg; - ret = impl()->setReadOutFlags(arg); - } - auto retval = impl()->getReadOutFlags(); - validate((int)arg, (int)(retval & arg), std::string("set readout flags"), HEX); - FILE_LOG(logDEBUG1) << "Readout flags: " << retval; - return socket.sendResult(retval); + if (arg >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting readout flag: " << arg; + ret = impl()->setReadOutFlags(arg); + } + auto retval = impl()->getReadOutFlags(); + validate((int)arg, (int)(retval & arg), std::string("set readout flags"), + HEX); + FILE_LOG(logDEBUG1) << "Readout flags: " << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_adc_mask(Interface &socket) { - auto arg = socket.receive(); - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting ADC enable mask: " << arg; - impl()->setADCEnableMask(arg); - auto retval = impl()->getADCEnableMask(); - if (retval != arg) { - sprintf(mess, "Could not ADC enable mask. Set 0x%x, but read 0x%x\n", arg, retval); - throw RuntimeError(mess); - } - FILE_LOG(logDEBUG1) << "ADC enable mask retval: " << retval; - return socket.sendResult(retval); + auto arg = socket.receive(); + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting ADC enable mask: " << arg; + impl()->setADCEnableMask(arg); + auto retval = impl()->getADCEnableMask(); + if (retval != arg) { + sprintf(mess, "Could not ADC enable mask. Set 0x%x, but read 0x%x\n", + arg, retval); + throw RuntimeError(mess); + } + FILE_LOG(logDEBUG1) << "ADC enable mask retval: " << retval; + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_dbit_list(Interface &socket) { sls::FixedCapacityContainer args; socket.receiveArg(args); - FILE_LOG(logDEBUG1) << "Setting DBIT list"; - for (auto &it : args) { - FILE_LOG(logDEBUG1) << it << " "; - } - FILE_LOG(logDEBUG1) << "\n"; - VerifyIdle(socket); - impl()->setDbitList(args); + FILE_LOG(logDEBUG1) << "Setting DBIT list"; + for (auto &it : args) { + FILE_LOG(logDEBUG1) << it << " "; + } + FILE_LOG(logDEBUG1) << "\n"; + VerifyIdle(socket); + impl()->setDbitList(args); return socket.sendData(OK); } int slsReceiverTCPIPInterface::get_dbit_list(Interface &socket) { - sls::FixedCapacityContainer retval; - retval = impl()->getDbitList(); - FILE_LOG(logDEBUG1) << "Dbit list size retval:" << retval.size(); - return socket.sendResult(retval); + sls::FixedCapacityContainer retval; + retval = impl()->getDbitList(); + FILE_LOG(logDEBUG1) << "Dbit list size retval:" << retval.size(); + return socket.sendResult(retval); } int slsReceiverTCPIPInterface::set_dbit_offset(Interface &socket) { - auto arg = socket.receive(); - if (arg >= 0) { - VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting Dbit offset: " << arg; - impl()->setDbitOffset(arg); - } - int retval = impl()->getDbitOffset(); - validate(arg, retval, std::string("set dbit offset"), DEC); - FILE_LOG(logDEBUG1) << "Dbit offset retval: " << retval; - return socket.sendResult(retval); + auto arg = socket.receive(); + if (arg >= 0) { + VerifyIdle(socket); + FILE_LOG(logDEBUG1) << "Setting Dbit offset: " << arg; + impl()->setDbitOffset(arg); + } + int retval = impl()->getDbitOffset(); + validate(arg, retval, std::string("set dbit offset"), DEC); + FILE_LOG(logDEBUG1) << "Dbit offset retval: " << retval; + return socket.sendResult(retval); }