From 775bde76c99ce68f02d716ddedff4d4521653c11 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 20 Feb 2019 09:34:55 +0100 Subject: [PATCH 1/6] ctb server: power regulator adjusted for precision --- slsDetectorServers/ctbDetectorServer/Makefile | 2 +- .../ctbDetectorServer/slsDetectorFunctionList.c | 16 ++++++++-------- .../ctbDetectorServer/slsDetectorServer_defs.h | 8 ++++---- slsDetectorServers/slsDetectorServer/common.h | 2 +- .../slsDetectorServer/slsDetectorServer_funcs.c | 2 +- .../slsDetector/slsDetectorCommand.cpp | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/Makefile b/slsDetectorServers/ctbDetectorServer/Makefile index 0fc48fd87..c9a810d32 100755 --- a/slsDetectorServers/ctbDetectorServer/Makefile +++ b/slsDetectorServers/ctbDetectorServer/Makefile @@ -1,6 +1,6 @@ CROSS = bfin-uclinux- CC = $(CROSS)gcc -CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER #-DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE +CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE LDLIBS += -lm -lstdc++ PROGS = ctbDetectorServer diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 1f8b40a69..bd191894d 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1215,7 +1215,8 @@ int getADCIndexFromDACIndex(enum DACINDEX ind) { } int isPowerValid(int val) { - if (val != 0 && (val < POWER_RGLTR_MIN || val > POWER_RGLTR_MAX)) { + // not power_rgltr_max because it is allowed only upto vchip max - 200 + if (val != 0 && (val != LTC2620_PWR_DOWN_VAL) && (val < POWER_RGLTR_MIN || val > (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT))) {//POWER_RGLTR_MAX)) { return 0; } return 1; @@ -1314,10 +1315,7 @@ void setPower(enum DACINDEX ind, int val) { // convert it to dac (power off is anyway done with power enable) if (val != LTC2620_PWR_DOWN_VAL) { FILE_LOG(logDEBUG1, ("Convert Power of %d mV to dac units\n", val)); -/* - val = (double)val * 0.95; - FILE_LOG(logDEBUG1, ("Convert new Power of %d mV to dac units\n", val)); -*/ + int dacval = -1; // convert voltage to dac if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_MAX_VAL, LTC2620_MIN_VAL, @@ -1326,11 +1324,13 @@ void setPower(enum DACINDEX ind, int val) { ind, val, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT)); return; } -/* + if (dacval > LTC2620_MAX_VAL) dacval = LTC2620_MAX_VAL; - FILE_LOG(logDEBUG1, ("Converted new dac val: %d\n", dacval)); -*/ + if (dacval < LTC2620_MIN_VAL) + dacval = LTC2620_MIN_VAL; + FILE_LOG(logDEBUG1, ("Adjusted for tolerance, hence within limits, new dac val: %d\n", dacval)); + // set and power on/ update dac FILE_LOG(logINFO, ("Setting P%d (DAC %d): %d dac (%d mV)\n", adcIndex, ind, dacval, val)); setDAC(ind, dacval, 0); diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h index 88393e1a4..3c44f5b5f 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h @@ -69,10 +69,10 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, #define HIGHVOLTAGE_MAX (200) // min dac val #define DAC_MIN_MV (0) #define DAC_MAX_MV (2500) -#define VCHIP_MIN_MV (1700) -#define VCHIP_MAX_MV (2700) // min dac val -#define POWER_RGLTR_MIN (600) -#define POWER_RGLTR_MAX (2500) // min dac val +#define VCHIP_MIN_MV (1673) +#define VCHIP_MAX_MV (2668) // min dac val +#define POWER_RGLTR_MIN (636) +#define POWER_RGLTR_MAX (2638) // min dac val (not vchip-max) because of dac conversions #define VCHIP_POWER_INCRMNT (200) /* Defines in the Firmware */ diff --git a/slsDetectorServers/slsDetectorServer/common.h b/slsDetectorServers/slsDetectorServer/common.h index 422f49967..a367b18ff 100755 --- a/slsDetectorServers/slsDetectorServer/common.h +++ b/slsDetectorServers/slsDetectorServer/common.h @@ -38,7 +38,7 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outpu } *outputValue = value; - FILE_LOG(logDEBUG1, (" Converted Ouput Value: %d\n", *outputValue)); + FILE_LOG(logDEBUG1, (" Converted Output Value: %d\n", *outputValue)); return OK; } diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index f4d27580c..b6325ae26 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -802,7 +802,7 @@ int set_dac(int file_des) { FILE_LOG(logERROR,(mess)); } else if (!isPowerValid(val)) { ret = FAIL; - sprintf(mess,"Could not set power. Power regulator %d should be between %d and %d mV\n", ind, POWER_RGLTR_MIN, POWER_RGLTR_MAX); + sprintf(mess,"Could not set power. Power regulator %d should be between %d and %d mV\n", ind, POWER_RGLTR_MIN, (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); FILE_LOG(logERROR,(mess)); } else { setPower(serverDacIndex, val); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 505e9f1b6..f37c9bd60 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1196,7 +1196,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page settings - - v_io [i] mv Sets/gets value for Vio on the new chiptest board. Must be in mV. \c Returns \c (int ["mV"]) + - v_io [i] mv Sets/gets value for Vio on the new chiptest board. Must be in mV. It should be the first power regulator to be set after server start up (fpga reset). To change again, reset fpga first. \c Returns \c (int ["mV"]) */ descrToFuncMap[i].m_pFuncName = "v_io"; // descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDAC; From 09546a8632bd1e10261ec5e47c5b2f9ab030e5cf Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 20 Feb 2019 15:36:34 +0100 Subject: [PATCH 2/6] ctb server: - allowed flags resetfpga and programfpga for moench and ctb - set a minimum voltage for vio as it powers the fpga (1200mV) - changed the min and max for vchip and power regulators due to tolerance - fixed pattern read function - fixed minor bugs with input of ctb patterns(waittime) and mode other than 1 - fixed calibration current register for i2c for tolerance (/1.2268) - fixed current readout of i2c - added digital, analog and normal readouts for flags --- .../slsDetectorFunctionList.c | 65 +++++++++--------- .../slsDetectorServer_defs.h | 1 + slsDetectorServers/slsDetectorServer/INA226.h | 67 ++++++------------- .../slsDetectorServer/LTC2620.h | 2 + .../slsDetectorFunctionList.h | 2 +- .../slsDetectorServer_funcs.c | 46 ++++++++----- .../slsDetector/slsDetector.cpp | 2 +- .../slsDetector/slsDetectorCommand.cpp | 2 +- 8 files changed, 88 insertions(+), 99 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index bd191894d..a6a42693d 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -523,6 +523,9 @@ void setupDetector() { INA226_CalibrateCurrentRegister(I2C_POWER_VD_DEVICE_ID); setVchip(VCHIP_MIN_MV); + // set vio to minimum for fpga to function + setPower(D_PWR_IO, VIO_MIN_MV); + // altera pll ALTERA_PLL_SetDefines(PLL_CNTRL_REG, PLL_PARAM_REG, PLL_CNTRL_RCNFG_PRMTR_RST_MSK, PLL_CNTRL_WR_PRMTR_MSK, PLL_CNTRL_PLL_RST_MSK, PLL_CNTRL_ADDR_MSK, PLL_CNTRL_ADDR_OFST); @@ -1214,9 +1217,11 @@ int getADCIndexFromDACIndex(enum DACINDEX ind) { } } -int isPowerValid(int val) { +int isPowerValid(enum DACINDEX ind, int val) { + int min = (ind == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN; + // not power_rgltr_max because it is allowed only upto vchip max - 200 - if (val != 0 && (val != LTC2620_PWR_DOWN_VAL) && (val < POWER_RGLTR_MIN || val > (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT))) {//POWER_RGLTR_MAX)) { + if (val != 0 && (val != LTC2620_PWR_DOWN_VAL) && (val < min || val > (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT))) { return 0; } return 1; @@ -1281,8 +1286,9 @@ void setPower(enum DACINDEX ind, int val) { FILE_LOG(logINFO, ("Setting Power to %d mV\n", val)); // validate value (already checked at tcp) - if (!isPowerValid(val)) { - FILE_LOG(logERROR, ("Invalid value of %d mV for Power %d. Is not between %d and %d mV\n", val, ind, POWER_RGLTR_MIN, POWER_RGLTR_MAX)); + if (!isPowerValid(ind, val)) { + FILE_LOG(logERROR, ("Invalid value of %d mV for Power %d. Is not between %d and %d mV\n", + val, ind, (ind == D_PWR_IO ? VIO_MIN_MV : POWER_RGLTR_MIN), POWER_RGLTR_MAX)); return; } @@ -1325,12 +1331,6 @@ void setPower(enum DACINDEX ind, int val) { return; } - if (dacval > LTC2620_MAX_VAL) - dacval = LTC2620_MAX_VAL; - if (dacval < LTC2620_MIN_VAL) - dacval = LTC2620_MIN_VAL; - FILE_LOG(logDEBUG1, ("Adjusted for tolerance, hence within limits, new dac val: %d\n", dacval)); - // set and power on/ update dac FILE_LOG(logINFO, ("Setting P%d (DAC %d): %d dac (%d mV)\n", adcIndex, ind, dacval, val)); setDAC(ind, dacval, 0); @@ -1725,12 +1725,12 @@ uint64_t writePatternClkControl(uint64_t word) { uint64_t readPatternWord(int addr) { // error (handled in tcp) if (addr < 0 || addr >= MAX_PATTERN_LENGTH) { - FILE_LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr %d. " - "Should be within %d\n", addr, MAX_PATTERN_LENGTH)); + FILE_LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr 0x%x. " + "Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH)); return -1; } - FILE_LOG(logDEBUG1, ("Reading Pattern - Word (addr:%d)\n", addr)); + FILE_LOG(logDEBUG1, ("Reading Pattern - Word (addr:0x%x)\n", addr)); uint32_t reg = PATTERN_CNTRL_REG; // overwrite with only addr @@ -1739,13 +1739,13 @@ uint64_t readPatternWord(int addr) { // set read strobe bus_w(reg, bus_r(reg) | PATTERN_CNTRL_RD_MSK); - // read value - uint64_t retval = get64BitReg(PATTERN_OUT_LSB_REG, PATTERN_OUT_MSB_REG); - FILE_LOG(logDEBUG1, ("Word(addr:%d): 0x%llx\n", addr, (long long int) retval)); - // unset read strobe bus_w(reg, bus_r(reg) & (~PATTERN_CNTRL_RD_MSK)); + // read value + uint64_t retval = get64BitReg(PATTERN_OUT_LSB_REG, PATTERN_OUT_MSB_REG); + FILE_LOG(logDEBUG1, ("Word(addr:0x%x): 0x%llx\n", addr, (long long int) retval)); + return retval; } @@ -1756,16 +1756,17 @@ uint64_t writePatternWord(int addr, uint64_t word) { // error (handled in tcp) if (addr < 0 || addr >= MAX_PATTERN_LENGTH) { - FILE_LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr %d. " - "Should be within %d\n", addr, MAX_PATTERN_LENGTH)); + FILE_LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr 0x%x. " + "Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH)); return -1; } - FILE_LOG(logINFO, ("Setting Pattern - Word (addr:%d, word:0x%llx)\n", addr, (long long int) word)); + FILE_LOG(logINFO, ("Setting Pattern - Word (addr:0x%x, word:0x%llx)\n", addr, (long long int) word)); uint32_t reg = PATTERN_CNTRL_REG; // write word set64BitReg(word, PATTERN_IN_LSB_REG, PATTERN_IN_MSB_REG); + FILE_LOG(logDEBUG1, ("Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(PATTERN_IN_LSB_REG, PATTERN_IN_MSB_REG))); // overwrite with only addr bus_w(reg, ((addr << PATTERN_CNTRL_ADDR_OFST) & PATTERN_CNTRL_ADDR_MSK)); @@ -1783,8 +1784,8 @@ int setPatternWaitAddress(int level, int addr) { // error (handled in tcp) if (addr >= (MAX_PATTERN_LENGTH + 1)) { - FILE_LOG(logERROR, ("Cannot set Pattern - Wait Address. Invalid addr %d. " - "Should be within %d\n", addr, MAX_PATTERN_LENGTH + 1)); + FILE_LOG(logERROR, ("Cannot set Pattern - Wait Address. Invalid addr 0x%x. " + "Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH + 1)); return -1; } @@ -1809,20 +1810,20 @@ int setPatternWaitAddress(int level, int addr) { mask = PATTERN_WAIT_2_ADDR_MSK; break; default: - FILE_LOG(logERROR, ("Cannot set Pattern - Wait Address. Invalid level %d. " + FILE_LOG(logERROR, ("Cannot set Pattern - Wait Address. Invalid level 0x%x. " "Should be between 0 and 2.\n", level)); return -1; } // set if (addr >= 0) { - FILE_LOG(logINFO, ("Setting Pattern - Wait Address (level:%d, addr:%d)\n", level, addr)); + FILE_LOG(logINFO, ("Setting Pattern - Wait Address (level:%d, addr:0x%x)\n", level, addr)); bus_w(reg, ((addr << offset) & mask)); } // get uint32_t regval = bus_r((reg & mask) >> offset); - FILE_LOG(logDEBUG1, ("Wait Address (level:%d, addr:%d)\n", level, regval)); + FILE_LOG(logDEBUG1, ("Wait Address (level:%d, addr:0x%x)\n", level, regval)); return regval; } @@ -1866,16 +1867,16 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) { // level 0-2, addr upto patternlength + 1 (checked at tcp) if ((level != -1) && (*startAddr >= 0 || *stopAddr > (MAX_PATTERN_LENGTH + 1))) { - FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, level:%d, startaddr:%d, stopaddr:%d). " - "Addr must be less than %d\n", + FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, level:%d, startaddr:0x%x, stopaddr:0x%x). " + "Addr must be less than 0x%x\n", level, *startAddr, *stopAddr, MAX_PATTERN_LENGTH + 1)); } //level -1, addr upto patternlength (checked at tcp) else if ((level == -1) && (*startAddr >= 0 || *stopAddr > MAX_PATTERN_LENGTH)) { - FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, complete pattern, stopaddr:%d). " - "Addr must be less than %d\n", + FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, complete pattern, stopaddr:0x%x). " + "Addr must be less than 0x%x\n", *startAddr, *stopAddr, MAX_PATTERN_LENGTH)); } @@ -1939,17 +1940,17 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) { // set start and stop addr if (*startAddr == -1) { *startAddr = ((bus_r(addr) >> startOffset) & startMask); - FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop Start Address (level:%d, startAddr:%d was -1)\n", + FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop Start Address (level:%d, startAddr:0x%x was -1)\n", level, *startAddr)); } if (*stopAddr == -1) { *stopAddr = ((bus_r(addr) >> stopOffset) & stopMask); - FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop Stop Address (level:%d, stopAddr:%d, was -1)\n", + FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop Stop Address (level:%d, stopAddr:0x%x, was -1)\n", level, *stopAddr)); } // writing start and stop addr - FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop (level:%d, startaddr:%d, stopaddr:%d)\n", + FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n", level, *startAddr, *stopAddr)); bus_w(addr, ((*startAddr << startOffset) & startMask) | ((*stopAddr << stopOffset) & stopMask)); } diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h index 3c44f5b5f..240ba3039 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h @@ -74,6 +74,7 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, #define POWER_RGLTR_MIN (636) #define POWER_RGLTR_MAX (2638) // min dac val (not vchip-max) because of dac conversions #define VCHIP_POWER_INCRMNT (200) +#define VIO_MIN_MV (1200) // for fpga to function /* Defines in the Firmware */ #define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo diff --git a/slsDetectorServers/slsDetectorServer/INA226.h b/slsDetectorServers/slsDetectorServer/INA226.h index 71ba30b2e..b7f2769ee 100755 --- a/slsDetectorServers/slsDetectorServer/INA226.h +++ b/slsDetectorServers/slsDetectorServer/INA226.h @@ -1,6 +1,7 @@ #pragma once #include "I2C.h" +#include "math.h" /** * To be defined in @@ -52,6 +53,9 @@ #define INA226_getConvertedCurrentUnits(shuntV, calibReg) ((double)shuntV * (double)calibReg / (double)2048) double INA226_Shunt_Resistor_Ohm = 0.0; +int INA226_Calibration_Register_Value = 0; + +#define INA226_CALIBRATION_CURRENT_TOLERANCE (1.2268) /** @@ -84,7 +88,11 @@ void INA226_CalibrateCurrentRegister(uint32_t deviceId) { FILE_LOG(logINFO, ("Calibrating Current Register for Device ID: 0x%x\n", deviceId)); // get calibration value based on shunt resistor uint16_t calVal = ((uint16_t)INA226_getCalibrationValue(INA226_Shunt_Resistor_Ohm)) & INA226_CALIBRATION_MSK; - FILE_LOG(logINFO, ("\tWriting to Calibration reg: 0x%0x\n", calVal)); + FILE_LOG(logINFO, ("\tCalculated calibration reg value: 0x%0x (%d)\n", calVal, calVal)); + + calVal = ((double)calVal / INA226_CALIBRATION_CURRENT_TOLERANCE) + 0.5; + FILE_LOG(logINFO, ("\tRealculated (for tolerance) calibration reg value: 0x%0x (%d)\n", calVal, calVal)); + INA226_Calibration_Register_Value = calVal; // calibrate current register I2C_Write(deviceId, INA226_CALIBRATION_REG, calVal); @@ -132,71 +140,38 @@ int INA226_ReadCurrent(uint32_t deviceId) { // read shunt voltage register FILE_LOG(logDEBUG1, (" Reading shunt voltage reg\n")); uint32_t shuntVoltageRegVal = I2C_Read(deviceId, INA226_SHUNT_VOLTAGE_REG); - FILE_LOG(logDEBUG1, (" shunt voltage reg: 0x%x\n", shuntVoltageRegVal)); + FILE_LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal)); // read it once more as this error has occured once if (shuntVoltageRegVal == 0xFFFF) { FILE_LOG(logDEBUG1, (" Reading shunt voltage reg again\n")); shuntVoltageRegVal = I2C_Read(deviceId, INA226_SHUNT_VOLTAGE_REG); - FILE_LOG(logDEBUG1, (" shunt voltage reg: 0x%x\n", shuntVoltageRegVal)); + FILE_LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal)); } - - // get absolute value and if negative - int negative = (shuntVoltageRegVal & INA226_SHUNT_NEGATIVE_MSK) ? 1: 0; - int shuntabsnV = shuntVoltageRegVal & INA226_SHUNT_ABS_VALUE_MSK; - FILE_LOG(logDEBUG1, (" negative: %d, absolute: 0x%x\n", negative, shuntabsnV)); - - // negative, convert absolute to 2s complement - if (negative) { - shuntabsnV = ((~shuntabsnV) + 1); - FILE_LOG(logDEBUG1, (" new absolute for negative (2's comple): 0x%x\n", shuntabsnV)); - } - - // calculate shunt voltage - int shuntVoltagenV = 0; - ConvertToDifferentRange(0, INA226_SHUNT_VOLTAGE_MX_STPS, - INA226_SHUNT_VOLTAGE_VMIN_NV, INA226_SHUNT_VOLTAGE_VMAX_NV, - shuntabsnV, &shuntVoltagenV); - // if negative, put the sign - if (negative) - shuntVoltagenV = -(shuntVoltagenV); - FILE_LOG(logDEBUG1, (" shunt voltage: %d nV\n", shuntVoltagenV)); - int shuntVoltageUV = shuntVoltagenV / 1000; - FILE_LOG(logDEBUG1, (" shunt voltage: %d uV\n\n", shuntVoltageUV)); - - // read calibration register - FILE_LOG(logDEBUG1, (" Reading calibration reg\n")); - uint32_t calibrationRegVal = I2C_Read(deviceId, INA226_CALIBRATION_REG); - FILE_LOG(logDEBUG1, (" calibration reg: 0x%08x\n\n", calibrationRegVal)); - - // read it once more as this error has occured once - if (calibrationRegVal == 0xFFFF) { - FILE_LOG(logDEBUG1, (" Reading calibration reg again\n")); - calibrationRegVal = I2C_Read(deviceId, INA226_CALIBRATION_REG); - FILE_LOG(logDEBUG1, (" calibration reg: 0x%x\n", calibrationRegVal)); - } - // value for current - int retval = INA226_getConvertedCurrentUnits(shuntVoltageUV, calibrationRegVal); + int retval = INA226_getConvertedCurrentUnits(shuntVoltageRegVal, INA226_Calibration_Register_Value); FILE_LOG(logDEBUG1, (" current unit value: %d\n", retval)); - FILE_LOG(logDEBUG1, (" To TEST: should be same as curent unit value\n" - " Reading current reg\n")); + + // reading directly the current reg + FILE_LOG(logDEBUG1, (" Reading current reg\n")); int cuurentRegVal = I2C_Read(deviceId, INA226_CURRENT_REG); - FILE_LOG(logDEBUG1, (" current reg: 0x%x\n", cuurentRegVal)); + FILE_LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal)); // read it once more as this error has occured once if (cuurentRegVal >= 0xFFF0) { FILE_LOG(logDEBUG1, (" Reading current reg again\n")); cuurentRegVal = I2C_Read(deviceId, INA226_CURRENT_REG); - FILE_LOG(logDEBUG1, (" current reg: 0x%x\n", cuurentRegVal)); + FILE_LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal)); } + // should be the same + FILE_LOG(logDEBUG1, (" ===============current reg: %d, current unit cal:%d=================================\n", cuurentRegVal, retval)); // current in uA - int currentuA = retval * INA226_CURRENT_IMIN_UA; + int currentuA = cuurentRegVal * INA226_CURRENT_IMIN_UA; FILE_LOG(logDEBUG1, (" current: %d uA\n", currentuA)); // current in mA - int currentmA = currentuA / 1000; + int currentmA = (currentuA / 1000.00) + 0.5; FILE_LOG(logDEBUG1, (" current: %d mA\n", currentmA)); FILE_LOG(logINFO, ("Current via I2C (Device: 0x%x): %d mA\n", deviceId, currentmA)); diff --git a/slsDetectorServers/slsDetectorServer/LTC2620.h b/slsDetectorServers/slsDetectorServer/LTC2620.h index 560f6e724..77cd63346 100755 --- a/slsDetectorServers/slsDetectorServer/LTC2620.h +++ b/slsDetectorServers/slsDetectorServer/LTC2620.h @@ -200,12 +200,14 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) { */ void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) { FILE_LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex)); + FILE_LOG(logDEBUG1, (" ================================================\n")); // ctb if (LTC2620_Ndac > LTC2620_NUMCHANNELS) LTC2620_SetDaisy(cmd, data, dacaddr, chipIndex); // others else LTC2620_SetSingle(cmd, data, dacaddr); + FILE_LOG(logDEBUG1, (" ================================================\n")); } diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h index b432d6433..b6b3985d8 100644 --- a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h @@ -178,7 +178,7 @@ void setVchip(int val); int getVChipToSet(enum DACINDEX ind, int val); int getDACIndexFromADCIndex(enum ADCINDEX ind); int getADCIndexFromDACIndex(enum DACINDEX ind); -int isPowerValid(int val); +int isPowerValid(enum DACINDEX ind, int val); int getPower(); void setPower(enum DACINDEX ind, int val); void powerOff(); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index b6325ae26..576581ef6 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -800,9 +800,10 @@ int set_dac(int file_des) { ret = FAIL; sprintf(mess,"Could not set power. Power regulator %d exceeds voltage limit %d.\n", ind, getVLimit()); FILE_LOG(logERROR,(mess)); - } else if (!isPowerValid(val)) { + } 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, POWER_RGLTR_MIN, (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); + 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)); FILE_LOG(logERROR,(mess)); } else { setPower(serverDacIndex, val); @@ -1795,7 +1796,7 @@ int set_readout_flags(int file_des) { return printSocketReadError(); FILE_LOG(logDEBUG1, ("Setting readout flags to %d\n", arg)); -#ifndef EIGERD +#if (!defined(EIGERD)) && (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD)) functionNotImplemented(); #else // set & get @@ -1809,6 +1810,11 @@ int set_readout_flags(int file_des) { case SAFE: case SHOW_OVERFLOW: case NOOVERFLOW: +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + case NORMAL_READOUT: + case DIGITAL_ONLY: + case ANALOG_AND_DIGITAL: +#endif retval = setReadOutFlags(arg); FILE_LOG(logDEBUG1, ("Read out flags: 0x%x\n", retval)); validate((int)arg, (int)(retval & arg), "set readout flag", HEX); @@ -2524,13 +2530,14 @@ int set_ctb_pattern(int file_des) { #else int addr = (int)args[0]; uint64_t word = args[1]; + FILE_LOG(logDEBUG1, ("addr:0x%x word:0x%llx\n", addr, word)); if ((word == -1) || (Server_VerifyLock() == OK)) { // address for set word should be valid (if not -1 or -2, it goes to setword) if (addr < -2 || addr > MAX_PATTERN_LENGTH) { ret = FAIL; - sprintf(mess, "Cannot set Pattern (Word, addr:%d). Addr must be less than %d\n", + sprintf(mess, "Cannot set Pattern (Word, addr:0x%x). Addr must be less than 0x%x\n", addr, MAX_PATTERN_LENGTH); FILE_LOG(logERROR, (mess)); } else { @@ -2580,6 +2587,7 @@ int set_ctb_pattern(int file_des) { int startAddr = (int)args[1]; int stopAddr = (int)args[2]; int numLoops = (int)args[3]; + FILE_LOG(logDEBUG1, ("loopLevel:%d startAddr:0x%x stopAddr:0x%x numLoops:%d word:0x%llx\n", loopLevel, startAddr, stopAddr, numLoops)); if (loopLevel < -1 || loopLevel > 2) { // -1 complete pattern ret = FAIL; @@ -2590,8 +2598,8 @@ int set_ctb_pattern(int file_des) { // level 0-2, addr upto patternlength + 1 else if ((loopLevel != -1) && (startAddr > (MAX_PATTERN_LENGTH + 1) || stopAddr > (MAX_PATTERN_LENGTH + 1))) { ret = FAIL; - sprintf(mess, "Cannot set Pattern (Pattern Loop, level:%d, startaddr:%d, stopaddr:%d). " - "Addr must be less than %d\n", + sprintf(mess, "Cannot set Pattern (Pattern Loop, level:%d, startaddr:0x%x, stopaddr:0x%x). " + "Addr must be less than 0x%x\n", loopLevel, startAddr, stopAddr, MAX_PATTERN_LENGTH + 1); FILE_LOG(logERROR, (mess)); } @@ -2599,8 +2607,8 @@ int set_ctb_pattern(int file_des) { //level -1, addr upto patternlength else if ((loopLevel == -1) && (startAddr > MAX_PATTERN_LENGTH || stopAddr > MAX_PATTERN_LENGTH)) { ret = FAIL; - sprintf(mess, "Cannot set Pattern (Pattern Loop, complete pattern, startaddr:%d, stopaddr:%d). " - "Addr must be less than %d\n", + sprintf(mess, "Cannot set Pattern (Pattern Loop, complete pattern, startaddr:0x%x, stopaddr:0x%x). " + "Addr must be less than 0x%x\n", startAddr, stopAddr, MAX_PATTERN_LENGTH); FILE_LOG(logERROR, (mess)); } @@ -2618,7 +2626,7 @@ int set_ctb_pattern(int file_des) { // mode 2: wait address - else if (mode == 1) { + else if (mode == 2) { // receive arguments uint64_t args[2] = {-1, -1}; if (receiveData(file_des, args, sizeof(args), INT64) < 0) @@ -2631,15 +2639,16 @@ int set_ctb_pattern(int file_des) { #else int loopLevel = (int)args[0]; int addr = (int)args[1]; + FILE_LOG(logDEBUG1, ("loopLevel:%d addr:0x%x\n", loopLevel, addr)); if ((addr == -1) || (Server_VerifyLock() == OK)) { if (loopLevel < 0 || loopLevel > 2) { ret = FAIL; - sprintf(mess, "Pattern (Wait Address) Level (%d) is not implemented for this detector\n", loopLevel); + sprintf(mess, "Pattern (Wait Address) Level (0x%x) is not implemented for this detector\n", loopLevel); FILE_LOG(logERROR,(mess)); } else if (addr > (MAX_PATTERN_LENGTH + 1)) { ret = FAIL; - sprintf(mess, "Cannot set Pattern (Wait Address, addr:%d). Addr must be less than %d\n", + sprintf(mess, "Cannot set Pattern (Wait Address, addr:0x%x). Addr must be less than 0x%x\n", addr, MAX_PATTERN_LENGTH + 1); FILE_LOG(logERROR, (mess)); } else { @@ -2660,7 +2669,7 @@ int set_ctb_pattern(int file_des) { // mode 3: wait time - else if (mode == 1) { + else if (mode == 3) { // receive arguments uint64_t args[2] = {-1, -1}; if (receiveData(file_des, args, sizeof(args), INT64) < 0) @@ -2671,8 +2680,9 @@ int set_ctb_pattern(int file_des) { functionNotImplemented(); return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); #else - int loopLevel = (int)args[1]; - uint64_t timeval = (int)args[2]; + int loopLevel = (int)args[0]; + uint64_t timeval = args[1]; + FILE_LOG(logDEBUG1, ("loopLevel:%d timeval:0x%lld\n", loopLevel, timeval)); if ((timeval == -1) || (Server_VerifyLock() == OK)) { if (loopLevel < 0 || loopLevel > 2) { @@ -2684,9 +2694,9 @@ int set_ctb_pattern(int file_des) { memset(tempName, 0, 100); sprintf(tempName, "Pattern (Wait Time, Level:%d)", loopLevel); - FILE_LOG(logDEBUG1, ("Setting %s to 0x%llx\n", tempName, (long long int)timeval)); + FILE_LOG(logDEBUG1, ("Setting %s to 0x%lld\n", tempName, (long long int)timeval)); retval64 = setPatternWaitTime(loopLevel, timeval); - FILE_LOG(logDEBUG1, ("%s: 0x%llx\n", tempName, (long long int)retval64)); + FILE_LOG(logDEBUG1, ("%s: 0x%lld\n", tempName, (long long int)retval64)); validate64(timeval, retval64, tempName, HEX); } } @@ -2985,7 +2995,7 @@ int program_fpga(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); -#ifndef JUNGFRAUD +#if (!defined(JUNGFRAUD)) && (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD)) //to receive any arguments int n = 1; while (n > 0) @@ -3111,7 +3121,7 @@ int reset_fpga(int file_des) { memset(mess, 0, sizeof(mess)); FILE_LOG(logDEBUG1, ("Reset FPGA\n")); -#ifndef JUNGFRAUD +#if (!defined(JUNGFRAUD)) && (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD)) functionNotImplemented(); #else // only set diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 9fd0bcd03..cbc517ed8 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -4865,7 +4865,7 @@ uint64_t slsDetector::setCTBWord(int addr, uint64_t word) { int mode = 0; // sets word uint64_t args[3] = {(uint64_t)mode, (uint64_t)addr, word}; uint64_t retval = -1; - FILE_LOG(logINFO) << "Setting CTB word, addr: 0x" << std::hex << addr << ", word: 0x" << word << std::dec; + FILE_LOG(logDEBUG1) << "Setting CTB word, addr: 0x" << std::hex << addr << ", word: 0x" << word << std::dec; if (thisDetector->onlineFlag == ONLINE_FLAG) { auto client = sls::ClientSocket(thisDetector->hostname, thisDetector->controlPort); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index f37c9bd60..2ae77b080 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1196,7 +1196,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page settings - - v_io [i] mv Sets/gets value for Vio on the new chiptest board. Must be in mV. It should be the first power regulator to be set after server start up (fpga reset). To change again, reset fpga first. \c Returns \c (int ["mV"]) + - v_io [i] mv Sets/gets value for Vio on the new chiptest board. Must be in mV. It should be minimum 1200 mV and must be the first power regulator to be set after server start up (fpga reset). To change again, reset fpga first. \c Returns \c (int ["mV"]) */ descrToFuncMap[i].m_pFuncName = "v_io"; // descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDAC; From a4f1b7670f7a6e5bfae9f34f561350643eab6ca5 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 21 Feb 2019 09:37:49 +0100 Subject: [PATCH 3/6] ctb server bug fixes:update client, get period left, getid(api and serial number), restrict setting vchip, allow write adc --- .../slsDetectorFunctionList.c | 5 +++ .../slsDetectorServer_funcs.c | 37 ++++++++++++------- .../slsDetector/slsDetector.cpp | 33 +++++++++++++---- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index a6a42693d..2292d7c7b 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -970,6 +970,11 @@ int64_t getTimeLeft(enum timerIndex ind){ FILE_LOG(logINFO, ("Getting number of frames left: %lld\n",(long long int)retval)); break; + case FRAME_PERIOD: + retval = get64BitReg(PERIOD_LEFT_LSB_REG, PERIOD_LEFT_MSB_REG) / (1E-3 * clkDivider[ADC_CLK]); + FILE_LOG(logINFO, ("Getting period left: %lldns\n", (long long int)retval)); + break; + case DELAY_AFTER_TRIGGER: retval = get64BitReg(DELAY_LEFT_LSB_REG, DELAY_LEFT_MSB_REG) / (1E-3 * clkDivider[ADC_CLK]); FILE_LOG(logINFO, ("Getting delay left: %lldns\n", (long long int)retval)); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 576581ef6..4085604bd 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -501,7 +501,7 @@ int get_id(int file_des) { // get switch (arg) { -#if defined(EIGERD) || defined(JUNGFRAUD) +#ifndef GOTTHARDD case SOFTWARE_FIRMWARE_API_VERSION: case DETECTOR_SERIAL_NUMBER: #endif @@ -818,6 +818,10 @@ int set_dac(int file_des) { 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"); + FILE_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"); @@ -829,6 +833,7 @@ int set_dac(int file_des) { } else { setVchip(val); } + */ } retval = getVchip(); FILE_LOG(logDEBUG1, ("Vchip: %d\n", retval)); @@ -1551,7 +1556,7 @@ int set_timer(int file_des) { case FRAME_PERIOD: case CYCLES_NUMBER: case SAMPLES: -#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) +#ifndef EIGERD case DELAY_AFTER_TRIGGER: #endif retval = setTimer(ind, tns); @@ -1696,6 +1701,7 @@ int get_time_left(int file_des) { case ACTUAL_TIME: case MEASUREMENT_TIME: case FRAME_NUMBER: + case FRAME_PERIOD: case DELAY_AFTER_TRIGGER: case CYCLES_NUMBER: #elif MOENCHD @@ -1704,6 +1710,7 @@ int get_time_left(int file_des) { case ACTUAL_TIME: case MEASUREMENT_TIME: case FRAME_NUMBER: + case FRAME_PERIOD: case DELAY_AFTER_TRIGGER: case CYCLES_NUMBER: #endif @@ -1796,7 +1803,7 @@ int set_readout_flags(int file_des) { return printSocketReadError(); FILE_LOG(logDEBUG1, ("Setting readout flags to %d\n", arg)); -#if (!defined(EIGERD)) && (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD)) +#if defined(JUNGFRAUD) || defined(GOTTHARDD) functionNotImplemented(); #else // set & get @@ -1874,7 +1881,7 @@ int set_roi(int file_des) { } } -#if !defined(GOTTHARDD) && !defined(CHIPTESTBOARDD) && !defined(MOENCHD) +#if defined(JUNGFRAUD) || defined(EIGERD) functionNotImplemented(); #else // set & get @@ -2120,9 +2127,11 @@ int send_update(int file_des) { n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); +#if defined(EIGERD) || defined(JUNGFRAUD) || defined(GOTTHARDD) i32 = (int)getSettings(); n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); +#endif #ifdef EIGERD i32 = getThresholdEnergy(GET_FLAG); @@ -2134,7 +2143,7 @@ int send_update(int file_des) { n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); -#ifndef CHIPTESTBOARDD +#if defined(EIGERD) || defined(JUNGFRAUD) || defined(GOTTHARDD) i64 = setTimer(ACQUISITION_TIME,GET_FLAG); n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); @@ -2164,16 +2173,18 @@ int send_update(int file_des) { n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); -#ifdef CHIPTESTBOARDD - i64 = setTimer(SAMPLES,GET_FLAG); - n = sendData(file_des,&i64,sizeof(i64),INT64); - if (n < 0) return printSocketReadError(); - +#if defined(EIGERD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) i32 = setReadOutFlags(GET_READOUT_FLAGS); n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); #endif +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + i64 = setTimer(SAMPLES,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); + if (n < 0) return printSocketReadError(); +#endif + if (lockStatus == 0) { strcpy(lastClientIP,thisClientIP); } @@ -2731,7 +2742,7 @@ int write_adc_register(int file_des) { #ifndef VIRTUAL // only set if (Server_VerifyLock() == OK) { -#ifdef JUNGFRAUD +#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) AD9257_Set(addr, val); #elif GOTTHARDD if (getBoardRevision() == 1) { @@ -2995,7 +3006,7 @@ int program_fpga(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); -#if (!defined(JUNGFRAUD)) && (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD)) +#if defined(EIGERD) || defined(GOTTHARDD) //to receive any arguments int n = 1; while (n > 0) @@ -3121,7 +3132,7 @@ int reset_fpga(int file_des) { memset(mess, 0, sizeof(mess)); FILE_LOG(logDEBUG1, ("Reset FPGA\n")); -#if (!defined(JUNGFRAUD)) && (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD)) +#if defined(EIGERD) || defined(GOTTHARDD) functionNotImplemented(); #else // only set diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index cbc517ed8..1dadec3b7 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1033,28 +1033,37 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) { n += client.receiveData(lastClientIP, sizeof(lastClientIP)); FILE_LOG(logDEBUG1) << "Updating detector last modified by " << lastClientIP; + // dr n += client.receiveData(&i32, sizeof(i32)); thisDetector->dynamicRange = i32; + // databytes n += client.receiveData(&i32, sizeof(i32)); thisDetector->dataBytes = i32; - n += client.receiveData(&i32, sizeof(i32)); - thisDetector->currentSettings = (detectorSettings)i32; + // settings + if ((thisDetector->myDetectorType != CHIPTESTBOARD) && (thisDetector->myDetectorType != MOENCH)) { + n += client.receiveData(&i32, sizeof(i32)); + thisDetector->currentSettings = (detectorSettings)i32; + } + // threshold if (thisDetector->myDetectorType == EIGER) { n += client.receiveData(&i32, sizeof(i32)); thisDetector->currentThresholdEV = i32; } + // frame number n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[FRAME_NUMBER] = i64; - if (thisDetector->myDetectorType != CHIPTESTBOARD) { + // exptime + if ((thisDetector->myDetectorType != CHIPTESTBOARD) && (thisDetector->myDetectorType != MOENCH)) { n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[ACQUISITION_TIME] = i64; } + // subexptime, subdeadtime if (thisDetector->myDetectorType == EIGER) { n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME] = i64; @@ -1063,29 +1072,37 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) { thisDetector->timerValue[SUBFRAME_DEADTIME] = i64; } + // period n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[FRAME_PERIOD] = i64; + // delay if (thisDetector->myDetectorType != EIGER) { n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[DELAY_AFTER_TRIGGER] = i64; } + // cycles n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[CYCLES_NUMBER] = i64; - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + // readout flags + if (thisDetector->myDetectorType == EIGER || + thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { + n += client.receiveData(&i32, sizeof(i32)); + thisDetector->roFlags = (readOutFlags)i32; + } + + // samples + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { n += client.receiveData(&i64, sizeof(i64)); if (i64 >= 0) { thisDetector->timerValue[SAMPLES] = i64; } - - n += client.receiveData(&i32, sizeof(i32)); - thisDetector->roFlags = (readOutFlags)i32; - getTotalNumberOfChannels(); } + if (!n) { FILE_LOG(logERROR) << "Could not update detector, received 0 bytes"; } From 617f3d26001d84bb14b383655cb0938dc8f317a7 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 21 Feb 2019 15:56:51 +0100 Subject: [PATCH 4/6] ctb server: modified program fpag in case of errors --- slsDetectorServers/ctbDetectorServer/Makefile | 4 ++-- slsDetectorServers/ctbDetectorServer/gitInfo.txt | 10 +++++----- slsDetectorServers/ctbDetectorServer/gitInfoCtb.h | 8 ++++---- .../slsDetectorServer/slsDetectorServer.c | 2 +- .../slsDetectorServer/slsDetectorServer_funcs.c | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/Makefile b/slsDetectorServers/ctbDetectorServer/Makefile index c9a810d32..099b148f6 100755 --- a/slsDetectorServers/ctbDetectorServer/Makefile +++ b/slsDetectorServers/ctbDetectorServer/Makefile @@ -1,6 +1,6 @@ CROSS = bfin-uclinux- CC = $(CROSS)gcc -CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE +CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER #-DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE LDLIBS += -lm -lstdc++ PROGS = ctbDetectorServer @@ -28,4 +28,4 @@ clean: rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb - \ No newline at end of file + diff --git a/slsDetectorServers/ctbDetectorServer/gitInfo.txt b/slsDetectorServers/ctbDetectorServer/gitInfo.txt index 9bad94956..13a20eab9 100644 --- a/slsDetectorServers/ctbDetectorServer/gitInfo.txt +++ b/slsDetectorServers/ctbDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/ctbDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: c93f88b7e5afe231ec43c47d60278c6acdb520af -Revision: 19 -Branch: refactor +Repsitory UUID: a4f1b7670f7a6e5bfae9f34f561350643eab6ca5 +Revision: 23 +Branch: ctbBugFixes Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4333 -Last Changed Date: 2019-02-20 08:12:50.000000002 +0100 ./RegisterDefs.h +Last Changed Rev: 4340 +Last Changed Date: 2019-02-21 11:22:00.000000002 +0100 ./Makefile diff --git a/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h b/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h index d8a4de296..01768d0b3 100644 --- a/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h +++ b/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "c93f88b7e5afe231ec43c47d60278c6acdb520af" +#define GITREPUUID "a4f1b7670f7a6e5bfae9f34f561350643eab6ca5" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4333 -#define GITDATE 0x20190220 -#define GITBRANCH "refactor" +#define GITREV 0x4340 +#define GITDATE 0x20190221 +#define GITBRANCH "ctbBugFixes" diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c index 9d0639af9..4bd9e1233 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c @@ -63,7 +63,7 @@ int main(int argc, char *argv[]){ FILE_LOG(logINFO, ("Detected phase shift of %d\n", phaseShift)); } #endif -#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) +#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) else if(!strcasecmp(argv[i],"-update")){ FILE_LOG(logINFO, ("Detected update mode\n")); debugflag = PROGRAMMING_MODE; diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 4085604bd..eccbe61df 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -63,7 +63,7 @@ void init_detector() { #endif if (isControlServer) { basictests(); -#ifdef JUNGFRAUD +#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) if (debugflag != PROGRAMMING_MODE) #endif initControlServer(); @@ -91,7 +91,7 @@ int decode_function(int file_des) { FILE_LOG(logDEBUG3, ("Received %d bytes\n", n )); // jungfrau in programming mode -#ifdef JUNGFRAUD +#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) if ((debugflag == PROGRAMMING_MODE) && (fnum != F_PROGRAM_FPGA) && (fnum != F_GET_DETECTOR_TYPE) && @@ -2096,7 +2096,7 @@ int set_port(int file_des) { int update_client(int file_des) { ret = FORCE_UPDATE; memset(mess, 0, sizeof(mess)); -#ifdef JUNGFRAUD +#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) if (debugflag == PROGRAMMING_MODE) { ret = OK; } @@ -3099,7 +3099,7 @@ int program_fpga(int file_des) { } } printf("\n"); - FILE_LOG(logINFO, ("Done copying program\n")); + FILE_LOG(logINFO, ("Done copying program or due to failure earlier\n")); // closing file pointer to flash and informing FPGA stopWritingFPGAprogram(fp); @@ -3112,7 +3112,7 @@ int program_fpga(int file_des) { FILE_LOG(logDEBUG1, ("Done with program receiving command\n")); - if (isControlServer) { + if (ret != FAIL && isControlServer) { basictests(); initControlServer(); } From 421dbdb9b58054f839ef6de8a86c16641af9e905 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 21 Feb 2019 16:00:40 +0100 Subject: [PATCH 5/6] ctb server: including moench as well for programfpga and other client ctb implementations --- .../slsDetector/slsDetector.cpp | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 1dadec3b7..aea87f3b5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -84,6 +84,9 @@ int slsDetector::checkDetectorVersionCompatibility() { case CHIPTESTBOARD: arg = APICTB; break; + case MOENCH: + arg = APIMOENCH; + break; default: FILE_LOG(logERROR) << "Check version compatibility is not implemented for this detector"; setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY)); @@ -290,6 +293,7 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL list.nGappixelsY = 0; break; case CHIPTESTBOARD: + case MOENCH: list.nChanX = 36; list.nChanY = 1; list.nChipX = 1; @@ -420,6 +424,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) { thisDetector->receiver_framesPerFile = JFRAU_MAX_FRAMES_PER_FILE; break; case CHIPTESTBOARD: + case MOENCH: thisDetector->receiver_framesPerFile = JFRAU_MAX_FRAMES_PER_FILE; break; default: @@ -455,7 +460,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) { thisDetector->dynamicRange / 8; // special for jctb - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { getTotalNumberOfChannels(); } @@ -735,7 +740,7 @@ std::string slsDetector::getDetectorTypeAsString() { int slsDetector::getTotalNumberOfChannels() { FILE_LOG(logDEBUG1) << "Get total number of channels"; - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { if (thisDetector->roFlags & DIGITAL_ONLY) { thisDetector->nChan[X] = 4; } else if (thisDetector->roFlags & ANALOG_AND_DIGITAL) { @@ -1187,6 +1192,10 @@ int slsDetector::writeConfigurationFile(std::ofstream &outfile, multiSlsDetector case CHIPTESTBOARD: names.emplace_back("vhighvoltage"); break; + case MOENCH: + names.emplace_back("powerchip"); + names.emplace_back("vhighvoltage"); + break; default: FILE_LOG(logERROR) << "Unknown detector type " << thisDetector->myDetectorType; setErrorMask((getErrorMask()) | (OTHER_ERROR_CODE)); @@ -2049,7 +2058,7 @@ int slsDetector::setDynamicRange(int n) { (thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * retval / 8; - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { getTotalNumberOfChannels(); } FILE_LOG(logDEBUG1) << "Data bytes " << thisDetector->dataBytes; @@ -2383,7 +2392,7 @@ std::string slsDetector::setReceiver(const std::string &receiverIP) { thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]); setTimer(SUBFRAME_DEADTIME, thisDetector->timerValue[SUBFRAME_DEADTIME]); } - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { setTimer(SAMPLES, thisDetector->timerValue[SAMPLES]); } setDynamicRange(thisDetector->dynamicRange); @@ -3032,7 +3041,7 @@ int slsDetector::setROI(int n, ROI roiLimits[]) { int ret = sendROI(n, roiLimits); if(ret==FAIL) setErrorMask((getErrorMask())|(COULDNOT_SET_ROI)); - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { getTotalNumberOfChannels(); } return ret; @@ -3041,7 +3050,7 @@ int slsDetector::setROI(int n, ROI roiLimits[]) { slsDetectorDefs::ROI *slsDetector::getROI(int &n) { sendROI(-1, nullptr); n = thisDetector->nROI; - if (thisDetector->myDetectorType == CHIPTESTBOARD) { + if (thisDetector->myDetectorType == CHIPTESTBOARD || thisDetector->myDetectorType == MOENCH) { getTotalNumberOfChannels(); } return thisDetector->roiLimits; @@ -3499,7 +3508,8 @@ int slsDetector::setStoragecellStart(int pos) { int slsDetector::programFPGA(const std::string &fname) { // only jungfrau implemented (client processing, so check now) - if (thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != CHIPTESTBOARD) { + if (thisDetector->myDetectorType != JUNGFRAU && + thisDetector->myDetectorType != CHIPTESTBOARD && thisDetector->myDetectorType != MOENCH) { FILE_LOG(logERROR) << "Not implemented for this detector"; setErrorMask((getErrorMask()) | (PROGRAMMING_ERROR)); return FAIL; @@ -3528,7 +3538,7 @@ int slsDetector::programFPGA(const std::string &fname) { } // create temp destination file - char destfname[] = "/tmp/Jungfrau_MCB.XXXXXX"; + char destfname[] = "/tmp/SLS_DET_MCB.XXXXXX"; int dst = mkstemp(destfname); // create temporary file and open it in r/w if (dst == -1) { FILE_LOG(logERROR) << "Could not create destination file in /tmp for programming: " << destfname; From f5244faa0232c6edff7db8d6c385a0092d64a994 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 21 Feb 2019 16:01:24 +0100 Subject: [PATCH 6/6] moench: adding enums for zmq parameters, needs modification in naming --- .../multiSlsDetector/multiSlsDetector.cpp | 47 ++++++++++ .../multiSlsDetector/multiSlsDetector.h | 24 +++++ .../slsDetector/slsDetectorCommand.cpp | 90 ++++++++++++++++++- .../slsDetector/slsDetectorCommand.h | 3 +- .../slsDetector/slsDetectorUsers.cpp | 13 ++- .../slsDetector/slsDetectorUsers.h | 36 +++++--- slsSupportLib/include/sls_detector_defs.h | 80 +++++++++++++++++ 7 files changed, 273 insertions(+), 20 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 934ff5ac1..0b88fc87a 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1955,6 +1955,53 @@ std::string multiSlsDetector::getAdditionalJsonParameter(const std::string &key, return sls::concatenateIfDifferent(r); } + +int multiSlsDetector::setDetectorMinMaxEnergyThreshold(const int index, int value, int detPos) { + std::string parameter = (index ? "emax" : "emin"); + + std::string result; + if (value < 0) { + result = getAdditionalJsonParameter(parameter, detPos); + } else { + result = setAdditionalJsonParameter(parameter, std::to_string(value), detPos); + } + + // convert to integer + try { + return stoi(result); + } + // not found or cannot scan integer + catch(...) { + return -1; + } +} + +int multiSlsDetector::setFrameMode(frameModeType value, int detPos) { + std::string parameter = "frameMode"; + std::string result; + + if (value == GET_FRAME_MODE) { + result = getAdditionalJsonParameter(parameter, detPos); + } else { + result = setAdditionalJsonParameter(parameter, getFrameModeType(value), detPos); + } + + return getFrameModeType(result); +} + +int multiSlsDetector::setDetectorMode(detectorModeType value, int detPos) { + std::string parameter = "detectorMode"; + std::string result; + + if (value == GET_DETECTOR_MODE) { + result = getAdditionalJsonParameter(parameter, detPos); + } else { + result = setAdditionalJsonParameter(parameter, getDetectorModeType(value), detPos); + } + + return getDetectorModeType(result); +} + int multiSlsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize, int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index fc17bcc50..2c62a579b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1087,6 +1087,30 @@ class multiSlsDetector : public virtual slsDetectorDefs, */ std::string getAdditionalJsonParameter(const std::string& key, int detPos = -1); + /** + * Sets the detector minimum/maximum energy threshold in processor (for Moench only) + * @param index 0 for emin, antyhing else for emax + * @param v value to set (-1 gets) + * @returns detector minimum/maximum energy threshold (-1 for not found or error in computing json parameter value) + */ + int setDetectorMinMaxEnergyThreshold(const int index, int value, int detPos = -1); + + /** + * Sets the frame mode in processor (Moench only) + * @param value frameModeType (-1 gets) + * @param detPos -1 for all detectors in list or specific detector position + * @returns frame mode (-1 for not found or error in computing json parameter value) + */ + int setFrameMode(frameModeType value, int detPos = -1); + + /** + * Sets the detector mode in processor (Moench only) + * @param value detectorModetype (-1 gets) + * @param detPos -1 for all detectors in list or specific detector position + * @returns detector mode (-1 for not found or error in computing json parameter value) + */ + int setDetectorMode(detectorModeType value, int detPos = -1); + /** * Sets the receiver UDP socket buffer size * @param udpsockbufsize additional json header diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 2ae77b080..d6aa07ac4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -63,7 +63,7 @@ The commands are sudivided into different pages depending on their functionaliti - \ref output "Output": commands to define output file destination and format - \ref network "Network": commands to setup the network between client, detector and receiver - \ref receiver "Receiver": commands to configure the receiver - - \ref prototype "Prototype (Chip Test Board / Moench)": commands specific for the chiptest board or moench + - \ref prototype "Chip Test Board / Moench": commands specific for the chiptest board or moench - \ref test "Developer": commands to be used only for software debugging. Avoid using them! */ @@ -1796,10 +1796,37 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { /* pattern generator */ - /*! \page prototype Protoype (Chip Test Board / Moench) + /*! \page prototype Chip Test Board / Moench Commands specific for the chiptest board or moench */ + /*! \page prototype + - emin [i] Sets/gets detector minimum energy threshold for Moench (soft setting in processor) + */ + descrToFuncMap[i].m_pFuncName = "emin"; // + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; + ++i; + + /*! \page prototype + - emax [i] Sets/gets detector maximum energy threshold for Moench (soft setting in processor) + */ + descrToFuncMap[i].m_pFuncName = "emax"; // + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; + ++i; + + /*! \page prototype + - framemode [i] Sets/gets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield + */ + descrToFuncMap[i].m_pFuncName = "framemode"; // + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; + ++i; + + /*! \page prototype + - detectormode [i] Sets/gets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog + */ + descrToFuncMap[i].m_pFuncName = "detectormode"; // + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; + ++i; /*! \page prototype - adcinvert [mask] Sets/gets ADC inversion mask (8 digits hex format) @@ -5443,3 +5470,62 @@ std::string slsDetectorCommand::cmdPulse(int narg, char *args[], int action, int } +std::string slsDetectorCommand::helpProcessor(int action) { + + std::ostringstream os; + if (action == PUT_ACTION || action == HELP_ACTION) { + os << "emin [n] \t Sets detector minimum energy threshold to x for Moench (soft setting in processor)" << std::endl; + os << "emax [n] \t Sets detector maximum energy threshold to x for Moench (soft setting in processor)" << std::endl; + os << "framemode [n] \t Sets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield" << std::endl; + os << "detectormode [n] \t Sets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog" << std::endl; + } + if (action == GET_ACTION || action == HELP_ACTION) { + os << "emin [n] \t Gets detector minimum energy threshold to x for Moench (soft setting in processor)" << std::endl; + os << "emax [n] \t Gets detector maximum energy threshold to x for Moench (soft setting in processor)" << std::endl; + os << "framemode [n] \t Gets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield" << std::endl; + os << "detectormode [n] \t Gets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog" << std::endl; + } + return os.str(); +} + +std::string slsDetectorCommand::cmdProcessor(int narg, char *args[], int action, int detPos) { + if (action == HELP_ACTION) + return helpProcessor(action); + + myDet->setOnline(ONLINE_FLAG, detPos); + myDet->setReceiverOnline(ONLINE_FLAG, detPos); + + if (cmd == "emin" || cmd == "emax") { + if (action == PUT_ACTION) { + int ival = -1; + if(!sscanf(args[1],"%d",&ival)) + return std::string("cannot parse emin/emax value"); + myDet->setDetectorMinMaxEnergyThreshold((cmd == "emin" ? 0 : 1), ival, detPos); + } + return std::to_string(myDet->setDetectorMinMaxEnergyThreshold(0, -1, detPos)); + } + + else if (cmd == "framemode") { + if (action == PUT_ACTION) { + frameModeType ival = getFrameModeType(args[1]); + if (ival == GET_FRAME_MODE) + return std::string("cannot parse frame mode value"); + myDet->setFrameMode(ival, detPos); + } + return getFrameModeType(frameModeType(myDet->setFrameMode(GET_FRAME_MODE, detPos))); + } + + else if (cmd == "detectorMode") { + if (action == PUT_ACTION) { + detectorModeType ival = getDetectorModeType(args[1]); + if (ival == GET_DETECTOR_MODE) + return std::string("cannot parse detector mode value"); + myDet->setDetectorMode(ival, detPos); + } + return getDetectorModeType(detectorModeType(myDet->setDetectorMode(GET_DETECTOR_MODE, detPos))); + } + return std::string("unknown action"); +} + + + diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h index f29185044..2a4117d9c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -79,7 +79,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpReceiver(int action); static std::string helpPattern(int action); static std::string helpPulse(int action); - + static std::string helpProcessor(int action); @@ -141,6 +141,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdReceiver(int narg, char *args[], int action, int detPos = -1); std::string cmdPattern(int narg, char *args[], int action, int detPos = -1); std::string cmdPulse(int narg, char *args[], int action, int detPos = -1); + std::string cmdProcessor(int narg, char *args[], int action, int detPos = -1); int numberOfCommands; std::string cmd; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp index 463ac3abe..5707be53c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp @@ -359,14 +359,19 @@ int slsDetectorUsers::setReceiverFramesPerFile(int f, int detPos) { return detector.setReceiverFramesPerFile(f, detPos); } -std::string slsDetectorUsers::setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos) { - return detector.setAdditionalJsonParameter(key, value, detPos); +int slsDetectorUsers::setDetectorMinMaxEnergyThreshold(const int index, int v, int detPos) { + return detector.setDetectorMinMaxEnergyThreshold(index, v, detPos); } -std::string slsDetectorUsers::getAdditionalJsonParameter(const std::string& key, int detPos) { - return detector.getAdditionalJsonParameter(key, detPos); +int slsDetectorUsers::setFrameMode(int value, int detPos) { + return detector.setFrameMode(slsDetectorDefs::frameModeType(value), detPos); } +int slsDetectorUsers::setDetectorMode(int value, int detPos) { + return detector.setDetectorMode(slsDetectorDefs::detectorModeType(value), detPos); +} + + /************************************************************************ CALLBACKS & COMMAND LINE PARSING diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 967d3682d..6d701392e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -769,24 +769,34 @@ public: */ int setReceiverFramesPerFile(int f = -1, int detPos = -1); - /** - * Sets the value for the additional json header parameter if found, else append it - * @param key additional json header parameter - * @param value additional json header parameter value (cannot be empty) + /** + * Sets the detector minimum/maximum energy threshold in processor (for Moench only) + * @param index 0 for emin, antyhing else for emax + * @param v value to set (-1 gets) * @param detPos -1 for all detectors in list or specific detector position - * @returns the additional json header parameter value, - * empty if no parameter found in additional json header - */ - std::string setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos = -1); + * @returns detector minimum/maximum energy threshold + */ + int setDetectorMinMaxEnergyThreshold(const int index, int v, int detPos = -1); + + /** + * Sets the frame mode in processor (Moench only) + * @param value frame mode value (-1 gets) + * Options (slsDetectorDefs::frameModeType) + * PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD + * @param detPos -1 for all detectors in list or specific detector position + * @returns frame mode (-1 for not found or error in computing json parameter value) + */ + int setFrameMode(int value, int detPos = -1); /** - * Returns the additional json header parameter value - * @param key additional json header parameter + * Sets the detector mode in processor (Moench only) + * @param value detector mode value (-1 gets) + * Options (slsDetectorDefs::detectorModeType) + * COUNTING, INTERPOLATING, ANALOG * @param detPos -1 for all detectors in list or specific detector position - * @returns the additional json header parameter value, - * empty if no parameter found in additional json header + * @returns detector mode (-1 for not found or error in computing json parameter value) */ - std::string getAdditionalJsonParameter(const std::string& key, int detPos = -1); + int setDetectorMode(int value, int detPos = -1); /************************************************************************ diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index b7554e2fb..bd083d207 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -557,6 +557,28 @@ public: }; + /** + * frame mode for processor + */ + enum frameModeType { + GET_FRAME_MODE = -1, + PEDESTAL, /** < pedestal */ + NEW_PEDESTAL, /** < new pedestal */ + FLATFIELD, /** < flatfield */ + NEW_FLATFIELD /** < new flatfield */ + }; + + /** + * detector mode for processor + */ + enum detectorModeType { + GET_DETECTOR_MODE = -1, + COUNTING, /** < counting */ + INTERPOLATING, /** < interpolating */ + ANALOG /** < analog */ + }; + + #ifdef __cplusplus /** returns string from enabled/disabled \param b true or false @@ -875,6 +897,64 @@ public: }}; \ + /** + * returns frameModeType as enum + * @param s pedestal, newpedestal, flatfield, newflatfield + * @returns PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD, GET_FRAME_MODE (if unknown) + */ + static frameModeType getFrameModeType(std::string s) { \ + for (auto &c: s) \ + c = std::tolower(c); \ + if (s == "pedestal") return PEDESTAL; \ + if (s == "newpedestal") return NEW_PEDESTAL; \ + if (s == "flatfield") return FLATFIELD; \ + if (s == "newflatfield")return NEW_FLATFIELD; \ + return GET_FRAME_MODE; \ + } \ + + /** + * returns frameModeType as string + * @param f PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD + * @return string pedestal, newpedestal, flatfield, newflatfield, unknown + */ + static std::string getFrameModeType(frameModeType f) { \ + switch(f) { \ + case PEDESTAL: return std::string("pedestal"); \ + case NEW_PEDESTAL: return std::string("newPedestal"); \ + case FLATFIELD: return std::string("flatfield"); \ + case NEW_FLATFIELD: return std::string("newFlatfield"); \ + default: return std::string("unknown"); \ + } \ + } \ + + /** + * returns detectorModeType as enum + * @param s counting, interpolating, analog + * @returns COUNTING, INTERPOLATING, ANALOG, GET_DETECTOR_MODE (if unknown) + */ + static detectorModeType getDetectorModeType(std::string s) { \ + for (auto &c: s) \ + c = std::tolower(c); \ + if (s == "counting") return COUNTING; \ + if (s == "interpolating") return INTERPOLATING; \ + if (s == "analog") return ANALOG; \ + return GET_DETECTOR_MODE; \ + } \ + + /** + * returns frameModeType as string + * @param f COUNTING, INTERPOLATING, ANALOG + * @return string counting, interpolating, analog, unknown + */ + static std::string getDetectorModeType(detectorModeType f) { \ + switch(f) { \ + case COUNTING: return std::string("counting"); \ + case INTERPOLATING: return std::string("interpolating"); \ + case ANALOG: return std::string("analog"); \ + default: return std::string("unknown"); \ + } \ + } \ + #endif #ifdef __cplusplus