diff --git a/slsDetectorSoftware/generator/commands.yaml b/slsDetectorSoftware/generator/commands.yaml index 2172d0615..a61934c6d 100644 --- a/slsDetectorSoftware/generator/commands.yaml +++ b/slsDetectorSoftware/generator/commands.yaml @@ -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: diff --git a/slsDetectorSoftware/generator/extended_commands.yaml b/slsDetectorSoftware/generator/extended_commands.yaml index 32685dcc5..1c0ca76f3 100644 --- a/slsDetectorSoftware/generator/extended_commands.yaml +++ b/slsDetectorSoftware/generator/extended_commands.yaml @@ -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: diff --git a/slsDetectorSoftware/src/Caller.h b/slsDetectorSoftware/src/Caller.h index 1add3a590..4abde06a7 100644 --- a/slsDetectorSoftware/src/Caller.h +++ b/slsDetectorSoftware/src/Caller.h @@ -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}, diff --git a/slsDetectorSoftware/src/CallerSpecial.cpp b/slsDetectorSoftware/src/CallerSpecial.cpp index 3a66053bf..774fd1c8a 100644 --- a/slsDetectorSoftware/src/CallerSpecial.cpp +++ b/slsDetectorSoftware/src/CallerSpecial.cpp @@ -5,6 +5,7 @@ #include "sls/logger.h" #include "sls/string_utils.h" #include +#include 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(tmp_time, unit); + } else { + converted_time = StringTo(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 \ No newline at end of file diff --git a/slsDetectorSoftware/src/inferAction.cpp b/slsDetectorSoftware/src/inferAction.cpp index edb717e9b..2a747a208 100644 --- a/slsDetectorSoftware/src/inferAction.cpp +++ b/slsDetectorSoftware/src/inferAction.cpp @@ -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) { diff --git a/slsDetectorSoftware/src/inferAction.h b/slsDetectorSoftware/src/inferAction.h index 3b0538a3e..f18ba1ac8 100644 --- a/slsDetectorSoftware/src/inferAction.h +++ b/slsDetectorSoftware/src/inferAction.h @@ -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}, diff --git a/slsDetectorSoftware/tests/Caller/test-Caller.cpp b/slsDetectorSoftware/tests/Caller/test-Caller.cpp index 5372c7141..fad23d35a 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller.cpp @@ -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 \ No newline at end of file