diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index ccdfaae73..977752522 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 3006b0969..3e9038579 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 3b395f52e..469e14de9 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -93,6 +93,7 @@ int eiger_virtual_interrupt_subframe = 0; int eiger_virtual_left_datastream = 1; int eiger_virtual_right_datastream = 1; #endif +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; int isInitCheckDone() { return initCheckDone; } @@ -750,18 +751,42 @@ void setupDetector() { int setDefaultDacs() { int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if ((detectorModules)->dacs[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if ((detectorModules)->dacs[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], (detectorModules)->dacs[i])); + defaultDacValues[i], (detectorModules)->dacs[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + /* advanced read/write reg */ int writeRegister(uint32_t offset, uint32_t data) { #ifdef VIRTUAL diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index dabd39758..e0f737703 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 3dbb46900..4c477828f 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -515,6 +515,31 @@ int setDefaultDacs() { return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + int readConfigFile() { if (initError == FAIL) { diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index 90989277d..4abdc5355 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index eae7a7722..c78130e24 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -45,6 +45,7 @@ int detPos[2] = {}; int detectorFirstServer = 1; int dacValues[NDAC] = {}; +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; enum detectorSettings thisSettings = UNINITIALIZED; enum externalSignalFlag signalMode = 0; @@ -436,18 +437,42 @@ void setupDetector() { int setDefaultDacs() { int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (dacValues[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if (dacValues[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], dacValues[i])); + defaultDacValues[i], dacValues[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + uint32_t writeRegister16And32(uint32_t offset, uint32_t data) { if (((offset << MEM_MAP_SHIFT) == CONTROL_REG) || ((offset << MEM_MAP_SHIFT) == FIFO_DATA_REG)) { diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index fbc19fb66..12d73a801 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 56e2e8653..efd143ad4 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -43,6 +43,9 @@ int virtual_image_test_mode = 0; enum detectorSettings thisSettings = UNINITIALIZED; int highvoltage = 0; int dacValues[NDAC] = {}; +int defaultDacValues[] = DEFAULT_DAC_VALS; +int defaultDacValue_G0[] = SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS; +int defaultDacValue_HG0[] = SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS; int32_t clkPhase[NUM_CLOCKS] = {}; int detPos[4] = {}; int chipVersion = 10; // (1.0) @@ -470,18 +473,88 @@ void setupDetector() { int setDefaultDacs() { int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (dacValues[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if (dacValues[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], dacValues[i])); + defaultDacValues[i], dacValues[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case DYNAMICGAIN: + *retval = defaultDacValue_G0[i]; + return OK; + case DYNAMICHG0: + *retval = defaultDacValue_HG0[i]; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + char *dac_names[] = {DAC_NAMES}; + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case DYNAMICGAIN: + LOG(logINFO, + ("Setting Default Dac [%d - %s, dynamicgain]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_G0[i] = value; + return OK; + case DYNAMICHG0: + LOG(logINFO, + ("Setting Default Dac [%d - %s, dynamichg0]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_HG0[i] = value; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + int readConfigFile() { if (initError == FAIL) { @@ -884,8 +957,6 @@ enum detectorSettings setSettings(enum detectorSettings sett) { if (sett == UNINITIALIZED) return thisSettings; - int G0DacVals[] = SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS; - int HG0DacVals[] = SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS; int *dacVals = NULL; // set settings switch (sett) { @@ -893,14 +964,14 @@ enum detectorSettings setSettings(enum detectorSettings sett) { bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); LOG(logINFO, ("Set settings - Dyanmic Gain, DAQ Reg: 0x%x\n", bus_r(DAQ_REG))); - dacVals = G0DacVals; + dacVals = defaultDacValue_G0; break; case DYNAMICHG0: bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_HIGHGAIN_VAL); LOG(logINFO, ("Set settings - Dyanmic High Gain 0, DAQ Reg: 0x%x\n", bus_r(DAQ_REG))); - dacVals = HG0DacVals; + dacVals = defaultDacValue_HG0; break; default: LOG(logERROR, @@ -927,26 +998,25 @@ enum detectorSettings setSettings(enum detectorSettings sett) { void validateSettings() { // if any special dac value is changed individually => undefined const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; - int specialDacValues[NUMSETTINGS][NSPECIALDACS] = { - SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS, - SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS}; - int settList[NUMSETTINGS] = {DYNAMICGAIN, DYNAMICHG0}; + int *specialDacValues[] = {defaultDacValue_G0, defaultDacValue_HG0}; + int settList[NUMSETTINGS] = {DYNAMICGAIN, DYNAMICHG0}; + enum detectorSettings sett = UNDEFINED; + for (int isett = 0; isett != NUMSETTINGS; ++isett) { - enum detectorSettings sett = UNDEFINED; - for (int isett = 0; isett != NUMSETTINGS; ++isett) { - // dont overwrite if settings is correct - if (sett != UNDEFINED) { - break; - } - // assume it matches current setting in list - sett = settList[isett]; - for (int ival = 0; ival < NSPECIALDACS; ++ival) { - // if one value does not match, undefined - if (getDAC(specialDacs[ival], 0) != specialDacValues[isett][ival]) { - 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; + } } // update settings if (thisSettings != sett) { diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index 215b4752f..1feac6539 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 849e6b62c..67db5dada 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -61,6 +61,7 @@ uint8_t adcEnableMask_10g = 0; int32_t clkPhase[NUM_CLOCKS] = {}; uint32_t clkFrequency[NUM_CLOCKS] = {40, 20, 20, 200}; int dacValues[NDAC] = {}; +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; // software limit that depends on the current chip on the ctb int vLimit = 0; enum detectorSettings thisSettings = UNINITIALIZED; @@ -616,17 +617,40 @@ void updateDataBytes() { int setDefaultDacs() { int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (dacValues[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if (dacValues[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], dacValues[i])); + defaultDacValues[i], dacValues[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} /* firmware functions (resets) */ diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index fd9b15709..af77a2a5f 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 3da8bda2f..3dd83bb0f 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -47,6 +47,10 @@ sls_detector_module *detectorModules = NULL; int *detectorChans = NULL; int *detectorDacs = NULL; int *channelMask = NULL; +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; +int defaultDacValue_standard[] = SPECIAL_DEFAULT_STANDARD_DAC_VALS; +int defaultDacValue_fast[] = SPECIAL_DEFAULT_FAST_DAC_VALS; +int defaultDacValue_highgain[] = SPECIAL_DEFAULT_HIGHGAIN_DAC_VALS; int32_t clkPhase[NUM_CLOCKS] = {}; uint32_t clkDivider[NUM_CLOCKS] = {}; @@ -527,19 +531,98 @@ int setDefaultDacs() { int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); { - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (detectorDacs[i] != defaultvals[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, - defaultvals[i], detectorDacs[i])); + defaultDacValues[i], detectorDacs[i])); } } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case STANDARD: + *retval = defaultDacValue_standard[i]; + return OK; + case FAST: + *retval = defaultDacValue_fast[i]; + return OK; + case HIGHGAIN: + *retval = defaultDacValue_highgain[i]; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + char *dac_names[] = {DAC_NAMES}; + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case STANDARD: + LOG(logINFO, + ("Setting Default Dac [%d - %s, standard]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_standard[i] = value; + return OK; + case FAST: + LOG(logINFO, ("Setting Default Dac [%d - %s, fast]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_fast[i] = value; + return OK; + case HIGHGAIN: + LOG(logINFO, + ("Setting Default Dac [%d - %s, highgain]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_highgain[i] = value; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + + if (index < 0 || index >= NDAC) + return FAIL; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + void setASICDefaults() { uint32_t val = bus_r(ASIC_EXP_STATUS_REG); val &= (~ASIC_EXP_STAT_STO_LNGTH_MSK); @@ -1201,24 +1284,19 @@ int getAllTrimbits() { } enum detectorSettings setSettings(enum detectorSettings sett) { + int *dacVals = NULL; switch (sett) { case STANDARD: LOG(logINFOBLUE, ("Setting to standard settings\n")); - thisSettings = sett; - setDAC(M_VRPREAMP, DEFAULT_STANDARD_VRPREAMP, 0); - setDAC(M_VRSHAPER, DEFAULT_STANDARD_VRSHAPER, 0); + dacVals = defaultDacValue_standard; break; case FAST: LOG(logINFOBLUE, ("Setting to fast settings\n")); - thisSettings = sett; - setDAC(M_VRPREAMP, DEFAULT_FAST_VRPREAMP, 0); - setDAC(M_VRSHAPER, DEFAULT_FAST_VRSHAPER, 0); + dacVals = defaultDacValue_fast; break; case HIGHGAIN: LOG(logINFOBLUE, ("Setting to high gain settings\n")); - thisSettings = sett; - setDAC(M_VRPREAMP, DEFAULT_HIGHGAIN_VRPREAMP, 0); - setDAC(M_VRSHAPER, DEFAULT_HIGHGAIN_VRSHAPER, 0); + dacVals = defaultDacValue_highgain; break; default: LOG(logERROR, @@ -1226,34 +1304,54 @@ enum detectorSettings setSettings(enum detectorSettings sett) { return thisSettings; } + thisSettings = sett; + + // set special dacs + const int specialDacs[] = SPECIALDACINDEX; + for (int i = 0; i < NSPECIALDACS; ++i) { + setDAC(specialDacs[i], dacVals[i], 0); + } + LOG(logINFO, ("Settings: %d\n", thisSettings)); return thisSettings; } void validateSettings() { - if (detectorDacs[M_VRPREAMP] == DEFAULT_STANDARD_VRPREAMP && - detectorDacs[M_VRSHAPER] == DEFAULT_STANDARD_VRSHAPER) { - if (thisSettings != STANDARD) { - thisSettings = STANDARD; - LOG(logINFOBLUE, ("Validated Settings changed to standard!\n")); + // if any special dac value is changed individually => undefined + const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; + int *specialDacValues[] = {defaultDacValue_standard, defaultDacValue_fast, + defaultDacValue_highgain}; + int settList[NUMSETTINGS] = {STANDARD, FAST, HIGHGAIN}; + + 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; + } } - } else if (detectorDacs[M_VRPREAMP] == DEFAULT_FAST_VRPREAMP && - detectorDacs[M_VRSHAPER] == DEFAULT_FAST_VRSHAPER) { - if (thisSettings != FAST) { - thisSettings = FAST; - LOG(logINFOBLUE, ("Validated Settings changed to fast!\n")); + + // all values matchd a setting + if (sett != UNDEFINED) { + break; } - } else if (detectorDacs[M_VRPREAMP] == DEFAULT_HIGHGAIN_VRPREAMP && - detectorDacs[M_VRSHAPER] == DEFAULT_HIGHGAIN_VRSHAPER) { - if (thisSettings != HIGHGAIN) { - thisSettings = HIGHGAIN; - LOG(logINFOBLUE, ("Validated Settings changed to highgain!\n")); - } - } else { - thisSettings = UNDEFINED; - LOG(logWARNING, - ("Settings set to undefined [vrpreamp: %d, vrshaper: %d]\n", - detectorDacs[M_VRPREAMP], detectorDacs[M_VRSHAPER])); + } + // update settings + if (thisSettings != sett) { + LOG(logINFOBLUE, + ("Validated settings to %s (%d)\n", + (sett == STANDARD + ? "standard" + : (sett == FAST + ? "fast" + : (sett == HIGHGAIN ? "highgain" : "undefined"))), + sett)); + thisSettings = sett; } } @@ -1335,8 +1433,11 @@ void setGeneralDAC(enum DACINDEX ind, int val, int mV) { detectorDacs[ind] = dacval; } #endif - if (ind == M_VRPREAMP || ind == M_VRSHAPER) { - validateSettings(); + const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)ind == specialDacs[i]) { + validateSettings(); + } } } diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 35f53caef..8efa6ead6 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -42,13 +42,6 @@ #define DEFAULT_TRIMBIT_VALUE (0) #define DEFAULT_COUNTER_DISABLED_VTH_VAL (2800) -#define DEFAULT_STANDARD_VRPREAMP (1100) -#define DEFAULT_FAST_VRPREAMP (300) -#define DEFAULT_HIGHGAIN_VRPREAMP (1300) -#define DEFAULT_STANDARD_VRSHAPER (1280) -#define DEFAULT_FAST_VRSHAPER (1500) -#define DEFAULT_HIGHGAIN_VRSHAPER (1100) - #define DEFAULT_READOUT_C0 (10) //(100000000) // rdo_clk, 100 MHz #define DEFAULT_READOUT_C1 (10) //(100000000) // smp sample clk (x2), 100 MHz #define DEFAULT_SYSTEM_C0 (10) //(100000000) // run_clk, 100 MHz @@ -118,6 +111,17 @@ enum DACINDEX { 2800, /* vTrim */ \ 800 /* VdcSh */ \ }; + +#define NUMSETTINGS (3) +#define NSPECIALDACS (2) +#define SPECIALDACINDEX {M_VRPREAMP, M_VRSHAPER}; +#define SPECIAL_DEFAULT_STANDARD_DAC_VALS \ + { 1100, 1280 } +#define SPECIAL_DEFAULT_FAST_DAC_VALS \ + { 300, 1500 } +#define SPECIAL_DEFAULT_HIGHGAIN_DAC_VALS \ + { 1300, 1100 } + enum CLKINDEX { READOUT_C0, READOUT_C1, diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 63f53f69a..066f73132 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -118,6 +118,8 @@ void updateDataBytes(); #ifndef CHIPTESTBOARDD int setDefaultDacs(); +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval); +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value); #endif #ifdef MYTHEN3D void setASICDefaults(); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 05414d4e7..cf96c4b07 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -40,6 +40,7 @@ int get_adc(int); int write_register(int); int read_register(int); int set_module(int); +void validate_settings(enum detectorSettings sett); int set_settings(int); int get_threshold_energy(int); int acquire(int blocking, int file_des); @@ -254,3 +255,5 @@ int set_veto_stream(int); int get_veto_algorithm(int); int set_veto_algorithm(int); int get_chip_version(int); +int get_default_dac(int); +int set_default_dac(int); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 6dd36fd6d..9751877d1 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -380,6 +380,8 @@ void function_table() { flist[F_GET_VETO_ALGORITHM] = &get_veto_algorithm; flist[F_SET_VETO_ALGORITHM] = &set_veto_algorithm; flist[F_GET_CHIP_VERSION] = &get_chip_version; + flist[F_GET_DEFAULT_DAC] = &get_default_dac; + flist[F_SET_DEFAULT_DAC] = &set_default_dac; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -749,8 +751,6 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case IB_TESTC: serverDacIndex = G_IB_TESTC; break; - case HIGH_VOLTAGE: - break; #elif EIGERD case VTHRESHOLD: serverDacIndex = E_VTHRESHOLD; @@ -803,13 +803,7 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case VISHAPER: serverDacIndex = E_VISHAPER; break; - case HIGH_VOLTAGE: - case IO_DELAY: - break; #elif CHIPTESTBOARDD - case ADC_VPP: - case HIGH_VOLTAGE: - break; case V_POWER_A: serverDacIndex = D_PWR_A; break; @@ -828,8 +822,6 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case V_POWER_CHIP: serverDacIndex = D_PWR_CHIP; break; - case V_LIMIT: - break; #elif MOENCHD case VBP_COLBUF: serverDacIndex = MO_VBP_COLBUF; @@ -855,14 +847,7 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case IBIAS_SFP: serverDacIndex = MO_IBIAS_SFP; break; - case ADC_VPP: - case HIGH_VOLTAGE: - case V_LIMIT: - break; - #elif MYTHEN3D - case HIGH_VOLTAGE: - break; case VCASSH: serverDacIndex = M_VCASSH; break; @@ -1004,239 +989,256 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { int validateAndSetDac(enum dacIndex ind, int val, int mV) { int retval = -1; - enum DACINDEX serverDacIndex = getDACIndex(ind); + enum DACINDEX serverDacIndex = 0; - if (ret == OK) { - switch (ind) { - - // adc vpp -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - case ADC_VPP: - // set - if (val >= 0) { - ret = AD9257_SetVrefVoltage(val, mV); - if (ret == FAIL) { - sprintf(mess, "Could not set Adc Vpp. Please set a " - "proper value\n"); - LOG(logERROR, (mess)); - } - } - retval = AD9257_GetVrefVoltage(mV); - LOG(logDEBUG1, - ("Adc Vpp retval: %d %s\n", retval, (mV ? "mV" : "mode"))); - // cannot validate (its just a variable and mv gives different - // value) - break; -#endif - - // io delay + // valid enums + switch (ind) { + case HIGH_VOLTAGE: #ifdef EIGERD - case IO_DELAY: - retval = setIODelay(val); - LOG(logDEBUG1, ("IODelay: %d\n", retval)); - validate(&ret, mess, val, retval, "set iodelay", DEC); - break; + case IO_DELAY: +#elif CHIPTESTBOARDD + case ADC_VPP: + case V_LIMIT: +#elif MOENCHD + case ADC_VPP: + case V_LIMIT: +#endif + break; + default: + serverDacIndex = getDACIndex(ind); + break; + } + if (ret == FAIL) { + return retval; + } + switch (ind) { + // adc vpp +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + case ADC_VPP: + // set + if (val >= 0) { + ret = AD9257_SetVrefVoltage(val, mV); + if (ret == FAIL) { + sprintf(mess, "Could not set Adc Vpp. Please set a " + "proper value\n"); + LOG(logERROR, (mess)); + } + } + retval = AD9257_GetVrefVoltage(mV); + LOG(logDEBUG1, + ("Adc Vpp retval: %d %s\n", retval, (mV ? "mV" : "mode"))); + // cannot validate (its just a variable and mv gives different + // value) + break; #endif - // high voltage - case HIGH_VOLTAGE: - retval = setHighVoltage(val); - LOG(logDEBUG1, ("High Voltage: %d\n", retval)); + // io delay +#ifdef EIGERD + case IO_DELAY: + retval = setIODelay(val); + LOG(logDEBUG1, ("IODelay: %d\n", retval)); + validate(&ret, mess, val, retval, "set iodelay", DEC); + break; +#endif + + // high voltage + case HIGH_VOLTAGE: + retval = setHighVoltage(val); + LOG(logDEBUG1, ("High Voltage: %d\n", retval)); #if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || \ - defined(GOTTHARD2D) || defined(MYTHEN3D) - validate(&ret, mess, val, retval, "set high voltage", DEC); +defined(GOTTHARD2D) || defined(MYTHEN3D) + validate(&ret, mess, val, retval, "set high voltage", DEC); #endif #ifdef GOTTHARDD - if (retval == -1) { - ret = FAIL; - strcpy(mess, "Invalid Voltage. Valid values are 0, 90, " - "110, 120, 150, 180, 200\n"); - LOG(logERROR, (mess)); - } else - validate(&ret, mess, val, retval, "set high voltage", DEC); + if (retval == -1) { + ret = FAIL; + strcpy(mess, "Invalid Voltage. Valid values are 0, 90, " + "110, 120, 150, 180, 200\n"); + LOG(logERROR, (mess)); + } else + validate(&ret, mess, val, retval, "set high voltage", DEC); #elif EIGERD - if ((retval != SLAVE_HIGH_VOLTAGE_READ_VAL) && (retval < 0)) { - ret = FAIL; - if (retval == -1) - sprintf(mess, - "Setting high voltage failed. Bad value %d. " - "The range is from 0 to 200 V.\n", - val); - else if (retval == -2) - strcpy(mess, "Setting high voltage failed. " - "Serial/i2c communication failed.\n"); - else if (retval == -3) - strcpy(mess, "Getting high voltage failed. " - "Serial/i2c communication failed.\n"); - LOG(logERROR, (mess)); - } + if ((retval != SLAVE_HIGH_VOLTAGE_READ_VAL) && (retval < 0)) { + ret = FAIL; + if (retval == -1) + sprintf(mess, + "Setting high voltage failed. Bad value %d. " + "The range is from 0 to 200 V.\n", + val); + else if (retval == -2) + strcpy(mess, "Setting high voltage failed. " + "Serial/i2c communication failed.\n"); + else if (retval == -3) + strcpy(mess, "Getting high voltage failed. " + "Serial/i2c communication failed.\n"); + LOG(logERROR, (mess)); + } #endif - break; + break; - // power, vlimit + // power, vlimit #ifdef CHIPTESTBOARDD - case V_POWER_A: - case V_POWER_B: - case V_POWER_C: - case V_POWER_D: - case V_POWER_IO: - if (val != GET_FLAG) { - if (!mV) { - ret = FAIL; - sprintf(mess, - "Could not set power. Power regulator %d " - "should be in mV and not dac units.\n", - ind); - LOG(logERROR, (mess)); - } else if (checkVLimitCompliant(val) == FAIL) { - ret = FAIL; - sprintf(mess, - "Could not set power. Power regulator %d " - "exceeds voltage limit %d.\n", - ind, getVLimit()); - LOG(logERROR, (mess)); - } else if (!isPowerValid(serverDacIndex, val)) { - ret = FAIL; - sprintf(mess, - "Could not set power. Power regulator %d " - "should be between %d and %d mV\n", - ind, - (serverDacIndex == D_PWR_IO ? VIO_MIN_MV - : POWER_RGLTR_MIN), - (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); - LOG(logERROR, (mess)); - } else { - setPower(serverDacIndex, val); - } - } - retval = getPower(serverDacIndex); - LOG(logDEBUG1, ("Power regulator(%d): %d\n", ind, retval)); - validate(&ret, mess, val, retval, "set power regulator", DEC); - break; - - case V_POWER_CHIP: - if (val >= 0) { - ret = FAIL; - sprintf(mess, "Can not set Vchip. Can only be set " - "automatically in the background (+200mV " - "from highest power regulator voltage).\n"); - LOG(logERROR, (mess)); - /* restrict users from setting vchip - if (!mV) { - ret = FAIL; - sprintf(mess,"Could not set Vchip. Should be in mV and - not dac units.\n"); LOG(logERROR,(mess)); } else if - (!isVchipValid(val)) { ret = FAIL; sprintf(mess,"Could not - set Vchip. Should be between %d and %d mV\n", VCHIP_MIN_MV, - VCHIP_MAX_MV); LOG(logERROR,(mess)); } else { setVchip(val); - } - */ - } - retval = getVchip(); - LOG(logDEBUG1, ("Vchip: %d\n", retval)); - if (ret == OK && val != GET_FLAG && val != -100 && retval != val) { - ret = FAIL; - sprintf(mess, "Could not set vchip. Set %d, but read %d\n", val, - retval); - LOG(logERROR, (mess)); - } - break; -#endif - -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - case V_LIMIT: - if (val >= 0) { - if (!mV) { - ret = FAIL; - strcpy(mess, "Could not set power. VLimit should be in " - "mV and not dac units.\n"); - LOG(logERROR, (mess)); - } else { - setVLimit(val); - } - } - retval = getVLimit(); - LOG(logDEBUG1, ("VLimit: %d\n", retval)); - validate(&ret, mess, val, retval, "set vlimit", DEC); - break; -#endif - // dacs - default: - if (mV && val > DAC_MAX_MV) { + case V_POWER_A: + case V_POWER_B: + case V_POWER_C: + case V_POWER_D: + case V_POWER_IO: + if (val != GET_FLAG) { + if (!mV) { ret = FAIL; sprintf(mess, - "Could not set dac %d to value %d. Allowed limits " - "(0 - %d mV).\n", - ind, val, DAC_MAX_MV); + "Could not set power. Power regulator %d " + "should be in mV and not dac units.\n", + ind); LOG(logERROR, (mess)); - } else if (!mV && val > getMaxDacSteps()) { + } else if (checkVLimitCompliant(val) == FAIL) { ret = FAIL; sprintf(mess, - "Could not set dac %d to value %d. Allowed limits " - "(0 - %d dac units).\n", - ind, val, getMaxDacSteps()); + "Could not set power. Power regulator %d " + "exceeds voltage limit %d.\n", + ind, getVLimit()); + LOG(logERROR, (mess)); + } else if (!isPowerValid(serverDacIndex, val)) { + ret = FAIL; + sprintf(mess, + "Could not set power. Power regulator %d " + "should be between %d and %d mV\n", + ind, + (serverDacIndex == D_PWR_IO ? VIO_MIN_MV + : POWER_RGLTR_MIN), + (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); LOG(logERROR, (mess)); } else { -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - if ((val != GET_FLAG && mV && - checkVLimitCompliant(val) == FAIL) || - (val != GET_FLAG && !mV && - checkVLimitDacCompliant(val) == FAIL)) { - ret = FAIL; - sprintf(mess, - "Could not set dac %d to value %d. " - "Exceeds voltage limit %d.\n", - ind, (mV ? val : dacToVoltage(val)), getVLimit()); - LOG(logERROR, (mess)); - } else -#endif - setDAC(serverDacIndex, val, mV); - retval = getDAC(serverDacIndex, mV); + setPower(serverDacIndex, val); } -#ifdef EIGERD - if (val != GET_FLAG && getSettings() != UNDEFINED) { - // changing dac changes settings to undefined - switch (serverDacIndex) { - case E_VCMP_LL: - case E_VCMP_LR: - case E_VCMP_RL: - case E_VCMP_RR: - case E_VRPREAMP: - case E_VCP: - setSettings(UNDEFINED); - LOG(logERROR, ("Settings has been changed " - "to undefined (changed specific dacs)\n")); - break; - default: - break; - } - } -#endif - // check - if (ret == OK) { - if ((abs(retval - val) <= 5) || val == GET_FLAG) { - ret = OK; - } else { - ret = FAIL; - sprintf(mess, "Setting dac %d : wrote %d but read %d\n", - serverDacIndex, val, retval); - LOG(logERROR, (mess)); - } - } - LOG(logDEBUG1, ("Dac (%d): %d %s\n\n", serverDacIndex, retval, - (mV ? "mV" : "dac units"))); -#ifdef MYTHEN3D - // changed for setsettings (direct), - // custom trimbit file (setmodule with myMod.reg as -1), - // change of dac (direct) - if (val != GET_FLAG && ret == OK) { - for (int i = 0; i < NCOUNTERS; ++i) { - setThresholdEnergy(i, -1); - } - } -#endif - break; } + retval = getPower(serverDacIndex); + LOG(logDEBUG1, ("Power regulator(%d): %d\n", ind, retval)); + validate(&ret, mess, val, retval, "set power regulator", DEC); + break; + + case V_POWER_CHIP: + if (val >= 0) { + ret = FAIL; + sprintf(mess, "Can not set Vchip. Can only be set " + "automatically in the background (+200mV " + "from highest power regulator voltage).\n"); + LOG(logERROR, (mess)); + /* restrict users from setting vchip + if (!mV) { + ret = FAIL; + sprintf(mess,"Could not set Vchip. Should be in mV and + not dac units.\n"); LOG(logERROR,(mess)); } else if + (!isVchipValid(val)) { ret = FAIL; sprintf(mess,"Could not + set Vchip. Should be between %d and %d mV\n", VCHIP_MIN_MV, + VCHIP_MAX_MV); LOG(logERROR,(mess)); } else { setVchip(val); + } + */ + } + retval = getVchip(); + LOG(logDEBUG1, ("Vchip: %d\n", retval)); + if (ret == OK && val != GET_FLAG && val != -100 && retval != val) { + ret = FAIL; + sprintf(mess, "Could not set vchip. Set %d, but read %d\n", val, + retval); + LOG(logERROR, (mess)); + } + break; +#endif + +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + case V_LIMIT: + if (val >= 0) { + if (!mV) { + ret = FAIL; + strcpy(mess, "Could not set power. VLimit should be in " + "mV and not dac units.\n"); + LOG(logERROR, (mess)); + } else { + setVLimit(val); + } + } + retval = getVLimit(); + LOG(logDEBUG1, ("VLimit: %d\n", retval)); + validate(&ret, mess, val, retval, "set vlimit", DEC); + break; +#endif + // dacs + default: + if (mV && val > DAC_MAX_MV) { + ret = FAIL; + sprintf(mess, + "Could not set dac %d to value %d. Allowed limits " + "(0 - %d mV).\n", + ind, val, DAC_MAX_MV); + LOG(logERROR, (mess)); + } else if (!mV && val > getMaxDacSteps()) { + ret = FAIL; + sprintf(mess, + "Could not set dac %d to value %d. Allowed limits " + "(0 - %d dac units).\n", + ind, val, getMaxDacSteps()); + LOG(logERROR, (mess)); + } else { +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + if ((val != GET_FLAG && mV && + checkVLimitCompliant(val) == FAIL) || + (val != GET_FLAG && !mV && + checkVLimitDacCompliant(val) == FAIL)) { + ret = FAIL; + sprintf(mess, + "Could not set dac %d to value %d. " + "Exceeds voltage limit %d.\n", + ind, (mV ? val : dacToVoltage(val)), getVLimit()); + LOG(logERROR, (mess)); + } else +#endif + setDAC(serverDacIndex, val, mV); + retval = getDAC(serverDacIndex, mV); + } +#ifdef EIGERD + if (val != GET_FLAG && getSettings() != UNDEFINED) { + // changing dac changes settings to undefined + switch (serverDacIndex) { + case E_VCMP_LL: + case E_VCMP_LR: + case E_VCMP_RL: + case E_VCMP_RR: + case E_VRPREAMP: + case E_VCP: + setSettings(UNDEFINED); + LOG(logERROR, ("Settings has been changed " + "to undefined (changed specific dacs)\n")); + break; + default: + break; + } + } +#endif + // check + if (ret == OK) { + if ((abs(retval - val) <= 5) || val == GET_FLAG) { + ret = OK; + } else { + ret = FAIL; + sprintf(mess, "Setting dac %d : wrote %d but read %d\n", + serverDacIndex, val, retval); + LOG(logERROR, (mess)); + } + } + LOG(logDEBUG1, ("Dac (%d): %d %s\n\n", serverDacIndex, retval, + (mV ? "mV" : "dac units"))); +#ifdef MYTHEN3D + // changed for setsettings (direct), + // custom trimbit file (setmodule with myMod.reg as -1), + // change of dac (direct) + if (val != GET_FLAG && ret == OK) { + for (int i = 0; i < NCOUNTERS; ++i) { + setThresholdEnergy(i, -1); + } + } +#endif + break; } return retval; } @@ -1531,28 +1533,12 @@ int set_module(int file_des) { else if (Server_VerifyLock() == OK) { // check index -#if !(defined(EIGERD) || defined(MYTHEN3D)) - // TODO! Check if this is used for any detector - switch (module.reg) { -#ifdef JUNGFRAUD - case DYNAMICGAIN: - case DYNAMICHG0: -#elif GOTTHARDD - case DYNAMICGAIN: - case HIGHGAIN: - case LOWGAIN: - case MEDIUMGAIN: - case VERYHIGHGAIN: -#endif - break; - default: - modeNotImplemented("Settings", (int)module.reg); - break; - } +#ifndef EIGERD + validate_settings((enum detectorSettings)(module.reg)); #endif ret = setModule(module, mess); enum detectorSettings retval = getSettings(); -#if !(defined(EIGERD) || defined(MYTHEN3D)) +#ifndef EIGERD validate(&ret, mess, module.reg, (int)retval, "set module (settings)", DEC); #endif @@ -1565,6 +1551,45 @@ int set_module(int file_des) { return Server_SendResult(file_des, INT32, NULL, 0); } +void validate_settings(enum detectorSettings sett) { + // check index + switch (sett) { +#ifdef EIGERD + case STANDARD: +#elif JUNGFRAUD + case DYNAMICGAIN: + case DYNAMICHG0: +#elif GOTTHARDD + case DYNAMICGAIN: + case HIGHGAIN: + case LOWGAIN: + case MEDIUMGAIN: + case VERYHIGHGAIN: +#elif GOTTHARD2D + case DYNAMICGAIN: + case FIXGAIN1: + case FIXGAIN2: +#elif MOENCHD + case G1_HIGHGAIN: + case G1_LOWGAIN: + case G2_HIGHCAP_HIGHGAIN: + case G2_HIGHCAP_LOWGAIN: + case G2_LOWCAP_HIGHGAIN: + case G2_LOWCAP_LOWGAIN: + case G4_HIGHGAIN: + case G4_LOWGAIN: +#elif MYTHEN3D + case STANDARD: + case FAST: + case HIGHGAIN: +#endif + break; + default: + modeNotImplemented("Settings Index", (int)sett); + break; + } +} + int set_settings(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -1583,47 +1608,14 @@ int set_settings(int file_des) { if (((int)isett == GET_FLAG) || (Server_VerifyLock() == OK)) { if ((int)isett != GET_FLAG) { - // check index - switch (isett) { -#ifdef JUNGFRAUD - case DYNAMICGAIN: - case DYNAMICHG0: -#elif GOTTHARDD - case DYNAMICGAIN: - case HIGHGAIN: - case LOWGAIN: - case MEDIUMGAIN: - case VERYHIGHGAIN: -#elif GOTTHARD2D - case DYNAMICGAIN: - case FIXGAIN1: - case FIXGAIN2: -#elif MOENCHD - case G1_HIGHGAIN: - case G1_LOWGAIN: - case G2_HIGHCAP_HIGHGAIN: - case G2_HIGHCAP_LOWGAIN: - case G2_LOWCAP_HIGHGAIN: - case G2_LOWCAP_LOWGAIN: - case G4_HIGHGAIN: - case G4_LOWGAIN: -#elif MYTHEN3D - case STANDARD: - case FAST: - case HIGHGAIN: +#ifdef EIGERD + ret = FAIL; + sprintf(mess, "Cannot set settings via SET_SETTINGS, use " + "SET_MODULE\n"); + LOG(logERROR, (mess)); +#else + validate_settings(isett); #endif - break; - default: - if (myDetectorType == EIGER) { - ret = FAIL; - sprintf(mess, "Cannot set settings via SET_SETTINGS, use " - "SET_MODULE\n"); - LOG(logERROR, (mess)); - } else - modeNotImplemented("Settings Index", (int)isett); - break; - } - if (ret == OK) { setSettings(isett); } @@ -7653,6 +7645,7 @@ int set_scan(int file_des) { } // dac scan else { + // validate index getDACIndex(index); if (ret == OK) { LOG(logINFOBLUE, ("Dac [%d] scan enabled\n", index)); @@ -8447,4 +8440,96 @@ int get_chip_version(int file_des) { #endif LOG(logDEBUG1, ("chip version retval: %d\n", retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int get_default_dac(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int args[2] = {-1, -1}; + int retval = -1; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + + enum dacIndex dacindex = args[0]; + enum detectorSettings sett = args[1]; + LOG(logDEBUG1, + ("Getting default dac [dacindex:%d, settings: %d]\n", dacindex, sett)); + +#ifdef CHIPTESTBOARDD + functionNotImplemented(); +#else + // get only + enum DACINDEX idac = getDACIndex(dacindex); + if (ret == OK) { + // to allow for default dacs (without settings) + if (sett != UNDEFINED) { + validate_settings(sett); + } + if (ret == OK) { + ret = getDefaultDac(idac, sett, &retval); + if (ret == FAIL) { + sprintf(mess, "Could not get default dac %d %s\n", (int)idac, + (sett != UNDEFINED ? "for this setting" : "")); + LOG(logERROR, (mess)); + } else { + LOG(logDEBUG1, + ("default dac retval [dacindex:%d, setting:%d]: %u\n", + (int)dacindex, (int)sett, retval)); + } + } + } +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_default_dac(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int args[3] = {-1, -1, -1}; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + + enum dacIndex dacindex = args[0]; + enum detectorSettings sett = args[1]; + int value = args[2]; + LOG(logDEBUG1, ("Setting default dac [dacindex: %d, settings: %d] to %d\n", + (int)dacindex, (int)sett, value)); + +#ifdef CHIPTESTBOARDD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + enum DACINDEX idac = getDACIndex(dacindex); + if (ret == OK) { + // to allow for default dacs (without settings) + if (sett != UNDEFINED) { + validate_settings(sett); + } + if (ret == OK) { + ret = setDefaultDac(idac, sett, value); + if (ret == FAIL) { + sprintf(mess, "Could not set default dac %d %s\n", + (int)idac, + (sett != UNDEFINED ? "for this setting" : "")); + LOG(logERROR, (mess)); + } else { + int retval = -1; + ret = getDefaultDac(idac, sett, &retval); + if (ret == FAIL) { + sprintf(mess, "Could not get default dac %d %s\n", + (int)idac, + (sett != UNDEFINED ? "for this setting" : "")); + LOG(logERROR, (mess)); + } else { + LOG(logDEBUG1, ("default dac retval [dacindex:%d, " + "setting:%d]: %u\n", + (int)dacindex, (int)sett, retval)); + } + } + } + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); } \ No newline at end of file diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 0ec970b34..59abaf190 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -412,6 +412,21 @@ class Detector { /** gets list of dac enums for this detector */ std::vector getDacList() const; + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + Result getDefaultDac(defs::dacIndex index, Positions pos = {}); + + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + void setDefaultDac(defs::dacIndex index, int defaultValue, + Positions pos = {}); + + /** [Jungfrau][Mythen3] */ + Result getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, + Positions pos = {}); + + /** [Jungfrau][Mythen3] */ + void setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos = {}); + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ void setDefaultDacs(Positions pos = {}); @@ -1778,7 +1793,6 @@ class Detector { std::vector getPortNumbers(int start_port); void updateRxRateCorrections(); void setNumberofUDPInterfaces_(int n, Positions pos); - Result getNumberofUDPInterfaces_(Positions pos) const; }; } // namespace sls diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 019019c42..a51bf437d 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1095,6 +1095,48 @@ std::string CmdProxy::DacValues(int action) { return os.str(); } +std::string CmdProxy::DefaultDac(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[dac name][value][(optional)setting]\n\tSets the default for " + "that dac to this value.\n\t[Jungfrau][Mythen3] When settings is " + "provided, it sets the default value only for that setting" + << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() < 1) { + WrongNumberOfParameters(1); + } + // optional settings + if (args.size() == 2) { + auto t = det->getDefaultDac( + StringTo(args[0]), + sls::StringTo(args[1])); + os << args[0] << ' ' << args[1] << ' ' << OutString(t) << '\n'; + } else { + auto t = det->getDefaultDac(StringTo(args[0])); + os << args[0] << ' ' << OutString(t) << '\n'; + } + } else if (action == defs::PUT_ACTION) { + if (args.size() < 2) { + WrongNumberOfParameters(2); + } + // optional settings + if (args.size() == 3) { + det->setDefaultDac( + StringTo(args[0]), StringTo(args[1]), + sls::StringTo(args[2])); + os << args[0] << ' ' << args[2] << ' ' << args[1] << '\n'; + } else { + det->setDefaultDac(StringTo(args[0]), + StringTo(args[1])); + os << args[0] << ' ' << args[1] << '\n'; + } + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} /* acquisition */ std::string CmdProxy::ReceiverStatus(int action) { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 22618489b..ced9be101 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -817,6 +817,7 @@ class CmdProxy { {"daclist", &CmdProxy::daclist}, {"dacvalues", &CmdProxy::DacValues}, {"defaultdacs", &CmdProxy::defaultdacs}, + {"defaultdac", &CmdProxy::DefaultDac}, /* on chip dacs */ {"vchip_comp_fe", &CmdProxy::vchip_comp_fe}, @@ -1094,6 +1095,7 @@ class CmdProxy { /* dacs */ std::string Dac(int action); std::string DacValues(int action); + std::string DefaultDac(int action); /* acquisition */ std::string ReceiverStatus(int action); std::string DetectorStatus(int action); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index a865559bb..a429cb446 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -620,6 +620,36 @@ std::vector Detector::getDacList() const { return retval; } +Result Detector::getDefaultDac(defs::dacIndex index, Positions pos) { + return pimpl->getDefaultDac(index, defs::UNDEFINED, pos); +} + +void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, + Positions pos) { + pimpl->setDefaultDac(index, defaultValue, defs::UNDEFINED, pos); +} + +Result Detector::getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos) { + if (sett == defs::UNDEFINED) { + throw RuntimeError("Invalid settings given for default dac"); + } + return pimpl->getDefaultDac(index, sett, pos); +} + +void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos) { + if (sett == defs::UNDEFINED) { + throw RuntimeError("Invalid settings given for default dac"); + } + pimpl->setDefaultDac(index, defaultValue, sett, pos); +} + + + + + void Detector::setDefaultDacs(Positions pos) { pimpl->Parallel(&Module::setDefaultDacs, pos); } @@ -753,7 +783,7 @@ Result Detector::getNumberofUDPInterfaces(Positions pos) const { "Cannot set number of udp interfaces for this detector."); } // also called by vetostream (for gotthard2) - return getNumberofUDPInterfaces_(pos); + return pimpl->getNumberofUDPInterfaces(pos); } void Detector::setNumberofUDPInterfaces(int n, Positions pos) { @@ -765,10 +795,6 @@ void Detector::setNumberofUDPInterfaces(int n, Positions pos) { setNumberofUDPInterfaces_(n, pos); } -Result Detector::getNumberofUDPInterfaces_(Positions pos) const { - return pimpl->Parallel(&Module::getNumberofUDPInterfaces, pos); -} - void Detector::setNumberofUDPInterfaces_(int n, Positions pos) { bool previouslyClientStreaming = pimpl->getDataStreamingToClient(); bool useReceiver = getUseReceiverFlag().squash(false); @@ -1584,7 +1610,7 @@ Result Detector::getVetoStream(Positions pos) const { // 3gbe auto r3 = pimpl->Parallel(&Module::getVetoStream, pos); // 10gbe (debugging interface) opens 2nd udp interface in receiver - auto r10 = getNumberofUDPInterfaces_(pos); + auto r10 = pimpl->getNumberofUDPInterfaces(pos); Result res(r3.size()); for (unsigned int i = 0; i < res.size(); ++i) { @@ -1604,7 +1630,7 @@ void Detector::setVetoStream(defs::ethernetInterface interface, Positions pos) { pimpl->Parallel(&Module::setVetoStream, pos, i3gbe); // 10gbe (debugging interface) opens 2nd udp interface in receiver - int old_numinterfaces = getNumberofUDPInterfaces_(pos).tsquash( + int old_numinterfaces = pimpl->getNumberofUDPInterfaces(pos).tsquash( "retrieved inconsistent number of udp interfaces"); int numinterfaces = (((interface & defs::ethernetInterface::I10GBE) == defs::ethernetInterface::I10GBE) @@ -2169,7 +2195,7 @@ std::vector Detector::getPortNumbers(int start_port) { break; case defs::JUNGFRAU: case defs::GOTTHARD2: - if (getNumberofUDPInterfaces_({}).squash() == 2) { + if (pimpl->getNumberofUDPInterfaces({}).squash() == 2) { num_sockets_per_detector *= 2; } break; diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 188b53167..e6af420f1 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1369,4 +1369,19 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { return buffer; } +sls::Result DetectorImpl::getNumberofUDPInterfaces(Positions pos) const { + return Parallel(&Module::getNumberofUDPInterfaces, pos); +} + +sls::Result DetectorImpl::getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos) { + return Parallel(&Module::getDefaultDac, pos, index, sett); +} + +void DetectorImpl::setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos) { + Parallel(&Module::setDefaultDac, pos, index, defaultValue, sett); +} + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index fa34c5ca1..8dd8f519b 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -291,6 +291,14 @@ class DetectorImpl : public virtual slsDetectorDefs { */ std::vector readProgrammingFile(const std::string &fname); + sls::Result getNumberofUDPInterfaces(Positions pos) const; + void setNumberofUDPInterfaces(int n, Positions pos); + sls::Result getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos = {}); + void setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos); + private: /** * Creates/open shared memory, initializes detector structure and members diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 03d67f030..e06775498 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -618,6 +618,16 @@ int Module::getDAC(dacIndex index, bool mV) const { int args[]{static_cast(index), static_cast(mV), GET_FLAG}; return sendToDetector(F_SET_DAC, args); } +int Module::getDefaultDac(slsDetectorDefs::dacIndex index, + slsDetectorDefs::detectorSettings sett) { + int args[]{static_cast(index), static_cast(sett)}; + return sendToDetector(F_GET_DEFAULT_DAC, args); +} +void Module::setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, + defs::detectorSettings sett) { + int args[]{static_cast(index), static_cast(sett), defaultValue}; + return sendToDetector(F_SET_DEFAULT_DAC, args, nullptr); +} void Module::setDefaultDacs() { sendToDetector(F_SET_DEFAULT_DACS); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index e9a5663a9..f3fda46a1 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -148,7 +148,10 @@ class Module : public virtual slsDetectorDefs { int getMaxClockPhaseShift(int clkIndex) const; int getClockFrequency(int clkIndex) const; void setClockFrequency(int clkIndex, int value); - /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + int getDefaultDac(slsDetectorDefs::dacIndex index, + slsDetectorDefs::detectorSettings sett); + void setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, + defs::detectorSettings sett); void setDefaultDacs(); int getDAC(dacIndex index, bool mV) const; void setDAC(int val, dacIndex index, bool mV); diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 984a3fd51..ab769e71c 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -1407,6 +1407,65 @@ TEST_CASE("dacvalues", "[.cmd]") { REQUIRE_THROWS(proxy.Call("dacvalues", {}, -1, PUT)); } +TEST_CASE("defaultdac", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type != defs::CHIPTESTBOARD) { + REQUIRE_THROWS(proxy.Call("defaultdac", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("defaultdac", {"blabla"}, -1, PUT)); + auto daclist = det.getDacList(); + for (auto it : daclist) { + auto dacname = sls::ToString(it); + auto prev_val = det.getDefaultDac(it); + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "1000"}, -1, PUT, oss); + REQUIRE(oss.str() == std::string("defaultdac ") + dacname + + std::string(" 1000\n")); + } + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname}, -1, GET, oss); + REQUIRE(oss.str() == std::string("defaultdac ") + dacname + + std::string(" 1000\n")); + } + for (int i = 0; i != det.size(); ++i) { + det.setDefaultDac(it, prev_val[i], {i}); + } + } + if (det_type == defs::JUNGFRAU) { + std::vector daclist = {defs::VB_COMP, defs::VREF_DS, + defs::VREF_COMP}; + for (auto it : daclist) { + auto dacname = sls::ToString(it); + auto prev_val = det.getDefaultDac(it, defs::DYNAMICGAIN); + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "1000", "dynamicgain"}, -1, + PUT, oss); + REQUIRE(oss.str() == + std::string("defaultdac ") + dacname + + std::string(" dynamicgain 1000\n")); + } + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "dynamicgain"}, -1, GET, + oss); + REQUIRE(oss.str() == + std::string("defaultdac ") + dacname + + std::string(" dynamicgain 1000\n")); + } + for (int i = 0; i != det.size(); ++i) { + det.setDefaultDac(it, prev_val[i], defs::DYNAMICGAIN, {i}); + } + } + } + } else { + REQUIRE_THROWS(proxy.Call("defaultdac", {}, -1, GET)); + } +} + TEST_CASE("defaultdacs", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index f517fd26a..27d783094 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -231,6 +231,8 @@ enum detFuncs { F_GET_VETO_ALGORITHM, F_SET_VETO_ALGORITHM, F_GET_CHIP_VERSION, + F_GET_DEFAULT_DAC, + F_SET_DEFAULT_DAC, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -568,6 +570,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_VETO_ALGORITHM: return "F_GET_VETO_ALGORITHM"; case F_SET_VETO_ALGORITHM: return "F_SET_VETO_ALGORITHM"; case F_GET_CHIP_VERSION: return "F_GET_CHIP_VERSION"; + case F_GET_DEFAULT_DAC: return "F_GET_DEFAULT_DAC"; + case F_SET_DEFAULT_DAC: return "F_SET_DEFAULT_DAC"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index cfc0ff245..04d04811d 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -3,10 +3,10 @@ #define APILIB 0x210225 #define APIRECEIVER 0x210225 #define APIGUI 0x210225 -#define APICTB 0x210727 -#define APIGOTTHARD 0x210727 -#define APIGOTTHARD2 0x210727 -#define APIMYTHEN3 0x210727 -#define APIMOENCH 0x210727 -#define APIEIGER 0x210727 +#define APICTB 0x210729 +#define APIGOTTHARD 0x210729 +#define APIGOTTHARD2 0x210729 #define APIJUNGFRAU 0x210729 +#define APIMYTHEN3 0x210729 +#define APIMOENCH 0x210729 +#define APIEIGER 0x210729