diff --git a/slsDetectorSoftware/include/slsDetectorCommand.h b/slsDetectorSoftware/include/slsDetectorCommand.h index f9cb934a7..9116d9e45 100755 --- a/slsDetectorSoftware/include/slsDetectorCommand.h +++ b/slsDetectorSoftware/include/slsDetectorCommand.h @@ -4,7 +4,7 @@ #include "sls_detector_defs.h" - +#include 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::vector getAllCommands(); + /* /\** */ /* returns the help for the executeLine command */ /* \param os output stream to return the help to */ diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 2b06959e3..c56d17441 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -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) { - 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) { return std::string("Must still develop ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n"); } +std::vector slsDetectorCommand::getAllCommands(){ + std::vector 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::ostringstream os; diff --git a/slsSupportLib/include/CmdProxy.h b/slsSupportLib/include/CmdProxy.h index 656ae5cf6..faaa7309c 100644 --- a/slsSupportLib/include/CmdProxy.h +++ b/slsSupportLib/include/CmdProxy.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -7,7 +8,9 @@ #include #include "logger.h" +#include "slsDetectorCommand.h" #include "sls_detector_exceptions.h" +#include "string_utils.h" namespace sls { @@ -58,7 +61,7 @@ template class CmdProxy { using StringMap = std::map; // Initialize maps for translating name and function - FunctionMap functions{{"newfunc", &CmdProxy::NewFunction}}; + FunctionMap functions{{"list", &CmdProxy::ListCommands}}; StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"}, {"r_padding", "rx_padding"}, @@ -80,34 +83,43 @@ template class CmdProxy { {"fileformat", "fformat"}, {"overwrite", "foverwrite"}}; - template 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) { - throw RuntimeError("ERROR: Expected " + std::to_string(expected) + - " parameters but got " + - std::to_string(args.size()) + "\n"); + throw RuntimeError( + "Command " + cmd + " expected <=" + std::to_string(expected) + + " parameter/s but got " + std::to_string(args.size()) + "\n"); } // Mapped functions - // example - std::string NewFunction() { + std::string ListCommands() { if (args.size() == 0) { - std::cout << "This is the new function function\n"; - return ResultToString(det->setExposureTime(-1, true)); + auto commands = slsDetectorCommand(nullptr).getAllCommands(); + 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) { - std::cout << "Setting exposure time to " << args[0] << "s\n"; - return ResultToString( - det->setExposureTime(std::stod(args[0]), true, det_id)); + if (args[0] == "deprecated") { + std::cout << "The following " << depreciated_functions.size() + << " 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 { WrongNumberOfParameters(1); - return {}; + return ""; } } };