From 8afeb92a32738785ae2cce6937b882dc2444bb89 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 18 Mar 2026 16:07:21 +0100 Subject: [PATCH] wip --- slsDetectorSoftware/include/sls/Detector.h | 5 +- slsDetectorSoftware/src/Detector.cpp | 141 ++++++++++-------- slsDetectorSoftware/src/DetectorImpl.h | 9 ++ slsDetectorSoftware/src/Module.cpp | 31 +++- slsDetectorSoftware/src/Module.h | 11 +- .../include/sls/sls_detector_funcs.h | 11 +- 6 files changed, 138 insertions(+), 70 deletions(-) diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index bb400ba1c..e6a6d71fa 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1632,7 +1632,10 @@ class Detector { /** gets list of power enums */ std::vector getPowerList() const; - /** [CTB][Xilinx CTB] */ + /** [CTB] Options: V_POWE_A, V_POWER_B, V_POWER_C, + * V_POWER_D, V_POWER_IO, V_POWER_CHIP + * [Xilinx CTB] Options: V_POWE_A, V_POWER_B, V_POWER_C, + * V_POWER_D, V_POWER_IO */ int getPowerDAC(defs::powerIndex index) const; /** [CTB][Xilinx CTB] Options: V_POWE_A, V_POWER_B, V_POWER_C, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 801e470cc..1fe721df1 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2166,15 +2166,92 @@ Result Detector::getSYNCClock(Positions pos) const { return pimpl->Parallel(&Module::getClockFrequency, pos, defs::SYNC_CLOCK); } -std::vector Detector::getPowerList() const { +std::vector Detector::getPowerList() const { auto dettype = getDetectorType().squash(); if (dettype != defs::CHIPTESTBOARD && dettype != defs::XILINX_CHIPTESTBOARD) { throw RuntimeError("Power list not implemented for this detector"); } - return std::vector{defs::V_POWER_A, defs::V_POWER_B, - defs::V_POWER_C, defs::V_POWER_D, - defs::V_POWER_IO}; + return std::vector{defs::V_POWER_A, defs::V_POWER_B, + defs::V_POWER_C, defs::V_POWER_D, + defs::V_POWER_IO}; +} + +int Detector::getPowerDAC(defs::powerIndex index) const { + pimpl->verifyChipTestBoard(__func__); + return pimpl->Parallel(&Module::getPowerDac, {0}, index)[0]; +} + +void Detector::setPowerDAC(defs::powerIndex index, int value) { + pimpl->verifyChipTestBoard(__func__); + pimpl->Parallel(&Module::setPowerDac, {0}, index, value); +} + +bool Detector::isPowerEnabled(defs::powerIndex index) const { + pimpl->verifyChipTestBoard(__func__); + std::vector valid_indices = getPowerList(); + if (std::find(valid_indices.begin(), valid_indices.end(), index) == + valid_indices.end()) { + throw RuntimeError("Unknown Power Index " + std::to_string(index)); + } + return pimpl->Parallel(&Module::isPowerEnabled, {0}, index)[0]; +} + +void Detector::setPowerEnabled(const std::vector &indices, + bool enable) { + pimpl->verifyChipTestBoard(__func__); + if (indices.empty()) { + throw RuntimeError("No Power Index provided"); + } + std::vector valid_indices = getPowerList(); + for (const auto &index : indices) { + if (std::find(valid_indices.begin(), valid_indices.end(), index) == + valid_indices.end()) { + throw RuntimeError("Unknown Power Index " + std::to_string(index)); + } + } + pimpl->Parallel(&Module::setPowerEnabled, {0}, indices, enable); +} + +int Detector::getMeasuredPower(defs::powerIndex index) const { + pimpl->verifyChipTestBoard(__func__); + switch (index) { + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Power Index " + std::to_string(index)); + } + return pimpl->Parallel(&Module::getPowerADC, {0}, index)[0]; +} + +int Detector::getMeasuredCurrent(defs::powerIndex index) const { + pimpl->verifyChipTestBoard(__func__); + switch (index) { + case defs::I_POWER_A: + case defs::I_POWER_B: + case defs::I_POWER_C: + case defs::I_POWER_D: + case defs::I_POWER_IO: + break; + default: + throw RuntimeError("Unknown Current Index " + std::to_string(index)); + } + return pimpl->Parallel(&Module::getPowerADC, {0}, index)[0]; +} + +int Detector::getVoltageLimit() const { + pimpl->verifyChipTestBoard(__func__); + return pimpl->Parallel(&Module::getVoltageLimit, {0})[0]; +} + +void Detector::setVoltageLimit(int value) { + pimpl->verifyChipTestBoard(__func__); + pimpl->Parallel(&Module::setVoltageLimit, {0}, value); } std::vector Detector::getSlowADCList() const { @@ -2188,31 +2265,6 @@ std::vector Detector::getSlowADCList() const { defs::SLOW_ADC4, defs::SLOW_ADC5, defs::SLOW_ADC6, defs::SLOW_ADC7}; } -Result Detector::isPowerEnabled(defs::dacIndex index, - Positions pos) const { - std::vector valid_indices = getPowerList(); - if (std::find(valid_indices.begin(), valid_indices.end(), index) == - valid_indices.end()) { - throw RuntimeError("Unknown Power Index"); - } - return pimpl->Parallel(&Module::isPowerEnabled, pos, index); -} - -void Detector::setPowerEnabled(const std::vector &indices, - bool value, Positions pos) { - if (indices.empty()) { - throw RuntimeError("No Power Index provided"); - } - std::vector valid_indices = getPowerList(); - for (const auto &index : indices) { - if (std::find(valid_indices.begin(), valid_indices.end(), index) == - valid_indices.end()) { - throw RuntimeError("Unknown Power Index"); - } - } - pimpl->Parallel(&Module::setPowerEnabled, pos, indices, value); -} - Result Detector::getADCVpp(bool mV, Positions pos) const { return pimpl->Parallel(&Module::getDAC, pos, defs::ADC_VPP, mV); } @@ -2279,37 +2331,6 @@ void Detector::setDBITClock(int value_in_MHz, Positions pos) { value_in_MHz); } -Result Detector::getMeasuredPower(defs::dacIndex index, - Positions pos) const { - switch (index) { - case defs::V_POWER_A: - case defs::V_POWER_B: - case defs::V_POWER_C: - case defs::V_POWER_D: - case defs::V_POWER_IO: - case defs::V_POWER_CHIP: - break; - default: - throw RuntimeError("Unknown Power Index"); - } - return pimpl->Parallel(&Module::getADC, pos, index); -} - -Result Detector::getMeasuredCurrent(defs::dacIndex index, - Positions pos) const { - switch (index) { - case defs::I_POWER_A: - case defs::I_POWER_B: - case defs::I_POWER_C: - case defs::I_POWER_D: - case defs::I_POWER_IO: - break; - default: - throw RuntimeError("Unknown Current Index"); - } - return pimpl->Parallel(&Module::getADC, pos, index); -} - Result Detector::getSlowADC(defs::dacIndex index, Positions pos) const { if (index < defs::SLOW_ADC0 || index > defs::SLOW_ADC7) { throw RuntimeError("Unknown Slow ADC Index"); diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index 921623b32..bcd0f199d 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -188,6 +188,15 @@ class DetectorImpl : public virtual slsDetectorDefs { shm()->detType == defs::XILINX_CHIPTESTBOARD); } + inline void verifyChipTestBoard(const std::string &funcName) const { + if (!isChipTestBoard()) + throw RuntimeError(funcName + " is only valid for chip test board"); + if (size() != 1) + throw RuntimeError( + funcName + + " is only valid for single module setup (chip test board)."); + } + /** set acquiring flag in shared memory */ void setAcquiringFlag(bool flag); diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index bebf7e82d..88234b088 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -819,25 +819,46 @@ void Module::setPowerChip(bool on) { sendToDetector(F_POWER_CHIP, static_cast(on)); } -bool Module::isPowerEnabled(defs::dacIndex index) const { - return sendToDetector(F_GET_POWER, index); +int Module::getPowerDAC(defs::powerIndex index) const { + return sendToDetector(F_GET_POWER_DAC, static_cast(index)); } -void Module::setPowerEnabled(const std::vector &indices, - bool value) { +void Module::setPowerDAC(defs::powerIndex index, int value) { + int args[]{static_cast(index), value}; + sendToDetector(F_SET_POWER_DAC, args, nullptr); +} + +bool Module::isPowerEnabled(defs::powerIndex index) const { + return sendToDetector(F_GET_POWER, static_cast(index)); +} + +void Module::setPowerEnabled(const std::vector &indices, + bool enable) { auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_SET_POWER); client.setFnum(F_SET_POWER); int count = indices.size(); client.Send(count); client.Send(indices); - client.Send(static_cast(value)); + client.Send(static_cast(enable)); if (client.Receive() == FAIL) { throw DetectorError("Detector " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } } +int Module::getPowerADC(defs::powerIndex index) const { + return sendToDetector(F_GET_POWER_ADC, static_cast(index)); +} + +int Module::getVoltageLimit() const { + return sendToDetector(F_GET_VOLTAGE_LIMIT); +} + +void Module::setVoltageLimit(const int limit_in_mV) { + sendToDetector(F_SET_VOLTAGE_LIMIT, limit_in_mV, nullptr); +} + int Module::getImageTestMode() const { return sendToDetector(F_GET_IMAGE_TEST_MODE); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 181355edd..1f1f5c2e0 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -177,9 +177,14 @@ class Module : public virtual slsDetectorDefs { void setDAC(int val, dacIndex index, bool mV); bool getPowerChip() const; void setPowerChip(bool on); - bool isPowerEnabled(defs::dacIndex index) const; - void setPowerEnabled(const std::vector &indices, - bool value); + int getPowerDAC(defs::powerIndex index) const; + void setPowerDAC(defs::powerIndex index, int value); + bool isPowerEnabled(defs::powerIndex index) const; + void setPowerEnabled(const std::vector &indices, + bool enable); + int getPowerADC(defs::powerIndex index) const; + int getVoltageLimit() const; + void setVoltageLimit(const int limit_in_mV); int getImageTestMode() const; void setImageTestMode(const int value); /* temperature in millidegrees */ diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 761f78fb0..c2fd7eb82 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -303,6 +303,11 @@ enum detFuncs { F_SPI_WRITE, F_GET_POWER, F_SET_POWER, + F_GET_POWER_DAC, + F_SET_POWER_DAC, + F_GET_POWER_ADC, + F_GET_VOLTAGE_LIMIT, + F_SET_VOLTAGE_LIMIT, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 512, /**< detector function should not exceed this @@ -717,7 +722,11 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SPI_WRITE: return "F_SPI_WRITE"; case F_GET_POWER: return "F_GET_POWER"; case F_SET_POWER: return "F_SET_POWER"; - + case F_GET_POWER_DAC: return "F_GET_POWER_DAC"; + case F_SET_POWER_DAC: return "F_SET_POWER_DAC"; + case F_GET_POWER_ADC: return "F_GET_POWER_ADC"; + case F_GET_VOLTAGE_LIMIT: return "F_GET_VOLTAGE_LIMIT"; + case F_SET_VOLTAGE_LIMIT: return "F_SET_VOLTAGE_LIMIT"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";