From 55ee699d9c921aa844842cee912e107bf1893a12 Mon Sep 17 00:00:00 2001 From: marcofilho <marco.filho@ess.eu> Date: Wed, 8 Jan 2025 00:38:26 +0100 Subject: [PATCH] Add missing ADC parameters All parameters that share the same ADC are now added: Pulser, Threshold, Temperature and Bandgap. All except temperature are showing weird values though, so that needs to be investigated. I suspect something to do with configHybrid or configFE or configVmm, but I am not sure. --- vmmTblApp/Db/vmm.template | 63 ++++++++++++++++++++++++++-- vmmTblApp/src/Utils.cpp | 13 ++++++ vmmTblApp/src/Utils.h | 10 ++++- vmmTblApp/src/vmm_tbl.cpp | 87 +++++++++++++++++++++++++++++++++++---- vmmTblApp/src/vmm_tbl.h | 6 +++ 5 files changed, 168 insertions(+), 11 deletions(-) diff --git a/vmmTblApp/Db/vmm.template b/vmmTblApp/Db/vmm.template index 0e9b641..0555e8c 100644 --- a/vmmTblApp/Db/vmm.template +++ b/vmmTblApp/Db/vmm.template @@ -65,9 +65,9 @@ record(ai, "$(P)$(R)$(HYB)$(VMM)$(C)ADCVal-R"){ record(fanout, "$(P)$(R)$(HYB)$(VMM)$(C)#ADCParams") { field(LNK1, "$(P)$(R)$(HYB)$(VMM)$(C)Temp-R") - #Pulser... - #Bandgap... - #Threshold... + field(LNK2, "$(P)$(R)$(HYB)$(VMM)$(C)Bdg-R") + field(LNK3, "$(P)$(R)$(HYB)$(VMM)$(C)Thresh-R") + field(LNK4, "$(P)$(R)$(HYB)$(VMM)$(C)Pulser-R") } # Is updated only when AnalogMon = 67 and ADCVal is read @@ -87,4 +87,61 @@ record(waveform, "$(P)$(R)$(HYB)$(VMM)$(C)TempTmstp-R") { field(FTVL, "CHAR") field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_TMP_TMSTP") field(SCAN, "Passive") +} + +# Is updated only when AnalogMon = 66 and ADCVal is read +record(ai, "$(P)$(R)$(HYB)$(VMM)$(C)Bdg-R"){ + field(DESC, "Last read Bandgap") + field(DTYP, "asynInt32") + field(PINI, "YES") + field(SCAN, "Passive") + field(FLNK, "$(P)$(R)$(HYB)$(VMM)$(C)BdgTmstp-R") + field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_BDG") +} + +record(waveform, "$(P)$(R)$(HYB)$(VMM)$(C)BdgTmstp-R") { + field(DESC, "Timestamp from last bandgap read") + field(DTYP, "asynOctetRead") + field(NELM, "256") + field(FTVL, "CHAR") + field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_BDG_TMSTP") + field(SCAN, "Passive") +} + +# Is updated only when AnalogMon = 65 and ADCVal is read +record(ai, "$(P)$(R)$(HYB)$(VMM)$(C)Thresh-R"){ + field(DESC, "Last read Threshold") + field(DTYP, "asynInt32") + field(PINI, "YES") + field(SCAN, "Passive") + field(FLNK, "$(P)$(R)$(HYB)$(VMM)$(C)ThreshTmstp-R") + field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_THR") +} + +record(waveform, "$(P)$(R)$(HYB)$(VMM)$(C)ThreshTmstp-R") { + field(DESC, "Timestamp from last threshold read") + field(DTYP, "asynOctetRead") + field(NELM, "256") + field(FTVL, "CHAR") + field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_THR_TMSTP") + field(SCAN, "Passive") +} + +# Is updated only when AnalogMon = 64 and ADCVal is read +record(ai, "$(P)$(R)$(HYB)$(VMM)$(C)Pulser-R"){ + field(DESC, "Last read Pulser ADC") + field(DTYP, "asynInt32") + field(PINI, "YES") + field(SCAN, "Passive") + field(FLNK, "$(P)$(R)$(HYB)$(VMM)$(C)PulserTmstp-R") + field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_PLS") +} + +record(waveform, "$(P)$(R)$(HYB)$(VMM)$(C)PulserTmstp-R") { + field(DESC, "Timestamp from last pulser ADC read") + field(DTYP, "asynOctetRead") + field(NELM, "256") + field(FTVL, "CHAR") + field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))HYB_$(HYB)_$(VMM)_PLS_TMSTP") + field(SCAN, "Passive") } \ No newline at end of file diff --git a/vmmTblApp/src/Utils.cpp b/vmmTblApp/src/Utils.cpp index 9aa6371..7cf2ab3 100644 --- a/vmmTblApp/src/Utils.cpp +++ b/vmmTblApp/src/Utils.cpp @@ -58,4 +58,17 @@ int VecUtils::getIndex(std::vector<std::vector<int>>& vec, int function, int& hy } return 0; // Found exactly once +} + +/** + * @brief Converts a timestamp to a string. + */ +std::string TimeUtils::timeToStr(std::chrono::time_point<std::chrono::system_clock> timestamp){ + + std::time_t time_t_value = std::chrono::system_clock::to_time_t(timestamp); + std::tm tm_value = *std::localtime(&time_t_value); + std::ostringstream oss; + oss << std::put_time(&tm_value, "%Y-%m-%d %H:%M:%S"); + return oss.str(); + } \ No newline at end of file diff --git a/vmmTblApp/src/Utils.h b/vmmTblApp/src/Utils.h index 089bbea..0c48440 100644 --- a/vmmTblApp/src/Utils.h +++ b/vmmTblApp/src/Utils.h @@ -1,10 +1,18 @@ // Generic utilities for the module #include <vector> +#include <string> +#include <chrono> namespace VecUtils { int getIndex(std::vector<int> &, int function); int getIndex(std::vector<std::vector<int>> &, int function, int &hyb_index, int &vmm_index); -} // namespace VecUtils \ No newline at end of file +} // namespace VecUtils + +namespace TimeUtils { + +std::string timeToStr(std::chrono::time_point<std::chrono::system_clock> timestamp); + +} \ No newline at end of file diff --git a/vmmTblApp/src/vmm_tbl.cpp b/vmmTblApp/src/vmm_tbl.cpp index 76fca14..1a13acd 100644 --- a/vmmTblApp/src/vmm_tbl.cpp +++ b/vmmTblApp/src/vmm_tbl.cpp @@ -85,6 +85,30 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) { goto endOfReadInt32; } + param_index = VecUtils::getIndex(vmmBdg_, function, hyb_index, vmm_index); + if (param_index == 0) { + GenericParameter param_value; + result = this->pVmmAPI->getBandgap(hyb_index, vmm_index, param_value); + *value = param_value.value_int; + goto endOfReadInt32; + } + + param_index = VecUtils::getIndex(vmmThr_, function, hyb_index, vmm_index); + if (param_index == 0) { + GenericParameter param_value; + result = this->pVmmAPI->getThresholdADC(hyb_index, vmm_index, param_value); + *value = param_value.value_int; + goto endOfReadInt32; + } + + param_index = VecUtils::getIndex(vmmPls_, function, hyb_index, vmm_index); + if (param_index == 0) { + GenericParameter param_value; + result = this->pVmmAPI->getPulserADC(hyb_index, vmm_index, param_value); + *value = param_value.value_int; + goto endOfReadInt32; + } + endOfReadInt32: if (param_index < 0) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Failed to find parameter %d.\n", driverName, __FUNCTION__, @@ -177,13 +201,31 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value, size_t nChars, si if (param_index >= 0) { GenericParameter val; result = this->pVmmAPI->getTemperature(hyb_index, vmm_index, val); + read = TimeUtils::timeToStr(val.timestamp); + goto endOfReadOctet; + } + + param_index = VecUtils::getIndex(vmmBdgTmstp_, function, hyb_index, vmm_index); + if (param_index >= 0) { + GenericParameter val; + result = this->pVmmAPI->getBandgap(hyb_index, vmm_index, val); + read = TimeUtils::timeToStr(val.timestamp); + goto endOfReadOctet; + } - // Converting timestamp to string - std::time_t time_t_value = std::chrono::system_clock::to_time_t(val.timestamp); - std::tm tm_value = *std::localtime(&time_t_value); - std::ostringstream oss; - oss << std::put_time(&tm_value, "%Y-%m-%d %H:%M:%S"); - read = oss.str(); + param_index = VecUtils::getIndex(vmmThrTmstp_, function, hyb_index, vmm_index); + if (param_index >= 0) { + GenericParameter val; + result = this->pVmmAPI->getThresholdADC(hyb_index, vmm_index, val); + read = TimeUtils::timeToStr(val.timestamp); + goto endOfReadOctet; + } + + param_index = VecUtils::getIndex(vmmPlsTmstp_, function, hyb_index, vmm_index); + if (param_index >= 0) { + GenericParameter val; + result = this->pVmmAPI->getPulserADC(hyb_index, vmm_index, val); + read = TimeUtils::timeToStr(val.timestamp); goto endOfReadOctet; } @@ -247,7 +289,8 @@ asynStatus VMMTbl::createEpicsParams() { createParamAndStoreInVector("HYB_" + std::to_string(hyb) + key, typ, vec); } - std::vector<int> SC, SL, ST, STH, SM, SD, SMX, ADCIDX, ADCVAL, TEMP, TEMPTMSTP; + std::vector<int> SC, SL, ST, STH, SM, SD, SMX, ADCIDX, ADCVAL; + std::vector<int> TEMP, TEMPTMSTP, BDG, BDGTMPSTP, THR, THRTMPSTP, PLS, PLSTMPSTP; for (int vmm = 0; vmm < VMMS_PER_HYBRID; vmm++) { param_name.str(""); @@ -293,6 +336,30 @@ asynStatus VMMTbl::createEpicsParams() { param_name.str(""); param_name << "HYB_" << hyb << "_" << vmm << "_TMP_TMSTP"; createParamAndStoreInVector(param_name.str(), asynParamOctet, &TEMPTMSTP); + + param_name.str(""); + param_name << "HYB_" << hyb << "_" << vmm << "_BDG"; + createParamAndStoreInVector(param_name.str(), asynParamInt32, &BDG); + + param_name.str(""); + param_name << "HYB_" << hyb << "_" << vmm << "_BDG_TMSTP"; + createParamAndStoreInVector(param_name.str(), asynParamOctet, &BDGTMPSTP); + + param_name.str(""); + param_name << "HYB_" << hyb << "_" << vmm << "_THR"; + createParamAndStoreInVector(param_name.str(), asynParamInt32, &THR); + + param_name.str(""); + param_name << "HYB_" << hyb << "_" << vmm << "_THR_TMSTP"; + createParamAndStoreInVector(param_name.str(), asynParamOctet, &THRTMPSTP); + + param_name.str(""); + param_name << "HYB_" << hyb << "_" << vmm << "_PLS"; + createParamAndStoreInVector(param_name.str(), asynParamInt32, &PLS); + + param_name.str(""); + param_name << "HYB_" << hyb << "_" << vmm << "_PLS_TMSTP"; + createParamAndStoreInVector(param_name.str(), asynParamOctet, &PLSTMPSTP); } this->vmmSC_.push_back(SC); @@ -306,6 +373,12 @@ asynStatus VMMTbl::createEpicsParams() { this->vmmADCVAL_.push_back(ADCVAL); this->vmmTemp_.push_back(TEMP); this->vmmTempTmstp_.push_back(TEMPTMSTP); + this->vmmBdg_.push_back(BDG); + this->vmmBdgTmstp_.push_back(BDGTMPSTP); + this->vmmThr_.push_back(THR); + this->vmmThrTmstp_.push_back(THRTMPSTP); + this->vmmPls_.push_back(PLS); + this->vmmPlsTmstp_.push_back(PLSTMPSTP); } return asynSuccess; diff --git a/vmmTblApp/src/vmm_tbl.h b/vmmTblApp/src/vmm_tbl.h index fa7c468..ef5f37e 100644 --- a/vmmTblApp/src/vmm_tbl.h +++ b/vmmTblApp/src/vmm_tbl.h @@ -55,6 +55,12 @@ class VMMTbl : public asynPortDriver { std::vector<std::vector<int>> vmmADCVAL_; std::vector<std::vector<int>> vmmTemp_; std::vector<std::vector<int>> vmmTempTmstp_; + std::vector<std::vector<int>> vmmBdg_; + std::vector<std::vector<int>> vmmBdgTmstp_; + std::vector<std::vector<int>> vmmThr_; + std::vector<std::vector<int>> vmmThrTmstp_; + std::vector<std::vector<int>> vmmPls_; + std::vector<std::vector<int>> vmmPlsTmstp_; private: static constexpr const char *driverName = "VMMTbl"; -- GitLab