diff --git a/.travis.yml b/.travis.yml index d6cd07a07..4b2a82db4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,4 +34,5 @@ deploy: script: find $HOME/miniconda/envs/testenv/conda-bld/${TRAVIS_OS_NAME}-64 -name "*.tar.bz2" -exec anaconda -t $CONDA_TOKEN upload --force {} \; on: branch: developer + tags: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b7e23376..def39765a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project(slsDetectorPackage) set(PROJECT_VERSION 5.0.0) include(CheckIPOSupported) - +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") cmake_policy(SET CMP0074 NEW) include(cmake/project_version.cmake) @@ -44,6 +44,9 @@ option(SLS_USE_PYTHON "Python bindings" OFF) option(SLS_USE_CTBGUI "ctb GUI" OFF) option(SLS_BUILD_DOCS "docs" OFF) option(SLS_BUILD_EXAMPLES "examples" OFF) +option(SLS_TUNE_LOCAL "tune to local machine" OFF) + + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -111,6 +114,11 @@ if(SLS_USE_SANITIZER) # target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread) endif() +if(SLS_TUNE_LOCAL) + target_compile_options(slsProjectOptions INTERFACE -mtune=native -march=native) +endif() + + #rapidjson add_library(rapidjson INTERFACE) target_include_directories(rapidjson INTERFACE diff --git a/conda-recepie/meta.yaml b/conda-recepie/meta.yaml index 361e1389a..9bec2c228 100755 --- a/conda-recepie/meta.yaml +++ b/conda-recepie/meta.yaml @@ -1,13 +1,13 @@ package: name: sls_detector_software - version: "developer" + version: {{ environ.get('GIT_DESCRIBE_TAG', '') }} source: - path: .. build: - number: 1 + number: 2 binary_relocation: True rpaths: - lib/ diff --git a/python/scripts/basic.py b/python/scripts/basic.py index 8cdd99885..5c92b32c3 100755 --- a/python/scripts/basic.py +++ b/python/scripts/basic.py @@ -3,9 +3,9 @@ import sys import numpy as np sys.path.append(os.path.join(os.getcwd(), 'bin')) -from sls_detector import Detector, Mythen3, Eiger, Jungfrau, DetectorDacs, Dac, Ctb -from sls_detector import dacIndex, readoutMode -from sls_detector.lookup import view, find +from slsdet import Detector, Mythen3, Eiger, Jungfrau, DetectorDacs, Dac, Ctb +from slsdet import dacIndex, readoutMode +from slsdet.lookup import view, find d = Detector() # e = Eiger() diff --git a/python/setup.py b/python/setup.py index bdf459762..229e265b6 100755 --- a/python/setup.py +++ b/python/setup.py @@ -8,7 +8,7 @@ import sys import setuptools import os -__version__ = 'udp' +__version__ = os.environ.get('GIT_DESCRIBE_TAG', 'developer') def get_conda_path(): diff --git a/python/slsdet/lookup.py b/python/slsdet/lookup.py index 30ad3842c..be157841d 100644 --- a/python/slsdet/lookup.py +++ b/python/slsdet/lookup.py @@ -1,9 +1,9 @@ from .detector import Detector -def view(name): - names = find(name) +def view(name, det = Detector): + names = find(name, det) for n in names: print(n) -def find(name): - return [n for n in dir(Detector) if name in n] \ No newline at end of file +def find(name, det = Detector): + return [n for n in dir(det) if name.lower() in n.lower()] \ No newline at end of file diff --git a/python/src/detector.cpp b/python/src/detector.cpp index ddd3e991f..c45daeb74 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -428,6 +428,13 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setImageTestMode", &Detector::setImageTestMode, py::arg(), py::arg() = Positions{}) + .def("getNumberOfBursts", &Detector::getNumberOfBursts, + py::arg() = Positions{}) + .def("setNumberOfBursts", &Detector::setNumberOfBursts, py::arg()) + .def("getBurstPeriod", &Detector::getBurstPeriod, + py::arg() = Positions{}) + .def("setBurstPeriod", &Detector::setBurstPeriod, py::arg(), + py::arg() = Positions{}) .def("getInjectChannel", &Detector::getInjectChannel, py::arg() = Positions{}) .def("setInjectChannel", &Detector::setInjectChannel, py::arg(), @@ -441,6 +448,14 @@ void init_det(py::module &m) { .def("getBurstMode", &Detector::getBurstMode, py::arg() = Positions{}) .def("setBurstMode", &Detector::setBurstMode, py::arg(), py::arg() = Positions{}) + .def("getCurrentSource", &Detector::getCurrentSource, + py::arg() = Positions{}) + .def("setCurrentSource", &Detector::setCurrentSource, py::arg(), + py::arg() = Positions{}) + .def("getTimingSource", &Detector::getTimingSource, + py::arg() = Positions{}) + .def("setTimingSource", &Detector::setTimingSource, py::arg(), + py::arg() = Positions{}) .def("getCounterMask", &Detector::getCounterMask, py::arg() = Positions{}) .def("setCounterMask", &Detector::setCounterMask, py::arg(), diff --git a/python/src/enums.cpp b/python/src/enums.cpp index bb7671e6f..9b857aa79 100644 --- a/python/src/enums.cpp +++ b/python/src/enums.cpp @@ -284,4 +284,11 @@ void init_enums(py::module &m) { .value("BURST_INTERNAL", slsDetectorDefs::burstMode::BURST_INTERNAL) .value("BURST_EXTERNAL", slsDetectorDefs::burstMode::BURST_EXTERNAL) .export_values(); + + py::enum_(Defs, "timingSourceType") + .value("TIMING_INTERNAL", + slsDetectorDefs::timingSourceType::TIMING_INTERNAL) + .value("TIMING_EXTERNAL", + slsDetectorDefs::timingSourceType::TIMING_EXTERNAL) + .export_values(); } diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index fdbad1b09..6f4b8934d 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -166,7 +166,7 @@ void qDrawPlot::SetupPlots() { plot1d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); plot1d->SetXFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); plot1d->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); - plot1d->SetTitle("--"); + plot1d->SetTitle(""); plot1d->SetXTitle(xTitle1d); plot1d->SetYTitle(yTitle1d); h->Attach(plot1d); @@ -186,12 +186,16 @@ void qDrawPlot::SetupPlots() { gainhist1d->setSymbolMarkers(isMarkers); // setup 1d gain plot gainplot1d = new SlsQt1DPlot(boxPlot); - //gainplot1d->setFont(QFont("Sans Serif", 3, 20)); + gainplot1d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); + gainplot1d->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); gainplot1d->SetTitle(""); - gainplot1d->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtScaleDraw::Labels, false); - gainplot1d->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtScaleDraw::Ticks, false); - gainplot1d->axisScaleDraw(QwtPlot::yLeft)->enableComponent(QwtScaleDraw::Labels, false); - gainplot1d->axisScaleDraw(QwtPlot::yLeft)->enableComponent(QwtScaleDraw::Ticks, false); + gainplot1d->SetYTitle("Gain"); + // set ticks to just 3 + QList majorTicks({0, 1, 2, 3}); + QwtScaleDiv div( 0, 3, QList(), QList(), majorTicks); + gainplot1d->setAxisScaleDiv( QwtPlot::yLeft, div ); + //gainplot1d->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtScaleDraw::Ticks, false); + //gainplot1d->axisScaleDraw(QwtPlot::yLeft)->enableComponent(QwtScaleDraw::Labels, false); gainhist1d->setItemAttribute(QwtPlotItem::Legend, false); gainhist1d->Attach(gainplot1d); gainplot1d->hide(); @@ -233,18 +237,21 @@ void qDrawPlot::SetupPlots() { gainplot2d = new SlsQt2DPlot(boxPlot); gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5, nPixelsY - 0.5, gainData); - gainplot2d->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); - gainplot2d->setTitle(""); - gainplot2d->enableAxis(0, false); - gainplot2d->enableAxis(1, false); - gainplot2d->enableAxis(2, false); + gainplot2d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); + gainplot2d->setTitle("Gain"); + gainplot2d->SetZTitle(""); + gainplot2d->enableAxis(QwtPlot::yLeft, false); + //gainplot2d->enableAxis(1, false); + gainplot2d->enableAxis(QwtPlot::xBottom, false); + // set ticks to just 3 + gainplot2d->setAxisScaleDiv( QwtPlot::yRight, div ); gainplot2d->hide(); // layout of plots int ratio = qDefs::DATA_GAIN_PLOT_RATIO - 1; plotLayout->addWidget(plot1d, 0, 0, ratio, ratio); plotLayout->addWidget(plot2d, 0, 0, ratio, ratio); - plotLayout->addWidget(gainplot1d, 0, ratio, 1, 1, Qt::AlignRight | Qt::AlignTop); + plotLayout->addWidget(gainplot1d, ratio, 0, 1, ratio, Qt::AlignTop); plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1, Qt::AlignRight | Qt::AlignTop); } @@ -254,7 +261,7 @@ void qDrawPlot::resizeEvent(QResizeEvent *event) { gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO); } if (gainplot1d->isVisible()) { - gainplot1d->setFixedWidth(plot1d->width() / qDefs::DATA_GAIN_PLOT_RATIO); + gainplot1d->setFixedWidth(plot1d->width()); gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO); } event->accept(); @@ -871,7 +878,7 @@ void qDrawPlot::Update1dPlot() { gainhist1d->setSymbolMarkers(isMarkers); gainhist1d->Attach(gainplot1d); if (!gainplot1d->isVisible()) { - gainplot1d->setFixedWidth(plot1d->width() / qDefs::DATA_GAIN_PLOT_RATIO); + gainplot1d->setFixedWidth(plot1d->width() ); gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO); gainplot1d->show(); } diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index 2bd73a927..4fbea4210 100755 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -65,6 +65,8 @@ void qTabPlot::SetupWidgetWindow() { case slsDetectorDefs::GOTTHARD2: is1d = true; chkGainPlot1D->setEnabled(true); + chkGainPlot1D->setChecked(true); + plot->EnableGainPlot(true); break; case slsDetectorDefs::EIGER: chkGapPixels->setEnabled(true); @@ -72,6 +74,8 @@ void qTabPlot::SetupWidgetWindow() { case slsDetectorDefs::JUNGFRAU: case slsDetectorDefs::MOENCH: chkGainPlot->setEnabled(true); + chkGainPlot->setChecked(true); + plot->EnableGainPlot(true); break; default: break; diff --git a/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h b/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h index ca750d137..1cf6c46ba 100644 --- a/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h +++ b/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h @@ -104,6 +104,8 @@ #define CONTROL_PRPHRL_RST_MSK (0x00000001 << CONTROL_PRPHRL_RST_OFST) #define CONTROL_CLR_ACQSTN_FIFO_OFST (15) #define CONTROL_CLR_ACQSTN_FIFO_MSK (0x00000001 << CONTROL_CLR_ACQSTN_FIFO_OFST) +#define CONTROL_TIMING_SOURCE_EXT_OFST (17) +#define CONTROL_TIMING_SOURCE_EXT_MSK (0x00000001 << CONTROL_TIMING_SOURCE_EXT_OFST) #define CONTROL_PWR_CHIP_OFST (31) #define CONTROL_PWR_CHIP_MSK (0x00000001 << CONTROL_PWR_CHIP_OFST) @@ -128,6 +130,8 @@ #define ASIC_CONFIG_FIX_GAIN_1_VAL ((0x1 << ASIC_CONFIG_GAIN_OFST) & ASIC_CONFIG_GAIN_MSK) #define ASIC_CONFIG_FIX_GAIN_2_VAL ((0x2 << ASIC_CONFIG_GAIN_OFST) & ASIC_CONFIG_GAIN_MSK) #define ASIC_CONFIG_RESERVED_VAL ((0x3 << ASIC_CONFIG_GAIN_OFST) & ASIC_CONFIG_GAIN_MSK) +#define ASIC_CONFIG_CURRENT_SRC_EN_OFST (7) +#define ASIC_CONFIG_CURRENT_SRC_EN_MSK (0x00000001 << ASIC_CONFIG_CURRENT_SRC_EN_OFST) #define ASIC_CONFIG_RST_DAC_OFST (15) #define ASIC_CONFIG_RST_DAC_MSK (0x00000001 << ASIC_CONFIG_RST_DAC_OFST) #define ASIC_CONFIG_DONE_OFST (31) diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index 8e9aa7171..2bdf2b037 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index fb9ccaad6..59773421c 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -447,6 +447,8 @@ void setupDetector() { setDelayAfterTrigger(DEFAULT_DELAY_AFTER_TRIGGER); setBurstPeriod(DEFAULT_BURST_PERIOD); setTiming(DEFAULT_TIMING_MODE); + setCurrentSource(DEFAULT_CURRENT_SOURCE); + setTimingSource(DEFAULT_TIMING_SOURCE); } int readConfigFile() { @@ -1961,6 +1963,44 @@ enum burstMode getBurstMode() { return burstMode; } +void setCurrentSource(int value) { + uint32_t addr = ASIC_CONFIG_REG; + if (value > 0) { + bus_w(addr, (bus_r(addr) | ASIC_CONFIG_CURRENT_SRC_EN_MSK)); + } else if (value == 0) { + bus_w(addr, (bus_r(addr) &~ ASIC_CONFIG_CURRENT_SRC_EN_MSK)); + } +} + +int getCurrentSource() { + return ((bus_r(ASIC_CONFIG_REG) & ASIC_CONFIG_CURRENT_SRC_EN_MSK) >> ASIC_CONFIG_CURRENT_SRC_EN_OFST); +} + +void setTimingSource(enum timingSourceType value) { + uint32_t addr = CONTROL_REG; + switch (value) { + case TIMING_INTERNAL: + FILE_LOG(logINFO, ("Setting timing source to internal\n")); + bus_w(addr, (bus_r(addr) &~ CONTROL_TIMING_SOURCE_EXT_MSK)); + break; + case TIMING_EXTERNAL: + FILE_LOG(logINFO, ("Setting timing source to exernal\n")); + bus_w(addr, (bus_r(addr) | CONTROL_TIMING_SOURCE_EXT_MSK)); + break; + default: + FILE_LOG(logERROR, ("Unknown timing source %d\n", value)); + break; + } +} + +enum timingSourceType getTimingSource() { + if (bus_r(CONTROL_REG) & CONTROL_TIMING_SOURCE_EXT_MSK) { + return TIMING_EXTERNAL; + } + return TIMING_INTERNAL; +} + + /* aquisition */ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h index 063464f0d..0104a0ee3 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h @@ -41,6 +41,9 @@ #define DEFAULT_HIGH_VOLTAGE (0) #define DEFAULT_TIMING_MODE (AUTO_TIMING) #define DEFAULT_SETTINGS (DYNAMICGAIN) +#define DEFAULT_CURRENT_SOURCE (0) +#define DEFAULT_TIMING_SOURCE (TIMING_INTERNAL) + #define DEFAULT_READOUT_C0 (144444448) // rdo_clk, 144 MHz #define DEFAULT_READOUT_C1 (144444448) // rdo_x2_clk, 144 MHz #define DEFAULT_SYSTEM_C0 (144444448) // run_clk, 144 MHz @@ -50,7 +53,7 @@ /* Firmware Definitions */ #define IP_HEADER_SIZE (20) -#define FIXED_PLL_FREQUENCY (020000000) // 20MHz +#define FIXED_PLL_FREQUENCY (20000000) // 20MHz #define READOUT_PLL_VCO_FREQ_HZ (866666688) // 866 MHz #define SYSTEM_PLL_VCO_FREQ_HZ (722222224) // 722 MHz diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 955a16feb..e0295aa1c 100755 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -482,6 +482,10 @@ int configureADC(); int setBurstModeinFPGA(enum burstMode value); int setBurstMode(enum burstMode burst); enum burstMode getBurstMode(); +void setCurrentSource(int value); +int getCurrentSource(); +void setTimingSource(enum timingSourceType value); +enum timingSourceType getTimingSource(); #endif diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 730a9e74e..964273cb4 100755 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -212,3 +212,7 @@ int get_num_bursts(int); int set_num_bursts(int); int get_burst_period(int); int set_burst_period(int); +int get_current_source(int); +int set_current_source(int); +int get_timing_source(int); +int set_timing_source(int); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index bff9d25d4..51170c764 100755 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -319,6 +319,10 @@ const char* getFunctionName(enum detFuncs func) { case F_SET_NUM_BURSTS: return "F_SET_NUM_BURSTS"; case F_GET_BURST_PERIOD: return "F_GET_BURST_PERIOD"; case F_SET_BURST_PERIOD: return "F_SET_BURST_PERIOD"; + case F_GET_CURRENT_SOURCE: return "F_GET_CURRENT_SOURCE"; + case F_SET_CURRENT_SOURCE: return "F_SET_CURRENT_SOURCE"; + case F_GET_TIMING_SOURCE: return "F_GET_TIMING_SOURCE"; + case F_SET_TIMING_SOURCE: return "F_SET_TIMING_SOURCE"; default: return "Unknown Function"; } @@ -507,6 +511,10 @@ void function_table() { flist[F_SET_NUM_BURSTS] = &set_num_bursts; flist[F_GET_BURST_PERIOD] = &get_burst_period; flist[F_SET_BURST_PERIOD] = &set_burst_period; + flist[F_GET_CURRENT_SOURCE] = &get_current_source; + flist[F_SET_CURRENT_SOURCE] = &set_current_source; + flist[F_GET_TIMING_SOURCE] = &get_timing_source; + flist[F_SET_TIMING_SOURCE] = &set_timing_source; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -6735,4 +6743,102 @@ int set_burst_period(int file_des) { } #endif return Server_SendResult(file_des, INT64, UPDATE, NULL, 0); +} + + +int set_current_source(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = 0; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logINFO, ("Setting current source enable: %u\n", arg)); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + setCurrentSource(arg); + int retval = getCurrentSource(); + FILE_LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); + validate(arg, retval, "current source enable", DEC); + } +#endif + return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); +} + + +int get_current_source(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retval = -1; + + FILE_LOG(logDEBUG1, ("Getting current source enable\n")); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // get only + retval = getCurrentSource(); + FILE_LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); +#endif + return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); +} + + +int set_timing_source(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + enum timingSourceType arg = TIMING_INTERNAL; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Setting timing source: %d\n", arg)); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + switch (arg) { + case TIMING_INTERNAL: + case TIMING_EXTERNAL: + break; + default: + modeNotImplemented("timing source", (int)arg); + break; + } + if (ret == OK) { + setTimingSource(arg); + enum timingSourceType retval = getTimingSource(); + FILE_LOG(logDEBUG, ("timing source retval: %d\n", retval)); + if (retval != arg) { + ret = FAIL; + sprintf(mess, "Could not set timing source. Set %d, got %d\n", arg, retval); + FILE_LOG(logERROR, (mess)); + } + } + } +#endif + return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); +} + + +int get_timing_source(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + enum timingSourceType retval = TIMING_INTERNAL; + + FILE_LOG(logDEBUG1, ("Getting timing source\n")); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // get only + retval = getTimingSource(); + FILE_LOG(logDEBUG1, ("Get timing source retval:%d\n", retval)); +#endif + return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); } \ No newline at end of file diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index e32635523..eab4b6f9c 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -931,6 +931,18 @@ class Detector { /** [Gotthard2] BURST_OFF, BURST_INTERNAL (default), BURST_EXTERNAL */ void setBurstMode(defs::burstMode value, Positions pos = {}); + /** [Gotthard2] */ + Result getCurrentSource(Positions pos = {}) const; + + /** default disabled */ + void setCurrentSource(bool value, Positions pos = {}); + + /** [Gotthard2] */ + Result getTimingSource(Positions pos = {}) const; + + /** [Gotthard2] Options: TIMING_INTERNAL, TIMING_EXTERNAL */ + void setTimingSource(defs::timingSourceType value, Positions pos = {}); + /************************************************** * * * Mythen3 Specific * diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 8dace8a6f..1a5adeca4 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -790,6 +790,8 @@ class CmdProxy { {"vetophoton", &CmdProxy::VetoPhoton}, {"vetoref", &CmdProxy::VetoReference}, {"burstmode", &CmdProxy::BurstMode}, + {"currentsource", &CmdProxy::currentsource}, + {"timingsource", &CmdProxy::timingsource}, /* Mythen3 Specific */ {"counters", &CmdProxy::Counters}, @@ -1564,6 +1566,12 @@ class CmdProxy { "[0, 1]\n\t[Gotthard] 1 adds channel intensity with precalculated values when taking an acquisition. Default is 0."); /* Gotthard2 Specific */ + INTEGER_COMMAND(currentsource, getCurrentSource, setCurrentSource, std::stoi, + "[0, 1]\n\t[Gotthard2] Enable or disable current source. Default is disabled."); + + INTEGER_COMMAND(timingsource, getTimingSource, setTimingSource, sls::StringTo, + "[internal|external]\n\t[Gotthard2] Timing source. Internal is crystal and external is system timing. Default is internal."); + /* Mythen3 Specific */ /* CTB Specific */ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 1cd925a3d..51520f027 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1204,6 +1204,22 @@ void Detector::setBurstMode(defs::burstMode value, Positions pos) { pimpl->Parallel(&slsDetector::setBurstMode, pos, value); } +Result Detector::getCurrentSource(Positions pos) const { + return pimpl->Parallel(&slsDetector::getCurrentSource, pos); +} + +void Detector::setCurrentSource(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setCurrentSource, pos, value); +} + +Result Detector::getTimingSource(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimingSource, pos); +} + +void Detector::setTimingSource(defs::timingSourceType value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimingSource, pos, value); +} + // Mythen3 Specific Result Detector::getCounterMask(Positions pos) const { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 331645f7c..3519f582a 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -2546,6 +2546,32 @@ void slsDetector::setBurstMode(slsDetectorDefs::burstMode value) { shm()->burstMode = value; } +bool slsDetector::getCurrentSource() { + int retval = -1; + sendToDetector(F_GET_CURRENT_SOURCE, nullptr, retval); + FILE_LOG(logDEBUG1) << "Current source enable:" << retval; + return static_cast(retval); +} + +void slsDetector::setCurrentSource(bool value) { + int arg = static_cast(value); + FILE_LOG(logDEBUG1) << "Setting current source enable to " << arg; + sendToDetector(F_SET_CURRENT_SOURCE, arg, nullptr); +} + +slsDetectorDefs::timingSourceType slsDetector::getTimingSource() { + int retval = -1; + sendToDetector(F_GET_TIMING_SOURCE, nullptr, retval); + FILE_LOG(logDEBUG1) << "Timing source:" << retval; + return static_cast(retval); +} + +void slsDetector::setTimingSource(slsDetectorDefs::timingSourceType value) { + int arg = static_cast(value); + FILE_LOG(logDEBUG1) << "Setting timing source to " << arg; + sendToDetector(F_SET_TIMING_SOURCE, arg, nullptr); +} + int slsDetector::setCounterBit(int cb) { int retval = -1; FILE_LOG(logDEBUG1) << "Sending counter bit " << cb; diff --git a/slsDetectorSoftware/src/slsDetector.h b/slsDetectorSoftware/src/slsDetector.h index 78d4e51aa..d5f318053 100755 --- a/slsDetectorSoftware/src/slsDetector.h +++ b/slsDetectorSoftware/src/slsDetector.h @@ -1152,6 +1152,18 @@ class slsDetector : public virtual slsDetectorDefs { /** [Gotthard2] BURST_OFF, BURST_INTERNAL (default), BURST_EXTERNAL */ void setBurstMode(burstMode value); + + /** [Gotthard2] */ + bool getCurrentSource(); + + /** default disabled */ + void setCurrentSource(bool value); + + /** [Gotthard2] */ + slsDetectorDefs::timingSourceType getTimingSource(); + + /** [Gotthard2] Options: TIMING_INTERNAL, TIMING_EXTERNAL */ + void setTimingSource(slsDetectorDefs::timingSourceType value); /** * Set/get counter bit in detector (Gotthard) diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index 688475aea..a15564970 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -282,3 +282,62 @@ TEST_CASE("burstperiod", "[.cmd]") { } +TEST_CASE("currentsource", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::GOTTHARD2) { + auto prev_val = det.getCurrentSource(); + { + std::ostringstream oss; + proxy.Call("currentsource", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "currentsource 1\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "currentsource 0\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {}, -1, GET, oss); + REQUIRE(oss.str() == "currentsource 0\n"); + } + for (int i = 0; i != det.size(); ++i) { + det.setCurrentSource(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("currentsource", {}, -1, GET)); + } +} + +TEST_CASE("timingsource", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::GOTTHARD2) { + auto prev_val = det.getTimingSource(); + /* { until its activated in fpga + std::ostringstream oss; + proxy.Call("timingsource", {"external"}, -1, PUT, oss); + REQUIRE(oss.str() == "timingsource external\n"); + }*/ + { + std::ostringstream oss; + proxy.Call("timingsource", {"internal"}, -1, PUT, oss); + REQUIRE(oss.str() == "timingsource internal\n"); + } + { + std::ostringstream oss; + proxy.Call("timingsource", {}, -1, GET, oss); + REQUIRE(oss.str() == "timingsource internal\n"); + } + for (int i = 0; i != det.size(); ++i) { + det.setTimingSource(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("timingsource", {}, -1, GET)); + } +} diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 6a0a1ed45..e22d1732a 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -217,6 +217,18 @@ inline std::string ToString(const defs::burstMode s) { } } + +inline std::string ToString(const defs::timingSourceType s) { + switch (s) { + case defs::TIMING_INTERNAL: + return std::string("internal"); + case defs::TIMING_EXTERNAL: + return std::string("external"); + default: + return std::string("Unknown"); + } +} + // in case we already have a string // causes a copy but might be needed in generic code inline std::string ToString(const std::string& s) { @@ -574,6 +586,15 @@ inline defs::burstMode StringTo(const std::string& s) { throw sls::RuntimeError("Unknown burst mode " + s); } +template <> +inline defs::timingSourceType StringTo(const std::string& s) { + if (s == "internal") + return defs::TIMING_INTERNAL; + if (s == "external") + return defs::TIMING_EXTERNAL; + throw sls::RuntimeError("Unknown timing source type " + s); +} + /** For types with a .str() method use this for conversion */ template diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index a28f4cc84..6c1056f84 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -444,9 +444,17 @@ class slsDetectorDefs { enum burstMode { BURST_OFF, BURST_INTERNAL, - BURST_EXTERNAL, + BURST_EXTERNAL }; + /** + * timing source for gotthard2 + */ + enum timingSourceType { + TIMING_INTERNAL, + TIMING_EXTERNAL + }; + #ifdef __cplusplus protected: diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index f7ae6c4ac..4985b985d 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -192,6 +192,10 @@ enum detFuncs{ F_SET_NUM_BURSTS, F_GET_BURST_PERIOD, F_SET_BURST_PERIOD, + F_GET_CURRENT_SOURCE, + F_SET_CURRENT_SOURCE, + F_GET_TIMING_SOURCE, + F_SET_TIMING_SOURCE, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this (detector server should not compile anyway) */ @@ -451,7 +455,11 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_NUM_BURSTS: return "F_GET_NUM_BURSTS"; case F_SET_NUM_BURSTS: return "F_SET_NUM_BURSTS"; case F_GET_BURST_PERIOD: return "F_GET_BURST_PERIOD"; - case F_SET_BURST_PERIOD: return "F_SET_BURST_PERIOD"; + case F_SET_BURST_PERIOD: return "F_SET_BURST_PERIOD"; + case F_GET_CURRENT_SOURCE: return "F_GET_CURRENT_SOURCE"; + case F_SET_CURRENT_SOURCE: return "F_SET_CURRENT_SOURCE"; + case F_GET_TIMING_SOURCE: return "F_GET_TIMING_SOURCE"; + case F_SET_TIMING_SOURCE: return "F_SET_TIMING_SOURCE"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 8a6c5cb72..b5d4b63ac 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -1,7 +1,6 @@ /** API versions */ #define GITBRANCH "developer" #define APIMOENCH 0x200131 -#define APIGOTTHARD2 0x200226 #define APIMYTHEN3 0x200226 #define APIJUNGFRAU 0x200226 #define APIEIGER 0x200226 @@ -10,3 +9,4 @@ #define APIRECEIVER 0x200227 #define APIGUI 0x200227 #define APICTB 0x200227 +#define APIGOTTHARD2 0x200228