* migrated more

* more
This commit is contained in:
Erik Fröjdh
2019-08-23 17:39:41 +02:00
committed by GitHub
parent 2c5ff0e9bf
commit 9a48d9b832
7 changed files with 158 additions and 306 deletions

View File

@ -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