mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-07 10:30:41 +02:00
adding list command (#34)
This commit is contained in:
parent
71f26b2831
commit
6c33f7de7b
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
#include <vector>
|
||||||
class multiSlsDetector;
|
class multiSlsDetector;
|
||||||
|
|
||||||
|
|
||||||
@ -31,6 +31,9 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
|||||||
*/
|
*/
|
||||||
std::string executeLine(int narg, const char * const args[], int action, int detPos = -1);
|
std::string executeLine(int narg, const char * const args[], int action, int detPos = -1);
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> getAllCommands();
|
||||||
|
|
||||||
/* /\** */
|
/* /\** */
|
||||||
/* returns the help for the executeLine command */
|
/* returns the help for the executeLine command */
|
||||||
/* \param os output stream to return the help to */
|
/* \param os output stream to return the help to */
|
||||||
|
@ -2162,12 +2162,19 @@ std::string slsDetectorCommand::executeLine(int narg, const char * const args[],
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetectorCommand::cmdUnknown(int narg, const char * const args[], int action, int detPos) {
|
std::string slsDetectorCommand::cmdUnknown(int narg, const char * const args[], int action, int detPos) {
|
||||||
return std::string("Unknown command ") + std::string(args[0]) + std::string("\n") + helpLine(0, args, action, detPos);
|
return std::string("Unknown command, use list to list all commands ");
|
||||||
}
|
}
|
||||||
std::string slsDetectorCommand::cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos) {
|
std::string slsDetectorCommand::cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos) {
|
||||||
return std::string("Must still develop ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
|
return std::string("Must still develop ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> slsDetectorCommand::getAllCommands(){
|
||||||
|
std::vector<std::string> commands;
|
||||||
|
for (int i = 0; i!= numberOfCommands; ++i)
|
||||||
|
commands.emplace_back(descrToFuncMap[i].m_pFuncName);
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
std::string slsDetectorCommand::helpLine(int narg, const char * const args[], int action, int detPos) {
|
std::string slsDetectorCommand::helpLine(int narg, const char * const args[], int action, int detPos) {
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -7,7 +8,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "slsDetectorCommand.h"
|
||||||
#include "sls_detector_exceptions.h"
|
#include "sls_detector_exceptions.h"
|
||||||
|
#include "string_utils.h"
|
||||||
|
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
@ -58,7 +61,7 @@ template <typename T> class CmdProxy {
|
|||||||
using StringMap = std::map<std::string, std::string>;
|
using StringMap = std::map<std::string, std::string>;
|
||||||
|
|
||||||
// Initialize maps for translating name and function
|
// Initialize maps for translating name and function
|
||||||
FunctionMap functions{{"newfunc", &CmdProxy::NewFunction}};
|
FunctionMap functions{{"list", &CmdProxy::ListCommands}};
|
||||||
|
|
||||||
StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"},
|
StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"},
|
||||||
{"r_padding", "rx_padding"},
|
{"r_padding", "rx_padding"},
|
||||||
@ -80,34 +83,43 @@ template <typename T> class CmdProxy {
|
|||||||
{"fileformat", "fformat"},
|
{"fileformat", "fformat"},
|
||||||
{"overwrite", "foverwrite"}};
|
{"overwrite", "foverwrite"}};
|
||||||
|
|
||||||
template <typename U> std::string ResultToString(const U &ret) {
|
|
||||||
std::ostringstream os;
|
|
||||||
if (det_id != -1)
|
|
||||||
os << det_id << ":";
|
|
||||||
os << cmd << " " << ret << "\n";
|
|
||||||
return os.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WrongNumberOfParameters(size_t expected) {
|
void WrongNumberOfParameters(size_t expected) {
|
||||||
throw RuntimeError("ERROR: Expected " + std::to_string(expected) +
|
throw RuntimeError(
|
||||||
" parameters but got " +
|
"Command " + cmd + " expected <=" + std::to_string(expected) +
|
||||||
std::to_string(args.size()) + "\n");
|
" parameter/s but got " + std::to_string(args.size()) + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapped functions
|
// Mapped functions
|
||||||
|
|
||||||
// example
|
std::string ListCommands() {
|
||||||
std::string NewFunction() {
|
|
||||||
if (args.size() == 0) {
|
if (args.size() == 0) {
|
||||||
std::cout << "This is the new function function\n";
|
auto commands = slsDetectorCommand(nullptr).getAllCommands();
|
||||||
return ResultToString(det->setExposureTime(-1, true));
|
for (const auto &it : functions)
|
||||||
|
commands.emplace_back(it.first);
|
||||||
|
std::sort(begin(commands), end(commands));
|
||||||
|
|
||||||
|
std::cout << "These " << commands.size()
|
||||||
|
<< " commands are available\n";
|
||||||
|
for (auto &c : commands)
|
||||||
|
std::cout << c << '\n';
|
||||||
|
return "";
|
||||||
} else if (args.size() == 1) {
|
} else if (args.size() == 1) {
|
||||||
std::cout << "Setting exposure time to " << args[0] << "s\n";
|
if (args[0] == "deprecated") {
|
||||||
return ResultToString(
|
std::cout << "The following " << depreciated_functions.size()
|
||||||
det->setExposureTime(std::stod(args[0]), true, det_id));
|
<< " commands are deprecated\n";
|
||||||
|
size_t field_width = 20;
|
||||||
|
for (const auto &it : depreciated_functions) {
|
||||||
|
std::cout << std::right << std::setw(field_width)
|
||||||
|
<< it.first << " -> " << it.second << '\n';
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
throw RuntimeError(
|
||||||
|
"Could not decode argument. Possible options: deprecated");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
WrongNumberOfParameters(1);
|
WrongNumberOfParameters(1);
|
||||||
return {};
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user