diff --git a/.clang-tidy b/.clang-tidy index 6e94d11e4..be4381b08 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -18,7 +18,8 @@ Checks: '*, -google-readability-todo, -google-readability-braces-around-statements, -modernize-use-trailing-return-type, - -readability-isolate-declaration' + -readability-isolate-declaration, + -llvmlibc-*' HeaderFilterRegex: \.h AnalyzeTemporaryDtors: false diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 9e558a235..e265814c7 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -354,9 +354,28 @@ void init_det(py::module &m) { py::arg(), py::arg() = Positions{}) .def("getDacList", (std::vector(Detector::*)() const) & Detector::getDacList) - .def("setDefaultDacs", - (void (Detector::*)(sls::Positions)) & Detector::setDefaultDacs, - py::arg() = Positions{}) + .def("getDefaultDac", + (Result(Detector::*)(defs::dacIndex, sls::Positions)) & + Detector::getDefaultDac, + py::arg(), py::arg() = Positions{}) + .def("setDefaultDac", + (void (Detector::*)(defs::dacIndex, int, sls::Positions)) & + Detector::setDefaultDac, + py::arg(), py::arg(), py::arg() = Positions{}) + .def("getDefaultDac", + (Result(Detector::*)(defs::dacIndex, defs::detectorSettings, + sls::Positions)) & + Detector::getDefaultDac, + py::arg(), py::arg(), py::arg() = Positions{}) + .def("setDefaultDac", + (void (Detector::*)(defs::dacIndex, int, defs::detectorSettings, + sls::Positions)) & + Detector::setDefaultDac, + py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) + .def("resetToDefaultDacs", + (void (Detector::*)(const bool, sls::Positions)) & + Detector::resetToDefaultDacs, + py::arg(), py::arg() = Positions{}) .def("getDAC", (Result(Detector::*)(defs::dacIndex, bool, sls::Positions) const) & @@ -923,6 +942,10 @@ void init_det(py::module &m) { sls::Positions)) & Detector::setDataStream, py::arg(), py::arg(), py::arg() = Positions{}) + .def("getChipVersion", + (Result(Detector::*)(sls::Positions) const) & + Detector::getChipVersion, + py::arg() = Positions{}) .def("getThresholdTemperature", (Result(Detector::*)(sls::Positions) const) & Detector::getThresholdTemperature, @@ -947,10 +970,6 @@ void init_det(py::module &m) { (void (Detector::*)(sls::Positions)) & Detector::resetTemperatureEvent, py::arg() = Positions{}) - .def("getChipVersion", - (Result(Detector::*)(sls::Positions) const) & - Detector::getChipVersion, - py::arg() = Positions{}) .def("getAutoCompDisable", (Result(Detector::*)(sls::Positions) const) & Detector::getAutoCompDisable, diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 469e14de9..284ac07a8 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -686,7 +686,7 @@ void allocateDetectorStructureMemory() { void setupDetector() { allocateDetectorStructureMemory(); - setDefaultDacs(); + resetToDefaultDacs(0); #ifdef VIRTUAL sharedMemory_setStatus(IDLE); #endif @@ -748,7 +748,15 @@ void setupDetector() { LOG(logDEBUG1, ("Setup detector done\n\n")); } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); for (int i = 0; i < NDAC; ++i) { diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 4c477828f..a71cbde0b 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -49,6 +49,7 @@ int highvoltage = 0; int dacValues[NDAC] = {}; int onChipdacValues[ONCHIP_NDAC][NCHIP] = {}; int defaultDacValues[NDAC] = {}; +int hardCodedDefaultDacValues[NDAC] = {}; int defaultOnChipdacValues[ONCHIP_NDAC][NCHIP] = {}; int injectedChannelsOffset = 0; int injectedChannelsIncrement = 0; @@ -393,6 +394,7 @@ void setupDetector() { memset(dacValues, 0, sizeof(dacValues)); for (int i = 0; i < NDAC; ++i) { defaultDacValues[i] = -1; + hardCodedDefaultDacValues[i] = -1; } for (int i = 0; i < ONCHIP_NDAC; ++i) { for (int j = 0; j < NCHIP; ++j) { @@ -481,7 +483,14 @@ void setupDetector() { setCurrentSource(DEFAULT_CURRENT_SOURCE); } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = hardCodedDefaultDacValues[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); for (int i = 0; i < NDAC; ++i) { @@ -831,6 +840,7 @@ int readConfigFile() { // set default dac variables defaultDacValues[idac] = value; + hardCodedDefaultDacValues[idac] = value; // set dac setDAC(idac, value, 0); diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index c78130e24..1f7e5104d 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -406,7 +406,7 @@ void setupDetector() { DAC_MAX_MV); LTC2620_Disable(); LTC2620_Configure(); - setDefaultDacs(); + resetToDefaultDacs(0); // temp bus_w(TEMP_SPI_IN_REG, TEMP_SPI_IN_IDLE_MSK); @@ -434,7 +434,15 @@ void setupDetector() { setDelayAfterTrigger(DEFAULT_DELAY); } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); for (int i = 0; i < NDAC; ++i) { diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index efd143ad4..f6d15482a 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -426,7 +426,7 @@ void setupDetector() { DAC_MAX_MV); LTC2620_Disable(); LTC2620_Configure(); - setDefaultDacs(); + resetToDefaultDacs(0); // altera pll ALTERA_PLL_SetDefines( @@ -470,18 +470,60 @@ void setupDetector() { setTemperatureEvent(0); } -int setDefaultDacs() { - int ret = OK; - LOG(logINFOBLUE, ("Setting Default Dac values\n")); +int resetToDefaultDacs(int hardReset) { + LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n", + (hardReset == 1 ? "hard" : ""))); + + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + const int vals_G0[] = SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_G0[i] = vals_G0[i]; + } + const int vals_HG0[] = SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_HG0[i] = vals_HG0[i]; + } + } + + // remember settings + enum detectorSettings oldSettings = thisSettings; + + // reset dacs to defaults + const int specialDacs[] = SPECIALDACINDEX; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultDacValues[i], 0); - if (dacValues[i] != defaultDacValues[i]) { - ret = FAIL; + int value = defaultDacValues[i]; + + for (int j = 0; j < NSPECIALDACS; ++j) { + // special dac: replace default value + if (specialDacs[j] == i) { + switch (oldSettings) { + case DYNAMICGAIN: + value = defaultDacValue_G0[j]; + break; + case DYNAMICHG0: + value = defaultDacValue_HG0[j]; + break; + default: + break; + } + break; + } + } + + // set to defualt + setDAC((enum DACINDEX)i, value, 0); + if (dacValues[i] != value) { LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultDacValues[i], dacValues[i])); + value, dacValues[i])); + return FAIL; } } - return ret; + return OK; } int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, @@ -999,24 +1041,24 @@ void validateSettings() { // if any special dac value is changed individually => undefined const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; int *specialDacValues[] = {defaultDacValue_G0, defaultDacValue_HG0}; - int settList[NUMSETTINGS] = {DYNAMICGAIN, DYNAMICHG0}; - enum detectorSettings sett = UNDEFINED; - for (int isett = 0; isett != NUMSETTINGS; ++isett) { + int settList[] = {DYNAMICGAIN, DYNAMICHG0}; + enum detectorSettings sett = UNDEFINED; + for (int isett = 0; isett != NUMSETTINGS; ++isett) { - // assume it matches current setting in list - sett = settList[isett]; - // if one value does not match, = undefined - for (int i = 0; i < NSPECIALDACS; ++i) { - if (getDAC(specialDacs[i], 0) != specialDacValues[isett][i]) { - sett = UNDEFINED; - break; - } - } + // assume it matches current setting in list + sett = settList[isett]; + // if one value does not match, = undefined + for (int i = 0; i < NSPECIALDACS; ++i) { + if (getDAC(specialDacs[i], 0) != specialDacValues[isett][i]) { + sett = UNDEFINED; + break; + } + } - // all values matchd a setting - if (sett != UNDEFINED) { - break; - } + // all values matchd a setting + if (sett != UNDEFINED) { + break; + } } // update settings if (thisSettings != sett) { diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 67db5dada..6a24aaa2a 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -517,7 +517,7 @@ void setupDetector() { DAC_MAX_MV); // has to be before setvchip LTC2620_Disable(); LTC2620_Configure(); - setDefaultDacs(); + resetToDefaultDacs(0); // altera pll ALTERA_PLL_SetDefines(PLL_CNTRL_REG, PLL_PARAM_REG, @@ -614,7 +614,15 @@ void updateDataBytes() { dataBytes = analogDataBytes; } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); for (int i = 0; i < NDAC; ++i) { diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 3dd83bb0f..d498614b5 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -42,7 +42,7 @@ pthread_t pthread_virtual_tid; int64_t virtual_currentFrameNumber = 2; #endif -enum detectorSettings thisSettings; +enum detectorSettings thisSettings = UNINITIALIZED; sls_detector_module *detectorModules = NULL; int *detectorChans = NULL; int *detectorDacs = NULL; @@ -450,7 +450,7 @@ void setupDetector() { // defaults setHighVoltage(DEFAULT_HIGH_VOLTAGE); - setDefaultDacs(); + resetToDefaultDacs(0); setASICDefaults(); setADIFDefaults(); @@ -527,20 +527,67 @@ void setupDetector() { setAllTrimbits(DEFAULT_TRIMBIT_VALUE); } -int setDefaultDacs() { - int ret = OK; - LOG(logINFOBLUE, ("Setting Default Dac values\n")); - { +int resetToDefaultDacs(int hardReset) { + LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n", + (hardReset == 1 ? "hard" : ""))); + + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultDacValues[i], 0); - if (detectorDacs[i] != defaultDacValues[i]) { - ret = FAIL; - LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultDacValues[i], detectorDacs[i])); + defaultDacValues[i] = vals[i]; + } + const int vals_standard[] = SPECIAL_DEFAULT_STANDARD_DAC_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_standard[i] = vals_standard[i]; + } + const int vals_fast[] = SPECIAL_DEFAULT_FAST_DAC_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_fast[i] = vals_fast[i]; + } + const int vals_highgain[] = SPECIAL_DEFAULT_HIGHGAIN_DAC_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_highgain[i] = vals_highgain[i]; + } + } + + // remember settings + enum detectorSettings oldSettings = thisSettings; + + // reset dacs to defaults + const int specialDacs[] = SPECIALDACINDEX; + for (int i = 0; i < NDAC; ++i) { + int value = defaultDacValues[i]; + + for (int j = 0; j < NSPECIALDACS; ++j) { + // special dac: replace default value + if (specialDacs[j] == i) { + switch (oldSettings) { + case STANDARD: + value = defaultDacValue_standard[j]; + break; + case FAST: + value = defaultDacValue_fast[j]; + break; + case HIGHGAIN: + value = defaultDacValue_highgain[j]; + break; + default: + break; + } + break; } } + + // set to defualt + setDAC((enum DACINDEX)i, value, 0); + if (detectorDacs[i] != value) { + LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, + value, detectorDacs[i])); + return FAIL; + } } - return ret; + return OK; } int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, @@ -1321,7 +1368,7 @@ void validateSettings() { const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; int *specialDacValues[] = {defaultDacValue_standard, defaultDacValue_fast, defaultDacValue_highgain}; - int settList[NUMSETTINGS] = {STANDARD, FAST, HIGHGAIN}; + int settList[] = {STANDARD, FAST, HIGHGAIN}; enum detectorSettings sett = UNDEFINED; for (int isett = 0; isett != NUMSETTINGS; ++isett) { diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 066f73132..6edd11497 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -117,7 +117,7 @@ void updateDataBytes(); #endif #ifndef CHIPTESTBOARDD -int setDefaultDacs(); +int resetToDefaultDacs(int hardReset); int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval); int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value); #endif diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index cf96c4b07..9313284af 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -239,7 +239,7 @@ int reconfigure_udp(int); int validate_udp_configuration(int); int get_bursts_left(int); int start_readout(int); -int set_default_dacs(int); +int reset_to_default_dacs(int); int is_virtual(int); int get_pattern(int); int load_default_pattern(int); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 9751877d1..93cdff606 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -364,7 +364,7 @@ void function_table() { flist[F_VALIDATE_UDP_CONFIG] = &validate_udp_configuration; flist[F_GET_BURSTS_LEFT] = &get_bursts_left; flist[F_START_READOUT] = &start_readout; - flist[F_SET_DEFAULT_DACS] = &set_default_dacs; + flist[F_RESET_TO_DEFAULT_DACS] = &reset_to_default_dacs; flist[F_IS_VIRTUAL] = &is_virtual; flist[F_GET_PATTERN] = &get_pattern; flist[F_LOAD_DEFAULT_PATTERN] = &load_default_pattern; @@ -1627,7 +1627,7 @@ int set_settings(int file_des) { validate(&ret, mess, (int)isett, (int)retval, "set settings", DEC); #ifdef GOTTHARDD if (ret == OK) { - ret = setDefaultDacs(); + ret = resetToDefaultDacs(0); if (ret == FAIL) { strcpy(mess, "Could change settings, but could not set to " "default dacs\n"); @@ -8090,17 +8090,22 @@ int start_readout(int file_des) { return Server_SendResult(file_des, INT32, NULL, 0); } -int set_default_dacs(int file_des) { +int reset_to_default_dacs(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); + int arg = -1; + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Resetting dacs to defaults (hard reset: %d)\n", arg)); #ifdef CHIPTESTBOARDD functionNotImplemented(); #else if (Server_VerifyLock() == OK) { - if (setDefaultDacs() == FAIL) { + if (resetToDefaultDacs(arg) == FAIL) { ret = FAIL; - strcpy(mess, "Could not set default dacs"); + sprintf(mess, "Could not %s reset default dacs", + (arg == 1 ? "hard" : "")); LOG(logERROR, (mess)); } } diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 59abaf190..15d241578 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -427,8 +427,10 @@ class Detector { void setDefaultDac(defs::dacIndex index, int defaultValue, defs::detectorSettings sett, Positions pos = {}); - /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ - void setDefaultDacs(Positions pos = {}); + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] + reset to defaults, hardReset will reset to hardcoded defaults on on-board + server */ + void resetToDefaultDacs(const bool hardReset, Positions pos = {}); Result getDAC(defs::dacIndex index, bool mV = false, Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index a51bf437d..3f8b93659 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1095,6 +1095,37 @@ std::string CmdProxy::DacValues(int action) { return os.str(); } +std::string CmdProxy::ResetDacs(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[(optional) hard] " + "\n\t[Eiger][Jungfrau][Gotthard][Moench][Gotthard2][" + "Mythen3]Reset dac values to the defaults. A 'hard' optional " + "reset will reset the dacs to the hardcoded defaults in on-board " + "detector server." + << '\n'; + } else if (action == defs::GET_ACTION) { + throw sls::RuntimeError("Cannot get"); + } else if (action == defs::PUT_ACTION) { + bool hardReset = false; + if (args.size() == 1) { + if (args[0] != "hard") { + throw sls::RuntimeError("Unknown argument " + args[0] + + ". Did you mean hard?"); + } + hardReset = true; + } else if (args.size() > 1) { + WrongNumberOfParameters(1); + } + det->resetToDefaultDacs(hardReset, std::vector{det_id}); + os << "successful\n"; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + std::string CmdProxy::DefaultDac(int action) { std::ostringstream os; os << cmd << ' '; @@ -1111,10 +1142,12 @@ std::string CmdProxy::DefaultDac(int action) { if (args.size() == 2) { auto t = det->getDefaultDac( StringTo(args[0]), - sls::StringTo(args[1])); + sls::StringTo(args[1]), + std::vector{det_id}); os << args[0] << ' ' << args[1] << ' ' << OutString(t) << '\n'; } else { - auto t = det->getDefaultDac(StringTo(args[0])); + auto t = det->getDefaultDac(StringTo(args[0]), + std::vector{det_id}); os << args[0] << ' ' << OutString(t) << '\n'; } } else if (action == defs::PUT_ACTION) { @@ -1125,7 +1158,8 @@ std::string CmdProxy::DefaultDac(int action) { if (args.size() == 3) { det->setDefaultDac( StringTo(args[0]), StringTo(args[1]), - sls::StringTo(args[2])); + sls::StringTo(args[2]), + std::vector{det_id}); os << args[0] << ' ' << args[2] << ' ' << args[1] << '\n'; } else { det->setDefaultDac(StringTo(args[0]), diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index ced9be101..6575fcf24 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -671,6 +671,8 @@ class CmdProxy { {"vipre_cds", "dac"}, {"ibias_sfp", "dac"}, + {"defaultdacs", "resetdacs"}, + /* acquisition */ {"busy", "clearbusy"}, {"receiver", "rx_status"}, @@ -816,7 +818,7 @@ class CmdProxy { {"dac", &CmdProxy::Dac}, {"daclist", &CmdProxy::daclist}, {"dacvalues", &CmdProxy::DacValues}, - {"defaultdacs", &CmdProxy::defaultdacs}, + {"resetdacs", &CmdProxy::ResetDacs}, {"defaultdac", &CmdProxy::DefaultDac}, /* on chip dacs */ @@ -1095,6 +1097,7 @@ class CmdProxy { /* dacs */ std::string Dac(int action); std::string DacValues(int action); + std::string ResetDacs(int action); std::string DefaultDac(int action); /* acquisition */ std::string ReceiverStatus(int action); @@ -1383,10 +1386,6 @@ class CmdProxy { daclist, getDacList, "\n\tGets the list of commands for every dac for this detector."); - EXECUTE_SET_COMMAND(defaultdacs, setDefaultDacs, - "\n\t[Eiger][Jungfrau][Gotthard][Moench][Gotthard2][" - "Mythen3]Sets default dacs on to the detector."); - /* on chip dacs */ INTEGER_USER_IND_COMMAND( vchip_comp_fe, getOnChipDAC, setOnChipDAC, StringTo, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index a429cb446..7b397efa7 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -650,8 +650,8 @@ void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, -void Detector::setDefaultDacs(Positions pos) { - pimpl->Parallel(&Module::setDefaultDacs, pos); +void Detector::resetToDefaultDacs(const bool hardReset, Positions pos) { + pimpl->Parallel(&Module::resetToDefaultDacs, pos, hardReset); } Result Detector::getDAC(defs::dacIndex index, bool mV, diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index e06775498..bb46d9ee2 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -629,7 +629,10 @@ void Module::setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, return sendToDetector(F_SET_DEFAULT_DAC, args, nullptr); } -void Module::setDefaultDacs() { sendToDetector(F_SET_DEFAULT_DACS); } +void Module::resetToDefaultDacs(const bool hardReset) { + sendToDetector(F_RESET_TO_DEFAULT_DACS, static_cast(hardReset), + nullptr); +} void Module::setDAC(int val, dacIndex index, bool mV) { int args[]{static_cast(index), static_cast(mV), val}; diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f3fda46a1..2e7248120 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -152,7 +152,7 @@ class Module : public virtual slsDetectorDefs { slsDetectorDefs::detectorSettings sett); void setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, defs::detectorSettings sett); - void setDefaultDacs(); + void resetToDefaultDacs(const bool hardReset); int getDAC(dacIndex index, bool mV) const; void setDAC(int val, dacIndex index, bool mV); bool getPowerChip() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index ab769e71c..9219b26b3 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -227,6 +227,12 @@ TEST_CASE("settings", "[.cmd]") { REQUIRE_THROWS(proxy.Call("settings", {it}, -1, PUT)); } } + for (int i = 0; i != det.size(); ++i) { + if (prev_val[i] != defs::UNDEFINED && + prev_val[i] != defs::UNINITIALIZED) { + det.setSettings(prev_val[i], {i}); + } + } } TEST_CASE("threshold", "[.cmd]") { @@ -1466,16 +1472,25 @@ TEST_CASE("defaultdac", "[.cmd]") { } } -TEST_CASE("defaultdacs", "[.cmd]") { +TEST_CASE("resetdacs", "[.cmd]") { Detector det; CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); if (det_type != defs::CHIPTESTBOARD) { - REQUIRE_THROWS(proxy.Call("defaultdacs", {}, -1, GET)); - REQUIRE_NOTHROW(proxy.Call("defaultdacs", {}, -1, PUT)); + auto prev_val = det.getSettings(); + + REQUIRE_THROWS(proxy.Call("resetdacs", {}, -1, GET)); + REQUIRE_NOTHROW(proxy.Call("resetdacs", {}, -1, PUT)); + REQUIRE_NOTHROW(proxy.Call("resetdacs", {"hard"}, -1, PUT)); + + // settings should not change especially for jungfrau and m3 + auto next_val = det.getSettings(); + for (int i = 0; i != det.size(); ++i) { + REQUIRE(prev_val[i] == next_val[i]); + } } else { - REQUIRE_THROWS(proxy.Call("defaultdacs", {}, -1, GET)); - REQUIRE_THROWS(proxy.Call("defaultdacs", {}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("resetdacs", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("resetdacs", {}, -1, PUT)); } } diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 27d783094..db452dcf0 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -215,7 +215,7 @@ enum detFuncs { F_VALIDATE_UDP_CONFIG, F_GET_BURSTS_LEFT, F_START_READOUT, - F_SET_DEFAULT_DACS, + F_RESET_TO_DEFAULT_DACS, F_IS_VIRTUAL, F_GET_PATTERN, F_LOAD_DEFAULT_PATTERN, @@ -555,7 +555,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_VALIDATE_UDP_CONFIG: return "F_VALIDATE_UDP_CONFIG"; case F_GET_BURSTS_LEFT: return "F_GET_BURSTS_LEFT"; case F_START_READOUT: return "F_START_READOUT"; - case F_SET_DEFAULT_DACS: return "F_SET_DEFAULT_DACS"; + case F_RESET_TO_DEFAULT_DACS: return "F_RESET_TO_DEFAULT_DACS"; case F_IS_VIRTUAL: return "F_IS_VIRTUAL"; case F_GET_PATTERN: return "F_GET_PATTERN"; case F_LOAD_DEFAULT_PATTERN: return "F_LOAD_DEFAULT_PATTERN";