From 95089b5faa89c651a58336df89e2f6333c59a74f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 3 Jul 2020 16:06:12 +0200 Subject: [PATCH] WIP --- .../slsDetectorFunctionList.c | 1 + .../slsDetectorFunctionList.c | 10 +- .../slsDetectorFunctionList.c | 9 +- .../include/slsDetectorServer_funcs.h | 3 + .../src/slsDetectorServer_funcs.c | 723 ++++++++---------- slsDetectorSoftware/include/Detector.h | 4 + slsDetectorSoftware/src/CmdProxy.cpp | 3 +- slsDetectorSoftware/src/CmdProxy.h | 5 + slsDetectorSoftware/src/Detector.cpp | 4 + slsDetectorSoftware/src/Module.cpp | 6 + slsDetectorSoftware/src/Module.h | 1 + slsSupportLib/include/sls_detector_defs.h | 4 +- slsSupportLib/include/sls_detector_funcs.h | 2 + slsSupportLib/src/ToString.cpp | 9 + 14 files changed, 373 insertions(+), 411 deletions(-) diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 05ec63e29..fd5a8e656 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -1267,6 +1267,7 @@ int setHighVoltage(int val) { if (master) { // set if (val != -1) { + LOG(logINFO, ("Setting High voltage: %d V\n", val)); eiger_theo_highvoltage = val; } return eiger_theo_highvoltage; diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 726ad235a..6db979921 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -1198,17 +1198,11 @@ int setHighVoltage(int val) { val = HV_SOFT_MAX_VOLTAGE; } -#ifdef VIRTUAL - if (val >= 0) - highvoltage = val; - return highvoltage; -#endif - // setting hv if (val >= 0) { LOG(logINFO, ("Setting High voltage: %d V\n", val)); - DAC6571_Set(val); - highvoltage = val; + if (DAC6571_Set(val) == OK) + highvoltage = val; } return highvoltage; } diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 6ac2dd066..850f51d74 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -1133,17 +1133,12 @@ int setHighVoltage(int val) { if (val > HV_SOFT_MAX_VOLTAGE) { val = HV_SOFT_MAX_VOLTAGE; } -#ifdef VIRTUAL - if (val >= 0) - highvoltage = val; - return highvoltage; -#endif // setting hv if (val >= 0) { LOG(logINFO, ("Setting High voltage: %d V\n", val)); - DAC6571_Set(val); - highvoltage = val; + if (DAC6571_Set(val) == OK) + highvoltage = val; } return highvoltage; } diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index a0d85ab42..47568d112 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -37,6 +37,7 @@ int set_bus_test(int); int set_image_test_mode(int); int get_image_test_mode(int); enum DACINDEX getDACIndex(enum dacIndex ind); +int validateAndSetDac(enum dacIndex ind, int val, int mV); int set_dac(int); int get_adc(int); int write_register(int); @@ -91,6 +92,7 @@ int get_last_client_ip(int); int set_port(int); int calibrate_pedestal(int); int enable_ten_giga(int); +int validateAndSetAllTrimbits(int arg); int set_all_trimbits(int); int set_pattern_io_control(int); int set_pattern_word(int); @@ -226,3 +228,4 @@ int set_veto(int); int set_pattern(int); int get_scan(int); int set_scan(int); +int get_scan_error_message(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 1c8ee25b4..55cd81845 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -59,8 +59,8 @@ int numScanSteps = 0; int *scanSteps = NULL; int64_t scanSettleTime_ns = 0; enum dacIndex scanGlobalIndex = 0; -enum DACINDEX scanDac = 0; int scanTrimbits = 0; +char scanErrMessage[MAX_STR_LENGTH] = ""; /* initialization functions */ @@ -345,6 +345,8 @@ void function_table() { flist[F_SET_PATTERN] = &set_pattern; flist[F_GET_SCAN] = get_scan; flist[F_SET_SCAN] = set_scan; + flist[F_GET_SCAN_ERROR_MESSAGE] = get_scan_error_message; + // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { LOG(logERROR, ("The last detector function enum has reached its " @@ -713,7 +715,7 @@ int get_image_test_mode(int file_des) { } enum DACINDEX getDACIndex(enum dacIndex ind) { - enum DACINDEX serverDacIndex = 0; + enum DACINDEX serverDacIndex = -1; // check if dac exists for this detector switch (ind) { #ifdef GOTTHARDD @@ -993,6 +995,235 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { return serverDacIndex; } +int validateAndSetDac(enum dacIndex ind, int val, int mV) { + int retval = -1; + enum DACINDEX serverDacIndex = getDACIndex(ind); + + 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 +#ifdef EIGERD + case IO_DELAY: + retval = setIODelay(val); + LOG(logDEBUG1, ("IODelay: %d\n", retval)); + validate(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(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(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)); + } +#endif + break; + + // 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(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(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"))); + break; + } + } + return retval; +} + int set_dac(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -1005,240 +1236,12 @@ int set_dac(int file_des) { enum dacIndex ind = args[0]; int mV = args[1]; int val = args[2]; - enum DACINDEX serverDacIndex = getDACIndex(ind); - // index exists - if (ret == OK) { - - LOG(logDEBUG1, ("Setting DAC %d to %d %s\n", serverDacIndex, val, - (mV ? "mV" : "dac units"))); - - // set & get - if ((val == GET_FLAG) || (Server_VerifyLock() == 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 -#ifdef EIGERD - case IO_DELAY: - retval = setIODelay(val); - LOG(logDEBUG1, ("IODelay: %d\n", retval)); - validate(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(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(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)); - } -#endif - break; - - // 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(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(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) { - // 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"))); - break; - } - } + LOG(logDEBUG1, + ("Setting DAC %d to %d %s\n", ind, val, (mV ? "mV" : "dac units"))); + // set & get + if ((val == GET_FLAG) || (Server_VerifyLock() == OK)) { + retval = validateAndSetDac(ind, val, mV); } return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); } @@ -1731,6 +1734,7 @@ int acquire(int blocking, int file_des) { "already running!\n"); LOG(logERROR, (mess)); } else { + memset(scanErrMessage, 0, MAX_STR_LENGTH); sharedMemory_setScanStop(0); sharedMemory_setScanStatus(IDLE); // if it was error if (pthread_create(&pthread_tid, NULL, &start_state_machine, @@ -1773,30 +1777,24 @@ void *start_state_machine(void *arg) { if (scanTrimbits) { LOG(logINFOBLUE, ("Trimbits scan %d/%d: [%d]\n", i, times, scanSteps[i])); -#if !defined(EIGERD) && !defined(MYTHEN3D) - ret = FAIL; - sprintf(mess, "trimbit scan not implemented for this " - "detector!\n"); - LOG(logERROR, (mess)); - sharedMemory_setScanStatus(ERROR); - break; -#else - setAllTrimbits(scanSteps[i]); -#endif + validateAndSetAllTrimbits(scanSteps[i]); + if (ret == FAIL) { + sprintf(scanErrMessage, "Cannot scan trimbit %d. ", + scanSteps[i]); + strcat(scanErrMessage, mess); + sharedMemory_setScanStatus(ERROR); + break; + } } // dac scan else { - LOG(logINFOBLUE, ("Dac [%d] scan %d/%d: [%d]\n", scanDac, i, - times, scanSteps[i])); - setDAC(scanDac, scanSteps[i], 0); - int retval = getDAC(scanDac, 0); - if (abs(retval - scanSteps[i]) > 5) { - ret = FAIL; - sprintf(mess, - "Could not scan. Setting dac %d : wrote %d but " - "read %d\n", - scanDac, scanSteps[i], scanSteps[i]); - LOG(logERROR, (mess)); + LOG(logINFOBLUE, ("Dac [%d] scan %d/%d: [%d]\n", + scanGlobalIndex, i, times, scanSteps[i])); + validateAndSetDac(scanGlobalIndex, scanSteps[i], 0); + if (ret == FAIL) { + sprintf(scanErrMessage, "Cannot scan dac %d at %d. ", + scanGlobalIndex, scanSteps[i]); + strcat(scanErrMessage, mess); sharedMemory_setScanStatus(ERROR); break; } @@ -1823,6 +1821,8 @@ void *start_state_machine(void *arg) { #endif LOG(logERROR, (mess)); if (scan) { + sprintf(scanErrMessage, "Cannot scan at %d. ", scanSteps[i]); + strcat(scanErrMessage, mess); sharedMemory_setScanStatus(ERROR); } break; @@ -1830,10 +1830,16 @@ void *start_state_machine(void *arg) { // blocking or scan if (*blocking || times > 1) { readFrame(&ret, mess); + if (ret == FAIL && scan) { + sprintf(scanErrMessage, "Cannot scan at %d. ", scanSteps[i]); + strcat(scanErrMessage, mess); + sharedMemory_setScanStatus(ERROR); + break; + } } } // end of scan - if (scan) { + if (scan && sharedMemory_getScanStatus() != ERROR) { sharedMemory_setScanStatus(IDLE); } return NULL; @@ -1917,7 +1923,9 @@ int set_num_frames(int file_des) { if (arg != numScanSteps) { ret = FAIL; sprintf(mess, - "Could not set number of frames %lld. In scan mode, it is number of steps %d\n", (long long unsigned int)arg, numScanSteps); + "Could not set number of frames %lld. In scan mode, it " + "is number of steps %d\n", + (long long unsigned int)arg, numScanSteps); LOG(logERROR, (mess)); } } else { @@ -2860,6 +2868,40 @@ int enable_ten_giga(int file_des) { return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); } +int validateAndSetAllTrimbits(int arg) { + int retval = -1; + +#if !defined(EIGERD) && !defined(MYTHEN3D) + functionNotImplemented(); +#else + // set + if (arg >= 0) { + if (arg > MAX_TRIMBITS_VALUE) { + ret = FAIL; + sprintf(mess, "Cannot set all trimbits. Range: 0 - %d\n", + MAX_TRIMBITS_VALUE); + LOG(logERROR, (mess)); + } else { + ret = setAllTrimbits(arg); +#ifdef EIGERD + // changes settings to undefined + if (getSettings() != UNDEFINED) { + setSettings(UNDEFINED); + LOG(logERROR, + ("Settings has been changed to undefined (change all " + "trimbits)\n")); + } +#endif + } + } + // get + retval = getAllTrimbits(); + LOG(logDEBUG1, ("All trimbits: %d\n", retval)); + validate(arg, retval, "set all trimbits", DEC); +#endif + return retval; +} + int set_all_trimbits(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2870,32 +2912,10 @@ int set_all_trimbits(int file_des) { return printSocketReadError(); LOG(logDEBUG1, ("Set all trmbits to %d\n", arg)); -#if !defined(EIGERD) && !defined(MYTHEN3D) - functionNotImplemented(); -#else - - // set - if (arg >= 0 && Server_VerifyLock() == OK) { - if (arg > MAX_TRIMBITS_VALUE) { - ret = FAIL; - sprintf(mess, "Cannot set all trimbits. Range: 0 - %d\n", - MAX_TRIMBITS_VALUE); - LOG(logERROR, (mess)); - } else { - ret = setAllTrimbits(arg); -#ifdef EIGERD - // changes settings to undefined - setSettings(UNDEFINED); - LOG(logERROR, ("Settings has been changed to undefined (change all " - "trimbits)\n")); -#endif - } + if ((arg >= 0 && Server_VerifyLock() == OK) || arg < 0) { + retval = validateAndSetAllTrimbits(arg); } - // get - retval = getAllTrimbits(); - LOG(logDEBUG1, ("All trimbits: %d\n", retval)); - validate(arg, retval, "set all trimbits", DEC); -#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); } @@ -4816,7 +4836,8 @@ int set_detector_position(int file_des) { int check_detector_idle() { enum runStatus status = getRunStatus(); - if (status != IDLE && status != RUN_FINISHED && status != STOPPED) { + if (status != IDLE && status != RUN_FINISHED && status != STOPPED && + status != ERROR) { ret = FAIL; sprintf(mess, "Cannot configure mac when detector is not idle. Detector at " @@ -7562,120 +7583,21 @@ int set_scan(int file_des) { sprintf(mess, "Invalid scan parameters\n"); LOG(logERROR, (mess)); } else { - // trimbit scan if (index == TRIMBIT_SCAN) { -#if !defined(EIGERD) && !defined(MYTHEN3D) - ret = FAIL; - sprintf(mess, - "Cannot enable trimbit scan. Not implemented for " - "this detector\n"); - LOG(logERROR, (mess)); -#else - if (start < 0 || start > MAX_TRIMBITS_VALUE || stop < 0 || - stop > MAX_TRIMBITS_VALUE) { - ret = FAIL; - sprintf(mess, "Invalid trimbits scan values\n"); - LOG(logERROR, (mess)); - } - // validated - else { - LOG(logINFOBLUE, ("Trimbit scan enabled\n")); - scanTrimbits = 1; - scanGlobalIndex = index; - scanSettleTime_ns = dacTime; -#ifdef EIGERD - // changing trimbits, settings to undefined - setSettings(UNDEFINED); - LOG(logERROR, ("Settings has been changed to undefined " - "(change all " - "trimbits)\n")); -#endif - } -#endif + LOG(logINFOBLUE, ("Trimbit scan enabled\n")); + scanTrimbits = 1; + scanGlobalIndex = index; + scanSettleTime_ns = dacTime; } // dac scan else { - if (start < 0 || start > getMaxDacSteps() || stop < 0 || - stop > getMaxDacSteps()) { - ret = FAIL; - sprintf(mess, "Invalid dac scan values\n"); - LOG(logERROR, (mess)); - } -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - else if (checkVLimitDacCompliant(start) == FAIL || - checkVLimitDacCompliant(stop) == FAIL) { - ret = FAIL; - sprintf(mess, - "Invalid scan dac values." - "Exceeds voltage limit %d.\n", - getVLimit()); - LOG(logERROR, (mess)); - } -#endif - else { - // validate allowed dac scans - switch (index) { - case HIGH_VOLTAGE: -#ifdef EIGERD - case IO_DELAY: -#elif CHIPTESTBOARDD - case ADC_VPP: - case V_POWER_A: - case V_POWER_B: - case V_POWER_C: - case V_POWER_D: - case V_POWER_IO: - case V_POWER_CHIP: - case V_LIMIT: -#elif MOENCHD - case ADC_VPP: - case V_LIMIT: -#endif - modeNotImplemented("Scan Dac Index", index); - break; - default: - break; - } - // validate dac according to detector type - if (ret == OK) { - enum DACINDEX dac = getDACIndex(index); - if (ret == FAIL) { - sprintf(mess, - "Cannot enable scan. Dac index %d not " - "implemented for " - "this detector for scanning\n", - (int)index); - LOG(logERROR, (mess)); - } - // validated - else { - LOG(logINFOBLUE, - ("Dac [%d] scan enabled\n", scanDac)); - scanTrimbits = 0; - scanGlobalIndex = index; - scanSettleTime_ns = dacTime; - scanDac = dac; -#ifdef EIGERD - // changing dac changes settings to undefined - switch (scanDac) { - 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 - } - } + getDACIndex(index); + if (ret == OK) { + LOG(logINFOBLUE, ("Dac [%d] scan enabled\n", index)); + scanTrimbits = 0; + scanGlobalIndex = index; + scanSettleTime_ns = dacTime; } } } @@ -7709,3 +7631,18 @@ int set_scan(int file_des) { } return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); } + +int get_scan_error_message(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + char retvals[MAX_STR_LENGTH]; + memset(retvals, 0, MAX_STR_LENGTH); + + LOG(logDEBUG1, ("Getting scan error message\n")); + + // get only + strcpy(retvals, scanErrMessage); + LOG(logDEBUG1, ("scan retval err message: [%s]\n", retvals)); + + return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals)); +} \ No newline at end of file diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index dfce564ac..e860dd692 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -401,6 +401,10 @@ class Detector { * receiver. Disabling scan sets number of frames to 1 */ void setScan(const defs::scanParameters t); + /** gets scan error message in case of error during scan in case of non + * blocking acquisition (startDetector, not acquire) */ + Result getScanErrorMessage(Positions pos = {}) const; + /************************************************** * * * Network Configuration (Detector<->Receiver) * diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 052fe1d25..857a9e838 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1039,7 +1039,8 @@ std::string CmdProxy::Scan(int action) { throw sls::RuntimeError("Unknown action"); } return os.str(); -} // namespace sls +} + /* Network Configuration (Detector<->Receiver) */ std::string CmdProxy::UDPDestinationIP(int action) { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index fd015bee5..def2ccdcb 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -738,6 +738,7 @@ class CmdProxy { {"startingfnum", &CmdProxy::startingfnum}, {"trigger", &CmdProxy::trigger}, {"scan", &CmdProxy::Scan}, + {"scanerrmsg", &CmdProxy::scanerrmsg}, /* Network Configuration (Detector<->Receiver) */ {"numinterfaces", &CmdProxy::numinterfaces}, @@ -1554,6 +1555,10 @@ class CmdProxy { trigger, sendSoftwareTrigger, "\n\t[Eiger] Sends software trigger signal to detector."); + GET_COMMAND(scanerrmsg, getScanErrorMessage, + "\n\tGets Scan error message if scan ended in error for non " + "blocking acquisitions."); + /* Network Configuration (Detector<->Receiver) */ INTEGER_COMMAND( diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index e2fe8dfe3..6eb4040bf 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -567,6 +567,10 @@ void Detector::setScan(const defs::scanParameters t) { pimpl->Parallel(&Module::setScan, {}, t); } +Result Detector::getScanErrorMessage(Positions pos) const { + return pimpl->Parallel(&Module::getScanErrorMessage, pos); +} + // Network Configuration (Detector<->Receiver) Result Detector::getNumberofUDPInterfaces(Positions pos) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 701d704f8..fa4cfe0c3 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -459,6 +459,12 @@ void Module::setScan(const defs::scanParameters t) { setNumberOfFrames(retval); } +std::string Module::getScanErrorMessage() { + char retval[MAX_STR_LENGTH]{}; + sendToDetector(F_GET_SCAN_ERROR_MESSAGE, nullptr, retval); + return retval; +} + // Network Configuration (Detector<->Receiver) int Module::getNumberofUDPInterfacesFromShm() { diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 36b230c41..53873be38 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -168,6 +168,7 @@ class Module : public virtual slsDetectorDefs { void sendSoftwareTrigger(); defs::scanParameters getScan(); void setScan(const defs::scanParameters t); + std::string getScanErrorMessage(); /************************************************** * * diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 42dc3bb98..8a12f37a3 100644 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -465,11 +465,11 @@ typedef struct { /** disable scan */ scanParameters() : enable(0), dacInd(DAC_0), startOffset(0), stopOffset(0), - stepSize(0), dacSettleTime_ns{10000} {} + stepSize(0), dacSettleTime_ns{0} {} /** enable scan */ scanParameters( dacIndex dac, int start, int stop, int step, - std::chrono::nanoseconds t = std::chrono::nanoseconds{10000}) + std::chrono::nanoseconds t = std::chrono::milliseconds{1}) : enable(1), dacInd(dac), startOffset(start), stopOffset(stop), stepSize(step) { dacSettleTime_ns = t.count(); diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index 431fa60df..c44dd4853 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -202,6 +202,7 @@ enum detFuncs { F_SET_PATTERN, F_GET_SCAN, F_SET_SCAN, + F_GET_SCAN_ERROR_MESSAGE, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -502,6 +503,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_PATTERN: return "F_SET_PATTERN"; case F_GET_SCAN: return "F_GET_SCAN"; case F_SET_SCAN: return "F_SET_SCAN"; + case F_GET_SCAN_ERROR_MESSAGE: return "F_GET_SCAN_ERROR_MESSAGE"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index b60344872..1f454d8f7 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -491,6 +491,10 @@ std::string ToString(const defs::dacIndex s) { return std::string("ibias_sfp"); case defs::TRIMBIT_SCAN: return std::string("trimbit_scan"); + case defs::HIGH_VOLTAGE: + return std::string("vhighvoltage"); + case defs::IO_DELAY: + return std::string("iodelay"); default: return std::string("Unknown"); } @@ -846,6 +850,11 @@ template <> defs::dacIndex StringTo(const std::string &s) { return defs::IBIAS_SFP; if (s == "trimbit_scan") return defs::TRIMBIT_SCAN; + if (s == "vhighvoltage") + return defs::HIGH_VOLTAGE; + if (s == "iodelay") + return defs::IO_DELAY; + throw sls::RuntimeError("Unknown dac Index " + s); }