diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 8a04a035c..e24eee0d4 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1270,26 +1270,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - // validate min value - if (dacval < 0 && dacval != LTC2620_GetPowerDownValue()) { - sprintf(mess, - "Could not set DAC %d. Input value %d must be positive or %d\n", - ind, dacval, LTC2620_GetPowerDownValue()); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_GetMaxInput()) { - sprintf(mess, - "Could not set DAC %d. Input value %d exceeds maximum %d \n", - ind, dacval, LTC2620_GetMaxInput()); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { // validate min value if (voltage < 0) { @@ -1428,7 +1408,6 @@ int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess) { int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { LOG(logINFO, ("Setting DAC %d: %d %s \n", ind, val, (mV ? "mV" : "dac units"))); - if (validateDACIndex(ind, mess) == FAIL) return FAIL; @@ -1438,27 +1417,15 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { if (validateDACVoltage(ind, val, mess) == FAIL) return FAIL; } - if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL) return FAIL; } - - if (writeDACSpi(ind, dacval, mess) == FAIL) - return FAIL; - - return OK; -} - -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) - return FAIL; - - if (LTC2620_SetDACValue((int)ind, dacval) == FAIL) { - sprintf(mess, "Could not set DAC %d.\n", ind); - LOG(logERROR, (mess)); - return FAIL; + { + char dacName[20] = {0}; + snprintf(dacName, sizeof(dacName), "dac %d", ind); + if (LTC2620_SetDacValue((int)ind, dacval, dacName, mess) == FAIL) + return FAIL; } - dacValues[ind] = dacval; return OK; } diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h index e9557376a..7b2a30716 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h @@ -128,7 +128,6 @@ int setADCVpp(int val, int mV, char *mess); int getADCVpp(int mV, int *retval, char *mess); int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); @@ -137,8 +136,6 @@ int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess); /** @param val value can be in mV or dac units */ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess); -/** @param dacval in dac units */ -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); int getVLimit(); int setVLimit(int val, char *mess); diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 448f3b0f0..b1896607f 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -1436,27 +1436,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - char *dacNames[] = {DAC_NAMES}; - // validate min value - if (dacval < 0) { - sprintf(mess, - "Could not set DAC %s. Input value %d cannot be negative\n", - dacNames[ind], dacval); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_MAX_VAL) { - sprintf(mess, - "Could not set DAC %s. Input value %d exceeds maximum %d \n", - dacNames[ind], dacval, LTC2620_MAX_VAL); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { char *dacNames[] = {DAC_NAMES}; // validate min value @@ -1535,11 +1514,9 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units"))); } - if (ind == E_VTHRESHOLD) { return setThresholdDACs(val, mV, mess); } - if (validateDACIndex(ind, mess) == FAIL) return FAIL; @@ -1547,21 +1524,10 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { if (mV) { if (validateDACVoltage(ind, val, mess) == FAIL) return FAIL; - if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL) return FAIL; } - if (writeDACSpi(ind, dacval, mess) == FAIL) - return FAIL; - - return OK; -} - -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) - return FAIL; - #ifdef VIRTUAL (detectorModules)->dacs[ind] = dacval; return OK; diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h index 49e442770..1907f03be 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h @@ -125,7 +125,6 @@ int setThresholdEnergy(int ev); // parameters - dac, adc, hv int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); @@ -134,8 +133,6 @@ int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess); /** @param val value can be in mV or dac units */ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess); -/** @param dacval in dac units */ -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); int setThresholdDACs(int val, bool mV, char *mess); int getThresholdDACs(bool mV, int *retval, char *mess); diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 9092e63ba..15af49ac2 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -1530,27 +1530,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - char *dacNames[] = {DAC_NAMES}; - // validate min value - if (dacval < 0) { - sprintf(mess, - "Could not set DAC %s. Input value %d cannot be negative\n", - dacNames[ind], dacval); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_D_GetMaxInput()) { - sprintf(mess, - "Could not set DAC %s. Input value %d exceeds maximum %d \n", - dacNames[ind], dacval, LTC2620_D_GetMaxInput()); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { char *dacNames[] = {DAC_NAMES}; // validate min value @@ -1633,24 +1612,12 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL) return FAIL; } - - if (writeDACSpi(ind, dacval, mess) == FAIL) - return FAIL; - - return OK; -} - -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) - return FAIL; - - if (LTC2620_D_SetDACValue((int)ind, dacval) == FAIL) { + { char *dacNames[] = {DAC_NAMES}; - sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]); - LOG(logERROR, (mess)); - return FAIL; + if (LTC2620_D_SetDacValue((int)ind, dacval, dacNames[ind], mess) == + FAIL) + return FAIL; } - dacValues[ind] = dacval; return OK; } diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.h index 170a37dde..4f84a1307 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.h @@ -118,8 +118,6 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val); int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex); int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); -int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, @@ -127,8 +125,6 @@ int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess); /** @param val value can be in mV or dac units */ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess); -/** @param dacval in dac units */ -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); int getADC(enum ADCINDEX ind, int *value); int setHighVoltage(int val, char *mess); diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 42ba5a80c..8d0d1379f 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1345,27 +1345,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - char *dacNames[] = {DAC_NAMES}; - // validate min value - if (dacval < 0) { - sprintf(mess, - "Could not set DAC %s. Input value %d cannot be negative\n", - dacNames[ind], dacval); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_GetMaxInput()) { - sprintf(mess, - "Could not set DAC %s. Input value %d exceeds maximum %d \n", - dacNames[ind], dacval, LTC2620_GetMaxInput()); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { char *dacNames[] = {DAC_NAMES}; // validate min value @@ -1436,7 +1415,6 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units"))); } - if (validateDACIndex(ind, mess) == FAIL) return FAIL; @@ -1444,28 +1422,14 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { if (mV) { if (validateDACVoltage(ind, val, mess) == FAIL) return FAIL; - if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL) return FAIL; } - - if (writeDACSpi(ind, dacval, mess) == FAIL) - return FAIL; - - return OK; -} - -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) - return FAIL; - - if (LTC2620_SetDACValue((int)ind, dacval) == FAIL) { + { char *dacNames[] = {DAC_NAMES}; - sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]); - LOG(logERROR, (mess)); - return FAIL; + if (LTC2620_SetDacValue((int)ind, dacval, dacNames[ind], mess) == FAIL) + return FAIL; } - dacValues[ind] = dacval; // ext daq ctrl diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h index 5bb4bb2f9..b775ff0e1 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h @@ -124,7 +124,6 @@ void setGainMode(enum gainMode mode); // parameters - dac, adc, hv int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); @@ -133,8 +132,6 @@ int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess); /** @param val value can be in mV or dac units */ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess); -/** @param dacval in dac units */ -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); int getADC(enum ADCINDEX ind); int setHighVoltage(int val, char *mess); diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 46295c5cf..509c92a15 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -921,27 +921,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - char *dacNames[] = {DAC_NAMES}; - // validate min value - if (dacval < 0) { - sprintf(mess, - "Could not set DAC %s. Input value %d cannot be negative\n", - dacNames[ind], dacval); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_GetMaxInput()) { - sprintf(mess, - "Could not set DAC %s. Input value %d exceeds maximum %d \n", - dacNames[ind], dacval, LTC2620_GetMaxInput()); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { char *dacNames[] = {DAC_NAMES}; // validate min value @@ -1012,7 +991,6 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units"))); } - if (validateDACIndex(ind, mess) == FAIL) return FAIL; @@ -1020,28 +998,14 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { if (mV) { if (validateDACVoltage(ind, val, mess) == FAIL) return FAIL; - if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL) return FAIL; } - - if (writeDACSpi(ind, dacval, mess) == FAIL) - return FAIL; - - return OK; -} - -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) - return FAIL; - - if (LTC2620_SetDACValue((int)ind, dacval) == FAIL) { + { char *dacNames[] = {DAC_NAMES}; - sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]); - LOG(logERROR, (mess)); - return FAIL; + if (LTC2620_SetDacValue((int)ind, dacval, dacNames[ind], mess) == FAIL) + return FAIL; } - dacValues[ind] = dacval; return OK; } diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h index e25900b98..ef68e5685 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h @@ -117,7 +117,6 @@ enum detectorSettings getSettings(); // parameters - dac, adc, hv int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); @@ -126,8 +125,6 @@ int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess); /** @param val value can be in mV or dac units */ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess); -/** @param dacval in dac units */ -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); int getADC(enum ADCINDEX ind); int setHighVoltage(int val, char *mess); diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 958860caf..8bebc1c64 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index fb13ff0f8..5a2c179a4 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -1314,11 +1314,6 @@ int setModule(sls_detector_module myMod, char *mess) { // set to default (ensure counter check) if (setDAC((enum DACINDEX)i, myMod.dacs[i], false, true, mess) == FAIL) { - // dont complain if that counter was disabled - if ((i == M_VTH1 || i == M_VTH2 || i == M_VTH3) && - (detectorDacs[i] == DEFAULT_COUNTER_DISABLED_VTH_VAL)) { - continue; - } return FAIL; } } @@ -1549,27 +1544,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - char *dacNames[] = {DAC_NAMES}; - // validate min value - if (dacval < 0) { - sprintf(mess, - "Could not set DAC %s. Input value %d cannot be negative\n", - dacNames[ind], dacval); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_D_GetMaxInput()) { - sprintf(mess, - "Could not set DAC %s. Input value %d exceeds maximum %d \n", - dacNames[ind], dacval, LTC2620_D_GetMaxInput()); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { char *dacNames[] = {DAC_NAMES}; // validate min value @@ -1678,15 +1652,9 @@ int setDAC(enum DACINDEX ind, int val, bool mV, bool counterCheck, char *mess) { } int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) + char *dacNames[] = {DAC_NAMES}; + if (LTC2620_D_SetDacValue((int)ind, dacval, dacNames[ind], mess) == FAIL) return FAIL; - - if (LTC2620_D_SetDACValue((int)ind, dacval) == FAIL) { - char *dacNames[] = {DAC_NAMES}; - sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]); - LOG(logERROR, (mess)); - return FAIL; - } detectorDacs[ind] = dacval; // validate settings @@ -1699,16 +1667,23 @@ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { return OK; } -int getCounterIndex(enum DACINDEX ind) { +int getCounterIndexFromDacIndex(enum DACINDEX ind, int *retval_counterIndex, + char *mess) { switch (ind) { case M_VTH1: - return 0; + *retval_counterIndex = 0; + return OK; case M_VTH2: - return 1; + *retval_counterIndex = 1; + return OK; case M_VTH3: - return 2; + *retval_counterIndex = 2; + return OK; default: - return -1; + snprintf(mess, MAX_STR_LENGTH, + "Invalid DAC index %d for threshold DACs\n", ind); + LOG(logERROR, (mess)); + return FAIL; } } @@ -1717,12 +1692,9 @@ int setSingleThresholdDAC(enum DACINDEX ind, int val, bool mV, int dacval, char *dacNames[] = {DAC_NAMES}; uint32_t counterMask = getCounterMask(); - int iCounter = getCounterIndex(ind); - if (iCounter == -1) { - sprintf(mess, "Invalid DAC index %d for threshold DACs\n", ind); - LOG(logERROR, (mess)); + int iCounter; + if (getCounterIndexFromDacIndex(ind, &iCounter, mess) == FAIL) return FAIL; - } // if not disabled value, remember value if (mV || val != DEFAULT_COUNTER_DISABLED_VTH_VAL) { diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.h index 837ea37be..3775e928a 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.h @@ -135,7 +135,6 @@ void setThresholdEnergy(int counterIndex, int eV); // parameters - dac, adc, hv int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); @@ -147,7 +146,8 @@ int setDAC(enum DACINDEX ind, int val, bool mV, bool counterCheck, char *mess); /** @param dacval in dac units */ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); -int getCounterIndex(enum DACINDEX ind); +int getCounterIndexFromDacIndex(enum DACINDEX ind, int *retval_counterIndex, + char *mess); int setSingleThresholdDAC(enum DACINDEX ind, int val, bool mV, int dacval, bool counterCheck, char *mess); int setThresholdDACs(int val, bool mV, int dacval, char *mess); diff --git a/slsDetectorServers/slsDetectorServer/include/LTC2620.h b/slsDetectorServers/slsDetectorServer/include/LTC2620.h index 9534e1e09..24262fced 100644 --- a/slsDetectorServers/slsDetectorServer/include/LTC2620.h +++ b/slsDetectorServers/slsDetectorServer/include/LTC2620.h @@ -103,11 +103,11 @@ void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex); void LTC2620_Configure(); /** - * Set Dac (obtains dacaddr, command and ichip and calls LTC2620_Set) + * Sets the ichip, address and command, Calls LTC2620_Set) * @param dacnum dac number * @param data dac value to set */ void LTC2620_SetDAC(int dacnum, int data); -/** Set dac in dac units */ -int LTC2620_SetDACValue(int dacnum, int val); \ No newline at end of file +/** From */ +int LTC2620_SetDacValue(int dacnum, int val, char *dacname, char *mess); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h b/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h index 14c451147..c63c332e7 100644 --- a/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h +++ b/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h @@ -28,6 +28,4 @@ int LTC2620_D_VoltageToDac(int voltage, int *dacval); */ int LTC2620_D_DacToVoltage(int dacval, int *voltage); -/** - * Set value in dac */ -int LTC2620_D_SetDACValue(int dacnum, int val); \ No newline at end of file +int LTC2620_D_SetDacValue(int dacnum, int val, char *dacname, char *mess); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/LTC2620.c b/slsDetectorServers/slsDetectorServer/src/LTC2620.c index be0df9a48..2a62fa982 100644 --- a/slsDetectorServers/slsDetectorServer/src/LTC2620.c +++ b/slsDetectorServers/slsDetectorServer/src/LTC2620.c @@ -222,24 +222,35 @@ void LTC2620_SetDAC(int dacnum, int data) { LTC2620_Set(cmd, data, addr, ichip); } -int LTC2620_SetDACValue(int dacnum, int val) { - LOG(logDEBUG1, ("dacnum:%d, val:%d\n", dacnum, val)); +int LTC2620_SetDacValue(int dacnum, int val, char *dacname, char *mess) { + LOG(logDEBUG1, ("dacnum:%s [%d], val:%d\n", dacname, dacnum, val)); // validate index if (dacnum < 0 || dacnum >= LTC2620_Ndac) { - LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, - LTC2620_Ndac - 1)); + snprintf(mess, MAX_STR_LENGTH, "Could not set DAC. Invalid index %d\n", + dacnum); + LOG(logERROR, (mess)); return FAIL; } - - // validate value - if ((val < 0 && val != LTC2620_PWR_DOWN_VAL) || val > LTC2620_MAX_VAL) { - LOG(logERROR, ("Could not set DAC %d. Input value %d is out of bounds " - "(0 to %d)\n", - val, LTC2620_MAX_VAL)); + // validate min value + if (val < 0 && val != LTC2620_PWR_DOWN_VAL) { + snprintf( + mess, MAX_STR_LENGTH, + "Could not set DAC %s [%d]. Input value %d must be positive or %d " + "(power down)\n", + dacname, dacnum, val, LTC2620_PWR_DOWN_VAL); + LOG(logERROR, (mess)); return FAIL; } - - LOG(logINFO, ("\tSetting DAC %d: %d dac\n", dacnum, val)); + // validate maxvalue + if (val > LTC2620_MAX_VAL) { + snprintf( + mess, MAX_STR_LENGTH, + "Could not set DAC %s [%d]. Input value %d exceeds maximum %d.\n", + dacname, dacnum, val, LTC2620_MAX_VAL); + LOG(logERROR, (mess)); + return FAIL; + } + LOG(logINFO, ("\tSetting DAC %s [%d]: %d dac\n", dacname, dacnum, val)); #ifndef VIRTUAL LTC2620_SetDAC(dacnum, val); #endif diff --git a/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c b/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c index f093bae52..e08a98caf 100644 --- a/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c +++ b/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c @@ -58,60 +58,66 @@ int LTC2620_D_DacToVoltage(int dacval, int *voltage) { LTC2620_D_HardMaxVoltage, dacval, voltage); } -int LTC2620_D_SetDACValue(int dacnum, int val) { - LOG(logDEBUG1, ("dacnum:%d, val:%d\n", dacnum, val)); - +int LTC2620_D_SetDacValue(int dacnum, int val, char *dacname, char *mess) { + LOG(logDEBUG1, ("dacnum:%s [%d], val:%d\n", dacname, dacnum, val)); // validate index if (dacnum < 0 || dacnum >= LTC2620_D_NumDacs) { - LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, - LTC2620_D_NumDacs - 1)); + snprintf(mess, MAX_STR_LENGTH, "Could not set DAC. Invalid index %d\n", + dacnum); + LOG(logERROR, (mess)); return FAIL; } - - // validate value - if ((val < 0 && val != LTC2620_D_PWR_DOWN_VAL) || - val > LTC2620_D_MAX_DAC_VAL) { - LOG(logERROR, ("Could not set DAC %d. Input value %d is out of bounds " - "(0 to %d)\n", - val, LTC2620_D_MAX_DAC_VAL)); + // validate min value + if (val < 0 && val != LTC2620_D_PWR_DOWN_VAL) { + snprintf( + mess, MAX_STR_LENGTH, + "Could not set DAC %s [%d]. Input value %d must be positive or %d " + "(power down)\n", + dacname, dacnum, val, LTC2620_D_PWR_DOWN_VAL); + LOG(logERROR, (mess)); return FAIL; } - - LOG(logINFO, ("\tSetting DAC %d: %d dac\n", dacnum, val)); + // validate maxvalue + if (val > LTC2620_D_MAX_DAC_VAL) { + snprintf( + mess, MAX_STR_LENGTH, + "Could not set DAC %s [%d]. Input value %d exceeds maximum %d.\n", + dacname, dacnum, val, LTC2620_D_MAX_DAC_VAL); + LOG(logERROR, (mess)); + return FAIL; + } + LOG(logINFO, ("\tSetting DAC %s [%d]: %d dac\n", dacname, dacnum, val)); #ifdef VIRTUAL return OK; #else + // fname to write to char fname[MAX_STR_LENGTH]; memset(fname, 0, MAX_STR_LENGTH); char fnameFormat[MAX_STR_LENGTH]; memset(fnameFormat, 0, MAX_STR_LENGTH); strcpy(fnameFormat, LTC2620_D_DriverFileName); + sprintf(fname, "%s%d", fnameFormat, dacnum); #if defined(XILINX_CHIPTESTBOARDD) if (val == LTC2620_D_PWR_DOWN_VAL) { - LOG(logINFO, ("Powering down DAC %2d\n", dacnum)); strcpy(fnameFormat, LTC2620_D_PowerDownDriverFileName); + val = 1; //-100?:Invalid Argument } sprintf(fname, fnameFormat, dacnum); -#else - sprintf(fname, "%s%d", fnameFormat, dacnum); #endif LOG(logDEBUG1, ("fname %s\n", fname)); // open file FILE *fd = fopen(fname, "w"); if (fd == NULL) { - LOG(logERROR, ("Could not open file %s for writing to set dac %d\n", - fname, dacnum)); + snprintf(mess, MAX_STR_LENGTH, + "Could not open file %s for writing to set DAC %s[%d]\n", + fname, dacname, dacnum); + LOG(logERROR, (mess)); return FAIL; } -#ifdef XILINX_CHIPTESTBOARDD - if (val == LTC2620_D_PWR_DOWN_VAL) - fprintf(fd, "1\n"); //-100?:Invalid Argument - else -#endif - fprintf(fd, "%d\n", val); + fprintf(fd, "%d\n", val); fclose(fd); -#endif return OK; +#endif } diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 983cd2e5c..9b30ab682 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -1174,27 +1174,6 @@ int validateDACIndex(enum DACINDEX ind, char *mess) { return OK; } -int validateDACValue(enum DACINDEX ind, int dacval, char *mess) { - // validate min value - if (dacval < 0 && dacval != LTC2620_D_GetPowerDownValue()) { - sprintf( - mess, - "Could not set DAC %d. Input value %d must be positive or %d.\n", - ind, dacval, LTC2620_D_GetPowerDownValue()); - LOG(logERROR, (mess)); - return FAIL; - } - // validate max value - if (dacval > LTC2620_D_GetMaxInput()) { - sprintf(mess, - "Could not set DAC %d. Input value %d exceeds maximum %d \n", - ind, dacval, LTC2620_D_GetMaxInput()); - LOG(logERROR, (mess)); - return FAIL; - } - return OK; -} - int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) { // validate min value if (voltage < 0) { @@ -1305,7 +1284,6 @@ int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess) { int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { LOG(logINFO, ("Setting DAC %d: %d %s \n", ind, val, (mV ? "mV" : "dac units"))); - if (validateDACIndex(ind, mess) == FAIL) return FAIL; @@ -1315,27 +1293,15 @@ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) { if (validateDACVoltage(ind, val, mess) == FAIL) return FAIL; } - if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL) return FAIL; } - - if (writeDACSpi(ind, dacval, mess) == FAIL) - return FAIL; - - return OK; -} - -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) { - if (validateDACValue(ind, dacval, mess) == FAIL) - return FAIL; - - if (LTC2620_D_SetDACValue((int)ind, dacval) == FAIL) { - sprintf(mess, "Could not set DAC %d.\n", ind); - LOG(logERROR, (mess)); - return FAIL; + { + char dacName[20] = {0}; + snprintf(dacName, sizeof(dacName), "dac %d", ind); + if (LTC2620_D_SetDacValue((int)ind, dacval, dacName, mess) == FAIL) + return FAIL; } - dacValues[ind] = dacval; return OK; } diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h index cd779c0c2..64766d63e 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h @@ -121,7 +121,6 @@ int setModule(sls_detector_module myMod, char *mess); // parameters - dac, adc, hv int validateDACIndex(enum DACINDEX ind, char *mess); -int validateDACValue(enum DACINDEX ind, int dacval, char *mess); int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess); int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int *retval_dacval, char *mess); @@ -130,8 +129,6 @@ int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int *retval_voltage, int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess); /** @param val value can be in mV or dac units */ int setDAC(enum DACINDEX ind, int val, bool mV, char *mess); -/** @param dacval in dac units */ -int writeDACSpi(enum DACINDEX ind, int dacval, char *mess); int getVLimit(); int setVLimit(int val, char *mess); diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 41d63f2cd..d0508b375 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -9,4 +9,4 @@ #define APIEIGER "0.0.0 0x260217" #define APIXILINXCTB "0.0.0 0x260217" #define APIJUNGFRAU "0.0.0 0x260217" -#define APIMYTHEN3 "0.0.0 0x260217" +#define APIMYTHEN3 "0.0.0 0x260218"