added const overloads for sendToDetector and sendToReceiver (#46)

This commit is contained in:
Erik Fröjdh
2019-08-06 16:58:22 +02:00
committed by Dhanya Thattil
parent d72b6c3659
commit e20b5e6952
3 changed files with 1064 additions and 943 deletions

View File

@ -1,14 +1,14 @@
#pragma once
#include "ClientSocket.h"
#include "FixedCapacityContainer.h"
#include "SharedMemory.h"
#include "logger.h"
#include "sls_detector_defs.h"
#include "network_utils.h"
#include "FixedCapacityContainer.h"
#include "sls_detector_defs.h"
#include <array>
#include <cmath>
#include <vector>
#include <array>
class ServerInterface;
@ -16,7 +16,8 @@ class ServerInterface;
#define SLS_SHMVERSION 0x190726
/**
* @short structure allocated in shared memory to store detector settings for IPC and cache
* @short structure allocated in shared memory to store detector settings for
* IPC and cache
*/
struct sharedSlsDetector {
@ -34,8 +35,8 @@ struct sharedSlsDetector {
/** END OF FIXED PATTERN -----------------------------------------------*/
/** Detector offset in the X & Y direction in the multi detector structure */
/** Detector offset in the X & Y direction in the multi detector structure
*/
int offset[2];
/** Number of detectors in multi list in x dir and y dir */
@ -114,13 +115,15 @@ struct sharedSlsDetector {
/** ip address of the receiver for the detector to send packets to**/
sls::IpAddr rxUDPIP;
/** ip address of the receiver for the 2nd interface of the detector to send packets to**/
/** ip address of the receiver for the 2nd interface of the detector to send
* packets to**/
sls::IpAddr rxUDPIP2;
/** mac address of receiver for the detector to send packets to **/
sls::MacAddr rxUDPMAC;
/** mac address of receiver for the 2nd interface of the detector to send packets to **/
/** mac address of receiver for the 2nd interface of the detector to send
* packets to **/
sls::MacAddr rxUDPMAC2;
/** mac address of the detector **/
@ -224,7 +227,6 @@ struct sharedSlsDetector {
/** reciever dbit offset */
int rxDbitOffset;
};
class slsDetector : public virtual slsDetectorDefs {
@ -234,22 +236,20 @@ class slsDetector : public virtual slsDetectorDefs{
* @param type detector type
* @param multi_id multi detector shared memory id
* @param id sls detector id (position in detectors list)
* @param verify true to verify if shared memory version matches existing one
* @param verify true to verify if shared memory version matches existing
* one
*/
explicit slsDetector(detectorType type,
int multi_id = 0,
int det_id = 0,
explicit slsDetector(detectorType type, int multi_id = 0, int det_id = 0,
bool verify = true);
/**
* Constructor called when opening existing shared memory
* @param multi_id multi detector shared memory id
* @param id sls detector id (position in detectors list)
* @param verify true to verify if shared memory version matches existing one
* @param verify true to verify if shared memory version matches existing
* one
*/
explicit slsDetector(int multi_id = 0,
int det_id = 0,
bool verify = true);
explicit slsDetector(int multi_id = 0, int det_id = 0, bool verify = true);
/**
* Destructor
@ -257,7 +257,8 @@ class slsDetector : public virtual slsDetectorDefs{
virtual ~slsDetector();
/**
* Returns false if it cannot get fixed pattern from an old version of shm (hostname, type), else true
* Returns false if it cannot get fixed pattern from an old version of shm
* (hostname, type), else true
*/
bool isFixedPatternSharedMemoryCompatible();
@ -281,71 +282,14 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Get Receiver Software version
*/
int64_t getReceiverSoftwareVersion();
/**
* Send function parameters to detector (control server)
* @param fnum function enum
* @param args argument pointer
* @param args_size size of argument
* @param retval return pointers
* @param retval_size size of return value
*/
void sendToDetector(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
template <typename Arg, typename Ret>
void sendToDetector(int fnum, const Arg &args, Ret &retval);
template<typename Arg>
void sendToDetector(int fnum, const Arg &args, std::nullptr_t);
template<typename Ret>
void sendToDetector(int fnum, std::nullptr_t, Ret & retval);
void sendToDetector(int fnum);
/**
* Send function parameters to detector (stop server)
* @param fnum function enum
* @param args argument pointer
* @param args_size size of argument
* @param retval return pointers
* @param retval_size size of return value
*/
void sendToDetectorStop(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
template <typename Arg, typename Ret>
void sendToDetectorStop(int fnum, const Arg &args, Ret &retval);
template<typename Arg>
void sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t);
template<typename Ret>
void sendToDetectorStop(int fnum, std::nullptr_t, Ret & retval);
void sendToDetectorStop(int fnum);
/**
* Send function parameters to receiver
* @param fnum function enum
* @param args argument pointer
* @param args_size size of argument
* @param retval return pointers
* @param retval_size size of return value
*/
void sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
template<typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg& args, Ret& retval);
template<typename Arg>
void sendToReceiver(int fnum, const Arg& args, std::nullptr_t);
template<typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret& retval);
void sendToReceiver(int fnum);
int64_t getReceiverSoftwareVersion() const;
/**
* Free shared memory and delete shared memory structure
* occupied by the sharedSlsDetector structure
* Is only safe to call if one deletes the slsDetector object afterward
* and frees multi shared memory/updates thisMultiDetector->numberOfDetectors
* and frees multi shared memory/updates
* thisMultiDetector->numberOfDetectors
*/
void freeSharedMemory();
@ -365,7 +309,8 @@ class slsDetector : public virtual slsDetectorDefs{
* Get detector type by connecting to the detector
* @returns detector tpe or GENERIC if failed
*/
static detectorType getTypeFromDetector(const std::string &hostname, int cport = DEFAULT_PORTNO);
static detectorType getTypeFromDetector(const std::string &hostname,
int cport = DEFAULT_PORTNO);
/**
* Get Detector type from shared memory variable
@ -406,8 +351,8 @@ class slsDetector : public virtual slsDetectorDefs{
int getTotalNumberOfChannels(dimension d) const;
/**
* Returns the total number of channels of in dimension d including gap pixels
* from shared memory
* Returns the total number of channels of in dimension d including gap
* pixels from shared memory
* @param d dimension d
* @returns the total number of channels including gap pixels in dimension d
* including gap pixels
@ -421,7 +366,8 @@ class slsDetector : public virtual slsDetectorDefs{
int getNChans() const;
/**
* returns the number of channels per chip in dimension d from shared memory (Mythen)
* returns the number of channels per chip in dimension d from shared memory
* (Mythen)
* @param d dimension d
* @returns number of channels per chip in dimension d
*/
@ -434,7 +380,8 @@ class slsDetector : public virtual slsDetectorDefs{
int getNChips() const;
/**
* returns the number of chips per module in dimension d from shared memory (Mythen)
* returns the number of chips per module in dimension d from shared memory
* (Mythen)
* @param d dimension d
* @returns number of chips per module in dimension d
*/
@ -547,18 +494,18 @@ class slsDetector : public virtual slsDetectorDefs{
detectorSettings getSettings();
/**
* Load detector settings from the settings file picked from the trimdir/settingsdir
* Eiger only stores in shared memory ( a get will overwrite this)
* For Eiger, one must use threshold
* Gotthard, Propix, Jungfrau and Moench only sends the settings enum to the detector
* Load detector settings from the settings file picked from the
* trimdir/settingsdir Eiger only stores in shared memory ( a get will
* overwrite this) For Eiger, one must use threshold Gotthard, Propix,
* Jungfrau and Moench only sends the settings enum to the detector
* @param isettings settings
* @returns current settings
*/
detectorSettings setSettings(detectorSettings isettings);
/**
* Send detector settings only (set only for Jungfrau, Gotthard, Moench, get for all)
* Only the settings enum is sent to the detector, where it will
* Send detector settings only (set only for Jungfrau, Gotthard, Moench, get
* for all) Only the settings enum is sent to the detector, where it will
* initialize al the dacs already hard coded in the detector server
* @param isettings settings
* @returns current settings
@ -579,7 +526,8 @@ class slsDetector : public virtual slsDetectorDefs{
* @param tb 1 to include trimbits, 0 to exclude
* @returns current threshold value in ev (-1 failed)
*/
int setThresholdEnergy(int e_eV, detectorSettings isettings = GET_SETTINGS, int tb = 1);
int setThresholdEnergy(int e_eV, detectorSettings isettings = GET_SETTINGS,
int tb = 1);
/**
* Set threshold energy and settings (Eiger only)
@ -587,7 +535,8 @@ class slsDetector : public virtual slsDetectorDefs{
* @param isettings ev. change settings
* @param tb 1 to include trimbits, 0 to exclude
*/
void setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb = 1);
void setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings,
int tb = 1);
/**
* Returns the detector trimbit/settings directory \sa sharedSlsDetector
@ -620,7 +569,7 @@ class slsDetector : public virtual slsDetectorDefs{
* Get run status of the detector
* @returns the status of the detector
*/
runStatus getRunStatus();
runStatus getRunStatus() const;
/**
* Prepares detector for acquisition (Eiger)
@ -643,12 +592,14 @@ class slsDetector : public virtual slsDetectorDefs{
void sendSoftwareTrigger();
/**
* Start detector acquisition and read all data (Blocking until end of acquisition)
* Start detector acquisition and read all data (Blocking until end of
* acquisition)
*/
void startAndReadAll();
/**
* Start readout (without exposure or interrupting exposure) (Eiger store in ram)
* Start readout (without exposure or interrupting exposure) (Eiger store in
* ram)
*/
void startReadOut();
@ -678,31 +629,37 @@ class slsDetector : public virtual slsDetectorDefs{
* Set/get timer value (not all implemented for all detectors)
* @param index timer index
* @param t time in ns or number of...(e.g. frames, gates, probes)
* @returns timer set value in ns or number of...(e.g. frames, gates, probes)
* @returns timer set value in ns or number of...(e.g. frames, gates,
* probes)
*/
int64_t setTimer(timerIndex index, int64_t t = -1);
/**
* Set/get timer value left in acquisition (not all implemented for all detectors)
* Set/get timer value left in acquisition (not all implemented for all
* detectors)
* @param index timer index
* @param t time in ns or number of...(e.g. frames, gates, probes)
* @returns timer set value in ns or number of...(e.g. frames, gates, probes)
* @returns timer set value in ns or number of...(e.g. frames, gates,
* probes)
*/
int64_t getTimeLeft(timerIndex index);
int64_t getTimeLeft(timerIndex index) const;
/**
* Set speed
* @param sp speed type (clkdivider option for Jungfrau and Eiger,
* adcphase for Gotthard, others for CTB & Moench)
* @param value (clkdivider 0,1,2 for full, half and quarter speed). Other values check manual
* @param mode 0 for shift, 1 for degrees. relevant only for speed type adcphase and dbit phase
* @param value (clkdivider 0,1,2 for full, half and quarter speed). Other
* values check manual
* @param mode 0 for shift, 1 for degrees. relevant only for speed type
* adcphase and dbit phase
* @returns value of speed set
*/
int setSpeed(speedVariable sp, int value = -1, int mode = 0);
/**
* Set/get dynamic range and updates the number of dataBytes
* (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to 1)
* (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to
* 1)
* @param i dynamic range (-1 get)
* @returns current dynamic range
* \sa sharedSlsDetector
@ -733,7 +690,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Get adc value
* @param index adc(DAC) index
* @returns current adc value (temperature for eiger and jungfrau in millidegrees)
* @returns current adc value (temperature for eiger and jungfrau in
* millidegrees)
*/
int getADC(dacIndex index);
@ -742,18 +700,22 @@ class slsDetector : public virtual slsDetectorDefs{
* @param pol timing mode (-1 gets)
* @returns current timing mode
*/
externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol = GET_EXTERNAL_COMMUNICATION_MODE);
externalCommunicationMode setExternalCommunicationMode(
externalCommunicationMode pol = GET_EXTERNAL_COMMUNICATION_MODE);
/**
* Set/get external signal flags (to specify triggerinrising edge etc) (Gotthard, Mythen)
* Set/get external signal flags (to specify triggerinrising edge etc)
* (Gotthard, Mythen)
* @param pol external signal flag (-1 gets)
* @returns current timing mode
*/
externalSignalFlag setExternalSignalFlags(externalSignalFlag pol = GET_EXTERNAL_SIGNAL_FLAG);
externalSignalFlag
setExternalSignalFlags(externalSignalFlag pol = GET_EXTERNAL_SIGNAL_FLAG);
/**
* Set/get readout flags (Eiger, Mythen)
* @param flag readout flag (Eiger options: parallel, nonparallel, safe etc.) (-1 gets)
* @param flag readout flag (Eiger options: parallel, nonparallel, safe
* etc.) (-1 gets)
* @returns readout flag
*/
int setReadOutFlags(readOutFlags flag = GET_READOUT_FLAGS);
@ -802,7 +764,8 @@ class slsDetector : public virtual slsDetectorDefs{
uint32_t clearBit(uint32_t addr, int n);
/**
* Validates the format of the detector MAC address and sets it \sa sharedSlsDetector
* Validates the format of the detector MAC address and sets it \sa
* sharedSlsDetector
* @param detectorMAC detector MAC address
* @returns the detector MAC address
*/
@ -815,7 +778,8 @@ class slsDetector : public virtual slsDetectorDefs{
sls::MacAddr getDetectorMAC();
/**
* Validates the format of the detector MAC address (bottom half) and sets it (Jungfrau only)
* Validates the format of the detector MAC address (bottom half) and sets
* it (Jungfrau only)
* @param detectorMAC detector MAC address (bottom half)
* @returns the detector MAC address (bottom half)
*/
@ -828,7 +792,8 @@ class slsDetector : public virtual slsDetectorDefs{
sls::MacAddr getDetectorMAC2();
/**
* Validates the format of the detector IP address and sets it \sa sharedSlsDetector
* Validates the format of the detector IP address and sets it \sa
* sharedSlsDetector
* @param detectorIP detector IP address
* @returns the detector IP address
*/
@ -841,7 +806,8 @@ class slsDetector : public virtual slsDetectorDefs{
sls::IpAddr getDetectorIP() const;
/**
* Validates the format of the detector IP address (bottom half) and sets it (Jungfrau only)
* Validates the format of the detector IP address (bottom half) and sets it
* (Jungfrau only)
* @param detectorIP detector IP address (bottom half)
* @returns the detector IP address (bottom half)
*/
@ -855,8 +821,9 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Validates and sets the receiver.
* Also updates the receiver with all the shared memory parameters significant for the receiver
* Also configures the detector to the receiver as UDP destination
* Also updates the receiver with all the shared memory parameters
* significant for the receiver Also configures the detector to the receiver
* as UDP destination
* @param receiver receiver hostname or IP address
* @returns the receiver IP address from shared memory
*/
@ -869,7 +836,8 @@ class slsDetector : public virtual slsDetectorDefs{
std::string getReceiverHostname() const;
/**
* Validates the format of the receiver UDP IP address and sets it \sa sharedSlsDetector
* Validates the format of the receiver UDP IP address and sets it \sa
* sharedSlsDetector
* @param udpip receiver UDP IP address
* @returns the receiver UDP IP address
*/
@ -882,7 +850,8 @@ class slsDetector : public virtual slsDetectorDefs{
sls::IpAddr getReceiverUDPIP() const;
/**
* Validates the format of the receiver UDP IP address (bottom half) and sets it(Jungfrau only)
* Validates the format of the receiver UDP IP address (bottom half) and
* sets it(Jungfrau only)
* @param udpip receiver UDP IP address (bottom half)
* @returns the receiver UDP IP address (bottom half)
*/
@ -895,7 +864,8 @@ class slsDetector : public virtual slsDetectorDefs{
sls::IpAddr getReceiverUDPIP2() const;
/**
* Validates the format of the receiver UDP MAC address and sets it \sa sharedSlsDetector
* Validates the format of the receiver UDP MAC address and sets it \sa
* sharedSlsDetector
* @param udpmac receiver UDP MAC address
* @returns the receiver UDP MAC address
*/
@ -908,7 +878,8 @@ class slsDetector : public virtual slsDetectorDefs{
sls::MacAddr getReceiverUDPMAC() const;
/**
* Validates the format of the receiver UDP MAC address (bottom half) and sets it (Jungfrau only)
* Validates the format of the receiver UDP MAC address (bottom half) and
* sets it (Jungfrau only)
* @param udpmac receiver UDP MAC address (bottom half)
* @returns the receiver UDP MAC address (bottom half)
*/
@ -934,40 +905,46 @@ class slsDetector : public virtual slsDetectorDefs{
int getReceiverUDPPort() const;
/**
* Sets the receiver UDP port 2\sa sharedSlsDetector (Eiger and Jungfrau only)
* Sets the receiver UDP port 2\sa sharedSlsDetector (Eiger and Jungfrau
* only)
* @param udpport receiver UDP port 2
* @returns the receiver UDP port 2
*/
int setReceiverUDPPort2(int udpport);
/**
* Returns the receiver UDP port 2 of same interface\sa sharedSlsDetector (Eiger and Jungfrau only)
* Returns the receiver UDP port 2 of same interface\sa sharedSlsDetector
* (Eiger and Jungfrau only)
* @returns the receiver UDP port 2 of same interface
*/
int getReceiverUDPPort2() const;
/**
* Sets the number of UDP interfaces to stream data from detector (Jungfrau only)
* Sets the number of UDP interfaces to stream data from detector (Jungfrau
* only)
* @param n number of interfaces. Options 1 or 2.
* @returns the number of interfaces
*/
int setNumberofUDPInterfaces(int n);
/**
* Returns the number of UDP interfaces to stream data from detector (Jungfrau only)
* Returns the number of UDP interfaces to stream data from detector
* (Jungfrau only)
* @returns the number of interfaces
*/
int getNumberofUDPInterfaces() const;
/**
* Selects the UDP interfaces to stream data from detector. Effective only when number of interfaces is 1. (Jungfrau only)
* Selects the UDP interfaces to stream data from detector. Effective only
* when number of interfaces is 1. (Jungfrau only)
* @param n selected interface. Options 1 or 2.
* @returns the interface selected
*/
int selectUDPInterface(int n);
/**
* Returns the UDP interfaces to stream data from detector. Effective only when number of interfaces is 1. (Jungfrau only)
* Returns the UDP interfaces to stream data from detector. Effective only
* when number of interfaces is 1. (Jungfrau only)
* @returns the interface selected
*/
int getSelectedUDPInterface() const;
@ -1004,7 +981,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Returns the client zmq ip \sa sharedSlsDetector
* @returns the client zmq ip, returns "none" if default setting and no custom ip set
* @returns the client zmq ip, returns "none" if default setting and no
* custom ip set
*/
std::string getClientStreamingIP();
@ -1016,7 +994,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Returns the receiver zmq ip \sa sharedSlsDetector
* @returns the receiver zmq ip, returns "none" if default setting and no custom ip set
* @returns the receiver zmq ip, returns "none" if default setting and no
* custom ip set
*/
std::string getReceiverStreamingIP();
@ -1032,24 +1011,28 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Sets the additional json header\sa sharedSlsDetector
* @param jsonheader additional json header
* @returns additional json header, returns "none" if default setting and no custom ip set
* @returns additional json header, returns "none" if default setting and no
* custom ip set
*/
std::string setAdditionalJsonHeader(const std::string &jsonheader);
/**
* Returns the additional json header \sa sharedSlsDetector
* @returns the additional json header, returns "none" if default setting and no custom ip set
* @returns the additional json header, returns "none" if default setting
* and no custom ip set
*/
std::string getAdditionalJsonHeader();
/**
* Sets the value for the additional json header parameter if found, else append it
* Sets the value for the additional json header parameter if found, else
* append it
* @param key additional json header parameter
* @param value additional json header parameter value (cannot be empty)
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string setAdditionalJsonParameter(const std::string &key, const std::string &value);
std::string setAdditionalJsonParameter(const std::string &key,
const std::string &value);
/**
* Returns the additional json header parameter value
@ -1076,7 +1059,7 @@ class slsDetector : public virtual slsDetectorDefs{
* Returns the receiver real UDP socket buffer size\sa sharedSlsDetector
* @returns the receiver real UDP socket buffer size
*/
int64_t getReceiverRealUDPSocketBufferSize();
int64_t getReceiverRealUDPSocketBufferSize() const;
/**
* Execute a digital test (Gotthard, Mythen)
@ -1122,7 +1105,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Set/get counter bit in detector (Gotthard)
* @param i is -1 to get, 0 to reset and any other value to set the counter bit
* @param i is -1 to get, 0 to reset and any other value to set the counter
* bit
* @returns the counter bit in detector
*/
int setCounterBit(int cb = -1);
@ -1136,7 +1120,8 @@ class slsDetector : public virtual slsDetectorDefs{
void setROI(int n = -1, ROI roiLimits[] = nullptr);
/**
* Get ROI from each detector and convert it to the multi detector scale (Gotthard)
* Get ROI from each detector and convert it to the multi detector scale
* (Gotthard)
* @param n number of rois
* @returns OK or FAIL
*/
@ -1224,7 +1209,7 @@ class slsDetector : public virtual slsDetectorDefs{
* @param detPos -1 for all detectors in list or specific detector position
* @returns external sampling enable
*/
std::vector<int> getReceiverDbitList();
std::vector<int> getReceiverDbitList() const;
/**
* Set digital data offset in bytes (CTB only)
@ -1240,7 +1225,8 @@ class slsDetector : public virtual slsDetectorDefs{
int getReceiverDbitOffset();
/**
* Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert users
* Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert
* users
* @param addr address of adc register
* @param val value
*/
@ -1255,8 +1241,10 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Set deactivated Receiver padding mode (Eiger only)
* @param padding padding option for deactivated receiver. Can be 1 (padding), 0 (no padding), -1 (gets)
* @returns 1 (padding), 0 (no padding), -1 (inconsistent values) for padding option
* @param padding padding option for deactivated receiver. Can be 1
* (padding), 0 (no padding), -1 (gets)
* @returns 1 (padding), 0 (no padding), -1 (inconsistent values) for
* padding option
*/
bool setDeactivatedRxrPaddingMode(int padding = -1);
@ -1373,7 +1361,8 @@ class slsDetector : public virtual slsDetectorDefs{
* @param fname name of detector server binary
* @param hostname name of pc to tftp from
*/
void copyDetectorServer(const std::string &fname, const std::string &hostname);
void copyDetectorServer(const std::string &fname,
const std::string &hostname);
/**
* Reboot detector controller (blackfin/ powerpc)
@ -1394,7 +1383,6 @@ class slsDetector : public virtual slsDetectorDefs{
*/
int setAutoComparatorDisableMode(int ival = -1);
/**
* Get trimbit filename with path for settings and energy
*
@ -1413,7 +1401,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Get module structure from detector (all detectors)
* @returns pointer to module structure (which has been created and must then be deleted)
* @returns pointer to module structure (which has been created and must
* then be deleted)
*/
sls_detector_module getModule();
@ -1466,7 +1455,7 @@ class slsDetector : public virtual slsDetectorDefs{
* Returns the IP of the last client connecting to the receiver
* @returns the IP of the last client connecting to the receiver
*/
std::string getReceiverLastClientIP();
std::string getReceiverLastClientIP() const;
/**
* Exits the receiver TCP server
@ -1544,7 +1533,8 @@ class slsDetector : public virtual slsDetectorDefs{
* @param f frames discard policy
* @returns frames discard policy set in receiver
*/
frameDiscardPolicy setReceiverFramesDiscardPolicy(frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY);
frameDiscardPolicy setReceiverFramesDiscardPolicy(
frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY);
/**
* Sets the partial frames padding enable in receiver
@ -1600,19 +1590,19 @@ class slsDetector : public virtual slsDetectorDefs{
* Gets the status of the listening mode of receiver
* @returns status
*/
runStatus getReceiverStatus();
runStatus getReceiverStatus() const;
/**
* Gets the number of frames caught by receiver
* @returns number of frames caught by receiver
*/
int getFramesCaughtByReceiver();
int getFramesCaughtByReceiver() const;
/**
* Gets the current frame index of receiver
* @returns current frame index of receiver
*/
uint64_t getReceiverCurrentFrameIndex();
uint64_t getReceiverCurrentFrameIndex() const;
/**
* Resets framescaught in receiver
@ -1662,7 +1652,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* (previously setReadReceiverFrequency)
* Sets the receiver streaming frequency
* @param freq nth frame streamed out, if 0, streamed out at a timer of 200 ms
* @param freq nth frame streamed out, if 0, streamed out at a timer of 200
* ms
* @param detPos -1 for all detectors in list or specific detector position
* @returns receiver streaming frequency
*/
@ -1738,7 +1729,8 @@ class slsDetector : public virtual slsDetectorDefs{
/**
* Writes a pattern word (CTB/ Moench)
* @param addr address of the word
* @param word 64bit word to be written, -1 reads the addr (same as executing the pattern)
* @param word 64bit word to be written, -1 reads the addr (same as
* executing the pattern)
* @returns actual value
*/
uint64_t setPatternWord(int addr, uint64_t word);
@ -1751,7 +1743,8 @@ class slsDetector : public virtual slsDetectorDefs{
* @param n number of loops for level 0-2, -1 gets
* @returns array of start addr, stop addr and number of loops
*/
std::array<int, 3> setPatternLoops(int level = -1, int start = -1, int stop = -1, int n = -1);
std::array<int, 3> setPatternLoops(int level = -1, int start = -1,
int stop = -1, int n = -1);
/**
* Sets the wait address (CTB/ Moench)
@ -1782,13 +1775,15 @@ class slsDetector : public virtual slsDetectorDefs{
uint64_t getPatternMask();
/**
* Selects the bits that the mask will be applied to for every pattern (CTB/ Moench)
* Selects the bits that the mask will be applied to for every pattern (CTB/
* Moench)
* @param mask mask to select bits
*/
void setPatternBitMask(uint64_t mask);
/**
* Gets the bits that the mask will be applied to for every pattern (CTB/ Moench)
* Gets the bits that the mask will be applied to for every pattern (CTB/
* Moench)
* @returns mask of bits selected
*/
uint64_t getPatternBitMask();
@ -1808,6 +1803,98 @@ class slsDetector : public virtual slsDetectorDefs{
void setDigitalIODelay(uint64_t pinMask, int delay);
private:
/**
* Send function parameters to detector (control server)
* @param fnum function enum
* @param args argument pointer
* @param args_size size of argument
* @param retval return pointers
* @param retval_size size of return value
*/
void sendToDetector(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
template <typename Arg, typename Ret>
void sendToDetector(int fnum, const Arg &args, Ret &retval);
template <typename Arg>
void sendToDetector(int fnum, const Arg &args, std::nullptr_t);
template <typename Ret>
void sendToDetector(int fnum, std::nullptr_t, Ret &retval);
void sendToDetector(int fnum);
/**
* Send function parameters to detector (stop server)
* @param fnum function enum
* @param args argument pointer
* @param args_size size of argument
* @param retval return pointers
* @param retval_size size of return value
*/
void sendToDetectorStop(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
void sendToDetectorStop(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const;
template <typename Arg, typename Ret>
void sendToDetectorStop(int fnum, const Arg &args, Ret &retval);
template <typename Arg, typename Ret>
void sendToDetectorStop(int fnum, const Arg &args, Ret &retval) const;
template <typename Arg>
void sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t);
template <typename Arg>
void sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t) const;
template <typename Ret>
void sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval);
template <typename Ret>
void sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) const;
void sendToDetectorStop(int fnum);
void sendToDetectorStop(int fnum) const;
/**
* Send function parameters to receiver
* @param fnum function enum
* @param args argument pointer
* @param args_size size of argument
* @param retval return pointers
* @param retval_size size of return value
*/
void sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
void sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const;
template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval);
template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval) const;
template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t);
template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const;
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval);
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const;
void sendToReceiver(int fnum);
void sendToReceiver(int fnum) const;
/**
* Get Detector Type from Shared Memory (opening shm without verifying size)
* @param multi_id multi detector Id
@ -1854,10 +1941,12 @@ class slsDetector : public virtual slsDetectorDefs{
void setUDPConnection();
/*
* Template function to do linear interpolation between two points (Eiger only)
* Template function to do linear interpolation between two points (Eiger
* only)
*/
template <typename E, typename V>
V linearInterpolation(const E x, const E x1, const E x2, const V y1, const V y2) {
V linearInterpolation(const E x, const E x1, const E x2, const V y1,
const V y2) {
double k = static_cast<double>(y2 - y1) / (x2 - x1);
double m = y1 - k * x1;
int y = round(k * x + m);
@ -1872,11 +1961,13 @@ class slsDetector : public virtual slsDetectorDefs{
* @param e1 reference trim value
* @param e2 reference trim value
* @param tb 1 to include trimbits, 0 to exclude (used for eiger)
* @returns the pointer to the module structure with interpolated values or NULL if error
* @returns the pointer to the module structure with interpolated values or
* NULL if error
*/
sls_detector_module interpolateTrim(
sls_detector_module *a, sls_detector_module *b, const int energy,
const int e1, const int e2, int tb = 1);
sls_detector_module interpolateTrim(sls_detector_module *a,
sls_detector_module *b,
const int energy, const int e1,
const int e2, int tb = 1);
/**
* reads a trim/settings file
@ -1907,6 +1998,4 @@ class slsDetector : public virtual slsDetectorDefs{
/** Shared Memory object */
mutable sls::SharedMemory<sharedSlsDetector> shm{0, 0};
};

View File

@ -116,7 +116,7 @@ int64_t slsDetector::getId(idMode mode) {
return retval;
}
int64_t slsDetector::getReceiverSoftwareVersion() {
int64_t slsDetector::getReceiverSoftwareVersion() const {
FILE_LOG(logDEBUG1) << "Getting receiver software version";
int64_t retval = -1;
if (shm()->useReceiverFlag) {
@ -158,6 +158,13 @@ void slsDetector::sendToDetector(int fnum) {
void slsDetector::sendToDetectorStop(int fnum, const void *args,
size_t args_size, void *retval,
size_t retval_size) {
static_cast<const slsDetector &>(*this).sendToDetectorStop(
fnum, args, args_size, retval, retval_size);
}
void slsDetector::sendToDetectorStop(int fnum, const void *args,
size_t args_size, void *retval,
size_t retval_size) const {
auto stop = DetectorSocket(shm()->hostname, shm()->stopPort);
stop.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
stop.close();
@ -168,31 +175,54 @@ void slsDetector::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) {
sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval));
}
template <typename Arg, typename Ret>
void slsDetector::sendToDetectorStop(int fnum, const Arg &args,
Ret &retval) const {
sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval));
}
template <typename Arg>
void slsDetector::sendToDetectorStop(int fnum, const Arg &args,
std::nullptr_t) {
sendToDetectorStop(fnum, &args, sizeof(args), nullptr, 0);
}
template <typename Arg>
void slsDetector::sendToDetectorStop(int fnum, const Arg &args,
std::nullptr_t) const {
sendToDetectorStop(fnum, &args, sizeof(args), nullptr, 0);
}
template <typename Ret>
void slsDetector::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) {
sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval));
}
template <typename Ret>
void slsDetector::sendToDetectorStop(int fnum, std::nullptr_t,
Ret &retval) const {
sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval));
}
void slsDetector::sendToDetectorStop(int fnum) {
sendToDetectorStop(fnum, nullptr, 0, nullptr, 0);
}
void slsDetector::sendToDetectorStop(int fnum) const {
sendToDetectorStop(fnum, nullptr, 0, nullptr, 0);
}
void slsDetector::sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) {
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
auto ret = receiver.sendCommandThenRead(fnum, args, args_size, retval,
retval_size);
receiver.close();
if (ret == FORCE_UPDATE) {
updateCachedReceiverVariables();
static_cast<const slsDetector &>(*this).sendToReceiver(
fnum, args, args_size, retval, retval_size);
}
void slsDetector::sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const {
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
receiver.close();
}
template <typename Arg, typename Ret>
@ -200,20 +230,40 @@ void slsDetector::sendToReceiver(int fnum, const Arg &args, Ret &retval) {
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
}
template <typename Arg, typename Ret>
void slsDetector::sendToReceiver(int fnum, const Arg &args, Ret &retval) const {
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
}
template <typename Arg>
void slsDetector::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) {
sendToReceiver(fnum, &args, sizeof(args), nullptr, 0);
}
template <typename Arg>
void slsDetector::sendToReceiver(int fnum, const Arg &args,
std::nullptr_t) const {
sendToReceiver(fnum, &args, sizeof(args), nullptr, 0);
}
template <typename Ret>
void slsDetector::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) {
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
}
template <typename Ret>
void slsDetector::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const {
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
}
void slsDetector::sendToReceiver(int fnum) {
sendToReceiver(fnum, nullptr, 0, nullptr, 0);
}
void slsDetector::sendToReceiver(int fnum) const {
sendToReceiver(fnum, nullptr, 0, nullptr, 0);
}
void slsDetector::freeSharedMemory() {
if (shm.IsExisting()) {
shm.RemoveSharedMemory();
@ -1147,7 +1197,7 @@ void slsDetector::saveSettingsFile(const std::string &fname) {
writeSettingsFile(fn, myMod);
}
slsDetectorDefs::runStatus slsDetector::getRunStatus() {
slsDetectorDefs::runStatus slsDetector::getRunStatus() const {
runStatus retval = ERROR;
FILE_LOG(logDEBUG1) << "Getting status";
sendToDetectorStop(F_GET_RUN_STATUS, nullptr, retval);
@ -1404,7 +1454,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
return shm()->timerValue[index];
}
int64_t slsDetector::getTimeLeft(timerIndex index) {
int64_t slsDetector::getTimeLeft(timerIndex index) const {
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting " << getTimerType(index) << " left";
sendToDetectorStop(F_GET_TIME_LEFT, index, retval);
@ -1540,7 +1590,6 @@ bool slsDetector::getInterruptSubframe() {
return static_cast<bool>(retval);
}
uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) {
uint32_t args[]{addr, val};
uint32_t retval = -1;
@ -2115,7 +2164,7 @@ int64_t slsDetector::getReceiverUDPSocketBufferSize() {
return setReceiverUDPSocketBufferSize();
}
int64_t slsDetector::getReceiverRealUDPSocketBufferSize() {
int64_t slsDetector::getReceiverRealUDPSocketBufferSize() const {
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting real UDP Socket Buffer size from receiver";
if (shm()->useReceiverFlag) {
@ -2455,7 +2504,7 @@ void slsDetector::setReceiverDbitList(std::vector<int> list) {
}
}
std::vector<int> slsDetector::getReceiverDbitList() {
std::vector<int> slsDetector::getReceiverDbitList() const {
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
FILE_LOG(logDEBUG1) << "Getting Receiver Dbit List";
if (shm()->useReceiverFlag) {
@ -2896,7 +2945,7 @@ int slsDetector::lockReceiver(int lock) {
return retval;
}
std::string slsDetector::getReceiverLastClientIP() {
std::string slsDetector::getReceiverLastClientIP() const {
char retval[INET_ADDRSTRLEN]{};
FILE_LOG(logDEBUG1) << "Getting last client ip to receiver server";
if (shm()->useReceiverFlag) {
@ -3200,7 +3249,7 @@ void slsDetector::stopReceiver() {
}
}
slsDetectorDefs::runStatus slsDetector::getReceiverStatus() {
slsDetectorDefs::runStatus slsDetector::getReceiverStatus() const {
runStatus retval = ERROR;
FILE_LOG(logDEBUG1) << "Getting Receiver Status";
if (shm()->useReceiverFlag) {
@ -3210,7 +3259,7 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus() {
return retval;
}
int slsDetector::getFramesCaughtByReceiver() {
int slsDetector::getFramesCaughtByReceiver() const {
int retval = -1;
FILE_LOG(logDEBUG1) << "Getting Frames Caught by Receiver";
if (shm()->useReceiverFlag) {
@ -3220,7 +3269,7 @@ int slsDetector::getFramesCaughtByReceiver() {
return retval;
}
uint64_t slsDetector::getReceiverCurrentFrameIndex() {
uint64_t slsDetector::getReceiverCurrentFrameIndex() const {
uint64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting Current Frame Index of Receiver";
if (shm()->useReceiverFlag) {

View File

@ -382,23 +382,6 @@ TEST_CASE("rx_lastclient", "[.cmd]") {
REQUIRE(oss.str() == "rx_lastclient " + test::my_ip + "\n");
}
TEST_CASE("rx_online", "[.cmd]") {
{
std::ostringstream oss;
multiSlsDetectorClient("rx_online 0", PUT, nullptr, oss);
REQUIRE(oss.str() == "rx_online 0\n");
}
{
std::ostringstream oss;
multiSlsDetectorClient("rx_online", GET, nullptr, oss);
REQUIRE(oss.str() == "rx_online 0\n");
}
{
std::ostringstream oss;
multiSlsDetectorClient("rx_online 1", PUT, nullptr, oss);
REQUIRE(oss.str() == "rx_online 1\n");
}
}
TEST_CASE("rx_checkonline", "[.cmd]") {