mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
sleep implemented for command line, mainly for config files for firmware developers (#982)
This commit is contained in:
@ -285,6 +285,7 @@ class Caller {
|
||||
std::string signalindex(int action);
|
||||
std::string signallist(int action);
|
||||
std::string signalname(int action);
|
||||
std::string sleep(int action);
|
||||
std::string slowadc(int action);
|
||||
std::string slowadcindex(int action);
|
||||
std::string slowadclist(int action);
|
||||
@ -631,6 +632,7 @@ class Caller {
|
||||
{"signalindex", &Caller::signalindex},
|
||||
{"signallist", &Caller::signallist},
|
||||
{"signalname", &Caller::signalname},
|
||||
{"sleep", &Caller::sleep},
|
||||
{"slowadc", &Caller::slowadc},
|
||||
{"slowadcindex", &Caller::slowadcindex},
|
||||
{"slowadclist", &Caller::slowadclist},
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "sls/logger.h"
|
||||
#include "sls/string_utils.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
namespace sls {
|
||||
// some helper functions to print
|
||||
|
||||
@ -1179,4 +1180,37 @@ std::string Caller::gaincaps(int action) {
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
std::string Caller::sleep(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[duration] [(optional unit) ns|us|ms|s]\n\tSleep for duration. "
|
||||
"Mainly for config files for firmware developers."
|
||||
"Default unit is s."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
throw RuntimeError("Cannot get.");
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 1 && args.size() != 2) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
time::ns converted_time{0};
|
||||
try {
|
||||
if (args.size() == 1) {
|
||||
std::string tmp_time(args[0]);
|
||||
std::string unit = RemoveUnit(tmp_time);
|
||||
converted_time = StringTo<time::ns>(tmp_time, unit);
|
||||
} else {
|
||||
converted_time = StringTo<time::ns>(args[0], args[1]);
|
||||
}
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not convert argument to time::ns");
|
||||
}
|
||||
std::this_thread::sleep_for(converted_time);
|
||||
os << "for " << ToString(converted_time) << " completed" << '\n';
|
||||
} else {
|
||||
throw RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
} // namespace sls
|
@ -3239,6 +3239,22 @@ int InferAction::signalname() {
|
||||
}
|
||||
}
|
||||
|
||||
int InferAction::sleep() {
|
||||
|
||||
if (args.size() == 1) {
|
||||
return slsDetectorDefs::PUT_ACTION;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
return slsDetectorDefs::PUT_ACTION;
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
throw RuntimeError("Could not infer action: Wrong number of arguments");
|
||||
}
|
||||
}
|
||||
|
||||
int InferAction::slowadc() {
|
||||
|
||||
if (args.size() == 1) {
|
||||
|
@ -240,6 +240,7 @@ class InferAction {
|
||||
int signalindex();
|
||||
int signallist();
|
||||
int signalname();
|
||||
int sleep();
|
||||
int slowadc();
|
||||
int slowadcindex();
|
||||
int slowadclist();
|
||||
@ -574,6 +575,7 @@ class InferAction {
|
||||
{"signalindex", &InferAction::signalindex},
|
||||
{"signallist", &InferAction::signallist},
|
||||
{"signalname", &InferAction::signalname},
|
||||
{"sleep", &InferAction::sleep},
|
||||
{"slowadc", &InferAction::slowadc},
|
||||
{"slowadcindex", &InferAction::slowadcindex},
|
||||
{"slowadclist", &InferAction::slowadclist},
|
||||
|
Reference in New Issue
Block a user