From 0fb6c8b8231a8e82e3ae29602e6f1435e24d5807 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 18 Feb 2022 10:32:07 +0100 Subject: [PATCH] updating dr 12 in server, changing signature to get fail for getdynamicrange --- .../slsDetectorFunctionList.c | 10 +- .../eigerDetectorServer/FebControl.c | 140 ++++++++++++++---- .../eigerDetectorServer/FebControl.h | 6 +- .../eigerDetectorServer/FebRegisterDefs.h | 2 + .../slsDetectorFunctionList.c | 58 +++++--- .../slsDetectorServer_defs.h | 2 +- .../slsDetectorFunctionList.c | 11 +- .../slsDetectorFunctionList.c | 11 +- .../slsDetectorFunctionList.c | 11 +- .../slsDetectorFunctionList.c | 11 +- .../slsDetectorFunctionList.c | 70 +++++---- .../include/slsDetectorFunctionList.h | 1 + .../src/slsDetectorServer_funcs.c | 74 +++++---- 13 files changed, 291 insertions(+), 116 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 06999e54d..40217eb41 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -702,8 +702,16 @@ void resetPeripheral() { } /* set parameters - dr, adcenablemask */ +int setDynamicRange(int dr) { + if (dr == 16) + return OK; + return FAIL; +} -int setDynamicRange(int dr) { return DYNAMIC_RANGE; } +int getDynamicRange(int *retval) { + *retval = DYNAMIC_RANGE; + return OK; +} int setADCEnableMask(uint32_t mask) { if (mask == 0u) { diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.c b/slsDetectorServers/eigerDetectorServer/FebControl.c index 8d3661a52..75a6a6f2a 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -931,7 +931,10 @@ unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec) { int Feb_Control_PrepareForAcquisition() { LOG(logINFOBLUE, ("Preparing for Acquisition\n")); - Feb_Control_PrintAcquisitionSetup(); + if (!Feb_Control_PrintAcquisitionSetup()) { + LOG(logERROR, ("Could not prepare acquisition\n")); + return 0; + } if (Feb_Control_Reset() == STATUS_ERROR) { LOG(logERROR, ("Trouble reseting daq or data stream\n")); @@ -988,20 +991,26 @@ int Feb_Control_PrepareForAcquisition() { return 1; } -void Feb_Control_PrintAcquisitionSetup() { +int Feb_Control_PrintAcquisitionSetup() { time_t rawtime; time(&rawtime); struct tm *timeinfo = localtime(&rawtime); - LOG(logINFO, - ("Starting an exposure: (%s)" - "\t Dynamic range nbits: %d\n" - "\t Trigger mode: 0x%x\n" - "\t Number of exposures: %d\n" - "\t Exsposure time (if used): %f seconds.\n" - "\t Exsposure period (if used): %f seconds.\n\n", - asctime(timeinfo), Feb_Control_GetDynamicRange(), - Feb_Control_triggerMode, Feb_Control_GetNExposures(), - Feb_Control_exposure_time_in_sec, Feb_Control_exposure_period_in_sec)); + int dr = 0; + if (!Feb_Control_GetDynamicRange(&dr)) { + LOG(logERROR, ("Could not print acquisition set up\n")); + return 0; + } + LOG(logINFO, ("Starting an exposure: (%s)" + "\t Dynamic range nbits: %d\n" + "\t Trigger mode: 0x%x\n" + "\t Number of exposures: %d\n" + "\t Exsposure time (if used): %f seconds.\n" + "\t Exsposure period (if used): %f seconds.\n\n", + asctime(timeinfo), dr, Feb_Control_triggerMode, + Feb_Control_GetNExposures(), Feb_Control_exposure_time_in_sec, + Feb_Control_exposure_period_in_sec)); + + return 1; } int Feb_Control_StartAcquisition() { @@ -1173,25 +1182,35 @@ int Feb_Control_SetDynamicRange(unsigned int dr) { static unsigned int everything_but_bit_mode = DAQ_STATIC_BIT_PROGRAM | DAQ_STATIC_BIT_CHIP_TEST | DAQ_STATIC_BIT_ROTEST; - if (dr == 4) { + switch (dr) { + case 4: Feb_Control_staticBits = DAQ_STATIC_BIT_M4 | (Feb_Control_staticBits & everything_but_bit_mode); // leave test bits in currernt state Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - } else if (dr == 8) { + break; + case 8: Feb_Control_staticBits = DAQ_STATIC_BIT_M8 | (Feb_Control_staticBits & everything_but_bit_mode); Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - } else if (dr == 16 || dr == 12) { + break; + case 12: + case 16: Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits & everything_but_bit_mode); Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - } else if (dr == 32) { + + // disable 16 bit conversion if 12 bit mode (enable if 16 bit) + if (!Feb_Control_Disable16bitConversion(dr == 12)) + return 0; + break; + case 32: Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits & everything_but_bit_mode); Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - } else { + break; + default: LOG(logERROR, ("dynamic range (%d) not valid, not setting bit mode.\n", dr)); LOG(logINFO, ("Set dynamic range int must equal 4,8 16, or 32.\n")); @@ -1202,15 +1221,63 @@ int Feb_Control_SetDynamicRange(unsigned int dr) { return 1; } -unsigned int Feb_Control_GetDynamicRange() { - if (Feb_Control_subFrameMode & DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) - return 32; - else if (DAQ_STATIC_BIT_M4 & Feb_Control_staticBits) - return 4; - else if (DAQ_STATIC_BIT_M8 & Feb_Control_staticBits) - return 8; +int Feb_Control_GetDynamicRange(unsigned int *retval) { + if (Feb_Control_subFrameMode & DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) { + *retval = 32; + } else if (DAQ_STATIC_BIT_M4 & Feb_Control_staticBits) { + *retval = 4; + } else if (DAQ_STATIC_BIT_M8 & Feb_Control_staticBits) { + *retval = 8; + } - return 16; + int disable16 = 0; + if (!Feb_Control_Get16bitConversionDisabled(&disable16)) { + LOG(logERROR, ("Could not get dynamic range (12 or 16 bit)\n")); + return 0; + } + if (disable16) { + *retval = 12; + } else { + *retval = 16; + } + + return 1; +} + +int Feb_Control_Disable16bitConversion(int disable) { + LOG(logINFO, ("%s 16 bit expansion\n", disable ? "Disabling" : "Enabling")); + unsigned int regval = 0; + if (!Feb_Control_ReadRegister(DAQ_REG_HRDWRE, ®val)) { + LOG(logERROR, ("Could not %s 16 bit expansion (bit mode)\n", + (disable ? "disable" : "enable"))); + return 0; + } + if (disable) { + regval |= DAQ_REG_HRDWRE_DSBL_16BIT_MSK; + } else { + regval &= ~DAQ_REG_HRDWRE_DSBL_16BIT_MSK; + } + + if (!Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval)) { + LOG(logERROR, ("Could not %s 16 bit expansion (bit mode)\n", + (disable ? "disable" : "enable"))); + return 0; + } + return 1; +} + +int Feb_Control_Get16bitConversionDisabled(int *ret) { + unsigned int regval = 0; + if (!Feb_Control_ReadRegister(DAQ_REG_HRDWRE, ®val)) { + LOG(logERROR, ("Could not get 16 bit expansion (bit mode)\n")); + return 0; + } + if (regval | DAQ_REG_HRDWRE_DSBL_16BIT_MSK) { + *ret = 1; + } else { + *ret = 0; + } + return 1; } int Feb_Control_SetReadoutSpeed(unsigned int readout_speed) { @@ -1553,7 +1620,10 @@ int Feb_Control_SetChipSignalsToTrimQuad(int enable) { regval &= ~(DAQ_REG_HRDWRE_PROGRAM_MSK | DAQ_REG_HRDWRE_M8_MSK); } - return Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval); + if (!Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval)) { + LOG(logERROR, ("Could not set chip signals to trim quad\n")); + return 0; + } } return 1; } @@ -1611,6 +1681,18 @@ int Feb_Control_WriteRegister(uint32_t offset, uint32_t data) { side[iloop], actualOffset)); return 0; } + uint32_t regVal = 0; + if (!Feb_Interface_ReadRegister(addr[iloop], actualOffset, + ®Val)) { + LOG(logERROR, ("Could not read %s register\n", addr[iloop])); + return 0; + } + if (regVal != data) { + LOG(logERROR, + ("Could not write %s register. Write 0x%x, read 0x%x\n", + addr[iloop], data, regVal)); + return 0; + } } } @@ -1823,7 +1905,11 @@ int64_t Feb_Control_Get_RateTable_Period_in_nsec() { int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec) { // period = exptime if 16bit, period = subexptime if 32 bit - int dr = Feb_Control_GetDynamicRange(); + int dr = 0; + if (!Feb_Control_GetDynamicRange(&dr)) { + LOG(logERROR, ("Could not set rate correction tau\n")); + return 0; + } double period_in_sec = (double)(Feb_Control_GetSubFrameExposureTime()) / (double)1e9; if (dr == 16) diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.h b/slsDetectorServers/eigerDetectorServer/FebControl.h index 3787000ec..110d9ed58 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.h +++ b/slsDetectorServers/eigerDetectorServer/FebControl.h @@ -55,7 +55,7 @@ int Feb_Control_ResetChipPartially(); int Feb_Control_SendBitModeToBebServer(); unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec); int Feb_Control_PrepareForAcquisition(); -void Feb_Control_PrintAcquisitionSetup(); +int Feb_Control_PrintAcquisitionSetup(); int Feb_Control_StartAcquisition(); int Feb_Control_StopAcquisition(); int Feb_Control_IsReadyForTrigger(int *readyForTrigger); @@ -64,7 +64,9 @@ int Feb_Control_SoftwareTrigger(int block); // parameters int Feb_Control_SetDynamicRange(unsigned int dr); -unsigned int Feb_Control_GetDynamicRange(); +int Feb_Control_GetDynamicRange(unsigned int *retval); +int Feb_Control_Disable16bitConversion(int disable); +int Feb_Control_Get16bitConversionDisabled(); int Feb_Control_SetReadoutSpeed(unsigned int readout_speed); int Feb_Control_SetReadoutMode(unsigned int readout_mode); int Feb_Control_SetTriggerMode(unsigned int trigger_mode); diff --git a/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h b/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h index db2627181..1ec86f834 100644 --- a/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h +++ b/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h @@ -29,6 +29,8 @@ #define DAQ_REG_HRDWRE_OW_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_OW_MASTER_OFST) #define DAQ_REG_HRDWRE_MASTER_OFST (4) #define DAQ_REG_HRDWRE_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_MASTER_OFST) +#define DAQ_REG_HRDWRE_DSBL_16BIT_OFST (5) +#define DAQ_REG_HRDWRE_DSBL_16BIT_MSK (0x00000001 << DAQ_REG_HRDWRE_DSBL_16BIT_OFST) #define DAQ_REG_HRDWRE_PROGRAM_OFST (30) #define DAQ_REG_HRDWRE_PROGRAM_MSK (0x00000001 << DAQ_REG_HRDWRE_PROGRAM_OFST) #define DAQ_REG_HRDWRE_M8_OFST (31) diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 4f7f73a83..7c8a3ea11 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -821,30 +821,38 @@ int readRegister(uint32_t offset, uint32_t *retval) { /* set parameters - dr, roi */ int setDynamicRange(int dr) { - // setting dr - if (dr > 0) { -#ifdef VIRTUAL - LOG(logINFO, ("Setting dynamic range: %d\n", dr)); -#else - sharedMemory_lockLocalLink(); - if (Feb_Control_SetDynamicRange(dr)) { - if (!Beb_SetUpTransferParameters(dr)) { - LOG(logERROR, ("Could not set bit mode in the back end\n")); - sharedMemory_unlockLocalLink(); - return eiger_dynamicrange; - } - } - sharedMemory_unlockLocalLink(); -#endif - eiger_dynamicrange = dr; + if (dr <= 0) { + return FAIL; } - // getting dr -#ifndef VIRTUAL +#ifdef VIRTUAL + LOG(logINFO, ("Setting dynamic range: %d\n", dr)); +#else sharedMemory_lockLocalLink(); - eiger_dynamicrange = Feb_Control_GetDynamicRange(); + if (Feb_Control_SetDynamicRange(dr)) { + if (!Beb_SetUpTransferParameters(dr)) { + LOG(logERROR, ("Could not set bit mode in the back end\n")); + sharedMemory_unlockLocalLink(); + return eiger_dynamicrange; + } + } sharedMemory_unlockLocalLink(); #endif - return eiger_dynamicrange; + eiger_dynamicrange = dr; + return OK; +} + +int getDynamicRange(int *retval) { +#ifdef VIRTUAL + *retval = eiger_dynamicrange; +#else + sharedMemory_lockLocalLink(); + if (!Feb_Control_GetDynamicRange(&eiger_dynamicrange)) { + sharedMemory_unlockLocalLink(); + return FAIL; + } + sharedMemory_unlockLocalLink(); +#endif + return OK; } /* parameters - readout */ @@ -1159,6 +1167,7 @@ int setModule(sls_detector_module myMod, char *mess) { // if quad, set M8 and PROGRAM manually if (!Feb_Control_SetChipSignalsToTrimQuad(1)) { + sharedMemory_unlockLocalLink(); return FAIL; } @@ -1171,6 +1180,7 @@ int setModule(sls_detector_module myMod, char *mess) { // if quad, reset M8 and PROGRAM manually if (!Feb_Control_SetChipSignalsToTrimQuad(0)) { + sharedMemory_unlockLocalLink(); return FAIL; } @@ -1180,6 +1190,7 @@ int setModule(sls_detector_module myMod, char *mess) { // if quad, reset M8 and PROGRAM manually if (!Feb_Control_SetChipSignalsToTrimQuad(0)) { + sharedMemory_unlockLocalLink(); return FAIL; } @@ -1924,7 +1935,8 @@ int setRateCorrection( else if (custom_tau_in_nsec == -1) custom_tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec(); - int dr = Feb_Control_GetDynamicRange(); + int dr = eiger_dynamicrange; + // get period = subexptime if 32bit , else period = exptime if 16 bit int64_t actual_period = Feb_Control_GetSubFrameExposureTime(); // already in nsec @@ -2780,9 +2792,9 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { int calculateDataBytes() { if (send_to_ten_gig) - return setDynamicRange(-1) * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE; + return eiger_dynamicrange * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE; else - return setDynamicRange(-1) * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE; + return eiger_dynamicrange * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE; } int getTotalNumberOfChannels() { diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index 95a1590b1..cca94c3fd 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -5,7 +5,7 @@ #define LINKED_SERVER_NAME "eigerDetectorServer" -#define REQUIRED_FIRMWARE_VERSION (29) +#define REQUIRED_FIRMWARE_VERSION (30) // virtual ones renamed for consistency // real ones keep previous name for compatibility (already in production) #ifdef VIRTUAL diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index da7576ef8..0816cfa05 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -952,7 +952,16 @@ void resetPeripheral() { /* set parameters - dr, roi */ -int setDynamicRange(int dr) { return DYNAMIC_RANGE; } +int setDynamicRange(int dr) { + if (dr == 16) + return OK; + return FAIL; +} + +int getDynamicRange(int *retval) { + *retval = DYNAMIC_RANGE; + return OK; +} /* parameters - timer */ void setNumFrames(int64_t val) { diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 362bf2079..ca415eeba 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -788,7 +788,16 @@ void setMasterSlaveConfiguration() { /* set parameters - dr, roi */ -int setDynamicRange(int dr) { return DYNAMIC_RANGE; } +int setDynamicRange(int dr) { + if (dr == 16) + return OK; + return FAIL; +} + +int getDynamicRange(int *retval) { + *retval = DYNAMIC_RANGE; + return OK; +} int setROI(ROI arg) { diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index dc8e1ea28..4a8bebcfd 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -796,7 +796,16 @@ void resetPeripheral() { /* set parameters - dr, roi */ -int setDynamicRange(int dr) { return DYNAMIC_RANGE; } +int setDynamicRange(int dr) { + if (dr == 16) + return OK; + return FAIL; +} + +int getDynamicRange(int *retval) { + *retval = DYNAMIC_RANGE; + return OK; +} void setADCInvertRegister(uint32_t val) { LOG(logINFO, ("Setting ADC Port Invert Reg to 0x%x\n", val)); diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index dd4b62c0d..684ba1152 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -700,7 +700,16 @@ void resetPeripheral() { /* set parameters - dr, adcenablemask */ -int setDynamicRange(int dr) { return DYNAMIC_RANGE; } +int setDynamicRange(int dr) { + if (dr == 16) + return OK; + return FAIL; +} + +int getDynamicRange(int *retval) { + *retval = DYNAMIC_RANGE; + return OK; +} int setADCEnableMask(uint32_t mask) { if (mask == 0u) { diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index f4b40499e..4235f145b 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -729,46 +729,53 @@ void resetPeripheral() { /* set parameters - dr, roi */ int setDynamicRange(int dr) { - if (dr > 0) { - uint32_t regval = 0; - switch (dr) { - /*case 1: TODO:Not implemented in firmware yet - regval = CONFIG_DYNAMIC_RANGE_1_VAL; - break;*/ - case 8: - regval = CONFIG_DYNAMIC_RANGE_8_VAL; - break; - case 16: - regval = CONFIG_DYNAMIC_RANGE_16_VAL; - break; - case 32: - regval = CONFIG_DYNAMIC_RANGE_24_VAL; - break; - default: - LOG(logERROR, ("Invalid dynamic range %d\n", dr)); - return -1; - } - // set it - bus_w(CONFIG_REG, bus_r(CONFIG_REG) & ~CONFIG_DYNAMIC_RANGE_MSK); - bus_w(CONFIG_REG, bus_r(CONFIG_REG) | regval); - updatePacketizing(); + if (dr <= 0) { + return FAIL; } + uint32_t regval = 0; + switch (dr) { + /*case 1: TODO:Not implemented in firmware yet + regval = CONFIG_DYNAMIC_RANGE_1_VAL; + break;*/ + case 8: + regval = CONFIG_DYNAMIC_RANGE_8_VAL; + break; + case 16: + regval = CONFIG_DYNAMIC_RANGE_16_VAL; + break; + case 32: + regval = CONFIG_DYNAMIC_RANGE_24_VAL; + break; + default: + LOG(logERROR, ("Invalid dynamic range %d\n", dr)); + return -1; + } + // set it + bus_w(CONFIG_REG, bus_r(CONFIG_REG) & ~CONFIG_DYNAMIC_RANGE_MSK); + bus_w(CONFIG_REG, bus_r(CONFIG_REG) | regval); + updatePacketizing(); +} +int getDynamicRange(int *retval) { uint32_t regval = bus_r(CONFIG_REG) & CONFIG_DYNAMIC_RANGE_MSK; switch (regval) { /*case CONFIG_DYNAMIC_RANGE_1_VAL: TODO:Not implemented in firmware yet return 1;*/ case CONFIG_DYNAMIC_RANGE_8_VAL: - return 8; + *retval = 8; + break; case CONFIG_DYNAMIC_RANGE_16_VAL: - return 16; + *retval = 16; + break; case CONFIG_DYNAMIC_RANGE_24_VAL: - return 32; + *retval = 32; + break; default: LOG(logERROR, ("Invalid dynamic range %d read back\n", regval >> CONFIG_DYNAMIC_RANGE_OFST)); - return -1; + return FAIL; } + return OK; } /* set parameters - readout */ @@ -1091,7 +1098,8 @@ void updatePacketizing() { // 10g if (tgEnable) { - const int dr = setDynamicRange(-1); + int dr = 0; + getDynamicRange(&dr); packetsPerFrame = 1; if (dr == 32 && ncounters > 1) { packetsPerFrame = 2; @@ -2202,7 +2210,8 @@ void *start_timer(void *arg) { const int imageSize = calculateDataBytes(); const int tgEnable = enableTenGigabitEthernet(-1); - const int dr = setDynamicRange(-1); + int dr = 0; + getDynamicRange(&dr); int ncounters = __builtin_popcount(getCounterMask()); int dataSize = 0; int packetsPerFrame = 0; @@ -2523,7 +2532,8 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { int calculateDataBytes() { int numCounters = __builtin_popcount(getCounterMask()); - int dr = setDynamicRange(-1); + int dr = 0; + getDynamicRange(&dr); return (NCHAN_1_COUNTER * NCHIP * numCounters * ((double)dr / 8.00)); } diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 955f35e6b..efc671d39 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -173,6 +173,7 @@ void setMasterSlaveConfiguration(); // parameters - dr, roi int setDynamicRange(int dr); +int getDynamicRange(int *retval); #ifdef GOTTHARDD int setROI(ROI arg); ROI getROI(); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 546936258..8f10c23cf 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -2821,14 +2821,20 @@ int set_dynamic_range(int file_des) { defined(MOENCHD) || defined(GOTTHARD2D) case 16: #endif - retval = setDynamicRange(dr); - LOG(logDEBUG1, ("Dynamic range: %d\n", retval)); - if (retval == -1) { - ret = FAIL; - sprintf(mess, "Could not get dynamic range.\n"); + ret = setDynamicRange(dr); + if (ret == FAIL) { + sprintf(mess, "Could not set dynamic range to %d\n", dr); LOG(logERROR, (mess)); + } else { + ret = getDynamicRange(&retval); + if (ret == FAIL) { + strcpy(mess, "Could not get dynamic range\n"); + LOG(logERROR, (mess)); + } else { + LOG(logDEBUG1, ("Dynamic range: %d\n", retval)); + validate(&ret, mess, dr, retval, "set dynamic range", DEC); + } } - validate(&ret, mess, dr, retval, "set dynamic range", DEC); break; default: modeNotImplemented("Dynamic range", dr); @@ -4649,21 +4655,28 @@ int set_read_n_rows(int file_des) { LOG(logERROR, (mess)); } else { #ifdef EIGERD - int dr = setDynamicRange(GET_FLAG); - int isTenGiga = enableTenGigabitEthernet(GET_FLAG); - unsigned int maxnl = MAX_ROWS_PER_READOUT; - unsigned int maxnp = (isTenGiga ? 4 : 16) * dr; - if ((arg * maxnp) % maxnl) { - ret = FAIL; - sprintf(mess, + int dr = 0; + ret = getDynamicRange(&dr); + if (ret == FAIL) { + strcpy(mess, + "Could not read n rows (failed to get dynamic range)\n"); + LOG(logERROR, (mess)); + } else { + int isTenGiga = enableTenGigabitEthernet(GET_FLAG); + unsigned int maxnl = MAX_ROWS_PER_READOUT; + unsigned int maxnp = (isTenGiga ? 4 : 16) * dr; + if ((arg * maxnp) % maxnl) { + ret = FAIL; + sprintf( + mess, "Could not set number of rows to %d. For %d bit " "mode and 10 giga %s, (%d (num " "rows) x %d (max num packets for this mode)) must be " "divisible by %d\n", arg, dr, isTenGiga ? "enabled" : "disabled", arg, maxnp, maxnl); - LOG(logERROR, (mess)); - } else + LOG(logERROR, (mess)); + } else #elif JUNGFRAUD if ((check_detector_idle("set number of rows") == OK) && (arg % READ_N_ROWS_MULTIPLE != 0)) { @@ -4682,20 +4695,22 @@ int set_read_n_rows(int file_des) { LOG(logERROR, (mess)); } else #endif - { - if (setReadNRows(arg) == FAIL) { - ret = FAIL; - sprintf(mess, "Could not set number of rows to %d.\n", arg); - LOG(logERROR, (mess)); - } else { - int retval = getReadNRows(); - if (arg != retval) { + { + if (setReadNRows(arg) == FAIL) { ret = FAIL; - sprintf(mess, - "Could not set number of rows. Set %d, but " - "read %d\n", - retval, arg); + sprintf(mess, "Could not set number of rows to %d.\n", + arg); LOG(logERROR, (mess)); + } else { + int retval = getReadNRows(); + if (arg != retval) { + ret = FAIL; + sprintf(mess, + "Could not set number of rows. Set %d, but " + "read %d\n", + retval, arg); + LOG(logERROR, (mess)); + } } } } @@ -7111,7 +7126,10 @@ int get_receiver_parameters(int file_des) { } // dynamic range - i32 = setDynamicRange(GET_FLAG); + ret = getDynamicRange(&i32); + if (ret == FAIL) { + i32 = 0; + } n += sendData(file_des, &i32, sizeof(i32), INT32); if (n < 0) return printSocketReadError();