From 834b1e58eaebc17eceb9d2023ecfc47a1f68ed69 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 24 Apr 2019 10:57:02 +0200 Subject: [PATCH] cleaning slsDetector --- integrationTests/CMakeLists.txt | 1 + integrationTests/test-eigerIntegration.cpp | 107 +++++++++++++++++++++ integrationTests/test-integrationMulti.cpp | 84 ---------------- slsDetectorSoftware/src/slsDetector.cpp | 41 ++------ 4 files changed, 118 insertions(+), 115 deletions(-) create mode 100644 integrationTests/test-eigerIntegration.cpp diff --git a/integrationTests/CMakeLists.txt b/integrationTests/CMakeLists.txt index df8f9aa07..5bfc62e07 100755 --- a/integrationTests/CMakeLists.txt +++ b/integrationTests/CMakeLists.txt @@ -10,6 +10,7 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-integrationMulti.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-integrationDectector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-eigerIntegration.cpp ) # if(SLS_USE_TESTS) diff --git a/integrationTests/test-eigerIntegration.cpp b/integrationTests/test-eigerIntegration.cpp new file mode 100644 index 000000000..bd19151d7 --- /dev/null +++ b/integrationTests/test-eigerIntegration.cpp @@ -0,0 +1,107 @@ +#include "catch.hpp" +#include "multiSlsDetector.h" +#include "string_utils.h" +#include "tests/globals.h" +#include + +TEST_CASE("Set and get dacs", "[.eigerintegration][cli]") { + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + auto th = 1000; + + // set and read back each individual dac of EIGER + d.setDAC(0, di::E_SvP, 0); + CHECK(d.setDAC(-1, di::E_SvP, 0) == 0); + d.setDAC(4000, di::E_SvN, 0); + CHECK(d.setDAC(-1, di::E_SvN, 0) == 4000); + d.setDAC(2000, di::E_Vtr, 0); + CHECK(d.setDAC(-1, di::E_Vtr, 0) == 2000); + d.setDAC(3500, di::E_Vrf, 0); + CHECK(d.setDAC(-1, di::E_Vrf, 0) == 3500); + d.setDAC(1400, di::E_Vrs, 0); + CHECK(d.setDAC(-1, di::E_Vrs, 0) == 1400); + d.setDAC(2556, di::E_Vtgstv, 0); + CHECK(d.setDAC(-1, di::E_Vtgstv, 0) == 2556); + d.setDAC(1500, di::E_Vcmp_ll, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == 1500); + d.setDAC(1400, di::E_Vcmp_lr, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_lr, 0) == 1400); + d.setDAC(4000, di::E_cal, 0); + CHECK(d.setDAC(-1, di::E_cal, 0) == 4000); + d.setDAC(1300, di::E_Vcmp_rl, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_rl, 0) == 1300); + d.setDAC(1200, di::E_Vcmp_rr, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_rr, 0) == 1200); + d.setDAC(1100, di::E_rxb_rb, 0); + CHECK(d.setDAC(-1, di::E_rxb_rb, 0) == 1100); + d.setDAC(1100, di::E_rxb_lb, 0); + CHECK(d.setDAC(-1, di::E_rxb_lb, 0) == 1100); + d.setDAC(1500, di::E_Vcp, 0); + CHECK(d.setDAC(-1, di::E_Vcp, 0) == 1500); + d.setDAC(2000, di::E_Vcn, 0); + CHECK(d.setDAC(-1, di::E_Vcn, 0) == 2000); + d.setDAC(1550, di::E_Vis, 0); + CHECK(d.setDAC(-1, di::E_Vis, 0) == 1550); + d.setDAC(660, di::IO_DELAY, 0); + CHECK(d.setDAC(-1, di::IO_DELAY, 0) == 660); + + // setting threshold sets all individual vcmp + d.setDAC(th, di::THRESHOLD, 0); + CHECK(d.setDAC(-1, di::THRESHOLD, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_lr, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_rl, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_rr, 0) == th); + + // different values gives -1 + if (d.getNumberOfDetectors() > 1) { + d.setDAC(1600, di::E_Vcmp_ll, 0, 0); + d.setDAC(1700, di::E_Vcmp_ll, 0, 1); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0, 0) == 1600); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0, 1) == 1700); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == -1); + CHECK(d.setDAC(-1, di::THRESHOLD, 0) == -1); + CHECK(d.setDAC(-1, di::THRESHOLD, 0, 0) == -1); + CHECK(d.setDAC(-1, di::THRESHOLD, 0, 1) == -1); + } + + d.freeSharedMemory(); +} + +TEST_CASE("Read temperatures", "[.eigerintegration][cli]") { + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + + std::vector tempindex{di::TEMPERATURE_FPGA, di::TEMPERATURE_FPGA2, + di::TEMPERATURE_FPGA3}; + for (auto index : tempindex) { + for (int i = 0; i != d.getNumberOfDetectors(); ++i) { + double temp = static_cast(d.getADC(index, 0)) / 1000; + CHECK(temp > 20); + CHECK(temp < 60); + } + } +} + +int to_time(uint32_t reg){ + uint32_t clocks = reg >> 3; + uint32_t exponent = (reg & 0b111)+1; + return clocks*pow(10, exponent); + // clocks = register >> 3 + // exponent = register & 0b111 + // return clocks*10**exponent / 100e6 +} + +TEST_CASE("Read/write register", "[.eigerintegration][cli]"){ + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + + d.setNumberOfFrames(1); + d.setExposureTime(10000); + d.acquire(); + CHECK(to_time(d.readRegister(0x4, 0)) == 10000); + + d.writeRegister(0x4, 500); + CHECK(d.readRegister(0x4) == 500); + +} \ No newline at end of file diff --git a/integrationTests/test-integrationMulti.cpp b/integrationTests/test-integrationMulti.cpp index 511ac797e..580d5723c 100755 --- a/integrationTests/test-integrationMulti.cpp +++ b/integrationTests/test-integrationMulti.cpp @@ -25,91 +25,7 @@ TEST_CASE("Initialize a multi detector", "[.integration][.multi]") { d.freeSharedMemory(); } -TEST_CASE("Set and get dacs", "[.integration][.multi]") { - multiSlsDetector d(0, true, true); - d.setHostname(hostname.c_str()); - auto th = 1000; - switch (type) { - case dt::EIGER: - // set and read back each individual dac of EIGER - d.setDAC(0, di::E_SvP, 0); - CHECK(d.setDAC(-1, di::E_SvP, 0) == 0); - d.setDAC(4000, di::E_SvN, 0); - CHECK(d.setDAC(-1, di::E_SvN, 0) == 4000); - d.setDAC(2000, di::E_Vtr, 0); - CHECK(d.setDAC(-1, di::E_Vtr, 0) == 2000); - d.setDAC(3500, di::E_Vrf, 0); - CHECK(d.setDAC(-1, di::E_Vrf, 0) == 3500); - d.setDAC(1400, di::E_Vrs, 0); - CHECK(d.setDAC(-1, di::E_Vrs, 0) == 1400); - d.setDAC(2556, di::E_Vtgstv, 0); - CHECK(d.setDAC(-1, di::E_Vtgstv, 0) == 2556); - d.setDAC(1500, di::E_Vcmp_ll, 0); - CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == 1500); - d.setDAC(1400, di::E_Vcmp_lr, 0); - CHECK(d.setDAC(-1, di::E_Vcmp_lr, 0) == 1400); - d.setDAC(4000, di::E_cal, 0); - CHECK(d.setDAC(-1, di::E_cal, 0) == 4000); - d.setDAC(1300, di::E_Vcmp_rl, 0); - CHECK(d.setDAC(-1, di::E_Vcmp_rl, 0) == 1300); - d.setDAC(1200, di::E_Vcmp_rr, 0); - CHECK(d.setDAC(-1, di::E_Vcmp_rr, 0) == 1200); - d.setDAC(1100, di::E_rxb_rb, 0); - CHECK(d.setDAC(-1, di::E_rxb_rb, 0) == 1100); - d.setDAC(1100, di::E_rxb_lb, 0); - CHECK(d.setDAC(-1, di::E_rxb_lb, 0) == 1100); - d.setDAC(1500, di::E_Vcp, 0); - CHECK(d.setDAC(-1, di::E_Vcp, 0) == 1500); - d.setDAC(2000, di::E_Vcn, 0); - CHECK(d.setDAC(-1, di::E_Vcn, 0) == 2000); - d.setDAC(1550, di::E_Vis, 0); - CHECK(d.setDAC(-1, di::E_Vis, 0) == 1550); - d.setDAC(660, di::IO_DELAY, 0); - CHECK(d.setDAC(-1, di::IO_DELAY, 0) == 660); - // setting threshold sets all individual vcmp - d.setDAC(th, di::THRESHOLD, 0); - CHECK(d.setDAC(-1, di::THRESHOLD, 0) == th); - CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == th); - CHECK(d.setDAC(-1, di::E_Vcmp_lr, 0) == th); - CHECK(d.setDAC(-1, di::E_Vcmp_rl, 0) == th); - CHECK(d.setDAC(-1, di::E_Vcmp_rr, 0) == th); - - // different values gives -1 - if (d.getNumberOfDetectors() > 1) { - d.setDAC(1600, di::E_Vcmp_ll, 0, 0); - d.setDAC(1700, di::E_Vcmp_ll, 0, 1); - CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0, 0) == 1600); - CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0, 1) == 1700); - CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == -1); - CHECK(d.setDAC(-1, di::THRESHOLD, 0) == -1); - CHECK(d.setDAC(-1, di::THRESHOLD, 0, 0) == -1); - CHECK(d.setDAC(-1, di::THRESHOLD, 0, 1) == -1); - } - - break; - case dt::JUNGFRAU: - CHECK(false); - break; - case dt::GOTTHARD: - CHECK(false); - break; - case dt::CHIPTESTBOARD: - CHECK(false); - break; - case dt::MOENCH: - CHECK(false); - break; - case dt::GENERIC: - CHECK(false); - break; - case dt::GET_DETECTOR_TYPE: - CHECK(false); - break; - } - - d.freeSharedMemory(); -} TEST_CASE("Set and read timers", "[.integration][.multi]") { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 472900858..968301f05 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -1825,20 +1825,16 @@ int slsDetector::getDataBytesInclGapPixels() { int slsDetector::setDAC(int val, dacIndex index, int mV) { int fnum = F_SET_DAC; - int ret = FAIL; int args[]{static_cast(index), mV, val}; int retval = -1; FILE_LOG(logDEBUG1) << "Setting DAC " << index << " to " << val << (mV != 0 ? "mV" : "dac units"); if (detector_shm()->onlineFlag == ONLINE_FLAG) { - ret = sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval)); + sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Dac index " << index << ": " << retval << (mV != 0 ? "mV" : "dac units"); } - if (ret == FORCE_UPDATE) { - updateDetector(); - } return retval; } @@ -1847,8 +1843,12 @@ int slsDetector::sendToDetector(int fnum, void* args, size_t args_size, void* re { auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); - - return client.sendCommandThenRead(fnum, args, args_size, retval, retval_size); + auto ret = client.sendCommandThenRead(fnum, args, args_size, retval, retval_size); + client.close(); + if (ret == FORCE_UPDATE) { + updateDetector(); + } + return ret; } int slsDetector::getADC(dacIndex index) { @@ -1858,10 +1858,7 @@ int slsDetector::getADC(dacIndex index) { FILE_LOG(logDEBUG1) << "Getting ADC " << index; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, - sizeof(retval)); + sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "ADC (" << index << "): " << retval; } return retval; @@ -1877,9 +1874,6 @@ slsDetector::setExternalCommunicationMode(externalCommunicationMode pol) { if (detector_shm()->onlineFlag == ONLINE_FLAG) { ret = sendToDetector(fnum, &arg, sizeof(arg), &retval,sizeof(retval)); - // auto client = DetectorSocket(detector_shm()->hostname, - // detector_shm()->controlPort); - // ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,sizeof(retval)); FILE_LOG(logDEBUG1) << "Timing Mode: " << retval; } if (ret == FORCE_UPDATE) { @@ -1958,45 +1952,30 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) { int fnum = F_WRITE_REGISTER; - int ret = FAIL; uint32_t args[]{addr, val}; uint32_t retval = -1; FILE_LOG(logDEBUG1) << "Writing to register 0x" << std::hex << addr << "data: 0x" << std::hex << val << std::dec; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval, - sizeof(retval)); + sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x" << std::hex << retval << std::dec; } - if (ret == FORCE_UPDATE) { - updateDetector(); - } return retval; } uint32_t slsDetector::readRegister(uint32_t addr) { int fnum = F_READ_REGISTER; - int ret = FAIL; - uint32_t arg = addr; uint32_t retval = -1; FILE_LOG(logDEBUG1) << "Reading register 0x" << std::hex << addr << std::dec; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, - sizeof(retval)); + sendToDetector(fnum, &addr, sizeof(addr), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x" << std::hex << retval << std::dec; } - if (ret == FORCE_UPDATE) { - updateDetector(); - } return retval; }