mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-06 09:22:26 +02:00
moench.wip
This commit is contained in:
@@ -1642,19 +1642,15 @@ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) {
|
||||
if (validateDACValue(ind, dacval, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
#ifdef VIRTUAL
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
#else
|
||||
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;
|
||||
}
|
||||
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value) {
|
||||
|
||||
Binary file not shown.
@@ -1457,16 +1457,13 @@ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) {
|
||||
if (validateDACValue(ind, dacval, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
#ifdef VIRTUAL
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
#else
|
||||
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;
|
||||
}
|
||||
|
||||
dacValues[ind] = dacval;
|
||||
|
||||
// ext daq ctrl
|
||||
@@ -1476,9 +1473,7 @@ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) {
|
||||
bus_w(addr, (bus_r(addr) | ((dacval << EXT_DAQ_CTRL_VREF_COMP_OFST) &
|
||||
EXT_DAQ_CTRL_VREF_COMP_MSK)));
|
||||
}
|
||||
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
@@ -540,7 +540,7 @@ int resetToDefaultDacs(int hardReset, char *mess) {
|
||||
for (int i = 0; i < NDAC; ++i) {
|
||||
int value = defaultDacValues[i];
|
||||
// set to defualt
|
||||
if (setDAC((enum DACINDEX)i, value, 0, mess) == FAIL)
|
||||
if (setDAC((enum DACINDEX)i, value, false, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
@@ -814,7 +814,7 @@ int setModule(sls_detector_module myMod, char *mess) {
|
||||
|
||||
// set dac values
|
||||
for (int i = 0; i < NDAC; ++i) {
|
||||
if (setDAC((enum DACINDEX)i, myMod.dacs[i], 0, mess) == FAIL)
|
||||
if (setDAC((enum DACINDEX)i, myMod.dacs[i], false, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
@@ -911,71 +911,130 @@ enum detectorSettings getSettings() {
|
||||
}
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
// validate index
|
||||
/* parameters - dac, adc, hv */
|
||||
int validateDACIndex(enum DACINDEX ind, char *mess) {
|
||||
if (ind < 0 || ind >= NDAC) {
|
||||
sprintf(mess, "Could not set DAC. Invalid index %d\n", ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate mV
|
||||
if (mV && val == LTC2620_GetPowerDownValue()) {
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Cannot use power down value and use 'mV'\n",
|
||||
dacNames[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate min value
|
||||
if (val < 0 && val != LTC2620_GetPowerDownValue()) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (mV && val > DAC_MAX_MV) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
|
||||
dacNames[ind], val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
} else if (!mV && val > LTC2620_GetMaxInput()) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d \n",
|
||||
dacNames[ind], val, LTC2620_GetMaxInput());
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
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 exceed 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
|
||||
if (voltage < 0) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], voltage);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (voltage > DAC_MAX_MV) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d mV exceed maximum %d mV\n", dacNames[ind], voltage, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int* retval_dacval, char *mess) {
|
||||
if (LTC2620_VoltageToDac(voltage, retval_dacval) == FAIL) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], voltage);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int* retval_voltage, char *mess) {
|
||||
*retval_voltage = -1;
|
||||
if (LTC2620_DacToVoltage(dacval, retval_voltage) == FAIL) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
sprintf(mess,
|
||||
"Could not get DAC %s. Could not convert %d dac units to mV\n",
|
||||
dacNames[ind], dacval);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess) {
|
||||
if (validateDACIndex(ind, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// mV: convert to dac value
|
||||
int dacval = val;
|
||||
int dacval = dacValues[ind];
|
||||
if (mV) {
|
||||
if (LTC2620_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
if (convertDACValueToVoltage(ind, dacval, retval, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
*retval = dacval;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) {
|
||||
{
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
}
|
||||
|
||||
if (validateDACIndex(ind, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
int dacval = val;
|
||||
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;
|
||||
@@ -985,34 +1044,6 @@ int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind >= NDAC) {
|
||||
sprintf(mess, "Could not get DAC %d. Invalid index.\n", ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
if (!mV) {
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
*retval = dacValues[ind];
|
||||
return OK;
|
||||
}
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_DacToVoltage(dacValues[ind], retval) == FAIL) {
|
||||
sprintf(mess,
|
||||
"Could not get DAC %s. Could not convert %d dac units to mV\n",
|
||||
dacNames[ind], dacValues[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
|
||||
dacValues[ind], *retval));
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getADC(enum ADCINDEX ind) {
|
||||
#ifdef VIRTUAL
|
||||
return 0;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <stdio.h> // FILE
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/****************************************************
|
||||
This functions are used by the slsDetectroServer_funcs interface.
|
||||
@@ -115,9 +116,17 @@ int setSettings(enum detectorSettings sett, char *mess);
|
||||
enum detectorSettings getSettings();
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, 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);
|
||||
int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int* retval_voltage, char *mess);
|
||||
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);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
@@ -1678,10 +1678,6 @@ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) {
|
||||
if (validateDACValue(ind, dacval, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
#ifdef VIRTUAL
|
||||
detectorDacs[ind] = dacval;
|
||||
return OK;
|
||||
#else
|
||||
if (LTC2620_D_SetDACValue((int)ind, dacval) == FAIL) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]);
|
||||
@@ -1698,7 +1694,6 @@ int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) {
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
int getCounterIndex (enum DACINDEX ind) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define APIRECEIVER "0.0.0 0x250822"
|
||||
#define APICTB "0.0.0 0x260210"
|
||||
#define APIGOTTHARD2 "0.0.0 0x260212"
|
||||
#define APIMOENCH "0.0.0 0x260210"
|
||||
#define APIMOENCH "0.0.0 0x260212"
|
||||
#define APIEIGER "0.0.0 0x260212"
|
||||
#define APIXILINXCTB "0.0.0 0x260210"
|
||||
#define APIJUNGFRAU "0.0.0 0x260212"
|
||||
|
||||
Reference in New Issue
Block a user