mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-15 22:31:32 +01:00
@@ -1,12 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include "Detector.h"
|
||||
#include "Result.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** Macro to make an integer command.
|
||||
* CMDNAME name of the function that does the command
|
||||
* GETFCN Detector function to get
|
||||
* SETFCN Detector function to set
|
||||
* CONV Function to convert from string to the correct integer type
|
||||
* HLPSTR Help string for --help and docs
|
||||
*/
|
||||
|
||||
#define INTEGER_COMMAND(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
|
||||
std::string CMDNAME(const int action) { \
|
||||
std::ostringstream os; \
|
||||
os << cmd << ' '; \
|
||||
if (action == slsDetectorDefs::HELP_ACTION) \
|
||||
os << HLPSTR << '\n'; \
|
||||
else if (action == slsDetectorDefs::GET_ACTION) { \
|
||||
auto t = det->GETFCN({det_id}); \
|
||||
if (args.size() == 0) { \
|
||||
os << OutString(t) << '\n'; \
|
||||
} else { \
|
||||
WrongNumberOfParameters(2); \
|
||||
} \
|
||||
} else if (action == slsDetectorDefs::PUT_ACTION) { \
|
||||
if (args.size() == 1) { \
|
||||
auto val = CONV(args[0]); \
|
||||
det->SETFCN(val, {det_id}); \
|
||||
os << args.front() << '\n'; \
|
||||
} else { \
|
||||
WrongNumberOfParameters(1); \
|
||||
} \
|
||||
\
|
||||
} else { \
|
||||
throw sls::RuntimeError("Unknown action"); \
|
||||
} \
|
||||
return os.str(); \
|
||||
}
|
||||
|
||||
#define INTEGER_COMMAND_NOID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
|
||||
std::string CMDNAME(const int action) { \
|
||||
std::ostringstream os; \
|
||||
os << cmd << ' '; \
|
||||
if (action == slsDetectorDefs::HELP_ACTION) \
|
||||
os << HLPSTR << '\n'; \
|
||||
else if (action == slsDetectorDefs::GET_ACTION) { \
|
||||
auto t = det->GETFCN(); \
|
||||
if (args.size() == 0) { \
|
||||
os << OutString(t) << '\n'; \
|
||||
} else { \
|
||||
WrongNumberOfParameters(2); \
|
||||
} \
|
||||
} else if (action == slsDetectorDefs::PUT_ACTION) { \
|
||||
if (args.size() == 1) { \
|
||||
auto val = CONV(args[0]); \
|
||||
det->SETFCN(val); \
|
||||
os << args.front() << '\n'; \
|
||||
} else { \
|
||||
WrongNumberOfParameters(1); \
|
||||
} \
|
||||
\
|
||||
} else { \
|
||||
throw sls::RuntimeError("Unknown action"); \
|
||||
} \
|
||||
return os.str(); \
|
||||
}
|
||||
|
||||
namespace sls {
|
||||
class Detector;
|
||||
|
||||
class CmdProxy {
|
||||
public:
|
||||
@@ -27,9 +93,17 @@ class CmdProxy {
|
||||
std::vector<std::string> args;
|
||||
int det_id{-1};
|
||||
|
||||
template <typename V> std::string OutString(const V &value);
|
||||
template <typename V> std::string OutString(const V &value) {
|
||||
if (value.equal())
|
||||
return ToString(value.front());
|
||||
return ToString(value);
|
||||
}
|
||||
template <typename V>
|
||||
std::string OutString(const V &value, const std::string &unit);
|
||||
std::string OutString(const V &value, const std::string &unit) {
|
||||
if (value.equal())
|
||||
return ToString(value.front(), unit);
|
||||
return ToString(value, unit);
|
||||
}
|
||||
|
||||
using FunctionMap = std::map<std::string, std::string (CmdProxy::*)(int)>;
|
||||
using StringMap = std::map<std::string, std::string>;
|
||||
@@ -39,8 +113,18 @@ class CmdProxy {
|
||||
{"exptime", &CmdProxy::Exptime},
|
||||
{"period", &CmdProxy::Period},
|
||||
{"subexptime", &CmdProxy::SubExptime},
|
||||
{"rx_fifodepth", &CmdProxy::RxFifoDepth},
|
||||
{"rx_silent", &CmdProxy::RxSilent}};
|
||||
{"frames", &CmdProxy::frames},
|
||||
{"fwrite", &CmdProxy::fwrite},
|
||||
{"fmaster", &CmdProxy::fmaster},
|
||||
{"foverwrite", &CmdProxy::foverwrite},
|
||||
{"findex", &CmdProxy::findex},
|
||||
{"rx_fifodepth", &CmdProxy::rx_fifodepth},
|
||||
{"rx_silent", &CmdProxy::rx_silent},
|
||||
{"rx_lock", &CmdProxy::rx_lock},
|
||||
{"lock", &CmdProxy::lock},
|
||||
{"rx_readfreq", &CmdProxy::rx_readfreq},
|
||||
{"rx_padding", &CmdProxy::rx_padding},
|
||||
{"rx_framesperfile", &CmdProxy::rx_framesperfile}};
|
||||
|
||||
StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"},
|
||||
{"r_padding", "rx_padding"},
|
||||
@@ -69,8 +153,46 @@ class CmdProxy {
|
||||
std::string Period(int action);
|
||||
std::string Exptime(int action);
|
||||
std::string SubExptime(int action);
|
||||
std::string RxFifoDepth(const int action);
|
||||
std::string RxSilent(const int action);
|
||||
|
||||
INTEGER_COMMAND(
|
||||
rx_fifodepth, getRxFifoDepth, setRxFifoDepth, std::stoi,
|
||||
"[n_frames]\n\tSet the number of frames in the receiver fifo");
|
||||
|
||||
INTEGER_COMMAND(rx_silent, getRxSilentMode, setRxSilentMode, std::stoi,
|
||||
"[0, 1]\n\tSwitch on or off receiver text output");
|
||||
|
||||
INTEGER_COMMAND(rx_lock, getRxLock, setRxLock, std::stoi,
|
||||
"[0, 1]\n\tLock receiver to one IP, 1: locks");
|
||||
|
||||
INTEGER_COMMAND(lock, getDetectorLock, setDetectorLock, std::stoi,
|
||||
"[0, 1]\n\tLock detector to one IP, 1: locks");
|
||||
|
||||
INTEGER_COMMAND(rx_readfreq, getRxZmqFrequency, setRxZmqFrequency,
|
||||
std::stoi, "[nth frame]\n\tStream out every nth frame");
|
||||
|
||||
INTEGER_COMMAND(rx_padding, getPartialFramesPadding,
|
||||
setPartialFramesPadding, std::stoi,
|
||||
"[0, 1]\n\tgets partial frames padding enable in the "
|
||||
"receiver. 0 does not pad partial frames(fastest), 1 "
|
||||
"(default) pads partial frames");
|
||||
INTEGER_COMMAND(rx_framesperfile, getFramesPerFile, setFramesPerFile,
|
||||
std::stoi, "[n_frames]\n\tNumber of frames per file");
|
||||
|
||||
INTEGER_COMMAND_NOID(frames, getNumberOfFrames, setNumberOfFrames,
|
||||
std::stol,
|
||||
"[n_frames]\n\tNumber of frames per aquire");
|
||||
|
||||
INTEGER_COMMAND(fwrite, getFileWrite, setFileWrite, std::stoi,
|
||||
"[0, 1]\n\tEnable or disable receiver file write");
|
||||
|
||||
INTEGER_COMMAND(fmaster, getMasterFileWrite, setMasterFileWrite, std::stoi,
|
||||
"[0, 1]\n\tEnable or disable receiver master file");
|
||||
|
||||
INTEGER_COMMAND(foverwrite, getFileOverWrite, setFileOverWrite, std::stoi,
|
||||
"[0, 1]\n\tEnable or disable file overwriting");
|
||||
|
||||
INTEGER_COMMAND(findex, getAcquisitionIndex, setAcquisitionIndex, std::stoi,
|
||||
"[0, 1]\n\tFile index");
|
||||
};
|
||||
|
||||
} // namespace sls
|
||||
|
||||
@@ -488,7 +488,7 @@ class Detector {
|
||||
*/
|
||||
void setFileNamePrefix(const std::string &fname, Positions pos = {});
|
||||
|
||||
Result<int> getAcquisitonIndex(Positions pos = {}) const;
|
||||
Result<int> getAcquisitionIndex(Positions pos = {}) const;
|
||||
|
||||
void setAcquisitionIndex(int i, Positions pos = {});
|
||||
|
||||
|
||||
@@ -52,12 +52,10 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
static std::string helpTrimEn(int action);
|
||||
static std::string helpOutDir(int action);
|
||||
static std::string helpFileName(int action);
|
||||
static std::string helpFileIndex(int action);
|
||||
static std::string helpRateCorr(int action);
|
||||
static std::string helpThreaded(int action);
|
||||
static std::string helpNetworkParameter(int action);
|
||||
static std::string helpPort(int action);
|
||||
static std::string helpLock(int action);
|
||||
static std::string helpLastClient(int action);
|
||||
static std::string helpOnline(int action);
|
||||
static std::string helpConfigureMac(int action);
|
||||
@@ -76,26 +74,12 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
static std::string helpCounter(int action);
|
||||
static std::string helpADC(int action);
|
||||
static std::string helpTempControl(int action);
|
||||
static std::string helpEnablefwrite(int action);
|
||||
static std::string helpOverwrite(int action);
|
||||
static std::string helpReceiver(int action);
|
||||
static std::string helpPattern(int action);
|
||||
static std::string helpPulse(int action);
|
||||
static std::string helpProcessor(int action);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
multiSlsDetector *myDet;
|
||||
|
||||
std::string cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos = -1);
|
||||
@@ -113,11 +97,9 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
std::string cmdTrimEn(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdOutDir(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdFileName(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdFileIndex(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdRateCorr(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdNetworkParameter(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdPort(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdLock(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdLastClient(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdOnline(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdConfigureMac(int narg, const char * const args[], int action, int detPos = -1);
|
||||
@@ -136,8 +118,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
std::string cmdCounter(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdADC(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdTempControl(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdEnablefwrite(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdOverwrite(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdReceiver(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdPattern(int narg, const char * const args[], int action, int detPos = -1);
|
||||
std::string cmdPulse(int narg, const char * const args[], int action, int detPos = -1);
|
||||
|
||||
Reference in New Issue
Block a user