mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
sleep implemented for command line, mainly for config files for firmware developers (#982)
This commit is contained in:
parent
2dc0963c56
commit
8144397b2c
@ -2690,6 +2690,17 @@ gaincaps:
|
||||
argc: -1
|
||||
arg_types: [ defs::defs::M3_GainCaps ]
|
||||
|
||||
sleep:
|
||||
is_description: true
|
||||
actions:
|
||||
PUT:
|
||||
args:
|
||||
- argc: 1
|
||||
arg_types: [ int ]
|
||||
- argc: 2
|
||||
arg_types: [ int, special::time_unit ]
|
||||
|
||||
|
||||
################# special commands ##########################
|
||||
|
||||
virtual:
|
||||
|
@ -10042,6 +10042,40 @@ signalname:
|
||||
\ to the given name."
|
||||
infer_action: true
|
||||
template: true
|
||||
sleep:
|
||||
actions:
|
||||
PUT:
|
||||
args:
|
||||
- arg_types:
|
||||
- int
|
||||
argc: 1
|
||||
cast_input: []
|
||||
check_det_id: false
|
||||
convert_det_id: true
|
||||
function: ''
|
||||
input: []
|
||||
input_types: []
|
||||
output: []
|
||||
require_det_id: false
|
||||
store_result_in_t: false
|
||||
- arg_types:
|
||||
- int
|
||||
- special::time_unit
|
||||
argc: 2
|
||||
cast_input: []
|
||||
check_det_id: false
|
||||
convert_det_id: true
|
||||
function: ''
|
||||
input: []
|
||||
input_types: []
|
||||
output: []
|
||||
require_det_id: false
|
||||
store_result_in_t: false
|
||||
command_name: sleep
|
||||
function_alias: sleep
|
||||
help: ''
|
||||
infer_action: true
|
||||
is_description: true
|
||||
slowadc:
|
||||
actions:
|
||||
GET:
|
||||
|
@ -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},
|
||||
|
@ -3586,4 +3586,14 @@ TEST_CASE("CALLER::user", "[.cmdcall]") {
|
||||
REQUIRE_NOTHROW(caller.call("user", {}, -1, GET));
|
||||
}
|
||||
|
||||
TEST_CASE("CALLER::sleep", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
REQUIRE_NOTHROW(caller.call("sleep", {"1"}, -1, PUT));
|
||||
REQUIRE_NOTHROW(caller.call("sleep", {"100", "ms"}, -1, PUT));
|
||||
REQUIRE_NOTHROW(caller.call("sleep", {"1000", "ns"}, -1, PUT));
|
||||
// This is a put only command
|
||||
REQUIRE_THROWS(caller.call("sleep", {}, -1, GET));
|
||||
}
|
||||
|
||||
} // namespace sls
|
Loading…
x
Reference in New Issue
Block a user