diff --git a/.gitignore b/.gitignore index d31ff259f..0a79fe941 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,10 @@ build RELEASE.txt Testing/ +ctbDict.cpp +ctbDict.h + + *.pyc */__pycache__/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 575e3c693..e73075393 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ option (SLS_USE_TESTS "TESTS" OFF) option (SLS_USE_INTEGRATION_TESTS "Integration Tests" OFF) option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF) option(SLS_USE_PYTHON "Python bindings" OFF) +option(SLS_BUILD_DOCS "Documentations" OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -151,8 +152,7 @@ if (SLS_USE_RECEIVER) if (SLS_USE_HDF5) find_package(HDF5 1.10 COMPONENTS CXX REQUIRED) endif (SLS_USE_HDF5) - add_subdirectory(slsReceiverSoftware) - add_subdirectory(manual/manual-api) + add_subdirectory(slsReceiverSoftware) endif (SLS_USE_RECEIVER) if (SLS_USE_GUI) @@ -181,10 +181,11 @@ configure_file( .clang-tidy ) -add_subdirectory(sample) - -add_subdirectory(docs) +#add_subdirectory(sample) +if(SLS_BUILD_DOCS) + add_subdirectory(docs) +endif(SLS_BUILD_DOCS) diff --git a/ctbGui/Makefile.root5 b/ctbGui/Makefile.root5 index 0617d61dd..698a06e4c 100644 --- a/ctbGui/Makefile.root5 +++ b/ctbGui/Makefile.root5 @@ -1,17 +1,17 @@ INCS=ctbMain.h ctbDacs.h ctbPattern.h ctbSignals.h ctbAdcs.h ctbAcquisition.h ctbPowers.h ctbSlowAdcs.h -SRC= $(SRC:.h=.cpp) ctbDict.cpp +SRC= $(INCS:.h=.cpp) ctbDict.cpp LINKDEF=ctbLinkDef.h ZMQLIB=../slsReceiverSoftware/include LIBRARYCBF=$(CBFLIBDIR)/lib/*.o INCDIR=-I../slsReceiverSoftware/include/ -I../slsDetectorSoftware/include/ -I../slsSupportLib/include/ -I../slsDetectorCalibration -I../slsDetectorCalibration/dataStructures -I$(CBFLIBDIR)/include -I../slsDetectorCalibration/interpolations -LDFLAG=-L../bin -lSlsDetector -lSlsSupport -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ -std=c++11 +LDFLAG=-L../build/bin -lSlsDetector -lSlsSupport -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ -std=c++11 # MAIN=ctbGui.cpp -DESTDIR?=../bin +DESTDIR?=../build/bin OBJS = $(SRC:.cpp=.o) $(MAIN:.cpp=.o) @@ -30,13 +30,13 @@ ctbDict.cpp: $(INCS) $(LINKDEF) %.o : %.cpp echo $@ - g++ -DMYROOT `source root-config --cflags --glibs` -lMinuit -DCTB $(LDFLAG) -o $@ -c $< $(INCDIR) + g++ -DMYROOT `root-config --cflags --glibs` -lMinuit -DCTB $(LDFLAG) -o $@ -c $< $(INCDIR) #$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) $(DESTDIR)/ctbGui: $(OBJS) $(LINKDEF) - g++ -DMYROOT `source root-config --cflags --glibs` -lMinuit -DCTB $(LDFLAG) -o ctbGui $(INCDIR) $(OBJS) ../slsDetectorCalibration/tiffIO.cpp + g++ -DMYROOT `root-config --cflags --glibs` -lMinuit -DCTB $(LDFLAG) -o ctbGui $(INCDIR) $(OBJS) ../slsDetectorCalibration/tiffIO.cpp mv ctbGui $(DESTDIR) clean: diff --git a/ctbGui/ctbAcquisition.cpp b/ctbGui/ctbAcquisition.cpp index 1b385fe3e..8246d6af8 100755 --- a/ctbGui/ctbAcquisition.cpp +++ b/ctbGui/ctbAcquisition.cpp @@ -597,12 +597,12 @@ hframe=new TGHorizontalFrame(this, 800,50); acqThread = new TThread("acqThread", ctbAcquisition::ThreadHandle,(void*)this); // acqThread->Run(); - cout <<"Registering progress callback" << endl; - try { - myDet->registerProgressCallback(&progressCallback,(void*)this); - } catch (...) { - cout << "Do nothing for this error" << endl; - } + // cout <<"Registering progress callback" << endl; + // try { + // myDet->registerProgressCallback(&progressCallback,(void*)this); + // } catch (...) { + // cout << "Do nothing for this error" << endl; + // } cout <<"Registering data callback" << endl; try{ diff --git a/python/sls_detector/experimental.py b/python/sls_detector/experimental.py index 1f9c749e1..82a591219 100755 --- a/python/sls_detector/experimental.py +++ b/python/sls_detector/experimental.py @@ -120,11 +120,11 @@ class ExperimentalDetector(multiDetectorApi): # File @property def fname(self): - return element_if_equal(self.getFileName()) + return element_if_equal(self.getFileNamePrefix()) @fname.setter def fname(self, file_name): - self.setFileName(file_name) + self.setFileNamePrefix(file_name) @property def fpath(self): diff --git a/python/src/DetectorPythonInterface.h b/python/src/DetectorPythonInterface.h index b044e519d..202fb2680 100755 --- a/python/src/DetectorPythonInterface.h +++ b/python/src/DetectorPythonInterface.h @@ -20,22 +20,8 @@ class DetectorPythonInterface { int getMultiDetectorId() { return multi_detector_id; } - // get image size as [nrow, ncols] return as a pair of ints - std::pair getImageSize() { - std::pair image_size{0, 0}; - image_size.first = det.getMaxNumberOfChannelsPerDetector( - slsDetectorDefs::dimension::Y); - image_size.second = det.getMaxNumberOfChannelsPerDetector( - slsDetectorDefs::dimension::X); - return image_size; - } - void setImageSize(const int rows, const int cols) { - det.setMaxNumberOfChannelsPerDetector(slsDetectorDefs::dimension::Y, - rows); - det.setMaxNumberOfChannelsPerDetector(slsDetectorDefs::dimension::X, - cols); - } + // blocking command, acquire set number of frames void acquire() { det.acquire(); } @@ -113,7 +99,7 @@ class DetectorPythonInterface { void setFileFormat(const std::string &format); std::string getFileFormat(); - std::string checkOnline() { return det.checkOnline(); } + // std::string checkOnline() { return det.checkOnline(); } bool isChipPowered() { return det.powerChip(); } void powerChip(const bool value) { det.powerChip(value); } @@ -150,13 +136,9 @@ class DetectorPythonInterface { slsDetectorDefs::dacIndex dacNameToEnum(std::string dac_name); - std::pair getDetectorGeometry() { - std::pair g; - det.getNumberOfDetectors(g.first, g.second); - return g; - } - int getNumberOfDetectors() { return det.getNumberOfDetectors(); } + + int getNumberOfDetectors() { return det.size(); } std::string getRunStatus() { auto s = det.getRunStatus(); @@ -234,7 +216,7 @@ class DetectorPythonInterface { } void setRateCorrection(std::vector tau) { - for (int i = 0; i < det.getNumberOfDetectors(); ++i) + for (size_t i = 0; i < det.size(); ++i) det.setRateCorrection(tau[i], i); } @@ -282,21 +264,21 @@ class DetectorPythonInterface { return det.setPatternWaitTime(level, -1, detPos); } - bool getFlippedDataX(int i) { - return det.getFlippedData(slsDetectorDefs::dimension::X, i); - } + // bool getFlippedDataX(int i) { + // return det.getFlippedData(slsDetectorDefs::dimension::X, i); + // } - bool getFlippedDataY(int i) { - return det.getFlippedData(slsDetectorDefs::dimension::Y, i); - } + // bool getFlippedDataY(int i) { + // return det.getFlippedData(slsDetectorDefs::dimension::Y, i); + // } - void setFlippedDataX(int i, bool value) { - det.setFlippedData(slsDetectorDefs::dimension::X, value, i); - } + // void setFlippedDataX(int i, bool value) { + // det.setFlippedData(slsDetectorDefs::dimension::X, value, i); + // } - void setFlippedDataY(int i, bool value) { - det.setFlippedData(slsDetectorDefs::dimension::Y, value, i); - } + // void setFlippedDataY(int i, bool value) { + // det.setFlippedData(slsDetectorDefs::dimension::Y, value, i); + // } /*** Frame and file settings ***/ void setFileName(std::string fname) { det.setFileName(fname); } @@ -334,7 +316,7 @@ class DetectorPythonInterface { std::vector getMeasuredPeriod() { std::vector mp; - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + for (size_t i = 0; i < det.size(); ++i) { auto t = det.getTimeLeft(slsDetectorDefs::MEASURED_PERIOD, i); mp.push_back(static_cast(t) * 1E-9); } @@ -342,7 +324,7 @@ class DetectorPythonInterface { } std::vector getMeasuredSubPeriod() { std::vector mp; - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + for (size_t i = 0; i < det.size(); ++i) { auto t = det.getTimeLeft(slsDetectorDefs::MEASURED_SUBPERIOD, i); mp.push_back(static_cast(t) * 1E-9); } @@ -505,12 +487,12 @@ class DetectorPythonInterface { } - int getNumberOfGates() { - return det.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER, -1); - } - void setNumberOfGates(const int t) { - det.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER, t); - } + // int getNumberOfGates() { + // return det.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER, -1); + // } + // void setNumberOfGates(const int t) { + // det.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER, t); + // } // time in ns int64_t getDelay() { @@ -538,19 +520,19 @@ class DetectorPythonInterface { det.setTimer(slsDetectorDefs::timerIndex::FRAME_NUMBER, nframes); } - std::string getTimingMode() { - return det.externalCommunicationType( - det.setExternalCommunicationMode()); - } - void setTimingMode(const std::string mode) { - det.setExternalCommunicationMode(det.externalCommunicationType(mode)); - } + // std::string getTimingMode() { + // return det.externalCommunicationType( + // det.setExternalCommunicationMode()); + // } + // void setTimingMode(const std::string mode) { + // det.setExternalCommunicationMode(det.externalCommunicationType(mode)); + // } void freeSharedMemory() { det.freeSharedMemory(); } std::vector getDetectorType() { std::vector detector_type; - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + for (size_t i = 0; i < det.size(); ++i) { detector_type.push_back(det.getDetectorTypeAsString(i)); } return detector_type; @@ -577,8 +559,8 @@ class DetectorPythonInterface { // detectors return a vector of strings std::vector getReceiverStreamingPort() { std::vector vec; - vec.reserve(det.getNumberOfDetectors()); - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + vec.reserve(det.size()); + for (size_t i = 0; i < det.size(); ++i) { vec.push_back(det.getReceiverStreamingPort(i)); } return vec; @@ -590,8 +572,8 @@ class DetectorPythonInterface { std::vector getReceiverUDPPort() { std::vector vec; - vec.reserve(det.getNumberOfDetectors()); - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + vec.reserve(det.size()); + for (size_t i = 0; i < det.size(); ++i) { vec.push_back(det.getReceiverUDPPort(i)); } return vec; @@ -599,8 +581,8 @@ class DetectorPythonInterface { std::vector getReceiverUDPPort2() { std::vector vec; - vec.reserve(det.getNumberOfDetectors()); - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + vec.reserve(det.size()); + for (size_t i = 0; i < det.size(); ++i) { vec.push_back(det.getReceiverUDPPort2(i)); } return vec; @@ -990,7 +972,7 @@ void DetectorPythonInterface::setReadoutFlag(const std::string flag_name) { std::vector DetectorPythonInterface::getRateCorrection() { std::vector rate_corr; - for (int i = 0; i < det.getNumberOfDetectors(); ++i) { + for (size_t i = 0; i < det.size(); ++i) { rate_corr.push_back(det.getRateCorrection(i)); } return rate_corr; diff --git a/python/src/experimental.cpp b/python/src/experimental.cpp index b8d31a9b2..7f7168876 100644 --- a/python/src/experimental.cpp +++ b/python/src/experimental.cpp @@ -18,16 +18,13 @@ void init_experimental(py::module &m) { // Acq related .def("acquire", &Detector::acquire) - .def("startReceiver", &Detector::startReceiver, py::arg() = Positions{}) - .def("stopReceiver", &Detector::stopReceiver, py::arg() = Positions{}) - .def("getAcquiringFlag", &Detector::getAcquiringFlag) - .def("setAcquiringFlag", &Detector::setAcquiringFlag) + .def("clearAcquiringFlag", &Detector::clearAcquiringFlag) .def("getReceiverStatus", &Detector::getReceiverStatus, py::arg() = Positions{}) // Configuration .def("free", &Detector::freeSharedMemory) - .def("setConfig", &Detector::setConfig) + .def("loadConfig", &Detector::loadConfig) .def("getHostname", &Detector::getHostname, py::arg() = Positions{}) // Bits and registers @@ -35,7 +32,7 @@ void init_experimental(py::module &m) { py::arg() = Positions{}) .def("clearBit", &Detector::clearBit, py::arg(), py::arg(), py::arg() = Positions{}) - .def("getRegister", &Detector::getRegister, py::arg(), + .def("readRegister", &Detector::readRegister, py::arg(), py::arg() = Positions{}) .def("getStartingFrameNumber", &Detector::getStartingFrameNumber, @@ -44,10 +41,10 @@ void init_experimental(py::module &m) { py::arg(), py::arg() = Positions{}) // File - .def("getFileName", &Detector::getFileName) - .def("setFileName", &Detector::setFileName, py::arg()) + .def("getFileNamePrefix", &Detector::getFileNamePrefix) + .def("setFileNamePrefix", &Detector::setFileNamePrefix, py::arg(),py::arg() = Positions{}) .def("getFilePath", &Detector::getFilePath) - .def("setFilePath", &Detector::setFilePath, py::arg()) + .def("setFilePath", &Detector::setFilePath, py::arg(),py::arg() = Positions{}) .def("setFileWrite", &Detector::setFileWrite, py::arg(), py::arg() = Positions{}) .def("getFileWrite", &Detector::getFileWrite, py::arg() = Positions{}) diff --git a/python/src/main.cpp b/python/src/main.cpp index 9eab3cdd8..0df93d2e2 100755 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -110,7 +110,7 @@ PYBIND11_MODULE(_sls_detector, m) { .def("readConfigurationFile", &DetectorPythonInterface::readConfigurationFile) .def("readParametersFile", &DetectorPythonInterface::readParametersFile) - .def("checkOnline", &DetectorPythonInterface::checkOnline) + // .def("checkOnline", &DetectorPythonInterface::checkOnline) .def("setReadoutClockSpeed", &DetectorPythonInterface::setReadoutClockSpeed) .def("getReadoutClockSpeed", @@ -173,8 +173,8 @@ PYBIND11_MODULE(_sls_detector, m) { .def("getCycles", &DetectorPythonInterface::getCycles) .def("setCycles", &DetectorPythonInterface::setCycles) - .def("getNumberOfGates", &DetectorPythonInterface::getNumberOfGates) - .def("setNumberOfGates", &DetectorPythonInterface::setNumberOfGates) + // .def("getNumberOfGates", &DetectorPythonInterface::getNumberOfGates) + // .def("setNumberOfGates", &DetectorPythonInterface::setNumberOfGates) .def("getDelay", &DetectorPythonInterface::getDelay) .def("setDelay", &DetectorPythonInterface::setDelay) @@ -183,8 +183,8 @@ PYBIND11_MODULE(_sls_detector, m) { .def("setNumberOfStorageCells", &DetectorPythonInterface::setNumberOfStorageCells) .def("getNumberOfStorageCells", &DetectorPythonInterface::getNumberOfStorageCells) - .def("getTimingMode", &DetectorPythonInterface::getTimingMode) - .def("setTimingMode", &DetectorPythonInterface::setTimingMode) + // .def("getTimingMode", &DetectorPythonInterface::getTimingMode) + // .def("setTimingMode", &DetectorPythonInterface::setTimingMode) .def("getDetectorType", &DetectorPythonInterface::getDetectorType) @@ -282,10 +282,10 @@ PYBIND11_MODULE(_sls_detector, m) { &DetectorPythonInterface::getReceiverCurrentFrameIndex) .def("getGapPixels", &DetectorPythonInterface::getGapPixels) .def("setGapPixels", &DetectorPythonInterface::setGapPixels) - .def("getFlippedDataX", &DetectorPythonInterface::getFlippedDataX) - .def("getFlippedDataY", &DetectorPythonInterface::getFlippedDataY) - .def("setFlippedDataX", &DetectorPythonInterface::setFlippedDataX) - .def("setFlippedDataY", &DetectorPythonInterface::setFlippedDataY) + // .def("getFlippedDataX", &DetectorPythonInterface::getFlippedDataX) + // .def("getFlippedDataY", &DetectorPythonInterface::getFlippedDataY) + // .def("setFlippedDataX", &DetectorPythonInterface::setFlippedDataX) + // .def("setFlippedDataY", &DetectorPythonInterface::setFlippedDataY) .def("getServerLock", &DetectorPythonInterface::getServerLock) .def("setServerLock", &DetectorPythonInterface::setServerLock) @@ -332,14 +332,10 @@ PYBIND11_MODULE(_sls_detector, m) { py::arg("level"), py::arg("duration"), py::arg("det_id") = -1) .def("getPatternWaitTime", &DetectorPythonInterface::getPatternWaitTime, - py::arg("level"), py::arg("det_id") = -1) + py::arg("level"), py::arg("det_id") = -1); + + - .def("getImageSize", &DetectorPythonInterface::getImageSize) - .def("setImageSize", &DetectorPythonInterface::setImageSize) - .def("getNumberOfDetectors", - &DetectorPythonInterface::getNumberOfDetectors) - .def("getDetectorGeometry", - &DetectorPythonInterface::getDetectorGeometry); diff --git a/sample/useResult.cpp b/sample/useResult.cpp index 08de0b04f..cf7cf89c7 100644 --- a/sample/useResult.cpp +++ b/sample/useResult.cpp @@ -40,7 +40,7 @@ auto main() -> int { std::cout << "res.squash(-1): " << res.squash(-1) << '\n'; std::cout << "res3.squash(-1): " << res3.squash(-1) << '\n'; - std::vector ivec{1, 3, 5}; + Result ivec{1, 3, 5}; Result nres(ivec); // for (const auto& i : ivec) diff --git a/slsDetectorCalibration/moenchCommonMode.h b/slsDetectorCalibration/moenchCommonMode.h index b34428113..cddadd1bb 100644 --- a/slsDetectorCalibration/moenchCommonMode.h +++ b/slsDetectorCalibration/moenchCommonMode.h @@ -9,7 +9,8 @@ class moenchCommonMode : public commonModeSubtraction { /** constructor - initalizes a commonModeSubtraction with 4 different regions of interest \param nn number of samples for the moving average */ - moenchCommonMode(int nn=1000) : commonModeSubtraction(0){} ; + + moenchCommonMode(int nn=0) : commonModeSubtraction(0){} ; /* /\** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each; */ diff --git a/slsDetectorGui/forms/form_tab_advanced.ui b/slsDetectorGui/forms/form_tab_advanced.ui index b6545fd4a..858567f9f 100755 --- a/slsDetectorGui/forms/form_tab_advanced.ui +++ b/slsDetectorGui/forms/form_tab_advanced.ui @@ -54,7 +54,7 @@ QTabWidget::North - 2 + 1 Qt::ElideLeft @@ -132,102 +132,20 @@ Region of Interest - - + + - + 0 0 - - - 130 - 0 - - - Add ROI Slot - - - - :/icons/images/add.png:/icons/images/add.png + X Min: - - - - - 0 - 0 - - - - - 130 - 0 - - - - Get ROI - - - - :/icons/images/download.png:/icons/images/download.png - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - - 130 - 0 - - - - Set ROI - - - - :/icons/images/upload.png:/icons/images/upload.png - - - - + @@ -237,12 +155,12 @@ - 130 - 0 + 0 + 35 - Clear ROI + Clear ROI @@ -250,45 +168,159 @@ - + + + + + 160 + 0 + + + + -1 + + + 1279 + + + -1 + + + + Qt::Horizontal - 20 + 40 20 - - - - QFrame::NoFrame + + + + + 0 + 0 + - - true + + X Max: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 160 + 0 + + + + -1 + + + 1279 + + + -1 + + + + + + + + 0 + 0 + + + + Readout: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + + 0 + 35 + + + + Set ROI + + + + :/icons/images/refresh.png:/icons/images/refresh.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 160 + 0 + - - - - 0 - 0 - 735 - 235 - - - - - 1 - - - 15 - - - @@ -399,7 +431,7 @@ - Detector Control Port: + Readout Control Port: @@ -910,7 +942,7 @@ - Detector UDP MAC: + Readout UDP MAC: @@ -929,7 +961,7 @@ - Detector: + Readout: @@ -968,7 +1000,7 @@ - Detector UDP IP: + Readout UDP IP: @@ -981,7 +1013,7 @@ - Detector Stop Port: + Readout Stop Port: @@ -1402,11 +1434,11 @@ Exposure Time of a sub frame. Only for Eiger in 32 bit mode tabAdvancedSettings spinSetAllTrimbits - btnAddRoi + comboReadout + spinXmin + spinXmax btnSetRoi - btnGetRoi btnClearRoi - scrollArea comboDetector spinControlPort spinStopPort diff --git a/slsDetectorGui/forms/form_tab_plot.ui b/slsDetectorGui/forms/form_tab_plot.ui index ca05edbc6..66c98e264 100755 --- a/slsDetectorGui/forms/form_tab_plot.ui +++ b/slsDetectorGui/forms/form_tab_plot.ui @@ -2000,16 +2000,10 @@ Displays minimum, maximum and sum of values for each plot. - <nobr> -Streaming Interval between 2 plots. Default is time interval with 200 ms. -</nobr><br><br><nobr> -<b>Time Interval</b>: Streaming time interval when an image should be streamed. -</nobr><br><nobr> -<b>Every nth Image</b>: Only every nth image is streamed. -</nobr> + <html><head/><body><p>Sets the pace at which the receiver streams out images. Images in between the timeout or frequency are not sent out.<br/><br/><span style=" font-weight:600;">Time Interval</span>: Streaming time interval when an image should be streamed. <br/><span style=" font-weight:600;">Every nth Image</span>: Only every nth image is streamed. </p><p><br/></p><p><br/></p></body></html> - Interval between Plots + Receiver Streaming Frequency / Timer Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 99898a72b..52ab92a23 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -74,7 +74,6 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { void SetupPlots(); void GetStatistics(double &min, double &max, double &sum); void DetachHists(); - static void GetProgressCallBack(double currentProgress, void *this_pointer); static void GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer); static void GetDataCallBack(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex, void *this_pointer); std::string AcquireThread(); diff --git a/slsDetectorGui/include/qTabAdvanced.h b/slsDetectorGui/include/qTabAdvanced.h index 921232914..62986e7b9 100755 --- a/slsDetectorGui/include/qTabAdvanced.h +++ b/slsDetectorGui/include/qTabAdvanced.h @@ -29,7 +29,6 @@ private slots: void SetRxrUDPMAC(); void SetRxrZMQPort(int port); void SetRxrZMQIP(); - void AddROISlot(); void GetROI(); void ClearROI(); void SetROI(); @@ -56,22 +55,12 @@ private: void GetRxrUDPMAC(); void GetRxrZMQPort(); void GetRxrZMQIP(); - void ClearROIWidgets(); void GetAllTrimbits(); void GetNumStoragecells(); void GetSubExposureTime(); void GetSubDeadTime(); multiSlsDetector *myDet; - /** ROI */ - std::vector lblFromX; - std::vector spinFromX; - std::vector lblFromY; - std::vector spinFromY; - std::vector lblToX; - std::vector spinToX; - std::vector lblToY; - std::vector spinToY; }; diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 2784f9e0a..b6b6606b9 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -64,7 +64,6 @@ void qDrawPlot::SetupWidgetWindow() { SetupPlots(); SetDataCallBack(true); myDet->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), this); - myDet->registerProgressCallback(&(GetProgressCallBack), this); // future watcher to watch result of AcquireThread only because it uses signals/slots to handle acquire exception acqResultWatcher = new QFutureWatcher(); @@ -80,8 +79,9 @@ void qDrawPlot::SetupPlots() { setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); // default image size - nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); - nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); + slsDetectorDefs::xy res = myDet->getNumberOfChannels(); + nPixelsX = res.x; + nPixelsY = res.y; switch(detType) { case slsDetectorDefs::MOENCH: npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::ANALOG_SAMPLES, -1) * 2)/25;// for moench 03 @@ -90,8 +90,11 @@ void qDrawPlot::SetupPlots() { break; case slsDetectorDefs::EIGER: if (myDet->getQuad()) { - nPixelsX = (myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X) / 2) - 1; - nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y) * 2; + nPixelsX /= 2; + nPixelsY *= 2; + if (nPixelsX != nPixelsY) { + --nPixelsX; + } } break; default: @@ -586,11 +589,6 @@ std::string qDrawPlot::AcquireThread() { return std::string(""); } -void qDrawPlot::GetProgressCallBack(double currentProgress, void *this_pointer) { - ((qDrawPlot *)this_pointer)->progress = currentProgress; - FILE_LOG(logDEBUG) << "Progress Call back successful"; -} - void qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer) { ((qDrawPlot *)this_pointer)->AcquisitionFinished(currentProgress, detectorStatus); FILE_LOG(logDEBUG) << "Acquisition Finished Call back successful"; @@ -602,6 +600,7 @@ void qDrawPlot::GetDataCallBack(detectorData *data, uint64_t frameIndex, uint32_ } void qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { + progress = currentProgress; std::string status = slsDetectorDefs::runStatusType(static_cast(detectorStatus)); if (detectorStatus == slsDetectorDefs::ERROR) { diff --git a/slsDetectorGui/src/qTabAdvanced.cpp b/slsDetectorGui/src/qTabAdvanced.cpp index 9efa24faf..811fd8217 100755 --- a/slsDetectorGui/src/qTabAdvanced.cpp +++ b/slsDetectorGui/src/qTabAdvanced.cpp @@ -10,18 +10,7 @@ qTabAdvanced::qTabAdvanced(QWidget *parent, multiSlsDetector *detector) FILE_LOG(logDEBUG) << "Advanced ready"; } -qTabAdvanced::~qTabAdvanced() { - for (size_t i = 0; i < lblFromX.size(); ++i) { - delete lblFromX[i]; - delete lblFromY[i]; - delete lblToX[i]; - delete lblToY[i]; - delete spinFromX[i]; - delete spinFromY[i]; - delete spinToX[i]; - delete spinToY[i]; - } -} +qTabAdvanced::~qTabAdvanced() {} void qTabAdvanced::SetupWidgetWindow() { // enabling according to det type @@ -93,9 +82,8 @@ void qTabAdvanced::Initialization() { // roi if (tab_roi->isEnabled()) { - connect(btnAddRoi, SIGNAL(clicked()), this, SLOT(AddROISlot())); + connect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI())); connect(btnSetRoi, SIGNAL(clicked()), this, SLOT(SetROI())); - connect(btnGetRoi, SIGNAL(clicked()), this, SLOT(GetROI())); connect(btnClearRoi, SIGNAL(clicked()), this, SLOT(ClearROI())); } @@ -122,14 +110,20 @@ void qTabAdvanced::PopulateDetectors() { FILE_LOG(logDEBUG) << "Populating detectors"; disconnect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDetector(int))); + disconnect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI())); comboDetector->clear(); - for (int i = 0; i < myDet->getNumberOfDetectors(); ++i) + comboReadout->clear(); + for (unsigned int i = 0; i < myDet->size(); ++i) { comboDetector->addItem(QString(myDet->getHostname(i).c_str())); + comboReadout->addItem(QString(myDet->getHostname(i).c_str())); + } comboDetector->setCurrentIndex(0); + comboReadout->setCurrentIndex(0); connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDetector(int))); + connect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI())); } void qTabAdvanced::GetControlPort() { @@ -332,7 +326,7 @@ void qTabAdvanced::SetDetector(int index) { GetRxrZMQPort(); GetRxrZMQIP(); - myDet->printReceiverConfiguration(logDEBUG); + FILE_LOG(logDEBUG) << myDet->printReceiverConfiguration(); } void qTabAdvanced::SetControlPort(int port) { @@ -462,173 +456,33 @@ void qTabAdvanced::SetRxrZMQIP() { &qTabAdvanced::GetRxrZMQIP) } -void qTabAdvanced::AddROISlot() { - FILE_LOG(logDEBUG) << "Add ROI Slot"; - - QLabel *lFromX = new QLabel("x min:"); - QLabel *lFromY = new QLabel("y min:"); - QLabel *lToX = new QLabel("x max:"); - QLabel *lToY = new QLabel("y max:"); - QSpinBox *sFromX = new QSpinBox(); - QSpinBox *sFromY = new QSpinBox(); - QSpinBox *sToX = new QSpinBox(); - QSpinBox *sToY = new QSpinBox(); - lFromX->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - lFromY->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - lToX->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - lToY->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sFromX->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sFromY->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sToX->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sToY->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - lFromX->setFixedWidth(50); - lFromY->setFixedWidth(50); - lToX->setFixedWidth(50); - lToY->setFixedWidth(50); - sFromX->setFixedWidth(80); - sFromY->setFixedWidth(80); - sToX->setFixedWidth(80); - sToY->setFixedWidth(80); - sFromX->setFixedHeight(19); - sFromY->setFixedHeight(19); - sToX->setFixedHeight(19); - sToY->setFixedHeight(19); - sFromX->setMaximum(myDet->getTotalNumberOfChannels(slsDetectorDefs::X) - 1); - sToX->setMaximum(myDet->getTotalNumberOfChannels(slsDetectorDefs::X) - 1); - sFromY->setMaximum(myDet->getTotalNumberOfChannels(slsDetectorDefs::Y) - 1); - sToY->setMaximum(myDet->getTotalNumberOfChannels(slsDetectorDefs::Y) - 1); - sFromX->setMinimum(-1); - sToX->setMinimum(-1); - sFromY->setMinimum(-1); - sToY->setMinimum(-1); - sFromX->setValue(-1); - sFromY->setValue(-1); - sToX->setValue(-1); - sToY->setValue(-1); - - lblFromX.push_back(lFromX); - lblFromY.push_back(lFromY); - lblToX.push_back(lToX); - lblToY.push_back(lToY); - spinFromX.push_back(sFromX); - spinFromY.push_back(sFromY); - spinToX.push_back(sToX); - spinToY.push_back(sToY); - - int nroi = (int)lblFromX.size(); - gridRoi->addWidget(lblFromX[nroi], nroi, 0, Qt::AlignTop); - gridRoi->addWidget(spinFromX[nroi], nroi, 1, Qt::AlignTop); - // FIXME: gridRoi->addItem(new - // QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Fixed), - // nroi,2,Qt::AlignTop); - gridRoi->addWidget(lblToX[nroi], nroi, 3, Qt::AlignTop); - gridRoi->addWidget(spinToX[nroi], nroi, 4, Qt::AlignTop); - // FIXME: gridRoi->addItem(new - // QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Fixed), - // nroi,5,Qt::AlignTop); - gridRoi->addWidget(lblFromY[nroi], nroi, 6, Qt::AlignTop); - gridRoi->addWidget(spinFromY[nroi], nroi, 7, Qt::AlignTop); - // FIXME: gridRoi->addItem(new - // QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Fixed), - // nroi,8,Qt::AlignTop); - gridRoi->addWidget(lblToY[nroi], nroi, 9, Qt::AlignTop); - gridRoi->addWidget(spinToY[nroi], nroi, 10, Qt::AlignTop); - - lblFromX[nroi]->show(); - spinFromX[nroi]->show(); - lblToX[nroi]->show(); - spinToX[nroi]->show(); - lblFromY[nroi]->show(); - spinFromY[nroi]->show(); - lblToY[nroi]->show(); - spinToY[nroi]->show(); - - FILE_LOG(logDEBUG) << "ROI Inputs added"; -} - void qTabAdvanced::GetROI() { FILE_LOG(logDEBUG) << "Getting ROI"; - ClearROIWidgets(); - try { - int nroi = 0; - const slsDetectorDefs::ROI *roi = myDet->getROI(nroi); - if (roi != nullptr) { - for (int i = 0; i < nroi; ++i) { - AddROISlot(); - spinFromX[i]->setValue(roi[i].xmin); - spinFromY[i]->setValue(roi[i].ymin); - spinToX[i]->setValue(roi[i].xmax); - spinToY[i]->setValue(roi[i].ymax); - } - FILE_LOG(logDEBUG) << "ROIs populated: " << nroi; - } - + slsDetectorDefs::ROI roi = myDet->getROI(comboReadout->currentIndex()); + spinXmin->setValue(roi.xmin); + spinXmax->setValue(roi.xmax); } CATCH_DISPLAY ("Could not get ROI.", "qTabAdvanced::GetROI") } -void qTabAdvanced::ClearROIWidgets() { - FILE_LOG(logDEBUG) << "Clear ROI Widgets"; - - // hide widgets - QLayoutItem *item; - while ((item = gridRoi->takeAt(0))) { - if (item->widget()) { - item->widget()->hide(); - gridRoi->removeWidget(item->widget()); - } - } - - // delete widgets - for (size_t i = 0; i < lblFromX.size(); ++i) { - delete lblFromX[i]; - delete spinFromX[i]; - delete lblToX[i]; - delete spinToY[i]; - delete lblFromY[i]; - delete spinFromY[i]; - delete lblToY[i]; - delete spinToY[i]; - } - lblFromX.clear(); - spinFromX.clear(); - lblToX.clear(); - spinToY.clear(); - lblFromY.clear(); - spinFromY.clear(); - lblToY.clear(); - spinToY.clear(); -} - void qTabAdvanced::ClearROI() { FILE_LOG(logINFO) << "Clearing ROI"; - if (QMessageBox::warning( - this, "Clear ROI", - "Are you sure you want to clear all the ROI in detector?", - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No) == QMessageBox::Yes) { - - ClearROIWidgets(); - SetROI(); - FILE_LOG(logDEBUG) << "ROIs cleared"; - } + spinXmin->setValue(-1); + spinXmax->setValue(-1); + SetROI(); + FILE_LOG(logDEBUG) << "ROIs cleared"; } void qTabAdvanced::SetROI() { - // get roi from widgets - int nroi = (int)lblFromX.size(); - slsDetectorDefs::ROI roi[nroi]; - for (int i = 0; i < nroi; ++i) { - roi[i].xmin = spinFromX[i]->value(); - roi[i].ymin = spinFromY[i]->value(); - roi[i].xmax = spinToX[i]->value(); - roi[i].ymax = spinToY[i]->value(); - } + + slsDetectorDefs::ROI roi; + roi.xmin = spinXmin->value(); + roi.xmax = spinXmax->value(); // set roi - FILE_LOG(logINFO) << "Setting ROI:" << nroi; + FILE_LOG(logINFO) << "Setting ROI: [" << roi.xmin << ", " << roi.xmax << "]"; try { - myDet->setROI(nroi, roi, -1); + myDet->setROI(roi, comboReadout->currentIndex()); } CATCH_DISPLAY ("Could not set these ROIs.", "qTabAdvanced::SetROI") diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index 58942a86f..afe65f3c3 100755 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -80,8 +80,8 @@ void qTabDataOutput::PopulateDetectors() { comboDetector->clear(); comboDetector->addItem("All"); - if (myDet->getNumberOfDetectors() > 1) { - for (int i = 0; i < myDet->getNumberOfDetectors(); ++i) + if (myDet->size() > 1) { + for (unsigned int i = 0; i < myDet->size(); ++i) comboDetector->addItem(QString(myDet->getHostname(i).c_str())); } } diff --git a/slsDetectorGui/src/qTabDebugging.cpp b/slsDetectorGui/src/qTabDebugging.cpp index 936efcba5..b9666f465 100755 --- a/slsDetectorGui/src/qTabDebugging.cpp +++ b/slsDetectorGui/src/qTabDebugging.cpp @@ -55,7 +55,7 @@ void qTabDebugging::PopulateDetectors() { FILE_LOG(logDEBUG) << "Populating detectors"; comboDetector->clear(); - for (int i = 0; i < myDet->getNumberOfDetectors(); ++i) { + for (unsigned int i = 0; i < myDet->size(); ++i) { comboDetector->addItem(QString(myDet->getHostname(i).c_str())); } } diff --git a/slsDetectorGui/src/qTabDeveloper.cpp b/slsDetectorGui/src/qTabDeveloper.cpp index e62f5ac4c..122c4daf0 100755 --- a/slsDetectorGui/src/qTabDeveloper.cpp +++ b/slsDetectorGui/src/qTabDeveloper.cpp @@ -124,8 +124,8 @@ void qTabDeveloper::PopulateDetectors() { comboDetector->clear(); comboDetector->addItem("All"); - if (myDet->getNumberOfDetectors() > 1) { - for (int i = 0; i < myDet->getNumberOfDetectors(); ++i) + if (myDet->size() > 1) { + for (unsigned int i = 0; i < myDet->size(); ++i) comboDetector->addItem(QString(myDet->getHostname(i).c_str())); } comboDetector->setCurrentIndex(0); diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index 7efad7761..679fc1d2d 100755 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -201,9 +201,9 @@ void qTabMeasurement::GetTimingMode() { try { auto oldMode = comboTimingMode->currentIndex(); - auto retval = myDet->setExternalCommunicationMode(); + auto retval = myDet->setTimingMode(); switch(retval) { - case slsDetectorDefs::GET_EXTERNAL_COMMUNICATION_MODE: + case slsDetectorDefs::GET_TIMING_MODE: qDefs::Message(qDefs::WARNING, "Timing Mode is inconsistent for all detectors.", "qTabMeasurement::GetTimingMode"); break; case slsDetectorDefs::AUTO_TIMING: @@ -229,7 +229,7 @@ void qTabMeasurement::SetTimingMode(int val) { FILE_LOG(logINFO) << "Setting timing mode:" << comboTimingMode->currentText().toAscii().data(); try { - myDet->setExternalCommunicationMode(static_cast(val)); + myDet->setTimingMode(static_cast(val)); EnableWidgetsforTimingMode(); } CATCH_HANDLE("Could not set timing mode.", "qTabMeasurement::SetTimingMode", this, &qTabMeasurement::GetTimingMode) } diff --git a/slsDetectorServers/CMakeLists.txt b/slsDetectorServers/CMakeLists.txt index a495e3cf4..7a05de417 100644 --- a/slsDetectorServers/CMakeLists.txt +++ b/slsDetectorServers/CMakeLists.txt @@ -1,2 +1,5 @@ +add_subdirectory(ctbDetectorServer) add_subdirectory(eigerDetectorServer) +add_subdirectory(gotthardDetectorServer) add_subdirectory(jungfrauDetectorServer) +#add_subdirectory(moenchDetectorServer) \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/AD7689.h b/slsDetectorServers/ctbDetectorServer/AD7689.h deleted file mode 120000 index fe4d6e3ce..000000000 --- a/slsDetectorServers/ctbDetectorServer/AD7689.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/AD7689.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/AD9257.h b/slsDetectorServers/ctbDetectorServer/AD9257.h deleted file mode 120000 index 87b70e097..000000000 --- a/slsDetectorServers/ctbDetectorServer/AD9257.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/AD9257.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/ALTERA_PLL.h b/slsDetectorServers/ctbDetectorServer/ALTERA_PLL.h deleted file mode 120000 index e665f009d..000000000 --- a/slsDetectorServers/ctbDetectorServer/ALTERA_PLL.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/ALTERA_PLL.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/CMakeLists.txt b/slsDetectorServers/ctbDetectorServer/CMakeLists.txt new file mode 100644 index 000000000..eb5133635 --- /dev/null +++ b/slsDetectorServers/ctbDetectorServer/CMakeLists.txt @@ -0,0 +1,31 @@ +add_executable(ctbDetectorServer + slsDetectorFunctionList.c + ../slsDetectorServer/slsDetectorServer.c + ../slsDetectorServer/slsDetectorServer_funcs.c + ../slsDetectorServer/communication_funcs.c +) + +include_directories( + ../slsDetectorServer/ + ../../slsSupportLib/include +) + +target_include_directories(ctbDetectorServer + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_definitions(ctbDetectorServer + PUBLIC CHIPTESTBOARDD VIRTUAL STOP_SERVER +) + +target_link_libraries(ctbDetectorServer + PUBLIC pthread rt +) + +set_target_properties(ctbDetectorServer PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) + +install(TARGETS ctbDetectorServer + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/slsDetectorServers/ctbDetectorServer/I2C.h b/slsDetectorServers/ctbDetectorServer/I2C.h deleted file mode 120000 index 88ae4a2f3..000000000 --- a/slsDetectorServers/ctbDetectorServer/I2C.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/I2C.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/INA226.h b/slsDetectorServers/ctbDetectorServer/INA226.h deleted file mode 120000 index 685ac1f8f..000000000 --- a/slsDetectorServers/ctbDetectorServer/INA226.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/INA226.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/LTC2620.h b/slsDetectorServers/ctbDetectorServer/LTC2620.h deleted file mode 120000 index 13157cb8b..000000000 --- a/slsDetectorServers/ctbDetectorServer/LTC2620.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/LTC2620.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/MAX1932.h b/slsDetectorServers/ctbDetectorServer/MAX1932.h deleted file mode 120000 index 8f7b239ea..000000000 --- a/slsDetectorServers/ctbDetectorServer/MAX1932.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/MAX1932.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/Makefile b/slsDetectorServers/ctbDetectorServer/Makefile index af9b6f823..10e446362 100755 --- a/slsDetectorServers/ctbDetectorServer/Makefile +++ b/slsDetectorServers/ctbDetectorServer/Makefile @@ -1,14 +1,17 @@ +current_dir = $(shell pwd) +main_server = ../slsDetectorServer/ +support_lib = ../../slsSupportLib/include/ + CROSS = bfin-uclinux- CC = $(CROSS)gcc -CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER #-DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE -LDLIBS += -lm -lstdc++ - +CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE +LDLIBS += -lm PROGS = ctbDetectorServer DESTDIR ?= bin INSTMODE = 0777 -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.c=.o) +SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c +OBJS = $(SRCS:.c=.o) all: clean versioning $(PROGS) #all: clean $(PROGS) @@ -29,7 +32,7 @@ $(PROGS): $(OBJS) rm *.gdb clean: - rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb + rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o diff --git a/slsDetectorServers/ctbDetectorServer/Makefile.virtual b/slsDetectorServers/ctbDetectorServer/Makefile.virtual deleted file mode 100755 index cfaacf70e..000000000 --- a/slsDetectorServers/ctbDetectorServer/Makefile.virtual +++ /dev/null @@ -1,27 +0,0 @@ -CC = gcc -CFLAGS += -Wall -DCHIPTESTBOARDD -DVIRTUAL -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -LDLIBS += -lm -lstdc++ -pthread - -PROGS = ctbDetectorServer_virtual -DESTDIR ?= bin -INSTMODE = 0777 - -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.c=.o) - -all: clean versioning $(PROGS) - -boot: $(OBJS) - -versioning: - @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` - -$(PROGS): $(OBJS) -# echo $(OBJS) - mkdir -p $(DESTDIR) - $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) - mv $(PROGS) $(DESTDIR) - -clean: - rm -rf $(DESTDIR)/$(PROGS) *.o - diff --git a/slsDetectorServers/ctbDetectorServer/UDPPacketHeaderGenerator.h b/slsDetectorServers/ctbDetectorServer/UDPPacketHeaderGenerator.h deleted file mode 120000 index eb0223a3e..000000000 --- a/slsDetectorServers/ctbDetectorServer/UDPPacketHeaderGenerator.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/UDPPacketHeaderGenerator.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/ansi.h b/slsDetectorServers/ctbDetectorServer/ansi.h deleted file mode 120000 index 4a82d0575..000000000 --- a/slsDetectorServers/ctbDetectorServer/ansi.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/ansi.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index eb9b82534..d555e70ef 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/ctbDetectorServer/blackfin.h b/slsDetectorServers/ctbDetectorServer/blackfin.h deleted file mode 120000 index 2873c7dc6..000000000 --- a/slsDetectorServers/ctbDetectorServer/blackfin.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/blackfin.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/common.h b/slsDetectorServers/ctbDetectorServer/common.h deleted file mode 120000 index 6776eb607..000000000 --- a/slsDetectorServers/ctbDetectorServer/common.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/common.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/commonServerFunctions.h b/slsDetectorServers/ctbDetectorServer/commonServerFunctions.h deleted file mode 120000 index 33bdd8d53..000000000 --- a/slsDetectorServers/ctbDetectorServer/commonServerFunctions.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/commonServerFunctions.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/communication_funcs.c b/slsDetectorServers/ctbDetectorServer/communication_funcs.c deleted file mode 120000 index 30435fdc4..000000000 --- a/slsDetectorServers/ctbDetectorServer/communication_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/communication_funcs.h b/slsDetectorServers/ctbDetectorServer/communication_funcs.h deleted file mode 120000 index c0c144994..000000000 --- a/slsDetectorServers/ctbDetectorServer/communication_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/communication_funcs_UDP.h b/slsDetectorServers/ctbDetectorServer/communication_funcs_UDP.h deleted file mode 120000 index 0d434a97d..000000000 --- a/slsDetectorServers/ctbDetectorServer/communication_funcs_UDP.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs_UDP.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/logger.h b/slsDetectorServers/ctbDetectorServer/logger.h deleted file mode 120000 index ff1930ce3..000000000 --- a/slsDetectorServers/ctbDetectorServer/logger.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/logger.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/programfpga.h b/slsDetectorServers/ctbDetectorServer/programfpga.h deleted file mode 120000 index 72c54d21d..000000000 --- a/slsDetectorServers/ctbDetectorServer/programfpga.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/programfpga.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index ce3ec8061..d03f5d053 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1,6 +1,6 @@ #include "slsDetectorFunctionList.h" #include "versionAPI.h" -#include "logger.h" +#include "clogger.h" #include "communication_funcs_UDP.h" #include "UDPPacketHeaderGenerator.h" @@ -1444,9 +1444,9 @@ int setHighVoltage(int val){ /* parameters - timing, extsig */ -void setTiming( enum externalCommunicationMode arg){ +void setTiming( enum timingMode arg){ - if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ + if(arg != GET_TIMING_MODE){ switch((int)arg){ case AUTO_TIMING: FILE_LOG(logINFO, ("Set Timing: Auto\n")); @@ -1464,7 +1464,7 @@ void setTiming( enum externalCommunicationMode arg){ } -enum externalCommunicationMode getTiming() { +enum timingMode getTiming() { if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) return TRIGGER_EXPOSURE; return AUTO_TIMING; diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h deleted file mode 120000 index 345b8c029..000000000 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorFunctionList.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer.c b/slsDetectorServers/ctbDetectorServer/slsDetectorServer.c deleted file mode 120000 index a7eb59acb..000000000 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer.c \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_funcs.c deleted file mode 120000 index a7532ccd4..000000000 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_funcs.h deleted file mode 120000 index 7569daf47..000000000 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/sls_detector_defs.h b/slsDetectorServers/ctbDetectorServer/sls_detector_defs.h deleted file mode 120000 index 2af30d73a..000000000 --- a/slsDetectorServers/ctbDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/sls_detector_funcs.h b/slsDetectorServers/ctbDetectorServer/sls_detector_funcs.h deleted file mode 120000 index 3f48959a9..000000000 --- a/slsDetectorServers/ctbDetectorServer/sls_detector_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/versionAPI.h b/slsDetectorServers/ctbDetectorServer/versionAPI.h deleted file mode 120000 index 5e580d8bb..000000000 --- a/slsDetectorServers/ctbDetectorServer/versionAPI.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/versionAPI.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index 7461e2df0..d1e941db6 100755 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -1,4 +1,4 @@ -#include "logger.h" +#include "clogger.h" #include "Beb.h" #include "FebRegisterDefs.h" #include "xparameters.h" @@ -1010,8 +1010,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets FILE_LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n")); - FILE_LOG(logDEBUG1, ("beb_number:%X, ten_gig:%X,dst_number:%X, npackets:%X, " - "Beb_bit_mode:%X, header_size:%X, nimages:%d, test_just_send_out_packets_no_wait:%X\n", + FILE_LOG(logINFO, ("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, " + "Beb_bit_mode:%d, header_size:%d, nimages:%d, test_just_send_out_packets_no_wait:%d\n", beb_number, ten_gig, dst_number, npackets, Beb_bit_mode, header_size, nimages, test_just_send_out_packets_no_wait)); diff --git a/slsDetectorServers/eigerDetectorServer/CMakeLists.txt b/slsDetectorServers/eigerDetectorServer/CMakeLists.txt index 4208fe5c6..2e68c33b2 100644 --- a/slsDetectorServers/eigerDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/eigerDetectorServer/CMakeLists.txt @@ -1,8 +1,13 @@ set(src slsDetectorFunctionList.c - slsDetectorServer.c - slsDetectorServer_funcs.c - communication_funcs.c + ../slsDetectorServer/slsDetectorServer.c + ../slsDetectorServer/slsDetectorServer_funcs.c + ../slsDetectorServer/communication_funcs.c +) + +include_directories( + ../slsDetectorServer + ../../slsSupportLib/include ) add_executable(eigerDetectorServerMaster diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.c b/slsDetectorServers/eigerDetectorServer/FebControl.c index e3594772b..c05d17aa7 100755 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -1,7 +1,7 @@ #include "FebControl.h" #include "FebRegisterDefs.h" #include "slsDetectorServer_defs.h" -#include "logger.h" +#include "clogger.h" #include "Beb.h" #include diff --git a/slsDetectorServers/eigerDetectorServer/FebInterface.c b/slsDetectorServers/eigerDetectorServer/FebInterface.c index 9c7d33051..d4fa1815c 100755 --- a/slsDetectorServers/eigerDetectorServer/FebInterface.c +++ b/slsDetectorServers/eigerDetectorServer/FebInterface.c @@ -1,7 +1,7 @@ #include "FebInterface.h" #include "LocalLinkInterface.h" #include "xparameters.h" -#include "logger.h" +#include "clogger.h" #include diff --git a/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c b/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c index 3e47cd61a..0e3cc52bc 100755 --- a/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c +++ b/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c @@ -1,6 +1,6 @@ #include "LocalLinkInterface.h" #include "HardwareMMappingDefs.h" -#include "logger.h" +#include "clogger.h" #include #include diff --git a/slsDetectorServers/eigerDetectorServer/Makefile b/slsDetectorServers/eigerDetectorServer/Makefile index 88ec734f7..f81cbd82e 100755 --- a/slsDetectorServers/eigerDetectorServer/Makefile +++ b/slsDetectorServers/eigerDetectorServer/Makefile @@ -1,16 +1,18 @@ -CC = powerpc-4xx-softfloat-gcc -BLACKFIN_CC = bfin-uclinux-gcc -CFLAGS += -Wall -DEIGERD -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -DPCCOMPILE -DMARTIN -LDLIBS += -lm -lstdc++ +current_dir = $(shell pwd) +main_server = ../slsDetectorServer/ +support_lib = ../../slsSupportLib/include/ +CROSS = powerpc-4xx-softfloat- +BLACKFIN_CC = bfin-uclinux-gcc +CC = $(CROSS)gcc +CFLAGS += -Wall -DEIGERD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE +LDLIBS += -lm PROGS = eigerDetectorServer DESTDIR ?= bin INSTMODE = 0777 - -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c -OBJS = $(SRC_CLNT:.c=.o) - +SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c +OBJS = $(SRCS:.c=.o) all: clean versioning $(PROGS) #hv9m_blackfin_server @@ -26,16 +28,16 @@ versioning: $(PROGS): $(OBJS) # echo $(OBJS) mkdir -p $(DESTDIR) - $(CC) -o $@ $(SRC_CLNT) $(CFLAGS) $(LDLIBS) + $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) mv $(PROGS) $(DESTDIR) hv9m_blackfin_server:9mhvserial_bf.c $(BLACKFIN_CC) -o hv9m_blackfin_server 9mhvserial_bf.c -Wall #-DVERBOSE mv hv9m_blackfin_server $(DESTDIR) - rm hv9m_blackfin_server.gdb + rm hv9m_blackfin_server.gdb $(main_server)*.o clean: - rm -rf $(DESTDIR)/$(PROGS) *.o $(DESTDIR)/hv9m_blackfin_server + rm -rf $(DESTDIR)/$(PROGS) *.o $(DESTDIR)/hv9m_blackfin_server $(main_server)*.o diff --git a/slsDetectorServers/eigerDetectorServer/ansi.h b/slsDetectorServers/eigerDetectorServer/ansi.h deleted file mode 120000 index 4a82d0575..000000000 --- a/slsDetectorServers/eigerDetectorServer/ansi.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/ansi.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index eaf92f6b2..444b16287 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/common.h b/slsDetectorServers/eigerDetectorServer/common.h deleted file mode 120000 index 6776eb607..000000000 --- a/slsDetectorServers/eigerDetectorServer/common.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/common.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/communication_funcs.c b/slsDetectorServers/eigerDetectorServer/communication_funcs.c deleted file mode 120000 index 30435fdc4..000000000 --- a/slsDetectorServers/eigerDetectorServer/communication_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/communication_funcs.h b/slsDetectorServers/eigerDetectorServer/communication_funcs.h deleted file mode 120000 index c0c144994..000000000 --- a/slsDetectorServers/eigerDetectorServer/communication_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/communication_funcs_UDP.h b/slsDetectorServers/eigerDetectorServer/communication_funcs_UDP.h deleted file mode 120000 index 0d434a97d..000000000 --- a/slsDetectorServers/eigerDetectorServer/communication_funcs_UDP.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs_UDP.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/logger.h b/slsDetectorServers/eigerDetectorServer/logger.h deleted file mode 120000 index ff1930ce3..000000000 --- a/slsDetectorServers/eigerDetectorServer/logger.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/logger.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index d147c6706..eedc0b4d6 100755 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -1,6 +1,6 @@ #include "slsDetectorFunctionList.h" #include "versionAPI.h" -#include "logger.h" +#include "clogger.h" #include "common.h" #ifndef VIRTUAL @@ -1193,9 +1193,9 @@ int setHighVoltage(int val) { /* parameters - timing, extsig */ -void setTiming( enum externalCommunicationMode arg) { - enum externalCommunicationMode ret=GET_EXTERNAL_COMMUNICATION_MODE; - if (arg != GET_EXTERNAL_COMMUNICATION_MODE) { +void setTiming( enum timingMode arg) { + enum timingMode ret=GET_TIMING_MODE; + if (arg != GET_TIMING_MODE) { switch((int)arg) { case AUTO_TIMING: ret = 0; break; case TRIGGER_EXPOSURE: ret = 2; break; @@ -1211,8 +1211,8 @@ void setTiming( enum externalCommunicationMode arg) { } -enum externalCommunicationMode getTiming() { - enum externalCommunicationMode ret = GET_EXTERNAL_COMMUNICATION_MODE; +enum timingMode getTiming() { + enum timingMode ret = GET_TIMING_MODE; ret = eiger_triggermode; switch((int)ret) { case 0: ret = AUTO_TIMING; break; diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h deleted file mode 120000 index 345b8c029..000000000 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorFunctionList.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer.c b/slsDetectorServers/eigerDetectorServer/slsDetectorServer.c deleted file mode 120000 index a7eb59acb..000000000 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer.c \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_funcs.c deleted file mode 120000 index a7532ccd4..000000000 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_funcs.h deleted file mode 120000 index 7569daf47..000000000 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/sls_detector_defs.h b/slsDetectorServers/eigerDetectorServer/sls_detector_defs.h deleted file mode 120000 index 2af30d73a..000000000 --- a/slsDetectorServers/eigerDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/sls_detector_funcs.h b/slsDetectorServers/eigerDetectorServer/sls_detector_funcs.h deleted file mode 120000 index 3f48959a9..000000000 --- a/slsDetectorServers/eigerDetectorServer/sls_detector_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/versionAPI.h b/slsDetectorServers/eigerDetectorServer/versionAPI.h deleted file mode 120000 index 5e580d8bb..000000000 --- a/slsDetectorServers/eigerDetectorServer/versionAPI.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/versionAPI.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/AD9252.h b/slsDetectorServers/gotthardDetectorServer/AD9252.h deleted file mode 120000 index 2ab1ed191..000000000 --- a/slsDetectorServers/gotthardDetectorServer/AD9252.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/AD9252.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/AD9257.h b/slsDetectorServers/gotthardDetectorServer/AD9257.h deleted file mode 120000 index 87b70e097..000000000 --- a/slsDetectorServers/gotthardDetectorServer/AD9257.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/AD9257.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt b/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt new file mode 100644 index 000000000..fa72c7d09 --- /dev/null +++ b/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt @@ -0,0 +1,31 @@ +add_executable(gotthardDetectorServer + slsDetectorFunctionList.c + ../slsDetectorServer/slsDetectorServer.c + ../slsDetectorServer/slsDetectorServer_funcs.c + ../slsDetectorServer/communication_funcs.c +) + +include_directories( + ../slsDetectorServer/ + ../../slsSupportLib/include +) + +target_include_directories(gotthardDetectorServer + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_definitions(gotthardDetectorServer + PUBLIC GOTTHARDD VIRTUAL STOP_SERVER +) + +target_link_libraries(gotthardDetectorServer + PUBLIC pthread rt +) + +set_target_properties(gotthardDetectorServer PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) + +install(TARGETS gotthardDetectorServer + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/slsDetectorServers/gotthardDetectorServer/LTC2620.h b/slsDetectorServers/gotthardDetectorServer/LTC2620.h deleted file mode 120000 index 13157cb8b..000000000 --- a/slsDetectorServers/gotthardDetectorServer/LTC2620.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/LTC2620.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/Makefile b/slsDetectorServers/gotthardDetectorServer/Makefile index 9d606f0c6..81f23deb3 100755 --- a/slsDetectorServers/gotthardDetectorServer/Makefile +++ b/slsDetectorServers/gotthardDetectorServer/Makefile @@ -1,14 +1,17 @@ -CROSS = bfin-uclinux- -CC = $(CROSS)gcc -CFLAGS += -Wall -DGOTTHARDD -DSTOP_SERVER # -DVERBOSE -LDLIBS += -lm -lstdc++ +current_dir = $(shell pwd) +main_server = ../slsDetectorServer/ +support_lib = ../../slsSupportLib/include/ +CROSS = bfin-uclinux- +CC = $(CROSS)gcc +CFLAGS += -Wall -DGOTTHARDD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE +LDLIBS += -lm PROGS = gotthardDetectorServer DESTDIR ?= bin INSTMODE = 0777 -SRCS = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRCS:%.c=%.o) +SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c +OBJS = $(SRCS:.c=.o) all: clean versioning $(PROGS) @@ -29,7 +32,7 @@ $(PROGS): $(OBJS) rm *.gdb clean: - rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb + rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o diff --git a/slsDetectorServers/gotthardDetectorServer/Makefile.virtual b/slsDetectorServers/gotthardDetectorServer/Makefile.virtual deleted file mode 100755 index 65174a82f..000000000 --- a/slsDetectorServers/gotthardDetectorServer/Makefile.virtual +++ /dev/null @@ -1,27 +0,0 @@ -CC = gcc -CFLAGS += -Wall -DGOTTHARDD -DVIRTUAL -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -LDLIBS += -lm -lstdc++ -pthread - -PROGS = gotthardDetectorServer_virtual -DESTDIR ?= bin -INSTMODE = 0777 - -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.c=.o) - -all: clean versioning $(PROGS) - -boot: $(OBJS) - -versioning: - @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` - -$(PROGS): $(OBJS) -# echo $(OBJS) - mkdir -p $(DESTDIR) - $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) - mv $(PROGS) $(DESTDIR) - -clean: - rm -rf $(DESTDIR)/$(PROGS) *.o - \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/ansi.h b/slsDetectorServers/gotthardDetectorServer/ansi.h deleted file mode 120000 index 4a82d0575..000000000 --- a/slsDetectorServers/gotthardDetectorServer/ansi.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/ansi.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index d138a3ae1..8523301b6 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/blackfin.h b/slsDetectorServers/gotthardDetectorServer/blackfin.h deleted file mode 120000 index 2873c7dc6..000000000 --- a/slsDetectorServers/gotthardDetectorServer/blackfin.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/blackfin.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/common.h b/slsDetectorServers/gotthardDetectorServer/common.h deleted file mode 120000 index 6776eb607..000000000 --- a/slsDetectorServers/gotthardDetectorServer/common.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/common.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/commonServerFunctions.h b/slsDetectorServers/gotthardDetectorServer/commonServerFunctions.h deleted file mode 120000 index 33bdd8d53..000000000 --- a/slsDetectorServers/gotthardDetectorServer/commonServerFunctions.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/commonServerFunctions.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/communication_funcs.c b/slsDetectorServers/gotthardDetectorServer/communication_funcs.c deleted file mode 120000 index 30435fdc4..000000000 --- a/slsDetectorServers/gotthardDetectorServer/communication_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/communication_funcs.h b/slsDetectorServers/gotthardDetectorServer/communication_funcs.h deleted file mode 120000 index c0c144994..000000000 --- a/slsDetectorServers/gotthardDetectorServer/communication_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/logger.h b/slsDetectorServers/gotthardDetectorServer/logger.h deleted file mode 120000 index ff1930ce3..000000000 --- a/slsDetectorServers/gotthardDetectorServer/logger.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/logger.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 6f7ce88b4..f8f06ca0e 100755 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -1,13 +1,12 @@ #include "slsDetectorFunctionList.h" #include "versionAPI.h" -#include "logger.h" +#include "clogger.h" #include "RegisterDefs.h" -#ifndef VIRTUAL #include "AD9257.h" // commonServerFunctions.h, blackfin.h, ansi.h #include "AD9252.h" // old board compatibility #include "LTC2620.h" // dacs -#else +#ifdef VIRTUAL #include "blackfin.h" #include #include @@ -33,12 +32,10 @@ int detectorFirstServer = 1; int dacValues[NDAC] = {0}; enum detectorSettings thisSettings = UNINITIALIZED; enum externalSignalFlag signalMode = 0; -int digitalTestBit = 0; // roi configuration int adcConfigured = -1; -ROI rois[MAX_ROIS]; -int nROI = 0; +ROI rois; int ipPacketSize = 0; int udpPacketSize = 0; @@ -247,12 +244,7 @@ int detectorTest( enum digitalTestMode arg, int ival) { return OK; #endif switch(arg){ - case DIGITAL_BIT_TEST: - if (ival > -1) { - digitalTestBit = (ival == 0) ? 0 : 1; - FILE_LOG(logINFO, ("Digital Test bit set: %d\n", digitalTestBit)); - } - return digitalTestBit; + case IMAGE_TEST: return testImage(ival); case DETECTOR_FIRMWARE_TEST: return testFpga(); case DETECTOR_BUS_TEST: return testBus(); default: @@ -262,6 +254,19 @@ int detectorTest( enum digitalTestMode arg, int ival) { return OK; } +int testImage(int ival) { + uint32_t addr = MULTI_PURPOSE_REG; + if (ival >= 0) { + if (ival == 0) { + FILE_LOG(logINFO, ("Switching on Image Test\n")); + bus_w (addr, bus_r(addr) & ~DGTL_TST_MSK); + } else { + FILE_LOG(logINFO, ("Switching off Image Test\n")); + bus_w (addr, bus_r(addr) | DGTL_TST_MSK); + } + } + return ((bus_r(addr) & DGTL_TST_MSK) >> DGTL_TST_OFST); +} /* Ids */ @@ -397,7 +402,9 @@ void setupDetector() { bus_w(TEMP_SPI_OUT_REG, 0x0); // roi, gbit readout - setROIADC(-1); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos, + rois.xmin = -1; + rois.xmax = -1; + setROI(rois);// set adcsyncreg, daqreg, chipofinterestreg, cleanfifos, setGbitReadout(); // master, slave (25um) @@ -726,95 +733,49 @@ int setDynamicRange(int dr){ return DYNAMIC_RANGE; } -ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret) { +int setROI(ROI arg) { - // set ROI - if(n >= 0){ - // print - if (!n) { - FILE_LOG(logINFO, ("Clearing ROI\n")); - } else { - FILE_LOG(logINFO, ("Setting ROI:\n")); - int i = 0; - for (i = 0; i < n; ++i) { - FILE_LOG(logINFO, ("\t(%d, %d)\n", arg[i].xmin, arg[i].xmax)); - } + int adc = -1; + if (arg.xmin == -1) { + FILE_LOG(logINFO, ("Clearing ROI\n")); + rois.xmin = -1; + rois.xmax = -1; + } else { + FILE_LOG(logINFO, ("Setting ROI:(%d, %d)\n", arg.xmin, arg.xmax)); + // validation + // xmin divisible by 256 and less than 1280 + if (((arg.xmin % NCHAN_PER_ADC) != 0) || (arg.xmin >= (NCHAN * NCHIP))) { + FILE_LOG(logERROR, ("Could not set roi. xmin is invalid\n")); + return FAIL; } - // only one ROI allowed per module - if (n > 1) { - FILE_LOG(logERROR, ("\tCannot set more than 1 ROI per module\n")); - *ret = FAIL; - *retvalsize = nROI; - return rois; + // xmax must be 255 more than xmin + if (arg.xmax != (arg.xmin + NCHAN_PER_ADC - 1)) { + FILE_LOG(logERROR, ("Could not set roi. xmax is invalid\n")); + return FAIL; } + rois.xmin = arg.xmin; + rois.xmax = arg.xmax; + adc = arg.xmin / NCHAN_PER_ADC; + } + FILE_LOG(logINFO, ("\tAdc to be configured: %d\n", adc)); + FILE_LOG(logINFO, ("\tROI to be configured: (%d, %d)\n", + (adc == -1) ? 0 : (rois.xmin), + (adc == -1) ? (NCHIP * NCHAN - 1) : (rois.xmax))); - //clear all rois - nROI = 0; + //set adc of interest + setROIADC(adc); + return OK; +} - // find adc number and recorrect channel limits - int adc = -1; - if (n) { - // all channels - if ((arg[0].xmin <= 0) && (arg[0].xmax >= NCHIP * NCHAN)) - adc = -1; - // single adc - else { - //adc = mid value/numchans - adc = ((((arg[0].xmax) + (arg[0].xmin))/2) / (NCHAN * NCHIPS_PER_ADC)); - // incorrect adc - if((adc < 0) || (adc > 4)) { - FILE_LOG(logERROR, ("\tadc value greater than 5. deleting roi\n")); - adc = -1; - } - // recorrect roi values - else { - rois[0].xmin = adc * (NCHAN * NCHIPS_PER_ADC); - rois[0].xmax = (adc + 1) * (NCHAN * NCHIPS_PER_ADC) - 1; - rois[0].ymin = -1; - rois[0].ymax = -1; - nROI = 1; - } - } - } - - if (adc == -1) - nROI = 0; - - FILE_LOG(logINFO, ("\tAdc to be configured: %d\n", adc)); - FILE_LOG(logINFO, ("\tROI to be configured: (%d, %d)\n", - (adc == -1) ? 0 : (rois[0].xmin), - (adc == -1) ? (NCHIP * NCHAN - 1) : (rois[0].xmax))); - - // could not set roi - if((n != 0) && ((arg[0].xmin != rois[0].xmin)|| - (arg[0].xmax != rois[0].xmax)|| - (arg[0].ymin != rois[0].ymin)|| - (arg[0].ymax != rois[0].ymax))) { - *ret = FAIL; - FILE_LOG(logERROR, ("\tCould not set given ROI\n")); - } - if(n != nROI) { - *ret = FAIL; - FILE_LOG(logERROR, ("\tCould not set or clear ROIs\n")); - } - - //set adc of interest - setROIADC(adc); - } else FILE_LOG(logINFO, ("Getting ROI:\n")); +ROI getROI() { + FILE_LOG(logINFO, ("Getting ROI:\n")); // print - if (!nROI) { + if (rois.xmin == -1) { FILE_LOG(logINFO, ("\tROI: None\n")); } else { - FILE_LOG(logINFO, ("ROI:\n")); - int i = 0; - for (i = 0; i < nROI; ++i) { - FILE_LOG(logINFO, ("\t(%d, %d)\n", rois[i].xmin, rois[i].xmax)); - - } + FILE_LOG(logINFO, ("ROI: (%d,%d)\n", rois.xmin, rois.xmax)); } - - *retvalsize = nROI; return rois; } @@ -1271,10 +1232,10 @@ int setHighVoltage(int val){ /* parameters - timing, extsig */ -void setTiming( enum externalCommunicationMode arg){ +void setTiming( enum timingMode arg){ u_int32_t addr = EXT_SIGNAL_REG; - if (arg != GET_EXTERNAL_COMMUNICATION_MODE){ + if (arg != GET_TIMING_MODE){ switch((int)arg){ case AUTO_TIMING: FILE_LOG(logINFO, ("Set Timing: Auto\n")); @@ -1296,7 +1257,7 @@ void setTiming( enum externalCommunicationMode arg){ } } -enum externalCommunicationMode getTiming() { +enum timingMode getTiming() { u_int32_t regval = bus_r(EXT_SIGNAL_REG); switch (regval) { case EXT_SIGNAL_TRGGR_IN_RSNG_VAL: @@ -1397,13 +1358,6 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t (long long unsigned int)destmac)); FILE_LOG(logINFO, ("\tDest. Port : %d (0x%08x)\n",udpport, udpport)); - // set/ unset the digital test bit - if (digitalTestBit) - bus_w (addr, bus_r(addr) | DGTL_TST_MSK); - else - bus_w (addr, bus_r(addr) & ~DGTL_TST_MSK); - FILE_LOG(logDEBUG1, ("\tDigital Test Bit. MultiPurpose reg: 0x%x\n", bus_r(addr))); - //reset mac bus_w (addr, bus_r(addr) | RST_MSK); FILE_LOG(logDEBUG1, ("\tReset Mac. MultiPurpose reg: 0x%x\n", bus_r(addr))); @@ -1501,7 +1455,7 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t */ FILE_LOG(logINFOBLUE, ("Sending an image to counter the packet numbers\n")); // remember old parameters - enum externalCommunicationMode oldtiming = getTiming(); + enum timingMode oldtiming = getTiming(); uint64_t oldframes = setTimer(FRAME_NUMBER, -1); uint64_t oldcycles = setTimer(CYCLES_NUMBER, -1); uint64_t oldPeriod = setTimer(FRAME_PERIOD, -1); @@ -1564,107 +1518,6 @@ int getAdcConfigured(){ } -/* gotthard specific - loadimage, read/reset counter block */ - -void loadImage(enum imageType index, short int imageVals[]){ - u_int32_t addr = DARK_IMAGE_REG; - if (index == GAIN_IMAGE) - addr = GAIN_IMAGE_REG; - int dataBytes = calculateDataBytes(); - - volatile u_int16_t *ptr = (u_int16_t*)(CSP0BASE + addr * 2); - memcpy((char*)ptr, (char*)imageVals, dataBytes); - - FILE_LOG(logINFO, ("Loaded %s image at 0x%p\n", - (index == GAIN_IMAGE) ? "Gain" : "Dark", (void*) ptr)); -} - -int readCounterBlock(int startACQ, short int counterVals[]){ - FILE_LOG(logINFO, ("Reading Counter Block with start Acq :%d\n", startACQ)); - - // stop any current acquisition - if (runBusy()) { - if (stopStateMachine() == FAIL) - return FAIL; - // waiting for the last frame read to be done - while(runBusy()) - usleep(500); - FILE_LOG(logDEBUG1, ("State machine stopped\n")); - } - - // copy memory - u_int32_t addr = COUNTER_MEMORY_REG; - volatile u_int16_t *ptr = (u_int16_t*)(CSP0BASE + addr * 2); - int dataBytes = calculateDataBytes(); - memcpy((char*)counterVals, (char*)ptr, dataBytes); - - // unreset counter - addr = MULTI_PURPOSE_REG; - bus_w(addr, (bus_r(addr) &~ RST_CNTR_MSK)); - FILE_LOG(logDEBUG1, ("\tUnsetting reset Counter. Multi Purpose Reg: 0x%x\n", bus_r(addr))); - - // start state machine - if (startACQ == 1){ - startStateMachine(); - if (runBusy()) { - FILE_LOG(logINFO, ("State machine RUNNING\n")); - } else { - FILE_LOG(logINFO, ("State machine IDLE\n")); - } - } - return OK; -} - -int resetCounterBlock(int startACQ){ - FILE_LOG(logINFO, ("Resetting Counter Block with start Acq :%d\n", startACQ)); - - // stop any current acquisition - if (runBusy()) { - if (stopStateMachine() == FAIL) - return FAIL; - // waiting for the last frame read to be done - while(runBusy()) - usleep(500); - FILE_LOG(logDEBUG1, ("State machine stopped\n")); - } - - // reset counter - u_int32_t addr = MULTI_PURPOSE_REG; - bus_w(addr, (bus_r(addr) | RST_CNTR_MSK)); - FILE_LOG(logDEBUG1, ("\tResetting Counter. Multi Purpose Reg: 0x%x\n", bus_r(addr))); - - // copy memory - addr = COUNTER_MEMORY_REG; - volatile u_int16_t *ptr = (u_int16_t*)(CSP0BASE + addr * 2); - int dataBytes = calculateDataBytes(); - char *counterVals = NULL; - counterVals = realloc(counterVals, dataBytes); - memcpy((char*)counterVals, (char*)ptr, dataBytes); - - // unreset counter - addr = MULTI_PURPOSE_REG; - bus_w(addr, (bus_r(addr) &~ RST_CNTR_MSK)); - FILE_LOG(logDEBUG1, ("\tUnsetting reset Counter. Multi Purpose Reg: 0x%x\n", bus_r(addr))); - - // start state machine - if (startACQ == 1){ - startStateMachine(); - if (runBusy()) { - FILE_LOG(logINFO, ("State machine RUNNING\n")); - } else { - FILE_LOG(logINFO, ("State machine IDLE\n")); - } - } - - if (sizeof(counterVals) <= 0){ - FILE_LOG(logERROR, ("\tSize of counterVals: %d\n", (int)sizeof(counterVals))); - return FAIL; - } - - return OK; -} - - /* aquisition */ int startStateMachine(){ diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.h deleted file mode 120000 index 345b8c029..000000000 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorFunctionList.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer.c deleted file mode 120000 index a7eb59acb..000000000 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer.c \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h index 6c037e852..16e1142cb 100755 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h @@ -24,6 +24,7 @@ enum DACINDEX {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN #define NCHIP (10) #define NDAC (8) #define NCHIPS_PER_ADC (2) +#define NCHAN_PER_ADC (256) #define DYNAMIC_RANGE (16) #define NUM_BITS_PER_PIXEL (DYNAMIC_RANGE / 8) #define DATA_BYTES (NCHIP * NCHAN * NUM_BITS_PER_PIXEL) diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_funcs.c deleted file mode 120000 index a7532ccd4..000000000 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_funcs.h deleted file mode 120000 index 7569daf47..000000000 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/sls_detector_defs.h b/slsDetectorServers/gotthardDetectorServer/sls_detector_defs.h deleted file mode 120000 index 2af30d73a..000000000 --- a/slsDetectorServers/gotthardDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/sls_detector_funcs.h b/slsDetectorServers/gotthardDetectorServer/sls_detector_funcs.h deleted file mode 120000 index 3f48959a9..000000000 --- a/slsDetectorServers/gotthardDetectorServer/sls_detector_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/gotthardDetectorServer/versionAPI.h b/slsDetectorServers/gotthardDetectorServer/versionAPI.h deleted file mode 120000 index 5e580d8bb..000000000 --- a/slsDetectorServers/gotthardDetectorServer/versionAPI.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/versionAPI.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/AD9257.h b/slsDetectorServers/jungfrauDetectorServer/AD9257.h deleted file mode 120000 index 87b70e097..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/AD9257.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/AD9257.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/ALTERA_PLL.h b/slsDetectorServers/jungfrauDetectorServer/ALTERA_PLL.h deleted file mode 120000 index e665f009d..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/ALTERA_PLL.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/ALTERA_PLL.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt b/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt index 50574aa34..a7461a986 100644 --- a/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt @@ -1,8 +1,13 @@ add_executable(jungfrauDetectorServer slsDetectorFunctionList.c - slsDetectorServer.c - slsDetectorServer_funcs.c - communication_funcs.c + ../slsDetectorServer/slsDetectorServer.c + ../slsDetectorServer/slsDetectorServer_funcs.c + ../slsDetectorServer/communication_funcs.c +) + +include_directories( + ../slsDetectorServer/ + ../../slsSupportLib/include ) target_include_directories(jungfrauDetectorServer diff --git a/slsDetectorServers/jungfrauDetectorServer/LTC2620.h b/slsDetectorServers/jungfrauDetectorServer/LTC2620.h deleted file mode 120000 index 13157cb8b..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/LTC2620.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/LTC2620.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/MAX1932.h b/slsDetectorServers/jungfrauDetectorServer/MAX1932.h deleted file mode 120000 index 8f7b239ea..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/MAX1932.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/MAX1932.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/Makefile b/slsDetectorServers/jungfrauDetectorServer/Makefile index f197d60dd..c2b2ad18e 100755 --- a/slsDetectorServers/jungfrauDetectorServer/Makefile +++ b/slsDetectorServers/jungfrauDetectorServer/Makefile @@ -1,14 +1,17 @@ +current_dir = $(shell pwd) +main_server = ../slsDetectorServer/ +support_lib = ../../slsSupportLib/include/ + CROSS = bfin-uclinux- CC = $(CROSS)gcc -CFLAGS += -Wall -DJUNGFRAUD -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -LDLIBS += -lm -lstdc++ - +CFLAGS += -Wall -DJUNGFRAUD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE +LDLIBS += -lm PROGS = jungfrauDetectorServer DESTDIR ?= bin INSTMODE = 0777 -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.c=.o) +SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c +OBJS = $(SRCS:.c=.o) all: clean versioning $(PROGS) @@ -23,12 +26,12 @@ versioning: $(PROGS): $(OBJS) # echo $(OBJS) mkdir -p $(DESTDIR) - $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) + $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) mv $(PROGS) $(DESTDIR) rm *.gdb clean: - rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb + rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/ansi.h b/slsDetectorServers/jungfrauDetectorServer/ansi.h deleted file mode 120000 index 4a82d0575..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/ansi.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/ansi.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index bed4cebbf..5eb78885f 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/blackfin.h b/slsDetectorServers/jungfrauDetectorServer/blackfin.h deleted file mode 120000 index 2873c7dc6..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/blackfin.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/blackfin.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/common.h b/slsDetectorServers/jungfrauDetectorServer/common.h deleted file mode 120000 index 6776eb607..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/common.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/common.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/commonServerFunctions.h b/slsDetectorServers/jungfrauDetectorServer/commonServerFunctions.h deleted file mode 120000 index 33bdd8d53..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/commonServerFunctions.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/commonServerFunctions.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/communication_funcs.c b/slsDetectorServers/jungfrauDetectorServer/communication_funcs.c deleted file mode 120000 index 30435fdc4..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/communication_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/communication_funcs.h b/slsDetectorServers/jungfrauDetectorServer/communication_funcs.h deleted file mode 120000 index c0c144994..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/communication_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/communication_funcs_UDP.h b/slsDetectorServers/jungfrauDetectorServer/communication_funcs_UDP.h deleted file mode 120000 index 0d434a97d..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/communication_funcs_UDP.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs_UDP.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/logger.h b/slsDetectorServers/jungfrauDetectorServer/logger.h deleted file mode 120000 index ff1930ce3..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/logger.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/logger.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/programfpga.h b/slsDetectorServers/jungfrauDetectorServer/programfpga.h deleted file mode 120000 index 72c54d21d..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/programfpga.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/programfpga.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index cf19332a2..4c2fb1fbb 100755 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1,6 +1,6 @@ #include "slsDetectorFunctionList.h" #include "versionAPI.h" -#include "logger.h" +#include "clogger.h" #include #include "AD9257.h" // commonServerFunctions.h, blackfin.h, ansi.h #include "LTC2620.h" // dacs @@ -976,9 +976,9 @@ int setHighVoltage(int val){ /* parameters - timing, extsig */ -void setTiming( enum externalCommunicationMode arg){ +void setTiming( enum timingMode arg){ - if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ + if(arg != GET_TIMING_MODE){ switch((int)arg){ case AUTO_TIMING: FILE_LOG(logINFO, ("Set Timing: Auto\n")); @@ -996,7 +996,7 @@ void setTiming( enum externalCommunicationMode arg){ } -enum externalCommunicationMode getTiming() { +enum timingMode getTiming() { if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) return TRIGGER_EXPOSURE; return AUTO_TIMING; diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h deleted file mode 120000 index 345b8c029..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorFunctionList.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer.c deleted file mode 120000 index a7eb59acb..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer.c \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_funcs.c deleted file mode 120000 index a7532ccd4..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_funcs.h deleted file mode 120000 index 7569daf47..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/sls_detector_defs.h b/slsDetectorServers/jungfrauDetectorServer/sls_detector_defs.h deleted file mode 120000 index 2af30d73a..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/sls_detector_funcs.h b/slsDetectorServers/jungfrauDetectorServer/sls_detector_funcs.h deleted file mode 120000 index 3f48959a9..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/sls_detector_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/versionAPI.h b/slsDetectorServers/jungfrauDetectorServer/versionAPI.h deleted file mode 120000 index 5e580d8bb..000000000 --- a/slsDetectorServers/jungfrauDetectorServer/versionAPI.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/versionAPI.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/AD9257.h b/slsDetectorServers/moenchDetectorServer/AD9257.h deleted file mode 120000 index 87b70e097..000000000 --- a/slsDetectorServers/moenchDetectorServer/AD9257.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/AD9257.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/ALTERA_PLL.h b/slsDetectorServers/moenchDetectorServer/ALTERA_PLL.h deleted file mode 120000 index e665f009d..000000000 --- a/slsDetectorServers/moenchDetectorServer/ALTERA_PLL.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/ALTERA_PLL.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/CMakeLists.txt b/slsDetectorServers/moenchDetectorServer/CMakeLists.txt new file mode 100644 index 000000000..f8b47a602 --- /dev/null +++ b/slsDetectorServers/moenchDetectorServer/CMakeLists.txt @@ -0,0 +1,31 @@ +add_executable(moenchDetectorServer + slsDetectorFunctionList.c + ../slsDetectorServer/slsDetectorServer.c + ../slsDetectorServer/slsDetectorServer_funcs.c + ../slsDetectorServer/communication_funcs.c +) + +include_directories( + ../slsDetectorServer/ + ../../slsSupportLib/include +) + +target_include_directories(moenchDetectorServer + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_definitions(moenchDetectorServer + PUBLIC MOENCHD VIRTUAL STOP_SERVER +) + +target_link_libraries(moenchDetectorServer + PUBLIC pthread rt +) + +set_target_properties(moenchDetectorServer PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) + +install(TARGETS moenchDetectorServer + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/slsDetectorServers/moenchDetectorServer/LTC2620.h b/slsDetectorServers/moenchDetectorServer/LTC2620.h deleted file mode 120000 index 13157cb8b..000000000 --- a/slsDetectorServers/moenchDetectorServer/LTC2620.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/LTC2620.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/MAX1932.h b/slsDetectorServers/moenchDetectorServer/MAX1932.h deleted file mode 120000 index 8f7b239ea..000000000 --- a/slsDetectorServers/moenchDetectorServer/MAX1932.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/MAX1932.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/Makefile b/slsDetectorServers/moenchDetectorServer/Makefile index 65960a021..2f2cda415 100755 --- a/slsDetectorServers/moenchDetectorServer/Makefile +++ b/slsDetectorServers/moenchDetectorServer/Makefile @@ -1,15 +1,18 @@ +current_dir = $(shell pwd) +main_server = ../slsDetectorServer/ +support_lib = ../../slsSupportLib/include/ + CROSS = bfin-uclinux- CC = $(CROSS)gcc -CFLAGS += -Wall -DMOENCHD -DSTOP_SERVER -DDEBUG1# -DVERBOSEI #-DVERBOSE -LDLIBS += -lm -lstdc++ - +CFLAGS += -Wall -DMOENCHD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE +LDLIBS += -lm PROGS = moenchDetectorServer DESTDIR ?= bin INSTMODE = 0777 -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.c=.o) - +SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c +OBJS = $(SRCS:.c=.o) + all: clean versioning $(PROGS) boot: $(OBJS) @@ -28,7 +31,7 @@ $(PROGS): $(OBJS) rm *.gdb clean: - rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb + rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/Makefile.virtual b/slsDetectorServers/moenchDetectorServer/Makefile.virtual deleted file mode 100755 index f502da862..000000000 --- a/slsDetectorServers/moenchDetectorServer/Makefile.virtual +++ /dev/null @@ -1,27 +0,0 @@ -CC = gcc -CFLAGS += -Wall -DMOENCHD -DVIRTUAL -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -LDLIBS += -lm -lstdc++ -pthread - -PROGS = moenchDetectorServer_virtual -DESTDIR ?= bin -INSTMODE = 0777 - -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.c=.o) - -all: clean versioning $(PROGS) - -boot: $(OBJS) - -versioning: - @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` - -$(PROGS): $(OBJS) -# echo $(OBJS) - mkdir -p $(DESTDIR) - $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) - mv $(PROGS) $(DESTDIR) - -clean: - rm -rf $(DESTDIR)/$(PROGS) *.o - diff --git a/slsDetectorServers/moenchDetectorServer/UDPPacketHeaderGenerator.h b/slsDetectorServers/moenchDetectorServer/UDPPacketHeaderGenerator.h deleted file mode 120000 index eb0223a3e..000000000 --- a/slsDetectorServers/moenchDetectorServer/UDPPacketHeaderGenerator.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/UDPPacketHeaderGenerator.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/ansi.h b/slsDetectorServers/moenchDetectorServer/ansi.h deleted file mode 120000 index 4a82d0575..000000000 --- a/slsDetectorServers/moenchDetectorServer/ansi.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/ansi.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/blackfin.h b/slsDetectorServers/moenchDetectorServer/blackfin.h deleted file mode 120000 index 2873c7dc6..000000000 --- a/slsDetectorServers/moenchDetectorServer/blackfin.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/blackfin.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/common.h b/slsDetectorServers/moenchDetectorServer/common.h deleted file mode 120000 index 6776eb607..000000000 --- a/slsDetectorServers/moenchDetectorServer/common.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/common.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/commonServerFunctions.h b/slsDetectorServers/moenchDetectorServer/commonServerFunctions.h deleted file mode 120000 index 33bdd8d53..000000000 --- a/slsDetectorServers/moenchDetectorServer/commonServerFunctions.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/commonServerFunctions.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/communication_funcs.c b/slsDetectorServers/moenchDetectorServer/communication_funcs.c deleted file mode 120000 index 30435fdc4..000000000 --- a/slsDetectorServers/moenchDetectorServer/communication_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/communication_funcs.h b/slsDetectorServers/moenchDetectorServer/communication_funcs.h deleted file mode 120000 index c0c144994..000000000 --- a/slsDetectorServers/moenchDetectorServer/communication_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/communication_funcs_UDP.h b/slsDetectorServers/moenchDetectorServer/communication_funcs_UDP.h deleted file mode 120000 index 0d434a97d..000000000 --- a/slsDetectorServers/moenchDetectorServer/communication_funcs_UDP.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/communication_funcs_UDP.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/logger.h b/slsDetectorServers/moenchDetectorServer/logger.h deleted file mode 120000 index ff1930ce3..000000000 --- a/slsDetectorServers/moenchDetectorServer/logger.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/logger.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/programfpga.h b/slsDetectorServers/moenchDetectorServer/programfpga.h deleted file mode 120000 index 72c54d21d..000000000 --- a/slsDetectorServers/moenchDetectorServer/programfpga.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/programfpga.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index b55a77983..9dcca2085 100755 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -1,6 +1,6 @@ #include "slsDetectorFunctionList.h" #include "versionAPI.h" -#include "logger.h" +#include "clogger.h" #include "communication_funcs_UDP.h" #include "UDPPacketHeaderGenerator.h" @@ -1061,9 +1061,9 @@ int setHighVoltage(int val){ /* parameters - timing, extsig */ -void setTiming( enum externalCommunicationMode arg){ +void setTiming( enum timingMode arg){ - if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ + if(arg != GET_TIMING_MODE){ switch((int)arg){ case AUTO_TIMING: FILE_LOG(logINFO, ("Set Timing: Auto\n")); @@ -1081,7 +1081,7 @@ void setTiming( enum externalCommunicationMode arg){ } -enum externalCommunicationMode getTiming() { +enum timingMode getTiming() { if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) return TRIGGER_EXPOSURE; return AUTO_TIMING; diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h deleted file mode 120000 index 345b8c029..000000000 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorFunctionList.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorServer.c b/slsDetectorServers/moenchDetectorServer/slsDetectorServer.c deleted file mode 120000 index a7eb59acb..000000000 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorServer.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer.c \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/moenchDetectorServer/slsDetectorServer_funcs.c deleted file mode 120000 index a7532ccd4..000000000 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.c \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/moenchDetectorServer/slsDetectorServer_funcs.h deleted file mode 120000 index 7569daf47..000000000 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorServer/slsDetectorServer_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/sls_detector_defs.h b/slsDetectorServers/moenchDetectorServer/sls_detector_defs.h deleted file mode 120000 index 2af30d73a..000000000 --- a/slsDetectorServers/moenchDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/sls_detector_funcs.h b/slsDetectorServers/moenchDetectorServer/sls_detector_funcs.h deleted file mode 120000 index 3f48959a9..000000000 --- a/slsDetectorServers/moenchDetectorServer/sls_detector_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/sls_detector_funcs.h \ No newline at end of file diff --git a/slsDetectorServers/moenchDetectorServer/versionAPI.h b/slsDetectorServers/moenchDetectorServer/versionAPI.h deleted file mode 120000 index 5e580d8bb..000000000 --- a/slsDetectorServers/moenchDetectorServer/versionAPI.h +++ /dev/null @@ -1 +0,0 @@ -../../slsSupportLib/include/versionAPI.h \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/UDPPacketHeaderGenerator.h b/slsDetectorServers/slsDetectorServer/UDPPacketHeaderGenerator.h index 9350d4bd6..7e9c47263 100755 --- a/slsDetectorServers/slsDetectorServer/UDPPacketHeaderGenerator.h +++ b/slsDetectorServers/slsDetectorServer/UDPPacketHeaderGenerator.h @@ -1,6 +1,6 @@ #pragma once -#include "logger.h" +#include "clogger.h" #include "sls_detector_defs.h" diff --git a/slsDetectorServers/slsDetectorServer/logger.h b/slsDetectorServers/slsDetectorServer/clogger.h similarity index 100% rename from slsDetectorServers/slsDetectorServer/logger.h rename to slsDetectorServers/slsDetectorServer/clogger.h diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.c b/slsDetectorServers/slsDetectorServer/communication_funcs.c index 3c4bae02e..756530280 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.c +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.c @@ -1,5 +1,5 @@ #include "communication_funcs.h" -#include "logger.h" +#include "clogger.h" #include #include diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs_UDP.h b/slsDetectorServers/slsDetectorServer/communication_funcs_UDP.h index 622e92694..0182ae46e 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs_UDP.h +++ b/slsDetectorServers/slsDetectorServer/communication_funcs_UDP.h @@ -1,6 +1,6 @@ #pragma once -#include "logger.h" +#include "clogger.h" #include "sls_detector_defs.h" diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h index fd4ca2898..b6de7aff7 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h @@ -1,7 +1,7 @@ #include "sls_detector_defs.h" #include "slsDetectorServer_defs.h" // DAC_INDEX, ADC_INDEX, also include RegisterDefs.h #ifdef GOTTHARDD -#include "logger.h" // runState(enum TLogLevel) +#include "clogger.h" // runState(enum TLogLevel) #endif #include #include // FILE @@ -27,6 +27,7 @@ int testBus(); #ifdef GOTTHARDD int detectorTest(enum digitalTestMode arg, int ival); +int testImage(int ival); #elif defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) int detectorTest(enum digitalTestMode arg); #endif @@ -114,7 +115,8 @@ void resetPeripheral(); // parameters - dr, roi int setDynamicRange(int dr); #ifdef GOTTHARDD -ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret); +int setROI(ROI arg); +ROI getROI(); #endif #if defined(CHIPTESTBOARDD) || defined(MOENCHD) int setADCEnableMask(uint32_t mask); @@ -211,8 +213,8 @@ int setHighVoltage(int val); // parameters - timing, extsig -void setTiming( enum externalCommunicationMode arg); -enum externalCommunicationMode getTiming(); +void setTiming( enum timingMode arg); +enum timingMode getTiming(); #ifdef GOTTHARDD void setExtSignal(enum externalSignalFlag mode); int getExtSignal(); @@ -300,14 +302,8 @@ void setPatternBitMask(uint64_t mask); uint64_t getPatternBitMask(); #endif -// gotthard specific - image, pedestal -#ifdef GOTTHARDD -void loadImage(enum imageType index, short int imageVals[]); -int readCounterBlock(int startACQ, short int counterVals[]); -int resetCounterBlock(int startACQ); - // jungfrau specific - powerchip, autocompdisable, clockdiv, asictimer, clock, pll, flashing firmware -#elif JUNGFRAUD +#ifdef JUNGFRAUD void initReadoutConfiguration(); int powerChip (int on); int autoCompDisable(int on); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c index 669009059..64c64a4b6 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c @@ -2,7 +2,7 @@ The port number is passed as an argument */ #include "sls_detector_defs.h" -#include "logger.h" +#include "clogger.h" #include "communication_funcs.h" #include "slsDetectorServer_funcs.h" #include "slsDetectorServer_defs.h" @@ -47,7 +47,7 @@ int main(int argc, char *argv[]){ FILE_LOG(logINFO, ("SLS Detector Server %s (0x%x)\n", GITBRANCH, version)); } - int portno = DEFAULT_PORTNO; + int portno = DEFAULT_PORTNO; int retval = OK; int fd = 0; @@ -67,6 +67,17 @@ int main(int argc, char *argv[]){ FILE_LOG(logINFO, ("Detected developer mode\n")); debugflag = 1; } + else if(!strcasecmp(argv[i],"--port")){ + if ((i + 1) >= argc) { + FILE_LOG(logERROR, ("no port value given. Exiting.\n")); + return -1; + } + if (sscanf(argv[i + 1], "%d", &portno) == 0) { + FILE_LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1])); + return -1; + } + FILE_LOG(logINFO, ("Detected port: %d\n", portno)); + } #ifdef GOTTHARDD else if(!strcasecmp(argv[i],"-phaseshift")){ if ((i + 1) >= argc) { @@ -88,20 +99,18 @@ int main(int argc, char *argv[]){ memset(cmd, 0, 100); #endif if (isControlServer) { - portno = DEFAULT_PORTNO; FILE_LOG(logINFO, ("Opening control server on port %d \n", portno)); #ifdef STOP_SERVER { int i; for (i = 0; i < argc; ++i) sprintf(cmd, "%s %s", cmd, argv[i]); - sprintf(cmd,"%s -stopserver&", cmd); + sprintf(cmd,"%s -stopserver --port %d &", cmd, portno + 1); FILE_LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd)); system(cmd); } #endif } else { - portno = DEFAULT_PORTNO + 1; FILE_LOG(logINFO,("Opening stop server on port %d \n", portno)); } diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 3c8420442..f6aa66775 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -1,7 +1,7 @@ #include "slsDetectorServer_funcs.h" #include "slsDetectorFunctionList.h" #include "communication_funcs.h" -#include "logger.h" +#include "clogger.h" #include #include @@ -116,7 +116,6 @@ const char* getTimerName(enum timerIndex ind) { case ACQUISITION_TIME: return "acquisition_time"; case FRAME_PERIOD: return "frame_period"; case DELAY_AFTER_TRIGGER: return "delay_after_trigger"; - case GATES_NUMBER: return "gates_number"; case CYCLES_NUMBER: return "cycles_number"; case ACTUAL_TIME: return "actual_time"; case MEASUREMENT_TIME: return "measurement_time"; @@ -168,7 +167,7 @@ const char* getFunctionName(enum detFuncs func) { case F_EXEC_COMMAND: return "F_EXEC_COMMAND"; case F_GET_DETECTOR_TYPE: return "F_GET_DETECTOR_TYPE"; case F_SET_EXTERNAL_SIGNAL_FLAG: return "F_SET_EXTERNAL_SIGNAL_FLAG"; - case F_SET_EXTERNAL_COMMUNICATION_MODE: return "F_SET_EXTERNAL_COMMUNICATION_MODE"; + case F_SET_TIMING_MODE: return "F_SET_TIMING_MODE"; case F_GET_ID: return "F_GET_ID"; case F_DIGITAL_TEST: return "F_DIGITAL_TEST"; case F_SET_DAC: return "F_SET_DAC"; @@ -190,6 +189,7 @@ const char* getFunctionName(enum detFuncs func) { case F_SET_DYNAMIC_RANGE: return "F_SET_DYNAMIC_RANGE"; case F_SET_READOUT_FLAGS: return "F_SET_READOUT_FLAGS"; case F_SET_ROI: return "F_SET_ROI"; + case F_GET_ROI: return "F_GET_ROI"; case F_SET_SPEED: return "F_SET_SPEED"; case F_EXIT_SERVER: return "F_EXIT_SERVER"; case F_LOCK_SERVER: return "F_LOCK_SERVER"; @@ -197,9 +197,6 @@ const char* getFunctionName(enum detFuncs func) { case F_SET_PORT: return "F_SET_PORT"; case F_UPDATE_CLIENT: return "F_UPDATE_CLIENT"; case F_CONFIGURE_MAC: return "F_CONFIGURE_MAC"; - case F_LOAD_IMAGE: return "F_LOAD_IMAGE"; - case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK"; - case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK"; case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA"; case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS"; case F_SET_PATTERN_IO_CONTROL: return "F_SET_PATTERN_IO_CONTROL"; @@ -258,7 +255,7 @@ void function_table() { flist[F_EXEC_COMMAND] = &exec_command; flist[F_GET_DETECTOR_TYPE] = &get_detector_type; flist[F_SET_EXTERNAL_SIGNAL_FLAG] = &set_external_signal_flag; - flist[F_SET_EXTERNAL_COMMUNICATION_MODE] = &set_external_communication_mode; + flist[F_SET_TIMING_MODE] = &set_timing_mode; flist[F_GET_ID] = &get_id; flist[F_DIGITAL_TEST] = &digital_test; flist[F_SET_DAC] = &set_dac; @@ -280,6 +277,7 @@ void function_table() { flist[F_SET_DYNAMIC_RANGE] = &set_dynamic_range; flist[F_SET_READOUT_FLAGS] = &set_readout_flags; flist[F_SET_ROI] = &set_roi; + flist[F_GET_ROI] = &get_roi; flist[F_SET_SPEED] = &set_speed; flist[F_EXIT_SERVER] = &exit_server; flist[F_LOCK_SERVER] = &lock_server; @@ -287,9 +285,6 @@ void function_table() { flist[F_SET_PORT] = &set_port; flist[F_UPDATE_CLIENT] = &update_client; flist[F_CONFIGURE_MAC] = &configure_mac; - flist[F_LOAD_IMAGE] = &load_image; - flist[F_READ_COUNTER_BLOCK] = &read_counter_block; - flist[F_RESET_COUNTER_BLOCK] = &reset_counter_block; flist[F_ENABLE_TEN_GIGA] = &enable_ten_giga; flist[F_SET_ALL_TRIMBITS] = &set_all_trimbits; flist[F_SET_PATTERN_IO_CONTROL] = &set_pattern_io_control; @@ -524,18 +519,18 @@ int set_external_signal_flag(int file_des) { -int set_external_communication_mode(int file_des) { +int set_timing_mode(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - enum externalCommunicationMode arg = GET_EXTERNAL_COMMUNICATION_MODE; - enum externalCommunicationMode retval = GET_EXTERNAL_COMMUNICATION_MODE; + enum timingMode arg = GET_TIMING_MODE; + enum timingMode retval = GET_TIMING_MODE; if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) return printSocketReadError(); FILE_LOG(logDEBUG1, ("Setting external communication mode to %d\n", arg)); // set - if ((arg != GET_EXTERNAL_COMMUNICATION_MODE) && (Server_VerifyLock() == OK)) { + if ((arg != GET_TIMING_MODE) && (Server_VerifyLock() == OK)) { switch (arg) { case AUTO_TIMING: case TRIGGER_EXPOSURE: @@ -618,7 +613,7 @@ int digital_test(int file_des) { case DETECTOR_FIRMWARE_TEST: case DETECTOR_BUS_TEST: #ifdef GOTTHARDD - case DIGITAL_BIT_TEST: + case IMAGE_TEST: retval = detectorTest(mode, ival); break; #else @@ -1897,76 +1892,49 @@ int set_readout_flags(int file_des) { int set_roi(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - int narg = -1; - ROI arg[MAX_ROIS]; - int nretval = -1; - ROI* retval = NULL; + ROI arg; - // receive number of ROIs - if (receiveData(file_des, &narg, sizeof(narg), INT32) < 0) + // receive ROI + if (receiveData(file_des, &arg.xmin, sizeof(int), INT32) < 0) return printSocketReadError(); - // receive ROIs - { - int iloop = 0; - for (iloop = 0; iloop < narg; ++iloop) { - if (receiveData(file_des, &arg[iloop].xmin, sizeof(int), INT32) < 0) - return printSocketReadError(); - if (receiveData(file_des, &arg[iloop].xmax, sizeof(int), INT32) < 0) - return printSocketReadError(); - if (receiveData(file_des, &arg[iloop].ymin, sizeof(int), INT32) < 0) - return printSocketReadError(); - if (receiveData(file_des, &arg[iloop].ymax, sizeof(int), INT32) < 0) - return printSocketReadError(); - } - } - FILE_LOG(logDEBUG1, ("Set ROI (narg:%d)\n", narg)); - { - int iloop = 0; - for (iloop = 0; iloop < narg; ++iloop) { - FILE_LOG(logDEBUG1, ("%d: %d\t%d\t%d\t%d\n", - arg[iloop].xmin, arg[iloop].xmax, arg[iloop].ymin, arg[iloop].ymax)); - } - } + if (receiveData(file_des, &arg.xmax, sizeof(int), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Set ROI: [%d, %d]\n", arg.xmin, arg.xmax)); #ifndef GOTTHARDD functionNotImplemented(); #else - // set & get - if ((narg == GET_READOUT_FLAGS) || (Server_VerifyLock() == OK)) { - if (myDetectorType == GOTTHARD && narg > 1) { - ret = FAIL; - strcpy(mess,"Can not set more than one ROI per module.\n"); - FILE_LOG(logERROR,(mess)); - } else { - retval = setROI(narg, arg, &nretval, &ret); - if (ret == FAIL) { - if (nretval == -1) // chip test board - sprintf(mess,"Could not set ROI. Max ROI level (100) reached!\n"); - else if (nretval == -2) - sprintf(mess, "Could not set ROI. Could not allocate RAM\n"); - else - sprintf(mess,"Could not set all roi. " - "Set %d rois, but read %d rois\n", narg, nretval); - FILE_LOG(logERROR,(mess)); - } - FILE_LOG(logDEBUG1, ("nRois: %d\n", nretval)); - } + // only set + if (Server_VerifyLock() == OK) { + ret = setROI(arg); + if (ret == FAIL) { + sprintf(mess, "Could not set ROI. Invalid xmin or xmax\n"); + FILE_LOG(logERROR,(mess)); + } } #endif - Server_SendResult(file_des, INT32, UPDATE, NULL, 0); + return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); +} + +int get_roi(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + ROI retval; + +#ifndef GOTTHARDD + functionNotImplemented(); +#else + // only get + retval = getROI(); + FILE_LOG(logDEBUG1, ("nRois: (%d, %d)\n", retval.xmin, retval.xmax)); +#endif + + Server_SendResult(file_des, INT32, UPDATE, NULL, 0); if (ret != FAIL) { - //retvalsize could be swapped during sendData - int nretval1 = nretval; - sendData(file_des, &nretval1, sizeof(nretval1), INT32); - int iloop = 0; - for(iloop = 0; iloop < nretval; ++iloop) { - sendData(file_des, &retval[iloop].xmin, sizeof(int), INT32); - sendData(file_des, &retval[iloop].xmax, sizeof(int), INT32); - sendData(file_des, &retval[iloop].ymin, sizeof(int), INT32); - sendData(file_des, &retval[iloop].ymax, sizeof(int), INT32); - } + sendData(file_des, &retval.xmin, sizeof(int), INT32); + sendData(file_des, &retval.xmax, sizeof(int), INT32); } return ret; } @@ -1974,7 +1942,6 @@ int set_roi(int file_des) { - int set_speed(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2208,11 +2175,6 @@ int send_update(int file_des) { n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); - // databytes - i32 = calculateDataBytes(); - n = sendData(file_des,&i32,sizeof(i32),INT32); - if (n < 0) return printSocketReadError(); - // settings #if defined(EIGERD) || defined(JUNGFRAUD) || defined(GOTTHARDD) i32 = (int)getSettings(); @@ -2285,20 +2247,9 @@ int send_update(int file_des) { // roi #if defined(GOTTHARDD) - ROI* retval = NULL; - ROI arg[1]; - int ret = OK, nretval = 0; - retval = setROI(-1, arg, &nretval, &ret); - //retvalsize could be swapped during sendData - int nretval1 = nretval; - sendData(file_des, &nretval1, sizeof(nretval1), INT32); - int iloop = 0; - for(iloop = 0; iloop < nretval; ++iloop) { - sendData(file_des, &retval[iloop].xmin, sizeof(int), INT32); - sendData(file_des, &retval[iloop].xmax, sizeof(int), INT32); - sendData(file_des, &retval[iloop].ymin, sizeof(int), INT32); - sendData(file_des, &retval[iloop].ymax, sizeof(int), INT32); - } + ROI retval = getROI(); + sendData(file_des, &retval.xmin, sizeof(int), INT32); + sendData(file_des, &retval.xmax, sizeof(int), INT32); #endif #if defined(CHIPTESTBOARDD) || defined(MOENCHD) @@ -2541,131 +2492,6 @@ int configure_mac(int file_des) { - - -int load_image(int file_des) { - ret = OK; - memset(mess, 0, sizeof(mess)); - int args[2] = {-1, -1}; - - if (receiveData(file_des, args, sizeof(args), INT32) < 0) - return printSocketReadError(); - - enum imageType index = args[0]; - int numChannels = args[1]; - short int imageVals[numChannels]; - memset(imageVals, 0, numChannels * sizeof(short int)); - if (numChannels > 0) { - if (receiveData(file_des, imageVals, numChannels * sizeof(short int), OTHER) < 0) { - return printSocketReadError(); - } - } - FILE_LOG(logDEBUG1, ("Loading %s image (ind:%d)\n", (index == DARK_IMAGE) ? "dark" : - ((index == GAIN_IMAGE) ? "gain" : "unknown"), index)); - -#ifndef GOTTHARDD - functionNotImplemented(); -#else - - // set only - if (Server_VerifyLock() == OK) { - switch (index) { - case DARK_IMAGE : - case GAIN_IMAGE : - // size of image does not match expected size - if (numChannels != (calculateDataBytes()/sizeof(short int))) { - ret = FAIL; - sprintf(mess, "Could not load image. " - "Number of Channels do not match. Expected %d, got %d\n", - calculateDataBytes(), numChannels); - FILE_LOG(logERROR,(mess)); - } else - loadImage(index, imageVals); - break; - default: - modeNotImplemented("Image index", (int)index); - break; - } - } -#endif - return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); -} - - - - - - -int read_counter_block(int file_des) { - ret = OK; - memset(mess, 0, sizeof(mess)); - int args[2] = {-1, -1}; - - if (receiveData(file_des, args, sizeof(args), INT32) < 0) - return printSocketReadError(); - int startACQ = args[0]; - int numChannels = args[1]; - short int retval[numChannels]; - memset(retval, 0, numChannels * sizeof(short int)); - FILE_LOG(logDEBUG1, ("Read counter block with start acq bit: %d\n", startACQ)); - -#ifndef GOTTHARDD - functionNotImplemented(); -#else - - // only set - if (Server_VerifyLock() == OK) { - // size of image does not match expected size - if (numChannels != (calculateDataBytes()/sizeof(short int))) { - ret = FAIL; - sprintf(mess, "Could not load image. " - "Number of Channels do not match. Expected %d, got %d\n", - calculateDataBytes(), numChannels); - FILE_LOG(logERROR,(mess)); - } else { - ret = readCounterBlock(startACQ, retval); - if (ret == FAIL) { - strcpy(mess, "Could not read counter block\n"); - FILE_LOG(logERROR,(mess)); - } - } - } -#endif - return Server_SendResult(file_des, OTHER, UPDATE, retval, numChannels * sizeof(short int)); -} - - - - - -int reset_counter_block(int file_des) { - ret = OK; - memset(mess, 0, sizeof(mess)); - int startACQ = -1; - - if (receiveData(file_des, &startACQ, sizeof(startACQ), INT32) < 0) - return printSocketReadError(); - FILE_LOG(logDEBUG1, ("Reset counter block with start acq bit: %d\n", startACQ)); - -#ifndef GOTTHARDD - functionNotImplemented(); -#else - // only set - if (Server_VerifyLock() == OK) { - ret = resetCounterBlock(startACQ); - if (ret == FAIL) { - strcpy(mess, "Could not reset counter block\n"); - FILE_LOG(logERROR, (mess)); - } - } -#endif - return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); -} - - - - - int enable_ten_giga(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h index 66ed015c7..7779308f2 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h @@ -1,6 +1,6 @@ #pragma once #include "sls_detector_defs.h" -#include "logger.h" +#include "clogger.h" enum numberMode {DEC, HEX}; #define GOODBYE (-200) @@ -27,7 +27,7 @@ int M_nofuncMode(int); int exec_command(int); int get_detector_type(int); int set_external_signal_flag(int); -int set_external_communication_mode(int); +int set_timing_mode(int); int get_id(int); int digital_test(int); int set_dac(int); @@ -49,6 +49,7 @@ int get_time_left(int); int set_dynamic_range(int); int set_readout_flags(int); int set_roi(int); +int get_roi(int); int set_speed(int); int exit_server(int); int lock_server(int); @@ -57,9 +58,6 @@ int set_port(int); int update_client(int); int send_update(int); int configure_mac(int); -int load_image(int); -int read_counter_block(int); -int reset_counter_block(int); int calibrate_pedestal(int); int enable_ten_giga(int); int set_all_trimbits(int); diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 3dd3b40ad..679646a37 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -6,10 +6,12 @@ #include class multiSlsDetector; +class detectorData; + namespace sls { using ns = std::chrono::nanoseconds; -using Positions = const std::vector &; -using defs = slsDetectorDefs; +class MacAddr; +class IpAddr; /** * \class Detector @@ -19,109 +21,1178 @@ class Detector { public: /** - * @param multi_id multi detector shared memory id + * @param shm_id detector shared memory id + * Default value is 0. Can be set to more values for + * multiple detectors.It is important only if you + * are controlling multiple detectors from the same pc. */ - Detector(int multi_id = 0); + Detector(int shm_id = 0); ~Detector(); - // Acquisition - - /** - * Blocking call, starts the receiver and detector. Acquired - * the number of frames set. - */ - void acquire(); - void startReceiver(Positions pos = {}); - void stopReceiver(Positions pos = {}); - - /** - * Get the acquiring flag. When true the detector blocks - * any attempt to start a new acquisition. - */ - bool getAcquiringFlag() const; - - /** - * Set the acquiring flag. This might have to done manually - * after an acquisition was aborted. - */ - void setAcquiringFlag(bool value); - - /** Read back the run status of the receiver */ - Result getReceiverStatus(Positions pos = {}); - - // Configuration - - /** - * Frees the shared memory of this detector and all modules - * belonging to it. - */ - void freeSharedMemory(); - void setConfig(const std::string &fname); - Result getHostname(Positions pos = {}) const; - // void setHostname(Positions pos = {}); - - Result getStartingFrameNumber(Positions pos = {}) const; - void setStartingFrameNumber(uint64_t value, Positions pos); - - // Bits and registers - - /** - * Clears (sets to 0) bit number bitnr in register at addr. - * @param addr address of the register - * @param bitnr bit number to clear - * @param pos detector position - */ - void clearBit(uint32_t addr, int bitnr, Positions pos = {}); - - /** - * Sets bit number bitnr in register at addr to 1 - * @param addr address of the register - * @param bitnr bit number to clear - * @param pos detector position - */ - void setBit(uint32_t addr, int bitnr, Positions pos = {}); - - /** - * Reads 32 bit register from detector - * @param addr address of the register - * @returns value read from register - */ - Result getRegister(uint32_t addr, Positions pos = {}); - /************************************************** * * - * FILE, anything concerning file writing or * - * reading goes here * + * CONFIGURATION * + * * + * ************************************************/ + + /* Free the shared memory of this detector and all modules + * belonging to it.*/ + void freeSharedMemory(); + + void loadConfig(const std::string &fname); + + Result getHostname(Positions pos = {}) const; + + /* Frees shared memory, adds detectors to the list + * and updates local detector cache */ + void setHostname(const std::vector &hostname); + + /** Gets shared memory ID */ + int getShmId() const; + + Result getFirmwareVersion(Positions pos = {}) const; + + Result getDetectorServerVersion(Positions pos = {}) const; + + Result getSerialNumber(Positions pos = {}) const; + + int64_t getClientVersion() const; + + Result getReceiverVersion(Positions pos = {}) const; + + Result getDetectorType(Positions pos = {}) const; + + /** Gets the total number of detectors */ + int size() const; + + defs::xy getModuleGeometry() const; + + Result getModuleSize(Positions pos = {}) const; + + /** Gets the actual full detector size. It is the same even if ROI changes + */ + defs::xy getDetectorSize() const; + + /** + * Sets the detector size in both dimensions. + * This value is used to calculate row and column positions for each module. + */ + void setDetectorSize(const defs::xy value); + + /** [Jungfrau][Gotthard] */ + Result getSettings(Positions pos = {}) const; + + /** [Jungfrau][Gotthard] */ + void setSettings(defs::detectorSettings value, Positions pos = {}); + + /************************************************** + * * + * Callbacks * * * * ************************************************/ /** - * Returns receiver file name prefix. The actual file name - * contains module id and file index as well. - * @param pos detector positions - * @returns file name prefix + * register callback for end of acquisition + * @param func function to be called with parameters: + * current progress in percentage, detector status, pArg pointer + * @param pArg pointer that is returned in call back */ - Result getFileName() const; + void registerAcquisitionFinishedCallback(void (*func)(double, int, void *), + void *pArg); /** - * Sets the receiver file name prefix - * @param fname file name prefix + * register callback for accessing reconstructed complete images + * Receiver sends out images via zmq, the client reconstructs them into + * complete images. Therefore, it also enables zmq streaming from receiver + * and the client. + * @param func function to be called for each image with parameters: + * detector data structure, frame number, sub frame number (for eiger in 32 + * bit mode), pArg pointer + * @param pArg pointer that is returned in call back */ - void setFileName(const std::string &fname); - Result getFilePath() const; - void setFilePath(const std::string &fname); + void registerDataCallback(void (*func)(detectorData *, uint64_t, uint32_t, + void *), + void *pArg); + + /************************************************** + * * + * Acquisition Parameters * + * * + * ************************************************/ + + Result getNumberOfFrames() const; + + void setNumberOfFrames(int64_t value); + + Result getNumberOfTriggers() const; + + void setNumberOfTriggers(int64_t value); + + Result getExptime(Positions pos = {}) const; + + void setExptime(ns t, Positions pos = {}); + + Result getPeriod(Positions pos = {}) const; + + void setPeriod(ns t, Positions pos = {}); + + /** [Gotthard][Jungfrau] */ + Result getDelayAfterTrigger(Positions pos = {}) const; + + /** [Gotthard][Jungfrau] */ + void setDelayAfterTrigger(ns value, Positions pos = {}); + + /** [Gotthard][Jungfrau][CTB] */ + Result getNumberOfFramesLeft(Positions pos = {}) const; + + /** [Gotthard][Jungfrau][CTB] */ + Result getNumberOfTriggersLeft(Positions pos = {}) const; + + /** [Gotthard][Jungfrau][CTB] */ + Result getDelayAfterTriggerLeft(Positions pos = {}) const; + + /** [Eiger][Jungfrau] */ + Result getSpeed(Positions pos = {}) const; + + /** [Eiger][Jungfrau] // TODO: create enum for speed + * Options: (0 full speed, 1 half speed, 2 quarter speed) + */ + void setSpeed(int value, Positions pos = {}); + + /** [Gotthard][Jungfrau][CTB] */ + Result getADCPhase(Positions pos = {}) const; + + /** [Gotthard][Jungfrau][CTB] */ + void setADCPhase(int value, Positions pos = {}); + + /** [Jungfrau][CTB] */ + Result getMaxADCPhaseShift(Positions pos = {}) const; + + /** [Gotthard][Jungfrau][CTB] */ + Result getADCPhaseInDegrees(Positions pos = {}) const; + + /** [Gotthard][Jungfrau][CTB] */ + void setADCPhaseInDegrees(int value, Positions pos = {}); + + Result getHighVoltage(Positions pos = {}) const; + + /** + * [Gotthard Options: 0, 90, 110, 120, 150, 180, 200] + * [Jungfrau, CTB Options: 0, 60 - 200] + * [Eiger Options: 0 - 200] + */ + void setHighVoltage(int value, Positions pos = {}); + + /** + * (Degrees) + * [Gotthard] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA + * [Jungfrau] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA + * [Eiger] Options: TEMPERATURE_FPGA, TEMPERATURE_FPGAEXT, TEMPERATURE_10GE, + * TEMPERATURE_DCDC, TEMPERATURE_SODL, TEMPERATURE_SODR, TEMPERATURE_FPGA2, + * TEMPERATURE_FPGA3 + * [CTB] Options: SLOW_ADC_TEMP + */ + Result getTemperature(defs::dacIndex index, Positions pos = {}) const; + + Result getDAC(defs::dacIndex index, bool mV, Positions pos = {}) const; + + void setDAC(int value, defs::dacIndex index, bool mV, Positions pos = {}); + + Result getTimingMode(Positions pos = {}) const; + + /** + * [Gotthard, Jungfrau, CTB Options: AUTO_TIMING, TRIGGER_EXPOSURE] + * [Eiger Options: AUTO_TIMING, TRIGGER_EXPOSURE, GATED, BURST_TRIGGER] + */ + void setTimingMode(defs::timingMode value, Positions pos = {}); + + /************************************************** + * * + * ACQUISITION * + * * + * ************************************************/ + /** + * Blocking call, starts the receiver and detector. + * Increments file index if file write enabled. + * Acquired the number of frames set. + */ + void acquire(); + + /** Non blocking + * Starts the reciever (if enabled) and then the detector + * You have to check detector status until it is idle before you call + * stopACquisition + * + */ + void startAcquisition(); + + /** + * Stops detector acquisition and then receiver (if enabled) + * If no receiver enabled, you can skip this for normal acquisition (no + * abort) + */ + void stopAcquisition(); + + /** + * Clears the acquiring flag. This has to be done manually + * after an acquisition was aborted. + */ + void clearAcquiringFlag(); + + Result getDetectorStatus(Positions pos = {}) const; + + Result getReceiverStatus(Positions pos = {}) const; + + Result getFramesCaught(Positions pos = {}) const; + + /** [Eiger][Jungfrau] */ + Result getStartingFrameNumber(Positions pos = {}) const; + + /** [Eiger][Jungfrau] */ + void setStartingFrameNumber(uint64_t value, Positions pos); + + /** [Eiger] Sends an internal software trigger to the detector */ + void sendSoftwareTrigger(Positions pos = {}); + + // TODO: remove resetframescaught in receiver + + /************************************************** + * * + * Network Configuration (Detector<->Receiver) * + * * + * ************************************************/ + + /** Configures the destination for UDP packets in the detector + * Needed only if you use a custom receiver (not slsReceiver) + * as it is already included in setReceiverHostname. + */ + void configureMAC(Positions pos = {}); // TODO: find a reasonable name + + /** [Jungfrau] */ + Result getNumberofUDPInterfaces(Positions pos = {}) const; + + /** [Jungfrau] Also restarts client and receiver sockets */ + void setNumberofUDPInterfaces(int n, Positions pos = {}); + + /** [Jungfrau] */ + Result getSelectedUDPInterface(Positions pos = {}) const; + + /** + * [Jungfrau: + * Effective only when number of interfaces is 1. + * Options: 0 (outer, default), 1(inner)] //TODO: enum? + */ + void selectUDPInterface(int interface, Positions pos = {}); + + Result getSourceUDPIP(Positions pos = {}) const; + + /* For Eiger 1G, the detector will replace with its own DHCP IP + * 10G Eiger and other detectors, the source UDP IP must be in the + * same subnet of the destination UDP IP + */ + void setSourceUDPIP(const std::string &ip, Positions pos = {}); + + /** [Jungfrau] bottom half */ + Result getSourceUDPIP2(Positions pos = {}) const; + + /** [Jungfrau] bottom half */ + void setSourceUDPIP2(const std::string &ip, Positions pos = {}); + + Result getSourceUDPMAC(Positions pos = {}) const; + + /* For Eiger 1G, the detector will replace with its own DHCP MAC + * For Eiger 10G, the detector will replace with its own DHCP MAC + 1 + * Others can be anything (beware of certain bits) + */ + + void setSourceUDPMAC(const std::string &mac, Positions pos = {}); + + /** [Jungfrau] bottom half */ + Result getSourceUDPMAC2(Positions pos = {}) const; + + /** [Jungfrau] bottom half */ + void setSourceUDPMAC2(const std::string &mac, Positions pos = {}); + + Result getDestinationUDPIP(Positions pos = {}) const; + + /** IP of the interface in receiver that the detector sends data to */ + void setDestinationUDPIP(const std::string &ip, Positions pos = {}); + + /** [Jungfrau bottom half] */ + Result getDestinationUDPIP2(Positions pos = {}) const; + + /** [Jungfrau bottom half] */ + void setDestinationUDPIP2(const std::string &ip, Positions pos = {}); + + Result getDestinationUDPMAC(Positions pos = {}) const; + + /** MAC of the interface in receiver that the detector sends data to + * Only needed if you use a custom receiver (not slsReceiver) + * Must be followed by configuremac. + */ + void setDestinationUDPMAC(const std::string &mac, Positions pos = {}); + + /** [Jungfrau bottom half] */ + Result getDestinationUDPMAC2(Positions pos = {}) const; + + /** [Jungfrau bottom half] */ + void setDestinationUDPMAC2(const std::string &mac, Positions pos = {}); + + Result getDestinationUDPPort(Positions pos = {}) const; + + /** module_id is -1 for all detectors, ports for each module is calculated + * (increments) */ + // TODO if Parallel takes a vector, can send multiple vaues to set in + // slsdetector.cp + void setDestinationUDPPort(int port, int module_id = -1); + + /** [Eiger right port][Jungfrau bottom half] */ + Result getDestinationUDPPort2(Positions pos = {}) const; + + /** [Eiger right port][Jungfrau bottom half] + * module_id is -1 for all detectors, ports for each module is calculated + * (increments) + */ + void setDestinationUDPPort2(int port, int module_id = -1); + + Result printRxConfiguration(Positions pos = {}) const; + + /** [Eiger][CTB] */ + Result getTenGiga(Positions pos = {}) const; + + /** [Eiger][CTB] */ + void setTenGiga(bool enable, Positions pos = {}); + + /** [Eiger, Jungfrau] */ + Result getTenGigaGFlowControl(Positions pos = {}) const; + + /** [Eiger, Jungfrau] */ + void setTenGigaGFlowControl(bool enable, Positions pos = {}); + + /** [Eiger, Jungfrau] */ + Result getTransmissionDelayFrame(Positions pos = {}) const; + + /** + * [Jungfrau]: Sets the transmission delay of the first UDP packet being + * streamed out of the module. Options: 0 - 31, each value represenets 1 ms + * [Eiger]: Sets the transmission delay of entire frame streamed out for + * both left and right UDP ports. Options: //TODO possible values + */ + void setTransmissionDelayFrame(int value, Positions pos = {}); + + /** [Eiger] */ + Result getTransmissionDelayLeft(Positions pos = {}) const; + + /** + * [Eiger] + * Sets the transmission delay of first packet streamed out of the left UDP + * port + */ + void setTransmissionDelayLeft(int value, Positions pos = {}); + + /** [Eiger] */ + Result getTransmissionDelayRight(Positions pos = {}) const; + + /** + * [Eiger] + * Sets the transmission delay of first packet streamed ut of the right UDP + * port + */ + void setTransmissionDelayRight(int value, Positions pos = {}); + + /************************************************** + * * + * RECEIVER CONFIG * + * * + * ************************************************/ + + /** true when slsReceiver is used */ + Result getUseReceiverFlag(Positions pos = {}) const; + + Result getRxHostname(Positions pos = {}) const; + + /** + * Validates and sets the receiver. + * Updates local receiver cache parameters + * Configures the detector to the receiver as UDP destination + * @param receiver receiver hostname or IP address + */ + void setRxHostname(const std::string &receiver, Positions pos = {}); + + Result getRxPort(Positions pos = {}) const; + + /** Receiver TCP port (for client communication with Receiver) */ + void setRxPort(int value, Positions pos = {}); + + Result getRxFifoDepth(Positions pos = {}) const; + + /** fifo between udp listening and processing threads */ + void setRxFifoDepth(int nframes, Positions pos = {}); + + Result getRxSilentMode(Positions pos = {}) const; + + /** receiver prints hardly any information while acquiring */ + void setRxSilentMode(bool value, Positions pos = {}); + + Result + getRxFrameDiscardPolicy(Positions pos = {}) const; + + /** + * default NO_DISCARD + * Options: NO_DISCARD, DISCARD_EMPTY_FRAMES, DISCARD_PARTIAL_FRAMES + * discard partial frames is the fastest + */ + void setRxFrameDiscardPolicy(defs::frameDiscardPolicy f, + Positions pos = {}); + + Result getPartialFramesPadding(Positions pos = {}) const; + + /** padding enabled. Disabling padding is the fastest */ + void setPartialFramesPadding(bool value, Positions pos = {}); + + Result getRxUDPSocketBufferSize(Positions pos = {}) const; + + void setRxUDPSocketBufferSize(int64_t udpsockbufsize, Positions pos = {}); + /** TODO: + * Linux kernel allocates twice the amount you set for bookkeeping purposes + */ + Result getRxRealUDPSocketBufferSize(Positions pos = {}) const; + + Result getRxLock(Positions pos = {}); + + /** locks receiver server to client IP */ + void setRxLock(bool value, Positions pos = {}); + + Result getRxLastClientIP(Positions pos = {}) const; + + /************************************************** + * * + * FILE * + * * + * ************************************************/ + Result getFileFormat(Positions pos = {}) const; + + /** default binary, Options: BINARY, HDF5 (library must be compiled with + * this option) */ + void setFileFormat(defs::fileFormat f, Positions pos = {}); + + Result getFilePath(Positions pos = {}) const; + + void setFilePath(const std::string &fname, Positions pos = {}); + + Result getFileNamePrefix(Positions pos = {}) const; + + /** default run + * File Name: [file name prefix]_d[module index]_f[file index]_[acquisition + * index].[file format] eg. run_d0_f0_5.raw + */ + void setFileNamePrefix(const std::string &fname, Positions pos = {}); + + Result getAcquisitonIndex(Positions pos = {}) const; + + void setAcquisitionIndex(int i, Positions pos = {}); + Result getFileWrite(Positions pos = {}) const; + + /** default writes */ void setFileWrite(bool value, Positions pos = {}); + + Result getMasterFileWrite(Positions pos = {}) const; + + /* default writes */ + void setMasterFileWrite(bool value, Positions pos = {}); + Result getFileOverWrite(Positions pos = {}) const; + + /** default overwites */ void setFileOverWrite(bool value, Positions pos = {}); - // Time - Result getExptime(Positions pos = {}) const; - void setExptime(ns t, Positions pos = {}); + Result getFramesPerFile(Positions pos = {}) const; + + /** 0 will set frames per file to unlimited */ + void setFramesPerFile(int n, Positions pos = {}); + + /************************************************** + * * + * ZMQ Streaming Parameters (Receiver<->Client)* + * * + * ************************************************/ + // TODO callback functions + + Result getRxZmqDataStream(Positions pos = {}) const; + + void setRxZmqDataStream(bool value, Positions pos = {}); + + Result getRxZmqFrequency(Positions pos = {}) const; + + /** @param freq nth frame streamed out of receiver. + * If 0, streaming timer is the timeout, + * after which current frame sent out. Default is 0 at 200 ms. + * Default is 1: send every frame. + * If you want just to see some frames for gui purposes, set to 0 (200ms + * default timer). + */ + void setRxZmqFrequency(int freq, Positions pos = {}); + + Result getRxZmqTimer(Positions pos = {}) const; + + /** + * If receiver streaming frequency is 0 (default), then this timer between + * each data stream is set. Default is 200 ms. + */ + void setRxZmqTimer(int time_in_ms, Positions pos = {}); + + Result getRxZmqPort(Positions pos = {}) const; + + /** + * module_id is -1 for all detectors, ports for each module is calculated + * (increments) Restarts receiver zmq sockets only if it was already enabled + */ + void setRxZmqPort(int port, int module_id = -1); + + Result getRxZmqIP(Positions pos = {}) const; + + void setRxZmqIP(const std::string &ip, Positions pos = {}); + + Result getClientZmqPort(Positions pos = {}) const; + + /** + * Needed only when using the client call back to get reconstructed data + * from multi modules module_id is -1 for all detectors, ports for each + * module is calculated (increments) Restarts client zmq sockets oonly if it + * was already enabled + */ + void setClientZmqPort(int port, int module_id = -1); + + Result getClientZmqIp(Positions pos = {}) const; + + void setClientZmqIp(const std::string &ip, Positions pos = {}); + + /************************************************** + * * + * Eiger Specific * + * * + * ************************************************/ + + Result getDynamicRange(Positions pos = {}) const; + + /** + * [Eiger] + * Options: 4, 8, 16, 32 + * If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to 1 + */ + void setDynamicRange(int value); + + /** [Eiger] in 32 bit mode */ Result getSubExptime(Positions pos = {}) const; + + /** [Eiger] in 32 bit mode */ void setSubExptime(ns t, Positions pos = {}); - Result getPeriod(Positions pos = {}) const; - void setPeriod(ns t, Positions pos = {}); + + /** [Eiger] in 32 bit mode */ + Result getSubDeadTime(Positions pos = {}) const; + + /** [Eiger] in 32 bit mode */ + void setSubDeadTime(ns value, Positions pos = {}); + + /** [Eiger] */ + Result getThresholdEnergy(Positions pos = {}) const; + + /** [Eiger] */ + void setThresholdEnergy(int threshold_ev, + defs::detectorSettings settings = defs::STANDARD, + bool trimbits = true, Positions pos = {}); + + /** [Eiger] */ + Result getSettingsDir(Positions pos = {}) const; + + /** [Eiger] */ + void setSettingsDir(const std::string &value, Positions pos = {}); + + /** [Eiger] */ + void loadTrimbits(const std::string &fname, Positions pos = {}); + + /**[Eiger] */ + Result getRxAddGapPixels(Positions pos = {}) const; + + /** + * [Eiger] + * 4 bit mode not implemented in Receiver, but in client data call back + * Fills in gap pixels in data + */ + void setRxAddGapPixels(bool enable); + + /** [Eiger] */ + Result getParallelMode(Positions pos = {}) const; + + /** [Eiger] */ + void setParallelMode(bool value, Positions pos = {}); + + /** [Eiger] */ + Result getOverFlowMode(Positions pos = {}) const; + + /** [Eiger] */ + void setOverFlowMode(bool value, Positions pos = {}); + + /** [Eiger] */ + Result getBottom(Positions pos = {}) const; + + /** [Eiger] for client call back (gui) purposes */ + void setBottom(bool value, Positions pos = {}); + + /** [Eiger] -1 if they are all different */ + Result getAllTrimbits(Positions pos = {}) const; + + /**[Eiger] */ + void setAllTrimbits(int value, Positions pos = {}); + + /**[Eiger] Returns energies in eV where the module is trimmed */ + Result> getTrimEnergies(Positions pos = {}) const; + + /** [Eiger] Set the energies where the detector is trimmed */ + void setTrimEnergies(std::vector energies, Positions pos = {}); + + /** [Eiger] deadtime in ns, 0 = disabled */ + Result getRateCorrection(Positions pos = {}) const; + + /** //TODO: default, get, set + * [Eiger] Set Rate correction + * 0 disable correction, < 0: default dead time from trimbit file, > 0 + * custom deadtime (advanced) + */ + void setRateCorrection(ns dead_time, Positions pos = {}); + + /** [Eiger] */ + Result getPartialReadout(Positions pos = {}) const; + + /** [Eiger] Number of lines to read out per half module + * Options: 0 - 256. Depending on dynamic range and + * 10 GbE enabled, only specific values are accepted. + */ + void setPartialReadout(const int lines, Positions pos = {}); + + /** [Eiger] */ + Result getInterruptSubframe(Positions pos = {}) const; + + /** [Eiger] when set, the last subframe is interrupted at end of acq */ + void setInterruptSubframe(const bool enable, Positions pos = {}); + + /** [Eiger] minimum two frames */ + Result getMeasuredPeriod(Positions pos = {}) const; + + /** [Eiger] */ + Result getMeasuredSubFramePeriod(Positions pos = {}) const; + + /** [Eiger] */ + Result getActive(Positions pos = {}) const; + + /** [Eiger] */ + void setActive(bool active, Positions pos = {}); + + /** [Eiger] */ + Result getRxPadDeactivatedMode(Positions pos = {}) const; + + /** [Eiger] Pad deactivated modules in receiver */ + void setRxPadDeactivatedMode(bool pad, Positions pos = {}); + + /** [Eiger] Advanced */ + Result getPartialReset(Positions pos = {}) const; + + /** [Eiger] Advanced + * used for pulsing chips */ + void setPartialReset(bool enable, Positions pos = {}); + + /** [Eiger] Advanced + * Pulse Pixel n times at x and y coordinates */ + void pulsePixel(int n, defs::xy pixel, Positions pos = {}); + + /** [Eiger] Advanced + * Pulse Pixel n times and move by a relative value of x and y + * coordinates */ + void pulsePixelNMove(int n, defs::xy pixel, Positions pos = {}); + + /** [Eiger] Advanced + * Pulse chip n times */ + void pulseChip(int n, Positions pos = {}); + + /** [Eiger] with specific quad hardware */ + Result getQuad(Positions pos = {}) const; + + /** [Eiger] with specific quad hardware */ + void setQuad(const bool enable); + + /************************************************** + * * + * Jungfrau Specific * + * * + * ************************************************/ + + /** [Jungfrau] */ + Result getThresholdTemperature(Positions pos = {}) const; + + /** + * [Jungfrau]Set threshold temperature + * If temperature crosses threshold temperature + * and temperature control is enabled, + * power to chip will be switched off and + * temperature event will be set + * @param val value in degrees + */ + void setThresholdTemperature(int temp, Positions pos = {}); + + /** [Jungfrau] */ + Result getTemperatureControl(Positions pos = {}) const; + + /** [Jungfrau] */ + void setTemperatureControl(bool enable, Positions pos = {}); + + /** [Jungfrau] */ + Result getTemperatureEvent(Positions pos = {}) const; + + /** [Jungfrau] */ + void resetTemperatureEvent(Positions pos = {}); + + /** [Jungfrau] */ + Result getPowerChip(Positions pos = {}) const; + + /** [Jungfrau] */ + void setPowerChip(bool on, Positions pos = {}); + + /** [Jungfrau] */ + Result getAutoCompDisable(Positions pos = {}) const; + + /** [Jungfrau] Advanced + * //TODO naming + * By default, the on-chip gain switching is active during the entire + * exposure. This mode disables the on-chip gain switching comparator + * automatically after 93.75% of exposure time (only for longer than 100us). + */ + void setAutoCompDisable(bool value, Positions pos = {}); + + /** [Jungfrau] Advanced TODO naming */ + Result getNumberOfAdditionalStorageCells() const; + + /** [Jungfrau] Advanced */ + void setNumberOfAdditionalStorageCells(int64_t value); + + /** [Jungfrau] Advanced */ + Result getStorageCellStart(Positions pos = {}) const; + + /** [Jungfrau] Advanced. Sets the storage cell storing the first acquisition + * of the series. Options: 0-15 + */ + void setStoragecellStart(int cell, Positions pos = {}); + + /** [Jungfrau] Advanced*/ + Result getStorageCellDelay(Positions pos = {}) const; + + /** [Jungfrau] Advanced + * Options: (0-1638375 ns (resolution of 25ns) */ + void setStorageCellDelay(ns value, Positions pos = {}); + + /************************************************** + * * + * Gotthard Specific * + * * + * ************************************************/ + + /** [Gotthard]*/ + Result getROI(Positions pos = {}) const; + + /** + * [Gotthard] + * Options: Only a single ROI per module + * Can set only a single ROI at a time + * @param module position index + */ + void setROI(defs::ROI value, int moduleId); + + /** [Gotthard] TODO: check with jiaguo if he needs any of these functions // + * TODO remove */ + Result getExptimeLeft(Positions pos = {}) const; + + /** [Gotthard] TODO remove */ + Result getPeriodLeft(Positions pos = {}) const; + + /** [Gotthard] */ + Result + getExternalSignalFlags(Positions pos = {}) const; + + /** [Gotthard] Options: TRIGGER_IN_RISING_EDGE, TRIGGER_IN_FALLING_EDGE */ + void setExternalSignalFlags(defs::externalSignalFlag value, + Positions pos = {}); + + /** [Gotthard] */ + Result getImageTestMode(Positions pos = {}); + + /** [Gotthard] If 1, adds channel intensity with precalculated values. + * Default is 0 */ + Result setImageTestMode(const int value, Positions pos = {}); + + /************************************************** + * * + * CTB Specific * + * * + * ************************************************/ + + /** [CTB] */ + Result getNumberOfAnalogSamples(Positions pos = {}) const; + + /** [CTB] */ + void setNumberOfAnalogSamples(int64_t value, Positions pos = {}); + + /** [CTB] */ + Result getNumberOfDigitalSamples(Positions pos = {}) const; + + /** [CTB] */ + void setNumberOfDigitalSamples(int64_t value, Positions pos = {}); + + /** [CTB] */ + Result getReadoutMode(Positions pos = {}) const; + + /** [CTB] Options: NORMAL_READOUT = 0, DIGITAL_ONLY = 1, ANALOG_AND_DIGITAL + * //TODO ANALOG_ONLY, make enum = 2 */ + void setReadoutMode(int value, Positions pos = {}); + + /** [CTB] */ + Result getDBITPhase(Positions pos = {}) const; + + /** [CTB] */ + void setDBITPhase(int value, Positions pos = {}); + + /** [CTB] */ + Result getMaxDBITPhaseShift(Positions pos = {}) const; + + /** [CTB] */ + Result getDBITPhaseInDegrees(Positions pos = {}) const; + + /** [CTB] */ + void setDBITPhaseInDegrees(int value, Positions pos = {}); + + /** [CTB] */ + Result getADCClock(Positions pos = {}) const; + + /** [CTB] */ + void setADCClock(int value_in_MHz, Positions pos = {}); + + /** [CTB] */ + Result getDBITClock(Positions pos = {}) const; + + /** [CTB] */ + void setDBITClock(int value_in_MHz, Positions pos = {}); + + /** [CTB] */ + Result getRUNClock(Positions pos = {}) const; + + /** [CTB] */ + void setRUNClock(int value_in_MHz, Positions pos = {}); + + /** [CTB] */ + Result getSYNCClock(Positions pos = {}) const; + + /** [CTB] */ + Result getADCPipeline(Positions pos = {}) const; + + /** [CTB] */ + void setADCPipeline(int value, Positions pos = {}); + + /** [CTB] */ + Result getDBITPipeline(Positions pos = {}) const; + + /** [CTB] */ + void setDBITPipeline(int value, Positions pos = {}); + + /** [CTB] */ + Result getVrefVoltage(bool mV, Positions pos = {}) const; + + /** [CTB] */ + void setVrefVoltage(int value, bool mV, Positions pos = {}); + + /** [CTB] */ + Result getVoltage(defs::dacIndex index, Positions pos = {}) const; + + /** + * [CTB] mV + * Options: V_LIMIT, V_POWER_A, V_POWER_B, V_POWER_C, + * V_POWER_D, V_POWER_IO, V_POWER_CHIP + */ + void setVoltage(int value, defs::dacIndex index, Positions pos = {}); + + /** + * [CTB] mV + * Options: V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, V_POWER_IO, + * V_POWER_CHIP + */ + Result getMeasuredVoltage(defs::dacIndex index, + Positions pos = {}) const; + + /** + * [CTB] mA + * Options: I_POWER_A, I_POWER_B, I_POWER_C, I_POWER_D, I_POWER_IO + */ + Result getMeasuredCurrent(defs::dacIndex index, + Positions pos = {}) const; + + /** [CTB] Options: SLOW_ADC0 - SLOW_ADC7 */ + Result getSlowADC(defs::dacIndex index, Positions pos = {}) const; + + /** [CTB]*/ + Result getADCEnableMask(Positions pos = {}) const; + + /** [CTB]*/ + void setADCEnableMask(uint32_t mask, Positions pos = {}); + + /** [CTB] */ + Result getADCInvert(Positions pos = {}) const; + + /** [CTB]*/ + void setADCInvert(uint32_t value, Positions pos = {}); + + /** [CTB] */ + Result getExternalSamplingSource(Positions pos = {}) const; + + /** [CTB] Value between 0-63 */ + void setExternalSamplingSource(int value, Positions pos = {}); + + /** [CTB] */ + Result getExternalSampling(Positions pos = {}) const; + + /** [CTB] */ + void setExternalSampling(bool value, Positions pos = {}); + + /** [CTB] */ + Result> getRxDbitList(Positions pos = {}) const; + + /** [CTB] list contains the set of bits (0-63) to save */ + void setRxDbitList(std::vector list, Positions pos = {}); + + /** [CTB] */ + Result getRxDbitOffset(Positions pos = {}) const; + + /** [CTB] Set number of bytes of digital data to skip in the Receiver */ + void setRxDbitOffset(int value, Positions pos = {}); + + /** + * [CTB] Set Digital IO Delay + * cannot get + * @param digital IO mask to select the pins + * @param delay delay in ps(1 bit=25ps, max of 775 ps) + */ + void setDigitalIODelay(uint64_t pinMask, int delay, Positions pos = {}); + + /** [CTB] */ + Result getLEDEnable(Positions pos = {}) const; + + /** [CTB] */ + void setLEDEnable(bool enable, Positions pos = {}); + + /************************************************** + * * + * PATTERN * + * * + * ************************************************/ + + /** [CTB] */ + void setPattern(const std::string &fname, Positions pos = {}); + + /** [CTB] */ + Result getPatternIOControl(Positions pos = {}) const; + + /** [CTB] */ + void setPatternIOControl(uint64_t word, Positions pos = {}); + + /** [CTB] */ + Result getPatternClockControl(Positions pos = {}) const; + + /** [CTB] */ + void setPatternClockControl(uint64_t word, Positions pos = {}); + + /** [CTB] Caution: If word is -1 reads the addr (same as + * executing the pattern) */ + void setPatternWord(int addr, uint64_t word, Positions pos = {}); + + /**[CTB] Options: level: -1 (complete pattern) and 0-2 levels + * @returns array of start address, stop address and number of loops + */ + Result> getPatternLoops(int level, + Positions pos = {}) const; + + /** [CTB] Options: start, stop, n : 0-2 + * level: -1 (complete pattern) and 0-2 levels */ + void setPatternLoops(int level, int start, int stop, int n, + Positions pos = {}); + + /* [CTB] */ + Result getPatternWaitAddr(int level, Positions pos = {}) const; + + /** [CTB] Options: level 0-2 */ + void setPatternWaitAddr(int level, int addr, Positions pos = {}); + + /** [CTB] */ + Result getPatternWaitTime(int level, Positions pos = {}) const; + + /** [CTB] Options: level 0-2 */ + void setPatternWaitTime(int level, uint64_t t, Positions pos = {}); + + /** [CTB] */ + Result getPatternMask(Positions pos = {}); + + /** [CTB] Sets the mask applied to every pattern to the selected bit mask */ + void setPatternMask(uint64_t mask, Positions pos = {}); + + /** [CTB] */ + Result getPatternBitMask(Positions pos = {}) const; + + /** [CTB] Sets the bitmask that the mask will be applied to for every + * pattern + */ + void setPatternBitMask(uint64_t mask, Positions pos = {}); + + /************************************************** + * * + * Moench * + * * + * ************************************************/ + + /** [Moench] */ + Result getAdditionalJsonHeader(Positions pos = {}) const; + + /** [Moench] */ + void setAdditionalJsonHeader(const std::string &jsonheader, + Positions pos = {}); + + /** [Moench] */ + Result getAdditionalJsonParameter(const std::string &key, + Positions pos = {}) const; + /** + * [Moench] + * Sets the value for additional json header parameter if found, + * else appends the parameter key and value + * The value cannot be empty + */ + void setAdditionalJsonParameter(const std::string &key, + const std::string &value, + Positions pos = {}); + + /** [Moench] TODO! How do we do this best??? Can be refactored to something + * else? Use a generic zmq message passing system... + * For now limiting to all detectors working the same*/ + /** [Moench: -1 if not found or cannot convert to int] */ + Result getDetectorMinMaxEnergyThreshold(const bool isEmax, + Positions pos = {}) const; + + /** [Moench] */ + void setDetectorMinMaxEnergyThreshold(const bool isEmax, const int value, + Positions pos = {}); + + /** [Moench: -1 if unknown mode] */ + Result getFrameMode(Positions pos = {}) const; + + /** [Moench] */ + void setFrameMode(defs::frameModeType value, Positions pos = {}); + + /** [Moench: -1 if unknown mode] */ + Result getDetectorMode(Positions pos = {}) const; + + /** [Moench] */ + void setDetectorMode(defs::detectorModeType value, Positions pos = {}); + + /************************************************** + * * + * Advanced * + * * + * ************************************************/ + + /** [Jungfrau][CTB] */ + void programFPGA(const std::string &fname, Positions pos = {}); + + /** [Jungfrau][CTB] */ + void resetFPGA(Positions pos = {}); + + /** [Jungfrau][Gotthard][CTB] + * Copy detector server fname from tftp folder of hostname to detector + * Also changes respawn server, which is effective after a reboot. + */ + void copyDetectorServer(const std::string &fname, + const std::string &hostname, Positions pos = {}); + + /** [Jungfrau][Gotthard][CTB] */ + void rebootController(Positions pos = {}); + + /** + * [Jungfrau][Gotthard][CTB] + * Updates the firmware, detector server and then reboots detector + * controller blackfin. + * @param sname name of detector server binary found on tftp folder of host + * pc + * @param hostname name of pc to tftp from + * @param fname programming file name + * @param pos detector positions + */ + void updateFirmwareAndServer(const std::string &sname, + const std::string &hostname, + const std::string &fname, Positions pos = {}); + + Result readRegister(uint32_t addr, Positions pos = {}) const; + + void writeRegister(uint32_t addr, uint32_t val, Positions pos = {}); + + void setBit(uint32_t addr, int bitnr, Positions pos = {}); + + void clearBit(uint32_t addr, int bitnr, Positions pos = {}); + + /** [Gotthard][Jungfrau][CTB] */ + Result executeFirmwareTest(Positions pos = {}); + + /** [Gotthard][Jungfrau][CTB] */ + Result executeBusTest(Positions pos = {}); + + /** [Gotthard][Jungfrau][CTB] not possible to read back*/ + void writeAdcRegister(uint32_t addr, uint32_t value, Positions pos = {}); + + /************************************************** + * * + * Insignificant * + * * + * ************************************************/ + + Result getControlPort(Positions pos = {}) const; + + /** Detector Control TCP port (for client communication with Detector + * control server) */ + void setControlPort(int value, Positions pos = {}); + + Result getStopPort(Positions pos = {}) const; + + /** Detector Stop TCP port (for client communication with Detector Stop + * server) */ + void setStopPort(int value, Positions pos = {}); + + Result getDetectorLock(Positions pos = {}) const; + + void setDetectorLock(bool lock, Positions pos = {}); + + /** Get last client IP saved on detector server */ + Result getLastClientIP(Positions pos = {}) const; + + /** Execute a command on the detector server console */ + void executeCommand(const std::string &value, Positions pos = {}); + + /** [Gotthard][Jungfrau][CTB] */ + Result getNumberOfFramesFromStart(Positions pos = {}) const; + + /** [Jungfrau][CTB] Get time from detector start */ + Result getActualTime(Positions pos = {}) const; + + /** [Jungfrau][CTB] Get timestamp at a frame start */ + Result getMeasurementTime(Positions pos = {}) const; + + std::string getUserDetails() const; + + Result getRxCurrentFrameIndex(Positions pos = {}) const; + + private: + std::vector getPortNumbers(int start_port); }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/include/Result.h b/slsDetectorSoftware/include/Result.h index ea9b810d8..08386677c 100644 --- a/slsDetectorSoftware/include/Result.h +++ b/slsDetectorSoftware/include/Result.h @@ -31,33 +31,34 @@ template > class Result { Result() = default; Result(std::initializer_list list) : vec(list){}; - - /** Custom constructor from integer type to Result */ + /** Custom constructor from integer type to Result or Result */ template ::value && - std::is_same::value>::type> - Result(const std::vector &from) { - + (std::is_same::value || + std::is_same::value)>::type> + Result(const Result &from) { vec.reserve(from.size()); for (const auto &item : from) vec.push_back(T(item)); } - /** Custom constructor from integer type to Result */ + /** Custom constructor from integer type to Result or Result */ template ::value && - std::is_same::value>::type> - Result(std::vector &from) { + (std::is_same::value || + std::is_same::value)>::type> + Result(Result &from) { vec.reserve(from.size()); for (const auto &item : from) vec.push_back(T(item)); } - /** Custom constructor from integer type to Result */ + /** Custom constructor from integer type to Result or Result */ template ::value && - std::is_same::value>::type> - Result(std::vector &&from) { + (std::is_same::value || + std::is_same::value)>::type> + Result(Result &&from) { vec.reserve(from.size()); for (const auto &item : from) vec.push_back(T(item)); @@ -89,6 +90,7 @@ template > class Result { auto empty() const noexcept -> decltype(vec.empty()) { return vec.empty(); } auto front() -> decltype(vec.front()) { return vec.front(); } auto front() const -> decltype(vec.front()) { return vec.front(); } + void reserve(size_type new_cap) { vec.reserve(new_cap); } template auto push_back(V value) -> decltype(vec.push_back(value)) { @@ -104,11 +106,23 @@ template > class Result { */ T squash() const { return Squash(vec); } + /** + * If all elements are equal it returns the front value + * otherwise throws an exception with custom message provided + */ + T tsquash(const std::string &error_msg) { + if (equal()) + return vec.front(); + else + throw RuntimeError(error_msg); + } /** * If all elements are equal return the front value, otherwise * return the supplied default value */ - T squash(T default_value) const { return Squash(vec, default_value); } + T squash(const T &default_value) const { + return Squash(vec, default_value); + } /** Test whether all elements of the result are equal */ bool equal() const noexcept { return allEqual(vec); } diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index ef9908af7..f486d0010 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1,5 +1,6 @@ #pragma once +#include "Result.h" #include "SharedMemory.h" #include "logger.h" #include "sls_detector_defs.h" @@ -15,11 +16,11 @@ class detectorData; #include #include -#define MULTI_SHMVERSION 0x190726 +#define MULTI_SHMAPIVERSION 0x190809 +#define MULTI_SHMVERSION 0x190814 #define SHORT_STRING_LENGTH 50 #define DATE_LENGTH 30 - #include #include /** @@ -46,43 +47,17 @@ struct sharedMultiSlsDetector { /** number of sls detectors in shared memory */ int numberOfDetectors; + /** multi detector type */ + slsDetectorDefs::detectorType multiDetectorType; + /** END OF FIXED PATTERN * -----------------------------------------------*/ /** Number of detectors operated at once */ - int numberOfDetector[2]; + slsDetectorDefs::xy numberOfDetector; - /** size of the data that are transfered from all detectors */ - int dataBytes; - - /** data bytes including gap pixels transferred from all detectors */ - int dataBytesInclGapPixels; - - /** total number of channels for all detectors */ - int numberOfChannels; - - /** total number of channels for all detectors in one dimension*/ - int numberOfChannel[2]; - - /** total number of channels including gap pixels in one dimension */ - int numberOfChannelInclGapPixels[2]; - - /** total number of channels for all detectors */ - int maxNumberOfChannels; - - /** max number of channels for all detectors in one dimension*/ - int maxNumberOfChannel[2]; - - /** max number of channels including gap pixels for all detectors in - * one dimension*/ - int maxNumberOfChannelInclGapPixels[2]; - - /** max number of channels allowed for the complete set of detectors in - * one dimension */ - int maxNumberOfChannelsPerDetector[2]; - - /** timer values */ - int64_t timerValue[slsDetectorDefs::timerIndex::MAX_TIMERS]; + /** max number of channels for complete detector*/ + slsDetectorDefs::xy numberOfChannels; /** flag for acquiring */ bool acquiringFlag; @@ -110,11 +85,12 @@ class multiSlsDetector : public virtual slsDetectorDefs { template struct NonDeduced { using type = CT; }; template - std::vector Parallel(RT (slsDetector::*somefunc)(CT...), + sls::Result Parallel(RT (slsDetector::*somefunc)(CT...), std::vector positions, typename NonDeduced::type... Args) { - if (positions.empty() || (positions.size() == 1 && positions[0] == -1 )) { + if (positions.empty() || + (positions.size() == 1 && positions[0] == -1)) { positions.resize(detectors.size()); std::iota(begin(positions), end(positions), 0); } @@ -126,7 +102,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { futures.push_back(std::async(std::launch::async, somefunc, detectors[i].get(), Args...)); } - std::vector result; + sls::Result result; result.reserve(positions.size()); for (auto &i : futures) { result.push_back(i.get()); @@ -135,11 +111,12 @@ class multiSlsDetector : public virtual slsDetectorDefs { } template - std::vector Parallel(RT (slsDetector::*somefunc)(CT...) const, + sls::Result Parallel(RT (slsDetector::*somefunc)(CT...) const, std::vector positions, - typename NonDeduced::type... Args) const{ + typename NonDeduced::type... Args) const { - if (positions.empty() || (positions.size() == 1 && positions[0] == -1 )) { + if (positions.empty() || + (positions.size() == 1 && positions[0] == -1)) { positions.resize(detectors.size()); std::iota(begin(positions), end(positions), 0); } @@ -151,7 +128,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { futures.push_back(std::async(std::launch::async, somefunc, detectors[i].get(), Args...)); } - std::vector result; + sls::Result result; result.reserve(positions.size()); for (auto &i : futures) { result.push_back(i.get()); @@ -161,10 +138,11 @@ class multiSlsDetector : public virtual slsDetectorDefs { template void Parallel(void (slsDetector::*somefunc)(CT...), - std::vector positions, - typename NonDeduced::type... Args) { + std::vector positions, + typename NonDeduced::type... Args) { - if (positions.empty() || (positions.size() == 1 && positions[0] == -1 )) { + if (positions.empty() || + (positions.size() == 1 && positions[0] == -1)) { positions.resize(detectors.size()); std::iota(begin(positions), end(positions), 0); } @@ -183,10 +161,11 @@ class multiSlsDetector : public virtual slsDetectorDefs { template void Parallel(void (slsDetector::*somefunc)(CT...) const, - std::vector positions, - typename NonDeduced::type... Args) const{ + std::vector positions, + typename NonDeduced::type... Args) const { - if (positions.empty() || (positions.size() == 1 && positions[0] == -1 )) { + if (positions.empty() || + (positions.size() == 1 && positions[0] == -1)) { positions.resize(detectors.size()); std::iota(begin(positions), end(positions), 0); } @@ -203,19 +182,10 @@ class multiSlsDetector : public virtual slsDetectorDefs { } } - /** - * Creates/open shared memory, initializes detector structure and members - * Called by constructor/ set hostname / read config file - * @param verify true to verify if shared memory version matches existing - * one - * @param update true to update last user pid, date etc - */ - void setupMultiDetector(bool verify = true, bool update = true); - /** * Loop through the detectors serially and return the result as a vector */ - + template std::vector serialCall(RT (slsDetector::*somefunc)(CT...), typename NonDeduced::type... Args); @@ -251,34 +221,17 @@ class multiSlsDetector : public virtual slsDetectorDefs { void parallelCall(void (slsDetector::*somefunc)(CT...) const, typename NonDeduced::type... Args) const; - /** - * Decodes which detector and the corresponding channel numbers for it - * Mainly useful in a multi detector setROI (Gotthard) - * @param offsetX channel number or total channel offset in x direction - * @param offsetY channel number or total channel offset in y direction - * @param channelX channel number from detector offset in x direction - * @param channelY channel number from detector offset in x direction - * @returns detector id or -1 if channel number out of range - */ - int decodeNChannel(int offsetX, int offsetY, int &channelX, int &channelY); - /** * Set acquiring flag in shared memory * @param b acquiring flag */ - void setAcquiringFlag(bool flag); + void setAcquiringFlag(bool flag); // /** * Get acquiring flag from shared memory * @returns acquiring flag */ - bool getAcquiringFlag() const; - - /** - * Check if acquiring flag is set, set error if set - * @returns FAIL if not ready, OK if ready - */ - bool isAcquireReady(); + bool getAcquiringFlag() const; // /** * Check version compatibility with detector software @@ -286,7 +239,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param p port type control port or receiver port * @param detPos -1 for all detectors in list or specific detector position */ - void checkDetectorVersionCompatibility(int detPos = -1); + void checkDetectorVersionCompatibility(int detPos = -1); // /** * Check version compatibility with receiver software @@ -294,7 +247,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param p port type control port or receiver port * @param detPos -1 for all detectors in list or specific detector position */ - void checkReceiverVersionCompatibility(int detPos = -1); + void checkReceiverVersionCompatibility(int detPos = -1); // /** * Get ID or version numbers @@ -302,34 +255,38 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns Id or version number of that type */ - int64_t getId(idMode mode, int detPos = -1); + int64_t getId(idMode mode, + int detPos = -1); // not needed anymore (later remove + // this_software_version from enum) - int getMultiId()const{return multiId;} + int getMultiId() const { return multiId; } // part of multi also /** * Get Client Software version * @returns client software version */ - int64_t getClientSoftwareVersion() const; + int64_t getClientSoftwareVersion() const; // /** * Get Receiver software version * @return receiver software version */ - int64_t getReceiverSoftwareVersion(int detPos = -1); + int64_t getReceiverSoftwareVersion(int detPos = -1); // /** * Get Detector Number * @returns vector of detector number */ - std::vector getDetectorNumber(); + std::vector + getDetectorNumber(); // renamed to getDetectorSerialNumber /** * Free shared memory from the command line * avoiding creating the constructor classes and mapping * @param multiId multi detector Id * @param detPos -1 for all detectors in list or specific detector position */ - static void freeSharedMemory(int multiId, int detPos = -1); + static void freeSharedMemory(int multiId, + int detPos = -1); // private or not needed /** * Free shared memory and delete shared memory structure @@ -338,13 +295,28 @@ class multiSlsDetector : public virtual slsDetectorDefs { * object back to state before object creation amap * @param detPos -1 for all detectors in list or specific detector position */ - void freeSharedMemory(int detPos = -1); + void freeSharedMemory(int detPos = -1); // /** * Get user details of shared memory * @returns string with user details */ - std::string getUserDetails(); + std::string getUserDetails(); // part of multi + + /** + * Connect to Virtual Detector Servers at local host + * @param ndet number of detectors + * @param port starting port number + */ + void setVirtualDetectorServers(const int numdet, const int port); + + /** + * Sets the hostname of all sls detectors in shared memory and updates local + * cache + * @param name hostname of all the sls detectors + */ + void setHostname( + const std::vector &name); // cannot set individually /** * Sets the hostname of all sls detectors in shared memory @@ -352,7 +324,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param name concatenated hostname of all the sls detectors * @param detPos -1 for all detectors in list or specific detector position */ - void setHostname(const char *name, int detPos = -1); + void setHostname(const char *name, int detPos = -1); // not needed /** * Gets the hostname of detector at particular position @@ -361,15 +333,13 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns concatenated hostnames of all detectors or hostname of specific * one */ - std::string getHostname(int detPos = -1) const; + std::string getHostname(int detPos = -1) const; // /** - * Appends detectors to the end of the list in shared memory - * Connects to them - * @param name concatenated hostname of the sls detectors to be appended to - * the list + * Get Detector type as an enum + * @returns detector type */ - void addMultipleDetectors(const char *name); + detectorType getDetectorTypeAsEnum() const; // /** * Get Detector type for a particular sls detector or get the first one @@ -377,7 +347,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns detector type of sls detector in position pos, if -1, returns * the first det type */ - detectorType getDetectorTypeAsEnum(int detPos = -1); + detectorType getDetectorTypeAsEnum(int detPos); // /** * Concatenates string types of all sls detectors or @@ -386,134 +356,63 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns detector type of sls detector in position pos, if -1, * concatenates */ - std::string getDetectorTypeAsString(int detPos = -1); + std::string getDetectorTypeAsString(int detPos = -1); // /** * Returns the number of detectors in the multidetector structure * @returns number of detectors */ - int getNumberOfDetectors() const; - - /** - * Returns number of detectors in dimension d - * @param d dimension d - * @returns number of detectors in dimension d - */ - int getNumberOfDetectors(dimension d) const; + size_t size() const; // /** * Returns the number of detectors in each direction - @param nx number of detectors in x direction - @param ny number of detectors in y direction */ - void getNumberOfDetectors(int &nx, int &ny) const; + slsDetectorDefs::xy getNumberOfDetectors() const; // /** - * Returns the total number of channels of all sls detectors from shared - * memory + * Returns the total number of channels of all sls detectors including gap + * pixels * @param detPos -1 for all detectors in list or specific detector position - * @returns the total number of channels of all sls detectors + * @returns the total number of channels of all sls detectors including gap + * pixels */ - int getTotalNumberOfChannels(int detPos = -1); + slsDetectorDefs::xy getNumberOfChannels(int detPos = -1) const; // /** - * Returns the total number of channels of all sls detectors in dimension d - * from shared memory - * @param d dimension d - * @param detPos -1 for all detectors in list or specific detector position - * @returns the total number of channels of all sls detectors in dimension d + * Must be set before setting hostname + * Sets maximum number of channels of all sls detectors in each + * dimension d from shared memory + * @param c maximum number of channels of all sls detectors */ - int getTotalNumberOfChannels(dimension d, int detPos = -1); - - /** - * Returns the total number of channels of all sls detectors in dimension d - * including gap pixels from shared memory - * @param d dimension d - * @param detPos -1 for all detectors in list or specific detector position - * @returns the total number of channels of all sls detectors in dimension d - * including gap pixels - */ - int getTotalNumberOfChannelsInclGapPixels(dimension d, int detPos = -1); - - /** - * Returns the maximum number of channels of all sls detectors in each - * dimension d from shared memory. multi detector shared memory variable to - * calculate offsets for each sls detector - * @param d dimension d - * @returns the maximum number of channels of all sls detectors in dimension - * d - */ - int getMaxNumberOfChannelsPerDetector(dimension d); - - /** - * Sets the maximum number of channels of all sls detectors in each - * dimension d from shared memory, multi detector shared memory variable to - * calculate offsets for each sls detector - * @param d dimension d - * @param i maximum number of channels for multi structure in dimension d - * @returns the maximum number of channels of all sls detectors in dimension - * d - */ - int setMaxNumberOfChannelsPerDetector(dimension d, int i); + void setNumberOfChannels(const slsDetectorDefs::xy c); // /** * Get Quad Type (Only for Eiger Quad detector hardware) * @param detPos -1 for all detectors in list or specific detector position * @returns quad type */ - int getQuad(int detPos = -1); + int getQuad(int detPos = -1); // - /** - * Set Quad Type (Only for Eiger Quad detector hardware) - * @param enable true if quad type set, else false - * @param detPos -1 for all detectors in list or specific detector position - */ - void setQuad(const bool enable, int detPos = -1); + /** + * Set Quad Type (Only for Eiger Quad detector hardware) + * @param enable true if quad type set, else false + * @param detPos -1 for all detectors in list or specific detector position + */ + void setQuad(const bool enable, int detPos = -1); // /** * Set number of rows to read out (Only for Eiger) * @param value number of lines * @param detPos -1 for all detectors in list or specific detector position */ - void setReadNLines(const int value, int detPos = -1); + void setReadNLines(const int value, int detPos = -1); // /** * Get number of rows to read out (Only for Eiger) * @param detPos -1 for all detectors in list or specific detector position * @returns number of lines */ - int getReadNLines(int detPos = -1); - - /** - * Get Detector offset from shared memory in dimension d - * @param d dimension d - * @param detPos -1 for all detectors in list or specific detector position - * @returns offset in dimension d, -1 if pos is not an actual position in - * list - */ - int getDetectorOffset(dimension d, int detPos = -1); - - /** - * Set Detector offset in shared memory in dimension d - * @param d dimension d - * @param off offset for detector - * @param detPos -1 for all detectors in list or specific detector position - */ - void setDetectorOffset(dimension d, int off, int detPos = -1); - - /** - * Updates the channel offsets in X and Y dimension for all the sls - * detectors It is required for decodeNMod and setting ROI - */ - void updateOffsets(); - - /** - * Checks if each of the detectors are online/offline - * @param detPos -1 for all detectors in list or specific detector position - * @returns empty string if they are all online, - * else returns concatenation of strings of all detectors that are offline - */ - std::string checkOnline(int detPos = -1); + int getReadNLines(int detPos = -1); // /** * Set/Gets TCP Port of the detector @@ -521,7 +420,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns port number */ - int setControlPort(int port_number = -1, int detPos = -1); + int setControlPort(int port_number = -1, int detPos = -1); // /** * Set/Gets TCP STOP Port of the detector @@ -529,7 +428,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns port number */ - int setStopPort(int port_number = -1, int detPos = -1); + int setStopPort(int port_number = -1, int detPos = -1); // /** * Set/Gets TCP Port of the receiver @@ -537,14 +436,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns port number */ - int setReceiverPort(int port_number = -1, int detPos = -1); + int setReceiverPort(int port_number = -1, int detPos = -1); // - /** - * Get Receiver port - * @param detPos -1 for all detectors in list or specific detector position - * @returns vector of receiver port - */ - int getReceiverPort(int detPos = -1) const; + /** + * Get Receiver port + * @param detPos -1 for all detectors in list or specific detector position + * @returns vector of receiver port + */ + int getReceiverPort(int detPos = -1) const; // /** * Lock server for this client IP @@ -552,47 +451,46 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns 1 for locked or 0 for unlocked */ - int lockServer(int p = -1, int detPos = -1); + int lockServer(int p = -1, int detPos = -1); // /** * Get last client IP saved on detector server * @param detPos -1 for all detectors in list or specific detector position * @returns last client IP saved on detector server */ - std::string getLastClientIP(int detPos = -1); + std::string getLastClientIP(int detPos = -1); // /** * Exit detector server * @param detPos -1 for all detectors in list or specific detector position */ - void exitServer(int detPos = -1); + void exitServer(int detPos = -1); // /** * Execute a command on the detector server * @param cmd command * @param detPos -1 for all detectors in list or specific detector position */ - void execCommand(const std::string &cmd, int detPos); + void execCommand(const std::string &cmd, int detPos); // /** * Load configuration from a configuration File * @param fname configuration file name */ - void readConfigurationFile(const std::string &fname); + void readConfigurationFile(const std::string &fname); // /** * Write current configuration to a file * @param fname configuration file name - * @returns OK or FAIL */ - int writeConfigurationFile(const std::string &fname); + void writeConfigurationFile(const std::string &fname); // /** * Get detector settings * @param detPos -1 for all detectors in list or specific detector position * @returns current settings */ - detectorSettings getSettings(int detPos = -1); + detectorSettings getSettings(int detPos = -1); // /** * Load detector settings from the settings file picked from the @@ -602,14 +500,15 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns current settings */ - detectorSettings setSettings(detectorSettings isettings, int detPos = -1); + detectorSettings setSettings(detectorSettings isettings, + int detPos = -1); // /** * Get threshold energy (Eiger) * @param detPos -1 for all detectors in list or specific detector position * @returns current threshold value for imod in ev (-1 failed) */ - int getThresholdEnergy(int detPos = -1); + int getThresholdEnergy(int detPos = -1); // /** * Set threshold energy (Eiger) @@ -620,14 +519,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns current threshold value for imod in ev (-1 failed) */ int setThresholdEnergy(int e_eV, detectorSettings isettings = GET_SETTINGS, - int tb = 1, int detPos = -1); + int tb = 1, int detPos = -1); // /** * Returns the detector trimbit/settings directory * @param detPos -1 for all detectors in list or specific detector position * @returns the trimbit/settings directory */ - std::string getSettingsDir(int detPos = -1); + std::string getSettingsDir(int detPos = -1); // /** * Sets the detector trimbit/settings directory @@ -635,7 +534,8 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the trimbit/settings directory */ - std::string setSettingsDir(const std::string &directory, int detPos = -1); + std::string setSettingsDir(const std::string &directory, + int detPos = -1); // /** * Loads the modules settings/trimbits reading from a specific file @@ -643,7 +543,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param fname specific settings/trimbits file * @param detPos -1 for all detectors in list or specific detector position */ - void loadSettingsFile(const std::string &fname, int detPos = -1); + void loadSettingsFile(const std::string &fname, int detPos = -1); // /** * Saves the modules settings/trimbits to a specific file @@ -651,88 +551,62 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param fname specific settings/trimbits file * @param detPos -1 for all detectors in list or specific detector position */ - void saveSettingsFile(const std::string &fname, int detPos = -1); + void saveSettingsFile(const std::string &fname, int detPos = -1); // /** * Get Detector run status * @param detPos -1 for all detectors in list or specific detector position * @returns status */ - runStatus getRunStatus(int detPos = -1); - - /** - * Prepares detector for acquisition (Eiger) - * @param detPos -1 for all detectors in list or specific detector position - */ - void prepareAcquisition(int detPos = -1); + runStatus getRunStatus(int detPos = -1); // /** * Start detector acquisition (Non blocking) * @param detPos -1 for all detectors in list or specific detector position */ - void startAcquisition(int detPos = -1); + void startAcquisition(int detPos = -1); // /** * Stop detector acquisition * @param detPos -1 for all detectors in list or specific detector position */ - void stopAcquisition(int detPos = -1); + void stopAcquisition(int detPos = -1); // /** * Give an internal software trigger to the detector (Eiger only) * @param detPos -1 for all detectors in list or specific detector position */ - void sendSoftwareTrigger(int detPos = -1); - - /** - * Start detector acquisition and read all data (Blocking until end of - * acquisition) - * @param detPos -1 for all detectors in list or specific detector position - */ - void startAndReadAll(int detPos = -1); - - /** - * Start readout (without exposure or interrupting exposure) (Eiger store in - * ram) - * @param detPos -1 for all detectors in list or specific detector position - */ - void startReadOut(int detPos = -1); - - /** - * Requests and receives all data from the detector (Eiger store in ram) - * @param detPos -1 for all detectors in list or specific detector position - */ - void readAll(int detPos = -1); + void sendSoftwareTrigger(int detPos = -1); // /** * Configures in detector the destination for UDP packets * @param detPos -1 for all detectors in list or specific detector position */ - void configureMAC(int detPos = -1); - - /** + void configureMAC(int detPos = -1); // + + /** * Set starting frame number for the next acquisition * @param val starting frame number * @param detPos -1 for all detectors in list or specific detector position */ - void setStartingFrameNumber(const uint64_t value, int detPos = -1); + void setStartingFrameNumber(const uint64_t value, int detPos = -1); // /** * Get starting frame number for the next acquisition * @param detPos -1 for all detectors in list or specific detector position * @returns starting frame number */ - uint64_t getStartingFrameNumber(int detPos = -1); + uint64_t getStartingFrameNumber(int detPos = -1); // /** * Set/get timer value (not all implemented for all detectors) * @param index timer index - * @param t time in ns or number of...(e.g. frames, gates, probes) + * @param t time in ns or number of...(e.g. frames, probes) * @param detPos -1 for all detectors in list or specific detector position - * @returns timer set value in ns or number of...(e.g. frames, gates, + * @returns timer set value in ns or number of...(e.g. frames, * probes) */ - int64_t setTimer(timerIndex index, int64_t t = -1, int detPos = -1); + int64_t setTimer(timerIndex index, int64_t t = -1, int detPos = -1); // /** * Set/get exposure time @@ -742,7 +616,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns exposure time in ns, or s if specified */ double setExposureTime(double t = -1, bool inseconds = false, - int detPos = -1); + int detPos = -1); // /** * Set/get exposure period @@ -752,7 +626,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns exposure period in ns, or s if specified */ double setExposurePeriod(double t = -1, bool inseconds = false, - int detPos = -1); + int detPos = -1); // /** * Set/get delay after trigger (Gotthard, Jungfrau(not for this release)) @@ -762,7 +636,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns delay after trigger in ns, or s if specified */ double setDelayAfterTrigger(double t = -1, bool inseconds = false, - int detPos = -1); + int detPos = -1); // /** * (Advanced users) @@ -773,7 +647,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns sub frame exposure time in ns, or s if specified */ double setSubFrameExposureTime(double t = -1, bool inseconds = false, - int detPos = -1); + int detPos = -1); // /** * (Advanced users) @@ -784,7 +658,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns sub frame dead time in ns, or s if specified */ double setSubFrameExposureDeadTime(double t = -1, bool inseconds = false, - int detPos = -1); + int detPos = -1); // /** * Set/get number of frames @@ -792,7 +666,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns number of frames */ - int64_t setNumberOfFrames(int64_t t = -1, int detPos = -1); + int64_t setNumberOfFrames(int64_t t = -1, int detPos = -1); // /** * Set/get number of cycles @@ -800,15 +674,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns number of cycles */ - int64_t setNumberOfCycles(int64_t t = -1, int detPos = -1); - - /** - * Set/get number of gates (none of the detectors at the moment) - * @param t number of gates (-1 gets) - * @param detPos -1 for all detectors in list or specific detector position - * @returns number of gates - */ - int64_t setNumberOfGates(int64_t t = -1, int detPos = -1); + int64_t setNumberOfCycles(int64_t t = -1, int detPos = -1); // /** * Set/get number of additional storage cells (Jungfrau) @@ -816,7 +682,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns number of additional storage cells */ - int64_t setNumberOfStorageCells(int64_t t = -1, int detPos = -1); + int64_t setNumberOfStorageCells(int64_t t = -1, int detPos = -1); // /** * Get measured period between previous two frames (EIGER) @@ -825,7 +691,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns sub frame dead time in ns, or s if specified */ - double getMeasuredPeriod(bool inseconds = false, int detPos = -1); + double getMeasuredPeriod(bool inseconds = false, int detPos = -1); // /** * Get sub period between previous two sub frames in 32 bit mode (EIGER) @@ -834,18 +700,19 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns sub frame dead time in ns, or s if specified */ - double getMeasuredSubFramePeriod(bool inseconds = false, int detPos = -1); + double getMeasuredSubFramePeriod(bool inseconds = false, + int detPos = -1); // /** * Set/get timer value left in acquisition (not all implemented for all * detectors) * @param index timer index - * @param t time in ns or number of...(e.g. frames, gates, probes) + * @param t time in ns or number of...(e.g. frames, probes) * @param detPos -1 for all detectors in list or specific detector position - * @returns timer set value in ns or number of...(e.g. frames, gates, + * @returns timer set value in ns or number of...(e.g. frames, * probes) */ - int64_t getTimeLeft(timerIndex index, int detPos = -1); + int64_t getTimeLeft(timerIndex index, int detPos = -1); // /** * Set speed @@ -853,12 +720,13 @@ class multiSlsDetector : public virtual slsDetectorDefs { * adcphase for Gotthard, others for CTB & Moench) * @param value (clkdivider 0,1,2 for full, half and quarter speed). Other * values check manual - * @param mode 0 for shift, 1 for degrees. relevant only for speed type adcphase and dbit phase + * @param mode 0 for shift, 1 for degrees. relevant only for speed type + * adcphase and dbit phase * @param detPos -1 for all detectors in list or specific detector position * @returns value of speed set */ int setSpeed(speedVariable index, int value = -1, int mode = 0, - int detPos = -1); + int detPos = -1); // /** * Set/get dynamic range and updates the number of dataBytes @@ -868,18 +736,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns current dynamic range */ - int setDynamicRange(int dr = -1, int detPos = -1); - - /** - * Recalculated number of data bytes for multi detector - * @param detPos -1 for all detectors in list or specific detector position - * @returns tota number of data bytes for multi detector - */ - int getDataBytes(int detPos = -1); - - /** - * Returns the number of detectors in the multi structure*/ - size_t size() const { return detectors.size(); } + int setDynamicRange(int dr = -1, int detPos = -1); // /** * Set/get dacs value @@ -889,7 +746,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns current DAC value */ - int setDAC(int val, dacIndex index, int mV, int detPos = -1); + int setDAC(int val, dacIndex index, int mV, int detPos = -1); // /** * Get adc value @@ -898,7 +755,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns current adc value (temperature for eiger and jungfrau in * millidegrees) */ - int getADC(dacIndex index, int detPos = -1); + int getADC(dacIndex index, int detPos = -1); // /** * Set/get timing mode @@ -906,9 +763,8 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns current timing mode */ - externalCommunicationMode setExternalCommunicationMode( - externalCommunicationMode pol = GET_EXTERNAL_COMMUNICATION_MODE, - int detPos = -1); + timingMode setTimingMode(timingMode pol = GET_TIMING_MODE, + int detPos = -1); // /** * Set/get external signal flags (to specify triggerinrising edge etc) @@ -919,7 +775,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ externalSignalFlag setExternalSignalFlags(externalSignalFlag pol = GET_EXTERNAL_SIGNAL_FLAG, - int detPos = -1); + int detPos = -1); // /** * Set/get readout flags (Eiger, Mythen) @@ -928,7 +784,8 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns readout flag */ - int setReadOutFlags(readOutFlags flag = GET_READOUT_FLAGS, int detPos = -1); + int setReadOutFlags(readOutFlags flag = GET_READOUT_FLAGS, + int detPos = -1); // /** * Set Interrupt last sub frame (Only for Eiger) @@ -951,7 +808,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns value read after writing */ - uint32_t writeRegister(uint32_t addr, uint32_t val, int detPos = -1); + uint32_t writeRegister(uint32_t addr, uint32_t val, int detPos = -1); // /** * Read from a register. For Advanced users @@ -959,7 +816,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns value read from register */ - uint32_t readRegister(uint32_t addr, int detPos = -1); + uint32_t readRegister(uint32_t addr, int detPos = -1); // /** * Set bit in a register. For Advanced users @@ -968,7 +825,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns value read from register */ - uint32_t setBit(uint32_t addr, int n, int detPos = -1); + uint32_t setBit(uint32_t addr, int n, int detPos = -1); // /** * Clear bit in a register. For Advanced users @@ -977,7 +834,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns value read from register */ - uint32_t clearBit(uint32_t addr, int n, int detPos = -1); + uint32_t clearBit(uint32_t addr, int n, int detPos = -1); // /** * Validates the format of the detector MAC address and sets it @@ -985,14 +842,15 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the detector MAC address */ - std::string setDetectorMAC(const std::string &detectorMAC, int detPos = -1); + std::string setDetectorMAC(const std::string &detectorMAC, + int detPos = -1); // /** * Returns the detector MAC address * @param detPos -1 for all detectors in list or specific detector position * @returns the detector MAC address */ - std::string getDetectorMAC(int detPos = -1); + std::string getDetectorMAC(int detPos = -1); // /** * Validates the format of the detector MAC address (bottom half) and sets @@ -1002,29 +860,31 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns the detector MAC address (bottom half) */ std::string setDetectorMAC2(const std::string &detectorMAC, - int detPos = -1); + int detPos = -1); // /** * Returns the detector MAC address (bottom half) Jungfrau only * @param detPos -1 for all detectors in list or specific detector position * @returns the detector MAC address (bottom half) */ - std::string getDetectorMAC2(int detPos = -1); + std::string getDetectorMAC2(int detPos = -1); // /** + * //TODO: custom ip (eiger 10G and other detectors), use 0.0.0.0 and test * Validates the format of the detector IP address and sets it * @param detectorIP detector IP address * @param detPos -1 for all detectors in list or specific detector position * @returns the detector IP address */ - std::string setDetectorIP(const std::string &detectorIP, int detPos = -1); + std::string setDetectorIP(const std::string &detectorIP, + int detPos = -1); // /** * Returns the detector IP address * @param detPos -1 for all detectors in list or specific detector position * @returns the detector IP address */ - std::string getDetectorIP(int detPos = -1) const; + std::string getDetectorIP(int detPos = -1) const; // /** * Validates the format of the detector IP address (bottom half) and sets it @@ -1033,14 +893,15 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the detector IP address (bottom half) */ - std::string setDetectorIP2(const std::string &detectorIP, int detPos = -1); + std::string setDetectorIP2(const std::string &detectorIP, + int detPos = -1); // /** * Returns the detector IP address (bottom half) Jungfrau only * @param detPos -1 for all detectors in list or specific detector position * @returns the detector IP address (bottom half) */ - std::string getDetectorIP2(int detPos = -1) const; + std::string getDetectorIP2(int detPos = -1) const; // /** * Validates and sets the receiver. @@ -1052,29 +913,30 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns the receiver IP address from shared memory */ std::string setReceiverHostname(const std::string &receiver, - int detPos = -1); + int detPos = -1); // /** * Returns the receiver IP address * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver IP address */ - std::string getReceiverHostname(int detPos = -1) const; + std::string getReceiverHostname(int detPos = -1) const; // /** + * TODO: replace this with setEthernetInterface * Validates the format of the receiver UDP IP address and sets it * @param udpip receiver UDP IP address * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP IP address */ - std::string setReceiverUDPIP(const std::string &udpip, int detPos = -1); + std::string setReceiverUDPIP(const std::string &udpip, int detPos = -1); // /** * Returns the receiver UDP IP address * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP IP address */ - std::string getReceiverUDPIP(int detPos = -1) const; + std::string getReceiverUDPIP(int detPos = -1) const; // /** * Validates the format of the receiver UDP IP address (bottom half) and @@ -1083,14 +945,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP IP address (bottom half) */ - std::string setReceiverUDPIP2(const std::string &udpip, int detPos = -1); + std::string setReceiverUDPIP2(const std::string &udpip, int detPos = -1); // /** * Returns the receiver UDP IP address (bottom half) Jungfrau only * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP IP address (bottom half) */ - std::string getReceiverUDPIP2(int detPos = -1) const; + std::string getReceiverUDPIP2(int detPos = -1) const; // /** * Validates the format of the receiver UDP MAC address and sets it @@ -1098,14 +960,15 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP MAC address */ - std::string setReceiverUDPMAC(const std::string &udpmac, int detPos = -1); + std::string setReceiverUDPMAC(const std::string &udpmac, + int detPos = -1); // /** * Returns the receiver UDP MAC address * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP MAC address */ - std::string getReceiverUDPMAC(int detPos = -1) const; + std::string getReceiverUDPMAC(int detPos = -1) const; // /** * Validates the format of the receiver UDP MAC address (bottom half) and @@ -1129,14 +992,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP port */ - int setReceiverUDPPort(int udpport, int detPos = -1); + int setReceiverUDPPort(int udpport, int detPos = -1); // /** * Returns the receiver UDP port * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP port */ - int getReceiverUDPPort(int detPos = -1) const; + int getReceiverUDPPort(int detPos = -1) const; // /** * Sets the receiver UDP port 2 (Eiger and Jungfrau only) @@ -1144,7 +1007,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP port 2 */ - int setReceiverUDPPort2(int udpport, int detPos = -1); + int setReceiverUDPPort2(int udpport, int detPos = -1); // /** * Returns the receiver UDP port 2 of same interface (Eiger and Jungfrau @@ -1152,7 +1015,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP port 2 of same interface */ - int getReceiverUDPPort2(int detPos = -1) const; + int getReceiverUDPPort2(int detPos = -1) const; // /** * Sets the number of UDP interfaces to stream data from detector (Jungfrau @@ -1161,7 +1024,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the number of interfaces */ - int setNumberofUDPInterfaces(int n, int detPos = -1); + int setNumberofUDPInterfaces(int n, int detPos = -1); // /** * Returns the number of UDP interfaces to stream data from detector @@ -1169,7 +1032,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the number of interfaces */ - int getNumberofUDPInterfaces(int detPos = -1) const; + int getNumberofUDPInterfaces(int detPos = -1) const; // /** * Selects the UDP interfaces to stream data from detector. Effective only @@ -1186,7 +1049,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the interface selected */ - int getSelectedUDPInterface(int detPos = -1) const; + int getSelectedUDPInterface(int detPos = -1) const; // /** * (advanced users) @@ -1205,7 +1068,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the client zmq port */ - int getClientStreamingPort(int detPos = -1); + int getClientStreamingPort(int detPos = -1); // /** * (advanced users) @@ -1215,7 +1078,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * individual detectors using i * @param detPos -1 for all detectors in list or specific detector position */ - void setReceiverDataStreamingOutPort(int i = -1, int detPos = -1); + void setReceiverDataStreamingOutPort(int i = -1, int detPos = -1); // /** * Returns the receiver zmq port @@ -1224,7 +1087,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver zmq port */ - int getReceiverStreamingPort(int detPos = -1); + int getReceiverStreamingPort(int detPos = -1); // /** * (advanced users) @@ -1234,7 +1097,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position */ void setClientDataStreamingInIP(const std::string &ip = "", - int detPos = -1); + int detPos = -1); // /** * Returns the client zmq ip @@ -1243,7 +1106,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the client zmq ip */ - std::string getClientStreamingIP(int detPos = -1); + std::string getClientStreamingIP(int detPos = -1); // /** * (advanced users) @@ -1253,7 +1116,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position */ void setReceiverDataStreamingOutIP(const std::string &ip = "", - int detPos = -1); + int detPos = -1); // /** * Returns the receiver zmq ip @@ -1262,7 +1125,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver zmq ip */ - std::string getReceiverStreamingIP(int detPos = -1); + std::string getReceiverStreamingIP(int detPos = -1); // /** * Sets the transmission delay for left, right or entire frame @@ -1273,7 +1136,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns transmission delay */ int setDetectorNetworkParameter(networkParameter index, int delay, - int detPos = -1); + int detPos = -1); // maybe not needed in API /** * Sets the additional json header @@ -1282,14 +1145,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns additional json header, default is empty */ std::string setAdditionalJsonHeader(const std::string &jsonheader, - int detPos = -1); + int detPos = -1); // /** * Returns the additional json header * @param detPos -1 for all detectors in list or specific detector position * @returns the additional json header, default is empty */ - std::string getAdditionalJsonHeader(int detPos = -1); + std::string getAdditionalJsonHeader(int detPos = -1); // /** * Sets the value for the additional json header parameter if found, else @@ -1302,7 +1165,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ std::string setAdditionalJsonParameter(const std::string &key, const std::string &value, - int detPos = -1); + int detPos = -1); // /** * Returns the additional json header parameter value @@ -1312,7 +1175,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * empty if no parameter found in additional json header */ std::string getAdditionalJsonParameter(const std::string &key, - int detPos = -1); + int detPos = -1); // /** * Sets the detector minimum/maximum energy threshold in processor (for @@ -1323,7 +1186,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * error in computing json parameter value) */ int setDetectorMinMaxEnergyThreshold(const int index, int value, - int detPos = -1); + int detPos = -1); // /** * Sets the frame mode in processor (Moench only) @@ -1350,21 +1213,21 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns receiver udp socket buffer size */ int64_t setReceiverUDPSocketBufferSize(int64_t udpsockbufsize = -1, - int detPos = -1); + int detPos = -1); // /** * Returns the receiver UDP socket buffer size * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver UDP socket buffer size */ - int64_t getReceiverUDPSocketBufferSize(int detPos = -1); + int64_t getReceiverUDPSocketBufferSize(int detPos = -1); // /** * Returns the receiver real UDP socket buffer size * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver real UDP socket buffer size */ - int64_t getReceiverRealUDPSocketBufferSize(int detPos = -1); + int64_t getReceiverRealUDPSocketBufferSize(int detPos = -1); // /** (users only) * Set 10GbE Flow Control (Eiger) @@ -1372,159 +1235,132 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns 10GbE flow Control */ - int setFlowControl10G(int enable = -1, int detPos = -1); + int setFlowControl10G(int enable = -1, int detPos = -1); // /** - * Execute a digital test (Gotthard) + * Execute a digital test (Gotthard, Jungfrau, CTB) * @param mode testmode type - * @param value 1 to set or 0 to clear the digital test bit + * @param value 1 to set or 0 to clear the image test bit (Gotthard) * @param detPos -1 for all detectors in list or specific detector position * @returns result of test */ int digitalTest(digitalTestMode mode, int ival = -1, int detPos = -1); /** - * Load dark or gain image to detector (Gotthard) - * @param index image type - * @param fname file name from which to load image - * @param detPos -1 for all detectors in list or specific detector position - */ - void loadImageToDetector(imageType index, const std::string &fname, - int detPos = -1); - - /** - * Writes the counter memory block from the detector (Gotthard) - * @param fname file name to load data from - * @param startACQ is 1 to start acquisition after reading counter - * @param detPos -1 for all detectors in list or specific detector position - */ - void writeCounterBlockFile(const std::string &fname, int startACQ = 0, - int detPos = -1); - - /** - * Resets counter in detector (Gotthard) - * @param startACQ is 1 to start acquisition after resetting counter - * @param detPos -1 for all detectors in list or specific detector position - */ - void resetCounterBlock(int startACQ = 0, int detPos = -1); - - /** - * Set/get counter bit in detector (Gotthard) + * Set/get counter bit in detector (Eiger) * @param i is -1 to get, 0 to reset and any other value to set the counter * bit * @param detPos -1 for all detectors in list or specific detector position * @returns the counter bit in detector */ - int setCounterBit(int i = -1, int detPos = -1); + int setCounterBit(int i = -1, int detPos = -1); // /** - * Ensures that min is less than max in both dimensions (Gotthard) - * @param n number of rois - * @param r array of rois + * Clear ROI (Gotthard) + * @param detPos -1 for all detectors in list or specific detector position */ - void verifyMinMaxROI(int n, ROI r[]); + void clearROI(int detPos = -1); /** * Set ROI (Gotthard) - * At the moment only one set allowed - * @param n number of rois - * @param roiLimits array of roi - * @param detPos -1 for all detectors in list or specific detector position + * At the moment only one set allowed per module + * Only allowed to set one ROI per module + * @param arg roi + * @param detPos specific detector position */ - void setROI(int n = -1, ROI roiLimits[] = nullptr, int detPos = -1); + void setROI(slsDetectorDefs::ROI arg, int detPos = -1); /** - * Get ROI from each detector and convert it to the multi detector scale - * (Gotthard) - * @param n number of rois - * @param detPos -1 for all detectors in list or specific detector position - * @returns OK or FAIL + * Get ROI (Gotthard) + * Only allowed to set one ROI per module + * @param detPos specific detector position + * @returns roi */ - const ROI *getROI(int &n, int detPos = -1); + slsDetectorDefs::ROI getROI(int detPos) const; /** * Set ADC Enable Mask (CTB, Moench) * @param mask ADC Enable mask * @param detPos -1 for all detectors in list or specific detector position */ - void setADCEnableMask(uint32_t mask, int detPos = -1); + void setADCEnableMask(uint32_t mask, int detPos = -1); // /** * Get ADC Enable Mask (CTB, Moench) * @param detPos -1 for all detectors in list or specific detector position * @returns ADC Enable mask */ - uint32_t getADCEnableMask(int detPos = -1); + uint32_t getADCEnableMask(int detPos = -1); // /** * Set ADC invert register (CTB, Moench) * @param value ADC invert value * @param detPos -1 for all detectors in list or specific detector position */ - void setADCInvert(uint32_t value, int detPos = -1); + void setADCInvert(uint32_t value, int detPos = -1); // /** * Get ADC invert register (CTB, Moench) * @param detPos -1 for all detectors in list or specific detector position * @returns ADC invert value */ - uint32_t getADCInvert(int detPos = -1); + uint32_t getADCInvert(int detPos = -1); // /** * Set external sampling source (CTB only) * @param value external sampling source (Option: 0-63) * @param detPos -1 for all detectors in list or specific detector position */ - void setExternalSamplingSource(int value, int detPos = -1); + void setExternalSamplingSource(int value, int detPos = -1); // /** * Get external sampling source (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns external sampling source */ - int getExternalSamplingSource(int detPos = -1); + int getExternalSamplingSource(int detPos = -1); // /** * Set external sampling enable (CTB only) * @param value external sampling source (Option: 0-63) * @param detPos -1 for all detectors in list or specific detector position */ - void setExternalSampling(bool value, int detPos = -1); + void setExternalSampling(bool value, int detPos = -1); // /** * Get external sampling source (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns external sampling enable */ - int getExternalSampling(int detPos = -1); + int getExternalSampling(int detPos = -1); // /** * Set external sampling enable (CTB only) * @param list external sampling source (Option: 0-63) * @param detPos -1 for all detectors in list or specific detector position */ - void setReceiverDbitList(std::vector list, int detPos = -1); + void setReceiverDbitList(std::vector list, int detPos = -1); // /** * Get external sampling source (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns external sampling enable */ - std::vector getReceiverDbitList(int detPos = -1); + std::vector getReceiverDbitList(int detPos = -1); // /** * Set digital data offset in bytes (CTB only) * @param value digital data offset in bytes * @param detPos -1 for all detectors in list or specific detector position */ - void setReceiverDbitOffset(int value, int detPos = -1); + void setReceiverDbitOffset(int value, int detPos = -1); // /** * Get digital data offset in bytes (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns digital data offset in bytes */ - int getReceiverDbitOffset(int detPos = -1); + int getReceiverDbitOffset(int detPos = -1); // /** * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert @@ -1533,7 +1369,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param val value * @param detPos -1 for all detectors in list or specific detector position */ - void writeAdcRegister(uint32_t addr, uint32_t val, int detPos = -1); + void writeAdcRegister(uint32_t addr, uint32_t val, int detPos = -1); // /** * Activates/Deactivates the detector (Eiger only) @@ -1541,7 +1377,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns 0 (inactive) or 1 (active)for activate mode */ - int activate(int const enable = -1, int detPos = -1); + int activate(int const enable = -1, int detPos = -1); // /** * Set deactivated Receiver padding mode (Eiger only) @@ -1554,22 +1390,20 @@ class multiSlsDetector : public virtual slsDetectorDefs { int setDeactivatedRxrPaddingMode(int padding = -1, int detPos = -1); /** - * Returns the enable if data will be flipped across x or y axis (Eiger) - * @param d axis across which data is flipped + * Returns the enable if data will be flipped across x axis (Eiger) * @param detPos -1 for all detectors in list or specific detector position * @returns 1 for flipped, else 0 */ - int getFlippedData(dimension d = X, int detPos = -1); + int getFlippedDataX(int detPos = -1); // /** * Sets the enable which determines if - * data will be flipped across x or y axis (Eiger) - * @param d axis across which data is flipped + * data will be flipped across x axis (Eiger) * @param value 0 or 1 to reset/set or -1 to get value * @param detPos -1 for all detectors in list or specific detector position * @returns enable flipped data across x or y axis */ - int setFlippedData(dimension d = X, int value = -1, int detPos = -1); + int setFlippedDataX(int value = -1, int detPos = -1); // /** * Sets all the trimbits to a particular value (Eiger) @@ -1577,7 +1411,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns OK or FAIL */ - int setAllTrimbits(int val, int detPos = -1); + int setAllTrimbits(int val, int detPos = -1); // /** * Enable gap pixels, only for Eiger and for 8,16 and 32 bit mode. (Eiger) @@ -1585,8 +1419,9 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param val 1 sets, 0 unsets, -1 gets * @returns gap pixel enable or -1 for error */ - int enableGapPixels(int val = -1, int detPos = -1); + int enableGapPixels(int val = -1, int detPos = -1); // + void setGapPixelsEnable(bool enable, sls::Positions pos = {}); /** * Sets the number of trim energies and their value (Eiger) * @@ -1595,7 +1430,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns number of trim energies */ - int setTrimEn(std::vector energies, int detPos = -1); + int setTrimEn(std::vector energies, int detPos = -1); // /** * Returns the number of trim energies and their value (Eiger) @@ -1603,7 +1438,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns vector of trim energies */ - std::vector getTrimEn(int detPos = -1); + std::vector getTrimEn(int detPos = -1); // /** * Pulse Pixel (Eiger) @@ -1612,7 +1447,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param y is y coordinate * @param detPos -1 for all detectors in list or specific detector position */ - void pulsePixel(int n = 0, int x = 0, int y = 0, int detPos = -1); + void pulsePixel(int n = 0, int x = 0, int y = 0, int detPos = -1); // /** * Pulse Pixel and move by a relative value (Eiger) @@ -1621,14 +1456,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param y is relative y value * @param detPos -1 for all detectors in list or specific detector position */ - void pulsePixelNMove(int n = 0, int x = 0, int y = 0, int detPos = -1); + void pulsePixelNMove(int n = 0, int x = 0, int y = 0, int detPos = -1); // /** * Pulse Chip (Eiger) * @param n is number of times to pulse * @param detPos -1 for all detectors in list or specific detector position */ - void pulseChip(int n = 0, int detPos = -1); + void pulseChip(int n = 0, int detPos = -1); // /** * Set/gets threshold temperature (Jungfrau) @@ -1636,7 +1471,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns threshold temperature in millidegrees */ - int setThresholdTemperature(int val = -1, int detPos = -1); + int setThresholdTemperature(int val = -1, int detPos = -1); // /** * Enables/disables temperature control (Jungfrau) @@ -1644,7 +1479,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns temperature control enable */ - int setTemperatureControl(int val = -1, int detPos = -1); + int setTemperatureControl(int val = -1, int detPos = -1); // /** * Resets/ gets over-temperature event (Jungfrau) @@ -1652,7 +1487,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns over-temperature event */ - int setTemperatureEvent(int val = -1, int detPos = -1); + int setTemperatureEvent(int val = -1, int detPos = -1); // /** * Set storage cell that stores first acquisition of the series (Jungfrau) @@ -1660,20 +1495,20 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the storage cell that stores the first acquisition of the series */ - int setStoragecellStart(int pos = -1, int detPos = -1); + int setStoragecellStart(int pos = -1, int detPos = -1); // /** - * Programs FPGA with pof file (Not Eiger) + * Programs FPGA with pof file (Jungfrau, CTB, Moench) * @param fname file name * @param detPos -1 for all detectors in list or specific detector position */ - void programFPGA(const std::string &fname, int detPos = -1); + void programFPGA(const std::string &fname, int detPos = -1); // /** - * Resets FPGA (Not Eiger) + * Resets FPGA (Jungfrau, CTB, Moench) * @param detPos -1 for all detectors in list or specific detector position */ - void resetFPGA(int detPos = -1); + void resetFPGA(int detPos = -1); // /** * Copies detector server from tftp and changes respawn server (Not Eiger) @@ -1681,13 +1516,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param hostname name of pc to tftp from * @param detPos -1 for all detectors in list or specific detector position */ - void copyDetectorServer(const std::string &fname, const std::string &hostname, int detPos = -1); + void copyDetectorServer(const std::string &fname, + const std::string &hostname, int detPos = -1); // /** * Reboot detector controller (Not Eiger) * @param detPos -1 for all detectors in list or specific detector position */ - void rebootController(int detPos = -1); + void rebootController(int detPos = -1); // /** * Updates the firmware, detector server and then reboots detector @@ -1697,7 +1533,8 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param fname programming file name * @param detPos -1 for all detectors in list or specific detector position */ - void update(const std::string &sname, const std::string &hostname, const std::string &fname, int detPos = -1); + void update(const std::string &sname, const std::string &hostname, + const std::string &fname, int detPos = -1); // /** * Power on/off Chip (Jungfrau) @@ -1705,7 +1542,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns OK or FAIL */ - int powerChip(int ival = -1, int detPos = -1); + int powerChip(int ival = -1, int detPos = -1); // /** * Automatic comparator disable (Jungfrau) @@ -1713,45 +1550,37 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns OK or FAIL */ - int setAutoComparatorDisableMode(int ival = -1, int detPos = -1); + int setAutoComparatorDisableMode(int ival = -1, int detPos = -1); // /** - * Set Rate correction ( Eiger) - * @param t dead time in ns - if 0 disable correction, - * if >0 set dead time to t, if < 0 set deadtime to default dead time - * for current settings - * @param detPos -1 for all detectors in list or specific detector position - */ - void setRateCorrection(int64_t t = 0, int detPos = -1); + * Set Rate correction ( Eiger) + * @param t dead time in ns - if 0 disable correction, + * if >0 set dead time to t, if < 0 set deadtime to default dead time + * for current settings + * @param detPos -1 for all detectors in list or specific detector position + */ + void setRateCorrection(int64_t t = 0, int detPos = -1); // /** * Get rate correction ( Eiger) * @param detPos -1 for all detectors in list or specific detector position * @returns 0 if rate correction disabled, > 0 otherwise (ns) */ - int64_t getRateCorrection(int detPos = -1); + int64_t getRateCorrection(int detPos = -1); // /** * Prints receiver configuration - * @param level print level * @param detPos -1 for all detectors in list or specific detector position + * @returns receiver configuration */ - void printReceiverConfiguration(TLogLevel level = logINFO, int detPos = -1); + std::string printReceiverConfiguration(int detPos = -1); // /** * Get receiver online status * @param detPos -1 for all detectors in list or specific detector position * @returns use receiver flag */ - bool getUseReceiverFlag(int detPos = -1); - - /** - * Checks if the receiver is really online - * @param detPos -1 for all detectors in list or specific detector position - * @returns empty string if all online, else concatenates hostnames of all - * detectors that are offline - */ - std::string checkReceiverOnline(int detPos = -1); + bool getUseReceiverFlag(int detPos = -1); // /** * Locks/Unlocks the connection to the receiver @@ -1759,14 +1588,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns lock status of the receiver */ - int lockReceiver(int lock = -1, int detPos = -1); + int lockReceiver(int lock = -1, int detPos = -1); // /** * Returns the IP of the last client connecting to the receiver * @param detPos -1 for all detectors in list or specific detector position * @returns IP of last client connecting to receiver */ - std::string getReceiverLastClientIP(int detPos = -1); + std::string getReceiverLastClientIP(int detPos = -1); // /** * Turns off the receiver server! @@ -1787,7 +1616,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns output file directory */ - std::string getFilePath(int detPos = -1); + std::string getFilePath(int detPos = -1); // /** * Sets up the file directory @@ -1795,14 +1624,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param s file directory * @returns file dir */ - std::string setFilePath(const std::string &path, int detPos = -1); + std::string setFilePath(const std::string &path, int detPos = -1); // /** * Returns file name prefix * @param detPos -1 for all detectors in list or specific detector position * @returns file name prefix */ - std::string getFileName(int detPos = -1); + std::string getFileName(int detPos = -1); // /** * Sets up the file name prefix @@ -1810,7 +1639,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param s file name prefix * @returns file name prefix */ - std::string setFileName(const std::string &fname, int detPos = -1); + std::string setFileName(const std::string &fname, int detPos = -1); // /** * Sets the max frames per file in receiver @@ -1818,14 +1647,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns max frames per file in receiver */ - int setFramesPerFile(int f = -1, int detPos = -1); + int setFramesPerFile(int f = -1, int detPos = -1); // /** * Gets the max frames per file in receiver * @param detPos -1 for all detectors in list or specific detector position * @returns max frames per file in receiver */ - int getFramesPerFile(int detPos = -1) const; + int getFramesPerFile(int detPos = -1) const; // /** * Sets the frames discard policy in receiver @@ -1834,7 +1663,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns frames discard policy set in receiver */ frameDiscardPolicy setReceiverFramesDiscardPolicy( - frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY, int detPos = -1); + frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY, int detPos = -1); // /** * Sets the partial frames padding enable in receiver @@ -1842,16 +1671,16 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns partial frames padding enable in receiver */ - int setPartialFramesPadding(bool padding, int detPos = -1); + int setPartialFramesPadding(bool padding, int detPos = -1); // - int getPartialFramesPadding(int detPos = -1) const; + int getPartialFramesPadding(int detPos = -1) const; // /** * Returns file format * @param detPos -1 for all detectors in list or specific detector position * @returns file name */ - fileFormat getFileFormat(int detPos = -1); + fileFormat getFileFormat(int detPos = -1); // /** * Sets up the file format @@ -1859,7 +1688,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns file format */ - fileFormat setFileFormat(fileFormat f, int detPos = -1); + fileFormat setFileFormat(fileFormat f, int detPos = -1); // /** * Sets up the file index @@ -1867,74 +1696,55 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns file index */ - int setFileIndex(int i, int detPos = -1); + int setFileIndex(int i, int detPos = -1); // /** * Get File index - * @param detPos -1 for all detectors in list or specific detector position + * @param detPos -1 for all detectors in list or specific detector + * position * @returns file index */ - int getFileIndex(int detPos = -1) const; - - /** - * increments file index - * @param detPos -1 for all detectors in list or specific detector position - * @returns the file index - */ - int incrementFileIndex(int detPos = -1); + int getFileIndex(int detPos = -1) const; // /** * Receiver starts listening to packets * @param detPos -1 for all detectors in list or specific detector position */ - void startReceiver(int detPos = -1); + void startReceiver(int detPos = -1); // /** * Stops the listening mode of receiver * @param detPos -1 for all detectors in list or specific detector position */ - void stopReceiver(int detPos = -1); + void stopReceiver(int detPos = -1); // /** * Gets the status of the listening mode of receiver * @param detPos -1 for all detectors in list or specific detector position * @returns status */ - runStatus getReceiverStatus(int detPos = -1); + runStatus getReceiverStatus(int detPos = -1); // /** * Gets the number of frames caught by receiver * @param detPos -1 for all detectors in list or specific detector position * @returns number of frames caught by receiver */ - int getFramesCaughtByReceiver(int detPos = -1); + int getFramesCaughtByReceiver(int detPos = -1); // /** * Gets the current frame index of receiver * @param detPos -1 for all detectors in list or specific detector position * @returns average of all current frame index of receiver */ - uint64_t getReceiverCurrentFrameIndex(int detPos = -1); + uint64_t getReceiverCurrentFrameIndex(int detPos = -1); // /** * Resets framescaught in receiver * Use this when using startAcquisition instead of acquire * @param detPos -1 for all detectors in list or specific detector position */ - void resetFramesCaught(int detPos = -1); - - /** - * Create Receiving Data Sockets - * @param destroy is true to destroy all the sockets - * @returns OK or FAIL - */ - int createReceivingDataSockets(const bool destroy = false); - - /** - * Reads frames from receiver through a constant socket - * Called during acquire() when call back registered or when using gui - */ - void readFrameFromReceiver(); + void resetFramesCaught(int detPos = -1); // /** * Sets/Gets receiver file write enable @@ -1942,13 +1752,13 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns file write enable */ - int setFileWrite(bool value, int detPos = -1); + int setFileWrite(bool value, int detPos = -1); // /** * Gets file write enable * @returns file write enable */ - int getFileWrite(int detPos = -1) const; + int getFileWrite(int detPos = -1) const; // /** * Sets/Gets receiver master file write enable @@ -1956,14 +1766,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns master file write enable */ - int setMasterFileWrite(bool value, int detPos = -1); + int setMasterFileWrite(bool value, int detPos = -1); // /** * Gets master file write enable * @param detPos -1 for all detectors in list or specific detector position * @returns master file write enable */ - int getMasterFileWrite(int detPos = -1) const; + int getMasterFileWrite(int detPos = -1) const; // /** * Sets/Gets file overwrite enable @@ -1971,14 +1781,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns file overwrite enable */ - int setFileOverWrite(bool enable, int detPos = -1); + int setFileOverWrite(bool enable, int detPos = -1); // /** * Gets file over write enable * @param detPos -1 for all detectors in list or specific detector position * @returns file over write enable */ - int getFileOverWrite(int detPos = -1) const; + int getFileOverWrite(int detPos = -1) const; // /** * (previously setReadReceiverFrequency) @@ -1999,14 +1809,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns receiver streaming timer in ms */ - int setReceiverStreamingTimer(int time_in_ms = 500, int detPos = -1); + int setReceiverStreamingTimer(int time_in_ms = 200, int detPos = -1); // /** * Enable data streaming to client * @param enable 0 to disable, 1 to enable, -1 to get the value * @returns data streaming to client enable */ - int enableDataStreamingToClient(int enable = -1); + bool enableDataStreamingToClient(int enable = -1); /** * Enable or disable streaming data from receiver to client @@ -2022,7 +1832,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns if 10Gbe is enabled */ - int enableTenGigabitEthernet(int i = -1, int detPos = -1); + int enableTenGigabitEthernet(int i = -1, int detPos = -1); // /** * Set/get receiver fifo depth @@ -2030,7 +1840,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver fifo depth */ - int setReceiverFifoDepth(int i = -1, int detPos = -1); + int setReceiverFifoDepth(int i = -1, int detPos = -1); // /** * Set/get receiver silent mode @@ -2038,15 +1848,14 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns the receiver silent mode enable */ - int setReceiverSilentMode(int i = -1, int detPos = -1); + int setReceiverSilentMode(int i = -1, int detPos = -1); // /** * Opens pattern file and sends pattern (CTB/ Moench) * @param fname pattern file to open * @param detPos -1 for all detectors in list or specific detector position - * @returns OK/FAIL */ - int setPattern(const std::string &fname, int detPos = -1); + void setPattern(const std::string &fname, int detPos = -1); // /** * Sets pattern IO control (CTB/ Moench) @@ -2054,7 +1863,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns actual value */ - uint64_t setPatternIOControl(uint64_t word = -1, int detPos = -1); + uint64_t setPatternIOControl(uint64_t word = -1, int detPos = -1); // /** * Sets pattern clock control (CTB/ Moench) @@ -2062,7 +1871,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns actual value */ - uint64_t setPatternClockControl(uint64_t word = -1, int detPos = -1); + uint64_t setPatternClockControl(uint64_t word = -1, int detPos = -1); // /** * Writes a pattern word (CTB/ Moench) @@ -2072,7 +1881,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns actual value */ - uint64_t setPatternWord(int addr, uint64_t word, int detPos = -1); + uint64_t setPatternWord(int addr, uint64_t word, int detPos = -1); // /** * Sets the pattern or loop limits (CTB/ Moench) @@ -2083,7 +1892,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position */ void setPatternLoops(int level, int start = -1, int stop = -1, int n = -1, - int detPos = -1); + int detPos = -1); // /** * Gets the pattern loop limits (CTB/ Moench) @@ -2091,7 +1900,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns array of start address, stop address and number of loops */ - std::array getPatternLoops(int level, int detPos = -1); + std::array getPatternLoops(int level, int detPos = -1); // /** * Sets the wait address (CTB/ Moench) @@ -2100,7 +1909,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns actual value */ - int setPatternWaitAddr(int level, int addr = -1, int detPos = -1); + int setPatternWaitAddr(int level, int addr = -1, int detPos = -1); // /** * Sets the wait time (CTB/ Moench) @@ -2109,21 +1918,21 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns actual value */ - uint64_t setPatternWaitTime(int level, uint64_t t = -1, int detPos = -1); + uint64_t setPatternWaitTime(int level, uint64_t t = -1, int detPos = -1); // /** * Sets the mask applied to every pattern (CTB/ Moench) * @param mask mask to be applied * @param detPos -1 for all detectors in list or specific detector position */ - void setPatternMask(uint64_t mask, int detPos = -1); + void setPatternMask(uint64_t mask, int detPos = -1); // /** * Gets the mask applied to every pattern (CTB/ Moench) * @param detPos -1 for all detectors in list or specific detector position * @returns mask set */ - uint64_t getPatternMask(int detPos = -1); + uint64_t getPatternMask(int detPos = -1); // /** * Selects the bits that the mask will be applied to for every pattern (CTB/ @@ -2131,7 +1940,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param mask mask to select bits * @param detPos -1 for all detectors in list or specific detector position */ - void setPatternBitMask(uint64_t mask, int detPos = -1); + void setPatternBitMask(uint64_t mask, int detPos = -1); // /** * Gets the bits that the mask will be applied to for every pattern (CTB/ @@ -2139,7 +1948,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns mask of bits selected */ - uint64_t getPatternBitMask(int detPos = -1); + uint64_t getPatternBitMask(int detPos = -1); // /** * Set LED Enable (Moench, CTB only) @@ -2147,7 +1956,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns LED enable */ - int setLEDEnable(int enable = -1, int detPos = -1); + int setLEDEnable(int enable = -1, int detPos = -1); // /** * Set Digital IO Delay (Moench, CTB only) @@ -2155,7 +1964,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param delay delay in ps(1 bit=25ps, max of 775 ps) * @param detPos -1 for all detectors in list or specific detector position */ - void setDigitalIODelay(uint64_t pinMask, int delay, int detPos = -1); + void setDigitalIODelay(uint64_t pinMask, int delay, int detPos = -1); // /** * Loads the detector setup from file @@ -2184,13 +1993,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ void registerAcquisitionFinishedCallback(void (*func)(double, int, void *), void *pArg); - /** - * register callback for accessing detector progress - * @param func function to be called at the end of the acquisition. - * gets detector status and progress index as arguments - * @param pArg argument - */ - void registerProgressCallback(void (*func)(double, void *), void *pArg); /** * register calbback for accessing detector final data, @@ -2201,8 +2003,8 @@ class multiSlsDetector : public virtual slsDetectorDefs { * s is for subframe number for eiger for 32 bit mode * @param pArg argument */ - void registerDataCallback(void (*userCallback)(detectorData *, uint64_t, uint32_t, - void *), + void registerDataCallback(void (*userCallback)(detectorData *, uint64_t, + uint32_t, void *), void *pArg); /** @@ -2212,7 +2014,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * index, loops for measurements, calls required call backs. * @returns OK or FAIL depending on if it already started */ - int acquire(); + int acquire(); // /** * Combines data from all readouts and gives it to the gui @@ -2220,9 +2022,24 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ void processData(); - void addSlsDetector(std::unique_ptr det); + /** + * Convert raw file + * @param fname name of pof file + * @param fpgasrc pointer in memory to read pof to + * @returns file size + */ + std::vector readPofFile(const std::string &fname); private: + /** + * Creates/open shared memory, initializes detector structure and members + * Called by constructor/ set hostname / read config file + * @param verify true to verify if shared memory version matches existing + * one + * @param update true to update last user pid, date etc + */ + void setupMultiDetector(bool verify = true, bool update = true); + /** * Initialize (open/create) shared memory for the sharedMultiDetector * structure @@ -2248,6 +2065,18 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ void updateUserdetails(); + /** + * Prepares detector for acquisition (Eiger) + * @param detPos -1 for all detectors in list or specific detector position + */ + void prepareAcquisition(int detPos = -1); // + + /** + * Check if acquiring flag is set, set error if set + * @returns FAIL if not ready, OK if ready + */ + bool isAcquireReady(); + /** * Execute in command line and return result * @param cmd command @@ -2255,20 +2084,55 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ std::string exec(const char *cmd); + /** + * Appends detectors to the end of the list in shared memory + * Connects to them + * @param name concatenated hostname of the sls detectors to be appended to + * the list + */ + void addMultipleDetectors(const char *name); // + /** * Add sls detector * @param s hostname of the single detector */ void addSlsDetector(const std::string &hostname); + /** + * Updates the channel size in X and Y dimension for all the sls + * detectors + */ + void updateDetectorSize(); + + /** + * increments file index + * @param detPos -1 for all detectors in list or specific detector position + * @returns the file index + */ + int incrementFileIndex(int detPos = -1); + /** * add gap pixels to the image (only for Eiger in 4 bit mode) * @param image pointer to image without gap pixels * @param gpImage poiner to image with gap pixels, if NULL, allocated * inside function + * quadEnable quad enabled * @returns number of data bytes of image with gap pixels */ - int processImageWithGapPixels(char *image, char *&gpImage); + int processImageWithGapPixels(char *image, char *&gpImage, bool quadEnable); + + /** + * Create Receiving Data Sockets + * @param destroy is true to destroy all the sockets + * @returns OK or FAIL + */ + int createReceivingDataSockets(const bool destroy = false); + + /** + * Reads frames from receiver through a constant socket + * Called during acquire() when call back registered or when using gui + */ + void readFrameFromReceiver(); /** * Set total progress (total number of frames/images in an acquisition) @@ -2298,6 +2162,26 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ void startProcessingThread(); + /** + * Start detector acquisition and read all data (Blocking until end of + * acquisition) + * @param detPos -1 for all detectors in list or specific detector position + */ + void startAndReadAll(int detPos = -1); // + + /** + * Start readout (without exposure or interrupting exposure) (Eiger store in + * ram) + * @param detPos -1 for all detectors in list or specific detector position + */ + void startReadOut(int detPos = -1); // + + /** + * Requests and receives all data from the detector (Eiger store in ram) + * @param detPos -1 for all detectors in list or specific detector position + */ + void readAll(int detPos = -1); // + /** * Check if processing thread is ready to join main thread * @returns true if ready, else false @@ -2316,14 +2200,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ int kbhit(); - /** - * Convert raw file - * @param fname name of pof file - * @param fpgasrc pointer in memory to read pof to - * @returns file size - */ - std::vector readPofFile(const std::string &fname); - /** * Convert a double holding time in seconds to an int64_t with nano seconds * Used for conversion when sending time to detector @@ -2364,9 +2240,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { /** mutex to synchronize main and data processing threads */ mutable std::mutex mp; - /** mutex to synchronizedata processing and plotting threads */ - mutable std::mutex mg; - /** sets when the acquisition is finished */ bool jointhread{false}; @@ -2380,9 +2253,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { void (*acquisition_finished)(double, int, void *){nullptr}; void *acqFinished_p{nullptr}; - void (*progress_call)(double, void *){nullptr}; - void *pProgressCallArg{nullptr}; - void (*dataReady)(detectorData *, uint64_t, uint32_t, void *){nullptr}; void *pCallbackArg{nullptr}; }; diff --git a/slsDetectorSoftware/include/multiSlsDetectorClient.h b/slsDetectorSoftware/include/multiSlsDetectorClient.h index e370d4905..e72e61332 100755 --- a/slsDetectorSoftware/include/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/include/multiSlsDetectorClient.h @@ -101,7 +101,7 @@ class multiSlsDetectorClient { return; } } - if (parser.detector_id() >= detPtr->getNumberOfDetectors()) { + if (parser.detector_id() >= static_cast(detPtr->size())) { os << "position is out of bounds.\n"; return; } diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 582b3283f..1afa9bf99 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -13,7 +13,7 @@ class ServerInterface; #define SLS_SHMAPIVERSION 0x190726 -#define SLS_SHMVERSION 0x190726 +#define SLS_SHMVERSION 0x190816 /** * @short structure allocated in shared memory to store detector settings for @@ -35,12 +35,8 @@ struct sharedSlsDetector { /** END OF FIXED PATTERN -----------------------------------------------*/ - /** Detector offset in the X & Y direction in the multi detector structure - */ - int offset[2]; - /** Number of detectors in multi list in x dir and y dir */ - int multiSize[2]; + slsDetectorDefs::xy multiSize; /** is the port used for control functions */ int controlPort; @@ -54,17 +50,11 @@ struct sharedSlsDetector { /** list of the energies at which the detector has been trimmed */ sls::FixedCapacityContainer trimEnergies; - /** number of channels per chip */ - int nChans; - /** number of channels per chip in one direction */ - int nChan[2]; - - /** number of chips per module*/ - int nChips; + slsDetectorDefs::xy nChan; /** number of chips per module in one direction */ - int nChip[2]; + slsDetectorDefs::xy nChip; /** number of dacs per module*/ int nDacs; @@ -72,14 +62,8 @@ struct sharedSlsDetector { /** dynamic range of the detector data */ int dynamicRange; - /** size of the data that are transfered from the detector */ - int dataBytes; - - /** number of rois defined */ - int nROI; - - /** list of rois */ - slsDetectorDefs::ROI roiLimits[MAX_ROIS]; + /** roi */ + slsDetectorDefs::ROI roi; /** adc enable mask */ uint32_t adcEnableMask; @@ -152,7 +136,7 @@ struct sharedSlsDetector { int tenGigaEnable; /** flipped data across x or y axis */ - int flippedData[2]; + int flippedDataX; /** tcp port from gui/different process to receiver (only data) */ int zmqport; @@ -176,10 +160,7 @@ struct sharedSlsDetector { int gappixels; /** gap pixels in each direction */ - int nGappixels[2]; - - /** data bytes including gap pixels */ - int dataBytesInclGapPixels; + slsDetectorDefs::xy nGappixels; /** additional json header */ char rxAdditionalJsonHeader[MAX_STR_LENGTH]; @@ -331,67 +312,23 @@ class slsDetector : public virtual slsDetectorDefs { */ int setDetectorType(detectorType type = GET_DETECTOR_TYPE); - /** - * Returns the total number of channels from shared memory - * @returns the total number of channels - */ - int getTotalNumberOfChannels() const; - /** * Update total number of channels (chiptestboard or moench) - * depending on the number of samples, roi, readout flags(ctb) + * depending on the number of samples, adenablemask, readout flags(ctb) */ - void updateTotalNumberOfChannels(); + void updateNumberOfChannels(); /** - * Returns the total number of channels in dimension d from shared memory - * @param d dimension d - * @returns the total number of channels in dimension d + * Returns the total number of channels including gap pixels + * @returns the total number of channels including gap pixels */ - int getTotalNumberOfChannels(dimension d) const; - - /** - * Returns the total number of channels of in dimension d including gap - * pixels from shared memory - * @param d dimension d - * @returns the total number of channels including gap pixels in dimension d - * including gap pixels - */ - int getTotalNumberOfChannelsInclGapPixels(dimension d) const; - - /** - * returns the number of channels per chip from shared memory (Mythen) - * @returns number of channels per chip - */ - int getNChans() const; - - /** - * returns the number of channels per chip in dimension d from shared memory - * (Mythen) - * @param d dimension d - * @returns number of channels per chip in dimension d - */ - int getNChans(dimension d) const; - - /** - * returns the number of chips per module from shared memory (Mythen) - * @returns number of chips per module - */ - int getNChips() const; - - /** - * returns the number of chips per module in dimension d from shared memory - * (Mythen) - * @param d dimension d - * @returns number of chips per module in dimension d - */ - int getNChips(dimension d) const; + slsDetectorDefs::xy getNumberOfChannels() const; /** * Get Quad Type (Only for Eiger Quad detector hardware) * @returns quad type */ - int getQuad(); + bool getQuad(); /** * Set Quad Type (Only for Eiger Quad detector hardware) @@ -399,7 +336,7 @@ class slsDetector : public virtual slsDetectorDefs { */ void setQuad(const bool enable); - /** + /** * Set number of rows to read out (Only for Eiger) * @param value number of lines */ @@ -411,33 +348,11 @@ class slsDetector : public virtual slsDetectorDefs { */ int getReadNLines(); - /** - * Get Detector offset from shared memory in dimension d - * @param d dimension d - * @returns offset in dimension d - */ - int getDetectorOffset(dimension d) const; - /** * Set Detector offset in shared memory in dimension d - * @param d dimension d - * @param off offset for detector + * @param det detector size */ - void setDetectorOffset(dimension d, int off); - - /** - * Set Detector offset in shared memory in dimension d - * @param detx number of detectors in X dir in multi list - * @param dety number of detectors in Y dir in multi list - */ - void updateMultiSize(int detx, int dety); - - /** - * Checks if each of the detector is online/offline - * @returns empty string if it is online - * else returns hostname if it is offline - */ - std::string checkOnline(); + void updateMultiSize(slsDetectorDefs::xy det); int setControlPort(int port_number); @@ -466,9 +381,9 @@ class slsDetector : public virtual slsDetectorDefs { /** * Lock server for this client IP * @param p 0 to unlock, 1 to lock (-1 gets) - * @returns 1 for locked or 0 for unlocked + * @returns true for locked or false for unlocked */ - int lockServer(int lock = -1); + bool lockServer(int lock = -1); /** * Get last client IP saved on detector server @@ -640,8 +555,8 @@ class slsDetector : public virtual slsDetectorDefs { /** * Set/get timer value (not all implemented for all detectors) * @param index timer index - * @param t time in ns or number of...(e.g. frames, gates, probes) - * @returns timer set value in ns or number of...(e.g. frames, gates, + * @param t time in ns or number of...(e.g. frames, probes) + * @returns timer set value in ns or number of...(e.g. frames, * probes) */ int64_t setTimer(timerIndex index, int64_t t = -1); @@ -650,8 +565,8 @@ class slsDetector : public virtual slsDetectorDefs { * Set/get timer value left in acquisition (not all implemented for all * detectors) * @param index timer index - * @param t time in ns or number of...(e.g. frames, gates, probes) - * @returns timer set value in ns or number of...(e.g. frames, gates, + * @param t time in ns or number of...(e.g. frames, probes) + * @returns timer set value in ns or number of...(e.g. frames, * probes) */ int64_t getTimeLeft(timerIndex index) const; @@ -669,7 +584,7 @@ class slsDetector : public virtual slsDetectorDefs { int setSpeed(speedVariable sp, int value = -1, int mode = 0); /** - * Set/get dynamic range and updates the number of dataBytes + * Set/get dynamic range * (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to * 1) * @param i dynamic range (-1 get) @@ -678,17 +593,7 @@ class slsDetector : public virtual slsDetectorDefs { */ int setDynamicRange(int n = -1); - /** - * Recalculated number of data bytes - * @returns tota number of data bytes - */ - int getDataBytes(); - - /** - * Recalculated number of data bytes including gap pixels - * @returns tota number of data bytes including gap pixels - */ - int getDataBytesInclGapPixels(); + int getDynamicRangeFromShm(); /** * Set/get dacs value @@ -712,8 +617,7 @@ class slsDetector : public virtual slsDetectorDefs { * @param pol timing mode (-1 gets) * @returns current timing mode */ - externalCommunicationMode setExternalCommunicationMode( - externalCommunicationMode pol = GET_EXTERNAL_COMMUNICATION_MODE); + timingMode setTimingMode(timingMode pol = GET_TIMING_MODE); /** * Set/get external signal flags (to specify triggerinrising edge etc) @@ -1074,47 +978,13 @@ class slsDetector : public virtual slsDetectorDefs { int64_t getReceiverRealUDPSocketBufferSize() const; /** - * Execute a digital test (Gotthard, Mythen) + * Execute a digital test (Gotthard, Jungfrau, CTB) * @param mode testmode type * @param value 1 to set or 0 to clear the digital test bit * @returns result of test */ int digitalTest(digitalTestMode mode, int ival = -1); - /** - * Load dark or gain image to detector (Gotthard) - * @param index image type, 0 for dark image and 1 for gain image - * @param fname file name from which to load image - */ - void loadImageToDetector(imageType index, const std::string &fname); - - /** - * Called from loadImageToDetector to send the image to detector - * @param index image type, 0 for dark image and 1 for gain image - * @param imageVals image - */ - void sendImageToDetector(imageType index, int16_t imageVals[]); - - /** - * Writes the counter memory block from the detector (Gotthard) - * @param fname file name to load data from - * @param startACQ is 1 to start acquisition after reading counter - */ - void writeCounterBlockFile(const std::string &fname, int startACQ = 0); - - /** - * Gets counter memory block in detector (Gotthard) - * @param image counter memory block from detector - * @param startACQ 1 to start acquisition afterwards, else 0 - */ - void getCounterBlock(int16_t image[], int startACQ = 0); - - /** - * Resets counter in detector - * @param startACQ is 1 to start acquisition after resetting counter - */ - void resetCounterBlock(int startACQ = 0); - /** * Set/get counter bit in detector (Gotthard) * @param i is -1 to get, 0 to reset and any other value to set the counter @@ -1123,35 +993,29 @@ class slsDetector : public virtual slsDetectorDefs { */ int setCounterBit(int cb = -1); + /** + * Clear ROI (Gotthard) + */ + void clearROI(); + /** * Set ROI (Gotthard) - * At the moment only one set allowed - * @param n number of rois - * @param roiLimits array of roi + * Also calls configuremac + * @param arg roi */ - void setROI(int n = -1, ROI roiLimits[] = nullptr); + void setROI(slsDetectorDefs::ROI arg); /** - * Get ROI from each detector and convert it to the multi detector scale - * (Gotthard) - * @param n number of rois - * @returns OK or FAIL + * Send ROI from shared memory to Receiver (Gotthard) */ - const slsDetectorDefs::ROI *getROI(int &n); + void sendROItoReceiver(); /** - * Returns number of rois - * @returns number of ROIs + * Get ROI (Gotthard) + * Update receiver if different from shm + * @returns roi */ - int getNRoi(); - - /** - * Send ROI to the detector after calculating - * from setROI - * @param n number of ROIs (-1 to get) - * @param roiLimits ROI - */ - void sendROI(int n = -1, ROI roiLimits[] = nullptr); + slsDetectorDefs::ROI getROI(); /** * Set ADC Enable Mask (CTB, Moench) @@ -1261,20 +1125,18 @@ class slsDetector : public virtual slsDetectorDefs { bool setDeactivatedRxrPaddingMode(int padding = -1); /** - * Returns the enable if data will be flipped across x or y axis (Eiger) - * @param d axis across which data is flipped + * Returns the enable if data will be flipped across x axis (Eiger) * @returns 1 for flipped, else 0 */ - int getFlippedData(dimension d = X) const; + int getFlippedDataX() const; /** * Sets the enable which determines if - * data will be flipped across x or y axis (Eiger) - * @param d axis across which data is flipped + * data will be flipped across x axis (Eiger) * @param value 0 or 1 to reset/set or -1 to get value - * @returns enable flipped data across x or y axis + * @returns enable flipped data across x axis */ - int setFlippedData(dimension d = X, int value = -1); + int setFlippedDataX(int value = -1); /** * Sets all the trimbits to a particular value (Eiger) @@ -1441,21 +1303,15 @@ class slsDetector : public virtual slsDetectorDefs { /** * Prints receiver configuration - * @param level print level + * @returns receiver configuration */ - void printReceiverConfiguration(TLogLevel level = logINFO); + std::string printReceiverConfiguration(); /** * Gets the use receiver flag from shared memory */ bool getUseReceiverFlag() const; - /** - * Checks if the receiver is really online - * @returns empty string if online, else returns receiver hostname - */ - std::string checkReceiverOnline(); - /** * Locks/Unlocks the connection to the receiver * @param lock sets (1), usets (0), gets (-1) the lock @@ -1679,7 +1535,7 @@ class slsDetector : public virtual slsDetectorDefs { * @param time_in_ms timer between frames * @returns receiver streaming timer in ms */ - int setReceiverStreamingTimer(int time_in_ms = 500); + int setReceiverStreamingTimer(int time_in_ms = 200); /** * Enable or disable streaming data from receiver to client @@ -1720,9 +1576,8 @@ class slsDetector : public virtual slsDetectorDefs { /** * Opens pattern file and sends pattern to CTB * @param fname pattern file to open - * @returns OK/FAIL */ - int setPattern(const std::string &fname); + void setPattern(const std::string &fname); /** * Sets pattern IO control (CTB/ Moench) @@ -1845,31 +1700,30 @@ class slsDetector : public virtual slsDetectorDefs { void sendToDetectorStop(int fnum, const void *args, size_t args_size, void *retval, size_t retval_size); - void sendToDetectorStop(int fnum, const void *args, size_t args_size, + void sendToDetectorStop(int fnum, const void *args, size_t args_size, void *retval, size_t retval_size) const; template void sendToDetectorStop(int fnum, const Arg &args, Ret &retval); - template + template void sendToDetectorStop(int fnum, const Arg &args, Ret &retval) const; template void sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t); - template + template void sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t) const; template void sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval); - template + template void sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) const; void sendToDetectorStop(int fnum); - void sendToDetectorStop(int fnum) const; - + void sendToDetectorStop(int fnum) const; /** * Send function parameters to receiver @@ -1882,30 +1736,30 @@ class slsDetector : public virtual slsDetectorDefs { void sendToReceiver(int fnum, const void *args, size_t args_size, void *retval, size_t retval_size); - void sendToReceiver(int fnum, const void *args, size_t args_size, + void sendToReceiver(int fnum, const void *args, size_t args_size, void *retval, size_t retval_size) const; template void sendToReceiver(int fnum, const Arg &args, Ret &retval); - template + template void sendToReceiver(int fnum, const Arg &args, Ret &retval) const; template void sendToReceiver(int fnum, const Arg &args, std::nullptr_t); - template + template void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const; template void sendToReceiver(int fnum, std::nullptr_t, Ret &retval); - template + template void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const; void sendToReceiver(int fnum); - void sendToReceiver(int fnum) const; + void sendToReceiver(int fnum) const; /** * Get Detector Type from Shared Memory (opening shm without verifying size) diff --git a/slsDetectorSoftware/include/slsDetectorCommand.h b/slsDetectorSoftware/include/slsDetectorCommand.h index 9116d9e45..053f716d3 100755 --- a/slsDetectorSoftware/include/slsDetectorCommand.h +++ b/slsDetectorSoftware/include/slsDetectorCommand.h @@ -73,7 +73,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpSpeed(int action); static std::string helpAdvanced(int action); static std::string helpConfiguration(int action); - static std::string helpImage(int action); static std::string helpCounter(int action); static std::string helpADC(int action); static std::string helpTempControl(int action); @@ -134,7 +133,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdSpeed(int narg, const char * const args[], int action, int detPos = -1); std::string cmdAdvanced(int narg, const char * const args[], int action, int detPos = -1); std::string cmdConfiguration(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdImage(int narg, const char * const args[], int action, int detPos = -1); std::string cmdCounter(int narg, const char * const args[], int action, int detPos = -1); std::string cmdADC(int narg, const char * const args[], int action, int detPos = -1); std::string cmdTempControl(int narg, const char * const args[], int action, int detPos = -1); diff --git a/slsDetectorSoftware/include/slsDetectorUsers.h b/slsDetectorSoftware/include/slsDetectorUsers.h index d05c0f96c..c0f5ee46f 100755 --- a/slsDetectorSoftware/include/slsDetectorUsers.h +++ b/slsDetectorSoftware/include/slsDetectorUsers.h @@ -99,28 +99,17 @@ public: * Returns the number of detectors in the multidetector structure * @returns number of detectors */ - int getNumberOfDetectors() const; + int size() const; + /** - * Returns the maximum number of channels of all detectors - * (provided by user in config file using detsizechan command) - * Offsets are calculated according to these dimensions - * @param nx number of channels in horizontal - * @param ny number of channels in vertical - * @returns the maximum number of channels of all detectors - */ - int getMaximumDetectorSize(int &nx, int &ny); - - /** - * Returns the size and offsets of detector/multi detector - * @param x horizontal position origin in channel number - * @param y vertical position origin in channel number + * Returns the size of detector/multi detector * @param nx number of channels in horiziontal * @param ny number of channels in vertical * @param detPos -1 for all detectors in list or specific detector position * @returns the total number of channels of all sls detectors */ - int getDetectorSize(int &x, int &y, int &nx, int &ny, int detPos = -1); + int getDetectorSize(int &nx, int &ny, int detPos); /** * Gets detector type @@ -139,9 +128,8 @@ public: /** * Write current configuration to a file (for one time detector setup) * @param fname configuration file name - * @returns OK or FAIL */ - int writeConfigurationFile(const std::string& fname); + void writeConfigurationFile(const std::string& fname); /** * Loads the detector setup from file (current measurement setup) @@ -359,14 +347,6 @@ public: */ int64_t setNumberOfCycles(int64_t t = -1, int detPos = -1); - /** - * Set/get number of gates (none of the detectors at the moment) - * @param t number of gates (-1 gets) - * @param detPos -1 for all detectors in list or specific detector position - * @returns number of gates - */ - int64_t setNumberOfGates(int64_t t = -1, int detPos = -1); - /** * Set/get number of additional storage cells (Jungfrau) * @param t number of additional storage cells. Default is 0. (-1 gets) @@ -396,8 +376,8 @@ public: /** * Set/get timing mode * @param pol timing mode (-1 gets) - * Options (slsDetectorDefs::externalCommunicationMode) - * (Eiger: AUTO_TIMING, TRIGGER_EXPOSURE, BURST_TRIGGER, GATE_FIX_NUMBER) + * Options (slsDetectorDefs::timingMode) + * (Eiger: AUTO_TIMING, TRIGGER_EXPOSURE, BURST_TRIGGER, GATED) * (Jungfrau: AUTO_TIMING, TRIGGER_EXPOSURE) * (Gotthard: AUTO_TIMING, TRIGGER_EXPOSURE) * @param detPos -1 for all detectors in list or specific detector position @@ -505,22 +485,22 @@ public: int setFlowControl10G(int enable = -1, int detPos = -1); /** - * Set ROI (Gotthard) (>= 1 roi, but max 1 roi per module) - * At the moment only one set allowed - * @param n number of rois - * @param roiLimits array of roi - * @param detPos -1 for all detectors in list or specific detector position + * Set ROI (Gotthard) + * At the moment only one set allowed per module + * Only allowed to set one ROI per module + * @param arg roi + * @param detPos specific detector position */ - void setROI(int n=-1, slsDetectorDefs::ROI roiLimits[]=NULL, int detPos = -1); + void setROI(slsDetectorDefs::ROI arg, int detPos = -1); + /** - * Get ROI from each detector and convert it to the multi detector scale (Gotthard) - * >= 1 roi, but max 1 roi per module - * @param n number of rois - * @param detPos -1 for all detectors in list or specific detector position - * @returns pointer to array of ROI structure + * Get ROI (Gotthard) + * Only allowed to set one ROI per module + * @param detPos specific detector position + * @returns roi */ - const slsDetectorDefs::ROI* getROI(int &n, int detPos = -1); + slsDetectorDefs::ROI getROI(int detPos = -1); @@ -795,14 +775,6 @@ public: */ void registerAcquisitionFinishedCallback(void( *func)(double,int, void*), void *pArg); - /** - * register callback for accessing detector progress in client, - * @param func function to be called at the end of the acquisition. - * gets detector status and progress index as arguments - * @param pArg argument - */ - void registerProgressCallback(void( *func)(double,void*), void *pArg); - /** @short [usage strongly discouraged] sets parameters trough command line interface http://www.psi.ch/detectors/UsersSupportEN/slsDetectorClientHowTo.pdf \param command string as it would be written on the command line diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0a1b91714..566b00561 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1,53 +1,119 @@ #include "Detector.h" #include "container_utils.h" +#include "logger.h" #include "multiSlsDetector.h" #include "slsDetector.h" #include "sls_detector_defs.h" +#include "detectorData.h" + namespace sls { using defs = slsDetectorDefs; -Detector::Detector(int multi_id) - : pimpl(sls::make_unique(multi_id)) {} +Detector::Detector(int shm_id) + : pimpl(sls::make_unique(shm_id)) {} Detector::~Detector() = default; -// Acquisition -void Detector::acquire() { pimpl->acquire(); } - -void Detector::startReceiver(Positions pos) { - pimpl->Parallel(&slsDetector::startReceiver, pos); -} -void Detector::stopReceiver(Positions pos) { - pimpl->Parallel(&slsDetector::stopReceiver, pos); -} - -Result Detector::getReceiverStatus(Positions pos) { - return pimpl->Parallel(&slsDetector::getReceiverStatus, pos); -} - -bool Detector::getAcquiringFlag() const { return pimpl->getAcquiringFlag(); } - -void Detector::setAcquiringFlag(bool value) { pimpl->setAcquiringFlag(value); } - // Configuration +void Detector::freeSharedMemory() { pimpl->freeSharedMemory(); } + +void Detector::loadConfig(const std::string &fname) { + pimpl->readConfigurationFile(fname); +} + Result Detector::getHostname(Positions pos) const { return pimpl->Parallel(&slsDetector::getHostname, pos); } -void Detector::freeSharedMemory() { pimpl->freeSharedMemory(); } - -void Detector::setConfig(const std::string &fname) { - pimpl->readConfigurationFile(fname); +void Detector::setHostname(const std::vector &value) { + pimpl->setHostname(value); } -void Detector::clearBit(uint32_t addr, int bitnr, Positions pos) { - pimpl->Parallel(&slsDetector::clearBit, pos, addr, bitnr); +int Detector::getShmId() const { return pimpl->getMultiId(); } + +Result Detector::getFirmwareVersion(Positions pos) const { + return pimpl->Parallel(&slsDetector::getId, pos, + defs::DETECTOR_FIRMWARE_VERSION); } -void Detector::setBit(uint32_t addr, int bitnr, Positions pos) { - pimpl->Parallel(&slsDetector::setBit, pos, addr, bitnr); + +Result Detector::getDetectorServerVersion(Positions pos) const { + return pimpl->Parallel(&slsDetector::getId, pos, + defs::DETECTOR_SOFTWARE_VERSION); } -Result Detector::getRegister(uint32_t addr, Positions pos) { - return pimpl->Parallel(&slsDetector::readRegister, pos, addr); + +Result Detector::getSerialNumber(Positions pos) const { + return pimpl->Parallel(&slsDetector::getId, pos, + defs::DETECTOR_SERIAL_NUMBER); +} + +int64_t Detector::getClientVersion() const { + return pimpl->getClientSoftwareVersion(); +} + +Result Detector::getReceiverVersion(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverSoftwareVersion, pos); +} + +Result Detector::getDetectorType(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorTypeAsEnum, pos); +} + +int Detector::size() const { return pimpl->size(); } + +defs::xy Detector::getModuleGeometry() const { + return pimpl->getNumberOfDetectors(); +} + +Result Detector::getModuleSize(Positions pos) const { + return pimpl->Parallel(&slsDetector::getNumberOfChannels, pos); +} + +defs::xy Detector::getDetectorSize() const { + return pimpl->getNumberOfChannels(); +} + +void Detector::setDetectorSize(const defs::xy value) { + pimpl->setNumberOfChannels(value); +} + +Result Detector::getSettings(Positions pos) const { + return pimpl->Parallel(&slsDetector::getSettings, pos); +} + +void Detector::setSettings(defs::detectorSettings value, Positions pos) { + pimpl->Parallel(&slsDetector::setSettings, pos, value); +} + +// Callback + +void Detector::registerAcquisitionFinishedCallback(void (*func)(double, int, + void *), + void *pArg) { + pimpl->registerAcquisitionFinishedCallback(func, pArg); +} + +void Detector::registerDataCallback(void (*func)(detectorData *, uint64_t, + uint32_t, void *), + void *pArg) { + pimpl->registerDataCallback(func, pArg); +} + +// Acquisition Parameters + +Result Detector::getNumberOfFrames() const { + return pimpl->Parallel(&slsDetector::setTimer, {}, defs::FRAME_NUMBER, -1); +} + +void Detector::setNumberOfFrames(int64_t value) { + pimpl->Parallel(&slsDetector::setTimer, {}, defs::FRAME_NUMBER, value); +} + +Result Detector::getNumberOfTriggers() const { + return pimpl->Parallel(&slsDetector::setTimer, {}, defs::CYCLES_NUMBER, -1); +} + +void Detector::setNumberOfTriggers(int64_t value) { + pimpl->Parallel(&slsDetector::setTimer, {}, defs::CYCLES_NUMBER, value); } Result Detector::getExptime(Positions pos) const { @@ -55,18 +121,599 @@ Result Detector::getExptime(Positions pos) const { -1); } -Result Detector::getStartingFrameNumber(Positions pos) const { - return pimpl->Parallel(&slsDetector::getStartingFrameNumber, pos); -} -void Detector::setStartingFrameNumber(uint64_t value, Positions pos) { - pimpl->Parallel(&slsDetector::setStartingFrameNumber, pos, value); -} - void Detector::setExptime(ns t, Positions pos) { pimpl->Parallel(&slsDetector::setTimer, pos, defs::ACQUISITION_TIME, t.count()); } +Result Detector::getPeriod(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, -1); +} + +void Detector::setPeriod(ns t, Positions pos) { + pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, t.count()); +} + +Result Detector::getDelayAfterTrigger(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimer, pos, + defs::DELAY_AFTER_TRIGGER, -1); +} + +void Detector::setDelayAfterTrigger(ns value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimer, pos, defs::DELAY_AFTER_TRIGGER, + value.count()); +} + +Result Detector::getNumberOfFramesLeft(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, defs::FRAME_NUMBER); +} + +Result Detector::getNumberOfTriggersLeft(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, defs::CYCLES_NUMBER); +} + +Result Detector::getDelayAfterTriggerLeft(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, + defs::DELAY_AFTER_TRIGGER); +} + +Result Detector::getSpeed(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, -1, + 0); +} + +void Detector::setSpeed(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, value, 0); +} + +Result Detector::getADCPhase(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PHASE, -1, 0); +} + +void Detector::setADCPhase(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PHASE, value, 0); +} + +Result Detector::getMaxADCPhaseShift(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, + defs::MAX_ADC_PHASE_SHIFT, -1, 0); +} + +Result Detector::getADCPhaseInDegrees(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PHASE, -1, 1); +} + +void Detector::setADCPhaseInDegrees(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PHASE, value, 1); +} + +Result Detector::getHighVoltage(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, defs::HIGH_VOLTAGE, + 0); +} + +void Detector::setHighVoltage(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, defs::HIGH_VOLTAGE, 0); +} + +Result Detector::getTemperature(defs::dacIndex index, + Positions pos) const { + switch (index) { + case defs::TEMPERATURE_ADC: + case defs::TEMPERATURE_FPGA: + case defs::TEMPERATURE_FPGAEXT: + case defs::TEMPERATURE_10GE: + case defs::TEMPERATURE_DCDC: + case defs::TEMPERATURE_SODL: + case defs::TEMPERATURE_SODR: + case defs::TEMPERATURE_FPGA2: + case defs::TEMPERATURE_FPGA3: + case defs::SLOW_ADC_TEMP: + break; + default: + throw RuntimeError("Unknown Temperature Index"); + } + auto res = pimpl->Parallel(&slsDetector::getADC, pos, index); + switch (getDetectorType().squash()) { + case defs::EIGER: + case defs::JUNGFRAU: + for (auto &it : res) { + it /= 1000; + } + break; + default: + break; + } + return res; +} + +Result Detector::getDAC(defs::dacIndex index, bool mV, + Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, index, mV); +} + +void Detector::setDAC(int value, defs::dacIndex index, bool mV, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, index, mV); +} + +Result Detector::getTimingMode(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimingMode, pos, + defs::GET_TIMING_MODE); +} + +void Detector::setTimingMode(defs::timingMode value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimingMode, pos, value); +} + +// Acquisition + +void Detector::acquire() { pimpl->acquire(); } + +void Detector::startAcquisition() { + if (getUseReceiverFlag({}).squash()) + pimpl->Parallel(&slsDetector::startReceiver, {}); + pimpl->Parallel(&slsDetector::startAcquisition, {}); +} + +void Detector::stopAcquisition() { + pimpl->Parallel(&slsDetector::stopAcquisition, {}); + if (getUseReceiverFlag({}).squash()) // TODO: problem for acquire() + pimpl->Parallel(&slsDetector::stopReceiver, {}); +} + +void Detector::clearAcquiringFlag() { pimpl->setAcquiringFlag(0); } + +Result Detector::getDetectorStatus(Positions pos) const { + return pimpl->Parallel(&slsDetector::getRunStatus, pos); +} + +Result Detector::getReceiverStatus(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverStatus, pos); +} + +Result Detector::getFramesCaught(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFramesCaughtByReceiver, pos); +} + +Result Detector::getStartingFrameNumber(Positions pos) const { + return pimpl->Parallel(&slsDetector::getStartingFrameNumber, pos); +} + +void Detector::setStartingFrameNumber(uint64_t value, Positions pos) { + pimpl->Parallel(&slsDetector::setStartingFrameNumber, pos, value); +} + +void Detector::sendSoftwareTrigger(Positions pos) { + pimpl->Parallel(&slsDetector::sendSoftwareTrigger, pos); +} + +// Network Configuration (Detector<->Receiver) + +void Detector::configureMAC(Positions pos) { + pimpl->Parallel(&slsDetector::configureMAC, pos); +} + +Result Detector::getNumberofUDPInterfaces(Positions pos) const { + return pimpl->Parallel(&slsDetector::getNumberofUDPInterfaces, pos); +} + +void Detector::setNumberofUDPInterfaces(int n, Positions pos) { + int previouslyClientStreaming = pimpl->enableDataStreamingToClient(); + bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true); + pimpl->Parallel(&slsDetector::setNumberofUDPInterfaces, pos, n); + // redo the zmq sockets if enabled + if (previouslyClientStreaming != 0) { + pimpl->enableDataStreamingToClient(0); + pimpl->enableDataStreamingToClient(1); + } + if (previouslyReceiverStreaming) { + setRxZmqDataStream(false, pos); + setRxZmqDataStream(true, pos); + } +} + +Result Detector::getSelectedUDPInterface(Positions pos) const { + return pimpl->Parallel(&slsDetector::getSelectedUDPInterface, pos); +} + +void Detector::selectUDPInterface(int interface, Positions pos) { + pimpl->Parallel(&slsDetector::selectUDPInterface, pos, interface); +} + +Result Detector::getSourceUDPIP(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorIP, pos); +} + +void Detector::setSourceUDPIP(const std::string &ip, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorIP, pos, ip); +} + +Result Detector::getSourceUDPIP2(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorIP2, pos); +} + +void Detector::setSourceUDPIP2(const std::string &ip, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorIP2, pos, ip); +} + +Result Detector::getSourceUDPMAC(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorMAC, pos); +} + +void Detector::setSourceUDPMAC(const std::string &mac, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorMAC, pos, mac); +} + +Result Detector::getSourceUDPMAC2(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorMAC2, pos); +} + +void Detector::setSourceUDPMAC2(const std::string &mac, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorMAC2, pos, mac); +} + +Result Detector::getDestinationUDPIP(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPIP, pos); +} + +void Detector::setDestinationUDPIP(const std::string &ip, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverUDPIP, pos, ip); +} + +Result Detector::getDestinationUDPIP2(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPIP2, pos); +} + +void Detector::setDestinationUDPIP2(const std::string &ip, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverUDPIP2, pos, ip); +} + +Result Detector::getDestinationUDPMAC(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPMAC, pos); +} + +void Detector::setDestinationUDPMAC(const std::string &mac, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverUDPMAC, pos, mac); +} + +Result Detector::getDestinationUDPMAC2(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPMAC2, pos); +} + +void Detector::setDestinationUDPMAC2(const std::string &mac, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverUDPMAC2, pos, mac); +} + +Result Detector::getDestinationUDPPort(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPPort, pos); +} + +void Detector::setDestinationUDPPort(int port, int module_id) { + if (module_id == -1) { + std::vector port_list = getPortNumbers(port); + for (int idet = 0; idet < size(); ++idet) { + pimpl->Parallel(&slsDetector::setReceiverUDPPort, {idet}, + port_list[idet]); + } + } else { + pimpl->Parallel(&slsDetector::setReceiverUDPPort, {module_id}, port); + } +} + +Result Detector::getDestinationUDPPort2(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPPort2, pos); +} + +void Detector::setDestinationUDPPort2(int port, int module_id) { + if (module_id == -1) { + std::vector port_list = getPortNumbers(port); + for (int idet = 0; idet < size(); ++idet) { + pimpl->Parallel(&slsDetector::setReceiverUDPPort2, {idet}, + port_list[idet]); + } + } else { + pimpl->Parallel(&slsDetector::setReceiverUDPPort2, {module_id}, port); + } +} + +Result Detector::printRxConfiguration(Positions pos) const { + return pimpl->Parallel(&slsDetector::printReceiverConfiguration, pos); +} + +Result Detector::getTenGiga(Positions pos) const { + return pimpl->Parallel(&slsDetector::enableTenGigabitEthernet, pos, -1); +} + +void Detector::setTenGiga(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::enableTenGigabitEthernet, pos, + static_cast(value)); +} + +Result Detector::getTenGigaGFlowControl(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::FLOW_CONTROL_10G, -1); +} + +void Detector::setTenGigaGFlowControl(bool enable, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::FLOW_CONTROL_10G, static_cast(enable)); +} + +Result Detector::getTransmissionDelayFrame(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::DETECTOR_TXN_DELAY_FRAME, -1); +} + +void Detector::setTransmissionDelayFrame(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::DETECTOR_TXN_DELAY_FRAME, value); +} + +Result Detector::getTransmissionDelayLeft(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::DETECTOR_TXN_DELAY_LEFT, -1); +} + +void Detector::setTransmissionDelayLeft(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::DETECTOR_TXN_DELAY_LEFT, value); +} + +Result Detector::getTransmissionDelayRight(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::DETECTOR_TXN_DELAY_RIGHT, -1); +} + +void Detector::setTransmissionDelayRight(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setDetectorNetworkParameter, pos, + defs::DETECTOR_TXN_DELAY_RIGHT, value); +} + +// Receiver + +Result Detector::getUseReceiverFlag(Positions pos) const { + return pimpl->Parallel(&slsDetector::getUseReceiverFlag, pos); +} + +Result Detector::getRxHostname(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverHostname, pos); +} + +void Detector::setRxHostname(const std::string &receiver, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverHostname, pos, receiver); +} + +Result Detector::getRxPort(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverPort, pos); +} + +void Detector::setRxPort(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverPort, pos, value); +} + +Result Detector::getRxFifoDepth(Positions pos) const { + return pimpl->Parallel(&slsDetector::setReceiverFifoDepth, pos, -1); +} + +void Detector::setRxFifoDepth(int nframes, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverFifoDepth, pos, nframes); +} + +Result Detector::getRxSilentMode(Positions pos) const { + return pimpl->Parallel(&slsDetector::setReceiverSilentMode, pos, -1); +} + +void Detector::setRxSilentMode(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverSilentMode, pos, + static_cast(value)); +} + +Result +Detector::getRxFrameDiscardPolicy(Positions pos) const { + return pimpl->Parallel(&slsDetector::setReceiverFramesDiscardPolicy, pos, + defs::GET_FRAME_DISCARD_POLICY); +} + +void Detector::setRxFrameDiscardPolicy(defs::frameDiscardPolicy f, + Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverFramesDiscardPolicy, pos, f); +} + +Result Detector::getPartialFramesPadding(Positions pos) const { + return pimpl->Parallel(&slsDetector::getPartialFramesPadding, pos); +} + +void Detector::setPartialFramesPadding(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setPartialFramesPadding, pos, value); +} + +Result Detector::getRxUDPSocketBufferSize(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverUDPSocketBufferSize, pos); +} + +void Detector::setRxUDPSocketBufferSize(int64_t udpsockbufsize, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverUDPSocketBufferSize, pos, + udpsockbufsize); +} + +Result Detector::getRxRealUDPSocketBufferSize(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverRealUDPSocketBufferSize, + pos); +} + +Result Detector::getRxLock(Positions pos) { + return pimpl->Parallel(&slsDetector::lockReceiver, pos, -1); +} + +void Detector::setRxLock(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::lockReceiver, pos, static_cast(value)); +} + +Result Detector::getRxLastClientIP(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverLastClientIP, pos); +} + +// File + +Result Detector::getFileFormat(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFileFormat, pos); +} + +void Detector::setFileFormat(defs::fileFormat f, Positions pos) { + pimpl->Parallel(&slsDetector::setFileFormat, pos, f); +} + +Result Detector::getFilePath(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFilePath, pos); +} + +void Detector::setFilePath(const std::string &fpath, Positions pos) { + pimpl->Parallel(&slsDetector::setFilePath, pos, fpath); +} + +Result Detector::getFileNamePrefix(Positions pos) const { + return pimpl->Parallel(&slsDetector::setFileName, pos, ""); +} +void Detector::setFileNamePrefix(const std::string &fname, Positions pos) { + pimpl->Parallel(&slsDetector::setFileName, pos, fname); +} + +Result Detector::getAcquisitonIndex(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFileIndex, pos); +} + +void Detector::setAcquisitionIndex(int i, Positions pos) { + pimpl->Parallel(&slsDetector::setFileIndex, pos, i); +} + +Result Detector::getFileWrite(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFileWrite, pos); +} + +void Detector::setFileWrite(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setFileWrite, pos, value); +} + +void Detector::setMasterFileWrite(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setMasterFileWrite, pos, value); +} + +Result Detector::getMasterFileWrite(Positions pos) const { + return pimpl->Parallel(&slsDetector::getMasterFileWrite, pos); +} + +Result Detector::getFileOverWrite(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFileOverWrite, pos); +} + +void Detector::setFileOverWrite(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setFileOverWrite, pos, value); +} + +Result Detector::getFramesPerFile(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFramesPerFile, pos); +} + +void Detector::setFramesPerFile(int n, Positions pos) { + pimpl->Parallel(&slsDetector::setFramesPerFile, pos, n); +} + +// Zmq Streaming (Receiver<->Client) + +Result Detector::getRxZmqDataStream(Positions pos) const { + return pimpl->Parallel(&slsDetector::enableDataStreamingFromReceiver, pos, + -1); +} + +void Detector::setRxZmqDataStream(bool enable, Positions pos) { + pimpl->Parallel(&slsDetector::enableDataStreamingFromReceiver, pos, + static_cast(enable)); +} + +Result Detector::getRxZmqFrequency(Positions pos) const { + return pimpl->Parallel(&slsDetector::setReceiverStreamingTimer, pos, -1); +} + +void Detector::setRxZmqFrequency(int freq, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverStreamingFrequency, pos, freq); +} + +Result Detector::getRxZmqTimer(Positions pos) const { + return pimpl->Parallel(&slsDetector::setReceiverStreamingTimer, pos, -1); +} + +void Detector::setRxZmqTimer(int time_in_ms, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverStreamingTimer, pos, time_in_ms); +} + +Result Detector::getRxZmqPort(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverStreamingPort, pos); +} + +void Detector::setRxZmqPort(int port, int module_id) { + if (module_id == -1) { + std::vector port_list = getPortNumbers(port); + for (int idet = 0; idet < size(); ++idet) { + pimpl->Parallel(&slsDetector::setReceiverStreamingPort, {idet}, + port_list[idet]); + } + } else { + pimpl->Parallel(&slsDetector::setReceiverStreamingPort, {module_id}, + port); + } +} + +Result Detector::getRxZmqIP(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverStreamingIP, pos); +} + +void Detector::setRxZmqIP(const std::string &ip, Positions pos) { + bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(false); + pimpl->Parallel(&slsDetector::setReceiverStreamingIP, pos, ip); + if (previouslyReceiverStreaming) { + setRxZmqDataStream(false, pos); + setRxZmqDataStream(true, pos); + } +} + +Result Detector::getClientZmqPort(Positions pos) const { + return pimpl->Parallel(&slsDetector::getClientStreamingPort, pos); +} + +void Detector::setClientZmqPort(int port, int module_id) { + if (module_id == -1) { + std::vector port_list = getPortNumbers(port); + for (int idet = 0; idet < size(); ++idet) { + pimpl->Parallel(&slsDetector::setClientStreamingPort, {idet}, + port_list[idet]); + } + } else { + pimpl->Parallel(&slsDetector::setClientStreamingPort, {module_id}, + port); + } +} + +Result Detector::getClientZmqIp(Positions pos) const { + return pimpl->Parallel(&slsDetector::getClientStreamingIP, pos); +} + +void Detector::setClientZmqIp(const std::string &ip, Positions pos) { + int previouslyClientStreaming = pimpl->enableDataStreamingToClient(-1); + pimpl->Parallel(&slsDetector::setClientStreamingIP, pos, ip); + if (previouslyClientStreaming != 0) { + pimpl->enableDataStreamingToClient(0); + pimpl->enableDataStreamingToClient(1); + } +} + +// Eiger Specific + +Result Detector::getDynamicRange(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDynamicRange, pos, -1); +} + +void Detector::setDynamicRange(int value) { pimpl->setDynamicRange(value); } + Result Detector::getSubExptime(Positions pos) const { return pimpl->Parallel(&slsDetector::setTimer, pos, defs::SUBFRAME_ACQUISITION_TIME, -1); @@ -77,43 +724,862 @@ void Detector::setSubExptime(ns t, Positions pos) { defs::SUBFRAME_ACQUISITION_TIME, t.count()); } -Result Detector::getPeriod(Positions pos) const { - return pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, -1); +Result Detector::getSubDeadTime(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimer, pos, defs::SUBFRAME_DEADTIME, + -1); } -void Detector::setPeriod(ns t, Positions pos) { - pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, t.count()); +void Detector::setSubDeadTime(ns value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimer, pos, defs::SUBFRAME_DEADTIME, + value.count()); } -// File -void Detector::setFileName(const std::string &fname) { - pimpl->Parallel(&slsDetector::setFileName, Positions{}, fname); -} -Result Detector::getFileName() const { - return pimpl->Parallel(&slsDetector::setFileName, Positions{}, ""); +Result Detector::getThresholdEnergy(Positions pos) const { + return pimpl->Parallel(&slsDetector::getThresholdEnergy, pos); } -void Detector::setFilePath(const std::string &fpath) { - pimpl->Parallel(&slsDetector::setFilePath, Positions{}, fpath); -} -Result Detector::getFilePath() const { - return pimpl->Parallel(&slsDetector::getFilePath, Positions{}); +void Detector::setThresholdEnergy(int threshold_ev, + defs::detectorSettings settings, + bool trimbits, Positions pos) { + pimpl->Parallel(&slsDetector::setThresholdEnergy, pos, threshold_ev, + settings, static_cast(trimbits)); } -void Detector::setFileWrite(bool value, Positions pos) { - pimpl->Parallel(&slsDetector::setFileWrite, Positions{}, value); +Result Detector::getSettingsDir(Positions pos) const { + return pimpl->Parallel(&slsDetector::getSettingsDir, pos); } -Result Detector::getFileWrite(Positions pos) const { - return pimpl->Parallel(&slsDetector::getFileWrite, Positions{}); +void Detector::setSettingsDir(const std::string &value, Positions pos) { + pimpl->Parallel(&slsDetector::setSettingsDir, pos, value); } -void Detector::setFileOverWrite(bool value, Positions pos) { - pimpl->Parallel(&slsDetector::setFileOverWrite, Positions{}, value); +void Detector::loadTrimbits(const std::string &value, Positions pos) { + pimpl->Parallel(&slsDetector::loadSettingsFile, pos, value); } -Result Detector::getFileOverWrite(Positions pos) const { - return pimpl->Parallel(&slsDetector::getFileOverWrite, Positions{}); +Result Detector::getRxAddGapPixels(Positions pos) const { + return pimpl->Parallel(&slsDetector::enableGapPixels, pos, -1); +} + +void Detector::setRxAddGapPixels(bool enable) { + pimpl->setGapPixelsEnable(enable, {}); +} + +Result Detector::getParallelMode(Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::setReadOutFlags, pos, + defs::GET_READOUT_FLAGS); + Result booleanRes; + for (unsigned int i = 0; i < res.size(); ++i) { + booleanRes[i] = (res[i] & defs::PARALLEL) ? true : false; + } + return booleanRes; +} + +void Detector::setParallelMode(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setReadOutFlags, pos, + value ? defs::PARALLEL : defs::NONPARALLEL); +} + +Result Detector::getOverFlowMode(Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::setReadOutFlags, pos, + defs::GET_READOUT_FLAGS); + Result booleanRes; + for (unsigned int i = 0; i < res.size(); ++i) { + booleanRes[i] = (res[i] & defs::SHOW_OVERFLOW) ? true : false; + } + return booleanRes; +} + +void Detector::setOverFlowMode(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setReadOutFlags, pos, + value ? defs::SHOW_OVERFLOW : defs::NOOVERFLOW); +} + +Result Detector::getBottom(Positions pos) const { + return pimpl->Parallel(&slsDetector::getFlippedDataX, pos); +} + +void Detector::setBottom(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setFlippedDataX, pos, + static_cast(value)); +} + +Result Detector::getAllTrimbits(Positions pos) const { + return pimpl->Parallel(&slsDetector::setAllTrimbits, pos, -1); +} + +void Detector::setAllTrimbits(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setAllTrimbits, pos, value); +} + +Result> Detector::getTrimEnergies(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTrimEn, pos); +} + +void Detector::setTrimEnergies(std::vector energies, Positions pos) { + pimpl->Parallel(&slsDetector::setTrimEn, pos, energies); +} + +Result Detector::getRateCorrection(Positions pos) const { + return pimpl->Parallel(&slsDetector::getRateCorrection, pos); +} + +void Detector::setRateCorrection(ns dead_time, Positions pos) { + pimpl->Parallel(&slsDetector::setRateCorrection, pos, dead_time.count()); +} + +Result Detector::getPartialReadout(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReadNLines, pos); +} + +void Detector::setPartialReadout(const int lines, Positions pos) { + pimpl->Parallel(&slsDetector::setReadNLines, pos, lines); +} + +Result Detector::getInterruptSubframe(Positions pos) const { + return pimpl->Parallel(&slsDetector::getInterruptSubframe, pos); +} + +void Detector::setInterruptSubframe(const bool enable, Positions pos) { + pimpl->Parallel(&slsDetector::setInterruptSubframe, pos, enable); +} + +Result Detector::getMeasuredPeriod(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, + defs::MEASURED_PERIOD); +} + +Result Detector::getMeasuredSubFramePeriod(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, + defs::MEASURED_SUBPERIOD); +} + +Result Detector::getActive(Positions pos) const { + return pimpl->Parallel(&slsDetector::activate, pos, -1); +} + +void Detector::setActive(bool active, Positions pos) { + pimpl->Parallel(&slsDetector::activate, pos, static_cast(active)); +} + +Result Detector::getRxPadDeactivatedMode(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDeactivatedRxrPaddingMode, pos, -1); +} + +void Detector::setRxPadDeactivatedMode(bool pad, Positions pos) { + pimpl->Parallel(&slsDetector::setDeactivatedRxrPaddingMode, pos, + static_cast(pad)); +} + +Result Detector::getPartialReset(Positions pos) const { + return pimpl->Parallel(&slsDetector::setCounterBit, pos, -1); +} + +void Detector::setPartialReset(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setCounterBit, pos, !value); +} + +void Detector::pulsePixel(int n, defs::xy pixel, Positions pos) { + pimpl->Parallel(&slsDetector::pulsePixel, pos, n, pixel.x, pixel.y); +} + +void Detector::pulsePixelNMove(int n, defs::xy pixel, Positions pos) { + pimpl->Parallel(&slsDetector::pulsePixelNMove, pos, n, pixel.x, pixel.y); +} + +void Detector::pulseChip(int n, Positions pos) { + pimpl->Parallel(&slsDetector::pulseChip, pos, n); +} + +Result Detector::getQuad(Positions pos) const { + return pimpl->Parallel(&slsDetector::getQuad, pos); +} + +void Detector::setQuad(const bool value) { pimpl->setQuad(value); } + +// Jungfrau Specific + +Result Detector::getThresholdTemperature(Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::setThresholdTemperature, pos, -1); + for (auto &it : res) { + it /= 1000; + } + return res; +} + +void Detector::setThresholdTemperature(int temp, Positions pos) { + pimpl->Parallel(&slsDetector::setThresholdTemperature, pos, temp * 1000); +} + +Result Detector::getTemperatureControl(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTemperatureControl, pos, -1); +} + +void Detector::setTemperatureControl(bool enable, Positions pos) { + pimpl->Parallel(&slsDetector::setTemperatureControl, pos, + static_cast(enable)); +} + +Result Detector::getTemperatureEvent(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTemperatureEvent, pos, -1); +} + +void Detector::resetTemperatureEvent(Positions pos) { + pimpl->Parallel(&slsDetector::setTemperatureEvent, pos, 0); +} + +Result Detector::getPowerChip(Positions pos) const { + return pimpl->Parallel(&slsDetector::powerChip, pos, -1); +} + +void Detector::setPowerChip(bool on, Positions pos) { + if (on && pimpl->size() > 3) { + for (unsigned int i = 0; i != pimpl->size(); ++i) { + pimpl->powerChip(static_cast(on), i); + usleep(1000 * 1000); + } + } else { + pimpl->Parallel(&slsDetector::powerChip, pos, static_cast(on)); + } +} + +Result Detector::getAutoCompDisable(Positions pos) const { + return pimpl->Parallel(&slsDetector::setAutoComparatorDisableMode, pos, -1); +} + +void Detector::setAutoCompDisable(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setAutoComparatorDisableMode, pos, + static_cast(value)); +} + +Result Detector::getNumberOfAdditionalStorageCells() const { + return pimpl->Parallel(&slsDetector::setTimer, {}, + defs::STORAGE_CELL_NUMBER, -1); +} + +void Detector::setNumberOfAdditionalStorageCells(int64_t value) { + pimpl->Parallel(&slsDetector::setTimer, {}, defs::STORAGE_CELL_NUMBER, + value); +} + +Result Detector::getStorageCellStart(Positions pos) const { + return pimpl->Parallel(&slsDetector::setStoragecellStart, pos, -1); +} + +void Detector::setStoragecellStart(int cell, Positions pos) { + pimpl->Parallel(&slsDetector::setStoragecellStart, pos, cell); +} + +Result Detector::getStorageCellDelay(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimer, pos, + defs::STORAGE_CELL_DELAY, -1); +} + +void Detector::setStorageCellDelay(ns value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimer, pos, defs::STORAGE_CELL_DELAY, + value.count()); +} + +// Gotthard Specific + +Result Detector::getROI(Positions pos) const { + return pimpl->Parallel(&slsDetector::getROI, pos); +} + +void Detector::setROI(defs::ROI value, int moduleId) { + if (moduleId < 0 && size() > 1) { + throw RuntimeError("Cannot set ROI for all modules simultaneously"); + } + pimpl->Parallel(&slsDetector::setROI, {moduleId}, value); +} + +Result Detector::getExptimeLeft(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, + defs::ACQUISITION_TIME); +} + +Result Detector::getPeriodLeft(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, defs::FRAME_PERIOD); +} + +Result +Detector::getExternalSignalFlags(Positions pos) const { + return pimpl->Parallel(&slsDetector::setExternalSignalFlags, pos, + defs::GET_EXTERNAL_SIGNAL_FLAG); +} + +void Detector::setExternalSignalFlags(defs::externalSignalFlag value, + Positions pos) { + pimpl->Parallel(&slsDetector::setExternalSignalFlags, pos, value); +} + +Result Detector::getImageTestMode(Positions pos) { + return pimpl->Parallel(&slsDetector::digitalTest, pos, defs::IMAGE_TEST, + -1); +} + +Result Detector::setImageTestMode(int value, Positions pos) { + return pimpl->Parallel(&slsDetector::digitalTest, pos, defs::IMAGE_TEST, + value); +} + +// CTB Specific + +Result Detector::getNumberOfAnalogSamples(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimer, pos, defs::ANALOG_SAMPLES, + -1); +} + +void Detector::setNumberOfAnalogSamples(int64_t value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimer, pos, defs::ANALOG_SAMPLES, value); +} + +Result Detector::getNumberOfDigitalSamples(Positions pos) const { + return pimpl->Parallel(&slsDetector::setTimer, pos, defs::DIGITAL_SAMPLES, + -1); +} + +void Detector::setNumberOfDigitalSamples(int64_t value, Positions pos) { + pimpl->Parallel(&slsDetector::setTimer, pos, defs::DIGITAL_SAMPLES, value); +} + +Result Detector::getReadoutMode(Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::setReadOutFlags, pos, + defs::GET_READOUT_FLAGS); + for (auto &it : res) { + if (it & defs::ANALOG_AND_DIGITAL) { + it = 2; + } else if (it & defs::DIGITAL_ONLY) { + it = 1; + } else if (it == defs::NORMAL_READOUT) { + it = 0; + } else { + throw RuntimeError("Unknown Signal Type"); + } + } + return res; +} + +void Detector::setReadoutMode(int value, Positions pos) { + defs::readOutFlags flag; + switch (value) { + case 0: + flag = defs::NORMAL_READOUT; + break; + case 1: + flag = defs::DIGITAL_ONLY; + break; + case 2: + flag = defs::ANALOG_AND_DIGITAL; + break; + default: + throw RuntimeError("Unknown Signal Type"); + } + pimpl->Parallel(&slsDetector::setReadOutFlags, pos, flag); +} + +Result Detector::getDBITPhase(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, -1, + 0); +} + +void Detector::setDBITPhase(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, value, 0); +} + +Result Detector::getMaxDBITPhaseShift(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, + defs::MAX_DBIT_PHASE_SHIFT, -1, 0); +} + +Result Detector::getDBITPhaseInDegrees(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, -1, + 1); +} + +void Detector::setDBITPhaseInDegrees(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, value, 1); +} + +Result Detector::getADCClock(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_CLOCK, -1, 0); +} + +void Detector::setADCClock(int value_in_MHz, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_CLOCK, value_in_MHz, + 0); +} + +Result Detector::getDBITClock(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_CLOCK, -1, + 0); +} + +void Detector::setDBITClock(int value_in_MHz, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_CLOCK, value_in_MHz, + 0); +} + +Result Detector::getRUNClock(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, -1, + 0); +} + +void Detector::setRUNClock(int value_in_MHz, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, + value_in_MHz, 0); +} + +Result Detector::getSYNCClock(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::SYNC_CLOCK, -1, + 0); +} + +Result Detector::getADCPipeline(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PIPELINE, -1, + 0); +} + +void Detector::setADCPipeline(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PIPELINE, value, 0); +} + +Result Detector::getDBITPipeline(Positions pos) const { + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PIPELINE, -1, + 0); +} + +void Detector::setDBITPipeline(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PIPELINE, value, 0); +} + +Result Detector::getVrefVoltage(bool mV, Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, defs::ADC_VPP, mV); +} + +void Detector::setVrefVoltage(int value, bool mV, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, defs::ADC_VPP, mV); +} + +Result Detector::getVoltage(defs::dacIndex index, Positions pos) const { + switch (index) { + case defs::V_LIMIT: + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Voltage Index"); + } + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, index, 1); +} + +void Detector::setVoltage(int value, defs::dacIndex index, Positions pos) { + switch (index) { + case defs::V_LIMIT: + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Voltage Index"); + } + pimpl->Parallel(&slsDetector::setDAC, pos, value, index, 1); +} + +Result Detector::getMeasuredVoltage(defs::dacIndex index, + Positions pos) const { + switch (index) { + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Voltage Index"); + } + return pimpl->Parallel(&slsDetector::getADC, pos, index); +} + +Result Detector::getMeasuredCurrent(defs::dacIndex index, + Positions pos) const { + switch (index) { + case defs::I_POWER_A: + case defs::I_POWER_B: + case defs::I_POWER_C: + case defs::I_POWER_D: + case defs::I_POWER_IO: + break; + default: + throw RuntimeError("Unknown Current Index"); + } + return pimpl->Parallel(&slsDetector::getADC, pos, index); +} + +Result Detector::getSlowADC(defs::dacIndex index, Positions pos) const { + if (index < defs::SLOW_ADC0 || index > defs::SLOW_ADC7) { + throw RuntimeError("Unknown Slow ADC Index"); + } + return pimpl->Parallel(&slsDetector::getADC, pos, index); +} + +Result Detector::getADCEnableMask(Positions pos) const { + return pimpl->Parallel(&slsDetector::getADCEnableMask, pos); +} + +void Detector::setADCEnableMask(uint32_t mask, Positions pos) { + pimpl->Parallel(&slsDetector::setADCEnableMask, pos, mask); +} + +Result Detector::getADCInvert(Positions pos) const { + return pimpl->Parallel(&slsDetector::getADCInvert, pos); +} + +void Detector::setADCInvert(uint32_t value, Positions pos) { + pimpl->Parallel(&slsDetector::setADCInvert, pos, value); +} + +Result Detector::getExternalSamplingSource(Positions pos) const { + return pimpl->Parallel(&slsDetector::getExternalSamplingSource, pos); +} + +void Detector::setExternalSamplingSource(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setExternalSamplingSource, pos, value); +} + +Result Detector::getExternalSampling(Positions pos) const { + return pimpl->Parallel(&slsDetector::getExternalSampling, pos); +} + +void Detector::setExternalSampling(bool value, Positions pos) { + pimpl->Parallel(&slsDetector::setExternalSampling, pos, value); +} + +Result> Detector::getRxDbitList(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverDbitList, pos); +} + +void Detector::setRxDbitList(std::vector list, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverDbitList, pos, list); +} + +Result Detector::getRxDbitOffset(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverDbitOffset, pos); +} + +void Detector::setRxDbitOffset(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setReceiverDbitOffset, pos, value); +} + +void Detector::setDigitalIODelay(uint64_t pinMask, int delay, Positions pos) { + pimpl->Parallel(&slsDetector::setDigitalIODelay, pos, pinMask, delay); +} + +Result Detector::getLEDEnable(Positions pos) const { + return pimpl->Parallel(&slsDetector::setLEDEnable, pos, -1); +} + +void Detector::setLEDEnable(bool enable, Positions pos) { + pimpl->Parallel(&slsDetector::setLEDEnable, pos, static_cast(enable)); +} + +// Pattern + +void Detector::setPattern(const std::string &fname, Positions pos) { + pimpl->Parallel(&slsDetector::setPattern, pos, fname); +} + +Result Detector::getPatternIOControl(Positions pos) const { + return pimpl->Parallel(&slsDetector::setPatternIOControl, pos, -1); +} + +void Detector::setPatternIOControl(uint64_t word, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternIOControl, pos, word); +} + +Result Detector::getPatternClockControl(Positions pos) const { + return pimpl->Parallel(&slsDetector::setPatternClockControl, pos, -1); +} + +void Detector::setPatternClockControl(uint64_t word, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternClockControl, pos, word); +} + +void Detector::setPatternWord(int addr, uint64_t word, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternWord, pos, addr, word); +} + +Result> Detector::getPatternLoops(int level, + Positions pos) const { + return pimpl->Parallel(&slsDetector::setPatternLoops, pos, level, -1, -1, + -1); +} + +void Detector::setPatternLoops(int level, int start, int stop, int n, + Positions pos) { + pimpl->Parallel(&slsDetector::setPatternLoops, pos, level, start, stop, n); +} + +Result Detector::getPatternWaitAddr(int level, Positions pos) const { + return pimpl->Parallel(&slsDetector::setPatternWaitAddr, pos, level, -1); +} + +void Detector::setPatternWaitAddr(int level, int addr, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternWaitAddr, pos, level, addr); +} + +Result Detector::getPatternWaitTime(int level, Positions pos) const { + return pimpl->Parallel(&slsDetector::setPatternWaitTime, pos, level, -1); +} + +void Detector::setPatternWaitTime(int level, uint64_t t, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternWaitTime, pos, level, t); +} + +Result Detector::getPatternMask(Positions pos) { + return pimpl->Parallel(&slsDetector::getPatternMask, pos); +} + +void Detector::setPatternMask(uint64_t mask, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternMask, pos, mask); +} + +Result Detector::getPatternBitMask(Positions pos) const { + return pimpl->Parallel(&slsDetector::getPatternBitMask, pos); +} + +void Detector::setPatternBitMask(uint64_t mask, Positions pos) { + pimpl->Parallel(&slsDetector::setPatternBitMask, pos, mask); +} + +// Moench + +Result Detector::getAdditionalJsonHeader(Positions pos) const { + return pimpl->Parallel(&slsDetector::getAdditionalJsonHeader, pos); +} + +void Detector::setAdditionalJsonHeader(const std::string &jsonheader, + Positions pos) { + pimpl->Parallel(&slsDetector::setAdditionalJsonHeader, pos, jsonheader); +} + +Result Detector::getAdditionalJsonParameter(const std::string &key, + Positions pos) const { + return pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos, key); +} + +void Detector::setAdditionalJsonParameter(const std::string &key, + const std::string &value, + Positions pos) { + pimpl->Parallel(&slsDetector::setAdditionalJsonParameter, pos, key, value); +} + +Result Detector::getDetectorMinMaxEnergyThreshold(const bool isEmax, + Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos, + isEmax ? "emax" : "emin"); + Result intResult; + try { + for (unsigned int i = 0; i < res.size(); ++i) { + intResult[i] = stoi(res[i]); + } + } catch (...) { + throw RuntimeError( + "Cannot find or convert emin/emax string to integer"); + } + return intResult; +} + +void Detector::setDetectorMinMaxEnergyThreshold(const bool isEmax, + const int value, + Positions pos) { + pimpl->Parallel(&slsDetector::setAdditionalJsonParameter, pos, + isEmax ? "emax" : "emin", std::to_string(value)); +} + +Result Detector::getFrameMode(Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos, + "frameMode"); + Result intResult; + try { + for (unsigned int i = 0; i < res.size(); ++i) { + intResult[i] = defs::getFrameModeType(res[i]); + } + } catch (...) { + throw RuntimeError( + "Cannot find or convert frameMode string to integer"); + } + return intResult; +} + +void Detector::setFrameMode(defs::frameModeType value, Positions pos) { + pimpl->Parallel(&slsDetector::setAdditionalJsonParameter, pos, "frameMode", + defs::getFrameModeType(value)); +} + +Result Detector::getDetectorMode(Positions pos) const { + auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos, + "detectorMode"); + Result intResult; + try { + for (unsigned int i = 0; i < res.size(); ++i) { + intResult[i] = defs::getDetectorModeType(res[i]); + } + } catch (...) { + throw RuntimeError( + "Cannot find or convert detectorMode string to integer"); + } + return intResult; +} + +void Detector::setDetectorMode(defs::detectorModeType value, Positions pos) { + pimpl->Parallel(&slsDetector::setAdditionalJsonParameter, pos, + "detectorMode", defs::getDetectorModeType(value)); +} + +// Advanced + +void Detector::programFPGA(const std::string &fname, Positions pos) { + FILE_LOG(logINFO) + << "Updating Firmware. This can take awhile. Please be patient..."; + std::vector buffer = pimpl->readPofFile(fname); + pimpl->Parallel(&slsDetector::programFPGA, pos, buffer); +} + +void Detector::resetFPGA(Positions pos) { + pimpl->Parallel(&slsDetector::resetFPGA, pos); +} + +void Detector::copyDetectorServer(const std::string &fname, + const std::string &hostname, Positions pos) { + pimpl->Parallel(&slsDetector::copyDetectorServer, pos, fname, hostname); + rebootController(pos); +} + +void Detector::rebootController(Positions pos) { + pimpl->Parallel(&slsDetector::rebootController, pos); +} + +void Detector::updateFirmwareAndServer(const std::string &sname, + const std::string &hostname, + const std::string &fname, + Positions pos) { + pimpl->Parallel(&slsDetector::copyDetectorServer, pos, fname, hostname); + programFPGA(fname, pos); + rebootController(pos); +} + +Result Detector::readRegister(uint32_t addr, Positions pos) const { + return pimpl->Parallel(&slsDetector::readRegister, pos, addr); +} + +void Detector::writeRegister(uint32_t addr, uint32_t val, Positions pos) { + pimpl->Parallel(&slsDetector::writeRegister, pos, addr, val); +} + +void Detector::setBit(uint32_t addr, int bitnr, Positions pos) { + pimpl->Parallel(&slsDetector::setBit, pos, addr, bitnr); +} + +void Detector::clearBit(uint32_t addr, int bitnr, Positions pos) { + pimpl->Parallel(&slsDetector::clearBit, pos, addr, bitnr); +} + +Result Detector::executeFirmwareTest(Positions pos) { + return pimpl->Parallel(&slsDetector::digitalTest, pos, + defs::DETECTOR_FIRMWARE_TEST, -1); +} + +Result Detector::executeBusTest(Positions pos) { + return pimpl->Parallel(&slsDetector::digitalTest, pos, + defs::DETECTOR_BUS_TEST, -1); +} + +void Detector::writeAdcRegister(uint32_t addr, uint32_t value, Positions pos) { + pimpl->Parallel(&slsDetector::writeAdcRegister, pos, addr, value); +} + +// Insignificant + +Result Detector::getControlPort(Positions pos) const { + return pimpl->Parallel(&slsDetector::getControlPort, pos); +} + +void Detector::setControlPort(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setControlPort, pos, value); +} + +Result Detector::getStopPort(Positions pos) const { + return pimpl->Parallel(&slsDetector::getStopPort, pos); +} + +void Detector::setStopPort(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setStopPort, pos, value); +} + +Result Detector::getDetectorLock(Positions pos) const { + return pimpl->Parallel(&slsDetector::lockServer, pos, -1); +} + +void Detector::setDetectorLock(bool lock, Positions pos) { + pimpl->Parallel(&slsDetector::lockServer, pos, static_cast(lock)); +} + +Result Detector::getLastClientIP(Positions pos) const { + return pimpl->Parallel(&slsDetector::getLastClientIP, pos); +} + +void Detector::executeCommand(const std::string &value, Positions pos) { + pimpl->Parallel(&slsDetector::execCommand, pos, value); +} + +Result Detector::getNumberOfFramesFromStart(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, + defs::FRAMES_FROM_START); +} + +Result Detector::getActualTime(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, defs::ACTUAL_TIME); +} + +Result Detector::getMeasurementTime(Positions pos) const { + return pimpl->Parallel(&slsDetector::getTimeLeft, pos, + defs::MEASUREMENT_TIME); +} + +std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); } + +Result Detector::getRxCurrentFrameIndex(Positions pos) const { + return pimpl->Parallel(&slsDetector::getReceiverCurrentFrameIndex, pos); +} + +std::vector Detector::getPortNumbers(int start_port) { + int num_sockets_per_detector = 1; + switch (getDetectorType({}).squash()) { + case defs::EIGER: + num_sockets_per_detector *= 2; + break; + case defs::JUNGFRAU: + if (getNumberofUDPInterfaces({}).squash() == 2) { + num_sockets_per_detector *= 2; + } + break; + default: + break; + } + std::vector res; + for (int idet = 0; idet < size(); ++idet) { + res.push_back(start_port + (idet * num_sockets_per_detector)); + } + return res; } } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 0c7b14feb..2183dcec7 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -131,37 +131,6 @@ void multiSlsDetector::parallelCall( return; } -int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX, - int &channelY) { - channelX = -1; - channelY = -1; - // loop over - for (size_t i = 0; i < detectors.size(); ++i) { - int x = detectors[i]->getDetectorOffset(X); - int y = detectors[i]->getDetectorOffset(Y); - // check x offset range - if ((offsetX >= x) && - (offsetX < - (x + detectors[i]->getTotalNumberOfChannelsInclGapPixels(X)))) { - if (offsetY == -1) { - channelX = offsetX - x; - return i; - } else { - // check y offset range - if ((offsetY >= y) && - (offsetY < - (y + detectors[i]->getTotalNumberOfChannelsInclGapPixels( - Y)))) { - channelX = offsetX - x; - channelY = offsetY - y; - return i; - } - } - } - } - return -1; -} - void multiSlsDetector::setAcquiringFlag(bool flag) { multi_shm()->acquiringFlag = flag; } @@ -170,18 +139,6 @@ bool multiSlsDetector::getAcquiringFlag() const { return multi_shm()->acquiringFlag; } -bool multiSlsDetector::isAcquireReady() { - if (multi_shm()->acquiringFlag) { - FILE_LOG(logWARNING) - << "Acquire has already started. " - "If previous acquisition terminated unexpectedly, " - "reset busy flag to restart.(sls_detector_put busy 0)"; - return FAIL != 0u; - } - multi_shm()->acquiringFlag = true; - return OK != 0u; -} - void multiSlsDetector::checkDetectorVersionCompatibility(int detPos) { if (detPos >= 0) { detectors[detPos]->checkDetectorVersionCompatibility(); @@ -276,11 +233,24 @@ std::string multiSlsDetector::getUserDetails() { std::ostringstream sstream; sstream << "\nHostname: "; for (auto &d : detectors) { - sstream << (d->isFixedPatternSharedMemoryCompatible() ? d->getHostname() : "Unknown") << "+"; + sstream << (d->isFixedPatternSharedMemoryCompatible() ? d->getHostname() + : "Unknown") + << "+"; } sstream << "\nType: "; - for (auto &d : detectors) { - sstream << (d->isFixedPatternSharedMemoryCompatible() ? d->getDetectorTypeAsString() : "Unknown") << "+"; + // get type from multi shm + if (multi_shm()->shmversion >= MULTI_SHMAPIVERSION) { + sstream << slsDetectorDefs::detectorTypeToString( + getDetectorTypeAsEnum()); + } + // get type from slsdet shm + else { + for (auto &d : detectors) { + sstream << (d->isFixedPatternSharedMemoryCompatible() + ? d->getDetectorTypeAsString() + : "Unknown") + << "+"; + } } sstream << "\nPID: " << multi_shm()->lastPID @@ -311,21 +281,11 @@ void multiSlsDetector::initSharedMemory(bool verify) { void multiSlsDetector::initializeDetectorStructure() { multi_shm()->shmversion = MULTI_SHMVERSION; multi_shm()->numberOfDetectors = 0; - multi_shm()->numberOfDetector[X] = 0; - multi_shm()->numberOfDetector[Y] = 0; - multi_shm()->dataBytes = 0; - multi_shm()->dataBytesInclGapPixels = 0; - multi_shm()->numberOfChannels = 0; - multi_shm()->numberOfChannel[X] = 0; - multi_shm()->numberOfChannel[Y] = 0; - multi_shm()->numberOfChannelInclGapPixels[X] = 0; - multi_shm()->numberOfChannelInclGapPixels[Y] = 0; - multi_shm()->maxNumberOfChannelsPerDetector[X] = 0; - multi_shm()->maxNumberOfChannelsPerDetector[Y] = 0; - for (int64_t &i : multi_shm()->timerValue) { - i = 0; - } - + multi_shm()->multiDetectorType = GENERIC; + multi_shm()->numberOfDetector.x = 0; + multi_shm()->numberOfDetector.y = 0; + multi_shm()->numberOfChannels.x = 0; + multi_shm()->numberOfChannels.y = 0; multi_shm()->acquiringFlag = false; multi_shm()->receiver_upstream = false; } @@ -344,9 +304,6 @@ void multiSlsDetector::initializeMembers(bool verify) { throw; } } - - // depend on number of detectors - updateOffsets(); } void multiSlsDetector::updateUserdetails() { @@ -362,6 +319,18 @@ void multiSlsDetector::updateUserdetails() { } } +bool multiSlsDetector::isAcquireReady() { + if (multi_shm()->acquiringFlag) { + FILE_LOG(logWARNING) + << "Acquire has already started. " + "If previous acquisition terminated unexpectedly, " + "reset busy flag to restart.(sls_detector_put busy 0)"; + return FAIL != 0u; + } + multi_shm()->acquiringFlag = true; + return OK != 0u; +} + std::string multiSlsDetector::exec(const char *cmd) { int bufsize = 128; char buffer[bufsize]; @@ -385,6 +354,32 @@ std::string multiSlsDetector::exec(const char *cmd) { return result; } +void multiSlsDetector::setVirtualDetectorServers(const int numdet, + const int port) { + std::vector hostnames; + for (int i = 0; i < numdet; ++i) { + // * 2 is for control and stop port + hostnames.push_back(std::string("localhost:") + + std::to_string(port + i * 2)); + } + setHostname(hostnames); +} + +void multiSlsDetector::setHostname(const std::vector &name) { + // this check is there only to allow the previous detsizechan command + if (multi_shm()->numberOfDetectors != 0) { + FILE_LOG(logWARNING) + << "There are already detector(s) in shared memory." + "Freeing Shared memory now."; + freeSharedMemory(); + setupMultiDetector(); + } + for (const auto &hostname : name) { + addSlsDetector(hostname); + } + updateDetectorSize(); +} + void multiSlsDetector::setHostname(const char *name, int detPos) { // single if (detPos >= 0) { @@ -412,53 +407,89 @@ std::string multiSlsDetector::getHostname(int detPos) const { // multi auto r = serialCall(&slsDetector::getHostname); - return sls::concatenateIfDifferent(r); + return sls::concatenateNonEmptyStrings(r); } void multiSlsDetector::addMultipleDetectors(const char *name) { for (const auto &hostname : sls::split(name, '+')) { addSlsDetector(hostname); } - - updateOffsets(); + updateDetectorSize(); } void multiSlsDetector::addSlsDetector(const std::string &hostname) { FILE_LOG(logDEBUG1) << "Adding detector " << hostname; - for (auto &d : detectors) { - if (d->getHostname() == hostname) { - FILE_LOG(logWARNING) - << "Detector " << hostname - << "already part of the multiDetector!" << std::endl - << "Remove it before adding it back in a new position!"; - return; + int port = DEFAULT_PORTNO; + std::string host = hostname; + auto res = sls::split(hostname, ':'); + if (res.size() > 1) { + host = res[0]; + port = std::stoi(res[1]); + } + + if (host != "localhost") { + for (auto &d : detectors) { + if (d->getHostname() == host) { + FILE_LOG(logWARNING) + << "Detector " << host + << "already part of the multiDetector!" << std::endl + << "Remove it before adding it back in a new position!"; + return; + } } } // get type by connecting - detectorType type = - slsDetector::getTypeFromDetector(hostname, DEFAULT_PORTNO); + detectorType type = slsDetector::getTypeFromDetector(host, port); int pos = (int)detectors.size(); detectors.push_back( sls::make_unique(type, multiId, pos, false)); multi_shm()->numberOfDetectors = detectors.size(); - multi_shm()->dataBytes += detectors[pos]->getDataBytes(); - multi_shm()->dataBytesInclGapPixels += - detectors[pos]->getDataBytesInclGapPixels(); - multi_shm()->numberOfChannels += detectors[pos]->getTotalNumberOfChannels(); - - detectors[pos]->setHostname(hostname); + detectors[pos]->setControlPort(port); + detectors[pos]->setStopPort(port + 1); + detectors[pos]->setHostname(host); + multi_shm()->multiDetectorType = + getDetectorTypeAsEnum(-1); // -1 needed here } -void multiSlsDetector::addSlsDetector(std::unique_ptr det) { - detectors.push_back(std::move(det)); - multi_shm()->numberOfDetectors = detectors.size(); - multi_shm()->dataBytes += detectors.back()->getDataBytes(); - multi_shm()->dataBytesInclGapPixels += - detectors.back()->getDataBytesInclGapPixels(); - multi_shm()->numberOfChannels += - detectors.back()->getTotalNumberOfChannels(); +void multiSlsDetector::updateDetectorSize() { + FILE_LOG(logDEBUG) << "Updating Multi-Detector Size: " << size(); + + const slsDetectorDefs::xy det_size = detectors[0]->getNumberOfChannels(); + + int maxy = multi_shm()->numberOfChannels.y; + if (maxy == 0) { + maxy = det_size.y * size(); + } + + int ndety = maxy / det_size.y; + int ndetx = size() / ndety; + if ((maxy % det_size.y) > 0) { + ++ndetx; + } + + multi_shm()->numberOfDetector.x = ndetx; + multi_shm()->numberOfDetector.y = ndety; + multi_shm()->numberOfChannels.x = det_size.x * ndetx; + multi_shm()->numberOfChannels.y = det_size.y * ndety; + + FILE_LOG(logDEBUG) << "\n\tNumber of Detectors in X direction:" + << multi_shm()->numberOfDetector.x + << "\n\tNumber of Detectors in Y direction:" + << multi_shm()->numberOfDetector.y + << "\n\tNumber of Channels in X direction:" + << multi_shm()->numberOfChannels.x + << "\n\tNumber of Channels in Y direction:" + << multi_shm()->numberOfChannels.y; + + for (auto &d : detectors) { + d->updateMultiSize(multi_shm()->numberOfDetector); + } +} + +slsDetectorDefs::detectorType multiSlsDetector::getDetectorTypeAsEnum() const { + return multi_shm()->multiDetectorType; } slsDetectorDefs::detectorType @@ -484,68 +515,41 @@ std::string multiSlsDetector::getDetectorTypeAsString(int detPos) { return sls::concatenateIfDifferent(r); } -int multiSlsDetector::getNumberOfDetectors() const { return detectors.size(); } +size_t multiSlsDetector::size() const { return detectors.size(); } -int multiSlsDetector::getNumberOfDetectors(dimension d) const { - return multi_shm()->numberOfDetector[d]; +slsDetectorDefs::xy multiSlsDetector::getNumberOfDetectors() const { + return multi_shm()->numberOfDetector; } -void multiSlsDetector::getNumberOfDetectors(int &nx, int &ny) const { - nx = multi_shm()->numberOfDetector[X]; - ny = multi_shm()->numberOfDetector[Y]; -} - -int multiSlsDetector::getTotalNumberOfChannels(int detPos) { +slsDetectorDefs::xy multiSlsDetector::getNumberOfChannels(int detPos) const { // single if (detPos >= 0) { - return detectors[detPos]->getTotalNumberOfChannels(); + return detectors[detPos]->getNumberOfChannels(); } // multi return multi_shm()->numberOfChannels; } -int multiSlsDetector::getTotalNumberOfChannels(dimension d, int detPos) { - // single - if (detPos >= 0) { - return detectors[detPos]->getTotalNumberOfChannels(d); +void multiSlsDetector::setNumberOfChannels(const slsDetectorDefs::xy c) { + if (size() > 1) { + throw RuntimeError( + "Set the number of channels before setting hostname."); } - - // multi - return multi_shm()->numberOfChannel[d]; -} - -int multiSlsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d, - int detPos) { - // single - if (detPos >= 0) { - return detectors[detPos]->getTotalNumberOfChannelsInclGapPixels(d); - } - - // multi - return multi_shm()->numberOfChannelInclGapPixels[d]; -} - -int multiSlsDetector::getMaxNumberOfChannelsPerDetector(dimension d) { - return multi_shm()->maxNumberOfChannelsPerDetector[d]; -} - -int multiSlsDetector::setMaxNumberOfChannelsPerDetector(dimension d, int i) { - multi_shm()->maxNumberOfChannelsPerDetector[d] = i; - return multi_shm()->maxNumberOfChannelsPerDetector[d]; + multi_shm()->numberOfChannels = c; } int multiSlsDetector::getQuad(int detPos) { int retval = detectors[0]->getQuad(); - if (retval && getNumberOfDetectors() > 1) { + if (retval && size() > 1) { throw RuntimeError("Quad type is available only for 1 Eiger Quad Half " - "module, but it Quad is enabled for 1st readout"); + "module, but Quad is enabled for 1st readout"); } return retval; } void multiSlsDetector::setQuad(const bool enable, int detPos) { - if (enable && getNumberOfDetectors() > 1) { + if (enable && size() > 1) { throw RuntimeError("Cannot set Quad type as it is available only for 1 " "Eiger Quad Half module."); } @@ -574,184 +578,6 @@ int multiSlsDetector::getReadNLines(int detPos) { return sls::minusOneIfDifferent(r); } -int multiSlsDetector::getDetectorOffset(dimension d, int detPos) { - return detectors[detPos]->getDetectorOffset(d); -} - -void multiSlsDetector::setDetectorOffset(dimension d, int off, int detPos) { - detectors[detPos]->setDetectorOffset(d, off); -} - -void multiSlsDetector::updateOffsets() { - FILE_LOG(logDEBUG1) << "Updating Multi-Detector Offsets"; - - int offsetX = 0, offsetY = 0, numX = 0, numY = 0; - int maxChanX = multi_shm()->maxNumberOfChannelsPerDetector[X]; - int maxChanY = multi_shm()->maxNumberOfChannelsPerDetector[Y]; - int prevChanX = 0; - int prevChanY = 0; - bool firstTime = true; - - multi_shm()->numberOfChannel[X] = 0; - multi_shm()->numberOfChannel[Y] = 0; - multi_shm()->numberOfDetector[X] = 0; - multi_shm()->numberOfDetector[Y] = 0; - - // gap pixels - int offsetX_gp = 0, offsetY_gp = 0, numX_gp = 0, numY_gp = 0; - int prevChanX_gp = 0, prevChanY_gp = 0; - multi_shm()->numberOfChannelInclGapPixels[X] = 0; - multi_shm()->numberOfChannelInclGapPixels[Y] = 0; - - for (size_t idet = 0; idet < detectors.size(); ++idet) { - FILE_LOG(logDEBUG1) - << "offsetX:" << offsetX << " prevChanX:" << prevChanX - << " offsetY:" << offsetY << " prevChanY:" << prevChanY - << " offsetX_gp:" << offsetX_gp << " prevChanX_gp:" << prevChanX_gp - << " offsetY_gp:" << offsetY_gp << " prevChanY_gp:" << prevChanY_gp; - - // incrementing in both direction - if (firstTime) { - // incrementing in both directions - firstTime = false; - if ((maxChanX > 0) && - ((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) > - maxChanX)) { - FILE_LOG(logWARNING) - << "\nDetector[" << idet - << "] exceeds maximum channels " - "allowed for complete detector set in X dimension!"; - } - if ((maxChanY > 0) && - ((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) > - maxChanY)) { - FILE_LOG(logERROR) - << "\nDetector[" << idet - << "] exceeds maximum channels " - "allowed for complete detector set in Y dimension!"; - } - prevChanX = detectors[idet]->getTotalNumberOfChannels(X); - prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); - prevChanX_gp = - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); - prevChanY_gp = - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); - numX += detectors[idet]->getTotalNumberOfChannels(X); - numY += detectors[idet]->getTotalNumberOfChannels(Y); - numX_gp += - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); - numY_gp += - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); - ++multi_shm()->numberOfDetector[X]; - ++multi_shm()->numberOfDetector[Y]; - FILE_LOG(logDEBUG1) << "incrementing in both direction"; - } - - // incrementing in y direction - else if ((maxChanY == -1) || - ((maxChanY > 0) && ((offsetY + prevChanY + - detectors[idet]->getTotalNumberOfChannels( - Y)) <= maxChanY))) { - offsetY += prevChanY; - offsetY_gp += prevChanY_gp; - prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); - prevChanY_gp = - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); - numY += detectors[idet]->getTotalNumberOfChannels(Y); - numY_gp += - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); - // increment in y again only in the first column (else you double - // increment) - if (multi_shm()->numberOfDetector[X] == 1) - ++multi_shm()->numberOfDetector[Y]; - FILE_LOG(logDEBUG1) << "incrementing in y direction"; - } - - // incrementing in x direction - else { - if ((maxChanX > 0) && - ((offsetX + prevChanX + - detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) { - FILE_LOG(logDEBUG1) - << "\nDetector[" << idet - << "] exceeds maximum channels " - "allowed for complete detector set in X dimension!"; - } - offsetY = 0; - offsetY_gp = 0; - prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); - prevChanY_gp = - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); - numY = 0; // assuming symmetry with this statement. - // whats on 1st column should be on 2nd column - numY_gp = 0; - offsetX += prevChanX; - offsetX_gp += prevChanX_gp; - prevChanX = detectors[idet]->getTotalNumberOfChannels(X); - prevChanX_gp = - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); - numX += detectors[idet]->getTotalNumberOfChannels(X); - numX_gp += - detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); - ++multi_shm()->numberOfDetector[X]; - FILE_LOG(logDEBUG1) << "incrementing in x direction"; - } - - double bytesperchannel = - (double)detectors[idet]->getDataBytes() / - (double)(detectors[idet]->getTotalNumberOfChannels(X) * - detectors[idet]->getTotalNumberOfChannels(Y)); - detectors[idet]->setDetectorOffset( - X, (bytesperchannel >= 1.0) ? offsetX_gp : offsetX); - detectors[idet]->setDetectorOffset( - Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY); - - FILE_LOG(logDEBUG1) << "Detector[" << idet << "] has offsets (" - << detectors[idet]->getDetectorOffset(X) << ", " - << detectors[idet]->getDetectorOffset(Y) << ")"; - // offsetY has been reset sometimes and offsetX the first time, - // but remember the highest values - if (numX > multi_shm()->numberOfChannel[X]) { - multi_shm()->numberOfChannel[X] = numX; - } - if (numY > multi_shm()->numberOfChannel[Y]) { - multi_shm()->numberOfChannel[Y] = numY; - } - if (numX_gp > multi_shm()->numberOfChannelInclGapPixels[X]) { - multi_shm()->numberOfChannelInclGapPixels[X] = numX_gp; - } - if (numY_gp > multi_shm()->numberOfChannelInclGapPixels[Y]) { - multi_shm()->numberOfChannelInclGapPixels[Y] = numY_gp; - } - } - FILE_LOG(logDEBUG1) - << "\n\tNumber of Channels in X direction:" - << multi_shm()->numberOfChannel[X] - << "\n\tNumber of Channels in Y direction:" - << multi_shm()->numberOfChannel[Y] - << "\n\tNumber of Channels in X direction with Gap Pixels:" - << multi_shm()->numberOfChannelInclGapPixels[X] - << "\n\tNumber of Channels in Y direction with Gap Pixels:" - << multi_shm()->numberOfChannelInclGapPixels[Y]; - - multi_shm()->numberOfChannels = - multi_shm()->numberOfChannel[0] * multi_shm()->numberOfChannel[1]; - - for (auto &d : detectors) { - d->updateMultiSize(multi_shm()->numberOfDetector[0], - multi_shm()->numberOfDetector[1]); - } -} - -std::string multiSlsDetector::checkOnline(int detPos) { - if (detPos >= 0) { - return detectors[detPos]->checkOnline(); - } - - auto r = parallelCall(&slsDetector::checkOnline); - return sls::concatenateNonEmptyStrings(r); -} - int multiSlsDetector::setControlPort(int port_number, int detPos) { if (detPos >= 0) { return detectors[detPos]->setControlPort(port_number); @@ -844,7 +670,7 @@ void multiSlsDetector::readConfigurationFile(const std::string &fname) { input_file.close(); } -int multiSlsDetector::writeConfigurationFile(const std::string &fname) { +void multiSlsDetector::writeConfigurationFile(const std::string &fname) { // TODO! make exception safe! const std::vector header{"detsizechan", "hostname"}; std::ofstream outfile; @@ -865,7 +691,6 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) { throw RuntimeError("Could not open configuration file " + fname + " for writing"); } - return OK; } slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int detPos) { @@ -1011,9 +836,6 @@ void multiSlsDetector::startAcquisition(int detPos) { } void multiSlsDetector::stopAcquisition(int detPos) { - // locks to synchronize using client->receiver simultaneously (processing - // thread) - std::lock_guard lock(mg); if (detPos >= 0) { detectors[detPos]->stopAcquisition(); } else { @@ -1064,7 +886,7 @@ void multiSlsDetector::readAll(int detPos) { } // multi - parallelCall(&slsDetector::readAll); + parallelCall(&slsDetector::readAll); } void multiSlsDetector::configureMAC(int detPos) { @@ -1109,41 +931,12 @@ uint64_t multiSlsDetector::getStartingFrameNumber(int detPos) { int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) { // single if (detPos >= 0) { - // error for setting values individually - // FIXME: what else? and error code - if (t != -1) { - switch (index) { - case FRAME_NUMBER: - case CYCLES_NUMBER: - case STORAGE_CELL_NUMBER: - throw RuntimeError("Cannot set number of frames, cycles or " - "storage cells individually."); - default: - break; - } - } return detectors[detPos]->setTimer(index, t); } // multi auto r = parallelCall(&slsDetector::setTimer, index, t); - int64_t ret = sls::minusOneIfDifferent(r); - - // set progress - if (t != -1) { - switch (index) { - case FRAME_NUMBER: - case CYCLES_NUMBER: - case STORAGE_CELL_NUMBER: - setTotalProgress(); - break; - default: - break; - } - } - - multi_shm()->timerValue[index] = ret; - return ret; + return sls::minusOneIfDifferent(r); } int64_t multiSlsDetector::secondsToNanoSeconds(double t) { @@ -1204,10 +997,6 @@ int64_t multiSlsDetector::setNumberOfCycles(int64_t t, int detPos) { return setTimer(CYCLES_NUMBER, t, detPos); } -int64_t multiSlsDetector::setNumberOfGates(int64_t t, int detPos) { - return setTimer(GATES_NUMBER, t, detPos); -} - int64_t multiSlsDetector::setNumberOfStorageCells(int64_t t, int detPos) { return setTimer(STORAGE_CELL_NUMBER, t, detPos); } @@ -1266,24 +1055,17 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) { } // multi + int prevValue = -1; + auto temp = Parallel(&slsDetector::getDynamicRangeFromShm, {}); + if (temp.equal()) { + prevValue = temp.squash(); + } + auto r = parallelCall(&slsDetector::setDynamicRange, dr); int ret = sls::minusOneIfDifferent(r); - // update shm - int prevValue = multi_shm()->dataBytes; - int prevGValue = multi_shm()->dataBytesInclGapPixels; - multi_shm()->dataBytes = 0; - multi_shm()->dataBytesInclGapPixels = 0; - for (auto &d : detectors) { - multi_shm()->dataBytes += d->getDataBytes(); - multi_shm()->dataBytesInclGapPixels += d->getDataBytesInclGapPixels(); - } - - // if there was a change FIXME:add dr to sls shm and check that instead - if ((prevValue != multi_shm()->dataBytes) || - (prevGValue != multi_shm()->dataBytesInclGapPixels)) { - - updateOffsets(); + // change in dr + if (dr != -1 && dr != prevValue) { // update speed, check ratecorrection if (getDetectorTypeAsEnum() == EIGER) { @@ -1314,17 +1096,6 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) { return ret; } -int multiSlsDetector::getDataBytes(int detPos) { - // single - if (detPos >= 0) { - return detectors[detPos]->getDataBytes(); - } - - // multi - auto r = parallelCall(&slsDetector::getDataBytes); - return sls::sum(r); -} - int multiSlsDetector::setDAC(int val, dacIndex index, int mV, int detPos) { // single if (detPos >= 0) { @@ -1359,16 +1130,15 @@ int multiSlsDetector::getADC(dacIndex index, int detPos) { return sls::minusOneIfDifferent(r); } -slsDetectorDefs::externalCommunicationMode -multiSlsDetector::setExternalCommunicationMode(externalCommunicationMode pol, - int detPos) { +slsDetectorDefs::timingMode multiSlsDetector::setTimingMode(timingMode pol, + int detPos) { // single if (detPos >= 0) { - return detectors[detPos]->setExternalCommunicationMode(pol); + return detectors[detPos]->setTimingMode(pol); } // multi - auto r = parallelCall(&slsDetector::setExternalCommunicationMode, pol); + auto r = parallelCall(&slsDetector::setTimingMode, pol); return sls::minusOneIfDifferent(r); } @@ -1748,7 +1518,7 @@ int multiSlsDetector::getReceiverUDPPort2(int detPos) const { int multiSlsDetector::setNumberofUDPInterfaces(int n, int detPos) { - int previouslyClientStreaming = enableDataStreamingToClient(); + bool previouslyClientStreaming = enableDataStreamingToClient(); int previouslyReceiverStreaming = enableDataStreamingFromReceiver(); // single @@ -1761,7 +1531,7 @@ int multiSlsDetector::setNumberofUDPInterfaces(int n, int detPos) { auto r = parallelCall(&slsDetector::setNumberofUDPInterfaces, n); // redo the zmq sockets - if (previouslyClientStreaming != 0) { + if (previouslyClientStreaming) { enableDataStreamingToClient(0); enableDataStreamingToClient(1); } @@ -1813,7 +1583,7 @@ int multiSlsDetector::getSelectedUDPInterface(int detPos) const { void multiSlsDetector::setClientDataStreamingInPort(int i, int detPos) { if (i >= 0) { - int prev_streaming = enableDataStreamingToClient(); + bool prev_streaming = enableDataStreamingToClient(); // single if (detPos >= 0) { @@ -1833,7 +1603,7 @@ void multiSlsDetector::setClientDataStreamingInPort(int i, int detPos) { } } - if (prev_streaming != 0) { + if (prev_streaming) { enableDataStreamingToClient(0); enableDataStreamingToClient(1); } @@ -1894,7 +1664,7 @@ int multiSlsDetector::getReceiverStreamingPort(int detPos) { void multiSlsDetector::setClientDataStreamingInIP(const std::string &ip, int detPos) { if (ip.length() != 0u) { - int prev_streaming = enableDataStreamingToClient(-1); + bool prev_streaming = enableDataStreamingToClient(-1); // single if (detPos >= 0) { @@ -1907,7 +1677,7 @@ void multiSlsDetector::setClientDataStreamingInIP(const std::string &ip, } } - if (prev_streaming != 0) { + if (prev_streaming) { enableDataStreamingToClient(0); enableDataStreamingToClient(1); } @@ -2124,57 +1894,6 @@ int multiSlsDetector::digitalTest(digitalTestMode mode, int ival, int detPos) { return sls::minusOneIfDifferent(r); } -void multiSlsDetector::loadImageToDetector(imageType index, - const std::string &fname, - int detPos) { - // single - if (detPos >= 0) { - detectors[detPos]->loadImageToDetector(index, fname); - } - - // multi - - // read image for all - int nch = multi_shm()->numberOfChannels; - short int imageVals[nch]; - if (readDataFile(fname, imageVals, nch) < nch * (int)sizeof(short int)) { - throw RuntimeError("Could not open file or not enough data in file to " - "load image to detector."); - } - - // send image to all - for (size_t idet = 0; idet < detectors.size(); ++idet) { - detectors[idet]->sendImageToDetector(index, imageVals + idet * detectors[idet]->getTotalNumberOfChannels()); - } -} - -void multiSlsDetector::writeCounterBlockFile(const std::string &fname, - int startACQ, int detPos) { - // single - if (detPos >= 0) { - detectors[detPos]->writeCounterBlockFile(fname, startACQ); - } - - // multi - int nch = multi_shm()->numberOfChannels; - short int imageVals[nch]; - for (size_t idet = 0; idet < detectors.size(); ++idet) { - detectors[idet]->getCounterBlock( - imageVals + idet * detectors[idet]->getTotalNumberOfChannels(), - startACQ); - } -} - -void multiSlsDetector::resetCounterBlock(int startACQ, int detPos) { - // single - if (detPos >= 0) { - detectors[detPos]->resetCounterBlock(startACQ); - } - - // multi - parallelCall(&slsDetector::resetCounterBlock, startACQ); -} - int multiSlsDetector::setCounterBit(int i, int detPos) { // single if (detPos >= 0) { @@ -2186,318 +1905,40 @@ int multiSlsDetector::setCounterBit(int i, int detPos) { return sls::minusOneIfDifferent(r); } -void multiSlsDetector::verifyMinMaxROI(int n, ROI r[]) { - int temp; - for (int i = 0; i < n; ++i) { - if ((r[i].xmax) < (r[i].xmin)) { - temp = r[i].xmax; - r[i].xmax = r[i].xmin; - r[i].xmin = temp; - } - if ((r[i].ymax) < (r[i].ymin)) { - temp = r[i].ymax; - r[i].ymax = r[i].ymin; - r[i].ymin = temp; - } - } -} - -void multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) { +void multiSlsDetector::clearROI(int detPos) { // single if (detPos >= 0) { - detectors[detPos]->setROI(n, roiLimits); + detectors[detPos]->clearROI(); } // multi - int xmin = 0, xmax = 0, ymin = 0, ymax = 0, channelX = 0, channelY = 0, - idet = 0, lastChannelX = 0, lastChannelY = 0, index = 0, offsetX = 0, - offsetY = 0; - - bool invalidroi = false; - int ndet = detectors.size(); - ROI allroi[ndet][n]; - int nroi[ndet]; - for (int i = 0; i < ndet; ++i) { - nroi[i] = 0; - } - - if ((n < 0) || (roiLimits == nullptr)) { - throw RuntimeError("Cannot set ROI due to Invalid ROI"); - } - - // ensures min < max - verifyMinMaxROI(n, roiLimits); - FILE_LOG(logDEBUG1) << "Setting ROI for " << n << "rois:"; - for (int i = 0; i < n; ++i) { - FILE_LOG(logDEBUG1) - << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax - << "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax; - } - // for each roi - for (int i = 0; i < n; ++i) { - xmin = roiLimits[i].xmin; - xmax = roiLimits[i].xmax; - ymin = roiLimits[i].ymin; - ymax = roiLimits[i].ymax; - - if (getNumberOfDetectors() > 1) { - // check roi max values - idet = decodeNChannel(xmax, ymax, channelX, channelY); - FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl - << "det:" << idet << "\t" << xmax << "\t" - << ymax << "\t" << channelX << "\t" << channelY; - if (idet == -1) { - FILE_LOG(logERROR) << "invalid roi"; - continue; - } - - // split in x dir - while (xmin <= xmax) { - invalidroi = false; - ymin = roiLimits[i].ymin; - // split in y dir - while (ymin <= ymax) { - // get offset for each detector - idet = decodeNChannel(xmin, ymin, channelX, channelY); - FILE_LOG(logDEBUG1) - << "Decoded Channel min vals: " << std::endl - << "det:" << idet << "\t" << xmin << "\t" << ymin - << "\t" << channelX << "\t" << channelY; - if (idet < 0 || idet >= (int)detectors.size()) { - FILE_LOG(logDEBUG1) << "invalid roi"; - invalidroi = true; - break; - } - // get last channel for each det in x and y dir - lastChannelX = - (detectors[idet]->getTotalNumberOfChannelsInclGapPixels( - X)) - - 1; - lastChannelY = - (detectors[idet]->getTotalNumberOfChannelsInclGapPixels( - Y)) - - 1; - - offsetX = detectors[idet]->getDetectorOffset(X); - offsetY = detectors[idet]->getDetectorOffset(Y); - // at the end in x dir - if ((offsetX + lastChannelX) >= xmax) { - lastChannelX = xmax - offsetX; - } - // at the end in y dir - if ((offsetY + lastChannelY) >= ymax) { - lastChannelY = ymax - offsetY; - } - - FILE_LOG(logDEBUG1) - << "lastChannelX:" << lastChannelX << "\t" - << "lastChannelY:" << lastChannelY; - - // creating the list of roi for corresponding detector - index = nroi[idet]; - allroi[idet][index].xmin = channelX; - allroi[idet][index].xmax = lastChannelX; - allroi[idet][index].ymin = channelY; - allroi[idet][index].ymax = lastChannelY; - nroi[idet] = nroi[idet] + 1; - - ymin = lastChannelY + offsetY + 1; - if ((lastChannelY + offsetY) == ymax) { - ymin = ymax + 1; - } - - FILE_LOG(logDEBUG1) - << "nroi[idet]:" << nroi[idet] << "\tymin:" << ymin; - } - if (invalidroi) { - break; - } - - xmin = lastChannelX + offsetX + 1; - if ((lastChannelX + offsetX) == xmax) { - xmin = xmax + 1; - } - } - } else { // FIXME: check if xmax is greater? or reduce logic above? - idet = 0; - nroi[idet] = n; - index = 0; - allroi[idet][index].xmin = xmin; - allroi[idet][index].xmax = xmax; - allroi[idet][index].ymin = ymin; - allroi[idet][index].ymax = ymax; - // nroi[idet] = nroi[idet] + 1; - } - } - - FILE_LOG(logDEBUG1) << "Setting ROI :"; - for (size_t i = 0; i < detectors.size(); ++i) { - FILE_LOG(logDEBUG1) << "detector " << i; - for (int j = 0; j < nroi[i]; ++j) { - FILE_LOG(logDEBUG1) - << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t" - << allroi[i][j].ymin << "\t" << allroi[i][j].ymax; - } - } - - // settings the rois for each detector - for (size_t i = 0; i != detectors.size(); ++i) { - detectors[i]->setROI(nroi[i], allroi[i]); - } + parallelCall(&slsDetector::clearROI); } -const slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) { +void multiSlsDetector::setROI(slsDetectorDefs::ROI arg, int detPos) { // single if (detPos >= 0) { - return detectors[detPos]->getROI(n); + detectors[detPos]->setROI(arg); } // multi - n = 0; - int num = 0; - int ndet = detectors.size(); - int maxroi = ndet * MAX_ROIS; - ROI temproi; - ROI roiLimits[maxroi]; - ROI *retval = new ROI[maxroi]; - const ROI *temp = nullptr; - int index = 0; + if (detPos < 0 && size() > 1) { + throw RuntimeError("Cannot set ROI for all modules simultaneously"); + } + detectors[0]->setROI(arg); +} - // get each detector's roi array - for (size_t idet = 0; idet < detectors.size(); ++idet) { - temp = detectors[idet]->getROI(index); - if (temp != nullptr) { - if (index != 0) { - FILE_LOG(logINFO) << "detector " << idet << ":"; - } - for (int j = 0; j < index; ++j) { - FILE_LOG(logINFO) - << temp[j].xmin << "\t" << temp[j].xmax << "\t" - << temp[j].ymin << "\t" << temp[j].ymax; - int x = detectors[idet]->getDetectorOffset(X); - int y = detectors[idet]->getDetectorOffset(Y); - roiLimits[n].xmin = temp[j].xmin + x; - roiLimits[n].xmax = temp[j].xmax + x; - roiLimits[n].ymin = temp[j].ymin + y; - roiLimits[n].ymax = temp[j].ymin + y; - ++n; - } - } +slsDetectorDefs::ROI multiSlsDetector::getROI(int detPos) const { + // single + if (detPos >= 0) { + return detectors[detPos]->getROI(); } - // empty roi - if (n == 0) { - return nullptr; + // multi + if (detPos < 0 && size() > 1) { + throw RuntimeError("Cannot get ROI for all modules simultaneously"); } - - FILE_LOG(logDEBUG1) << "ROI :" << std::endl; - for (int j = 0; j < n; ++j) { - FILE_LOG(logDEBUG1) - << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t" - << roiLimits[j].ymin << "\t" << roiLimits[j].ymax; - } - - // combine all the adjacent rois in x direction - for (int i = 0; i < n; ++i) { - // since the ones combined are replaced by -1 - if ((roiLimits[i].xmin) == -1) { - continue; - } - for (int j = i + 1; j < n; ++j) { - // since the ones combined are replaced by -1 - if ((roiLimits[j].xmin) == -1) { - continue; - } - // if y values are same - if (((roiLimits[i].ymin) == (roiLimits[j].ymin)) && - ((roiLimits[i].ymax) == (roiLimits[j].ymax))) { - // if adjacent, increase [i] range and replace all [j] with -1 - if ((roiLimits[i].xmax) + 1 == roiLimits[j].xmin) { - roiLimits[i].xmax = roiLimits[j].xmax; - roiLimits[j].xmin = -1; - roiLimits[j].xmax = -1; - roiLimits[j].ymin = -1; - roiLimits[j].ymax = -1; - } - // if adjacent, increase [i] range and replace all [j] with -1 - else if ((roiLimits[i].xmin) - 1 == roiLimits[j].xmax) { - roiLimits[i].xmin = roiLimits[j].xmin; - roiLimits[j].xmin = -1; - roiLimits[j].xmax = -1; - roiLimits[j].ymin = -1; - roiLimits[j].ymax = -1; - } - } - } - } - - FILE_LOG(logDEBUG1) << "Combined along x axis Getting ROI :\ndetector " - << n; - for (int j = 0; j < n; ++j) { - FILE_LOG(logDEBUG1) - << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t" - << roiLimits[j].ymin << "\t" << roiLimits[j].ymax; - } - - // combine all the adjacent rois in y direction - for (int i = 0; i < n; ++i) { - // since the ones combined are replaced by -1 - if ((roiLimits[i].ymin) == -1) { - continue; - } - for (int j = i + 1; j < n; ++j) { - // since the ones combined are replaced by -1 - if ((roiLimits[j].ymin) == -1) { - continue; - } - // if x values are same - if (((roiLimits[i].xmin) == (roiLimits[j].xmin)) && - ((roiLimits[i].xmax) == (roiLimits[j].xmax))) { - // if adjacent, increase [i] range and replace all [j] with -1 - if ((roiLimits[i].ymax) + 1 == roiLimits[j].ymin) { - roiLimits[i].ymax = roiLimits[j].ymax; - roiLimits[j].xmin = -1; - roiLimits[j].xmax = -1; - roiLimits[j].ymin = -1; - roiLimits[j].ymax = -1; - } - // if adjacent, increase [i] range and replace all [j] with -1 - else if ((roiLimits[i].ymin) - 1 == roiLimits[j].ymax) { - roiLimits[i].ymin = roiLimits[j].ymin; - roiLimits[j].xmin = -1; - roiLimits[j].xmax = -1; - roiLimits[j].ymin = -1; - roiLimits[j].ymax = -1; - } - } - } - } - - // get rid of -1s - for (int i = 0; i < n; ++i) { - if ((roiLimits[i].xmin) != -1) { - retval[num] = roiLimits[i]; - ++num; - } - } - // sort final roi - for (int i = 0; i < num; ++i) { - for (int j = i + 1; j < num; ++j) { - if (retval[j].xmin < retval[i].xmin) { - temproi = retval[i]; - retval[i] = retval[j]; - retval[j] = temproi; - } - } - } - n = num; - - FILE_LOG(logDEBUG1) << "\nxmin\txmax\tymin\tymax"; - for (int i = 0; i < n; ++i) { - FILE_LOG(logDEBUG1) << retval[i].xmin << "\t" << retval[i].xmax << "\t" - << retval[i].ymin << "\t" << retval[i].ymax; - } - return retval; + return detectors[0]->getROI(); } void multiSlsDetector::setADCEnableMask(uint32_t mask, int detPos) { @@ -2613,7 +2054,7 @@ int multiSlsDetector::getReceiverDbitOffset(int detPos) { } void multiSlsDetector::writeAdcRegister(uint32_t addr, uint32_t val, - int detPos) { + int detPos) { // single if (detPos >= 0) { detectors[detPos]->writeAdcRegister(addr, val); @@ -2646,25 +2087,25 @@ int multiSlsDetector::setDeactivatedRxrPaddingMode(int padding, int detPos) { return sls::minusOneIfDifferent(r); } -int multiSlsDetector::getFlippedData(dimension d, int detPos) { +int multiSlsDetector::getFlippedDataX(int detPos) { // single if (detPos >= 0) { - return detectors[detPos]->getFlippedData(d); + return detectors[detPos]->getFlippedDataX(); } // multi - auto r = serialCall(&slsDetector::getFlippedData, d); + auto r = serialCall(&slsDetector::getFlippedDataX); return sls::minusOneIfDifferent(r); } -int multiSlsDetector::setFlippedData(dimension d, int value, int detPos) { +int multiSlsDetector::setFlippedDataX(int value, int detPos) { // single if (detPos >= 0) { - return detectors[detPos]->setFlippedData(d, value); + return detectors[detPos]->setFlippedDataX(value); } // multi - auto r = parallelCall(&slsDetector::setFlippedData, d, value); + auto r = parallelCall(&slsDetector::setFlippedDataX, value); return sls::minusOneIfDifferent(r); } @@ -2701,17 +2142,32 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) { auto r = parallelCall(&slsDetector::enableGapPixels, val); int ret = sls::minusOneIfDifferent(r); - // update data bytes incl gap pixels if (val != -1) { - auto r2 = serialCall(&slsDetector::getDataBytesInclGapPixels); - multi_shm()->dataBytesInclGapPixels = sls::sum(r2); - - // update - updateOffsets(); + Parallel(&slsDetector::enableGapPixels, {}, val); + Result res = + Parallel(&slsDetector::getNumberOfChannels, {}); + multi_shm()->numberOfChannels.x = 0; + multi_shm()->numberOfChannels.y = 0; + for (auto &it : res) { + multi_shm()->numberOfChannels.x += it.x; + multi_shm()->numberOfChannels.y += it.y; + } } return ret; } +void multiSlsDetector::setGapPixelsEnable(bool enable, Positions pos) { + Parallel(&slsDetector::enableGapPixels, pos, static_cast(enable)); + Result res = + Parallel(&slsDetector::getNumberOfChannels, {}); + multi_shm()->numberOfChannels.x = 0; + multi_shm()->numberOfChannels.y = 0; + for (auto &it : res) { + multi_shm()->numberOfChannels.x += it.x; + multi_shm()->numberOfChannels.y += it.y; + } +} + int multiSlsDetector::setTrimEn(std::vector energies, int detPos) { if (detPos >= 0) { return detectors[detPos]->setTrimEn(energies); @@ -2827,14 +2283,14 @@ void multiSlsDetector::resetFPGA(int detPos) { } void multiSlsDetector::copyDetectorServer(const std::string &fname, - const std::string &hostname, - int detPos) { + const std::string &hostname, + int detPos) { // single if (detPos >= 0) { detectors[detPos]->copyDetectorServer(fname, hostname); - detectors[detPos]->rebootController(); + detectors[detPos]->rebootController(); // reboot and copy should be independant for - // update command + // update command } // multi @@ -2853,8 +2309,8 @@ void multiSlsDetector::rebootController(int detPos) { } void multiSlsDetector::update(const std::string &sname, - const std::string &hostname, - const std::string &fname, int detPos) { + const std::string &hostname, + const std::string &fname, int detPos) { FILE_LOG(logINFO) << "This can take awhile. Please be patient..."; // read pof file std::vector buffer = readPofFile(fname); @@ -2877,7 +2333,7 @@ int multiSlsDetector::powerChip(int ival, int detPos) { } // multi delayed call for safety - if (ival >= 0 && getNumberOfDetectors() > 3) { + if (ival >= 0 && size() > 3) { std::vector r; r.reserve(detectors.size()); for (auto &d : detectors) { @@ -2923,16 +2379,15 @@ int64_t multiSlsDetector::getRateCorrection(int detPos) { return sls::minusOneIfDifferent(r); } -void multiSlsDetector::printReceiverConfiguration(TLogLevel level, int detPos) { +std::string multiSlsDetector::printReceiverConfiguration(int detPos) { // single if (detPos >= 0) { - return detectors[detPos]->printReceiverConfiguration(level); + return detectors[detPos]->printReceiverConfiguration(); } // multi - for (auto &d : detectors) { - d->printReceiverConfiguration(level); - } + auto r = parallelCall(&slsDetector::printReceiverConfiguration); + return sls::concatenateIfDifferent(r); } bool multiSlsDetector::getUseReceiverFlag(int detPos) { @@ -2950,17 +2405,6 @@ bool multiSlsDetector::getUseReceiverFlag(int detPos) { } } -std::string multiSlsDetector::checkReceiverOnline(int detPos) { - // single - if (detPos >= 0) { - return detectors[detPos]->checkReceiverOnline(); - } - - // multi - auto r = parallelCall(&slsDetector::checkReceiverOnline); - return sls::concatenateNonEmptyStrings(r); -} - int multiSlsDetector::lockReceiver(int lock, int detPos) { // single if (detPos >= 0) { @@ -3296,6 +2740,7 @@ void multiSlsDetector::readFrameFromReceiver() { int nDetPixelsX = 0; int nDetPixelsY = 0; bool gappixelsenable = false; + bool quadEnable = false; bool eiger = false; bool numInterfaces = getNumberofUDPInterfaces(); // cannot pick up from zmq @@ -3389,10 +2834,10 @@ void multiSlsDetector::readFrameFromReceiver() { ? true : false; // to be changed to EIGER when firmware // updates its header data - // gap pixels enable gappixelsenable = (doc["gappixels"].GetUint() == 0) ? false : true; - + quadEnable = + (doc["quad"].GetUint() == 0) ? false : true; FILE_LOG(logDEBUG1) << "One Time Header Info:" "\n\tsize: " @@ -3402,7 +2847,8 @@ void multiSlsDetector::readFrameFromReceiver() { << "\n\tnPixelsX: " << nPixelsX << "\n\tnPixelsY: " << nPixelsY << "\n\tnX: " << nX << "\n\tnY: " << nY << "\n\teiger: " << eiger - << "\n\tgappixelsenable: " << gappixelsenable; + << "\n\tgappixelsenable: " << gappixelsenable + << "\n\tquadEnable: " << quadEnable; } // each time, parse rest of header currentFileName = doc["fname"].GetString(); @@ -3468,13 +2914,30 @@ void multiSlsDetector::readFrameFromReceiver() { } } } + FILE_LOG(logDEBUG) << "Call Back Info:" + << "\n\t nDetPixelsX: " << nDetPixelsX + << "\n\t nDetPixelsY: " << nDetPixelsY + << "\n\t databytes: " << multisize + << "\n\t dynamicRange: " << dynamicRange; // send data to callback if (data) { setCurrentProgress(currentAcquisitionIndex + 1); // 4bit gap pixels if (dynamicRange == 4 && gappixelsenable) { - int n = processImageWithGapPixels(multiframe, multigappixels); + if (quadEnable) { + nDetPixelsX += 2; + nDetPixelsY += 2; + } else { + nDetPixelsX = nX * (nPixelsX + 3); + nDetPixelsY = nY * (nPixelsY + 1); + } + int n = processImageWithGapPixels(multiframe, multigappixels, + quadEnable); + FILE_LOG(logDEBUG) << "Call Back Info Recalculated:" + << "\n\t nDetPixelsX: " << nDetPixelsX + << "\n\t nDetPixelsY: " << nDetPixelsY + << "\n\t databytes: " << n; thisData = new detectorData( getCurrentProgress(), currentFileName.c_str(), nDetPixelsX, nDetPixelsY, multigappixels, n, dynamicRange, @@ -3530,15 +2993,25 @@ void multiSlsDetector::readFrameFromReceiver() { delete[] multigappixels; } -int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) { +int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage, + bool quadEnable) { // eiger 4 bit mode - int nxb = multi_shm()->numberOfDetector[X] * (512 + 3); - int nyb = multi_shm()->numberOfDetector[Y] * (256 + 1); + int nxb = + multi_shm()->numberOfDetector.x * (512 + 3); //(divided by 2 already) + int nyb = multi_shm()->numberOfDetector.y * (256 + 1); + int nchipInRow = 4; + int nxchip = multi_shm()->numberOfDetector.x * 4; + int nychip = multi_shm()->numberOfDetector.y * 1; + if (quadEnable) { + nxb = multi_shm()->numberOfDetector.x * + (256 + 1); //(divided by 2 already) + nyb = multi_shm()->numberOfDetector.y * (512 + 2); + nxchip /= 2; + nychip *= 2; + nchipInRow /= 2; + } int gapdatabytes = nxb * nyb; - int nxchip = multi_shm()->numberOfDetector[X] * 4; - int nychip = multi_shm()->numberOfDetector[Y] * 1; - // allocate if (gpImage == nullptr) { gpImage = new char[gapdatabytes]; @@ -3554,14 +3027,14 @@ int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) { // copying line by line src = image; dst = gpImage; - for (int row = 0; row < nychip; ++row) { // for each chip in a row + for (int row = 0; row < nychip; ++row) { // for each chip row for (int ichipy = 0; ichipy < b1chipy; - ++ichipy) { // for each row in a chip - for (int col = 0; col < nxchip; ++col) { + ++ichipy) { // for each row in a chip + for (int col = 0; col < nxchip; ++col) { // for each chip in a row memcpy(dst, src, b1chipx); src += b1chipx; dst += b1chipx; - if (((col + 1) % 4) != 0) { + if (((col + 1) % nchipInRow) != 0) { // skip gap pixels ++dst; } } @@ -3575,12 +3048,13 @@ int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) { uint8_t temp, g1, g2; int mod; dst = gpImage; - for (int row = 0; row < nychip; ++row) { // for each chip in a row + for (int row = 0; row < nychip; ++row) { // for each chip row for (int ichipy = 0; ichipy < b1chipy; ++ichipy) { // for each row in a chip - for (int col = 0; col < nxchip; ++col) { + for (int col = 0; col < nxchip; + ++col) { // for each chip in a row dst += b1chipx; - mod = (col + 1) % 4; + mod = (col + 1) % nchipInRow; // get gap pixels // copy gap pixel(chip 0, 1, 2) if (mod != 0) { // neighbouring gap pixels to left @@ -3612,7 +3086,7 @@ int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) { uint8_t temp, g1, g2; char *dst_prevline = nullptr; dst = gpImage; - for (int row = 0; row < nychip; ++row) { // for each chip in a row + for (int row = 0; row < nychip; ++row) { // for each chip row dst += (b1chipy * nxb); // horizontal copying of gap pixels from neighboring past line // (bottom parts) @@ -3724,7 +3198,7 @@ int multiSlsDetector::setReceiverStreamingTimer(int time_in_ms, int detPos) { return sls::minusOneIfDifferent(r); } -int multiSlsDetector::enableDataStreamingToClient(int enable) { +bool multiSlsDetector::enableDataStreamingToClient(int enable) { if (enable >= 0) { // destroy data threads if (enable == 0) { @@ -3736,7 +3210,7 @@ int multiSlsDetector::enableDataStreamingToClient(int enable) { } } } - return static_cast(client_downstream); + return client_downstream; } int multiSlsDetector::enableDataStreamingFromReceiver(int enable, int detPos) { @@ -3785,24 +3259,14 @@ int multiSlsDetector::setReceiverSilentMode(int i, int detPos) { return sls::minusOneIfDifferent(r); } -int multiSlsDetector::setPattern(const std::string &fname, int detPos) { +void multiSlsDetector::setPattern(const std::string &fname, int detPos) { // single if (detPos >= 0) { - return detectors[detPos]->setPattern(fname); - } - FILE *fd = fopen(fname.c_str(), "r"); - if (fd == nullptr) { - throw RuntimeError("multiSlsDetector::setPattern: Could not open file"); - } else { - int addr{0}; - uint64_t word{0}; - while (fread(&word, sizeof(word), 1, fd) != 0u) { - serialCall(&slsDetector::setPatternWord, addr, word); - ++addr; - } - fclose(fd); - return addr; + detectors[detPos]->setPattern(fname); } + + // multi + parallelCall(&slsDetector::setPattern, fname); } uint64_t multiSlsDetector::setPatternIOControl(uint64_t word, int detPos) { @@ -3939,7 +3403,7 @@ int multiSlsDetector::setLEDEnable(int enable, int detPos) { } void multiSlsDetector::setDigitalIODelay(uint64_t pinMask, int delay, - int detPos) { + int detPos) { // single if (detPos >= 0) { detectors[detPos]->setDigitalIODelay(pinMask, delay); @@ -4140,12 +3604,6 @@ void multiSlsDetector::registerAcquisitionFinishedCallback( acqFinished_p = pArg; } -void multiSlsDetector::registerProgressCallback(void (*func)(double, void *), - void *pArg) { - progress_call = func; - pProgressCallArg = pArg; -} - void multiSlsDetector::registerDataCallback( void (*userCallback)(detectorData *, uint64_t, uint32_t, void *), void *pArg) { @@ -4163,22 +3621,22 @@ void multiSlsDetector::registerDataCallback( } int multiSlsDetector::setTotalProgress() { - int nf = 1, nc = 1, ns = 1; - - if (multi_shm()->timerValue[FRAME_NUMBER] != 0) { - nf = multi_shm()->timerValue[FRAME_NUMBER]; + int nf = Parallel(&slsDetector::setTimer, {}, FRAME_NUMBER, -1) + .tsquash("Inconsistent number of frames"); + int nc = Parallel(&slsDetector::setTimer, {}, CYCLES_NUMBER, -1) + .tsquash("Inconsistent number of cycles"); + if (nf == 0 || nc == 0) { + throw RuntimeError("Number of frames or cycles is 0"); } - if (multi_shm()->timerValue[CYCLES_NUMBER] > 0) { - nc = multi_shm()->timerValue[CYCLES_NUMBER]; - } - - if (multi_shm()->timerValue[STORAGE_CELL_NUMBER] > 0) { - ns = multi_shm()->timerValue[STORAGE_CELL_NUMBER] + 1; + int ns = 1; + if (getDetectorTypeAsEnum() == JUNGFRAU) { + ns = Parallel(&slsDetector::setTimer, {}, STORAGE_CELL_NUMBER, -1) + .tsquash("Inconsistent number of additional storage cells"); + ++ns; } totalProgress = nf * nc * ns; - FILE_LOG(logDEBUG1) << "nf " << nf << " nc " << nc << " ns " << ns; FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl; return totalProgress; @@ -4230,23 +3688,21 @@ int multiSlsDetector::acquire() { // verify receiver is idle if (receiver) { - std::lock_guard lock(mg); if (getReceiverStatus() != IDLE) { stopReceiver(); } } + setTotalProgress(); startProcessingThread(); // resets frames caught in receiver if (receiver) { - std::lock_guard lock(mg); resetFramesCaught(); } // start receiver if (receiver) { - std::lock_guard lock(mg); startReceiver(); // let processing thread listen to these packets sem_post(&sem_newRTAcquisition); @@ -4256,14 +3712,13 @@ int multiSlsDetector::acquire() { // stop receiver if (receiver) { - std::lock_guard lock(mg); stopReceiver(); - if (dataReady != nullptr) { - sem_wait(&sem_endRTAcquisition); // waits for receiver's - } - // external process to be - // done sending data to gui - + if (dataReady != nullptr) { + sem_wait(&sem_endRTAcquisition); // waits for receiver's + } + // external process to be + // done sending data to gui + incrementFileIndex(); } @@ -4272,10 +3727,6 @@ int multiSlsDetector::acquire() { sem_post(&sem_newRTAcquisition); dataProcessingThread.join(); - if (progress_call != nullptr) { - progress_call(getCurrentProgress(), pProgressCallArg); - } - if (acquisition_finished != nullptr) { acquisition_finished(getCurrentProgress(), getRunStatus(), acqFinished_p); @@ -4318,10 +3769,8 @@ void multiSlsDetector::processData() { } } // get progress - { - std::lock_guard lock(mg); - caught = getFramesCaughtByReceiver(0); - } + caught = getFramesCaughtByReceiver(0); + // updating progress if (caught != -1) { setCurrentProgress(caught); @@ -4457,9 +3906,3 @@ std::vector multiSlsDetector::readPofFile(const std::string &fname) { FILE_LOG(logINFO) << "Read file into memory"; return buffer; } - - - - - - diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 6a6386a6e..41c543ee2 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -23,13 +23,10 @@ using namespace sls; -#define DEFAULT_HOSTNAME "localhost" - +// create shm slsDetector::slsDetector(detectorType type, int multi_id, int det_id, bool verify) : detId(det_id), shm(multi_id, det_id) { - /* called from put hostname command, - * so sls shared memory will be created */ // ensure shared memory was not created before if (shm.IsExisting()) { @@ -42,10 +39,9 @@ slsDetector::slsDetector(detectorType type, int multi_id, int det_id, initSharedMemory(type, multi_id, verify); } +// pick up from shm slsDetector::slsDetector(int multi_id, int det_id, bool verify) : detId(det_id), shm(multi_id, det_id) { - /* called from multi constructor to populate structure, - * so sls shared memory will be opened, not created */ // getDetectorType From shm will check if it was already existing detectorType type = getDetectorTypeFromShm(multi_id, verify); @@ -305,18 +301,15 @@ void slsDetector::initSharedMemory(detectorType type, int multi_id, void slsDetector::initializeDetectorStructure(detectorType type) { shm()->shmversion = SLS_SHMVERSION; - shm()->controlPort = DEFAULT_PORTNO; - sls::strcpy_safe(shm()->hostname, DEFAULT_HOSTNAME); + memset(shm()->hostname, 0, MAX_STR_LENGTH); shm()->myDetectorType = type; - shm()->offset[X] = 0; - shm()->offset[Y] = 0; - shm()->multiSize[X] = 0; - shm()->multiSize[Y] = 0; - + shm()->multiSize.x = 0; + shm()->multiSize.y = 0; + shm()->controlPort = DEFAULT_PORTNO; shm()->stopPort = DEFAULT_PORTNO + 1; sls::strcpy_safe(shm()->settingsDir, getenv("HOME")); - shm()->nROI = 0; - memset(shm()->roiLimits, 0, MAX_ROIS * sizeof(ROI)); + shm()->roi.xmin = -1; + shm()->roi.xmax = -1; shm()->adcEnableMask = BIT32_MASK; shm()->roFlags = NORMAL_READOUT; shm()->currentSettings = UNINITIALIZED; @@ -325,7 +318,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) { shm()->timerValue[ACQUISITION_TIME] = 0; shm()->timerValue[FRAME_PERIOD] = 0; shm()->timerValue[DELAY_AFTER_TRIGGER] = 0; - shm()->timerValue[GATES_NUMBER] = 0; shm()->timerValue[CYCLES_NUMBER] = 1; shm()->timerValue[ACTUAL_TIME] = 0; shm()->timerValue[MEASUREMENT_TIME] = 0; @@ -357,14 +349,13 @@ void slsDetector::initializeDetectorStructure(detectorType type) { shm()->selectedUDPInterface = 0; shm()->useReceiverFlag = false; shm()->tenGigaEnable = 0; - shm()->flippedData[X] = 0; - shm()->flippedData[Y] = 0; + shm()->flippedDataX = 0; shm()->zmqport = DEFAULT_ZMQ_CL_PORTNO + (detId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); shm()->rxZmqport = DEFAULT_ZMQ_RX_PORTNO + (detId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); shm()->rxUpstream = false; - shm()->rxReadFreq = 0; + shm()->rxReadFreq = 1; shm()->zmqip = 0u; shm()->rxZmqip = 0u; shm()->gappixels = 0u; @@ -404,30 +395,18 @@ void slsDetector::initializeDetectorStructure(detectorType type) { // get the detector parameters based on type detParameters parameters{type}; - shm()->nChan[X] = parameters.nChanX; - shm()->nChan[Y] = parameters.nChanY; - shm()->nChip[X] = parameters.nChipX; - shm()->nChip[Y] = parameters.nChipY; + shm()->nChan.x = parameters.nChanX; + shm()->nChan.y = parameters.nChanY; + shm()->nChip.x = parameters.nChipX; + shm()->nChip.y = parameters.nChipY; shm()->nDacs = parameters.nDacs; shm()->dynamicRange = parameters.dynamicRange; - shm()->nGappixels[X] = parameters.nGappixelsX; - shm()->nGappixels[Y] = parameters.nGappixelsY; + shm()->nGappixels.x = parameters.nGappixelsX; + shm()->nGappixels.y = parameters.nGappixelsY; - // derived parameters - shm()->nChans = shm()->nChan[X] * shm()->nChan[Y]; - shm()->nChips = shm()->nChip[X] * shm()->nChip[Y]; - - // calculating databytes - shm()->dataBytes = shm()->nChips * shm()->nChans * shm()->dynamicRange / 8; - shm()->dataBytesInclGapPixels = (shm()->nChip[X] * shm()->nChan[X] + - shm()->gappixels * shm()->nGappixels[X]) * - (shm()->nChip[Y] * shm()->nChan[Y] + - shm()->gappixels * shm()->nGappixels[Y]) * - shm()->dynamicRange / 8; - - // update #nchans and databytes, as it depends on #samples, adcmask, + // update #nchan, as it depends on #samples, adcmask, // readoutflags (ctb only) - updateTotalNumberOfChannels(); + updateNumberOfChannels(); } int slsDetector::sendModule(sls_detector_module *myMod, @@ -502,8 +481,7 @@ int slsDetector::receiveModule(sls_detector_module *myMod, if (shm()->myDetectorType == EIGER) { ts += client.Receive(myMod->chanregs, sizeof(int) * (myMod->nchan)); FILE_LOG(logDEBUG1) - << "nchans= " << shm()->nChans << " nchips= " << shm()->nChips - << "mod - nchans= " << myMod->nchan << " nchips= " << myMod->nchip + << " nchan= " << myMod->nchan << " nchip= " << myMod->nchip << "received chans of size " << ts; } FILE_LOG(logDEBUG1) << "received module of size " << ts << " register " @@ -577,16 +555,11 @@ std::string slsDetector::getDetectorTypeAsString() const { return slsDetectorDefs::detectorTypeToString(getDetectorTypeAsEnum()); } -int slsDetector::getTotalNumberOfChannels() const { - return shm()->nChans * shm()->nChips; -} - -void slsDetector::updateTotalNumberOfChannels() { +void slsDetector::updateNumberOfChannels() { if (shm()->myDetectorType == CHIPTESTBOARD || shm()->myDetectorType == MOENCH) { int nachans = 0, ndchans = 0; - int adatabytes = 0, ddatabytes = 0; // analog channels (normal, analog/digital readout) if (shm()->roFlags == slsDetectorDefs::NORMAL_READOUT || ((shm()->roFlags & slsDetectorDefs::ANALOG_AND_DIGITAL) != 0)) { @@ -599,10 +572,7 @@ void slsDetector::updateTotalNumberOfChannels() { ++nachans; } } - adatabytes = nachans * (shm()->dynamicRange / 8) * - shm()->timerValue[ANALOG_SAMPLES]; - FILE_LOG(logDEBUG1) << "#Analog Channels:" << nachans - << " Databytes: " << adatabytes; + FILE_LOG(logDEBUG1) << "#Analog Channels:" << nachans; } // digital channels (ctb only, digital, analog/digital readout) @@ -610,41 +580,28 @@ void slsDetector::updateTotalNumberOfChannels() { (((shm()->roFlags & DIGITAL_ONLY) != 0) || ((shm()->roFlags & ANALOG_AND_DIGITAL) != 0))) { ndchans = 64; - ddatabytes = - (sizeof(uint64_t) * shm()->timerValue[DIGITAL_SAMPLES]); - FILE_LOG(logDEBUG1) << "#Digital Channels:" << ndchans - << " Databytes: " << ddatabytes; + FILE_LOG(logDEBUG1) << "#Digital Channels:" << ndchans; } - shm()->nChans = nachans + ndchans; - shm()->dataBytes = adatabytes + ddatabytes; - FILE_LOG(logDEBUG1) << "# Total #Channels:" << shm()->nChans - << " Databytes: " << shm()->dataBytes; + shm()->nChan.x = nachans + ndchans; + FILE_LOG(logDEBUG1) << "# Total #Channels:" << shm()->nChan.x; } } -int slsDetector::getTotalNumberOfChannels(dimension d) const { - return shm()->nChan[d] * shm()->nChip[d]; +slsDetectorDefs::xy slsDetector::getNumberOfChannels() const { + slsDetectorDefs::xy coord; + coord.x = (shm()->nChan.x * shm()->nChip.x + + shm()->gappixels * shm()->nGappixels.x); + coord.y = (shm()->nChan.y * shm()->nChip.y + + shm()->gappixels * shm()->nGappixels.y); + return coord; } -int slsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d) const { - return (shm()->nChan[d] * shm()->nChip[d] + - shm()->gappixels * shm()->nGappixels[d]); -} - -int slsDetector::getNChans() const { return shm()->nChans; } - -int slsDetector::getNChans(dimension d) const { return shm()->nChan[d]; } - -int slsDetector::getNChips() const { return shm()->nChips; } - -int slsDetector::getNChips(dimension d) const { return shm()->nChip[d]; } - -int slsDetector::getQuad() { +bool slsDetector::getQuad() { int retval = -1; FILE_LOG(logDEBUG1) << "Getting Quad Type"; sendToDetector(F_GET_QUAD, nullptr, retval); FILE_LOG(logDEBUG1) << "Quad Type :" << retval; - return retval; + return (retval == 0 ? false : true); } void slsDetector::setQuad(const bool enable) { @@ -660,10 +617,11 @@ void slsDetector::setQuad(const bool enable) { void slsDetector::setReadNLines(const int value) { FILE_LOG(logDEBUG1) << "Setting read n lines to " << value; sendToDetector(F_SET_READ_N_LINES, value, nullptr); - FILE_LOG(logDEBUG1) << "Setting read n lines to " << value << " in Receiver"; + FILE_LOG(logDEBUG1) << "Setting read n lines to " << value + << " in Receiver"; if (shm()->useReceiverFlag) { sendToReceiver(F_SET_RECEIVER_READ_N_LINES, value, nullptr); -} + } } int slsDetector::getReadNLines() { @@ -674,40 +632,21 @@ int slsDetector::getReadNLines() { return retval; } -int slsDetector::getDetectorOffset(dimension d) const { - return shm()->offset[d]; -} - -void slsDetector::setDetectorOffset(dimension d, int off) { - if (off >= 0) { - shm()->offset[d] = off; - } -} - -void slsDetector::updateMultiSize(int detx, int dety) { - shm()->multiSize[0] = detx; - shm()->multiSize[1] = dety; -} - -std::string slsDetector::checkOnline() { - std::string retval; - try { - // Need both control and stop socket to work! - auto client = DetectorSocket(shm()->hostname, shm()->controlPort); - auto stop = DetectorSocket(shm()->hostname, shm()->stopPort); - } catch (...) { - retval = shm()->hostname; - } - return retval; +void slsDetector::updateMultiSize(slsDetectorDefs::xy det) { + shm()->multiSize = det; } int slsDetector::setControlPort(int port_number) { int retval = -1; FILE_LOG(logDEBUG1) << "Setting control port to " << port_number; if (port_number >= 0 && port_number != shm()->controlPort) { - sendToDetector(F_SET_PORT, port_number, retval); - shm()->controlPort = retval; - FILE_LOG(logDEBUG1) << "Control port: " << retval; + if (strlen(shm()->hostname) > 0) { + sendToDetector(F_SET_PORT, port_number, retval); + shm()->controlPort = retval; + FILE_LOG(logDEBUG1) << "Control port: " << retval; + } else { + shm()->controlPort = port_number; + } } return shm()->controlPort; } @@ -716,9 +655,13 @@ int slsDetector::setStopPort(int port_number) { int retval = -1; FILE_LOG(logDEBUG1) << "Setting stop port to " << port_number; if (port_number >= 0 && port_number != shm()->stopPort) { - sendToDetectorStop(F_SET_PORT, port_number, retval); - shm()->stopPort = retval; - FILE_LOG(logDEBUG1) << "Stop port: " << retval; + if (strlen(shm()->hostname) > 0) { + sendToDetectorStop(F_SET_PORT, port_number, retval); + shm()->stopPort = retval; + FILE_LOG(logDEBUG1) << "Stop port: " << retval; + } else { + shm()->stopPort = port_number; + } } return shm()->stopPort; } @@ -745,12 +688,12 @@ int slsDetector::getControlPort() const { return shm()->controlPort; } int slsDetector::getStopPort() const { return shm()->stopPort; } -int slsDetector::lockServer(int lock) { +bool slsDetector::lockServer(int lock) { int retval = -1; FILE_LOG(logDEBUG1) << "Setting detector server lock to " << lock; sendToDetector(F_LOCK_SERVER, lock, retval); FILE_LOG(logDEBUG1) << "Lock: " << retval; - return retval; + return (retval == 1 ? true : false); } std::string slsDetector::getLastClientIP() { @@ -795,10 +738,6 @@ void slsDetector::updateCachedDetectorVariables() { n += client.Receive(&i32, sizeof(i32)); shm()->dynamicRange = i32; - // databytes - n += client.Receive(&i32, sizeof(i32)); - shm()->dataBytes = i32; - // settings if ((shm()->myDetectorType != CHIPTESTBOARD) && (shm()->myDetectorType != MOENCH)) { @@ -863,17 +802,9 @@ void slsDetector::updateCachedDetectorVariables() { // roi if (shm()->myDetectorType == GOTTHARD) { n += client.Receive(&i32, sizeof(i32)); - shm()->nROI = i32; - for (int i = 0; i < shm()->nROI; ++i) { - n += client.Receive(&i32, sizeof(i32)); - shm()->roiLimits[i].xmin = i32; - n += client.Receive(&i32, sizeof(i32)); - shm()->roiLimits[i].xmax = i32; - n += client.Receive(&i32, sizeof(i32)); - shm()->roiLimits[i].ymin = i32; - n += client.Receive(&i32, sizeof(i32)); - shm()->roiLimits[i].xmax = i32; - } + shm()->roi.xmin = i32; + n += client.Receive(&i32, sizeof(i32)); + shm()->roi.xmax = i32; } if (shm()->myDetectorType == CHIPTESTBOARD || @@ -897,9 +828,9 @@ void slsDetector::updateCachedDetectorVariables() { if (shm()->myDetectorType == MOENCH) setAdditionalJsonParameter("adcmask", std::to_string(u32)); - // update #nchans and databytes, as it depends on #samples, adcmask, + // update #nchan, as it depends on #samples, adcmask, // readoutflags - updateTotalNumberOfChannels(); + updateNumberOfChannels(); } if (n == 0) { @@ -1325,7 +1256,7 @@ void slsDetector::configureMAC() { // 2d positions to detector to put into udp header { int pos[2] = {0, 0}; - int max = shm()->multiSize[Y] * (shm()->numUDPInterfaces); + int max = shm()->multiSize.y * (shm()->numUDPInterfaces); // row pos[0] = (detId % max); // col for horiz. udp ports @@ -1406,10 +1337,10 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { sendToDetector(F_SET_TIMER, args, retval); FILE_LOG(logDEBUG1) << getTimerType(index) << ": " << retval; shm()->timerValue[index] = retval; - // update #nchans and databytes, as it depends on #samples, adcmask, + // update #nchan, as it depends on #samples, adcmask, // readoutflags if (index == ANALOG_SAMPLES || index == DIGITAL_SAMPLES) { - updateTotalNumberOfChannels(); + updateNumberOfChannels(); } // setting timers consequences (eiger (ratecorr) ) @@ -1493,27 +1424,10 @@ int slsDetector::setDynamicRange(int n) { // TODO! Properly handle fail int retval = -1; FILE_LOG(logDEBUG1) << "Setting dynamic range to " << n; - int olddr = shm()->dynamicRange; sendToDetector(F_SET_DYNAMIC_RANGE, n, retval); FILE_LOG(logDEBUG1) << "Dynamic Range: " << retval; shm()->dynamicRange = retval; - // only for eiger - // setting dr consequences on databytes shm - // (a get can also change timer value, hence check difference) - if (olddr != shm()->dynamicRange) { - shm()->dataBytes = shm()->nChips * shm()->nChans * retval / 8; - shm()->dataBytesInclGapPixels = - (shm()->nChip[X] * shm()->nChan[X] + - shm()->gappixels * shm()->nGappixels[X]) * - (shm()->nChip[Y] * shm()->nChan[Y] + - shm()->gappixels * shm()->nGappixels[Y]) * - retval / 8; - FILE_LOG(logDEBUG1) << "Data bytes " << shm()->dataBytes; - FILE_LOG(logDEBUG1) << "Data bytes including gap pixels" - << shm()->dataBytesInclGapPixels; - } - if (shm()->useReceiverFlag) { n = shm()->dynamicRange; retval = -1; @@ -1524,11 +1438,7 @@ int slsDetector::setDynamicRange(int n) { return shm()->dynamicRange; } -int slsDetector::getDataBytes() { return shm()->dataBytes; } - -int slsDetector::getDataBytesInclGapPixels() { - return shm()->dataBytesInclGapPixels; -} +int slsDetector::getDynamicRangeFromShm() { return shm()->dynamicRange; } int slsDetector::setDAC(int val, dacIndex index, int mV) { int args[]{static_cast(index), mV, val}; @@ -1549,11 +1459,10 @@ int slsDetector::getADC(dacIndex index) { return retval; } -slsDetectorDefs::externalCommunicationMode -slsDetector::setExternalCommunicationMode(externalCommunicationMode pol) { - int fnum = F_SET_EXTERNAL_COMMUNICATION_MODE; +slsDetectorDefs::timingMode slsDetector::setTimingMode(timingMode pol) { + int fnum = F_SET_TIMING_MODE; auto arg = static_cast(pol); - externalCommunicationMode retval = GET_EXTERNAL_COMMUNICATION_MODE; + timingMode retval = GET_TIMING_MODE; FILE_LOG(logDEBUG1) << "Setting communication to mode " << pol; sendToDetector(fnum, arg, retval); FILE_LOG(logDEBUG1) << "Timing Mode: " << retval; @@ -1577,10 +1486,10 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { sendToDetector(F_SET_READOUT_FLAGS, arg, retval); FILE_LOG(logDEBUG1) << "Readout flag: " << retval; shm()->roFlags = retval; - // update #nchans and databytes, as it depends on #samples, adcmask, + // update #nchan, as it depends on #samples, adcmask, // readoutflags if (shm()->myDetectorType == CHIPTESTBOARD) { - updateTotalNumberOfChannels(); + updateNumberOfChannels(); } FILE_LOG(logDEBUG1) << "Setting receiver readout flags to " << arg; if (shm()->useReceiverFlag) { @@ -1762,7 +1671,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { << "\nasamples:" << (shm()->timerValue[ANALOG_SAMPLES]) << "\ndsamples:" << (shm()->timerValue[DIGITAL_SAMPLES]) << "\ndynamic range:" << shm()->dynamicRange - << "\nflippeddatax:" << (shm()->flippedData[X]) + << "\nflippeddatax:" << (shm()->flippedDataX) << "\nactivated: " << shm()->activated << "\nreceiver deactivated padding: " << shm()->rxPadDeactivatedModules << "\nsilent Mode:" << shm()->rxSilentMode @@ -1804,13 +1713,14 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { shm()->timerValue[SUBFRAME_ACQUISITION_TIME]); setTimer(SUBFRAME_DEADTIME, shm()->timerValue[SUBFRAME_DEADTIME]); setDynamicRange(shm()->dynamicRange); - setFlippedData(X, -1); + setFlippedDataX(-1); activate(-1); setDeactivatedRxrPaddingMode( static_cast(shm()->rxPadDeactivatedModules)); enableGapPixels(shm()->gappixels); enableTenGigabitEthernet(shm()->tenGigaEnable); setReadOutFlags(GET_READOUT_FLAGS); + setQuad(getQuad()); break; case CHIPTESTBOARD: @@ -1820,6 +1730,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { setReadOutFlags(GET_READOUT_FLAGS); setADCEnableMask(shm()->adcEnableMask); setReceiverDbitOffset(shm()->rxDbitOffset); + setReceiverDbitList(shm()->rxDbitList); break; case MOENCH: @@ -1830,17 +1741,13 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { break; case GOTTHARD: - sendROI(-1, nullptr); + sendROItoReceiver(); break; default: break; } - if (shm()->myDetectorType == CHIPTESTBOARD) { - setReceiverDbitList(shm()->rxDbitList); - } - setReceiverSilentMode(static_cast(shm()->rxSilentMode)); // data streaming setReceiverStreamingFrequency(shm()->rxReadFreq); @@ -2245,7 +2152,7 @@ void slsDetector::setUDPConnection() { } else { throw ReceiverError("setUDPConnection: Receiver is OFFLINE"); } - printReceiverConfiguration(logDEBUG1); + FILE_LOG(logDEBUG1) << printReceiverConfiguration(); } int slsDetector::digitalTest(digitalTestMode mode, int ival) { @@ -2258,65 +2165,6 @@ int slsDetector::digitalTest(digitalTestMode mode, int ival) { return retval; } -void slsDetector::loadImageToDetector(imageType index, - const std::string &fname) { - int nChan = getTotalNumberOfChannels(); - int16_t args[nChan]; - FILE_LOG(logDEBUG1) << "Loading " << (index == 0u ? "Dark" : "Gain") - << "image from file " << fname; - - if (readDataFile(fname, args, nChan) != 0) { - sendImageToDetector(index, args); - } else { - throw RuntimeError( - "slsDetector::loadImageToDetector: Could not open file: " + fname); - } -} - -void slsDetector::sendImageToDetector(imageType index, int16_t imageVals[]) { - int fnum = F_LOAD_IMAGE; - int nChan = getTotalNumberOfChannels(); - int args[]{static_cast(index), nChan}; - FILE_LOG(logDEBUG1) << "Sending image to detector"; - auto client = DetectorSocket(shm()->hostname, shm()->controlPort); - client.Send(&fnum, sizeof(fnum)); - client.Send(args, sizeof(args)); - client.Send(imageVals, nChan * sizeof(int16_t)); - int ret = FAIL; - client.Receive(&ret, sizeof(ret)); - char mess[MAX_STR_LENGTH]{}; - client.Receive(mess, MAX_STR_LENGTH); - throw DetectorError("Detector " + std::to_string(detId) + - " returned error: " + std::string(mess)); - if (ret == FORCE_UPDATE) { - updateCachedDetectorVariables(); - } -} - -void slsDetector::writeCounterBlockFile(const std::string &fname, - int startACQ) { - int nChan = getTotalNumberOfChannels(); - int16_t retvals[nChan]; - FILE_LOG(logDEBUG1) << "Reading Counter to " << fname - << (startACQ != 0 ? " and Restarting Acquisition" - : "\n"); - getCounterBlock(retvals, startACQ); - writeDataFile(fname, nChan, retvals); -} - -void slsDetector::getCounterBlock(int16_t image[], int startACQ) { - int fnum = F_READ_COUNTER_BLOCK; - int nChan = getTotalNumberOfChannels(); - int args[] = {startACQ, nChan}; - FILE_LOG(logDEBUG1) << "Reading Counter block with startacq: " << startACQ; - sendToDetector(fnum, args, sizeof(args), image, nChan * sizeof(int16_t)); -} - -void slsDetector::resetCounterBlock(int startACQ) { - FILE_LOG(logDEBUG1) << "Resetting Counter with startacq: " << startACQ; - sendToDetector(F_RESET_COUNTER_BLOCK, startACQ, nullptr); -} - int slsDetector::setCounterBit(int cb) { int retval = -1; FILE_LOG(logDEBUG1) << "Sending counter bit " << cb; @@ -2325,44 +2173,28 @@ int slsDetector::setCounterBit(int cb) { return retval; } -void slsDetector::setROI(int n, ROI roiLimits[]) { - std::sort(roiLimits, roiLimits + n, - [](ROI a, ROI b) { return a.xmin < b.xmin; }); - - sendROI(n, roiLimits); +void slsDetector::clearROI() { + FILE_LOG(logDEBUG1) << "Clearing ROI"; + slsDetectorDefs::ROI arg; + arg.xmin = -1; + arg.xmax = -1; + setROI(arg); } -const slsDetectorDefs::ROI *slsDetector::getROI(int &n) { - sendROI(-1, nullptr); - n = shm()->nROI; - return shm()->roiLimits; -} - -int slsDetector::getNRoi() { return shm()->nROI; } - -void slsDetector::sendROI(int n, ROI roiLimits[]) { +void slsDetector::setROI(slsDetectorDefs::ROI arg) { int fnum = F_SET_ROI; int ret = FAIL; - int narg = n; - // send roiLimits if given, else from shm - ROI *arg = (roiLimits != nullptr) ? roiLimits : shm()->roiLimits; - int nretval = 0; - ROI retval[MAX_ROIS]; - FILE_LOG(logDEBUG1) << "Sending ROI to detector" << narg; - + if (arg.xmin < 0 || arg.xmax >= getNumberOfChannels().x) { + arg.xmin = -1; + arg.xmax = -1; + } + FILE_LOG(logDEBUG) << "Sending ROI to detector [" << arg.xmin << ", " + << arg.xmax << "]"; auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(&fnum, sizeof(fnum)); - client.Send(&narg, sizeof(narg)); - if (narg != -1) { - for (int i = 0; i < narg; ++i) { - client.Send(&arg[i].xmin, sizeof(int)); - client.Send(&arg[i].xmax, sizeof(int)); - client.Send(&arg[i].ymin, sizeof(int)); - client.Send(&arg[i].ymax, sizeof(int)); - } - } + client.Send(&arg.xmin, sizeof(int)); + client.Send(&arg.xmax, sizeof(int)); client.Receive(&ret, sizeof(ret)); - // handle ret if (ret == FAIL) { char mess[MAX_STR_LENGTH]{}; @@ -2370,63 +2202,58 @@ void slsDetector::sendROI(int n, ROI roiLimits[]) { throw RuntimeError("Detector " + std::to_string(detId) + " returned error: " + std::string(mess)); } else { - client.Receive(&nretval, sizeof(nretval)); - int nrec = 0; - for (int i = 0; i < nretval; ++i) { - nrec += client.Receive(&retval[i].xmin, sizeof(int)); - nrec += client.Receive(&retval[i].xmax, sizeof(int)); - nrec += client.Receive(&retval[i].ymin, sizeof(int)); - nrec += client.Receive(&retval[i].ymax, sizeof(int)); - } - shm()->nROI = nretval; - FILE_LOG(logDEBUG1) << "nRoi: " << nretval; - for (int i = 0; i < nretval; ++i) { - shm()->roiLimits[i] = retval[i]; - FILE_LOG(logDEBUG1) - << "ROI [" << i << "] (" << shm()->roiLimits[i].xmin << "," - << shm()->roiLimits[i].xmax << "," << shm()->roiLimits[i].ymin - << "," << shm()->roiLimits[i].ymax << ")"; + memcpy(&shm()->roi, &arg, sizeof(ROI)); + if (ret == FORCE_UPDATE) { + updateCachedDetectorVariables(); } } - if (ret == FORCE_UPDATE) { - updateCachedDetectorVariables(); - } + // old firmware requires configuremac after setting roi - if (shm()->myDetectorType == GOTTHARD && n != -1) { + if (shm()->myDetectorType == GOTTHARD) { configureMAC(); } + sendROItoReceiver(); +} + +void slsDetector::sendROItoReceiver() { // update roi in receiver if (shm()->useReceiverFlag) { - fnum = F_RECEIVER_SET_ROI; - ret = FAIL; - narg = shm()->nROI; - arg = shm()->roiLimits; - FILE_LOG(logDEBUG1) << "Sending ROI to receiver: " << shm()->nROI; + FILE_LOG(logDEBUG1) << "Sending ROI to receiver"; + sendToReceiver(F_RECEIVER_SET_ROI, shm()->roi, nullptr); + } +} - auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); - receiver.Send(&fnum, sizeof(fnum)); - receiver.Send(&narg, sizeof(narg)); - if (narg != -1) { - for (int i = 0; i < narg; ++i) { - receiver.Send(&arg[i].xmin, sizeof(int)); - receiver.Send(&arg[i].xmax, sizeof(int)); - receiver.Send(&arg[i].ymin, sizeof(int)); - receiver.Send(&arg[i].ymax, sizeof(int)); - } - } - receiver.Receive(&ret, sizeof(ret)); - - if (ret == FAIL) { - char mess[MAX_STR_LENGTH]{}; - receiver.Receive(mess, MAX_STR_LENGTH); - throw ReceiverError("Receiver " + std::to_string(detId) + - " returned error: " + std::string(mess)); - } +slsDetectorDefs::ROI slsDetector::getROI() { + int fnum = F_GET_ROI; + int ret = FAIL; + FILE_LOG(logDEBUG1) << "Getting ROI from detector"; + auto client = DetectorSocket(shm()->hostname, shm()->controlPort); + client.Send(&fnum, sizeof(fnum)); + client.Receive(&ret, sizeof(ret)); + // handle ret + if (ret == FAIL) { + char mess[MAX_STR_LENGTH]{}; + client.Receive(mess, MAX_STR_LENGTH); + throw RuntimeError("Detector " + std::to_string(detId) + + " returned error: " + std::string(mess)); + } else { + ROI retval; + client.Receive(&retval.xmin, sizeof(int)); + client.Receive(&retval.xmax, sizeof(int)); + FILE_LOG(logDEBUG1) + << "ROI retval [" << retval.xmin << "," << retval.xmax << "]"; if (ret == FORCE_UPDATE) { - updateCachedReceiverVariables(); + updateCachedDetectorVariables(); + } + // if different from shm, update and send to receiver + if (shm()->roi.xmin != retval.xmin || shm()->roi.xmax != retval.xmax) { + memcpy(&shm()->roi, &retval, sizeof(ROI)); + sendROItoReceiver(); } } + + return shm()->roi; } void slsDetector::setADCEnableMask(uint32_t mask) { @@ -2436,9 +2263,9 @@ void slsDetector::setADCEnableMask(uint32_t mask) { sendToDetector(F_SET_ADC_ENABLE_MASK, &arg, sizeof(arg), nullptr, 0); shm()->adcEnableMask = mask; - // update #nchans and databytes, as it depends on #samples, adcmask, + // update #nchan, as it depends on #samples, adcmask, // readoutflags - updateTotalNumberOfChannels(); + updateNumberOfChannels(); // send to processor if (shm()->myDetectorType == MOENCH) @@ -2583,29 +2410,23 @@ bool slsDetector::setDeactivatedRxrPaddingMode(int padding) { return shm()->rxPadDeactivatedModules; } -int slsDetector::getFlippedData(dimension d) const { - return shm()->flippedData[d]; -} +int slsDetector::getFlippedDataX() const { return shm()->flippedDataX; } -int slsDetector::setFlippedData(dimension d, int value) { - if (d == Y) { - throw RuntimeError("Flipped across Y axis is not implemented"); - } +int slsDetector::setFlippedDataX(int value) { // replace get with shm value (write to shm right away as it is a det value, // not rx value) if (value > -1) { - shm()->flippedData[d] = (value > 0) ? 1 : 0; + shm()->flippedDataX = (value > 0) ? 1 : 0; } - int args[]{static_cast(d), value}; int retval = -1; - args[1] = shm()->flippedData[d]; - FILE_LOG(logDEBUG1) << "Setting flipped data across axis " << d - << " with value: " << value; + int arg = shm()->flippedDataX; + FILE_LOG(logDEBUG1) << "Setting flipped data across x axis with value: " + << arg; if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, args, retval); + sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval); FILE_LOG(logDEBUG1) << "Flipped data:" << retval; } - return shm()->flippedData[d]; + return shm()->flippedDataX; } int slsDetector::setAllTrimbits(int val) { @@ -2625,16 +2446,6 @@ int slsDetector::enableGapPixels(int val) { sendToReceiver(fnum, &val, sizeof(val), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Gap pixels enable to receiver:" << retval; shm()->gappixels = retval; - // update databytes - shm()->dataBytesInclGapPixels = 0; - if (shm()->dynamicRange != 4) { - shm()->dataBytesInclGapPixels = - (shm()->nChip[X] * shm()->nChan[X] + - shm()->gappixels * shm()->nGappixels[X]) * - (shm()->nChip[Y] * shm()->nChan[Y] + - shm()->gappixels * shm()->nGappixels[Y]) * - shm()->dynamicRange / 8; - } } } return shm()->gappixels; @@ -2926,32 +2737,24 @@ void slsDetector::updateRateCorrection() { } } -void slsDetector::printReceiverConfiguration(TLogLevel level) { - FILE_LOG(level) << "#Detector " << detId << ":\n Receiver Hostname:\t" - << getReceiverHostname() - << "\nDetector UDP IP (Source):\t\t" << getDetectorIP() - << "\nDetector UDP IP2 (Source):\t\t" << getDetectorIP2() - << "\nDetector UDP MAC:\t\t" << getDetectorMAC() - << "\nDetector UDP MAC2:\t\t" << getDetectorMAC2() - << "\nReceiver UDP IP:\t" << getReceiverUDPIP() - << "\nReceiver UDP IP2:\t" << getReceiverUDPIP2() - << "\nReceiver UDP MAC:\t" << getReceiverUDPMAC() - << "\nReceiver UDP MAC2:\t" << getReceiverUDPMAC2() - << "\nReceiver UDP Port:\t" << getReceiverUDPPort() - << "\nReceiver UDP Port2:\t" << getReceiverUDPPort2(); +std::string slsDetector::printReceiverConfiguration() { + std::ostringstream os; + os << "#Detector " << detId << ":\n Receiver Hostname:\t" + << getReceiverHostname() << "\nDetector UDP IP (Source):\t\t" + << getDetectorIP() << "\nDetector UDP IP2 (Source):\t\t" + << getDetectorIP2() << "\nDetector UDP MAC:\t\t" << getDetectorMAC() + << "\nDetector UDP MAC2:\t\t" << getDetectorMAC2() + << "\nReceiver UDP IP:\t" << getReceiverUDPIP() + << "\nReceiver UDP IP2:\t" << getReceiverUDPIP2() + << "\nReceiver UDP MAC:\t" << getReceiverUDPMAC() + << "\nReceiver UDP MAC2:\t" << getReceiverUDPMAC2() + << "\nReceiver UDP Port:\t" << getReceiverUDPPort() + << "\nReceiver UDP Port2:\t" << getReceiverUDPPort2(); + return os.str(); } bool slsDetector::getUseReceiverFlag() const { return shm()->useReceiverFlag; } -std::string slsDetector::checkReceiverOnline() { - try { - getReceiverSoftwareVersion(); - } catch (...) { - return shm()->rxHostname; - } - return std::string(); -} - int slsDetector::lockReceiver(int lock) { FILE_LOG(logDEBUG1) << "Setting receiver server lock to " << lock; int retval = -1; @@ -3102,10 +2905,10 @@ void slsDetector::updateCachedReceiverVariables() const { } void slsDetector::sendMultiDetectorSize() { - int args[]{shm()->multiSize[0], shm()->multiSize[1]}; + int args[]{shm()->multiSize.x, shm()->multiSize.y}; int retval = -1; FILE_LOG(logDEBUG1) << "Sending multi detector size to receiver: (" - << shm()->multiSize[0] << "," << shm()->multiSize[1] + << shm()->multiSize.x << "," << shm()->multiSize.y << ")"; if (shm()->useReceiverFlag) { sendToReceiver(F_SEND_RECEIVER_MULTIDETSIZE, args, retval); @@ -3429,7 +3232,7 @@ void slsDetector::restreamStopFromReceiver() { } } -int slsDetector::setPattern(const std::string &fname) { +void slsDetector::setPattern(const std::string &fname) { uint64_t word; uint64_t addr = 0; FILE *fd = fopen(fname.c_str(), "r"); @@ -3441,9 +3244,8 @@ int slsDetector::setPattern(const std::string &fname) { } fclose(fd); } else { - return -1; + throw RuntimeError("Could not open file to set pattern"); } - return addr; } uint64_t slsDetector::setPatternIOControl(uint64_t word) { diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index e5f3ee928..68985ad85 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -122,19 +122,12 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdExitServer; ++i; - /*! \page test - - flippeddatay [i] enables/disables data being flipped across y axis. 1 enables, 0 disables. Not implemented. - */ - descrToFuncMap[i].m_pFuncName = "flippeddatay"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDetectorSize; - ++i; - /* digital test and debugging */ /*! \page test - - digibittest:[i] performs digital test of the module i. Returns 0 if succeeded, otherwise error mask. Gotthard only. Only put! + - imagetest [i] If 1, adds channel intensity with precalculated values. Default is 0. Gotthard only. */ - descrToFuncMap[i].m_pFuncName = "digibittest"; + descrToFuncMap[i].m_pFuncName = "imagetest"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDigiTest; ++i; @@ -221,21 +214,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page acquisition - - readctr Reads the counters from the detector memory (analog detector returning values translated into number of photons - only GOTTHARD). Cannot put. - */ - descrToFuncMap[i].m_pFuncName = "readctr"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdCounter; - ++i; - - /*! \page acquisition - - resetctr i Resets counter in detector, restarts acquisition if i=1(analog detector returning values translated into number of photons - only GOTTHARD). Cannot put. - */ - descrToFuncMap[i].m_pFuncName = "resetctr"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdCounter; - ++i; - - /*! \page acquisition - - resmat i sets/resets counter bit in detector.gets the counter bit in detector ???? + - resmat i sets/resets counter bit in detector.gets the counter bit in Eiger */ descrToFuncMap[i].m_pFuncName = "resmat"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdCounter; @@ -276,18 +255,12 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page config - - \b add appends a hostname (or IP address) at the end of the multi-detector structure. Only allowed at multi detector level. Cannot get. \c Returns the current list of detector hostnames. \c (string) + - virtual [n] [p] \c connects to n virtual detector servers at local host starting at port p \c Returns the list of the hostnames of the multi-detector structure. \c (string) */ - descrToFuncMap[i].m_pFuncName = "add"; + descrToFuncMap[i].m_pFuncName = "virtual"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdHostname; ++i; - /*! \page config - - replace \c Sets the hostname (or IP adress) for a single detector. Only allowed at single detector level. Cannot get. \c Returns the hostnames for that detector \c (string) - */ - descrToFuncMap[i].m_pFuncName = "replace"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdHostname; - ++i; /*! \page config - user \c Returns user details from shared memory. Only allowed at multi detector level. Cannot put. \c (string) @@ -301,12 +274,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { commands to configure detector status */ - /*! \page config - - checkonline returns the hostnames of all detectors without connecting to them. \c Returns (string) "All online" or "[list of offline hostnames] : Not online". - */ - descrToFuncMap[i].m_pFuncName = "checkonline"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdOnline; - ++i; /*! \page config - activate [b] [p] Activates/Deactivates the detector. \c b is 1 for activate, 0 for deactivate. Deactivated detector does not send data. \c p is optional and can be padding (default) or nonpadding for receivers for deactivated detectors. Used for EIGER only. \c Returns \c (int) (string) */ @@ -328,14 +295,21 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page config - - roi [i] [xmin] [xmax] [ymin] [ymax] sets region of interest of the detector, where i is number of rois;i=0 to clear rois. Used for GOTTHARD only. \c Returns \c (int) + - clearroi resets region of interest of the detector. Used for GOTTHARD only. \c Returns \c (string) + */ + descrToFuncMap[i].m_pFuncName = "clearroi"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDetectorSize; + ++i; + + /*! \page config + - roi [xmin] [xmax] sets region of interest of the detector. Used for GOTTHARD only. \c Returns \c (int) */ descrToFuncMap[i].m_pFuncName = "roi"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDetectorSize; ++i; /*! \page config - - detsizechan [xmax] [ymax] sets the maximum number of channels in each dimension for complete detector set; -1 is no limit. Use for multi-detector system as first command in config file. \c Returns \c ("int int") + - detsizechan [xmax] [ymax] sets the maximum number of channels in each dimension for complete detector set; 0 is no limit. Use for multi-detector system as first command in config file. \c Returns \c ("int int") */ descrToFuncMap[i].m_pFuncName = "detsizechan"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDetectorSize; @@ -398,9 +372,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page config - - extsig [flag] sets/gets the mode of the external signal. Options: \c off, \c gate_in_active_high, \c gate_in_active_low, \c trigger_in_rising_edge, \c trigger_in_falling_edge, - \c ro_trigger_in_rising_edge, \c ro_trigger_in_falling_edge, \c gate_out_active_high, \c gate_out_active_low, \c trigger_out_rising_edge, \c trigger_out_falling_edge, \c ro_trigger_out_rising_edge, - \c ro_trigger_out_falling_edge. \n Used in GOTTHARDonly. \c Returns \c (string) + - extsig [flag] sets/gets the mode of the external signal. Options: \c trigger_in_rising_edge, \c trigger_in_falling_edge. Used in GOTTHARDonly. \c Returns \c (string) */ descrToFuncMap[i].m_pFuncName = "extsig"; /* find command! */ descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced; @@ -597,13 +569,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer; ++i; - /*! \page timing - - gates [i] sets/gets number of gates. Used in GOTTHARD only. \c Returns \c (long long int) - */ - descrToFuncMap[i].m_pFuncName = "gates"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer; - ++i; - /*! \page timing - frames [i] sets/gets number of frames. If \c timing is not \c auto, then it is the number of frames per cycle/trigger. \c Returns \c (long long int) */ @@ -877,19 +842,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded; // ++i; - /*! \page data - - darkimage fn Loads the dark image to the detector from file fn (pedestal image). Cannot get. For Gotthard only. - */ - descrToFuncMap[i].m_pFuncName = "darkimage"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdImage; - ++i; - - /*! \page data - - gainimage fn Loads the gain image to the detector from file fn (gain map for translation into number of photons of an analog detector). Cannot get. For Gotthard only. - */ - descrToFuncMap[i].m_pFuncName = "gainimage"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdImage; - ++i; /*! \page settings Detector settings commands Commands to setup the settings of the detector @@ -1811,13 +1763,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; ++i; - /*! \page receiver - - rx_checkonline Checks the receiver if it is online/offline mode. Only get! \c Returns (string) "All online" or "[list of offline hostnames] : Not online". - */ - descrToFuncMap[i].m_pFuncName = "rx_checkonline"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdOnline; - ++i; - /*! \page receiver - framescaught gets the number of frames caught by receiver. Average of all for multi-detector command. Only get! \c Returns \c (int) */ @@ -1854,7 +1799,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page receiver - - rx_readfreq [i] sets/gets the stream frequency of data from receiver to client. i > 0 is the nth frame being streamed. 0 sets frequency to a default timer (200ms). \c Returns \c (int) + - rx_readfreq [i] sets/gets the stream frequency of data from receiver to client. i > 0 is the nth frame being streamed. 0 sets frequency to a default timer (200ms). Default: sends every frame \c Returns \c (int) */ descrToFuncMap[i].m_pFuncName = "rx_readfreq"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; @@ -2210,7 +2155,7 @@ std::string slsDetectorCommand::cmdAcquire(int narg, const char * const args[], if (action == HELP_ACTION) { return helpAcquire(HELP_ACTION); } - if (!myDet->getNumberOfDetectors()) { + if (!myDet->size()) { FILE_LOG(logERROR) << "This shared memory has no detectors added. Aborting."; return std::string("acquire failed"); } @@ -2378,21 +2323,12 @@ std::string slsDetectorCommand::cmdHostname(int narg, const char * const args[], if (action == HELP_ACTION) { return helpHostname(HELP_ACTION); } - if (action == GET_ACTION) { - if ((cmd == "add") || (cmd == "replace")) - return std::string("cannot get"); - } if (action == PUT_ACTION) { - if (((cmd == "add") || (cmd == "hostname")) && - (detPos >= 0)) { - return std::string("Wrong usage - setting hostname/add only from " + if (detPos >= 0) { + return std::string("Wrong usage - setting hostname/virtual only from " "multiDetector level"); } - if ((cmd == "replace") && (detPos < 0)) { - return std::string("Wrong usage - replace only from " - "single detector level"); - } char hostname[1000]; strcpy(hostname, ""); @@ -2402,13 +2338,23 @@ std::string slsDetectorCommand::cmdHostname(int narg, const char * const args[], if (narg > 2) strcat(hostname, "+"); } - - if (cmd == "add") - myDet->addMultipleDetectors(hostname); - else + if (cmd == "hostname") { myDet->setHostname(hostname, detPos); + } + else if (cmd == "virtual") { + int port = -1; + int numDetectors = 0; + if (!sscanf(args[1], "%d", &numDetectors)) { + throw sls::RuntimeError("Cannot scan number of detector servers from virtual command\n"); + } + if (!sscanf(args[2], "%d", &port)) { + throw sls::RuntimeError("Cannot scan port from virtual command\n"); + } + myDet->setVirtualDetectorServers(numDetectors, port); + } else { + throw sls::RuntimeError("unknown command\n"); + } } - return myDet->getHostname(detPos); } @@ -2416,18 +2362,11 @@ std::string slsDetectorCommand::helpHostname(int action) { std::ostringstream os; if (action == GET_ACTION || action == HELP_ACTION) { os << std::string("hostname \t returns the hostname(s) of the multi detector structure.\n"); - os << std::string("add \t cannot get\n"); - os << std::string("replace \t cannot get\n"); } if (action == PUT_ACTION || action == HELP_ACTION) { os << std::string("hostname name [name name]\t frees shared memory and " "sets the hostname (or IP adress). Only allowed at multi detector level.\n"); - os << std::string("add det [det det]\t appends a hostname (or IP address) at " - "the end of the multi-detector structure. Only allowed at multi detector level." - "Returns hostnames in the multi detector structure\n"); - os << std::string("replace det \t Sets the hostname (or IP adress) for a " - "single detector. Only allowed at single detector level. " - "Returns the hostnames for that detector\n"); + os << std::string("virtual [n] [p]\t connects to n virtual detector servers at local host starting at port p \n"); } return os.str(); } @@ -2767,36 +2706,6 @@ std::string slsDetectorCommand::helpThreaded(int action) { return os.str(); } -std::string slsDetectorCommand::cmdImage(int narg, const char * const args[], int action, int detPos) { - std::string sval; - if (action == HELP_ACTION) - return helpImage(HELP_ACTION); - else if (action == GET_ACTION) - return std::string("Cannot get"); - - sval = std::string(args[1]); - - if (std::string(args[0]) == std::string("darkimage")) - myDet->loadImageToDetector(DARK_IMAGE, sval, detPos); - else if (std::string(args[0]) == std::string("gainimage")) - myDet->loadImageToDetector(GAIN_IMAGE, sval, detPos); - - return std::string("Image loaded succesfully"); -} - -std::string slsDetectorCommand::helpImage(int action) { - std::ostringstream os; - if (action == PUT_ACTION || action == HELP_ACTION) { - os << "darkimage f \t loads the image to detector from file f" << std::endl; - os << "gainimage f \t loads the image to detector from file f" << std::endl; - } - if (action == GET_ACTION || action == HELP_ACTION) { - os << "darkimage \t Cannot get" << std::endl; - os << "gainimage \t Cannot get" << std::endl; - } - return os.str(); -} - std::string slsDetectorCommand::cmdCounter(int narg, const char * const args[], int action, int detPos) { int ival; char answer[100]; @@ -2807,27 +2716,7 @@ std::string slsDetectorCommand::cmdCounter(int narg, const char * const args[], else if (action == PUT_ACTION) ival = atoi(args[1]); - - if (std::string(args[0]) == std::string("readctr")) { - if (action == PUT_ACTION) - return std::string("Cannot put"); - else { - if (narg < 3) - return std::string("should specify I/O file"); - sval = std::string(args[2]); - myDet->writeCounterBlockFile(sval, ival, detPos); - return std::string("Counter read succesfully"); - } - } else if (std::string(args[0]) == std::string("resetctr")) { - if (action == GET_ACTION) - return std::string("Cannot get"); - else { - myDet->resetCounterBlock(ival, detPos); - return std::string("successful"); - } - } - - else if (std::string(args[0]) == std::string("resmat")) { + if (std::string(args[0]) == std::string("resmat")) { if (action == PUT_ACTION) { if (!sscanf(args[1], "%d", &ival)) return std::string("Could not scan resmat input ") + std::string(args[1]); @@ -2848,13 +2737,9 @@ std::string slsDetectorCommand::helpCounter(int action) { std::ostringstream os; os << std::endl; if (action == PUT_ACTION || action == HELP_ACTION) { - os << "readctr \t Cannot put" << std::endl; - os << "resetctr i \t resets counter in detector, restarts acquisition if i=1" << std::endl; os << "resmat i \t sets/resets counter bit in detector" << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { - os << "readctr i fname\t reads counter in detector to file fname, restarts acquisition if i=1" << std::endl; - os << "resetctr \t Cannot get" << std::endl; os << "resmat i \t gets the counter bit in detector" << std::endl; } return os.str(); @@ -3241,15 +3126,7 @@ std::string slsDetectorCommand::cmdOnline(int narg, const char * const args[], i int ival; char ans[1000]; - if (cmd == "checkonline") { - if (action == PUT_ACTION) - return std::string("cannot set"); - strcpy(ans, myDet->checkOnline(detPos).c_str()); - if (!strlen(ans)) - strcpy(ans, "All online"); - else - strcat(ans, " :Not online"); - } else if (cmd == "activate") { + if (cmd == "activate") { if (action == PUT_ACTION) { if (!sscanf(args[1], "%d", &ival)) @@ -3269,13 +3146,7 @@ std::string slsDetectorCommand::cmdOnline(int narg, const char * const args[], i int ret = myDet->setDeactivatedRxrPaddingMode(-1, detPos); sprintf(ans, "%d %s", myDet->activate(-1, detPos), ret == 1 ? "padding" : (ret == 0 ? "nopadding" : "unknown")); } else { - if (action == PUT_ACTION) - return std::string("cannot set"); - strcpy(ans, myDet->checkReceiverOnline(detPos).c_str()); - if (!strlen(ans)) - strcpy(ans, "All receiver online"); - else - strcat(ans, " :Not all receiver online"); + return std::string("unknown command"); } return ans; @@ -3288,8 +3159,6 @@ std::string slsDetectorCommand::helpOnline(int action) { os << "activate i [p]\n sets the detector in activated (1) or deactivated (0) mode (does not send data). p is optional and can be padding (default) or nonpadding for receivers for deactivated detectors. Only for Eiger." << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { - os << "checkonline \n returns the hostnames of all detectors in offline mode" << std::endl; - os << "rx_checkonline \n returns the hostnames of all receiver in offline mode" << std::endl; os << "activate \n gets the detector activated (1) or deactivated (0) mode. And padding or nonpadding for the deactivated receiver. Only for Eiger." << std::endl; } return os.str(); @@ -3324,35 +3193,39 @@ std::string slsDetectorCommand::cmdDetectorSize(int narg, const char * const arg if (action == HELP_ACTION) return helpDetectorSize(action); - int ret, val = -1, pos = -1, i; + int ret, val = -1; char ans[1000]; if (action == PUT_ACTION) { - if (!sscanf(args[1], "%d", &val)) + if (cmd != "roi" && !sscanf(args[1], "%d", &val)) return std::string("could not scan ") + std::string(args[0]) + std::string(" ") + std::string(args[1]); + if (cmd == "clearroi") { + myDet->clearROI(detPos); + } + if (cmd == "roi") { //debug number of arguments - if ((val < 0) || (narg != ((val * 4) + 2))) + if (narg != 3) return helpDetectorSize(action); - ROI allroi[val]; - pos = 2; - for (i = 0; i < val; ++i) { - if ((!sscanf(args[pos++], "%d", &allroi[i].xmin)) || - (!sscanf(args[pos++], "%d", &allroi[i].xmax)) || - (!sscanf(args[pos++], "%d", &allroi[i].ymin)) || - (!sscanf(args[pos++], "%d", &allroi[i].ymax))) - return std::string("cannot parse arguments for roi"); - } - myDet->setROI(val, allroi, detPos); + ROI roi; + if (!sscanf(args[1], "%d", &roi.xmin)) + return std::string("cannot parse arguments for roi xmin"); + if (!sscanf(args[2], "%d", &roi.xmax)) + return std::string("cannot parse arguments for roi xmax"); + myDet->setROI(roi, detPos); } if (cmd == "detsizechan") { - if ((sscanf(args[1], "%d", &val)) && (val > 0)) - myDet->setMaxNumberOfChannelsPerDetector(X, val); - if ((narg > 2) && (sscanf(args[2], "%d", &val)) && (val > 0)) - myDet->setMaxNumberOfChannelsPerDetector(Y, val); + int val2 = 0; + if ((!sscanf(args[1], "%d", &val)) || (narg <= 2) || (!sscanf(args[2], "%d", &val2))) { + return std::string("Could not scan det size chan values"); + } + slsDetectorDefs::xy res; + res.x = val; + res.y = val2; + myDet->setNumberOfChannels(res); } if(cmd=="quad"){ @@ -3365,44 +3238,38 @@ std::string slsDetectorCommand::cmdDetectorSize(int narg, const char * const arg if ((!sscanf(args[1], "%d", &val)) || (val != 0 && val != 1)) return std::string("cannot scan flippeddata x mode: must be 0 or 1"); - myDet->setFlippedData(X, val, detPos); - } - - if (cmd == "flippeddatay") { - return std::string("Not required for this detector\n"); - if ((!sscanf(args[1], "%d", &val)) || (val != 0 && val != 1)) - return std::string("cannot scan flippeddata y mode: must be 0 or 1"); - - myDet->setFlippedData(Y, val, detPos); + myDet->setFlippedDataX(val, detPos); } if (cmd == "gappixels") { if ((!sscanf(args[1], "%d", &val)) || (val != 0 && val != 1)) return std::string("cannot scan gappixels mode: must be 0 or 1"); - if (detPos < 0) // only in multi detector level to update offsets etc. + if (detPos < 0) // only in multi detector level to update number of channels etc. myDet->enableGapPixels(val, detPos); } } if (cmd == "dr") { ret = myDet->setDynamicRange(val, detPos); + } else if (cmd == "clearroi") { + if (action == GET_ACTION) { + return std::string("Cannot get"); + } + return std::string("successful"); } else if (cmd == "roi") { - const ROI* r = myDet->getROI(ret, detPos); - - delete [] r; + ROI roi = myDet->getROI(detPos); + return (std::string("[") + std::to_string(roi.xmin) + std::string(",") + std::to_string(roi.xmax) + std::string("]")); } else if (cmd == "detsizechan") { - sprintf(ans, "%d %d", myDet->getMaxNumberOfChannelsPerDetector(X), myDet->getMaxNumberOfChannelsPerDetector(Y)); + slsDetectorDefs::xy res = myDet->getNumberOfChannels(); + sprintf(ans, "%d %d", res.x, res.y); return std::string(ans); } else if (cmd=="quad") { return std::to_string(myDet->getQuad()); } else if (cmd == "flippeddatax") { - ret = myDet->getFlippedData(X, detPos); - } else if (cmd == "flippeddatay") { - return std::string("Not required for this detector\n"); - ret = myDet->getFlippedData(Y, detPos); + ret = myDet->getFlippedDataX(detPos); } else if (cmd == "gappixels") { - if (detPos >= 0) // only in multi detector level to update offsets etc. + if (detPos >= 0) // only in multi detector level to update number of channels etc. return std::string("Cannot execute this command from slsDetector level. Please use multiSlsDetector level.\n"); ret = myDet->enableGapPixels(-1, detPos); } @@ -3421,20 +3288,19 @@ std::string slsDetectorCommand::helpDetectorSize(int action) { std::ostringstream os; if (action == PUT_ACTION || action == HELP_ACTION) { os << "dr i \n sets the dynamic range of the detector" << std::endl; - os << "roi i xmin xmax ymin ymax \n sets region of interest where i is number of rois;i=0 to clear rois" << std::endl; - os << "detsizechan x y \n sets the maximum number of channels for complete detector set in both directions; -1 is no limit" << std::endl; + os << "clearroi \n resets region of interest" << std::endl; + os << "roi xmin xmax \n sets region of interest " << std::endl; + os << "detsizechan x y \n sets the maximum number of channels for complete detector set in both directions; 0 is no limit" << std::endl; os << "quad i \n if i = 1, sets the detector size to a quad (Specific to an EIGER quad hardware). 0 by default."<< std::endl; os << "flippeddatax x \n sets if the data should be flipped on the x axis" << std::endl; - os << "flippeddatay y \n sets if the data should be flipped on the y axis" << std::endl; os << "gappixels i \n enables/disables gap pixels in system (detector & receiver). 1 sets, 0 unsets. Used in EIGER only and multidetector level." << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { os << "dr \n gets the dynamic range of the detector" << std::endl; os << "roi \n gets region of interest" << std::endl; - os << "detsizechan \n gets the maximum number of channels for complete detector set in both directions; -1 is no limit" << std::endl; + os << "detsizechan \n gets the maximum number of channels for complete detector set in both directions; 0 is no limit" << std::endl; os << "quad \n returns 1 if the detector size is a quad (Specific to an EIGER quad hardware). 0 by default."<< std::endl; os << "flippeddatax\n gets if the data will be flipped on the x axis" << std::endl; - os << "flippeddatay\n gets if the data will be flipped on the y axis" << std::endl; os << "gappixels\n gets if gap pixels is enabled in system. Used in EIGER only and multidetector level." << std::endl; } return os.str(); @@ -3659,18 +3525,17 @@ std::string slsDetectorCommand::cmdDigiTest(int narg, const char * const args[], return std::string(answer); } - else if (cmd == "digibittest") { - if (action == GET_ACTION) - return std::string("cannot get ") + cmd; - int ival = -1; - if (sscanf(args[1], "%d", &ival)) { - if ((ival == 0) || (ival == 1)) { - sprintf(answer, "%d", myDet->digitalTest(DIGITAL_BIT_TEST, ival, detPos)); - return std::string(answer); - } else - return std::string("Use only 0 or 1 to set/clear digital test bit\n"); - } else - return std::string("undefined number"); + else if (cmd == "imagetest") { + if (action == PUT_ACTION) { + int ival = -1; + if (!sscanf(args[1], "%d", &ival)) { + return std::string("could not scan parameter for imagetest\n"); + } + ival = (ival == 0) ? 0 : 1; + myDet->digitalTest(IMAGE_TEST, ival, detPos); + } + + return std::to_string(myDet->digitalTest(IMAGE_TEST, -1, detPos)); } return std::string("unknown test mode ") + cmd; @@ -3680,7 +3545,12 @@ std::string slsDetectorCommand::helpDigiTest(int action) { std::ostringstream os; if (action == GET_ACTION || action == HELP_ACTION) { - os << "digibittest:i \t performs digital test of the module i. Returns 0 if succeeded, otherwise error mask.Gotthard only." << std::endl; + os << "imagetest i \t If 1, adds channel intensity with precalculated values. Default is 0. Gotthard only." << std::endl; + os << "bustest \t performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes. Jungfrau only." << std::endl; + os << "firmwaretest \t performs the firmware test. Jungfrau only." << std::endl; + } + if (action == PUT_ACTION || action == HELP_ACTION) { + os << "imagetest i \t If 1, adds channel intensity with precalculated values. Default is 0. Gotthard only." << std::endl; os << "bustest \t performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes. Jungfrau only." << std::endl; os << "firmwaretest \t performs the firmware test. Jungfrau only." << std::endl; } @@ -4360,11 +4230,11 @@ std::string slsDetectorCommand::cmdTiming(int narg, const char * const args[], i return helpTiming(HELP_ACTION); } if (action == PUT_ACTION) { - if (myDet->externalCommunicationType(std::string(args[1])) == GET_EXTERNAL_COMMUNICATION_MODE) + if (myDet->timingModeType(std::string(args[1])) == GET_TIMING_MODE) return helpTiming(action); - myDet->setExternalCommunicationMode(myDet->externalCommunicationType(std::string(args[1])), detPos); + myDet->setTimingMode(myDet->timingModeType(std::string(args[1])), detPos); } - return myDet->externalCommunicationType(myDet->setExternalCommunicationMode(GET_EXTERNAL_COMMUNICATION_MODE, detPos)); + return myDet->timingModeType(myDet->setTimingMode(GET_TIMING_MODE, detPos)); } std::string slsDetectorCommand::helpTiming(int action) { @@ -4396,8 +4266,6 @@ std::string slsDetectorCommand::cmdTimer(int narg, const char * const args[], in index = SUBFRAME_DEADTIME; else if (cmd == "delay") index = DELAY_AFTER_TRIGGER; - else if (cmd == "gates") - index = GATES_NUMBER; else if (cmd == "frames") index = FRAME_NUMBER; else if (cmd == "cycles") @@ -4888,7 +4756,7 @@ std::string slsDetectorCommand::helpAdvanced(int action) { std::ostringstream os; if (action == PUT_ACTION || action == HELP_ACTION) { - os << "extsig mode \t sets the mode of the external signal. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; + os << "extsig mode \t sets the mode of the external signal. can be trigger_out_rising_edge, trigger_out_falling_edge. Gotthard only" << std::endl; os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, digital, analog_digital, overlow, nooverflow, unknown." << std::endl; os << "interruptsubframe flag \t sets the interrupt subframe flag. Setting it to 1 will interrupt the last subframe at the required exposure time. By default, this is disabled and set to 0, ie. it will wait for the last sub frame to finish exposing. Used for EIGER in 32 bit mode only." << std::endl; os << "readnlines f \t sets the number of rows to read out per half module. Options: 1 - 256 (Not all values as it depends on dynamic range and 10GbE enabled). Used for EIGER only. " << std::endl; @@ -4900,17 +4768,17 @@ std::string slsDetectorCommand::helpAdvanced(int action) { os << "led s \t sets led status (0 off, 1 on)" << std::endl; os << "diodelay m v \tsets the delay for the digital IO pins selected by mask m and delay set by v. mask is upto 64 bits in hex, delay max is 775ps, and set in steps of 25 ps. Used for MOENCH/CTB only." << std::endl; os << "powerchip i \t powers on or off the chip. i = 1 for on, i = 0 for off" << std::endl; - os << "auto_comp_disable i \t Currently not implemented. this mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). 1 enables mode, 0 disables mode. By default, mode is disabled (comparator is enabled throughout). (JUNGFRAU only). " << std::endl; + os << "auto_comp_disable i \t this mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). 1 enables mode, 0 disables mode. By default, mode is disabled (comparator is enabled throughout). (JUNGFRAU only). " << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { - os << "extsig \t gets the mode of the external signal. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; + os << "extsig \t gets the mode of the external signal. can be trigger_in_rising_edge, trigger_in_falling_edge. Gotthard only" << std::endl; os << "flags \t gets the readout flags. can be none, storeinram, tot, continous, parallel, nonparallel, digital, analog_digital, overflow, nooverflow, unknown" << std::endl; os << "interruptsubframe \t gets the interrupt subframe flag. Setting it to 1 will interrupt the last subframe at the required exposure time. By default, this is disabled and set to 0, ie. it will wait for the last sub frame to finish exposing. Used for EIGER in 32 bit mode only." << std::endl; os << "readnlines \t gets the number of rows to read out per half module. Used for EIGER only. " << std::endl; os << "led \t returns led status (0 off, 1 on)" << std::endl; os << "powerchip \t gets if the chip has been powered on or off" << std::endl; - os << "auto_comp_disable \t Currently not implemented. gets if the automatic comparator diable mode is enabled/disabled" << std::endl; + os << "auto_comp_disable \t gets if the automatic comparator diable mode is enabled/disabled" << std::endl; } return os.str(); } @@ -4938,7 +4806,7 @@ std::string slsDetectorCommand::cmdConfiguration(int narg, const char * const ar } else if (cmd == "rx_printconfig") { if (action == PUT_ACTION) return std::string("cannot put"); - myDet->printReceiverConfiguration(logINFO, detPos); + FILE_LOG(logINFO) << myDet->printReceiverConfiguration(detPos); return std::string(""); } else if (cmd == "parameters") { if (action == PUT_ACTION) { @@ -5131,7 +4999,7 @@ std::string slsDetectorCommand::helpReceiver(int action) { if (action == PUT_ACTION || action == HELP_ACTION) { os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start, stop." << std::endl; os << "resetframescaught [any value] \t resets frames caught by receiver" << std::endl; - os << "rx_readfreq \t sets the gui read frequency of the receiver, 0 if gui requests frame, >0 if receiver sends every nth frame to gui" << std::endl; + os << "rx_readfreq \t sets the gui read frequency of the receiver, 0 if gui requests frame, >0 if receiver sends every nth frame to gui. Default : 1" << std::endl; os << "tengiga \t sets system to be configure for 10Gbe if set to 1, else 1Gbe if set to 0" << std::endl; os << "rx_fifodepth [val]\t sets receiver fifo depth to val" << std::endl; os << "rx_silent [i]\t sets receiver in silent mode, ie. it will not print anything during real time acquisition. 1 sets, 0 unsets." << std::endl; @@ -5148,7 +5016,7 @@ std::string slsDetectorCommand::helpReceiver(int action) { os << "receiver \t returns the status of receiver - can be running or idle" << std::endl; os << "framescaught \t returns the number of frames caught by receiver(average for multi)" << std::endl; os << "frameindex \t returns the current frame index of receiver(average for multi)" << std::endl; - os << "rx_readfreq \t returns the gui read frequency of the receiver" << std::endl; + os << "rx_readfreq \t returns the gui read frequency of the receiver. DEfault: 1" << std::endl; os << "tengiga \t returns 1 if the system is configured for 10Gbe else 0 for 1Gbe" << std::endl; os << "rx_fifodepth \t returns receiver fifo depth" << std::endl; os << "rx_silent \t returns receiver silent mode enable. 1 is silent, 0 not silent." << std::endl; @@ -5245,7 +5113,8 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], if (action == PUT_ACTION) { fname = std::string(args[1]); - os << myDet->setPattern(fname, detPos); + myDet->setPattern(fname, detPos); + os << "successful"; } else if (action == GET_ACTION) os << "Cannot get"; } else if (cmd == "patword") { diff --git a/slsDetectorSoftware/src/slsDetectorUsers.cpp b/slsDetectorSoftware/src/slsDetectorUsers.cpp index 5aa1aeabe..acab7f2a9 100755 --- a/slsDetectorSoftware/src/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/src/slsDetectorUsers.cpp @@ -4,26 +4,14 @@ -int slsDetectorUsers::getNumberOfDetectors() const { - return detector.getNumberOfDetectors(); +int slsDetectorUsers::size() const { + return detector.size(); } -int slsDetectorUsers::getMaximumDetectorSize(int &nx, int &ny){ - nx=detector.getMaxNumberOfChannelsPerDetector(slsDetectorDefs::X); - ny=detector.getMaxNumberOfChannelsPerDetector(slsDetectorDefs::Y); - return nx*ny; -} - -int slsDetectorUsers::getDetectorSize(int &x, int &y, int &nx, int &ny, int detPos){ - if (detPos < 0) { - x = 0; - y = 0; - } else { - x = detector.getDetectorOffset(slsDetectorDefs::X, detPos); - y = detector.getDetectorOffset(slsDetectorDefs::Y, detPos); - } - nx=detector.getTotalNumberOfChannels(slsDetectorDefs::X, detPos); - ny=detector.getTotalNumberOfChannels(slsDetectorDefs::Y, detPos); +int slsDetectorUsers::getDetectorSize(int &nx, int &ny, int detPos){ + slsDetectorDefs::xy res = detector.getNumberOfChannels(); + nx=res.x; + ny=res.y; return nx*ny; } @@ -40,8 +28,8 @@ int slsDetectorUsers::readConfigurationFile(const std::string& fname){ } } -int slsDetectorUsers::writeConfigurationFile(const std::string& fname){ - return detector.writeConfigurationFile(fname); +void slsDetectorUsers::writeConfigurationFile(const std::string& fname){ + detector.writeConfigurationFile(fname); } int slsDetectorUsers::retrieveDetectorSetup(const std::string& fname){ @@ -159,10 +147,6 @@ int64_t slsDetectorUsers::setNumberOfCycles(int64_t t, int detPos){ return detector.setNumberOfCycles(t, detPos); } -int64_t slsDetectorUsers::setNumberOfGates(int64_t t, int detPos){ - return detector.setNumberOfGates(t, detPos); -} - int64_t slsDetectorUsers::setNumberOfStorageCells(int64_t t, int detPos) { return detector.setNumberOfStorageCells(t, detPos); } @@ -176,7 +160,7 @@ double slsDetectorUsers::getMeasuredSubFramePeriod(bool inseconds, int detPos) { } int slsDetectorUsers::setTimingMode(int pol, int detPos){ - return detector.setExternalCommunicationMode(slsDetectorDefs::externalCommunicationMode(pol), detPos); + return detector.setTimingMode(slsDetectorDefs::timingMode(pol), detPos); } int slsDetectorUsers::setClockDivider(int value, int detPos) { @@ -230,12 +214,12 @@ int slsDetectorUsers::setFlowControl10G(int i, int detPos) { return detector.setFlowControl10G(i, detPos); } -void slsDetectorUsers::setROI(int n, slsDetectorDefs::ROI roiLimits[], int detPos) { - detector.setROI(n, roiLimits, detPos); +void slsDetectorUsers::setROI(slsDetectorDefs::ROI arg, int detPos) { + detector.setROI(arg, detPos); } -const slsDetectorDefs::ROI* slsDetectorUsers::getROI(int &n, int detPos) { - return detector.getROI(n, detPos); +slsDetectorDefs::ROI slsDetectorUsers::getROI(int detPos) { + return detector.getROI(detPos); } /************************************************************************ @@ -399,10 +383,6 @@ void slsDetectorUsers::registerAcquisitionFinishedCallback(void( *func)(double,i detector.registerAcquisitionFinishedCallback(func,pArg); } -void slsDetectorUsers::registerProgressCallback(void( *func)(double,void*), void *pArg) { - detector.registerProgressCallback(func,pArg); -} - void slsDetectorUsers::putCommand(const std::string& command){ multiSlsDetectorClient(command, slsDetectorDefs::PUT_ACTION, &detector); } diff --git a/slsDetectorSoftware/tests/test-Result.cpp b/slsDetectorSoftware/tests/test-Result.cpp index 73e3878df..61a34efdc 100644 --- a/slsDetectorSoftware/tests/test-Result.cpp +++ b/slsDetectorSoftware/tests/test-Result.cpp @@ -1,17 +1,21 @@ #include "Result.h" +#include "TypeTraits.h" #include "catch.hpp" - -#include +#include using sls::Result; -TEST_CASE("Default construction", "[detector][n2]") { +TEST_CASE("Result looks and behaves like a standard container") { + REQUIRE(sls::is_container>::value == true); +} + +TEST_CASE("Default construction is possible and gives an empty result") { Result res; REQUIRE(res.size() == 0); REQUIRE(res.empty() == true); } -TEST_CASE("Initializer list construction", "[n2]") { +TEST_CASE("Result can be constructed from std::initializer_list") { Result res{1, 2, 5}; REQUIRE(res.empty() == false); REQUIRE(res.size() == 3); @@ -20,7 +24,7 @@ TEST_CASE("Initializer list construction", "[n2]") { REQUIRE(res[2] == 5); } -TEST_CASE("Construct with value and number", "[n2]") { +TEST_CASE("Like vector it can be constructed from size and value") { Result res(5, 7); REQUIRE(res.size() == 5); REQUIRE(res[0] == 7); @@ -30,46 +34,125 @@ TEST_CASE("Construct with value and number", "[n2]") { REQUIRE(res[4] == 7); } -TEST_CASE("Squash empty", "[n2]") { - Result res; - REQUIRE(res.squash() == 0.); +TEST_CASE("Result can be iterated using modern syntax"){ + Result res{0,1,2,3,4,5}; + + int i = 0; + for (const auto& r:res) + REQUIRE(r == i++); + } -TEST_CASE("Squash gives either value or default constructed value", "[n2]") { +TEST_CASE("Calling squash on an empty Result produces default value") { + Result res; + REQUIRE(res.squash() == 0.); + + Result res2; + REQUIRE(res2.squash() == 0u); + + Result res3; + REQUIRE(res3.squash() == ""); +} + +TEST_CASE("When equal squash gives the front value") { Result res{3, 3, 3}; REQUIRE(res.squash() == 3); +} - res.push_back(5); +TEST_CASE("When elements are not equal squash gives default value") { + Result res{3, 3, 3, 5}; REQUIRE(res.squash() == 0); +} + +TEST_CASE("String compare with squash") { + Result res{"hej", "hej", "hej"}; + REQUIRE(res.squash() == "hej"); +} + +TEST_CASE("tsquash throws for different elements") { + Result res{1, 2, 3}; + REQUIRE_THROWS(res.tsquash("something is wrong")); +} + +TEST_CASE("tsquash returns front element when equal") { + Result res{"word", "word"}; + REQUIRE(res.tsquash("error") == "word"); +} + +TEST_CASE("When provided squash gives default value if elements differ") { + Result res{5, 5, 5}; + REQUIRE(res.squash(-1) == 5); + + res.push_back(7); // adding a different value REQUIRE(res.squash(-1) == -1); } -TEST_CASE("Updating an element", "[n2]") { - +TEST_CASE("It is possible to update elements by index access") { Result res{1, 2, 3}; - REQUIRE(res[0] == 1); - REQUIRE(res[1] == 2); - REQUIRE(res[2] == 3); - res[0] = 5; REQUIRE(res[0] == 5); REQUIRE(res[1] == 2); REQUIRE(res[2] == 3); } -TEST_CASE("equal", "[n2]"){ +TEST_CASE("Check if elements are equal") { Result res; + REQUIRE(res.equal() == false); // no elements to compare - // There are no elements to compare - REQUIRE(res.equal() == false); - - //all (the one) elements are equal - res.push_back(1.2); + res.push_back(1.2); // one element "all" equal REQUIRE(res.equal() == true); - res.push_back(1.2); + res.push_back(1.2); // two elements REQUIRE(res.equal() == true); - res.push_back(1.3); + res.push_back(1.3); // three elements 1.2, 1.2, 1.3 REQUIRE(res.equal() == false); } + +TEST_CASE("Result can be converted to std::vector") { + Result res{1, 2, 3, 4, 5}; + std::vector vec{1, 2, 3, 4, 5}; + std::vector vec2 = res; + REQUIRE(vec2 == vec); +} + +TEST_CASE("Result can be printed using <<") { + Result res{1, 2, 3}; + std::ostringstream os; + os << res; + REQUIRE(os.str() == "[1, 2, 3]"); +} + +TEST_CASE("Convert from Result to Result") { + // This function is used when the detector class + // returns time as integers + using ns = std::chrono::nanoseconds; + Result res{10, 50, 236}; + + Result res2 = res; + REQUIRE(res2[0] == ns(10)); + REQUIRE(res2[1] == ns(50)); + REQUIRE(res2[2] == ns(236)); +} + + +TEST_CASE("Result of vectors"){ + using VecVec = std::vector>; + VecVec vecvec{{1,2,3}, {4,5,6}}; + Result res{vecvec}; +} + +TEST_CASE("Free function begin end"){ + Result res{"ett", "nio", "sjutton"}; + REQUIRE(begin(res) == res.begin()); + REQUIRE(end(res) == res.end()); +} + +TEST_CASE("Sorting a Result"){ + Result res{4,5,1,3}; + std::sort(res.begin(), res.end()); + REQUIRE(res[0] == 1); + REQUIRE(res[1] == 3); + REQUIRE(res[2] == 4); + REQUIRE(res[3] == 5); +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-multiSlsDetector.cpp b/slsDetectorSoftware/tests/test-multiSlsDetector.cpp index 37342ece6..5f09b1a03 100755 --- a/slsDetectorSoftware/tests/test-multiSlsDetector.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetector.cpp @@ -9,75 +9,75 @@ using namespace sls; -SCENARIO("Multi detector operation", "[detector]") { +// SCENARIO("Multi detector operation", "[detector]") { - multiSlsDetector::freeSharedMemory(20, -1); +// multiSlsDetector::freeSharedMemory(20, -1); - GIVEN("An empty multi detector") { - multiSlsDetector m(20); - THEN("the size is zero") { - CHECK(m.getNumberOfDetectors() == 0); - CHECK(m.getDataBytes() == 0); - CHECK(m.getTotalNumberOfChannels() == 0); - } +// GIVEN("An empty multi detector") { +// multiSlsDetector m(20); +// THEN("the size is zero") { +// CHECK(m.getNumberOfDetectors() == 0); +// CHECK(m.getDataBytes() == 0); +// CHECK(m.getTotalNumberOfChannels() == 0); +// } - WHEN("we add a detector") { - m.addSlsDetector(sls::make_unique( - slsDetectorDefs::detectorType::EIGER, 20, 0)); - THEN("the size and number of detector changes") { - CHECK(m.getNumberOfDetectors() == 1); - CHECK(m.getTotalNumberOfChannels() == 256 * 1024); - } +// WHEN("we add a detector") { +// m.addSlsDetector(sls::make_unique( +// slsDetectorDefs::detectorType::EIGER, 20, 0)); +// THEN("the size and number of detector changes") { +// CHECK(m.getNumberOfDetectors() == 1); +// CHECK(m.getTotalNumberOfChannels() == 256 * 1024); +// } - WHEN("we add another detector") { - m.addSlsDetector(sls::make_unique( - slsDetectorDefs::detectorType::EIGER, 20, 1)); - THEN("the size and number of detector changes") { - CHECK(m.getNumberOfDetectors() == 2); - CHECK(m.getTotalNumberOfChannels() == 2 * 256 * 1024); - } +// WHEN("we add another detector") { +// m.addSlsDetector(sls::make_unique( +// slsDetectorDefs::detectorType::EIGER, 20, 1)); +// THEN("the size and number of detector changes") { +// CHECK(m.getNumberOfDetectors() == 2); +// CHECK(m.getTotalNumberOfChannels() == 2 * 256 * 1024); +// } - WHEN("We set the trimen") { - std::vector energies{5000, 6000, 7000, 8000, 9000}; - m.setTrimEn(energies); - THEN("we read back the same values") { - CHECK(m.getTrimEn() == energies); - } - } - WHEN("We set the trimen to different values") { - std::vector en0{5000, 6000, 7000, 8000, 9000}; - std::vector en1{6000, 7000, 8000, 9000}; - m.setTrimEn(en0, 0); - m.setTrimEn(en1, 1); - THEN("we read back the same values") { - CHECK(m.getTrimEn(0) == en0); - CHECK(m.getTrimEn(1) == en1); - CHECK(m.getTrimEn() == std::vector{-1}); - } - } - } - } - m.freeSharedMemory(); - } -} +// WHEN("We set the trimen") { +// std::vector energies{5000, 6000, 7000, 8000, 9000}; +// m.setTrimEn(energies); +// THEN("we read back the same values") { +// CHECK(m.getTrimEn() == energies); +// } +// } +// WHEN("We set the trimen to different values") { +// std::vector en0{5000, 6000, 7000, 8000, 9000}; +// std::vector en1{6000, 7000, 8000, 9000}; +// m.setTrimEn(en0, 0); +// m.setTrimEn(en1, 1); +// THEN("we read back the same values") { +// CHECK(m.getTrimEn(0) == en0); +// CHECK(m.getTrimEn(1) == en1); +// CHECK(m.getTrimEn() == std::vector{-1}); +// } +// } +// } +// } +// m.freeSharedMemory(); +// } +// } -TEST_CASE("Set and get partialFramesPadding", "[detector][somenewtag]"){ +// TEST_CASE("Set and get partialFramesPadding", "[detector][somenewtag]"){ - multiSlsDetector::freeSharedMemory(20, -1); - multiSlsDetector m(20); - m.addSlsDetector(sls::make_unique( - slsDetectorDefs::detectorType::EIGER, 20, 0)); - m.addSlsDetector(sls::make_unique( - slsDetectorDefs::detectorType::EIGER, 20, 1)); +// multiSlsDetector::freeSharedMemory(20, -1); +// multiSlsDetector m(20); +// m.addSlsDetector(sls::make_unique( +// slsDetectorDefs::detectorType::EIGER, 20, 0)); +// m.addSlsDetector(sls::make_unique( +// slsDetectorDefs::detectorType::EIGER, 20, 1)); - m.setPartialFramesPadding(false); - CHECK(m.getPartialFramesPadding() == 0); +// m.setPartialFramesPadding(false); +// CHECK(m.getPartialFramesPadding() == 0); - m.setPartialFramesPadding(true); - CHECK(m.getPartialFramesPadding() == 1); +// m.setPartialFramesPadding(true); +// CHECK(m.getPartialFramesPadding() == 1); - m.setPartialFramesPadding(false, 0); - CHECK(m.getPartialFramesPadding() == -1); +// m.setPartialFramesPadding(false, 0); +// CHECK(m.getPartialFramesPadding() == -1); - m.freeSharedMemory(); -} +// m.freeSharedMemory(); +// } diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index a27633663..80f38d4b8 100755 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -88,11 +88,29 @@ target_link_libraries(slsReceiver PUBLIC rt ) +add_executable(slsMultiReceiver + src/multiReceiver.cpp) + + +set_target_properties(slsMultiReceiver PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) + +target_link_libraries(slsMultiReceiver PUBLIC + slsProjectOptions + slsProjectWarnings + slsSupportLib + slsReceiverShared + pthread + ${ZeroMQ_LIBRARIES} + rt +) + if (SLS_USE_TESTS) add_subdirectory(tests) endif(SLS_USE_TESTS) -install(TARGETS slsReceiverShared slsReceiver +install(TARGETS slsReceiverShared slsReceiver slsMultiReceiver EXPORT "${TARGETS_EXPORT_NAME}" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/slsReceiverSoftware/include/BinaryFile.h b/slsReceiverSoftware/include/BinaryFile.h index 1ac9ff8ab..6178d728c 100755 --- a/slsReceiverSoftware/include/BinaryFile.h +++ b/slsReceiverSoftware/include/BinaryFile.h @@ -58,19 +58,10 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi /** * Create master file * @param mfwenable master file write enable - * @param en ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - int CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap) override; + int CreateMasterFile(bool mfwenable, masterAttributes& attr) override; /** * Close Current File diff --git a/slsReceiverSoftware/include/BinaryFileStatic.h b/slsReceiverSoftware/include/BinaryFileStatic.h index 3fbd8c25a..49f42eae1 100755 --- a/slsReceiverSoftware/include/BinaryFileStatic.h +++ b/slsReceiverSoftware/include/BinaryFileStatic.h @@ -97,26 +97,11 @@ class BinaryFileStatic { * @param fd pointer to file handle * @param fname master file name * @param owenable overwrite enable - * @param dr dynamic range - * @param tenE ten giga enable - * @param size image size - * @param nPixelsX number of pixels in x direction - * @param nPixelsY number of pixels in y direction - * @param nf number of images - * @param maxf maximum frames per file - * @param acquisitionTime acquisition time - * @param acquisitionPeriod acquisition period - * @param subexposuretime sub exposure time - * @param subperiod sub period - * @param version version of software for binary writing + * @param attr master file attributes * @returns 0 for success and 1 for fail */ static int CreateMasterDataFile(FILE*& fd, std::string fname, bool owenable, - uint32_t dr, bool tenE, uint32_t size, - uint32_t nPixelsX, uint32_t nPixelsY, uint64_t nf, - uint32_t maxf, - uint64_t acquisitionTime, uint64_t subexposuretime, - uint64_t subperiod, uint64_t acquisitionPeriod, double version) + masterAttributes& attr) { if(!owenable){ if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ @@ -135,17 +120,27 @@ class BinaryFileStatic { char message[MAX_MASTER_FILE_LENGTH]; sprintf(message, "Version : %.1f\n" + "Detector Type : %d\n" "Dynamic Range : %d\n" "Ten Giga : %d\n" "Image Size : %d bytes\n" - "row : %d pixels\n" - "col : %d pixels\n" - "Max. Frames Per File : %u\n" + "nPixelsX : %d pixels\n" + "nPixelsY : %d pixels\n" + "Max Frames Per File : %u\n" "Total Frames : %lld\n" "Exptime (ns) : %lld\n" "SubExptime (ns) : %lld\n" "SubPeriod(ns) : %lld\n" "Period (ns) : %lld\n" + "Gap Pixels Enable : %d\n" + "Quad Enable : %d\n" + "Parallel Flag : %d\n" + "Analog Flag : %d\n" + "Digital Flag : %d\n" + "ADC Mask : %d\n" + "Dbit Offset : %d\n" + "Dbit Bitset : %lld\n" + "Roi (xmin, xmax) : %d %d\n" "Timestamp : %s\n\n" "#Frame Header\n" @@ -164,18 +159,29 @@ class BinaryFileStatic { "Header Version : 1 byte\n" "Packets Caught Mask : 64 bytes\n" , - version, - dr, - tenE, - size, - nPixelsX, - nPixelsY, - maxf, - (long long int)nf, - (long long int)acquisitionTime, - (long long int)subexposuretime, - (long long int)subperiod, - (long long int)acquisitionPeriod, + attr.version, + attr.detectorType, + attr.dynamicRange, + attr.tenGiga, + attr.imageSize, + attr.nPixelsX, + attr.nPixelsY, + attr.maxFramesPerFile, + (long long int)attr.totalFrames, + (long long int)attr.exptimeNs, + (long long int)attr.subExptimeNs, + (long long int)attr.subPeriodNs, + (long long int)attr.periodNs, + attr.gapPixelsEnable, + attr.quadEnable, + attr.parallelFlag, + attr.analogFlag, + attr.digitalFlag, + attr.adcmask, + attr.dbitoffset, + (long long int)attr.dbitlist, + attr.roiXmin, + attr.roiXmax, ctime(&t)); if (strlen(message) > MAX_MASTER_FILE_LENGTH) { FILE_LOG(logERROR) << "Master File Size " << strlen(message) << diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index 496c9ab5f..61dbe3b66 100755 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -10,6 +10,7 @@ */ #include "ThreadObject.h" +#include "receiver_defs.h" class GeneralData; class Fifo; @@ -176,16 +177,10 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** * Create New File - * @param en ten giga enable - * @param nf number of frames - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - int CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t st, - uint64_t sp, uint64_t ap); + int CreateNewFile(masterAttributes& attr); /** * Closes files diff --git a/slsReceiverSoftware/include/DataStreamer.h b/slsReceiverSoftware/include/DataStreamer.h index b3e62d48d..567cf364a 100755 --- a/slsReceiverSoftware/include/DataStreamer.h +++ b/slsReceiverSoftware/include/DataStreamer.h @@ -31,9 +31,10 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { * @param ajh additional json header * @param nd pointer to number of detectors in each dimension * @param gpEnable pointer to gap pixels enable + * @param qe pointer to quad Enable */ - DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector* r, - uint64_t* fi, int fd, char* ajh, int* nd, bool* gpEnable); + DataStreamer(int ind, Fifo* f, uint32_t* dr, ROI* r, + uint64_t* fi, int fd, char* ajh, int* nd, bool* gpEnable, bool* qe); /** * Destructor @@ -188,7 +189,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { uint32_t* dynamicRange; /** ROI */ - std::vector* roi; + ROI* roi; /** adc Configured */ int adcConfigured; @@ -226,5 +227,8 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { /** Gap Pixels Enable */ bool* gapPixelsEnable; + /** Quad Enable */ + bool* quadEnable; + }; diff --git a/slsReceiverSoftware/include/File.h b/slsReceiverSoftware/include/File.h index 2a0dfb761..02a43c8e0 100755 --- a/slsReceiverSoftware/include/File.h +++ b/slsReceiverSoftware/include/File.h @@ -10,6 +10,7 @@ #include "sls_detector_defs.h" #include "logger.h" +#include "receiver_defs.h" #include @@ -109,19 +110,10 @@ class File : private virtual slsDetectorDefs { /** * Create master file * @param mfwenable master file write enable - * @param en ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - virtual int CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, - uint64_t sp, uint64_t ap) = 0; + virtual int CreateMasterFile(bool mfwenable, masterAttributes& attr) = 0; // HDf5 specific /** diff --git a/slsReceiverSoftware/include/GeneralData.h b/slsReceiverSoftware/include/GeneralData.h index bfbd1e1c7..9a3c4f422 100755 --- a/slsReceiverSoftware/include/GeneralData.h +++ b/slsReceiverSoftware/include/GeneralData.h @@ -137,17 +137,17 @@ public: * Set ROI * @param i ROI */ - virtual void SetROI(std::vector i) { + virtual void SetROI(slsDetectorDefs::ROI i) { FILE_LOG(logERROR) << "SetROI is a generic function that should be overloaded by a derived class"; }; /** * Get Adc configured * @param index thread index for debugging purposes - * @param i pointer to a vector of ROI pointers + * @param ROI * @returns adc configured */ - virtual int GetAdcConfigured(int index, std::vector* i) const{ + virtual int GetAdcConfigured(int index, slsDetectorDefs::ROI i) const{ FILE_LOG(logERROR) << "GetAdcConfigured is a generic function that should be overloaded by a derived class"; return 0; }; @@ -299,9 +299,9 @@ private: * Set ROI * @param i ROI */ - void SetROI(std::vector i) { + void SetROI(slsDetectorDefs::ROI i) { // all adcs - if(!i.size()) { + if(i.xmin == -1) { nPixelsX = 1280; dataSize = 1280; packetSize = GOTTHARD_PACKET_SIZE; @@ -340,28 +340,21 @@ private: /** * Get Adc configured * @param index thread index for debugging purposes - * @param i pointer to a vector of ROI + * @param i ROI * @returns adc configured */ - int GetAdcConfigured(int index, std::vector* i) const{ + int GetAdcConfigured(int index, slsDetectorDefs::ROI i) const{ int adc = -1; // single adc - if(i->size()) { + if(i.xmin != -1) { // gotthard can have only one adc per detector enabled (or all) - // so just looking at the first roi is enough (more not possible at the moment) - - //if its for 1 adc or general - if ((i->at(0).xmin == 0) && (i->at(0).xmax == nChip * nChan)) + //adc = mid value/numchans also for only 1 roi + adc = ((((i.xmax) + (i.xmin))/2)/ + (nChan * nChipsPerAdc)); + if((adc < 0) || (adc > 4)) { + FILE_LOG(logWARNING) << index << ": Deleting ROI. " + "Adc value should be between 0 and 4"; adc = -1; - else { - //adc = mid value/numchans also for only 1 roi - adc = ((((i->at(0).xmax) + (i->at(0).xmin))/2)/ - (nChan * nChipsPerAdc)); - if((adc < 0) || (adc > 4)) { - FILE_LOG(logWARNING) << index << ": Deleting ROI. " - "Adc value should be between 0 and 4"; - adc = -1; - } } } FILE_LOG(logINFO) << "Adc Configured: " << adc; diff --git a/slsReceiverSoftware/include/HDF5File.h b/slsReceiverSoftware/include/HDF5File.h index 0a93ed712..c3727109e 100755 --- a/slsReceiverSoftware/include/HDF5File.h +++ b/slsReceiverSoftware/include/HDF5File.h @@ -94,19 +94,10 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt /** * Create master file * @param mfwenable master file write enable - * @param en ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - int CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap); + int CreateMasterFile(bool mfwenable, masterAttributes& attr); /** * End of Acquisition diff --git a/slsReceiverSoftware/include/HDF5FileStatic.h b/slsReceiverSoftware/include/HDF5FileStatic.h index fc771ab99..7008478d5 100755 --- a/slsReceiverSoftware/include/HDF5FileStatic.h +++ b/slsReceiverSoftware/include/HDF5FileStatic.h @@ -291,26 +291,11 @@ public: * Create master file * @param fname master file name * @param owenable overwrite enable - * @param dr dynamic range - * @param tenE ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param nf number of images - * @param maxf maximum frames per file - * @param acquisitionTime acquisition time - * @param subexposuretime sub exposure time - * @param subperiod sub period - * @param acquisitionPeriod acquisition period - * @param version version of software for hdf5 writing + * @param attr master file attributes * @returns 0 for success and 1 for fail */ static int CreateMasterDataFile(H5File*& fd, std::string fname, bool owenable, - uint32_t dr, bool tenE, uint32_t size, - uint32_t nPixelsx, uint32_t nPixelsy, uint64_t nf, - uint32_t maxf, - uint64_t acquisitionTime, uint64_t subexposuretime, - uint64_t subperiod, uint64_t acquisitionPeriod, double version) + masterAttributes& attr) { try { Exception::dontPrint(); //to handle errors @@ -337,7 +322,7 @@ public: //create attributes //version - dValue=version; + dValue = attr.version; attribute = fd->createAttribute("version",PredType::NATIVE_DOUBLE, dataspace); attribute.write(PredType::NATIVE_DOUBLE, &dValue); @@ -351,61 +336,109 @@ public: //Dynamic Range dataset = group5.createDataSet ( "dynamic range", PredType::NATIVE_INT, dataspace ); - dataset.write ( &dr, PredType::NATIVE_INT); + dataset.write ( &(attr.dynamicRange), PredType::NATIVE_INT); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("bits")); //Ten Giga - iValue = tenE; + iValue = attr.tenGiga; dataset = group5.createDataSet ( "ten giga enable", PredType::NATIVE_INT, dataspace ); dataset.write ( &iValue, PredType::NATIVE_INT); //Image Size dataset = group5.createDataSet ( "image size", PredType::NATIVE_INT, dataspace ); - dataset.write ( &size, PredType::NATIVE_INT); + dataset.write ( &(attr.imageSize), PredType::NATIVE_INT); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("bytes")); //x dataset = group5.createDataSet ( "number of pixels in x axis", PredType::NATIVE_INT, dataspace ); - dataset.write ( &nPixelsx, PredType::NATIVE_INT); + dataset.write ( &(attr.nPixelsX), PredType::NATIVE_INT); //y dataset = group5.createDataSet ( "number of pixels in y axis", PredType::NATIVE_INT, dataspace ); - dataset.write ( &nPixelsy, PredType::NATIVE_INT); + dataset.write ( &(attr.nPixelsY), PredType::NATIVE_INT); //Maximum frames per file dataset = group5.createDataSet ( "maximum frames per file", PredType::NATIVE_INT, dataspace ); - dataset.write ( &maxf, PredType::NATIVE_INT); + dataset.write ( &(attr.maxFramesPerFile), PredType::NATIVE_INT); //Total Frames dataset = group5.createDataSet ( "total frames", PredType::STD_U64LE, dataspace ); - dataset.write ( &nf, PredType::STD_U64LE); + dataset.write ( &(attr.totalFrames), PredType::STD_U64LE); //Exptime dataset = group5.createDataSet ( "exposure time", PredType::STD_U64LE, dataspace ); - dataset.write ( &acquisitionTime, PredType::STD_U64LE); + dataset.write ( &(attr.exptimeNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); //SubExptime dataset = group5.createDataSet ( "sub exposure time", PredType::STD_U64LE, dataspace ); - dataset.write ( &subexposuretime, PredType::STD_U64LE); + dataset.write ( &(attr.subExptimeNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); //SubPeriod dataset = group5.createDataSet ( "sub period", PredType::STD_U64LE, dataspace ); - dataset.write ( &subperiod, PredType::STD_U64LE); + dataset.write ( &(attr.subPeriodNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); //Period dataset = group5.createDataSet ( "acquisition period", PredType::STD_U64LE, dataspace ); - dataset.write ( &acquisitionPeriod, PredType::STD_U64LE); + dataset.write ( &(attr.periodNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); + //Gap Pixels Enable + dataset = group5.createDataSet ( "gap pixels enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //Quad Enable + dataset = group5.createDataSet ( "quad enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Gap Pixels Enable + dataset = group5.createDataSet ( "gap pixels enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //Quad Enable + dataset = group5.createDataSet ( "quad enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Parallel Flag + dataset = group5.createDataSet ( "parallel flag", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //Analog Flag + dataset = group5.createDataSet ( "analog flag", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Digital Flag + dataset = group5.createDataSet ( "digital flag", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //ADC Mask + dataset = group5.createDataSet ( "adc mask", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Dbit Offset + dataset = group5.createDataSet ( "dbit offset", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + // Dbit List + dataset = group5.createDataSet ( "dbit bitset list", PredType::STD_U64LE, dataspace ); + dataset.write ( &(attr.periodNs), PredType::STD_U64LE); + + // Roi xmin + dataset = group5.createDataSet ( "roi xmin", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.roiXmin), PredType::NATIVE_INT); + + // Roi xmax + dataset = group5.createDataSet ( "roi xmax", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.roiXmax), PredType::NATIVE_INT); + //Timestamp time_t t = time(0); dataset = group5.createDataSet ( "timestamp", strdatatype, dataspace ); diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index d1d004f87..e4f6b30e4 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -30,8 +30,8 @@ #define MAX_CHUNKED_IMAGES (1) //versions -#define HDF5_WRITER_VERSION (3.0) //1 decimal places -#define BINARY_WRITER_VERSION (3.0) //1 decimal places +#define HDF5_WRITER_VERSION (5.0) //1 decimal places +#define BINARY_WRITER_VERSION (5.0) //1 decimal places //parameters to calculate fifo depth @@ -49,3 +49,28 @@ #define STREAMER_PRIORITY (10) #define TCP_PRIORITY (10) +struct masterAttributes { + double version; + uint32_t detectorType; + uint32_t dynamicRange; + uint32_t tenGiga; + uint32_t imageSize; + uint32_t nPixelsX; + uint32_t nPixelsY; + uint32_t maxFramesPerFile; + uint64_t totalFrames; + uint64_t exptimeNs; + uint64_t subExptimeNs; + uint64_t subPeriodNs; + uint64_t periodNs; + uint32_t gapPixelsEnable; + uint32_t quadEnable; + uint32_t parallelFlag; + uint32_t analogFlag; + uint32_t digitalFlag; + uint32_t adcmask; + uint32_t dbitoffset; + uint64_t dbitlist; + uint32_t roiXmin; + uint32_t roiXmax; + }; \ No newline at end of file diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index 1fb3b7b15..f80bf91ac 100755 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -64,10 +64,10 @@ class slsReceiverImplementation : private virtual slsDetectorDefs { std::string getDetectorHostname() const; /* - * Get flipped data across 'axis' - * @return if data is flipped across 'axis' + * Get flipped data across x axis + * @return if data is flipped across x axis */ - int getFlippedData(int axis = 0) const; + int getFlippedDataX() const; /** * Get Gap Pixels Enable (eiger specific) @@ -208,9 +208,9 @@ class slsReceiverImplementation : private virtual slsDetectorDefs { //***acquisition parameters*** /** * Get ROI - * @return index of adc enabled, else -1 if all enabled + * @return roi */ - std::vector getROI() const; + ROI getROI() const; /** * Get ADC Enable Mask @@ -391,10 +391,10 @@ class slsReceiverImplementation : private virtual slsDetectorDefs { void setMultiDetectorSize(const int *size); /* - * Get flipped data across 'axis' - * @return if data is flipped across 'axis' + * Get flipped data across x axis + * @return if data is flipped across x axis */ - void setFlippedData(int axis = 0, int enable = -1); + void setFlippedDataX(int enable = -1); /** * Set Gap Pixels Enable (eiger specific) @@ -530,10 +530,10 @@ class slsReceiverImplementation : private virtual slsDetectorDefs { //***acquisition parameters*** /** * Set ROI - * @param i ROI + * @param arg ROI * @return OK or FAIL */ - int setROI(const std::vector new_roi); + int setROI(ROI arg); /** * Set ADC Enable Mask @@ -962,7 +962,7 @@ class slsReceiverImplementation : private virtual slsDetectorDefs { //***acquisition parameters*** /* ROI */ - std::vector roi; + ROI roi; /** ADC Enable Mask */ uint32_t adcEnableMask; /** streaming frequency */ diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index 24923a9e9..78caee98f 100755 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -114,9 +114,7 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_ } -int BinaryFile::CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap) { +int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) { //beginning of every acquisition numFramesInFile = 0; numActualPacketsInFile = 0; @@ -127,10 +125,9 @@ int BinaryFile::CreateMasterFile(bool mfwenable, bool en, uint32_t size, if(!(*silentMode)) { FILE_LOG(logINFO) << "Master File: " << masterFileName; } + attr.version = BINARY_WRITER_VERSION; return BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName, - *overWriteEnable, - *dynamicRange, en, size, nx, ny, *numImages, *maxFramesPerFile, - at, st, sp, ap, BINARY_WRITER_VERSION); + *overWriteEnable, attr); } return OK; } diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 766a3d72e..d9cd81f13 100755 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -248,15 +248,12 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf, } // only the first file -int DataProcessor::CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t st, - uint64_t sp, uint64_t ap) { +int DataProcessor::CreateNewFile(masterAttributes& attr) { if (file == nullptr) return FAIL; file->CloseAllFiles(); file->resetSubFileIndex(); - if (file->CreateMasterFile(*masterFileWriteEnable, en, generalData->imageSize, - generalData->nPixelsX, generalData->nPixelsY, - at, st, sp, ap) == FAIL) + if (file->CreateMasterFile(*masterFileWriteEnable, attr) == FAIL) return FAIL; if (file->CreateFile() == FAIL) return FAIL; diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index c11d383df..2f16b7078 100755 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -16,8 +16,8 @@ const std::string DataStreamer::TypeName = "DataStreamer"; -DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector* r, - uint64_t* fi, int fd, char* ajh, int* nd, bool* gpEnable) : +DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, ROI* r, + uint64_t* fi, int fd, char* ajh, int* nd, bool* gpEnable, bool* qe) : ThreadObject(ind), runningFlag(0), generalData(nullptr), @@ -34,7 +34,8 @@ DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector* r, firstAcquisitionIndex(0), firstMeasurementIndex(0), completeBuffer(nullptr), - gapPixelsEnable(gpEnable) + gapPixelsEnable(gpEnable), + quadEnable(qe) { numDet[0] = nd[0]; numDet[1] = nd[1]; @@ -93,9 +94,9 @@ void DataStreamer::ResetParametersforNewMeasurement(const std::string& fname){ delete[] completeBuffer; completeBuffer = nullptr; } - if (roi->size()) { + if (roi->xmin != -1) { if (generalData->myDetectorType == GOTTHARD) { - adcConfigured = generalData->GetAdcConfigured(index, roi); + adcConfigured = generalData->GetAdcConfigured(index, *roi); } completeBuffer = new char[generalData->imageSizeComplete]; memset(completeBuffer, 0, generalData->imageSizeComplete); @@ -263,7 +264,7 @@ int DataStreamer::SendHeader(sls_receiver_header* rheader, uint32_t size, uint32 header.modId, header.row, header.column, header.reserved, header.debug, header.roundRNumber, header.detType, header.version, - *gapPixelsEnable ? 1 : 0, flippedDataX, + *gapPixelsEnable ? 1 : 0, flippedDataX, *quadEnable, additionJsonHeader ); } diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index c462a8520..ec1b07982 100755 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -240,9 +240,7 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t } -int HDF5File::CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap) { +int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) { //beginning of every acquisition numFramesInFile = 0; @@ -257,11 +255,9 @@ int HDF5File::CreateMasterFile(bool mfwenable, bool en, uint32_t size, FILE_LOG(logINFO) << "Master File: " << masterFileName; } pthread_mutex_lock(&Mutex); + attr.version = HDF5_WRITER_VERSION; int ret = HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName, - *overWriteEnable, - *dynamicRange, en, size, nx, ny, *numImages, *maxFramesPerFile, - at, st, sp, ap, - HDF5_WRITER_VERSION); + *overWriteEnable, attr); pthread_mutex_unlock(&Mutex); return ret; } diff --git a/slsReceiverSoftware/src/multiReceiver.cpp b/slsReceiverSoftware/src/multiReceiver.cpp new file mode 100755 index 000000000..7762079e5 --- /dev/null +++ b/slsReceiverSoftware/src/multiReceiver.cpp @@ -0,0 +1,306 @@ +/** + \file mainReceiver.cpp + +This file is an example of how to implement the slsReceiverUsers class +You can compile it linking it to the slsReceiver library + +g++ mainReceiver.cpp -L lib -lSlsReceiver -L/usr/lib64/ -L lib2 -lzmq -pthread -lrt -lm -lstdc++ + +where, + +lib is the location of lSlsReceiver.so + +lib2 is the location of the libzmq.a. +[ libzmq.a is required only when using data call backs and enabling data streaming from receiver to client. +It is linked in manual/manual-api from slsReceiverSoftware/include ] + + */ + +#include "sls_detector_defs.h" +#include "slsReceiverUsers.h" + +#include //SIGINT +#include //system +#include +#include +//#include "utilities.h" +//#include "logger.h" +#include +#include +#include //wait +#include //wait +#include //tid +#include //usleep +using namespace std; + + +/** Define Colors to print data call back in different colors for different recievers */ +#define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__) + + +/** Variable is true to continue running, set to false upon interrupt */ +bool keeprunning; + +/** + * Control+C Interrupt Handler + * Sets the variable keeprunning to false, to let all the processes know to exit properly + */ +void sigInterruptHandler(int p){ + keeprunning = false; +} + +/** + * prints usage of this example program + */ +void printHelp() { + cprintf(RESET, "Usage:\n" + "./slsMultiReceiver(detReceiver) [start_tcp_port] [num_receivers] [1 for call back, 0 for none]\n\n"); + exit(EXIT_FAILURE); +} + +/** + * Start Acquisition Call back + * slsReceiver writes data if file write enabled. + * Users get data to write using call back if registerCallBackRawDataReady is registered. + * @param filepath file path + * @param filename file name + * @param fileindex file index + * @param datasize data size in bytes + * @param p pointer to object + * \returns ignored + */ +int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){ + cprintf(BLUE, "#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n", + filepath, filename, (long long unsigned int)fileindex, datasize); + + cprintf(BLUE, "--StartAcq: returning 0\n"); + return 0; +} + +/** + * Acquisition Finished Call back + * @param frames Number of frames caught + * @param p pointer to object + */ +void AcquisitionFinished(uint64_t frames, void*p){ + cprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",(long long unsigned int)frames); +} + + +/** + * Get Receiver Data Call back + * Prints in different colors(for each receiver process) the different headers for each image call back. + * @param metadata sls_receiver_header metadata + * @param datapointer pointer to data + * @param datasize data size in bytes. + * @param p pointer to object + */ +void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){ + slsDetectorDefs::sls_receiver_header* header = (slsDetectorDefs::sls_receiver_header*)metadata; + slsDetectorDefs::sls_detector_header detectorHeader = header->detHeader; + + PRINT_IN_COLOR (detectorHeader.modId?detectorHeader.modId:detectorHeader.row, + "#### %d GetData: ####\n" + "frameNumber: %lu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %lu" + "\t\ttimestamp: %lu\t\tmodId: %u\t\t" + "row: %u\t\tcolumn: %u\t\treserved: %u\t\tdebug: %u" + "\t\troundRNumber: %u\t\tdetType: %u\t\tversion: %u" + //"\t\tpacketsMask:%s" + "\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n", + detectorHeader.row, (long unsigned int)detectorHeader.frameNumber, + detectorHeader.expLength, detectorHeader.packetNumber, (long unsigned int)detectorHeader.bunchId, + (long unsigned int)detectorHeader.timestamp, detectorHeader.modId, + detectorHeader.row, detectorHeader.column, detectorHeader.reserved, + detectorHeader.debug, detectorHeader.roundRNumber, + detectorHeader.detType, detectorHeader.version, + //header->packetsMask.to_string().c_str(), + ((uint8_t)(*((uint8_t*)(datapointer)))), datasize); +} + + + +/** + * Get Receiver Data Call back (modified) + * Prints in different colors(for each receiver process) the different headers for each image call back. + * @param metadata sls_receiver_header metadata + * @param datapointer pointer to data + * @param datasize data size in bytes. + * @param revDatasize new data size in bytes after the callback. + * This will be the size written/streamed. (only smaller value is allowed). + * @param p pointer to object + */ +void GetData(char* metadata, char* datapointer, uint32_t &revDatasize, void* p){ + slsDetectorDefs::sls_receiver_header* header = (slsDetectorDefs::sls_receiver_header*)metadata; + slsDetectorDefs::sls_detector_header detectorHeader = header->detHeader; + + PRINT_IN_COLOR (detectorHeader.modId?detectorHeader.modId:detectorHeader.row, + "#### %d GetData: ####\n" + "frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu" + "\t\ttimestamp: %llu\t\tmodId: %u\t\t" + "row: %u\t\tcolumn: %u\t\treserved: %u\t\tdebug: %u" + "\t\troundRNumber: %u\t\tdetType: %u\t\tversion: %u" + //"\t\tpacketsMask:%s" + "\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n", + detectorHeader.row, (long long unsigned int)detectorHeader.frameNumber, + detectorHeader.expLength, detectorHeader.packetNumber, (long long unsigned int)detectorHeader.bunchId, + (long long unsigned int)detectorHeader.timestamp, detectorHeader.modId, + detectorHeader.row, detectorHeader.column, detectorHeader.reserved, + detectorHeader.debug, detectorHeader.roundRNumber, + detectorHeader.detType, detectorHeader.version, + //header->packetsMask.to_string().c_str(), + ((uint8_t)(*((uint8_t*)(datapointer)))), revDatasize); + + // if data is modified, eg ROI and size is reduced + revDatasize = 26000; +} + + + + +/** + * Example of main program using the slsReceiverUsers class + * + * - Defines in file for: + * - Default Number of receivers is 1 + * - Default Start TCP port is 1954 + */ +int main(int argc, char *argv[]) { + + /** - set default values */ + int numReceivers = 1; + int startTCPPort = 1954; + int withCallback = 0; + keeprunning = true; + + /** - get number of receivers and start tcp port from command line arguments */ + if ( (argc != 4) || (!sscanf(argv[1],"%d", &startTCPPort)) || (!sscanf(argv[2],"%d", &numReceivers)) || (!sscanf(argv[3],"%d", &withCallback)) ) + printHelp(); + cprintf(BLUE,"Parent Process Created [ Tid: %ld ]\n", (long)syscall(SYS_gettid)); + cprintf(RESET, "Number of Receivers: %d\n", numReceivers); + cprintf(RESET, "Start TCP Port: %d\n", startTCPPort); + cprintf(RESET, "Callback Enable: %d\n", withCallback); + + + + /** - Catch signal SIGINT to close files and call destructors properly */ + struct sigaction sa; + sa.sa_flags=0; // no flags + sa.sa_handler=sigInterruptHandler; // handler function + sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler + if (sigaction(SIGINT, &sa, nullptr) == -1) { + cprintf(RED, "Could not set handler function for SIGINT\n"); + } + + /** - Ignore SIG_PIPE, prevents global signal handler, handle locally, + instead of a server crashing due to client crash when writing, it just gives error */ + struct sigaction asa; + asa.sa_flags=0; // no flags + asa.sa_handler=SIG_IGN; // handler function + sigemptyset(&asa.sa_mask); // dont block additional signals during invocation of handler + if (sigaction(SIGPIPE, &asa, nullptr) == -1) { + cprintf(RED, "Could not set handler function for SIGPIPE\n"); + } + + + /** - loop over number of receivers */ + for (int i = 0; i < numReceivers; ++i) { + + /** - fork process to create child process */ + pid_t pid = fork(); + + /** - if fork failed, raise SIGINT and properly destroy all child processes */ + if (pid < 0) { + cprintf(RED,"fork() failed. Killing all the receiver objects\n"); + raise(SIGINT); + } + + /** - if child process */ + else if (pid == 0) { + cprintf(BLUE,"Child process %d [ Tid: %ld ]\n", i, (long)syscall(SYS_gettid)); + + char temp[10]; + sprintf(temp,"%d",startTCPPort + i); + char* args[] = {(char*)"ignored", (char*)"--rx_tcpport", temp}; + int ret = slsDetectorDefs::OK; + /** - create slsReceiverUsers object with appropriate arguments */ + slsReceiverUsers *receiver = new slsReceiverUsers(3, args, ret); + if(ret==slsDetectorDefs::FAIL){ + delete receiver; + exit(EXIT_FAILURE); + } + + + /** - register callbacks. remember to set file write enable to 0 (using the client) + if we should not write files and you will write data using the callbacks */ + if (withCallback) { + + /** - Call back for start acquisition */ + cprintf(BLUE, "Registering StartAcq()\n"); + receiver->registerCallBackStartAcquisition(StartAcq, nullptr); + + /** - Call back for acquisition finished */ + cprintf(BLUE, "Registering AcquisitionFinished()\n"); + receiver->registerCallBackAcquisitionFinished(AcquisitionFinished, nullptr); + + /* - Call back for raw data */ + cprintf(BLUE, "Registering GetData() \n"); + if (withCallback == 1) receiver->registerCallBackRawDataReady(GetData,nullptr); + else if (withCallback == 2) receiver->registerCallBackRawDataModifyReady(GetData,nullptr); + } + + + + /** - start tcp server thread */ + if (receiver->start() == slsDetectorDefs::FAIL){ + delete receiver; + cprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long)syscall(SYS_gettid)); + exit(EXIT_FAILURE); + } + + /** - as long as keeprunning is true (changes with Ctrl+C) */ + while(keeprunning) + pause(); + /** - interrupt caught, delete slsReceiverUsers object and exit */ + delete receiver; + cprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long)syscall(SYS_gettid)); + exit(EXIT_SUCCESS); + break; + } + } + + /** - Parent process ignores SIGINT (exits only when all child process exits) */ + sa.sa_flags=0; // no flags + sa.sa_handler=SIG_IGN; // handler function + sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler + if (sigaction(SIGINT, &sa, nullptr) == -1) { + cprintf(RED, "Could not set handler function for SIGINT\n"); + } + + + /** - Print Ready and Instructions how to exit */ + cout << "Ready ... " << endl; + cprintf(RESET, "\n[ Press \'Ctrl+c\' to exit ]\n"); + + /** - Parent process waits for all child processes to exit */ + for(;;) { + pid_t childPid = waitpid (-1, nullptr, 0); + + // no child closed + if (childPid == -1) { + if (errno == ECHILD) { + cprintf(GREEN,"All Child Processes have been closed\n"); + break; + } else { + cprintf(RED, "Unexpected error from waitpid(): (%s)\n",strerror(errno)); + break; + } + } + + //child closed + cprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long int) childPid); + } + + cout << "Goodbye!" << endl; + return 0; +} + diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index 1634f8c83..4bf587362 100755 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -104,9 +104,10 @@ void slsReceiverImplementation::InitializeMembers() { overwriteEnable = true; //***acquisition parameters*** - roi.clear(); + roi.xmin = -1; + roi.xmax = -1; adcEnableMask = BIT32_MASK; - streamingFrequency = 0; + streamingFrequency = 1; streamingTimerInMs = DEFAULT_STREAMING_TIMER_IN_MS; dataStreamEnable = false; streamingPort = 0; @@ -147,16 +148,9 @@ std::string slsReceiverImplementation::getDetectorHostname() const { return std::string(detHostname); } -int slsReceiverImplementation::getFlippedData(int axis) const { +int slsReceiverImplementation::getFlippedDataX() const { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - switch(axis) { - case 0: - return flippedDataX; - case 1: - return 0; - default: - return -1; - } + return flippedDataX; } bool slsReceiverImplementation::getGapPixelsEnable() const { @@ -305,7 +299,7 @@ int slsReceiverImplementation::getNumberofUDPInterfaces() const { } /***acquisition parameters***/ -std::vector slsReceiverImplementation::getROI() const { +slsDetectorDefs::ROI slsReceiverImplementation::getROI() const { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; return roi; } @@ -481,10 +475,8 @@ void slsReceiverImplementation::setMultiDetectorSize(const int *size) { FILE_LOG(logINFO) << log_message; } -void slsReceiverImplementation::setFlippedData(int axis, int enable) { +void slsReceiverImplementation::setFlippedDataX(int enable) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if (axis != 0) - return; flippedDataX = (enable == 0) ? 0 : 1; if (!quadEnable) { @@ -792,7 +784,7 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) { } dataStreamer.push_back(sls::make_unique( i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, - fd, additionalJsonHeader, (int*)nd, &gapPixelsEnable)); + fd, additionalJsonHeader, (int*)nd, &gapPixelsEnable, &quadEnable)); dataStreamer[i]->SetGeneralData(generalData); dataStreamer[i]->CreateZmqSockets( &numThreads, streamingPort, streamingSrcIP); @@ -858,51 +850,21 @@ int slsReceiverImplementation::setUDPSocketBufferSize(const int64_t s) { } /***acquisition parameters***/ -int slsReceiverImplementation::setROI( - const std::vector new_roi) { - bool change = false; - if (roi.size() != new_roi.size()) - change = true; - else { - for (size_t i = 0; i != new_roi.size(); ++i) { - if ((roi[i].xmin != new_roi[i].xmin) || - (roi[i].xmax != new_roi[i].xmax) || - (roi[i].ymin != new_roi[i].ymin) || - (roi[i].xmax != new_roi[i].xmax)) { - change = true; - break; - } - } - } +int slsReceiverImplementation::setROI(slsDetectorDefs::ROI arg) { + if (roi.xmin != arg.xmin || roi.xmax != arg.xmax) { + roi.xmin = arg.xmin; + roi.xmax = arg.xmax; - if (change) { - roi = new_roi; - switch (myDetectorType) { - case GOTTHARD: - generalData->SetROI(new_roi); - framesPerFile = generalData->maxFramesPerFile; - break; - default: - break; - } + // only for gotthard + generalData->SetROI(arg); + framesPerFile = generalData->maxFramesPerFile; for (const auto &it : dataProcessor) it->SetPixelDimension(); if (SetupFifoStructure() == FAIL) return FAIL; } - std::stringstream sstm; - sstm << "ROI: "; - if (!roi.size()) - sstm << "0"; - else { - for (size_t i = 0; i < roi.size(); ++i) { - sstm << "( " << roi[i].xmin << ", " << roi[i].xmax << ", " - << roi[i].ymin << ", " << roi[i].ymax << " )"; - } - } - std::string message = sstm.str(); - FILE_LOG(logINFO) << message; + FILE_LOG(logINFO) << "ROI: [" << roi.xmin << ", " << roi.xmax << "]";; FILE_LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); return OK; @@ -974,7 +936,7 @@ int slsReceiverImplementation::setDataStreamEnable(const bool enable) { } dataStreamer.push_back(sls::make_unique( i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, - fd, additionalJsonHeader, (int*)nd, &gapPixelsEnable)); + fd, additionalJsonHeader, (int*)nd, &gapPixelsEnable, &quadEnable)); dataStreamer[i]->SetGeneralData(generalData); dataStreamer[i]->CreateZmqSockets( &numThreads, streamingPort, streamingSrcIP); @@ -1399,7 +1361,7 @@ void slsReceiverImplementation::stopReceiver() { dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught); } - // wait for the processes (DataStreamer) to be done + // wait for the processes (dataStreamer) to be done running = true; while (running) { running = false; @@ -1676,10 +1638,34 @@ int slsReceiverImplementation::CreateUDPSockets() { int slsReceiverImplementation::SetupWriter() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; bool error = false; + masterAttributes attr; + attr.detectorType = myDetectorType; + attr.dynamicRange = dynamicRange; + attr.tenGiga = tengigaEnable; + attr.imageSize = generalData->imageSize; + attr.nPixelsX = generalData->nPixelsX; + attr.nPixelsY = generalData->nPixelsY; + attr.maxFramesPerFile = framesPerFile; + attr.totalFrames = numberOfFrames; + attr.exptimeNs = acquisitionTime; + attr.subExptimeNs = subExpTime; + attr.subPeriodNs = subPeriod; + attr.periodNs = acquisitionPeriod; + attr.gapPixelsEnable = gapPixelsEnable; + attr.quadEnable = quadEnable; + attr.parallelFlag = (readoutFlags & PARALLEL) ? 1 : 0; + attr.analogFlag = (readoutFlags == NORMAL_READOUT || readoutFlags & ANALOG_AND_DIGITAL) ? 1 : 0; + attr.digitalFlag = (readoutFlags & DIGITAL_ONLY || readoutFlags & ANALOG_AND_DIGITAL) ? 1 : 0; + attr.adcmask = adcEnableMask; + attr.dbitoffset = ctbDbitOffset; + attr.dbitlist = 0; + attr.roiXmin = roi.xmin; + attr.roiXmax = roi.xmax; + for (auto &i : ctbDbitList) { + attr.dbitlist |= (1 << i); + } for (unsigned int i = 0; i < dataProcessor.size(); ++i) - if (dataProcessor[i]->CreateNewFile( - tengigaEnable, numberOfFrames, acquisitionTime, subExpTime, - subPeriod, acquisitionPeriod) == FAIL) { + if (dataProcessor[i]->CreateNewFile(attr) == FAIL) { error = true; break; } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ba99be5ae..aa86b5b42 100755 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -510,22 +510,12 @@ int slsReceiverTCPIPInterface::set_detector_hostname(Interface &socket) { } int slsReceiverTCPIPInterface::set_roi(Interface &socket) { - static_assert(sizeof(ROI) == 4 * sizeof(int), "ROI not packed"); - auto narg = socket.Receive(); - std::vector arg; - for (int iloop = 0; iloop < narg; ++iloop) { - ROI temp{}; - socket.Receive(temp); - arg.push_back(temp); - } - FILE_LOG(logDEBUG1) << "Set ROI narg: " << narg; - for (int iloop = 0; iloop < narg; ++iloop) { - FILE_LOG(logDEBUG1) - << "(" << arg[iloop].xmin << ", " << arg[iloop].xmax << ", " - << arg[iloop].ymin << ", " << arg[iloop].ymax << ")"; - } + static_assert(sizeof(ROI) == 2 * sizeof(int), "ROI not packed"); + ROI arg; + socket.Receive(arg); + FILE_LOG(logDEBUG1) << "Set ROI: [" << arg.xmin << ", " << arg.xmax << "]"; - if (myDetectorType == EIGER || myDetectorType == JUNGFRAU) + if (myDetectorType != GOTTHARD) functionNotImplemented(); VerifyIdle(socket); @@ -986,19 +976,18 @@ int slsReceiverTCPIPInterface::set_streaming_timer(Interface &socket) { int slsReceiverTCPIPInterface::set_flipped_data(Interface &socket) { // TODO! Why 2 args? memset(mess, 0, sizeof(mess)); - int args[2]{0, -1}; - socket.Receive(args); + auto arg = socket.Receive(); if (myDetectorType != EIGER) functionNotImplemented(); - if (args[1] >= 0) { + if (arg >= 0) { VerifyIdle(socket); - FILE_LOG(logDEBUG1) << "Setting flipped data:" << args[1]; - impl()->setFlippedData(args[0], args[1]); + FILE_LOG(logDEBUG1) << "Setting flipped data:" << arg; + impl()->setFlippedDataX(arg); } - int retval = impl()->getFlippedData(args[0]); - validate(args[1], retval, std::string("set flipped data"), DEC); + int retval = impl()->getFlippedDataX(); + validate(arg, retval, std::string("set flipped data"), DEC); FILE_LOG(logDEBUG1) << "Flipped Data:" << retval; return socket.sendResult(retval); } diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt index 21ebdfa71..20380e13c 100755 --- a/slsSupportLib/CMakeLists.txt +++ b/slsSupportLib/CMakeLists.txt @@ -7,7 +7,6 @@ set(SOURCES src/ServerSocket.cpp src/ServerInterface2.cpp src/network_utils.cpp - src/ToString.cpp ) set(HEADERS diff --git a/slsSupportLib/include/FixedCapacityContainer.h b/slsSupportLib/include/FixedCapacityContainer.h index d53136baa..f6b57caa9 100644 --- a/slsSupportLib/include/FixedCapacityContainer.h +++ b/slsSupportLib/include/FixedCapacityContainer.h @@ -1,194 +1,146 @@ #pragma once +#include "TypeTraits.h" #include #include +#include #include #include namespace sls { template class FixedCapacityContainer { + + public: + using size_type = typename std::array::size_type; + using value_type = typename std::array::value_type; + using iterator = typename std::array::iterator; + using const_iterator = typename std::array::const_iterator; + + private: + size_type current_size{}; + std::array data_; + public: FixedCapacityContainer() = default; - explicit FixedCapacityContainer(std::initializer_list l); - explicit FixedCapacityContainer(const std::vector &v); - template - explicit FixedCapacityContainer( - const FixedCapacityContainer &other) noexcept; + explicit FixedCapacityContainer(std::initializer_list l) + : current_size(l.size()) { + size_check(l.size()); + std::copy(l.begin(), l.end(), data_.begin()); + } - FixedCapacityContainer &operator=(const std::vector &other); + /** Copy construct from another container */ + template ::value && + std::is_same::value>::type> + FixedCapacityContainer(const V &v) : current_size(v.size()) { + size_check(v.size()); + std::copy(v.begin(), v.end(), data_.begin()); + } - bool operator==(const std::vector &other) const noexcept; - bool operator!=(const std::vector &other) const noexcept; + /** copy assignment from another container */ + template + typename std::enable_if::value, + FixedCapacityContainer &>::type + operator=(const V &other) { + size_check(other.size()); + std::copy(other.begin(), other.end(), data_.begin()); + current_size = other.size(); + return *this; + } - operator std::vector(){return std::vector(begin(), end());} + /** Compare FixedCapacityContainer with any other container*/ + template + typename std::enable_if::value, bool>::type + operator==(const V &other) const noexcept { + if (current_size != other.size()) { + return false; + } else { + for (size_t i = 0; i != current_size; ++i) { + if (data_[i] != other[i]) { + return false; + } + } + } + return true; + } - template - bool operator==(const FixedCapacityContainer &other) const - noexcept; + template + typename std::enable_if::value, bool>::type + operator!=(const V &other) const noexcept { + return !(*this == other); + } - template - bool operator!=(const FixedCapacityContainer &other) const - noexcept; + operator std::vector() { return std::vector(begin(), end()); } T &operator[](size_t i) { return data_[i]; } const T &operator[](size_t i) const { return data_[i]; } - - constexpr size_t size() const noexcept { return size_; } - bool empty() const noexcept { return size_ == 0; } + constexpr size_type size() const noexcept { return current_size; } + bool empty() const noexcept { return current_size == 0; } constexpr size_t capacity() const noexcept { return Capacity; } - void push_back(const T &value); - void resize(size_t new_size); - void erase(T *ptr); + void push_back(const T &value) { + if (current_size == Capacity) { + throw std::runtime_error("Container is full"); + } else { + data_[current_size] = value; + ++current_size; + } + } + + void resize(size_t new_size) { + if (new_size > Capacity) { + throw std::runtime_error("Cannot resize beyond capacity"); + } else { + current_size = new_size; + } + } + + void erase(T *ptr) { + if (ptr >= begin() && ptr < end()) { + current_size = static_cast(ptr - begin()); + } else { + throw std::runtime_error("tried to erase with a ptr outside obj"); + } + } T &front() noexcept { return data_.front(); } - T &back() noexcept { return data_[size_ - 1]; } + T &back() noexcept { return data_[current_size - 1]; } constexpr const T &front() const noexcept { return data_.front(); } - constexpr const T &back() const noexcept { return data_[size_ - 1]; } + constexpr const T &back() const noexcept { return data_[current_size - 1]; } // iterators - T *begin() noexcept { return &data_[0]; } - T *end() noexcept { return &data_[size_]; } - const T *cbegin() const noexcept { return &data_[0]; } - const T *cend() const noexcept { return &data_[size_]; } + iterator begin() noexcept { return data_.begin(); } + // auto begin() noexcept -> decltype(data_.begin()) { return data_.begin(); + // } + const_iterator begin() const noexcept { return data_.begin(); } + iterator end() noexcept { return &data_[current_size]; } + const_iterator end() const noexcept { return &data_[current_size]; } + const_iterator cbegin() const noexcept { return data_.cbegin(); } + const_iterator cend() const noexcept { return &data_[current_size]; } + + void size_check(size_type s) const { + if (s > Capacity) { + throw std::runtime_error( + "Capacity needs to be same size or larger than vector"); + } + } - private: - size_t size_{0}; - std::array data_; } __attribute__((packed)); -/* Member functions */ -template -FixedCapacityContainer::FixedCapacityContainer( - std::initializer_list l) { - size_ = l.size(); - std::copy(l.begin(), l.end(), data_.begin()); -} - -template -FixedCapacityContainer::FixedCapacityContainer( - const std::vector &v) { - if (v.size() > Capacity) { - throw std::runtime_error( - "Capacity needs to be same size or larger than vector"); - } - size_ = v.size(); - std::copy(v.begin(), v.end(), data_.begin()); -} - -template -template -FixedCapacityContainer::FixedCapacityContainer( - const FixedCapacityContainer &other) noexcept { - static_assert(Capacity >= OtherCapacity, - "Container needs to be same size or larger"); - size_ = other.size(); - std::copy(other.cbegin(), other.cend(), data_.begin()); -} - -template -void FixedCapacityContainer::push_back(const T &value) { - if (size_ == Capacity) { - throw std::runtime_error("Container is full"); - } else { - data_[size_] = value; - ++size_; - } -} -template -void FixedCapacityContainer::resize(size_t new_size) { - if (new_size > Capacity) { - throw std::runtime_error("Cannot resize beyond capacity"); - } else { - size_ = new_size; - } -} - -template -FixedCapacityContainer &FixedCapacityContainer:: -operator=(const std::vector &other) { - std::copy(other.begin(), other.end(), data_.begin()); - size_ = other.size(); - return *this; -} - -template -bool FixedCapacityContainer:: -operator==(const std::vector &other) const noexcept { - if (size_ != other.size()) { - return false; - } else { - for (size_t i = 0; i != size_; ++i) { - if (data_[i] != other[i]) { - return false; - } - } - } - return true; -} - -template -bool FixedCapacityContainer:: -operator!=(const std::vector &other) const noexcept { - return !(*this == other); -} - -template -template -bool FixedCapacityContainer:: -operator==(const FixedCapacityContainer &other) const - noexcept { - if (size_ != other.size()) { - return false; - } else { - for (size_t i = 0; i != size_; ++i) { - if (data_[i] != other[i]) { - return false; - } - } - } - return true; -} - -template -template -bool FixedCapacityContainer:: -operator!=(const FixedCapacityContainer &other) const - noexcept { - return !(*this == other); -} - -template -void FixedCapacityContainer::erase(T *ptr) { - if (ptr >= begin() && ptr < end()) { - size_ = static_cast(ptr - begin()); - } else { - throw std::runtime_error("tried to erase with a ptr outside obj"); - } -} - -/* Free function concerning FixedCapacityContainer */ -template -constexpr T *begin(FixedCapacityContainer &container) noexcept { - return container.begin(); -} - -template -constexpr T *end(FixedCapacityContainer &container) noexcept { - return container.end(); -} - -template -bool operator==( - const std::vector &vec, +/** support flipped order compare */ +template +typename std::enable_if::value, bool>::type operator==( + const C &container, const FixedCapacityContainer &fixed_container) noexcept { - return fixed_container == vec; + return fixed_container.operator==(container); } -template -bool operator!=( - const std::vector &vec, +/** support flipped order compare */ +template +typename std::enable_if::value, bool>::type operator!=( + const C &container, const FixedCapacityContainer &fixed_container) noexcept { - return fixed_container != vec; + return fixed_container.operator!=(container); } } // namespace sls diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 8acd31a29..750e6585a 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -2,9 +2,9 @@ /** * \file ToString.h - * + * * Conversion from various types to std::string - * + * */ #include "TimeHelper.h" @@ -19,8 +19,17 @@ namespace sls { -std::string ToString(const std::vector &vec, - const char delimiter = ' '); +inline std::string ToString(const std::vector &vec, + const char delimiter = ' ') { + std::ostringstream os; + if(!vec.empty()){ + auto it = vec.begin(); + os << *it++; + while(it != vec.end()) + os << delimiter << *it++; + } + return os.str(); +} /** Convert std::chrono::duration with specified output unit */ template @@ -137,4 +146,11 @@ template T StringTo(std::string t) { return StringTo(t, unit); } +/** For types with a .str() method use this for conversion */ +template +typename std::enable_if::value, std::string>::type +ToString(const T &obj) { + return obj.str(); +} + } // namespace sls diff --git a/slsSupportLib/include/TypeTraits.h b/slsSupportLib/include/TypeTraits.h index 2a5409e78..39b9525c2 100644 --- a/slsSupportLib/include/TypeTraits.h +++ b/slsSupportLib/include/TypeTraits.h @@ -4,7 +4,7 @@ namespace sls { /** - * Type trait to check if atemplate parameter is a std::chrono::duration + * Type trait to check if a template parameter is a std::chrono::duration */ template @@ -22,6 +22,32 @@ struct is_duration().zero())>, void>::type> : public std::true_type {}; +/** + * Has str method + */ +template struct has_str : std::false_type {}; + +template struct has_str_helper {}; + +template +struct has_str().str())>, + void>::type> : public std::true_type {}; + +/** + * Has emplace_back method + */ +template struct has_emplace_back : std::false_type {}; + +template struct has_emplace_back_helper {}; + +template +struct has_emplace_back().emplace_back())>, + void>::type> : public std::true_type {}; + /** * Type trait to evaluate if template parameter is * complying with a standard container @@ -45,4 +71,25 @@ struct is_container< decltype(std::declval().empty())>, void>::type> : public std::true_type {}; + +/** + * Type trait to evaluate if template parameter is + * complying with a standard container + */ +template +struct is_light_container : std::false_type {}; + +template struct is_light_container_helper {}; + +template +struct is_light_container< + T, typename std::conditional< + false, + is_container_helper().size()), + decltype(std::declval().begin()), + decltype(std::declval().end())>, + void>::type> : public std::true_type {}; + } // namespace sls \ No newline at end of file diff --git a/slsSupportLib/include/ZmqSocket.h b/slsSupportLib/include/ZmqSocket.h index 033205914..9506a1804 100755 --- a/slsSupportLib/include/ZmqSocket.h +++ b/slsSupportLib/include/ZmqSocket.h @@ -265,6 +265,7 @@ public: * @param version detector header version * @param gapPixelsEnable gap pixels enable (exception: if gap pixels enable for 4 bit mode, data is not yet gap pixel enabled in receiver) * @param flippedDataX if it is flipped across x axis + * @param quadEnable if quad is enabled * @param additionalJsonHeader additional json header * @returns 0 if error, else 1 */ @@ -276,6 +277,7 @@ public: uint16_t modId = 0, uint16_t row = 0, uint16_t column = 0, uint16_t reserved = 0, uint32_t debug = 0, uint16_t roundRNumber = 0, uint8_t detType = 0, uint8_t version = 0, int gapPixelsEnable = 0, int flippedDataX = 0, + uint32_t quadEnable = 0, char* additionalJsonHeader = 0) { @@ -310,7 +312,8 @@ public: //additional stuff "\"gappixels\":%u, " - "\"flippedDataX\":%u" + "\"flippedDataX\":%u, " + "\"quad\":%u" ;//"}\n"; char buf[MAX_STR_LENGTH] = ""; @@ -324,7 +327,8 @@ public: //additional stuff gapPixelsEnable, - flippedDataX + flippedDataX, + quadEnable ); if (additionalJsonHeader && strlen(additionalJsonHeader)) { diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 63f474901..a3f854b32 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -68,6 +68,8 @@ // typedef char mystring[MAX_STR_LENGTH]; + + #ifdef __cplusplus class slsDetectorDefs { public: @@ -106,7 +108,6 @@ class slsDetectorDefs { FRAME_PERIOD, /**< period between exposures */ DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */ - GATES_NUMBER, /**< number of gates per frame (in gated mode) */ CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */ ACTUAL_TIME, /**< Actual time of the detector's internal timer */ @@ -219,12 +220,18 @@ format @short structure for a region of interest xmin,xmax,ymin,ymax define the limits of the region */ + + #ifdef __cplusplus + struct ROI { + int xmin{-1}; /**< is the roi xmin (in channel number) */ + int xmax{-1}; /**< is the roi xmax (in channel number)*/ + }; + #else typedef struct { int xmin; /**< is the roi xmin (in channel number) */ int xmax; /**< is the roi xmax (in channel number)*/ - int ymin; /**< is the roi ymin (in channel number)*/ - int ymax; /**< is the roi ymax (in channel number)*/ - } ROI; + } ROI; + #endif /** network parameters @@ -284,6 +291,12 @@ format Y = 1 /**< Y dimension */ }; +#ifdef __cplusplus + struct xy { + int x{0}; + int y{0}; + }; +#endif /** enable/disable flags */ @@ -324,9 +337,8 @@ format /** communication mode using external signals */ - enum externalCommunicationMode { - GET_EXTERNAL_COMMUNICATION_MODE = - -1, /** //hmm... but currently no way around +namespace sls{ +using Positions = const std::vector &; +using defs = slsDetectorDefs; +} +#endif diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index cbc2caedd..e9418da70 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -13,7 +13,7 @@ enum detFuncs{ F_EXEC_COMMAND=0, /**< command is executed */ F_GET_DETECTOR_TYPE, /**< return detector type */ F_SET_EXTERNAL_SIGNAL_FLAG, /**< set/get flag for external signal */ - F_SET_EXTERNAL_COMMUNICATION_MODE, /**< set/get external communication mode (obsolete) */ + F_SET_TIMING_MODE, /**< set/get external communication mode (obsolete) */ F_GET_ID, /**< get detector id of version */ F_DIGITAL_TEST, /**< digital test of the detector */ F_SET_DAC, /**< set DAC value */ @@ -35,16 +35,14 @@ enum detFuncs{ F_SET_DYNAMIC_RANGE, /**< set/get detector dynamic range */ F_SET_READOUT_FLAGS, /**< set/get readout flags */ F_SET_ROI, /**< set/get region of interest */ + F_GET_ROI, F_SET_SPEED, /**< set/get readout speed parameters */ F_EXIT_SERVER, /**< turn off detector server */ F_LOCK_SERVER, /**< Locks/Unlocks server communication to the given client */ F_GET_LAST_CLIENT_IP, /**< returns the IP of the client last connected to the detector */ F_SET_PORT, /**< Changes communication port of the server */ F_UPDATE_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */ - F_CONFIGURE_MAC, /**< Configures MAC for Gotthard readout */ - F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */ - F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */ - F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */ + F_CONFIGURE_MAC, /**< Configures MAC */ F_ENABLE_TEN_GIGA, /**< enable 10Gbe */ F_SET_ALL_TRIMBITS, /** < set all trimbits to this value */ F_SET_PATTERN_IO_CONTROL, /** < set pattern i/o control */ @@ -163,7 +161,7 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_EXEC_COMMAND: return "F_EXEC_COMMAND"; case F_GET_DETECTOR_TYPE: return "F_GET_DETECTOR_TYPE"; case F_SET_EXTERNAL_SIGNAL_FLAG: return "F_SET_EXTERNAL_SIGNAL_FLAG"; - case F_SET_EXTERNAL_COMMUNICATION_MODE: return "F_SET_EXTERNAL_COMMUNICATION_MODE"; + case F_SET_TIMING_MODE: return "F_SET_TIMING_MODE"; case F_GET_ID: return "F_GET_ID"; case F_DIGITAL_TEST: return "F_DIGITAL_TEST"; case F_SET_DAC: return "F_SET_DAC"; @@ -185,6 +183,7 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_DYNAMIC_RANGE: return "F_SET_DYNAMIC_RANGE"; case F_SET_READOUT_FLAGS: return "F_SET_READOUT_FLAGS"; case F_SET_ROI: return "F_SET_ROI"; + case F_GET_ROI: return "F_GET_ROI"; case F_SET_SPEED: return "F_SET_SPEED"; case F_EXIT_SERVER: return "F_EXIT_SERVER"; case F_LOCK_SERVER: return "F_LOCK_SERVER"; @@ -192,9 +191,6 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_PORT: return "F_SET_PORT"; case F_UPDATE_CLIENT: return "F_UPDATE_CLIENT"; case F_CONFIGURE_MAC: return "F_CONFIGURE_MAC"; - case F_LOAD_IMAGE: return "F_LOAD_IMAGE"; - case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK"; - case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK"; case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA"; case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS"; case F_SET_PATTERN_IO_CONTROL: return "F_SET_PATTERN_IO_CONTROL"; diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 60b5d2a3f..aeb36a6d9 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -1,10 +1,10 @@ /** API versions */ #define GITBRANCH "developer" -#define APIMOENCH 0x181108 -#define APIGOTTHARD 0x190715 #define APILIB 0x190723 #define APIRECEIVER 0x190722 #define APIGUI 0x190723 -#define APIJUNGFRAU 0x190730 -#define APIEIGER 0x190806 +#define APIMOENCH 0x190820 +#define APIGOTTHARD 0x190820 +#define APIEIGER 0x190820 +#define APIJUNGFRAU 0x190820 #define APICTB 0x190821 diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp deleted file mode 100644 index 541ce2829..000000000 --- a/slsSupportLib/src/ToString.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "ToString.h" - -namespace sls { - -std::string ToString(const std::vector &vec, - const char delimiter) { - std::ostringstream os; - if (vec.empty()) - return os.str(); - auto it = vec.cbegin(); - os << *it++; - if (vec.size() > 1) { - while (it != vec.cend()) - os << delimiter << *it++; - } - return os.str(); -} -} // namespace sls \ No newline at end of file diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt index 4490ec18b..2d131a537 100755 --- a/slsSupportLib/tests/CMakeLists.txt +++ b/slsSupportLib/tests/CMakeLists.txt @@ -8,4 +8,5 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-Sockets.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-FixedCapacityContainer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-ToString.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-TypeTraits.cpp ) \ No newline at end of file diff --git a/slsSupportLib/tests/test-FixedCapacityContainer.cpp b/slsSupportLib/tests/test-FixedCapacityContainer.cpp index d4853cab7..3fc6089dc 100644 --- a/slsSupportLib/tests/test-FixedCapacityContainer.cpp +++ b/slsSupportLib/tests/test-FixedCapacityContainer.cpp @@ -1,8 +1,81 @@ #include "FixedCapacityContainer.h" +#include "TypeTraits.h" #include "catch.hpp" +#include +#include using sls::FixedCapacityContainer; +TEST_CASE("FixedCapacityContainer is a container") { + REQUIRE(sls::is_container>::value == true); +} + +TEST_CASE("Compare array and fixed capacity container") { + std::array arr{1, 2, 3}; + std::array arr2{1, 7, 3}; + FixedCapacityContainer fcc{1, 2, 3}; + REQUIRE(fcc == arr); + REQUIRE(arr == fcc); + REQUIRE_FALSE(fcc != arr); + REQUIRE_FALSE(arr != fcc); + REQUIRE_FALSE(fcc == arr2); + REQUIRE_FALSE(arr2 == fcc); +} + +TEST_CASE("Compare vector and fixed capacity container") { + std::vector vec{1, 2, 3}; + std::vector vec2{10, 2, 3}; + FixedCapacityContainer fcc{1, 2, 3}; + REQUIRE(fcc == vec); + REQUIRE(vec == fcc); + REQUIRE_FALSE(fcc != vec); + REQUIRE_FALSE(vec != fcc); + REQUIRE_FALSE(fcc == vec2); + REQUIRE_FALSE(vec2 == fcc); +} + +TEST_CASE("Construct from vector") { + std::vector vec{1, 2, 3}; + FixedCapacityContainer fcc{vec}; + REQUIRE(fcc == vec); +} + +TEST_CASE("Copy construct from vector") { + std::vector vec{1, 2, 3}; + FixedCapacityContainer fcc = vec; + REQUIRE(fcc == vec); +} + +TEST_CASE("Copy assignment from vector") { + std::vector vec{1, 2, 3}; + FixedCapacityContainer fcc; + fcc = vec; + REQUIRE(fcc == vec); +} + +TEST_CASE("Construct from array") { + std::array arr{1, 2, 3}; + FixedCapacityContainer fcc{arr}; + REQUIRE(fcc == arr); +} + +TEST_CASE("Copy assign from array") { + std::array arr{1, 2, 3}; + FixedCapacityContainer fcc; + fcc = arr; + REQUIRE(fcc == arr); +} + +TEST_CASE("Copy construct from array") { + std::array arr{1, 2, 3}; + FixedCapacityContainer fcc = arr; + REQUIRE(fcc == arr); +} + +TEST_CASE("Free function and method gives the same iterators") { + FixedCapacityContainer fcc{1, 2, 3}; + REQUIRE(std::begin(fcc) == fcc.begin()); +} SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { GIVEN("A default constructed container") { @@ -10,7 +83,7 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { FixedCapacityContainer vec; REQUIRE(vec.empty()); - REQUIRE(vec.size() == 0); //NOLINT + REQUIRE(vec.size() == 0); // NOLINT REQUIRE(vec.capacity() == n_elem); REQUIRE(sizeof(vec) == sizeof(int) * n_elem + sizeof(size_t)); @@ -74,13 +147,12 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { WHEN("We try to resize beyond the capacity") { THEN("it throws") { CHECK_THROWS(vec.resize(25)); } } - WHEN("We call front and back"){ - THEN("They return referenced to the first and last element"){ + WHEN("We call front and back") { + THEN("They return referenced to the first and last element") { REQUIRE(vec.front() == 23); REQUIRE(&vec.front() == &vec[0]); REQUIRE(vec.back() == 11); REQUIRE(&vec.back() == &vec[2]); - } } } @@ -143,7 +215,8 @@ SCENARIO("Comparison of FixedCapacityContainers", "[support]") { } } -SCENARIO("Sorting, removing and other manipulation of a container", "[support]") { +SCENARIO("Sorting, removing and other manipulation of a container", + "[support]") { GIVEN("An unsorted container") { FixedCapacityContainer a{14, 12, 90, 12}; WHEN("We sort it") { @@ -155,23 +228,23 @@ SCENARIO("Sorting, removing and other manipulation of a container", "[support]") REQUIRE(a[3] == 90); } } - WHEN("Sorting is done using free function for begin and end") { - std::sort(begin(a), end(a)); - THEN("it also works") { - REQUIRE(a[0] == 12); - REQUIRE(a[1] == 12); - REQUIRE(a[2] == 14); - REQUIRE(a[3] == 90); - } - } - WHEN("Erasing elements of a certain value") { - a.erase(std::remove(begin(a), end(a), 12)); - THEN("all elements of that value are removed") { - REQUIRE(a.size() == 2); - REQUIRE(a[0] == 14); - REQUIRE(a[1] == 90); - } - } + // WHEN("Sorting is done using free function for begin and end") { + // std::sort(begin(a), end(a)); + // THEN("it also works") { + // REQUIRE(a[0] == 12); + // REQUIRE(a[1] == 12); + // REQUIRE(a[2] == 14); + // REQUIRE(a[3] == 90); + // } + // } + // WHEN("Erasing elements of a certain value") { + // a.erase(std::remove(begin(a), end(a), 12)); + // THEN("all elements of that value are removed") { + // REQUIRE(a.size() == 2); + // REQUIRE(a[0] == 14); + // REQUIRE(a[1] == 90); + // } + // } } } @@ -201,30 +274,28 @@ SCENARIO("Assigning containers to each other", "[support]") { REQUIRE(c[2] == 3); } } - WHEN("We create a const FixedCapacityContainer"){ + WHEN("We create a const FixedCapacityContainer") { const FixedCapacityContainer c(a); - THEN("The values are still the same using const operators"){ + THEN("The values are still the same using const operators") { REQUIRE(c[0] == 1); REQUIRE(c[1] == 2); REQUIRE(c[2] == 3); REQUIRE(c.front() == 1); REQUIRE(c.back() == 3); - } } } } -SCENARIO("Converting to vector", "[support]"){ - GIVEN("a FixedCapacityContainer"){ - FixedCapacityContainer a{1,2,3}; - WHEN("Converted into a vector"){ +SCENARIO("Converting to vector", "[support]") { + GIVEN("a FixedCapacityContainer") { + FixedCapacityContainer a{1, 2, 3}; + WHEN("Converted into a vector") { std::vector b(a); - THEN("Data and size matches"){ + THEN("Data and size matches") { REQUIRE(a == b); REQUIRE(a.size() == b.size()); } } } } - diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index f080003b0..b3119b4c5 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -1,20 +1,25 @@ #include "TimeHelper.h" #include "ToString.h" +#include "network_utils.h" #include "catch.hpp" +#include #include -using namespace sls; +// using namespace sls; +using sls::StringTo; +using sls::ToString; +using namespace sls::time; -TEST_CASE("Integer conversions", "[support][now]"){ +TEST_CASE("Integer conversions", "[support]") { REQUIRE(ToString(0) == "0"); REQUIRE(ToString(1) == "1"); REQUIRE(ToString(-1) == "-1"); REQUIRE(ToString(100) == "100"); REQUIRE(ToString(589633100) == "589633100"); - } -TEST_CASE("floating point conversions", "[support][now]"){ +TEST_CASE("floating point conversions", "[support]") { + // Should strip trailing zeros REQUIRE(ToString(0.) == "0"); REQUIRE(ToString(1.) == "1"); REQUIRE(ToString(-1.) == "-1"); @@ -25,36 +30,35 @@ TEST_CASE("floating point conversions", "[support][now]"){ REQUIRE(ToString(2.35010) == "2.3501"); REQUIRE(ToString(5000) == "5000"); REQUIRE(ToString(5E15) == "5000000000000000"); - } -TEST_CASE("conversion from duration to string", "[support][now]") { - REQUIRE(ToString(time::ns(150)) == "150ns"); - REQUIRE(ToString(time::ms(783)) == "0.783s"); - REQUIRE(ToString(time::ms(783), "ms") == "783ms"); - REQUIRE(ToString(time::us(0)) == "0ns"); // Defaults to the lowest unit - REQUIRE(ToString(time::us(0), "s") == "0s"); - REQUIRE(ToString(time::s(-1)) == "-1s"); - REQUIRE(ToString(time::us(-100)) == "-100us"); +TEST_CASE("conversion from duration to string", "[support]") { + REQUIRE(ToString(ns(150)) == "150ns"); + REQUIRE(ToString(ms(783)) == "0.783s"); + REQUIRE(ToString(ms(783), "ms") == "783ms"); + REQUIRE(ToString(us(0)) == "0ns"); // Defaults to the lowest unit + REQUIRE(ToString(us(0), "s") == "0s"); + REQUIRE(ToString(s(-1)) == "-1s"); + REQUIRE(ToString(us(-100)) == "-100us"); } -TEST_CASE("string to std::chrono::duration", "[support][now]") { - REQUIRE(StringTo("150", "ns") == time::ns(150)); - REQUIRE(StringTo("150ns") == time::ns(150)); - REQUIRE(StringTo("150s") == time::s(150)); - REQUIRE(StringTo("3 s") == time::s(3)); +TEST_CASE("string to std::chrono::duration", "[support]") { + REQUIRE(StringTo("150", "ns") == ns(150)); + REQUIRE(StringTo("150ns") == ns(150)); + REQUIRE(StringTo("150s") == s(150)); + REQUIRE(StringTo("3 s") == s(3)); - REQUIRE_THROWS(StringTo("5xs")); - REQUIRE_THROWS(StringTo("asvn")); + REQUIRE_THROWS(StringTo("5xs")); + REQUIRE_THROWS(StringTo("asvn")); } -TEST_CASE("Convert vector of time", "[support][now]"){ - std::vector vec{time::ns(150), time::us(10), time::ns(600)}; +TEST_CASE("Convert vector of time", "[support]") { + std::vector vec{ns(150), us(10), ns(600)}; REQUIRE(ToString(vec) == "[150ns, 10us, 600ns]"); REQUIRE(ToString(vec, "ns") == "[150ns, 10000ns, 600ns]"); } -TEST_CASE("Vector of int", "[support][now]"){ +TEST_CASE("Vector of int", "[support]") { std::vector vec; REQUIRE(ToString(vec) == "[]"); @@ -66,10 +70,9 @@ TEST_CASE("Vector of int", "[support][now]"){ vec.push_back(5000); REQUIRE(ToString(vec) == "[1, 172, 5000]"); - } -TEST_CASE("Vector of double", "[support][now]"){ +TEST_CASE("Vector of double", "[support]") { std::vector vec; REQUIRE(ToString(vec) == "[]"); @@ -81,5 +84,24 @@ TEST_CASE("Vector of double", "[support][now]"){ vec.push_back(-5669.325005); REQUIRE(ToString(vec) == "[1.3, 5669.325, -5669.325005]"); +} + +TEST_CASE("Array") { + std::array arr{1, 2, 3}; + REQUIRE(ToString(arr) == "[1, 2, 3]"); +} + +TEST_CASE("Convert types with str method"){ + sls::IpAddr addr; + REQUIRE(ToString(addr) == "0.0.0.0"); + REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0"); +} + +TEST_CASE("vector of strings"){ + std::vector vec{"5", "s"}; + REQUIRE(ToString(vec) == "5 s"); + + std::vector vec2{"some", "strange", "words", "75"}; + REQUIRE(ToString(vec2) == "some strange words 75"); } \ No newline at end of file diff --git a/slsSupportLib/tests/test-TypeTraits.cpp b/slsSupportLib/tests/test-TypeTraits.cpp new file mode 100644 index 000000000..0df0ed186 --- /dev/null +++ b/slsSupportLib/tests/test-TypeTraits.cpp @@ -0,0 +1,51 @@ +#include "TypeTraits.h" +#include "catch.hpp" +#include +#include +#include +#include +#include + +//Dummy classes only used here for testing +class DummyWithStr { + public: + std::string str(); +}; + +class DummyNoStr { + public: + std::string somethingelse(); +}; + +TEST_CASE("sls::is_container") { + + CHECK(sls::is_container>::value == true); + CHECK(sls::is_container>::value == true); +} + +TEST_CASE("Check for str() method") { + REQUIRE(sls::has_str::value == true); + REQUIRE(sls::has_str::value == false); +} + +TEST_CASE("Check for str() on ostream") { + REQUIRE(sls::has_str::value == true); +} + +TEST_CASE("sls::is_duration"){ + REQUIRE(sls::is_duration::value == true); + REQUIRE(sls::is_duration::value == true); + REQUIRE(sls::is_duration::value == true); + + REQUIRE(sls::is_duration::value == false); + REQUIRE(sls::is_duration>::value == false); +} + +TEST_CASE("initializer list"){ + REQUIRE(sls::is_light_container>::value == true); +} + +TEST_CASE("Check for emplace back"){ + //we know vector should have this its the type trait that is tested + REQUIRE(sls::has_emplace_back>::value == true); +} \ No newline at end of file