* WIP

* WIP

* WIP

* cleaned up multi

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* split up python module

* WIP

* WIP

* WIP

* WIP

* WIP

* ok

* fixed bugs from rebase

* WIP

* fixed broken test

* WIP

* fixed python

* WIP

* sphinx help

* including new commands

* docs

* WIP

* WIP

* more tests

* added missing public header

* WIP
This commit is contained in:
Dhanya Thattil
2019-08-07 11:21:07 +02:00
committed by GitHub
parent 98ddf154b2
commit 4ceee97c03
58 changed files with 2317 additions and 571 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
@@ -7,12 +8,48 @@
#include <string>
#include <vector>
#include "Result.h"
#include "TimeHelper.h"
#include "ToString.h"
#include "container_utils.h"
#include "logger.h"
#include "slsDetectorCommand.h"
#include "sls_detector_exceptions.h"
#include "sls_detector_defs.h"
#include "sls_detector_exceptions.h"
#include "string_utils.h"
#define TIME_COMMAND(GETFCN, SETFCN, HLPSTR) \
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 if (args.size() == 1) { \
os << OutString(t, args[0]) << '\n'; \
} else { \
WrongNumberOfParameters(2); \
} \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() == 1) { \
std::string time_str(args[0]); \
std::string unit = RemoveUnit(time_str); \
auto t = StringTo<time::ns>(time_str, unit); \
det->SETFCN(t, {det_id}); \
} else if (args.size() == 2) { \
auto t = StringTo<time::ns>(args[0], args[1]); \
det->SETFCN(t, {det_id}); \
} else { \
WrongNumberOfParameters(2); \
} \
os << ToString(args) << '\n'; \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str();
namespace sls {
template <typename T> class CmdProxy {
@@ -20,9 +57,8 @@ template <typename T> class CmdProxy {
explicit CmdProxy(T *detectorPtr) : det(detectorPtr) {}
std::string Call(const std::string &command,
const std::vector<std::string> &arguments,
int detector_id,
int action=-1) {
const std::vector<std::string> &arguments, int detector_id,
int action = -1, std::ostream &os = std::cout) {
cmd = command;
args = arguments;
det_id = detector_id;
@@ -31,7 +67,7 @@ template <typename T> class CmdProxy {
auto it = functions.find(cmd);
if (it != functions.end()) {
std::cout << ((*this).*(it->second))(action);
os << ((*this).*(it->second))(action);
return {};
} else {
return cmd;
@@ -53,17 +89,47 @@ template <typename T> class CmdProxy {
size_t GetFunctionMapSize() const noexcept { return functions.size(); };
std::vector<std::string> GetAllCommands() {
auto commands = slsDetectorCommand(nullptr).getAllCommands();
for (const auto &it : functions)
commands.emplace_back(it.first);
std::sort(begin(commands), end(commands));
return commands;
}
std::vector<std::string> GetProxyCommands() {
std::vector<std::string> commands;
for (const auto &it : functions)
commands.emplace_back(it.first);
std::sort(begin(commands), end(commands));
return commands;
}
private:
T *det;
std::string cmd;
std::vector<std::string> args;
int det_id{-1};
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) {
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>;
// Initialize maps for translating name and function
FunctionMap functions{{"list", &CmdProxy::ListCommands}};
FunctionMap functions{{"list", &CmdProxy::ListCommands},
{"exptime2", &CmdProxy::Exptime},
{"period2", &CmdProxy::Period},
{"subexptime2", &CmdProxy::SubExptime}};
StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"},
{"r_padding", "rx_padding"},
@@ -92,10 +158,10 @@ template <typename T> class CmdProxy {
}
// Mapped functions
std::string ListCommands(int action) {
if (action==slsDetectorDefs::HELP_ACTION)
return "list - lists all available commands, list deprecated - list deprecated commands\n";
if (action == slsDetectorDefs::HELP_ACTION)
return "list\n\tlists all available commands, list deprecated - "
"list deprecated commands\n";
if (args.size() == 0) {
auto commands = slsDetectorCommand(nullptr).getAllCommands();
@@ -127,6 +193,22 @@ template <typename T> class CmdProxy {
return "";
}
}
std::string Period(int action) {
TIME_COMMAND(
getPeriod, setPeriod,
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the period");
}
std::string Exptime(int action) {
TIME_COMMAND(
getExptime, setExptime,
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the exposure time");
}
std::string SubExptime(int action) {
TIME_COMMAND(getSubExptime, setSubExptime,
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the "
"exposure time of EIGER subframes");
}
};
} // namespace sls