fixed output

This commit is contained in:
Erik Frojdh 2019-08-23 15:44:47 +02:00
parent e89b65002a
commit 2c5ff0e9bf
2 changed files with 25 additions and 10 deletions

View File

@ -10,6 +10,10 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <iostream>
#include <vector>
#define TIME_COMMAND(GETFCN, SETFCN, HLPSTR) \ #define TIME_COMMAND(GETFCN, SETFCN, HLPSTR) \
std::ostringstream os; \ std::ostringstream os; \
@ -37,13 +41,13 @@
} else { \ } else { \
WrongNumberOfParameters(2); \ WrongNumberOfParameters(2); \
} \ } \
os << ToString(args) << '\n'; \ os << args << '\n'; \
} else { \ } else { \
throw sls::RuntimeError("Unknown action"); \ throw sls::RuntimeError("Unknown action"); \
} \ } \
return os.str(); return os.str();
#define INTEGER_COMMAND(GETFCN, SETFCN, HLPSTR) \ #define INTEGER_COMMAND(GETFCN, SETFCN, CONV, HLPSTR) \
std::ostringstream os; \ std::ostringstream os; \
os << cmd << ' '; \ os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \ if (action == slsDetectorDefs::HELP_ACTION) \
@ -57,12 +61,13 @@
} \ } \
} else if (action == slsDetectorDefs::PUT_ACTION) { \ } else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() == 1) { \ if (args.size() == 1) { \
auto val = std::stoi(args[0]); \ auto val = CONV(args[0]); \
det->SETFCN(val, {det_id}); \ det->SETFCN(val, {det_id}); \
os << args.front() << '\n'; \
} else { \ } else { \
WrongNumberOfParameters(1); \ WrongNumberOfParameters(1); \
} \ } \
os << ToString(args) << '\n'; \ \
} else { \ } else { \
throw sls::RuntimeError("Unknown action"); \ throw sls::RuntimeError("Unknown action"); \
} \ } \
@ -70,6 +75,17 @@
namespace sls { namespace sls {
std::ostream &operator<<(std::ostream &os,
const std::vector<std::string> &vec) {
if (!vec.empty()) {
auto it = vec.begin();
os << *it++;
while (it != vec.end())
os << ' ' << *it++;
}
return os;
}
std::string CmdProxy::Call(const std::string &command, std::string CmdProxy::Call(const std::string &command,
const std::vector<std::string> &arguments, const std::vector<std::string> &arguments,
int detector_id, int action, std::ostream &os) { int detector_id, int action, std::ostream &os) {
@ -158,14 +174,13 @@ std::string CmdProxy::SubExptime(int action) {
std::string CmdProxy::RxFifoDepth(const int action) { std::string CmdProxy::RxFifoDepth(const int action) {
INTEGER_COMMAND( INTEGER_COMMAND(
getRxFifoDepth, setRxFifoDepth, getRxFifoDepth, setRxFifoDepth, std::stoi,
"[n_frames]\n\tSet the number of frames in the receiver fifo"); "[n_frames]\n\tSet the number of frames in the receiver fifo");
} }
std::string CmdProxy::RxSilent(const int action){ std::string CmdProxy::RxSilent(const int action) {
INTEGER_COMMAND( INTEGER_COMMAND(getRxSilentMode, setRxSilentMode, std::stoi,
getRxSilentMode, setRxSilentMode, "[0, 1]\n\tSwitch on or off receiver text output");
"[0, 1]\n\tSwitch on or off receiver text output");
} }
std::string CmdProxy::ListCommands(int action) { std::string CmdProxy::ListCommands(int action) {

View File

@ -171,4 +171,4 @@ TEST_CASE("Printing Result<int>"){
os << res; os << res;
REQUIRE(os.str() == "[1, 2, 3]"); REQUIRE(os.str() == "[1, 2, 3]");
} }