diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 3b4be1e99..495255709 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1940,13 +1940,14 @@ int setHighVoltage(int val, char *mess) { LOG(logERROR, (mess)); return FAIL; } - LOG(logINFO, ("Setting High voltage: %d V", val)); + LOG(logINFO, ("Setting High voltage: %d V\n", val)); uint32_t addr = POWER_REG; // switch to external high voltage bus_w(addr, bus_r(addr) & (~POWER_HV_INTERNAL_SLCT_MSK)); - MAX1932_Set(&val); + if (MAX1932_Set(val, mess) == FAIL) + return FAIL; // switch on internal high voltage, if set if (val > 0) @@ -1958,7 +1959,8 @@ int setHighVoltage(int val, char *mess) { int getHighVoltage(int *retval, char *mess) { LOG(logDEBUG1, ("High Voltage: %d\n", retval)); - return highvoltage; + *retval = highvoltage; + return OK; } /* parameters - timing, extsig */ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 3f0209e08..24a51fbb5 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -1539,7 +1539,10 @@ int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) { if ((retvals[0] != retvals[1]) || (retvals[1] != retvals[2]) || (retvals[2] != retvals[3]) || (retvals[3] != retvals[4])) { - LOG(logWARNING, ("Vthreshold mismatch. vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d vcmp_rr:%d vcp:%d\n",retvals[0], retvals[1], retvals[2], retvals[3], retvals[4])); + LOG(logWARNING, + ("Vthreshold mismatch. vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d " + "vcmp_rr:%d vcp:%d\n", + retvals[0], retvals[1], retvals[2], retvals[3], retvals[4])); *retval = -1; return OK; } diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index d3a96932f..375c5d531 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1474,20 +1474,17 @@ int getADC(enum ADCINDEX ind) { } int setHighVoltage(int val, char *mess) { - if (val < 0) { - sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val); - LOG(logERROR, (mess)); + LOG(logINFO, ("Setting High voltage: %d V\n", val)); + if (MAX1932_Set(val, mess) == FAIL) return FAIL; - } - LOG(logINFO, ("Setting High voltage: %d V", val)); - MAX1932_Set(&val); highvoltage = val; return OK; } int getHighVoltage(int *retval, char *mess) { LOG(logDEBUG1, ("High Voltage: %d\n", retval)); - return highvoltage; + *retval = highvoltage; + return OK; } /* parameters - timing, extsig */ diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index c1ebe32ea..2e94fceae 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -1040,20 +1040,17 @@ int getADC(enum ADCINDEX ind) { } int setHighVoltage(int val, char *mess) { - if (val < 0) { - sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val); - LOG(logERROR, (mess)); + LOG(logINFO, ("Setting High voltage: %d V\n", val)); + if (MAX1932_Set(val, mess) == FAIL) return FAIL; - } - LOG(logINFO, ("Setting High voltage: %d V", val)); - MAX1932_Set(&val); highvoltage = val; return OK; } int getHighVoltage(int *retval, char *mess) { LOG(logDEBUG1, ("High Voltage: %d\n", retval)); - return highvoltage; + *retval = highvoltage; + return OK; } /* parameters - timing, extsig */ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index b0a0b7f98..04cbeef78 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -1715,7 +1715,8 @@ int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) { } // different values for enabled counters else if (retval1 != *retval) { - LOG(logWARNING,("Could not get threhsold dac. Different values for enabled counters.\n")); + LOG(logWARNING, ("Could not get threhsold dac. Different " + "values for enabled counters.\n")); *retval = -1; return OK; } diff --git a/slsDetectorServers/slsDetectorServer/include/MAX1932.h b/slsDetectorServers/slsDetectorServer/include/MAX1932.h index e19e0c8da..06d863cc1 100644 --- a/slsDetectorServers/slsDetectorServer/include/MAX1932.h +++ b/slsDetectorServers/slsDetectorServer/include/MAX1932.h @@ -17,14 +17,5 @@ void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int minMV, int maxMV); -/** - * Disable SPI - */ void MAX1932_Disable(); - -/** - * Set value (value is updated to correct range) - * @param val pointer to value to set - * @return OK or FAIL - */ -int MAX1932_Set(int *val); +int MAX1932_Set(int val, char *mess); diff --git a/slsDetectorServers/slsDetectorServer/src/MAX1932.c b/slsDetectorServers/slsDetectorServer/src/MAX1932.c index 2edf69f27..32829a1b8 100644 --- a/slsDetectorServers/slsDetectorServer/src/MAX1932.c +++ b/slsDetectorServers/slsDetectorServer/src/MAX1932.c @@ -43,33 +43,33 @@ void MAX1932_Disable() { ~(MAX1932_DigMask)); } -int MAX1932_Set(int *val) { - LOG(logDEBUG1, ("Setting high voltage to %d\n", *val)); - if (*val < 0) - return FAIL; - - int dacvalue = 0; +int MAX1932_Set(int val, char *mess) { + LOG(logDEBUG1, ("Setting high voltage to %d\n", val)); // limit values (normally < 60 => 0 (off)) - if (*val < MAX1932_MinVoltage) { + if ((val != 0 && val < MAX1932_MinVoltage) || val > MAX1932_MaxVoltage) { + sprintf(mess, + "Could not set high voltage. Invalid value:%d. Should bet be 0 " + "or between %d and %d\n", + val, MAX1932_MinVoltage, MAX1932_MaxVoltage); + LOG(logERROR, (mess)); + return FAIL; + } + int dacvalue = 0; + if (val == 0) dacvalue = MAX1932_POWER_OFF_DAC_VAL; - *val = 0; + else if (ConvertToDifferentRange(MAX1932_MinVoltage, MAX1932_MaxVoltage, + MAX1932_MIN_DAC_VAL, MAX1932_MAX_DAC_VAL, + val, &dacvalue) == FAIL) { + sprintf( + mess, + "Could not set high voltage %d. Could not convert to dac units\n", + val); + LOG(logERROR, (mess)); + return FAIL; } - // limit values (normally > 200 => 0x1 (max)) - else if (*val > MAX1932_MaxVoltage) { - dacvalue = MAX1932_MAX_DAC_VAL; - *val = MAX1932_MaxVoltage; - } - // convert value - else { - // no failure in conversion as limits handled (range from 0x1 to 0xFF) - ConvertToDifferentRange(MAX1932_MinVoltage, MAX1932_MaxVoltage, - MAX1932_MIN_DAC_VAL, MAX1932_MAX_DAC_VAL, *val, - &dacvalue); - dacvalue &= MAX1932_HV_DATA_MSK; - } - - LOG(logINFO, ("\t%dV (dacval %d)\n", *val, dacvalue)); + dacvalue &= MAX1932_HV_DATA_MSK; + LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue)); serializeToSPI(MAX1932_Reg, dacvalue, MAX1932_CsMask, MAX1932_HV_NUMBITS, MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset, 0); return OK; diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index fc911900d..0c94389f2 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -7,9 +7,9 @@ #include "sls/sls_detector_funcs.h" #include "slsDetectorFunctionList.h" +#include #include #include -#include #if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD) || \ defined(MYTHEN3D) @@ -10950,175 +10950,180 @@ int set_pattern_wait_interval(int file_des) { /** * Non destructive read from SPI register. Read n_bytes by shifting in dummy * data while keeping csn 0 after the operation. Shift the read out data back - * in to restore the register. + * in to restore the register. */ -int spi_read(int file_des){ +int spi_read(int file_des) { #if !defined(XILINX_CHIPTESTBOARDD) functionNotImplemented(); return sendError(file_des); #endif int chip_id = 0; - if (receiveData(file_des, &chip_id, sizeof(chip_id), INT32) < 0){ + if (receiveData(file_des, &chip_id, sizeof(chip_id), INT32) < 0) { return printSocketReadError(); } - if(chip_id < 0 || chip_id > 15){ + if (chip_id < 0 || chip_id > 15) { sprintf(mess, "Invalid chip_id %d. Must be 0-15\n", chip_id); return sendError(file_des); } int register_id = 0; - if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0){ + if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0) { return printSocketReadError(); } - if(register_id < 0 || register_id > 15){ + if (register_id < 0 || register_id > 15) { sprintf(mess, "Invalid register_id %d. Must be 0-15\n", register_id); return sendError(file_des); } int n_bytes = 0; - if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0){ + if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0) { return printSocketReadError(); } - if(n_bytes < 1 ){ - sprintf(mess, "Invalid n_bytes %d. Must ask for a read of at least 1 byte\n", n_bytes); + if (n_bytes < 1) { + sprintf(mess, + "Invalid n_bytes %d. Must ask for a read of at least 1 byte\n", + n_bytes); return sendError(file_des); } - LOG(logINFO, ("SPI Read Requested: chip_id=%d, register_id=%d, n_bytes=%d\n", - chip_id, register_id, n_bytes)); - + LOG(logINFO, + ("SPI Read Requested: chip_id=%d, register_id=%d, n_bytes=%d\n", + chip_id, register_id, n_bytes)); #ifdef VIRTUAL // For the virtual detector we create a fake register to read from // and fill it with 0,2,4,6,... This way we can check that copying // of the data works as expected uint8_t *fake_register = malloc(n_bytes); - if(fake_register == NULL){ + if (fake_register == NULL) { LOG(logERROR, ("Could not allocate memory for fake register\n")); exit(EXIT_FAILURE); } for (int i = 0; i < n_bytes; i++) { - fake_register[i] = (uint8_t)( (i*2) % 256 ); + fake_register[i] = (uint8_t)((i * 2) % 256); } #else int spifd = open("/dev/spidev2.0", O_RDWR); LOG(logINFO, ("SPI Read: opened spidev2.0 with fd=%d\n", spifd)); - if(spifd < 0){ + if (spifd < 0) { sprintf(mess, "Could not open /dev/spidev2.0\n"); return sendError(file_des); } #endif - // Allocate dummy data to shif in, we keep a copy of this + // Allocate dummy data to shif in, we keep a copy of this // to double check that we access a register of the correct size uint8_t *dummy_data = malloc(n_bytes); - if(dummy_data == NULL){ + if (dummy_data == NULL) { LOG(logERROR, ("Could not allocate memory for dummy data\n")); exit(EXIT_FAILURE); } - for(int i=0; i 15){ + if (chip_id < 0 || chip_id > 15) { ret = FAIL; sprintf(mess, "Invalid chip_id %d. Must be 0-15\n", chip_id); LOG(logERROR, (mess)); @@ -11160,10 +11162,10 @@ int spi_write(int file_des){ } int register_id = 0; - if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0){ + if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0) { return printSocketReadError(); } - if(register_id < 0 || register_id > 15){ + if (register_id < 0 || register_id > 15) { ret = FAIL; sprintf(mess, "Invalid register_id %d. Must be 0-15\n", register_id); LOG(logERROR, (mess)); @@ -11171,64 +11173,67 @@ int spi_write(int file_des){ } int n_bytes = 0; - if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0){ + if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0) { return printSocketReadError(); } - if(n_bytes < 1 ){ - sprintf(mess, "Invalid n_bytes %d. Must ask for a write of at least 1 byte\n", n_bytes); + if (n_bytes < 1) { + sprintf(mess, + "Invalid n_bytes %d. Must ask for a write of at least 1 byte\n", + n_bytes); return sendError(file_des); } - LOG(logINFO, ("SPI Write Requested: chip_id=%d, register_id=%d, n_bytes=%d\n", - chip_id, register_id, n_bytes)); - + LOG(logINFO, + ("SPI Write Requested: chip_id=%d, register_id=%d, n_bytes=%d\n", + chip_id, register_id, n_bytes)); + uint8_t *data = malloc(n_bytes); - if(data == NULL){ + if (data == NULL) { LOG(logERROR, ("Could not allocate memory for SPI write data\n")); exit(EXIT_FAILURE); } memset(data, 0, n_bytes); - if (receiveData(file_des, data, n_bytes, OTHER) < 0){ + if (receiveData(file_des, data, n_bytes, OTHER) < 0) { free(data); return printSocketReadError(); } - uint8_t* local_tx = malloc(n_bytes+1); - if(local_tx == NULL){ + uint8_t *local_tx = malloc(n_bytes + 1); + if (local_tx == NULL) { LOG(logERROR, ("Could not allocate memory for local_tx\n")); exit(EXIT_FAILURE); } - uint8_t* local_rx = malloc(n_bytes+1); - if(local_rx == NULL){ + uint8_t *local_rx = malloc(n_bytes + 1); + if (local_rx == NULL) { LOG(logERROR, ("Could not allocate memory for local_rx\n")); exit(EXIT_FAILURE); } struct spi_ioc_transfer send_cmd[1]; memset(send_cmd, 0, sizeof(send_cmd)); - send_cmd[0].len = n_bytes+1; - send_cmd[0].tx_buf = (unsigned long) local_tx; - send_cmd[0].rx_buf = (unsigned long) local_rx; + send_cmd[0].len = n_bytes + 1; + send_cmd[0].tx_buf = (unsigned long)local_tx; + send_cmd[0].rx_buf = (unsigned long)local_rx; // 0 - Normal operation, 1 - CSn remains zero after operation - send_cmd[0].cs_change = 0; + send_cmd[0].cs_change = 0; local_tx[0] = ((chip_id & 0xF) << 4) | (register_id & 0xF); - for (int i=0; i < n_bytes; i++) - local_tx[i+1] = data[i]; + for (int i = 0; i < n_bytes; i++) + local_tx[i + 1] = data[i]; #ifdef VIRTUAL - // For the virtual detector we have nothing to do + // For the virtual detector we have nothing to do #else int spifd = open("/dev/spidev2.0", O_RDWR); LOG(logINFO, ("SPI Read: opened spidev2.0 with fd=%d\n", spifd)); - if(spifd < 0){ + if (spifd < 0) { free(data); free(local_tx); free(local_rx); sprintf(mess, "Could not open /dev/spidev2.0\n"); return sendError(file_des); } - if(ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd)<0){ + if (ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd) < 0) { close(spifd); free(data); free(local_tx); diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index c7c95693f..1133c2a3e 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -427,13 +427,6 @@ void setupDetector() { if (initError == FAIL) return; } - for (int idac = NDAC_ONLY; idac < NDAC; ++idac) { - if (idac == D_PWR_EMPTY) - continue; - int min = (idac == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN; - // will not enable power at startup (dacValues = -1) - setPower(idac, min); - } resetFlow(); cleanFifos(); diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 958e64dc5..17215f0dc 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -2248,10 +2248,10 @@ class Detector { ///@} Result> readSpi(int chip_id, int register_id, - int n_bytes, Positions pos = {}) const; + int n_bytes, Positions pos = {}) const; void writeSpi(int chip_id, int register_id, - const std::vector &data, Positions pos = {}); + const std::vector &data, Positions pos = {}); private: std::vector getValidPortNumbers(uint16_t start_port); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 1960fd858..a27666f10 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2962,11 +2962,8 @@ Result> Detector::readSpi(int chip_id, int register_id, } void Detector::writeSpi(int chip_id, int register_id, - const std::vector &data, Positions pos){ + const std::vector &data, Positions pos) { pimpl->Parallel(&Module::writeSpi, pos, chip_id, register_id, data); - } - - - +} } // namespace sls diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index b0dc43211..595f14ead 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -4076,7 +4076,7 @@ void Module::simulatingActivityinDetector(const std::string &functionType, } std::vector Module::readSpi(int chip_id, int register_id, - int n_bytes) const{ + int n_bytes) const { auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_SPI_READ); client.setFnum(F_SPI_READ); @@ -4084,7 +4084,7 @@ std::vector Module::readSpi(int chip_id, int register_id, client.Send(register_id); client.Send(n_bytes); - if (client.Receive() == FAIL) { + if (client.Receive() == FAIL) { std::ostringstream os; os << "Module " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); @@ -4094,11 +4094,10 @@ std::vector Module::readSpi(int chip_id, int register_id, std::vector data(n_bytes); client.Receive(data); return data; - } void Module::writeSpi(int chip_id, int register_id, - const std::vector &data){ + const std::vector &data) { auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_SPI_WRITE); client.setFnum(F_SPI_WRITE); diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 2e4fb5684..eb373c935 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -608,9 +608,10 @@ class Module : public virtual slsDetectorDefs { int64_t getActualTime() const; int64_t getMeasurementTime() const; std::vector readSpi(int chip_id, int register_id, - int n_bytes) const; + int n_bytes) const; - void writeSpi(int chip_id, int register_id, const std::vector &data); + void writeSpi(int chip_id, int register_id, + const std::vector &data); private: std::string getReceiverLongVersion() const; diff --git a/tests/scripts/utils_for_test.py b/tests/scripts/utils_for_test.py index 66c43fb38..9e1b527ee 100644 --- a/tests/scripts/utils_for_test.py +++ b/tests/scripts/utils_for_test.py @@ -200,7 +200,7 @@ def runProcess(name, cmd, fp, log_file_name = None, quiet_mode=False): Log(LogLevel.INFOBLUE, info_text, fp, True) Log(LogLevel.INFOBLUE, 'Cmd: ' + ' '.join(cmd), fp, True) - error_log = None + captured_log = [] try: if log_file_name: @@ -212,8 +212,8 @@ def runProcess(name, cmd, fp, log_file_name = None, quiet_mode=False): except subprocess.CalledProcessError as e: print("error: ", str(e)) - captured_log = e.stdout.splitlines() - pass + if not log_file_name and e.stdout: + captured_log = e.stdout.splitlines() except Exception as e: print("something else failed") Log(LogLevel.ERROR, f'Failed to run {name}:{str(e)}', fp)