diff --git a/.gitea/workflows/rh8-native.yml b/.gitea/workflows/docker-rh8-build-test.yml similarity index 56% rename from .gitea/workflows/rh8-native.yml rename to .gitea/workflows/docker-rh8-build-test.yml index 7aae3be69..ed569282d 100644 --- a/.gitea/workflows/rh8-native.yml +++ b/.gitea/workflows/docker-rh8-build-test.yml @@ -1,4 +1,4 @@ -name: Build on RHEL8 +name: Build on RHEL8 docker image on: push: @@ -26,4 +26,17 @@ jobs: - name: C++ unit tests working-directory: ${{gitea.workspace}}/build - run: ctest -j1 --rerun-failed --output-on-failure \ No newline at end of file + run: ctest -j1 --rerun-failed --output-on-failure + + - name: Install Python dependencies + run: | + python3.12 -m pip install --upgrade pip + python3.12 -m pip install pytest + python3.12 -m pip install colorama + python3.12 -m pip install numpy + + - name: Python unit tests + working-directory: ${{gitea.workspace}} + run: | + export PYTHONPATH=$PWD/build/bin:$PYTHONPATH + python3.12 -m pytest python/tests \ No newline at end of file diff --git a/.gitea/workflows/docker-rh9-build-test.yml b/.gitea/workflows/docker-rh9-build-test.yml new file mode 100644 index 000000000..9c2e392fd --- /dev/null +++ b/.gitea/workflows/docker-rh9-build-test.yml @@ -0,0 +1,40 @@ +name: Build on RHEL9 docker image + +on: + push: + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: "ubuntu-latest" + container: + image: gitea.psi.ch/detectors/rhel9-detectors-dev + steps: + - uses: actions/checkout@v4 + + + - name: Build library + run: | + mkdir build && cd build + cmake .. -DSLS_USE_PYTHON=ON -DSLS_USE_TESTS=ON -DSLS_USE_SIMULATOR=ON + make -j 2 + + - name: C++ unit tests + working-directory: ${{gitea.workspace}}/build + run: ctest -j1 --rerun-failed --output-on-failure + + - name: Install Python dependencies + run: | + python3.12 -m pip install --upgrade pip + python3.12 -m pip install pytest + python3.12 -m pip install colorama + python3.12 -m pip install numpy + + - name: Python unit tests + working-directory: ${{gitea.workspace}} + run: | + export PYTHONPATH=$PWD/build/bin:$PYTHONPATH + python3.12 -m pytest python/tests \ No newline at end of file diff --git a/.gitea/workflows/rh8-local.yml b/.gitea/workflows/rh8-local-build-deploy.yml similarity index 87% rename from .gitea/workflows/rh8-local.yml rename to .gitea/workflows/rh8-local-build-deploy.yml index 128d3176c..120605dac 100644 --- a/.gitea/workflows/rh8-local.yml +++ b/.gitea/workflows/rh8-local-build-deploy.yml @@ -1,4 +1,4 @@ -name: Build on local RHEL8 +name: Build and Deploy on local RHEL8 on: push: @@ -21,7 +21,7 @@ jobs: conda activate det mkdir build && cd build conda activate det - cmake .. -DSLS_USE_PYTHON=ON + cmake .. -DSLS_USE_PYTHON=ON -DSLS_USE_SIMULATOR=ON -DSLS_USE_GUI=ON make -j 2 - name: Deploy to NFS update server diff --git a/.gitea/workflows/rh8-local-tests.yml b/.gitea/workflows/rh8-local-tests.yml index 8865e43ce..7c0a379fb 100644 --- a/.gitea/workflows/rh8-local-tests.yml +++ b/.gitea/workflows/rh8-local-tests.yml @@ -2,11 +2,7 @@ name: Run Simulator Tests on local RHEL8 on: push: - branches: - - developer - - main - - 'dev/*' - - '*.*.*.rc' + workflow_dispatch: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) diff --git a/.gitea/workflows/rh9-local.yml b/.gitea/workflows/rh9-local-build-deploy.yml similarity index 87% rename from .gitea/workflows/rh9-local.yml rename to .gitea/workflows/rh9-local-build-deploy.yml index 58de1cb88..94db2a2ec 100644 --- a/.gitea/workflows/rh9-local.yml +++ b/.gitea/workflows/rh9-local-build-deploy.yml @@ -1,4 +1,4 @@ -name: Build on local RHEL9 +name: Build and Deploy on local RHEL9 on: push: @@ -18,7 +18,7 @@ jobs: - name: Build library run: | mkdir build && cd build - cmake -DSLS_USE_PYTHON=ON -DPython_EXECUTABLE=/usr/bin/python3.13 -DPython_INCLUDE_DIR=/usr/include/python3.13 -DPython_LIBRARY=/usr/lib64/libpython3.13.so .. + cmake -DSLS_USE_PYTHON=ON -DPython_EXECUTABLE=/usr/bin/python3.13 -DPython_INCLUDE_DIR=/usr/include/python3.13 -DPython_LIBRARY=/usr/lib64/libpython3.13.so -DSLS_USE_SIMULATOR=ON -DSLS_USE_GUI=ON .. make -j 2 - name: Deploy to NFS update server diff --git a/.gitea/workflows/rh9-local-tests.yml b/.gitea/workflows/rh9-local-tests.yml index 4aa1a9f98..5efc5569f 100644 --- a/.gitea/workflows/rh9-local-tests.yml +++ b/.gitea/workflows/rh9-local-tests.yml @@ -2,11 +2,7 @@ name: Run Simulator Tests on local RHEL9 on: push: - branches: - - developer - - main - - 'dev/*' - - '*.*.*.rc' + workflow_dispatch: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) diff --git a/.gitea/workflows/rh9-native.yml b/.gitea/workflows/rh9-native.yml deleted file mode 100644 index a019074ef..000000000 --- a/.gitea/workflows/rh9-native.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Build on RHEL9 - -on: - push: - workflow_dispatch: - -permissions: - contents: read - -jobs: - build: - runs-on: "ubuntu-latest" - container: - image: gitea.psi.ch/detectors/rhel9-detectors-dev - steps: - - uses: actions/checkout@v4 - - - - name: Build library - run: | - mkdir build && cd build - cmake .. -DSLS_USE_PYTHON=ON -DSLS_USE_TESTS=ON -DSLS_USE_SIMULATOR=ON - make -j 2 - - - name: C++ unit tests - working-directory: ${{gitea.workspace}}/build - run: ctest -j1 --rerun-failed --output-on-failure \ No newline at end of file diff --git a/python/src/bit.cpp b/python/src/bit.cpp index 498319f51..bd08390f2 100644 --- a/python/src/bit.cpp +++ b/python/src/bit.cpp @@ -25,8 +25,12 @@ void init_bit(py::module &m) { }) .def("__str__", &RegisterAddress::str) .def("value", &RegisterAddress::value) + .def("__int__", &RegisterAddress::value) .def(py::self == py::self) - .def(py::self != py::self); + .def(py::self != py::self) + .def("__add__",&RegisterAddress::operator+) + .def("__radd__",&RegisterAddress::operator+) + .def("__iadd__",&RegisterAddress::operator+=, py::return_value_policy::reference_internal); py::class_(m, "BitAddress") .def(py::init()) @@ -51,6 +55,7 @@ void init_bit(py::module &m) { }) .def("__str__", &RegisterValue::str) .def("value", &RegisterValue::value) + .def("__int__", &RegisterValue::value) .def(py::self == py::self) .def(py::self != py::self) .def("__or__", [](const RegisterValue &lhs, diff --git a/python/tests/test_bits.py b/python/tests/test_bits.py index e679ea656..d2084c2e5 100644 --- a/python/tests/test_bits.py +++ b/python/tests/test_bits.py @@ -1,4 +1,5 @@ from slsdet.bits import clearbit, clearbit_arr, setbit, setbit_arr +from slsdet import RegisterAddress import numpy as np @@ -47,4 +48,13 @@ def test_setbit_arr(): def test_clearbit_arr(): arr = np.array((5, 5, 5), dtype=np.int8) clearbit_arr(0, arr) - assert all(arr == (4, 4, 4)) \ No newline at end of file + assert all(arr == (4, 4, 4)) + +def test_RegisterAddress_addition(): + r = RegisterAddress(0x10) + r2 = r + 0x5 + assert r2.value() == 0x15 + r3 = 0x5 + r + assert r3.value() == 0x15 + r += 0x5 + assert r.value() == 0x15 \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/Makefile b/slsDetectorServers/ctbDetectorServer/Makefile index 0b56dd825..2bc1a2576 100755 --- a/slsDetectorServers/ctbDetectorServer/Makefile +++ b/slsDetectorServers/ctbDetectorServer/Makefile @@ -28,7 +28,7 @@ boot: $(OBJS) version_name=APICTB version_path=slsDetectorServers/ctbDetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index 2692e11e1..4684df85c 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/Makefile b/slsDetectorServers/eigerDetectorServer/Makefile index 63910c6f9..f7f2be00a 100755 --- a/slsDetectorServers/eigerDetectorServer/Makefile +++ b/slsDetectorServers/eigerDetectorServer/Makefile @@ -28,7 +28,7 @@ boot: $(OBJS) version_name=APIEIGER version_path=slsDetectorServers/eigerDetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 8890ca0bc..6bfcff974 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/Makefile b/slsDetectorServers/gotthard2DetectorServer/Makefile index b5670a658..30c71d318 100755 --- a/slsDetectorServers/gotthard2DetectorServer/Makefile +++ b/slsDetectorServers/gotthard2DetectorServer/Makefile @@ -27,7 +27,7 @@ boot: $(OBJS) version_name=APIGOTTHARD2 version_path=slsDetectorServers/gotthard2DetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index d45912b79..0086d8737 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/Makefile b/slsDetectorServers/jungfrauDetectorServer/Makefile index 881f2e660..cc92b99c6 100755 --- a/slsDetectorServers/jungfrauDetectorServer/Makefile +++ b/slsDetectorServers/jungfrauDetectorServer/Makefile @@ -27,7 +27,7 @@ boot: $(OBJS) version_name=APIJUNGFRAU version_path=slsDetectorServers/jungfrauDetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index 56fbc590f..e9d362f54 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/Makefile b/slsDetectorServers/moenchDetectorServer/Makefile index 71ebbf4fd..2637c4e5d 100755 --- a/slsDetectorServers/moenchDetectorServer/Makefile +++ b/slsDetectorServers/moenchDetectorServer/Makefile @@ -27,7 +27,7 @@ boot: $(OBJS) version_name=APIMOENCH version_path=slsDetectorServers/moenchDetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index 1d3665c96..5f7877f33 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/Makefile b/slsDetectorServers/mythen3DetectorServer/Makefile index b6d68fac0..0b342191c 100755 --- a/slsDetectorServers/mythen3DetectorServer/Makefile +++ b/slsDetectorServers/mythen3DetectorServer/Makefile @@ -28,7 +28,7 @@ boot: $(OBJS) version_name=APIMYTHEN3 version_path=slsDetectorServers/mythen3DetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 2149b2a6c..42dcef1d9 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index fa13d9d7a..1fa4fe417 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1641,7 +1641,9 @@ int get_adc(int file_des) { // valid index if (ret == OK) { LOG(logDEBUG1, ("Getting ADC %d\n", serverAdcIndex)); -#if defined(MYTHEN3D) || defined(GOTTHARD2D) || defined(XILINX_CHIPTESTBOARDD) +#if defined(XILINX_CHIPTESTBOARDD) + ret = getADC(serverAdcIndex, &retval, mess); +#elif defined(MYTHEN3D) || defined(GOTTHARD2D) ret = getADC(serverAdcIndex, &retval); if (ret == FAIL) { if (ind == TEMPERATURE_FPGA) { diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/Makefile b/slsDetectorServers/xilinx_ctbDetectorServer/Makefile index 487959d6f..68609daa0 100755 --- a/slsDetectorServers/xilinx_ctbDetectorServer/Makefile +++ b/slsDetectorServers/xilinx_ctbDetectorServer/Makefile @@ -39,7 +39,7 @@ boot: $(OBJS) version_name=APIXILINXCTB version_path=slsDetectorServers/xilinx_ctbDetectorServer versioning: - cd ../../ && echo $(PWD) && echo `tput setaf 6; python updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` + cd ../../ && echo $(PWD) && echo `tput setaf 6; python etc/updateAPIVersion.py $(version_name) $(version_path); tput sgr0;` $(PROGS): $(OBJS) diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer index 3fb9ec0b3..f88fa6422 100755 Binary files a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer and b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer differ diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 9b30ab682..3d8b1d493 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -1482,11 +1482,8 @@ int setPower(enum DACINDEX ind, int val, char *mess) { return OK; } -int getADC(enum ADCINDEX ind, int *value) { +int getADC(enum ADCINDEX ind, int *value, char *mess) { *value = 0; -#ifdef VIRTUAL - return OK; -#endif switch (ind) { // slow adcs case S_ADC0: @@ -1498,44 +1495,60 @@ int getADC(enum ADCINDEX ind, int *value) { case S_ADC6: case S_ADC7: LOG(logDEBUG1, ("Reading Slow ADC Channel %d\n", (int)ind - S_ADC0)); - return getSlowADC((int)ind - S_ADC0, value); + return getSlowADC((int)ind - S_ADC0, value, mess); case TEMP_FPGA: LOG(logDEBUG1, ("Reading FPGA Temperature\n")); - return getTemperature(value); + return getTemperature(value, mess); default: - LOG(logERROR, ("Adc Index %d not defined \n", (int)ind)); + snprintf(mess, MAX_STR_LENGTH, "Adc Index %d not defined\n", (int)ind); + LOG(logERROR, (mess)); return FAIL; } } -int getSlowADC(int ichan, int *retval) { +int getSlowADC(int ichan, int *retval, char *mess) { *retval = 0; -#ifndef VIRTUAL + int fval = 0; + +#ifdef VIRTUAL + fval = 1; +#else char fname[MAX_STR_LENGTH]; memset(fname, 0, MAX_STR_LENGTH); sprintf(fname, SLOWADC_DRIVER_FILE_NAME, ichan); LOG(logDEBUG1, ("fname %s\n", fname)); - - if (readParameterFromFile(fname, "slow adc", retval) == FAIL) { - LOG(logERROR, ("Could not get slow adc\n")); + if (readParameterFromFile(fname, "slow adc", &fval) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, "Could not read slow adc channel %d\n", + ichan); + LOG(logERROR, (mess)); return FAIL; } - // TODO assuming already converted to uV - // convert to uV - // double value = SLOWDAC_CONVERTION_FACTOR_TO_UV * (double)(*retval); - // LOG(logINFO, ("Slow ADC [%d]: %f uV\n", ichan, value)); - //*retval = (int)value; - - LOG(logINFO, ("Slow ADC [%d]: %d uV\n", ichan, (*retval))); #endif + + // value in uV + int refMaxuv = SLOW_ADC_MAX_MV * 1000; + int regMinuv = 0; + int maxSteps = SLOW_ADC_MAX_STEPS; + if (ConvertToDifferentRange(0, maxSteps, regMinuv, refMaxuv, fval, + retval) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, + "Could not convert slow adc channel (fval:0x%x) to uv\n", + fval); + LOG(logERROR, (mess)); + return -1; + } + + LOG(logINFO, + ("\tSlow adc [%d]: %d uV (reg: 0x%x)\n", ichan, *retval, fval)); return OK; } -int getTemperature(int *retval) { +int getTemperature(int *retval, char *mess) { *retval = 0; #ifndef VIRTUAL if (readParameterFromFile(TEMP_DRIVER_FILE_NAME, "temperature", retval) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, "Could not read temperature\n"); LOG(logERROR, ("Could not get temperature\n")); return FAIL; } diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h index 64766d63e..8ccea05b8 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h @@ -143,9 +143,9 @@ int getPowerRail(enum PWRINDEX ind, int *retval, char *mess); int getPower(enum DACINDEX ind, int *retval, char *mess); int setPower(enum DACINDEX ind, int val, char *mess); -int getADC(enum ADCINDEX ind, int *value); -int getSlowADC(int ichan, int *retval); -int getTemperature(int *retval); +int getADC(enum ADCINDEX ind, int *value, char *mess); +int getSlowADC(int ichan, int *retval, char *mess); +int getTemperature(int *retval, char *mess); int setHighVoltage(int val); // parameters - timing, extsig diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h index ef1cef945..591bf7545 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h @@ -65,11 +65,13 @@ #define MAX_ANALOG_SAMPLES (0x3FFF) #define MAX_DIGITAL_SAMPLES (0x3FFF) -#define DAC_MIN_MV (0) -#define DAC_MAX_MV (2048) -#define POWER_RGLTR_MIN (1041) -#define POWER_RGLTR_MAX (2661) -#define VIO_MIN_MV (1200) // for fpga to function +#define DAC_MIN_MV (0) +#define DAC_MAX_MV (2048) +#define POWER_RGLTR_MIN (1041) +#define POWER_RGLTR_MAX (2661) +#define VIO_MIN_MV (1200) // for fpga to function +#define SLOW_ADC_MAX_MV (2500) // AD7689 +#define SLOW_ADC_MAX_STEPS (0xFFFF + 1) // AD7689 /* Defines in the Firmware */ #define WAIT_TIME_PATTERN_READ (10) diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 300396547..1c0870ae0 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1831,6 +1831,13 @@ void DetectorImpl::setRxROI(const std::vector &args) { auto moduleGlobalRoi = getModuleROI(iModule); // at most 2 rois per module (for each port) std::vector portRois(nPortsPerModule); + for (auto &roi : portRois) { + roi.setNoRoi(); + if (shm()->numberOfChannels.y == 1) { + roi.ymin = -1; + roi.ymax = -1; + } + } // check overlap with module for (const auto &arg : args) { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp index f00c239e3..1e489b0b0 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp @@ -540,6 +540,16 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") { REQUIRE(oss.str() == "rx_roi [[5, 10], [" + stringMin + ", " + stringMax + "]]\n"); + // setting to only one port and verify individual roi + { + REQUIRE_NOTHROW( + caller.call("rx_roi", {"[5, 10, -1, -1]"}, -1, PUT)); + std::ostringstream oss, oss1; + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss)); + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 1, GET, oss1)); + REQUIRE(oss.str() == "rx_roi [[5, 10]]\n"); + REQUIRE(oss1.str() == "rx_roi [[0, 0]]\n"); + } // verify individual roi { stringMin = std::to_string(moduleSize.x - 50); @@ -643,6 +653,38 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") { REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30], [" + stringMin + ", " + stringMax + ", 20, 30]]\n"); + // setting to only one port and verify individual roi + { + REQUIRE_NOTHROW( + caller.call("rx_roi", {"[5, 10, 20, 30]"}, -1, PUT)); + std::ostringstream oss, oss1; + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss)); + // eiger returns 2 values for 2 ports per module + if (det_type == defs::EIGER) { + REQUIRE(oss.str() == + "rx_roi [[5, 10, 20, 30], [0, 0, 0, 0]]\n"); + + } + // others return only 1 roi per module (1 port per module) + else { + REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30]]\n"); + } + if (det.size() > 1) { + REQUIRE_NOTHROW( + caller.call("rx_roi", {}, 1, GET, oss1)); + // eiger returns 2 values for 2 ports per module + if (det_type == defs::EIGER) { + REQUIRE(oss1.str() == + "rx_roi [[0, 0, 0, 0], [0, 0, 0, 0]]\n"); + + } + // others return only 1 roi per module (1 port per + // module) + else { + REQUIRE(oss1.str() == "rx_roi [[0, 0, 0, 0]]\n"); + } + } + } // verify individual roi { stringMin = std::to_string(portSize.x - delta); @@ -710,6 +752,43 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") { REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30], [25, 28, " + stringMin + ", " + stringMax + "]]\n"); + // setting to only one port and verify individual roi + { + REQUIRE_NOTHROW( + caller.call("rx_roi", {"[ 5, 10, 20, 30]"}, -1, PUT)); + std::ostringstream oss, oss1; + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss)); + + // 2 ports + if (((det_type == defs::JUNGFRAU || + det_type == defs::MOENCH) && + (numinterfaces == 2)) || + (det_type == defs::EIGER)) { + REQUIRE(oss.str() == + "rx_roi [[5, 10, 20, 30], [0, 0, 0, 0]]\n"); + } + // others return only 1 roi per module (1 port per module) + else { + REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30]]\n"); + } + if (det.size() > 2) { + REQUIRE_NOTHROW( + caller.call("rx_roi", {}, 1, GET, oss1)); + // 2 ports + if (((det_type == defs::JUNGFRAU || + det_type == defs::MOENCH) && + (numinterfaces == 2)) || + (det_type == defs::EIGER)) { + REQUIRE(oss1.str() == + "rx_roi [[0, 0, 0, 0], [0, 0, 0, 0]]\n"); + } + // others return only 1 roi per module (1 port per + // module) + else { + REQUIRE(oss1.str() == "rx_roi [[0, 0, 0, 0]]\n"); + } + } + } // verify individual roi { stringMin = std::to_string(portSize.y - delta); @@ -741,7 +820,7 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") { REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + - "], [-1, -1]]\n"); + "], [0, 0, 0, 0]]\n"); } else { REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + diff --git a/slsDetectorSoftware/tests/test-SharedMemory.cpp b/slsDetectorSoftware/tests/test-SharedMemory.cpp index 1f9355a4b..d8a1efb16 100644 --- a/slsDetectorSoftware/tests/test-SharedMemory.cpp +++ b/slsDetectorSoftware/tests/test-SharedMemory.cpp @@ -42,9 +42,11 @@ constexpr int shm_id = 10; // macOS does not expose shm in the filesystem #ifndef __APPLE__ +const char *env_p = std::getenv(SHM_ENV_NAME); +std::string env_name = env_p ? ("_" + std::string(env_p)) : ""; const std::string file_path = std::string("/dev/shm/slsDetectorPackage_detector_") + - std::to_string(shm_id); + std::to_string(shm_id) + env_name; TEST_CASE("Free obsolete (without isValid)", "[detector][shm]") { diff --git a/slsSupportLib/include/sls/bit_utils.h b/slsSupportLib/include/sls/bit_utils.h index af86a8462..559e11b26 100644 --- a/slsSupportLib/include/sls/bit_utils.h +++ b/slsSupportLib/include/sls/bit_utils.h @@ -36,6 +36,15 @@ class RegisterAddress { constexpr bool operator!=(const RegisterAddress &other) const { return (value_ != other.value_); } + constexpr RegisterAddress &operator+=(uint32_t offset) noexcept { + value_ += offset; + return *this; + } + constexpr RegisterAddress operator+(uint32_t offset) const noexcept { + RegisterAddress tmp(*this); + tmp += offset; + return tmp; + } }; class BitAddress { @@ -102,4 +111,9 @@ std::ostream &operator<<(std::ostream &os, const RegisterAddress &r); std::ostream &operator<<(std::ostream &os, const BitAddress &r); std::ostream &operator<<(std::ostream &os, const RegisterValue &r); +constexpr RegisterAddress operator+(uint32_t offset, + const RegisterAddress &addr) noexcept { + return addr + offset; +} + } // namespace sls diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 69f65fa66..bb8c4c4d4 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -3,10 +3,10 @@ /** API versions */ #define APILIB "0.0.0 0x250909" #define APIRECEIVER "0.0.0 0x250822" -#define APICTB "0.0.0 0x260219" -#define APIGOTTHARD2 "0.0.0 0x260218" -#define APIMOENCH "0.0.0 0x260218" -#define APIEIGER "0.0.0 0x260218" -#define APIXILINXCTB "0.0.0 0x260227" -#define APIJUNGFRAU "0.0.0 0x260218" -#define APIMYTHEN3 "0.0.0 0x260219" +#define APICTB "0.0.0 0x260227" +#define APIGOTTHARD2 "0.0.0 0x260227" +#define APIMOENCH "0.0.0 0x260227" +#define APIEIGER "0.0.0 0x260227" +#define APIXILINXCTB "0.0.0 0x260305" +#define APIJUNGFRAU "0.0.0 0x260227" +#define APIMYTHEN3 "0.0.0 0x260227" diff --git a/slsSupportLib/tests/test-bit_utils.cpp b/slsSupportLib/tests/test-bit_utils.cpp index 713e1c2ce..ac9ddad8a 100644 --- a/slsSupportLib/tests/test-bit_utils.cpp +++ b/slsSupportLib/tests/test-bit_utils.cpp @@ -43,7 +43,7 @@ TEST_CASE("Get set bits from 523") { REQUIRE(vec == std::vector{0, 1, 3, 9}); } -TEST_CASE("Convert RegisterAddress using classes ", "[support][.bit_utils]") { +TEST_CASE("Convert RegisterAddress using classes ", "[support]") { std::vector vec_addr{0x305, 0xffffffff, 0x0, 0x34550987, 0x1fff1fff}; std::vector vec_ans{"0x305", "0xffffffff", "0x0", "0x34550987", @@ -64,7 +64,7 @@ TEST_CASE("Convert RegisterAddress using classes ", "[support][.bit_utils]") { } } -TEST_CASE("Convert RegisterValue using classes ", "[support][.bit_utils]") { +TEST_CASE("Convert RegisterValue using classes ", "[support]") { std::vector vec_addr{0x305, 0xffffffff, 0x0, 500254562, 0x1fff1fff}; std::vector vec_ans{"0x305", "0xffffffff", "0x0", "0x1dd14762", @@ -80,11 +80,10 @@ TEST_CASE("Convert RegisterValue using classes ", "[support][.bit_utils]") { CHECK(reg0.str() == vec_ans[i]); CHECK((reg0 | 0xffffffffu) == RegisterValue(0xffffffffu)); CHECK((reg0 | 0x0) == reg0); - CHECK((reg0 | 0x1) == reg0); } } -TEST_CASE("Convert BitAddress using classes", "[support][.bit_utils]") { +TEST_CASE("Convert BitAddress using classes", "[support]") { std::vector vec_addr{ RegisterAddress(0x305), RegisterAddress(0xffffffffu), RegisterAddress(0x0), RegisterAddress(0x34550987), @@ -123,7 +122,7 @@ TEST_CASE("Convert BitAddress using classes", "[support][.bit_utils]") { } TEST_CASE("Output operator gives same result as string", - "[support][.bit_utils]") { + "[support]") { { RegisterAddress addr{0x3456af}; std::ostringstream os; @@ -148,3 +147,23 @@ TEST_CASE("Output operator gives same result as string", } } // namespace sls + +TEST_CASE("RegisterAddress addition with uint", "[support]") { + using sls::RegisterAddress; + + RegisterAddress r{0x10u}; + + // member operator+ + auto r_plus = r + 5u; + CHECK(r_plus == RegisterAddress(0x15u)); + // original unchanged + CHECK(r == RegisterAddress(0x10u)); + + // operator+= + r += 2u; + CHECK(r == RegisterAddress(0x12u)); + + // non-member uint + RegisterAddress + auto uint_plus = 3u + r; // 0x12 + 3 == 0x15 + CHECK(uint_plus == RegisterAddress(0x15u)); +}