Dhanya Thattil ce7270e8a2
commands code generation (#871)
* commands code generation  (#803)

* commands code generation for only frames command

* fix cmake file and add Caller files

* working exptime, fully extended commands file and its variants

* start adding template commands

* add INT_CMD_VEC_ID template

* add list command, generate multiple bins, format code

* reach 208 commands using the cpp macros

* add tests for command parser

* start adding tests for commands parser

* fix typo to use commands.yaml

* add more tests for command_parser

* add all template functions (up to 218 commands)

* finish template functions and add more CmdProxy.cpp functions (250+)

* 257 commands

* 300 commands the rest are very special commands

* add special commands without generation

* separate special functions from generated c++ file

* implementing one command for put and get (buggy)

* add infer action in a separate file

* generate header for special commands from yaml

* allow only 0 or 1 for bool inputs

* group all commands in gen_commands.py

* add help to gen_commands.py

* add autocomplete bash script

* autocompletion: add support for module levels and help

* remove debugging line

* add autocompletion, help to commands, change int [0,1] to bool

* copy tests for Caller.cpp. Tests pass

* update with the new developer branch changes

* fix errors after merging (there is problems with tests)

* fixed port/stopport in yaml (intput typo), added '_caller' to the test dac and test on chip dac command in global test for cmdcaller

* undo previous test simulator debug change

* add documentation for the generated code

* reducing the comment to be replaced in length so formatting does not split into 2 lines

* removed formatting specific style of C++11 in gen_commands.py to keep with the top level clang format of the project
* regeneratign code for commands

* automation generated

* Redirect deprecated commands (#872)

* working implementation, need to fix dac

* fixed deprecation redirect for dac command

* Detector specific autocomplete (#873)

* working implementation, need to fix dac

* fixed deprecation redirect for dac command

* detector specific completion for dac

* added autocomplete using detector specific

* fixed error when autocompleting partial words

* Generate commands/fix commands (#875)

* fix vm_a, im_a etc have deg Celsius suffix, also help missing or changed in some places

* dac: require det id for all, arg0 to be printed at output, help for onchip dac and dac, onchipdac: spacing

* getscan detid and blocking trigger help

* udp_Dstlist det_id fixed, but rx_id invalid

* cmdApp in line with cmdLineApp (missing version, receiver_id, not creating det object in help action

* added set_command to differentiate between check_det_id and require_det_id (mixed up), args: -1 needs to check for at least one argument

* reordering

* reordering and checked till integer_command_hex

* fixed a lot more commands

* fix caller tests for eiger

* changes to tests after Bechir left

* changing .cmd to .cmdcall for the caller commands

* fixed tests for caller, still warning for setexptime about cast input

* autocomplete ran

* add moench test

* regenerating autocomplete and commands

* fixing other things from merge conflicts (renaming slsDetectorDefs to defs in commands.yaml)

* formatting

* added code injection to help (#876)

* updated 3 commands to have get output that can be put into put (#877)

* updated some commands to have get output that can be put into put

* fix tests for clkdiv

* adding help to free (#878)

* removing old commands and renaming them, (also making it work for parameters command as it was still calling cmdproxy) (#879)

* More helpful error messages for unsupported actions (#880)

* removing old commands and renaming them, (also making it work for parameters command as it was still calling cmdproxy)

* Added specific help for unsupported actions

* fixed a vetofile get special exception message. more specific warning for special exception message instead of no function warning

* added condition checking true in exceptions for special message

---------
Co-authored-by: Bechir Brahem <bachbrahem@gmail.com>
Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
2023-12-13 14:43:38 +01:00

750 lines
29 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Caller.h"
#include "catch.hpp"
#include "sls/Detector.h"
#include "sls/sls_detector_defs.h"
#include <sstream>
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* dacs */
TEST_CASE("Caller::Setting and reading back Jungfrau dacs",
"[.cmdcall][.dacs]") {
// vb_comp, vdd_prot, vin_com, vref_prech, vb_pixbuf, vb_ds, vref_ds,
// vref_comp
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
SECTION("vb_comp") { test_dac_caller(defs::VB_COMP, "vb_comp", 1220); }
SECTION("vdd_prot") {
test_dac_caller(defs::VDD_PROT, "vdd_prot", 3000);
}
SECTION("vin_com") { test_dac_caller(defs::VIN_COM, "vin_com", 1053); }
SECTION("vref_prech") {
test_dac_caller(defs::VREF_PRECH, "vref_prech", 1450);
}
SECTION("vb_pixbuf") {
test_dac_caller(defs::VB_PIXBUF, "vb_pixbuf", 750);
}
SECTION("vb_ds") { test_dac_caller(defs::VB_DS, "vb_ds", 1000); }
SECTION("vref_ds") { test_dac_caller(defs::VREF_DS, "vref_ds", 480); }
SECTION("vref_comp") {
test_dac_caller(defs::VREF_COMP, "vref_comp", 420);
}
// eiger
REQUIRE_THROWS(caller.call("vthreshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtgstv", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_ll", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_lr", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rl", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rr", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_rb", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_lb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("iodelay", {}, -1, GET));
// gotthard
// REQUIRE_THROWS(caller.call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascn_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascp_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vout_cm", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcasc_out", {}, -1, GET));
REQUIRE_THROWS(caller.call("vin_cm", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vref_comp", {}, -1, GET));
REQUIRE_THROWS(caller.call("ib_test_c", {}, -1, GET));
// mythen3
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth2", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth3", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_p", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcassh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcas", {}, -1, GET));
REQUIRE_THROWS(caller.call("vicin", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre_out", {}, -1, GET));
// gotthard2
REQUIRE_THROWS(caller.call("vref_h_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_rstore", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_1st", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_l_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_cs", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_fd", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc2", {}, -1, GET));
}
}
/* Network Configuration (Detector<->Receiver) */
TEST_CASE("Caller::selinterface", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getSelectedUDPInterface().tsquash(
"inconsistent selected interface to test");
{
std::ostringstream oss;
caller.call("selinterface", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "selinterface 1\n");
}
{
std::ostringstream oss;
caller.call("selinterface", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "selinterface 0\n");
}
{
std::ostringstream oss;
caller.call("selinterface", {}, -1, GET, oss);
REQUIRE(oss.str() == "selinterface 0\n");
}
det.selectUDPInterface(prev_val);
REQUIRE_THROWS(caller.call("selinterface", {"2"}, -1, PUT));
} else {
REQUIRE_THROWS(caller.call("selinterface", {}, -1, GET));
}
}
/* Jungfrau/moench Specific */
TEST_CASE("Caller::temp_threshold", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getThresholdTemperature();
{
std::ostringstream oss;
caller.call("temp_threshold", {"65"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_threshold 65\n");
}
{
std::ostringstream oss;
caller.call("temp_threshold", {"70"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_threshold 70\n");
}
{
std::ostringstream oss;
caller.call("temp_threshold", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_threshold 70\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setThresholdTemperature(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("temp_threshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_threshold", {"70"}, -1, PUT));
}
}
TEST_CASE("Caller::chipversion", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
REQUIRE_NOTHROW(caller.call("chipversion", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("chipversion", {}, -1, GET));
}
REQUIRE_THROWS(caller.call("chipversion", {"0"}, -1, PUT));
}
TEST_CASE("Caller::temp_control", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getTemperatureControl();
{
std::ostringstream oss;
caller.call("temp_control", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_control 0\n");
}
{
std::ostringstream oss;
caller.call("temp_control", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_control 1\n");
}
{
std::ostringstream oss;
caller.call("temp_control", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_control 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTemperatureControl(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("temp_control", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_control", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::temp_event", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
{
std::ostringstream oss;
caller.call("temp_event", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_event cleared\n");
}
{
std::ostringstream oss;
caller.call("temp_event", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_event 0\n");
}
} else {
REQUIRE_THROWS(caller.call("temp_event", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_event", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::autocompdisable", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getAutoComparatorDisable();
{
std::ostringstream oss;
caller.call("autocompdisable", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "autocompdisable 0\n");
}
{
std::ostringstream oss;
caller.call("autocompdisable", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "autocompdisable 1\n");
}
{
std::ostringstream oss;
caller.call("autocompdisable", {}, -1, GET, oss);
REQUIRE(oss.str() == "autocompdisable 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setAutoComparatorDisable(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("autocompdisable", {}, -1, GET));
REQUIRE_THROWS(caller.call("autocompdisable", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::compdisabletime", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU &&
det.getChipVersion().squash() * 10 == 11) {
auto prev_val = det.getComparatorDisableTime();
{
std::ostringstream oss;
caller.call("compdisabletime", {"125ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "compdisabletime 125ns\n");
}
{
std::ostringstream oss;
caller.call("compdisabletime", {}, -1, GET, oss);
REQUIRE(oss.str() == "compdisabletime 125ns\n");
}
{
std::ostringstream oss;
caller.call("compdisabletime", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "compdisabletime 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setComparatorDisableTime(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("compdisabletime", {}, -1, GET));
REQUIRE_THROWS(caller.call("compdisabletime", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::extrastoragecells", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash(
"inconsistent #additional storage cells to test");
{
std::ostringstream oss;
caller.call("extrastoragecells", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 1\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 15\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 0\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {}, -1, GET, oss);
REQUIRE(oss.str() == "extrastoragecells 0\n");
}
REQUIRE_THROWS(caller.call("extrastoragecells", {"16"}, -1, PUT));
det.setNumberOfAdditionalStorageCells(prev_val);
}
// chip version 1.1
else {
// cannot set number of addl. storage cells
REQUIRE_THROWS(caller.call("extrastoragecells", {"1"}, -1, PUT));
}
} else {
REQUIRE_THROWS(caller.call("extrastoragecells", {}, -1, GET));
REQUIRE_THROWS(caller.call("extrastoragecells", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::storagecell_start", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getStorageCellStart();
{
std::ostringstream oss;
caller.call("storagecell_start", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 1\n");
}
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
std::ostringstream oss;
caller.call("storagecell_start", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 15\n");
}
// chip version 1.1
else {
// max is 3
REQUIRE_THROWS(caller.call("storagecell_start", {"15"}, -1, PUT));
std::ostringstream oss;
caller.call("storagecell_start", {"3"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 3\n");
}
{
std::ostringstream oss;
caller.call("storagecell_start", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 0\n");
}
{
std::ostringstream oss;
caller.call("storagecell_start", {}, -1, GET, oss);
REQUIRE(oss.str() == "storagecell_start 0\n");
}
REQUIRE_THROWS(caller.call("storagecell_start", {"16"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setStorageCellStart(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("storagecell_start", {}, -1, GET));
REQUIRE_THROWS(caller.call("storagecell_start", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::storagecell_delay", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
auto prev_val = det.getStorageCellDelay();
{
std::ostringstream oss;
caller.call("storagecell_delay", {"1.62ms"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_delay 1.62ms\n");
}
{
std::ostringstream oss;
caller.call("storagecell_delay", {}, -1, GET, oss);
REQUIRE(oss.str() == "storagecell_delay 1.62ms\n");
}
{
std::ostringstream oss;
caller.call("storagecell_delay", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_delay 0\n");
}
REQUIRE_THROWS(
caller.call("storagecell_delay", {"1638376ns"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setStorageCellDelay(prev_val[i], {i});
}
}
// chip version 1.1
else {
// cannot set storage cell delay
REQUIRE_THROWS(
caller.call("storagecell_delay", {"1.62ms"}, -1, PUT));
}
} else {
REQUIRE_THROWS(caller.call("storagecell_delay", {}, -1, GET));
REQUIRE_THROWS(caller.call("storagecell_delay", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::gainmode", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getGainMode();
{
std::ostringstream oss;
caller.call("gainmode", {"forceswitchg1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode forceswitchg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "gainmode forceswitchg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"dynamic"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode dynamic\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"forceswitchg2"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode forceswitchg2\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg2"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg2\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setGainMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gainmode", {}, -1, GET));
}
}
TEST_CASE("Caller::filtercells", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.1
if (det.getChipVersion().squash() * 10 == 11) {
auto prev_val = det.getNumberOfFilterCells();
{
std::ostringstream oss;
caller.call("filtercells", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 1\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {"12"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 12\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 0\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {}, -1, GET, oss);
REQUIRE(oss.str() == "filtercells 0\n");
}
REQUIRE_THROWS(caller.call("filtercells", {"13"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setNumberOfFilterCells(prev_val[i], {i});
}
}
// chip version 1.0
else {
// cannot set/get filter cell
REQUIRE_THROWS(caller.call("filtercells", {"1"}, -1, PUT));
REQUIRE_THROWS(caller.call("filtercells", {}, -1, GET));
}
} else {
REQUIRE_THROWS(caller.call("filtercells", {}, -1, GET));
REQUIRE_THROWS(caller.call("filtercells", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::pedestalmode", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getPedestalMode();
auto prev_frames = det.getNumberOfFrames().tsquash(
"Inconsistent number of frames to test");
auto prev_triggers = det.getNumberOfTriggers().tsquash(
"Inconsistent number of triggers to test");
auto prev_timingmode =
det.getTimingMode().tsquash("Inconsistent timing mode to test");
REQUIRE_NOTHROW(caller.call("pedestalmode", {}, 0, GET));
REQUIRE_NOTHROW(caller.call("pedestalmode", {}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"0"}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"256", "10"}, -1, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"-1", "10"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"20", "65536"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"20", "-1"}, 0, PUT));
{
std::ostringstream oss;
caller.call("pedestalmode", {"30", "1000"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [30, 1000]\n");
}
// cannot change any of these in pedestal mode
REQUIRE_THROWS_WITH(caller.call("frames", {"200"}, -1, PUT),
"Detector returned: Cannot set frames in pedestal "
"mode. It is overwritten anyway.\n");
REQUIRE_THROWS_WITH(caller.call("triggers", {"200"}, -1, PUT),
"Detector returned: Cannot set triggers in "
"pedestal mode. It is overwritten anyway.\n");
REQUIRE_THROWS_WITH(
caller.call("timing", {"auto"}, -1, PUT),
"Detector returned: Cannot set timing mode in pedestal mode. "
"Switch off pedestal mode to change timing mode.\n");
REQUIRE_THROWS_WITH(
caller.call("scan", {"vb_comp", "500", "1500", "10"}, -1, PUT),
"Detector returned: Cannot set scan when in pedestal mode.\n");
REQUIRE_THROWS_WITH(
caller.call("scan", {"0"}, -1, PUT),
"Detector returned: Cannot set scan when in pedestal mode.\n");
// should not throw to get these values though
REQUIRE_NOTHROW(caller.call("frames", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("triggers", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("timing", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("scan", {}, -1, GET));
{
std::ostringstream oss;
caller.call("pedestalmode", {"50", "500"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [50, 500]\n");
}
{
std::ostringstream oss;
caller.call("pedestalmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "pedestalmode [enabled, 50, 500]\n");
}
{
auto pedemode = det.getPedestalMode().tsquash(
"Inconsistent pedestal mode to test");
REQUIRE(pedemode.enable == true);
REQUIRE(pedemode.frames == 50);
REQUIRE(pedemode.loops == 500);
}
{
std::ostringstream oss;
caller.call("pedestalmode", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [0]\n");
}
{
std::ostringstream oss;
caller.call("pedestalmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "pedestalmode [disabled]\n");
}
uint8_t pedestalFrames = 50;
uint16_t pedestalLoops = 1000;
int64_t expNumFrames = pedestalFrames * pedestalLoops * 2;
auto origFrames = det.getNumberOfFrames().squash(-1);
auto origTriggers = det.getNumberOfTriggers().squash(-1);
// auto mode
det.setTimingMode(defs::AUTO_TIMING);
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
auto numTriggers = det.getNumberOfTriggers().squash(-1);
auto numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == expNumFrames);
REQUIRE(numTriggers == 1);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
// trigger mode (frames > 1)
REQUIRE_NOTHROW(det.setTimingMode(defs::TRIGGER_EXPOSURE));
origFrames = 5;
REQUIRE_NOTHROW(det.setNumberOfFrames(origFrames));
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == expNumFrames);
REQUIRE(numTriggers == 1);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
// trigger mode (frames = 1)
origFrames = 1;
REQUIRE_NOTHROW(det.setNumberOfFrames(origFrames));
origTriggers = 10;
REQUIRE_NOTHROW(det.setNumberOfTriggers(origTriggers));
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == 1);
REQUIRE(numTriggers == expNumFrames);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
det.setNumberOfFrames(prev_frames);
det.setNumberOfTriggers(prev_triggers);
det.setTimingMode(prev_timingmode);
for (int i = 0; i != det.size(); ++i) {
det.setPedestalMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("pedestalmode", {}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::sync", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getSynchronization().tsquash(
"inconsistent synchronization to test");
{
std::ostringstream oss;
caller.call("sync", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "sync 0\n");
}
{
std::ostringstream oss;
caller.call("sync", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "sync 1\n");
}
// setting to master or slave when synced
{
// get previous master
int prevMaster = 0;
auto previous = det.getMaster();
for (int i = 0; i != det.size(); ++i) {
if (previous[i] == 1) {
prevMaster = i;
break;
}
}
caller.call("master", {"1"}, 0, PUT);
caller.call("master", {"0"}, 0, PUT);
std::ostringstream oss;
caller.call("status", {}, -1, GET, oss);
REQUIRE(oss.str() != "status running\n");
// set all to slaves, and then master
for (int i = 0; i != det.size(); ++i) {
det.setMaster(0, {i});
}
det.setMaster(1, prevMaster);
}
{
std::ostringstream oss;
caller.call("sync", {}, -1, GET, oss);
REQUIRE(oss.str() == "sync 1\n");
}
// setting sync when running
{
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode in test");
auto prev_frames =
det.getNumberOfFrames().tsquash("inconsistent #frames in test");
auto prev_exptime =
det.getExptime().tsquash("inconsistent exptime in test");
auto prev_period =
det.getPeriod().tsquash("inconsistent period in test");
det.setTimingMode(defs::AUTO_TIMING);
det.setNumberOfFrames(10000);
det.setExptime(std::chrono::microseconds(200));
det.setPeriod(std::chrono::milliseconds(1000));
det.setSynchronization(1);
det.startDetector();
REQUIRE_THROWS(caller.call("sync", {"0"}, -1, PUT));
{
std::ostringstream oss;
caller.call("sync", {}, -1, GET, oss);
REQUIRE(oss.str() == "sync 1\n");
}
det.stopDetector();
det.setTimingMode(prev_timing);
det.setNumberOfFrames(prev_frames);
det.setExptime(prev_exptime);
det.setPeriod(prev_period);
}
det.setSynchronization(prev_val);
} else {
REQUIRE_THROWS(caller.call("sync", {}, -1, GET));
REQUIRE_THROWS(caller.call("sync", {"0"}, -1, PUT));
}
}
} // namespace sls