From e14519c23663d06d0ff7ff8036e8c55948685c2b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 3 May 2019 20:37:40 +0200 Subject: [PATCH] slsReceiver: removed special receiver config, added rx_dbitlist, rx_dbitoffset to put bits together in file, connected adcinvert, extsamplingsrc and extsampling properly to the detector, added tests --- CMakeLists.txt | 1 - cmk.sh | 13 +- .../test-integrationDectector.cpp | 72 +++++++ .../slsDetectorFunctionList.c | 32 +++ .../slsDetectorFunctionList.h | 4 + .../slsDetectorServer_funcs.c | 109 +++++++++- .../slsDetectorServer_funcs.h | 5 +- .../include/multiSlsDetector.h | 78 +++++++ slsDetectorSoftware/include/slsDetector.h | 86 +++++++- slsDetectorSoftware/src/multiSlsDetector.cpp | 94 +++++++- slsDetectorSoftware/src/slsDetector.cpp | 163 ++++++++++++++ .../src/slsDetectorCommand.cpp | 201 +++++++++++++----- .../tests/test-slsDetector.cpp | 43 ++++ slsReceiverSoftware/CMakeLists.txt | 14 +- slsReceiverSoftware/include/DataProcessor.h | 56 ++--- slsReceiverSoftware/include/slsReceiver.h | 15 -- .../include/slsReceiverImplementation.h | 65 +++--- .../include/slsReceiverTCPIPInterface.h | 40 +--- .../include/slsReceiverUsers.h | 10 - slsReceiverSoftware/src/DataProcessor.cpp | 75 ++++--- slsReceiverSoftware/src/mainCustomized.cpp | 189 ---------------- slsReceiverSoftware/src/slsReceiver.cpp | 12 +- .../src/slsReceiverImplementation.cpp | 47 ++-- .../src/slsReceiverTCPIPInterface.cpp | 127 +++++++++-- slsReceiverSoftware/src/slsReceiverUsers.cpp | 5 - slsSupportLib/include/sls_detector_funcs.h | 15 ++ slsSupportLib/include/versionAPI.h | 2 +- 27 files changed, 1088 insertions(+), 485 deletions(-) delete mode 100755 slsReceiverSoftware/src/mainCustomized.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3865b5643..87f1c0bdb 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,6 @@ option (SLS_USE_HDF5 "HDF5 File format" OFF) option (SLS_USE_TEXTCLIENT "Text Client" OFF) option (SLS_USE_RECEIVER "Receiver" OFF) option (SLS_USE_GUI "GUI" OFF) -option (SLS_USE_MYTHEN302_CTB_RECEIVER "Mythen302 CTB Receiver" OFF) option (SLS_USE_TESTS "TESTS" ON) option (SLS_USE_INTEGRATION_TESTS "Integration Tests" ON) option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF) diff --git a/cmk.sh b/cmk.sh index 31f7fef44..661d6c526 100755 --- a/cmk.sh +++ b/cmk.sh @@ -8,7 +8,6 @@ RECEIVER=0 GUI=0 DEBUG=0 PYTHON=0 -SPECIAL_RECEIVER_TYPE=0 CLEAN=0 @@ -17,7 +16,7 @@ CMAKE_PRE="" CMAKE_POST="" usage() { echo -e " -Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d ] [-j] [-s] +Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d ] [-j] -[no option]: only make -c: Clean -b: Builds/Rebuilds CMake files normal mode @@ -29,7 +28,6 @@ Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d ] [-j] list = m.getReceiverDbitList(); + list.clear(); + for (int i = 0; i < 10; ++i) + list.push_back(i); + m.setReceiverDbitList(list); + + CHECK(m.getReceiverDbitList().size() == 10); + + list.push_back(64); + CHECK_THROWS_AS(m.setReceiverDbitList(list), sls::RuntimeError); + CHECK_THROWS_WITH(m.setReceiverDbitList(list), + Catch::Matchers::Contains("be between 0 and 63")); + + list.clear(); + for (int i = 0; i < 65; ++i) + list.push_back(i); + CHECK(list.size() == 65); + CHECK_THROWS_WITH(m.setReceiverDbitList(list), + Catch::Matchers::Contains("be greater than 64")); + + list.clear(); + m.setReceiverDbitList(list); + CHECK(m.getReceiverDbitList().empty()); + + // adcinvert + m.setADCInvert(0); + CHECK(m.getADCInvert() == 0); + m.setADCInvert(5); + CHECK(m.getADCInvert() == 5); + m.setADCInvert(-1); + CHECK(m.getADCInvert() == -1); + + // ext sampling reg + m.setExternalSamplingSource(0); + CHECK(m.getExternalSamplingSource() == 0); + m.setExternalSamplingSource(62); + CHECK(m.getExternalSamplingSource() == 62); + CHECK_THROWS_WITH(m.setExternalSamplingSource(64), + Catch::Matchers::Contains("be 0-63")); + CHECK(m.getExternalSamplingSource() == 62); + m.setExternalSampling(1); + CHECK(m.getExternalSampling() == 1); + m.setExternalSampling(0); + CHECK(m.getExternalSampling() == 0); + m.setExternalSampling(1); + CHECK(m.getExternalSampling() == 1); + CHECK(m.readRegister(0x7b) == 0x1003E); + } \ No newline at end of file diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index a71a11d96..2a71dbc1e 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -714,6 +714,38 @@ uint32_t getADCEnableMask() { return retval; } +void setADCInvertRegister(uint32_t val) { + FILE_LOG(logINFO, ("Setting ADC Port Invert Reg to 0x%x\n", val)); + bus_w(ADC_PORT_INVERT_REG, val); +} + +uint32_t getADCInvertRegister() { + return bus_r(ADC_PORT_INVERT_REG); +} + +int setExternalSamplingSource(int val) { + uint32_t addr = DBIT_EXT_TRG_REG; + if (val >= 0) { + FILE_LOG(logINFO, ("Setting External sampling source to %d\n", val)); + bus_w(addr, bus_r(addr) &~ DBIT_EXT_TRG_SRC_MSK); + bus_w(addr, bus_r(addr) | ((val << DBIT_EXT_TRG_SRC_OFST) & DBIT_EXT_TRG_SRC_MSK)); + } + return ((bus_r(addr) & DBIT_EXT_TRG_SRC_MSK) >> DBIT_EXT_TRG_SRC_OFST); +} + +int setExternalSampling(int val) { + uint32_t addr = DBIT_EXT_TRG_REG; + if (val > 0) { + FILE_LOG(logINFO, ("Enabling External sampling\n")); + bus_w(addr, bus_r(addr) | DBIT_EXT_TRG_OPRTN_MD_MSK); + } + else if (val == 0) { + FILE_LOG(logINFO, ("Disabling External sampling\n")); + bus_w(addr, bus_r(addr) &~ DBIT_EXT_TRG_OPRTN_MD_MSK); + } + + return ((bus_r(addr) & DBIT_EXT_TRG_OPRTN_MD_MSK) >> DBIT_EXT_TRG_OPRTN_MD_OFST); +} /* parameters - speed, readout */ diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h index ba4ae9da8..57aad1b21 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h @@ -115,6 +115,10 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret); #if defined(CHIPTESTBOARDD) || defined(MOENCHD) int setADCEnableMask(uint32_t mask); uint32_t getADCEnableMask(); +void setADCInvertRegister(uint32_t val); +uint32_t getADCInvertRegister(); +int setExternalSamplingSource(int val); +int setExternalSampling(int val); #endif // parameters - readout diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 3bdcd7f77..97b9f99bd 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -238,7 +238,10 @@ const char* getFunctionName(enum detFuncs func) { case F_REBOOT_CONTROLLER: return "F_REBOOT_CONTROLLER"; case F_SET_ADC_ENABLE_MASK: return "F_SET_ADC_ENABLE_MASK"; case F_GET_ADC_ENABLE_MASK: return "F_GET_ADC_ENABLE_MASK"; - + case F_SET_ADC_INVERT: return "F_SET_ADC_INVERT"; + case F_GET_ADC_INVERT: return "F_GET_ADC_INVERT"; + case F_EXTERNAL_SAMPLING_SOURCE: return "F_EXTERNAL_SAMPLING_SOURCE"; + case F_EXTERNAL_SAMPLING: return "F_EXTERNAL_SAMPLING"; default: return "Unknown Function"; } } @@ -317,6 +320,10 @@ void function_table() { flist[F_REBOOT_CONTROLLER] = &reboot_controller; flist[F_SET_ADC_ENABLE_MASK] = &set_adc_enable_mask; flist[F_GET_ADC_ENABLE_MASK] = &get_adc_enable_mask; + flist[F_SET_ADC_INVERT] = &set_adc_invert; + flist[F_GET_ADC_INVERT] = &get_adc_invert; + flist[F_EXTERNAL_SAMPLING_SOURCE] = &set_external_sampling_source; + flist[F_EXTERNAL_SAMPLING] = &set_external_sampling; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -3904,3 +3911,103 @@ int get_adc_enable_mask(int file_des) { #endif return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); } + + +int set_adc_invert(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint32_t arg = 0; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Seting ADC Invert to %u\n", arg)); + +#if (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD)) + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + setADCInvertRegister(arg); + uint32_t retval = getADCInvertRegister(); + if (arg != retval) { + ret = FAIL; + sprintf(mess, "Could not set ADC Invert register. Set 0x%x, but read 0x%x\n", arg, retval); + FILE_LOG(logERROR,(mess)); + } + } +#endif + return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); +} + + +int get_adc_invert(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint32_t retval = -1; + + FILE_LOG(logDEBUG1, ("Getting ADC Invert register \n")); + +#if (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD)) + functionNotImplemented(); +#else + // get + retval = getADCInvertRegister(); + FILE_LOG(logDEBUG1, ("ADC Invert register retval: %u\n", retval)); +#endif + return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); +} + + + +int set_external_sampling_source(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + int retval = -1; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Setting external sampling source to %d\n", arg)); + +#ifndef CHIPTESTBOARDD + functionNotImplemented(); +#else + // set & get + if ((arg == -1) || (Server_VerifyLock() == OK)) { + if (arg < -1 || arg > 63) { + ret = FAIL; + sprintf(mess, "Could not set external sampling source to %d. Value must be 0-63.\n", arg); + FILE_LOG(logERROR,(mess)); + } else { + retval = setExternalSamplingSource(arg); + FILE_LOG(logDEBUG1, ("External Sampling source: %d\n", retval)); + validate(arg, retval, "External sampling source", DEC); + } + } +#endif + return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); +} + +int set_external_sampling(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + int retval = -1; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Setting external sampling enable to %d\n", arg)); + +#ifndef CHIPTESTBOARDD + functionNotImplemented(); +#else + // set & get + if ((arg == -1) || (Server_VerifyLock() == OK)) { + arg = (arg > 0) ? 1 : arg; + retval = setExternalSampling(arg); + FILE_LOG(logDEBUG1, ("External Sampling enable: %d\n", retval)); + validate(arg, retval, "External sampling enable", DEC); + } +#endif + return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); +} diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h index 25f55902b..6b824b99d 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h @@ -99,4 +99,7 @@ int copy_detector_server(int); int reboot_controller(int); int set_adc_enable_mask(int); int get_adc_enable_mask(int); - +int set_adc_invert(int); +int get_adc_invert(int); +int set_external_sampling_source(int); +int set_external_sampling(int); diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 812c61829..613034514 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -236,6 +236,10 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ int64_t getReceiverSoftwareVersion(int detPos = -1); + /** + * Get Detector Number + * @returns vector of detector number + */ std::vector getDetectorNumber(); /** * Free shared memory from the command line @@ -438,6 +442,10 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ int setReceiverPort(int port_number = -1, int detPos = -1); + /** + * Get Receiver port + * @returns vector of receiver port + */ std::vector getReceiverPort() const; /** @@ -1305,6 +1313,76 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + /** * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert * users diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index c3b92c3bc..e491e25f3 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -16,10 +16,8 @@ class multiSlsDetector; class ServerInterface; class MySocketTCP; -#define SLS_SHMVERSION 0x190430 -#define NCHIPSMAX 10 -#define NCHANSMAX 65536 -#define NDACSMAX 16 +#define SLS_SHMVERSION 0x190503 +#define MAX_RX_DBIT 64 /** @@ -245,6 +243,15 @@ struct sharedSlsDetector { /** overwrite enable */ bool rxFileOverWrite; + + /** receiver dbit size */ + int rxDbitListSize; + + /** receiver dbit list */ + int rxDbitList[MAX_RX_DBIT]; + + /** reciever dbit offset */ + int rxDbitOffset; }; @@ -1218,6 +1225,77 @@ class slsDetector : public virtual slsDetectorDefs{ * @returns ADC Enable mask */ uint32_t getADCEnableMask(); + + /** + * 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); + + /** + * 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(); + + /** + * 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 + * @returns external sampling source + */ + int setExternalSamplingSource(int value); + + /** + * Get external sampling source (CTB only) + * @param detPos -1 for all detectors in list or specific detector position + * @returns external sampling source + */ + int getExternalSamplingSource(); + + /** + * 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 + * @returns external sampling enable + */ + int setExternalSampling(int value); + + /** + * Get external sampling source (CTB only) + * @param detPos -1 for all detectors in list or specific detector position + * @returns external sampling enable + */ + int getExternalSampling(); + + /** + * 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); + + /** + * 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(); + + /** + * Set digital data offset in bytes (CTB only) + * @param value digital data offset in bytes + * @returns digital data offset in bytes + */ + int setReceiverDbitOffset(int value); + + /** + * Get digital data offset in bytes (CTB only) + * @returns digital data offset in bytes + */ + int getReceiverDbitOffset(); /** * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert users diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 9598deb72..97839a048 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -2446,22 +2446,18 @@ const slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) { } void multiSlsDetector::setADCEnableMask(uint32_t mask, int detPos) { - // single if (detPos >= 0) { detectors[detPos]->setADCEnableMask(mask); } - // multi parallelCall(&slsDetector::setADCEnableMask, mask); } uint32_t multiSlsDetector::getADCEnableMask(int detPos) { - // single if (detPos >= 0) { return detectors[detPos]->getADCEnableMask(); } - // multi auto r = parallelCall(&slsDetector::getADCEnableMask); if (sls::allEqual(r)) { return r.front(); @@ -2471,6 +2467,96 @@ uint32_t multiSlsDetector::getADCEnableMask(int detPos) { throw RuntimeError("Error: Different Values for function getADCEnableMask"); } +void multiSlsDetector::setADCInvert(uint32_t value, int detPos) { + if (detPos >= 0) { + detectors[detPos]->setADCInvert(value); + } + + parallelCall(&slsDetector::setADCInvert, value); +} + +uint32_t multiSlsDetector::getADCInvert(int detPos) { + if (detPos >= 0) { + return detectors[detPos]->getADCInvert(); + } + + auto r = parallelCall(&slsDetector::getADCInvert); + if (sls::allEqual(r)) { + return r.front(); + } + + // can't have different values + throw RuntimeError("Error: Different Values for function getADCInvert"); +} + +void multiSlsDetector::setExternalSamplingSource(int value, int detPos) { + if (detPos >= 0) { + detectors[detPos]->setExternalSamplingSource(value); + } + + parallelCall(&slsDetector::setExternalSamplingSource, value); +} + +int multiSlsDetector::getExternalSamplingSource(int detPos) { + if (detPos >= 0) { + return detectors[detPos]->getExternalSamplingSource(); + } + + auto r = parallelCall(&slsDetector::getExternalSamplingSource); + return sls::minusOneIfDifferent(r); +} + +void multiSlsDetector::setExternalSampling(bool value, int detPos) { + if (detPos >= 0) { + detectors[detPos]->setExternalSampling(static_cast(value)); + } + + parallelCall(&slsDetector::setExternalSampling, static_cast(value)); +} + +int multiSlsDetector::getExternalSampling(int detPos) { + if (detPos >= 0) { + return detectors[detPos]->getExternalSampling(); + } + + auto r = parallelCall(&slsDetector::getExternalSampling); + return sls::minusOneIfDifferent(r); +} + +void multiSlsDetector::setReceiverDbitList(std::vector list, int detPos) { + if (detPos >= 0) { + detectors[detPos]->setReceiverDbitList(list); + } + + parallelCall(&slsDetector::setReceiverDbitList, list); +} + +std::vector multiSlsDetector::getReceiverDbitList(int detPos) { + if (detPos >= 0) { + return detectors[detPos]->getReceiverDbitList(); + } + + auto r = parallelCall(&slsDetector::getReceiverDbitList); + return sls::minusOneIfDifferent(r); +} + +void multiSlsDetector::setReceiverDbitOffset(int value, int detPos) { + if (detPos >= 0) { + detectors[detPos]->setReceiverDbitOffset(value); + } + + parallelCall(&slsDetector::setReceiverDbitOffset, value); +} + +int multiSlsDetector::getReceiverDbitOffset(int detPos) { + if (detPos >= 0) { + return detectors[detPos]->getReceiverDbitOffset(); + } + + auto r = parallelCall(&slsDetector::getReceiverDbitOffset); + return sls::minusOneIfDifferent(r); +} + int multiSlsDetector::writeAdcRegister(uint32_t addr, uint32_t val, int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index a1cbb2060..9d45316e2 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -393,6 +393,9 @@ void slsDetector::initializeDetectorStructure(detectorType type) { shm()->rxFileWrite = true; shm()->rxMasterFileWrite = true; shm()->rxFileOverWrite = true; + shm()->rxDbitListSize = 0; + memset(shm()->rxDbitList, 0, MAX_RX_DBIT * sizeof(int)); + shm()->rxDbitOffset = 0; // get the detector parameters based on type detParameters parameters{type}; @@ -1908,6 +1911,8 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { << "\nrx streaming source ip:" << shm()->rxZmqip << "\nrx additional json header:" << shm()->rxAdditionalJsonHeader << "\nrx_datastream:" << enableDataStreamingFromReceiver(-1) + << "\nrx_dbitlistsize:" << shm()->rxDbitListSize + << "\nrx_DbitOffset:" << shm()->rxDbitOffset << std::endl; if (setDetectorType(shm()->myDetectorType) != GENERIC) { @@ -1954,6 +1959,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { enableTenGigabitEthernet(shm()->tenGigaEnable); setReadOutFlags(GET_READOUT_FLAGS); setADCEnableMask(shm()->adcEnableMask); + setReceiverDbitOffset(shm()->rxDbitOffset); break; case MOENCH: @@ -1971,6 +1977,11 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { break; } + if (shm()->myDetectorType == CHIPTESTBOARD) { + std::vector list(shm()->rxDbitList, shm()->rxDbitList + shm()->rxDbitListSize); + setReceiverDbitList(list); + } + setReceiverSilentMode(static_cast(shm()->rxSilentMode)); // data streaming setReceiverStreamingFrequency(shm()->rxReadFreq); @@ -2666,6 +2677,143 @@ uint32_t slsDetector::getADCEnableMask() { return shm()->adcEnableMask; } +void slsDetector::setADCInvert(uint32_t value) { + uint32_t arg = value; + FILE_LOG(logDEBUG1) << "Setting ADC Invert to 0x" << std::hex << arg << std::dec; + if (shm()->onlineFlag == ONLINE_FLAG) { + sendToDetector(F_SET_ADC_INVERT, &arg, sizeof(arg), nullptr, 0); + } +} + +uint32_t slsDetector::getADCInvert() { + uint32_t retval = -1; + FILE_LOG(logDEBUG1) << "Getting ADC Invert"; + if (shm()->onlineFlag == ONLINE_FLAG) { + sendToDetector(F_GET_ADC_INVERT, nullptr, 0, &retval, sizeof(retval)); + FILE_LOG(logDEBUG1) << "ADC Invert: 0x" << std::hex << retval << std::dec; + } + return retval; +} + +int slsDetector::setExternalSamplingSource(int value) { + int arg = value; + int retval = -1; + FILE_LOG(logDEBUG1) << "Setting External Sampling Source to " << arg; + if (shm()->onlineFlag == ONLINE_FLAG) { + sendToDetector(F_EXTERNAL_SAMPLING_SOURCE, arg, retval); + FILE_LOG(logDEBUG1) << "External Sampling source: " << retval; + } + return retval; +} + +int slsDetector::getExternalSamplingSource() { + return setExternalSamplingSource(-1); +} + +int slsDetector::setExternalSampling(int value) { + int arg = value; + int retval = -1; + FILE_LOG(logDEBUG1) << "Setting External Sampling to " << arg; + if (shm()->onlineFlag == ONLINE_FLAG) { + sendToDetector(F_EXTERNAL_SAMPLING, arg, retval); + FILE_LOG(logDEBUG1) << "External Sampling: " << retval; + } + return retval; +} + +int slsDetector::getExternalSampling() { + return setExternalSampling(-1); +} + +void slsDetector::setReceiverDbitList(std::vector list) { + FILE_LOG(logDEBUG1) << "Setting Receiver Dbit List"; + + if (list.size() > 64) { + throw sls::RuntimeError("Dbit list size cannot be greater than 64\n"); + } + for (auto &it : list) { + if (it < 0 || it > 63) { + throw sls::RuntimeError("Dbit list value must be between 0 and 63\n"); + } + } + + // copy size and vector to shm + shm()->rxDbitListSize = list.size(); + std::copy(list.begin(), list.end(), shm()->rxDbitList); + + int ret = FAIL; + if (shm()->rxOnlineFlag == ONLINE_FLAG) { + int fnum = F_SET_RECEIVER_DBIT_LIST; + int arg = list.size(); + auto receiver = + sls::ClientSocket("Receiver", shm()->rxHostname, shm()->rxTCPPort); + receiver.sendData(&fnum, sizeof(fnum)); + receiver.sendData(&arg, sizeof(arg)); + receiver.sendData(shm()->rxDbitList, arg * sizeof(int)); + receiver.receiveData(&ret, sizeof(ret)); + if (ret == FAIL) { + char mess[MAX_STR_LENGTH]{}; + receiver.receiveData(mess, MAX_STR_LENGTH); + throw ReceiverError("Receiver " + std::to_string(detId) + + " returned error: " + std::string(mess)); + } + } + if (ret == FORCE_UPDATE) { + ret = updateCachedReceiverVariables(); + } +} + +std::vector slsDetector::getReceiverDbitList() { + int fnum = F_GET_RECEIVER_DBIT_LIST; + int ret = FAIL; + std::vector retval; + int retsize = 0; + FILE_LOG(logDEBUG1) << "Getting Receiver Dbit List"; + if (shm()->rxOnlineFlag == ONLINE_FLAG) { + auto receiver = + sls::ClientSocket("Receiver", shm()->rxHostname, shm()->rxTCPPort); + receiver.sendData(&fnum, sizeof(fnum)); + receiver.receiveData(&ret, sizeof(ret)); + if (ret == FAIL) { + char mess[MAX_STR_LENGTH]{}; + receiver.receiveData(mess, MAX_STR_LENGTH); + throw ReceiverError("Receiver " + std::to_string(detId) + + " returned error: " + std::string(mess)); + } + receiver.receiveData(&retsize, sizeof(retsize)); + int list[retsize]; + receiver.receiveData(list, sizeof(list)); + + // copy after no errors + shm()->rxDbitListSize = retsize; + std::copy(list, list + retsize, shm()->rxDbitList); + } + + if (shm()->rxDbitListSize) { + retval.resize(shm()->rxDbitListSize); + std::copy(shm()->rxDbitList, shm()->rxDbitList + shm()->rxDbitListSize, std::begin(retval)); + } + + return retval; +} + +int slsDetector::setReceiverDbitOffset(int value) { + int arg = value; + int retval = -1; + if (value >= 0) + shm()->rxDbitOffset = value; + FILE_LOG(logDEBUG1) << "Setting digital bit offset in receiver to " << arg; + if (shm()->rxOnlineFlag == ONLINE_FLAG) { + sendToReceiver(F_RECEIVER_DBIT_OFFSET, arg, retval); + FILE_LOG(logDEBUG1) << "Receiver digital bit offset: " << retval; + } + return shm()->rxDbitOffset; +} + +int slsDetector::getReceiverDbitOffset() { + return shm()->rxDbitOffset; +} + int slsDetector::writeAdcRegister(uint32_t addr, uint32_t val) { uint32_t args[]{addr, val}; FILE_LOG(logDEBUG1) << "Writing to ADC register 0x" << std::hex << addr @@ -3295,6 +3443,21 @@ int slsDetector::updateCachedReceiverVariables() const { n += receiver.receiveData(&i32, sizeof(i32)); shm()->rxSilentMode = static_cast(i32); + // dbit list size + { + int listsize = 0; + n += receiver.receiveData(&listsize, sizeof(listsize)); + int list[listsize]; + n += receiver.receiveData(list, sizeof(list)); + // copy after no errors + shm()->rxDbitListSize = listsize; + std::copy(list, list + listsize, shm()->rxDbitList); + } + + // dbit offset + n += receiver.receiveData(&i32, sizeof(i32)); + shm()->rxDbitOffset = i32; + if (n == 0) { throw RuntimeError("Could not update receiver: " + std::string(shm()->rxHostname) + diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 326b75f62..87533de64 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -1934,13 +1934,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; ++i; - /*! \page prototype - - adcinvert [mask] Sets/gets ADC inversion mask (8 digits hex format) - */ - descrToFuncMap[i].m_pFuncName = "adcinvert"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - /*! \page prototype - adcenable [mask] Sets/gets ADC enable mask (8 digits hex format) */ @@ -1948,11 +1941,46 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; ++i; - /** not documenting this, but keeping this for backwards compatibility */ + /** not documenting this, but keeping this for backwards compatibility */ descrToFuncMap[i].m_pFuncName = "adcdisable"; descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; ++i; + /*! \page prototype + - adcinvert [mask] Sets/gets ADC inversion mask (8 digits hex format) CTB or Moench only + */ + descrToFuncMap[i].m_pFuncName = "adcinvert"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; + ++i; + + /*! \page prototype + - extsamplingsrc [i] sets/gets the sampling source signal for digital data. \ci must be between 0 and 63. Advanced! CTB only \Returns (int) + */ + descrToFuncMap[i].m_pFuncName = "extsamplingsrc"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; + ++i; + + /*! \page prototype + - extsampling [i] enables/disables the external sampling signal to the \c samplingsrc signal for digital data. Advanced! CTB only \Returns (int) + */ + descrToFuncMap[i].m_pFuncName = "extsampling"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; + ++i; + + /*! \page prototype + - rx_dbitlist [i] sets/gets the list of digital signal bits required for chip in receiver. If set to "all", then all digital bits are enabled. Advanced! CTB only \Returns (string) + */ + descrToFuncMap[i].m_pFuncName = "rx_dbitlist"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; + ++i; + + /*! \page prototype + - rx_dbitoffset [i] sets/gets the offset in bytes in receiver of digital data from chip in receiver. Advanced! CTB only \Returns (int) + */ + descrToFuncMap[i].m_pFuncName = "rx_dbitoffset"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; + ++i; + /*! \page prototype - pattern fn loads binary pattern file fn */ @@ -2086,13 +2114,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; ++i; - /*! \page prototype - - dut_clk [i] sets/gets the signal to be used as a clock for the digital data coming from the device under test. Advanced! - */ - descrToFuncMap[i].m_pFuncName = "dut_clk"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - numberOfCommands = i; // #ifdef VERBOSE @@ -5233,8 +5254,12 @@ std::string slsDetectorCommand::helpPattern(int action) { os << "patwaittime2 nclk \t sets wait 2 waiting time in clock number " << std::endl; os << "patmask m \t sets the 64 bit mask (hex) applied to every pattern. Only the bits from patsetbit are selected to mask for the corresponding bit value from m mask" << std::endl; os << "patsetbit m \t selects bits (hex) of the 64 bits that the patmask will be applied to every pattern. Only the bits from m mask are selected to mask for the corresponding bit value from patmask." << std::endl; - os << "adcinvert mask\t sets the adcinversion mask (hex)" << std::endl; - os << "adcenable mask\t sets the adcenable mask (hex)" << std::endl; + os << "adcinvert mask\t sets the adcinversion mask (hex) CTB or Moench only" << std::endl; + os << "adcenable mask\t sets the adcenable mask (hex) CTB or Moench only" << std::endl; + os << "extsamplingsrc i\t sets the external sampling source signal for digital data. i must be between 0 and 63. Advanced! CTB only " << std::endl; + os << "extsampling i\t enables/disables the external sampling signal to the samplingsrc signal for digital data. Advanced! CTB only" << std::endl; + os << "rx_dbitlist i..\t sets the list of digital signal bits required for chip in receiver. If set to 'all', then all digital bits are enabled. Advanced! CTB only " << std::endl; + os << "rx_dbitoffset i\t sets the offset in bytes in receiver of digital data from chip in receiver. Advanced! CTB only " << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { os << "pattern \t cannot get" << std::endl; @@ -5257,8 +5282,12 @@ std::string slsDetectorCommand::helpPattern(int action) { os << "patmask \t gets the 64 bit mask (hex) applied to every pattern." << std::endl; os << "patsetbit \t gets 64 bit mask (hex) of the selected bits that the patmask will be applied to every pattern. " << std::endl; os << "adcinvert \t returns the adcinversion mask " << std::endl; - os << "adcenable \t returns the adcenable mask " << std::endl; + os << "extsamplingsrc \t gets the external sampling source signal for digital data. i must be between 0 and 63. Advanced! CTB only " << std::endl; + os << "extsampling \t gets the external sampling signal enable to the samplingsrc signal for digital data. Advanced! CTB only" << std::endl; + os << "rx_dbitlist \t gets the list of digital signal bits required for chip in receiver. If value is 'all', all digital bits are enabled. Advanced! CTB only " << std::endl; + os << "rx_dbitoffset \t gets the offset in bytes in receiver of digital data from chip in receiver. Advanced! CTB only " << std::endl; + } return os.str(); } @@ -5274,6 +5303,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i **********/ std::string fname; int addr, start, stop, n; + uint32_t u32; uint64_t word, t; myDet->setOnline(ONLINE_FLAG, detPos); @@ -5589,41 +5619,15 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i os << "0x" << std::hex << myDet->getPatternBitMask(detPos) << std::dec; - } else if (cmd == "adcinvert") { - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%x", &addr)) - ; - else - return std::string("Could not scan adcinvert reg ") + std::string(args[1]); - - myDet->writeRegister(67, addr, detPos); - } - - os << std::hex << myDet->readRegister(67, detPos) << std::dec ; - - } else if (cmd == "dut_clk") { - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%x", &addr)) - ; - else - return std::string("Could not scan dut_clk reg ") + std::string(args[1]); - - myDet->writeRegister(123, addr, detPos); //0x7b - } - - os << std::hex << myDet->readRegister(123, detPos) << std::dec ; //0x7b - } else if (cmd == "adcenable") { + } else if (cmd == "adcenable") { if (action == PUT_ACTION) { - uint32_t adcEnableMask = 0; - if (sscanf(args[1], "%x", &adcEnableMask)) + if (sscanf(args[1], "%x", &u32)) ; else return std::string("Could not scan adcenable reg ") + std::string(args[1]); - myDet->setADCEnableMask(adcEnableMask, detPos); + myDet->setADCEnableMask(u32, detPos); } os << std::hex << myDet->getADCEnableMask(detPos) << std::dec; @@ -5632,22 +5636,109 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i else if (cmd == "adcdisable") { if (action == PUT_ACTION) { - uint32_t adcEnableMask = 0; - if (sscanf(args[1], "%x", &adcEnableMask)) + if (sscanf(args[1], "%x", &u32)) ; else return std::string("Could not scan adcdisable reg ") + std::string(args[1]); // get enable mask from enable mask - adcEnableMask ^= BIT32_MASK; - myDet->setADCEnableMask(adcEnableMask, detPos); + u32 ^= BIT32_MASK; + myDet->setADCEnableMask(u32, detPos); } - uint32_t retval = myDet->getADCEnableMask(detPos); + u32 = myDet->getADCEnableMask(detPos); // get disable mask - retval ^= BIT32_MASK; - os << std::hex << retval << std::dec; - } + u32 ^= BIT32_MASK; + os << std::hex << u32 << std::dec; + + } else if (cmd == "adcinvert") { + if (action == PUT_ACTION) { + + if (sscanf(args[1], "%x", &u32)) + ; + else + return std::string("Could not scan adcinvert reg ") + std::string(args[1]); + + myDet->setADCInvert(u32, detPos); + } + + os << std::hex << myDet->getADCInvert(detPos) << std::dec; + + } else if (cmd == "extsamplingsrc") { + if (action == PUT_ACTION) { + + if (!sscanf(args[1], "%d", &addr)) + return std::string("Could not scan extsampling src ") + std::string(args[1]); + + if (addr < 0 || addr > 63) + return std::string("extsamplingsrc must be between 0 and 63. ") + std::string(args[1]); + + myDet->setExternalSamplingSource(addr, detPos); + } + + os << myDet->getExternalSamplingSource(detPos); + + } else if (cmd == "extsampling") { + if (action == PUT_ACTION) { + + if (!sscanf(args[1], "%d", &addr)) + return std::string("Could not scan extsampling enable ") + std::string(args[1]); + + myDet->setExternalSampling(addr, detPos); + } + + os << myDet->getExternalSampling(detPos); + + } else if (cmd == "rx_dbitlist") { + + myDet->setReceiverOnline(ONLINE_FLAG, detPos); + + if (action == PUT_ACTION) { + std::vector dbitlist; + + // if not all digital bits enabled + if (std::string(args[1]) != "all") { + for (int i = 1; i < narg; ++i) { + int temp = 0; + if (!sscanf(args[i], "%d", &temp)) + return std::string("Could not scan dbitlist value ") + + std::string(args[i]); + if (temp < 0 || temp > 63) + return std::string("dbitlist value should be between 0 and 63 ") + + std::string(args[i]); + dbitlist.push_back(temp); + } + if (dbitlist.size() > 64) { + return std::string("Max number of values for dbitlist is 64 "); + } + } + + myDet->setReceiverDbitList(dbitlist, detPos); + } + + std::vector dbitlist = myDet->getReceiverDbitList(detPos); + // all digital bits enabled + if (dbitlist.empty()) + return std::string("all"); + // selective bits + for (const auto &value : dbitlist) + os << value << " "; + + } else if (cmd == "rx_dbitoffset") { + + myDet->setReceiverOnline(ONLINE_FLAG, detPos); + + if (action == PUT_ACTION) { + + if (!sscanf(args[1], "%d", &addr)) + return std::string("Could not scan rx_dbitoffset enable ") + std::string(args[1]); + + myDet->setReceiverDbitOffset(addr, detPos); + } + + os << myDet->getReceiverDbitOffset(detPos); + + } else return helpPattern(action); diff --git a/slsDetectorSoftware/tests/test-slsDetector.cpp b/slsDetectorSoftware/tests/test-slsDetector.cpp index b6fb6ce39..d79c47f99 100755 --- a/slsDetectorSoftware/tests/test-slsDetector.cpp +++ b/slsDetectorSoftware/tests/test-slsDetector.cpp @@ -217,4 +217,47 @@ TEST_CASE("create detParamets struct", "[detector][new]"){ CHECK(par2.dynamicRange == 16); CHECK(par2.nGappixelsX == 6); CHECK(par2.nGappixelsY == 1); +} + + +TEST_CASE("ctb digital offset and list", "[detector][ctb]"){ + slsDetector::freeSharedMemory(20, 20); + slsDetector d(slsDetectorDefs::detectorType::CHIPTESTBOARD, 20, 20); + + // dbit offset + CHECK(d.getReceiverDbitOffset() == 0); + CHECK(d.setReceiverDbitOffset(-1) == 0); + CHECK(d.setReceiverDbitOffset(0) == 0); + CHECK(d.setReceiverDbitOffset(5) == 5); + CHECK(d.getReceiverDbitOffset() == 5); + + // dbit list + std::vector list = d.getReceiverDbitList(); + CHECK(list.empty()); + + + for (int i = 0; i < 10; ++i) + list.push_back(i); + d.setReceiverDbitList(list); + + CHECK(d.getReceiverDbitList().size() == 10); + + list.push_back(64); + CHECK_THROWS_AS(d.setReceiverDbitList(list), sls::RuntimeError); + CHECK_THROWS_WITH(d.setReceiverDbitList(list), + Catch::Matchers::Contains("be between 0 and 63")); + + list.clear(); + for (int i = 0; i < 65; ++i) + list.push_back(i); + CHECK(list.size() == 65); + CHECK_THROWS_WITH(d.setReceiverDbitList(list), + Catch::Matchers::Contains("be greater than 64")); + + list.clear(); + d.setReceiverDbitList(list); + CHECK(d.getReceiverDbitList().empty()); + + + } \ No newline at end of file diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index c5bcc311d..4d483adc7 100755 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -70,19 +70,9 @@ set_target_properties(slsReceiverShared PROPERTIES PUBLIC_HEADER "${PUBLICHEADERS}" ) +add_executable(slsReceiver + src/main.cpp) -if (SLS_USE_MYTHEN302_CTB_RECEIVER) - add_executable(slsReceiver - src/mainCustomized.cpp - ) - add_definitions( - -DMYTHEN302 - ) -else() - add_executable(slsReceiver - src/main.cpp - ) -endif (SLS_USE_MYTHEN302_CTB_RECEIVER) set_target_properties(slsReceiver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index d30c60c9b..21a1348fd 100755 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -39,15 +39,15 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { * @param act pointer to activated * @param depaden pointer to deactivated padding enable * @param sm pointer to silent mode - * @param ct pointer to ctb type - * @param cdo pointer to ctb digital offset + * @param cdl pointer to vector or ctb digital bits enable + * @param cdo pointer to digital bits offset * @param cad pointer to ctb analog databytes */ DataProcessor(int ind, detectorType dtype, Fifo* f, fileFormat* ftype, bool fwenable, bool* mfwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr, uint32_t* freq, uint32_t* timer, bool* fp, bool* act, bool* depaden, bool* sm, - int* ct, int* cdo, int* cad); + std::vector * cdl, int* cdo, int* cad); /** * Destructor @@ -223,20 +223,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &, void*),void *arg); - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void registerCallBackCTBReceiverReady(void (*func)(char*, - char*, uint32_t &, int, int, int, void*),void *arg); - private: @@ -307,6 +293,11 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { */ void PadMissingPackets(char* buf); + /** + * Align corresponding digital bits together (CTB only if ctbDbitlist is not empty) + */ + void RearrangeDbitData(char* buf); + /** * Processing Function (inserting gap pixels) eiger specific * @param buf pointer to image @@ -380,6 +371,15 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** frame padding */ bool* framePadding; + /** ctb digital bits enable list */ + std::vector *ctbDbitList; + + /** ctb digital bits offset */ + int* ctbDbitOffset; + + /** ctb analog databytes */ + int* ctbAnalogDataBytes; + //acquisition start /** Aquisition Started flag */ bool acquisitionStartedFlag; @@ -404,14 +404,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** Frame Number of latest processed frame number of an entire Acquisition (including all scans) */ uint64_t currentFrameIndex; - // for ctb call back - /** ctb type*/ - int* ctbType; - /** ctb digital offset */ - int* ctbDigitalOffset; - /** ctb analog databytes */ - int* ctbAnalogDataBytes; - @@ -435,20 +427,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { */ void (*rawDataModifyReadyCallBack)(char*, char*, uint32_t &, void*); - - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void (*ctbRawDataReadyCallBack)(char*, - char*, uint32_t &, int, int, int, void*); void *pRawDataReady; diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index 43e567d6e..e7f14685f 100755 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -95,21 +95,6 @@ class slsReceiver : private virtual slsDetectorDefs { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &,void*),void *arg); - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void registerCallBackCTBReceiverReady(void (*func)(char*, - char*, uint32_t &, int, int, int, void*),void *arg); - - private: std::unique_ptr tcpipInterface; diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index 8913ea04e..d3abff1b5 100755 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -300,6 +300,18 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { */ bool getSilentMode() const; + /** + * Get CTB digital bits enable list + * @returns digital bits enable list + */ + std::vector getDbitList() const; + + /** + * Get CTB digital bits offset + * @returns digital bits offset + */ + int getDbitOffset() const; + /** * Get activate * If deactivated, receiver will create dummy data if deactivated padding is enabled @@ -637,6 +649,18 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { */ void setSilentMode(const bool i); + /** + * Set CTB digital bits enable list + * @param v digital bits enable list + */ + void setDbitList(const std::vector v); + + /** + * Set CTB digital bits offset + * @param s digital bits offset + */ + void setDbitOffset(const int s); + /************************************************************************* * Behavioral functions*************************************************** @@ -751,20 +775,6 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &,void*),void *arg); - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void registerCallBackCTBReceiverReady(void (*func)(char*, - char*, uint32_t &, int, int, int, void*),void *arg); - private: /** @@ -877,6 +887,12 @@ private: bool framePadding; /** silent mode */ bool silentMode; + /** ctb digital bits enabled list (empty: all enabled) */ + std::vector ctbDbitList; + /** ctb digital bit offset in bytes */ + int ctbDbitOffset; + /* analog data bytes */ + int ctbAnalogDataBytes; //***connection parameters*** /** Number of UDP Interfaces */ @@ -938,13 +954,6 @@ private: /** Fifo Structure to store addresses of memory writes */ std::vector> fifo; - /** ctb type for callback*/ - int ctbType; - /* ctb digital offset for callback */ - int ctbDigitalOffset; - /* analog data bytes */ - int ctbAnalogDataBytes; - //***callback parameters*** /** * Call back for start acquisition @@ -986,20 +995,6 @@ private: void (*rawDataModifyReadyCallBack)(char* , char*, uint32_t &, void*); - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void (*ctbRawDataReadyCallBack)(char*, - char*, uint32_t &, int, int, int, void*); - void *pRawDataReady; diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index be1d5a132..00431f8f8 100755 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -92,20 +92,6 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &,void*),void *arg); - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void registerCallBackCTBReceiverReady(void (*func)(char*, - char*, uint32_t &, int, int, int, void*),void *arg); - private: @@ -295,7 +281,7 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { int set_padding_enable(); /** set deactivated receiver padding enable */ - int set_deactivated_receiver_padding_enable(); + int set_deactivated_padding_enable(); /** set readout flags */ int set_readout_flags(); @@ -303,6 +289,15 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { /** set adc mask */ int set_adc_mask(); + /** set receiver dbit list */ + int set_dbit_list(); + + /** get receiver dbit list */ + int get_dbit_list(); + + /** set dbit offset */ + int set_dbit_offset(); + /** detector type */ detectorType myDetectorType; @@ -382,21 +377,6 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { void (*rawDataModifyReadyCallBack)(char* , char*, uint32_t &, void*); - /** - * Call back for raw CTB data that will be modified - * args to raw data call back are - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). - * type CTB chip type - * digitalOffset digital offset - * analogdataBytes analog databytes - */ - void (*ctbRawDataReadyCallBack)(char*, - char*, uint32_t &, int, int, int, void*); - - void *pRawDataReady; diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index a6d0ad513..39456bd94 100755 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -87,16 +87,6 @@ public: void registerCallBackRawDataModifyReady(void (*func)(char* header, char* datapointer, uint32_t &revDatasize, void*),void *arg); - /** - @short register callback to be called when CTB data are available in receiver (to process and/or save the data). - \param func raw data ready callback. arguments are sls_receiver_header, dataPointer, revDatasize is the reference of data size in bytes, chip type, digital offset, analog databytes. revDatasize be modified to the new size to be written/streamed. (only smaller value). - \param arg argument - \returns nothing - */ - void registerCallBackCTBReceiverReady(void (*func)(char* header, - char* datapointer, uint32_t &revDatasize, int type, int digitalOffset, int analogDataBytes, void*),void *arg); - - //receiver object std::unique_ptr receiver; }; diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index c16a8bbba..21d3163d9 100755 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -28,7 +28,7 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f, bool* dsEnable, bool* gpEnable, uint32_t* dr, uint32_t* freq, uint32_t* timer, bool* fp, bool* act, bool* depaden, bool* sm, - int* ct, int* cdo, int* cad) : + std::vector * cdl, int* cdo, int* cad) : ThreadObject(ind), runningFlag(0), @@ -50,6 +50,9 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f, deactivatedPaddingEnable(depaden), silentMode(sm), framePadding(fp), + ctbDbitList(cdl), + ctbDbitOffset(cdo), + ctbAnalogDataBytes(cad), acquisitionStartedFlag(false), measurementStartedFlag(false), firstAcquisitionIndex(0), @@ -57,12 +60,8 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f, numTotalFramesCaught(0), numFramesCaught(0), currentFrameIndex(0), - ctbType(ct), - ctbDigitalOffset(cdo), - ctbAnalogDataBytes(cad), rawDataReadyCallBack(nullptr), rawDataModifyReadyCallBack(nullptr), - ctbRawDataReadyCallBack(nullptr), pRawDataReady(nullptr) { if(ThreadObject::CreateThread() == FAIL) @@ -356,6 +355,11 @@ void DataProcessor::ProcessAnImage(char* buf) { else if (!(*activated) && *deactivatedPaddingEnable) PadMissingPackets(buf); + // rearrange ctb digital bits (if ctbDbitlist is not empty) + if (!(*ctbDbitList).empty()) { + RearrangeDbitData(buf); + } + // normal call back if (rawDataReadyCallBack) { rawDataReadyCallBack( @@ -376,20 +380,6 @@ void DataProcessor::ProcessAnImage(char* buf) { (*((uint32_t*)buf)) = revsize; } - // ctb call back - else if (ctbRawDataReadyCallBack) { - uint32_t revsize = (uint32_t)(*((uint32_t*)buf)); - ctbRawDataReadyCallBack( - (char*)rheader, - buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header), - revsize, - *ctbType, - *ctbDigitalOffset, - *ctbAnalogDataBytes, - pRawDataReady); - (*((uint32_t*)buf)) = revsize; - } - // write to file if (file) @@ -397,8 +387,6 @@ void DataProcessor::ProcessAnImage(char* buf) { sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)), //+ size of data (resizable from previous call back fnum-firstMeasurementIndex, nump); - - } @@ -464,12 +452,6 @@ void DataProcessor::registerCallBackRawDataModifyReady(void (*func)(char* , pRawDataReady=arg; } -void DataProcessor::registerCallBackCTBReceiverReady(void (*func)(char* , - char*, uint32_t&, int, int, int, void*),void *arg) { - ctbRawDataReadyCallBack=func; - pRawDataReady=arg; -} - void DataProcessor::PadMissingPackets(char* buf) { FILE_LOG(logDEBUG) << index << ": Padding Missing Packets"; @@ -519,6 +501,45 @@ void DataProcessor::PadMissingPackets(char* buf) { } } +/** ctb specific */ +void DataProcessor::RearrangeDbitData(char* buf) { + int totalSize = (int)(*((uint32_t*)buf)); + int ctbDigitalDataBytes = totalSize - (*ctbAnalogDataBytes) - (*ctbDbitOffset); + + // no digital data + if (!ctbDigitalDataBytes) { + FILE_LOG(logWARNING) << "No digital data for call back, yet dbitlist is not empty."; + return; + } + + const int numSamples = (ctbDigitalDataBytes / sizeof(uint64_t)); + + // ceil as numResult64Bytes could be decimal + const int numResult64Bytes = ceil((double)(numSamples * (*ctbDbitList).size()) / 64.00); + std::vector result(numResult64Bytes, 0); + + auto dest = result.data(); + const int digOffset = FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header) + (*ctbAnalogDataBytes) + (*ctbDbitOffset); + auto source = (uint64_t*)(buf + digOffset); + + // loop through digital bit enable vector + for (auto bi : (*ctbDbitList)) { + // loop through the frame digital data + for (auto ptr = source; ptr < (source + numSamples);) { + // extract destination in 64 bit batches + for (int i = 0; i != 64; ++i) { + // get selected bit from each 64 bit + int bit = (*ptr++ >> bi) & 1; + *dest |= bit << i; + } + ++dest; + } + } + + // copy back to buf and update size + memcpy(source + digOffset, result.data(), result.size() * sizeof(uint64_t)); + (*((uint32_t*)buf)) = result.size() * sizeof(uint64_t); +} /** eiger specific */ void DataProcessor::InsertGapPixels(char* buf, uint32_t dr) { diff --git a/slsReceiverSoftware/src/mainCustomized.cpp b/slsReceiverSoftware/src/mainCustomized.cpp deleted file mode 100755 index 360da811f..000000000 --- a/slsReceiverSoftware/src/mainCustomized.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* A simple server in the internet domain using TCP - The port number is passed as an argument */ - -#include "sls_detector_defs.h" -#include "slsReceiverUsers.h" -#include "logger.h" - -#include -#include -#include //SIGINT -#include //system -#include //wait -#include //wait -#include //usleep -#include -#include -#include - -bool keeprunning; -int ctbOffset = 0; -bool printData = false; - -void sigInterruptHandler(int p){ - keeprunning = false; -} - - -#ifdef MYTHEN302 -void GetData(char* metadata, char* datapointer, uint32_t& datasize, - int ctbType, int ctbDigitalOffset, int ctbAnalogDataBytes, void* p) { - - // only analog data - if (ctbAnalogDataBytes == (int)datasize) { - FILE_LOG(logWARNING) << "No digital data for call back. Remove this unnecessary call back."; - return; - } - - constexpr int dynamicRange = 24; - constexpr int numSamples = 32 * 3; // 32 channels * 3 counters = 96 - constexpr int numCounters = numSamples * 2; // 2 strips - // validate datasize - { - FILE_LOG(logDEBUG) << "Datasize:" << datasize; - int wordsCaught = ((datasize - ctbAnalogDataBytes) / sizeof(uint64_t)) - ctbOffset; - int expectedWordSize = numSamples * dynamicRange; - if (expectedWordSize != wordsCaught) { - FILE_LOG(logWARNING) << "Number of words do not match, Expected " - << expectedWordSize << ", got " << wordsCaught; - } - } - - // source - uint64_t* ptr = (uint64_t*)(datapointer + ctbAnalogDataBytes); - // remove the offset from source - ptr += ctbOffset; - // destination - auto result = new int[numCounters]; - memset((char*)result, 0, numCounters * sizeof(int)); - auto strip0 = result; - auto strip1 = strip0 + numSamples; - constexpr int bit_index0 = 17; - constexpr int bit_index1 = 6; - FILE_LOG(logINFO) << "Bits (" << bit_index0 << ", " << bit_index1 << ")"; - constexpr int mask0 = (1 << bit_index0); - constexpr int mask1 = (1 << bit_index1); - - for (int j = 0; j < numSamples; ++j) { - for (int i = 0; i < dynamicRange; ++i) { - int bit0 = (*ptr & mask0) >> bit_index0; - int bit1 = (*ptr++ & mask1) >> bit_index1; - *strip0 |= bit0 << i; - *strip1 |= bit1 << i; - } - strip0++; - strip1++; - } - - if (printData) { - slsDetectorDefs::sls_receiver_header* header = (slsDetectorDefs::sls_receiver_header*)metadata; - slsDetectorDefs::sls_detector_header detectorHeader = header->detHeader; - FILE_LOG(logINFO) << "Frame Number: " << detectorHeader.frameNumber; - for (int i = 0; i < numCounters; ++i) { - cprintf(MAGENTA, "%d:%u\t", i, result[i]); - } - std::cout << std::endl; - } - - // update the size to be written to file & overwrite data in memory - datasize = numCounters * sizeof(int); - memcpy(datapointer + ctbAnalogDataBytes, (char*)result, datasize); - delete[] result; - datasize += ctbAnalogDataBytes; - FILE_LOG(logDEBUG) << "Modified Size: " << datasize; -} -#endif - - -int main(int argc, char *argv[]) { - - // options - std::map configuration_map; - //parse command line for config - static struct option long_options[] = { - {"ctb_offset", required_argument, nullptr, 'o'}, - {"print_data", no_argument, nullptr, 'p'}, - {nullptr, 0, nullptr, 0} - }; - //initialize global optind variable (required when instantiating multiple receivers in the same process) - optind = 1; - // getopt_long stores the option index here. - int option_index = 0; - int c = 0; - while ( c != -1 ) { - c = getopt_long (argc, argv, "hvf:t:o:p", long_options, &option_index); - // Detect the end of the options. - if (c == -1) - break; - switch(c) { - case 'o': - sscanf(optarg, "%d", &ctbOffset); - break; - case 'p': - printData = true; - break; - default: - break; - } - } - -#ifdef MYTHEN302 - FILE_LOG(logINFOGREEN) << "Mythen 302 Receiver"; - FILE_LOG(logINFO) << "CTB Offset: " << ctbOffset; - FILE_LOG(logINFO) << "Print Data: " << printData; -#endif - - keeprunning = true; - FILE_LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]"; - - // 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) { - FILE_LOG(logERROR) << "Could not set handler function for SIGINT"; - } - - - // if socket crash, ignores SISPIPE, prevents global signal handler - // subsequent read/write to socket gives error - must handle locally - 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) { - FILE_LOG(logERROR) << "Could not set handler function for SIGPIPE"; - } - - int ret = slsDetectorDefs::OK; - slsReceiverUsers *receiver = new slsReceiverUsers(argc, argv, ret); - if(ret==slsDetectorDefs::FAIL){ - delete receiver; - FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; - exit(EXIT_FAILURE); - } - - - //register callbacks - receiver->registerCallBackCTBReceiverReady(GetData, NULL); - - //start tcp server thread - if (receiver->start() == slsDetectorDefs::FAIL){ - delete receiver; - FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; - exit(EXIT_FAILURE); - } - - FILE_LOG(logINFO) << "Ready ... "; - FILE_LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]"; - while(keeprunning) - pause(); - - delete receiver; - FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; - FILE_LOG(logINFO) << "Exiting Receiver"; - return 0; -} - diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index d6d9ae45b..d9b5855c1 100755 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -44,17 +44,13 @@ slsReceiver::slsReceiver(int argc, char *argv[]): int c = 0; while ( c != -1 ){ - c = getopt_long (argc, argv, "hvf:t:o:p", long_options, &option_index); + c = getopt_long (argc, argv, "hvf:t:", long_options, &option_index); // Detect the end of the options. if (c == -1) break; switch(c){ - // reserved for ctb receiver users - case 'o': - case 'p': - break; case 't': sscanf(optarg, "%d", &tcpip_port_no); @@ -113,7 +109,6 @@ void slsReceiver::registerCallBackStartAcquisition(int (*func)( } - void slsReceiver::registerCallBackAcquisitionFinished( void (*func)(uint64_t, void*),void *arg){ tcpipInterface->registerCallBackAcquisitionFinished(func,arg); @@ -131,8 +126,3 @@ void slsReceiver::registerCallBackRawDataModifyReady(void (*func)(char*, tcpipInterface->registerCallBackRawDataModifyReady(func,arg); } - -void slsReceiver::registerCallBackCTBReceiverReady(void (*func)(char* , - char*, uint32_t &, int, int, int, void*),void *arg){ - tcpipInterface->registerCallBackCTBReceiverReady(func,arg); -} diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index 874785edb..7bb1bd238 100755 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -46,6 +46,7 @@ void slsReceiverImplementation::DeleteMembers() { dataProcessor.clear(); dataStreamer.clear(); fifo.clear(); + ctbDbitList.clear(); } @@ -80,6 +81,8 @@ void slsReceiverImplementation::InitializeMembers() { frameDiscardMode = NO_DISCARD; framePadding = false; silentMode = false; + ctbDbitOffset = 0; + ctbAnalogDataBytes = 0; //***connection parameters*** numUDPInterfaces = 1; @@ -113,11 +116,6 @@ void slsReceiverImplementation::InitializeMembers() { //** class objects *** generalData = nullptr; - //** ctb callback parameters - ctbType = 0; - ctbDigitalOffset = 0; - ctbAnalogDataBytes = 0; - //***callback parameters*** startAcquisitionCallBack = nullptr; pStartAcquisition = nullptr; @@ -125,7 +123,6 @@ void slsReceiverImplementation::InitializeMembers() { pAcquisitionFinished = nullptr; rawDataReadyCallBack = nullptr; rawDataModifyReadyCallBack = nullptr; - ctbRawDataReadyCallBack = nullptr; pRawDataReady = nullptr; } @@ -383,6 +380,16 @@ bool slsReceiverImplementation::getSilentMode() const{ return silentMode; } +std::vector slsReceiverImplementation::getDbitList() const{ + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return ctbDbitList; +} + +int slsReceiverImplementation::getDbitOffset() const{ + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + return ctbDbitOffset; +} + bool slsReceiverImplementation::getActivate() const{ FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; return activated; @@ -703,7 +710,7 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) { fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &streamingFrequency, &streamingTimerInMs, &framePadding, &activated, &deactivatedPaddingEnable, &silentMode, - &ctbType, &ctbDigitalOffset, &ctbAnalogDataBytes)); + &ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes)); dataProcessor[i]->SetGeneralData(generalData); } catch (...) { @@ -748,10 +755,6 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) { for (const auto& it : dataProcessor) it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); } - if(ctbRawDataReadyCallBack) { - for (const auto& it : dataProcessor) - it->registerCallBackCTBReceiverReady(ctbRawDataReadyCallBack,pRawDataReady); - } // test socket buffer size with current set up if (setUDPSocketBufferSize(0) == FAIL) { @@ -1088,6 +1091,17 @@ void slsReceiverImplementation::setSilentMode(const bool i) { FILE_LOG(logINFO) << "Silent Mode: " << i; } +void slsReceiverImplementation::setDbitList(const std::vector v) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + ctbDbitList = v; +} + +void slsReceiverImplementation::setDbitOffset(const int s) { + FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; + ctbDbitOffset = s; +} + + /************************************************************************* * Behavioral functions*************************************************** @@ -1148,7 +1162,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) { fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &streamingFrequency, &streamingTimerInMs, &framePadding, &activated, &deactivatedPaddingEnable, &silentMode, - &ctbType, &ctbDigitalOffset, &ctbAnalogDataBytes)); + &ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes)); } catch (...) { FILE_LOG(logERROR) << "Could not create listener/dataprocessor threads (index:" << i << ")"; @@ -1434,15 +1448,6 @@ void slsReceiverImplementation::registerCallBackRawDataModifyReady(void (*func)( } -void slsReceiverImplementation::registerCallBackCTBReceiverReady(void (*func)(char* , - char*, uint32_t&, int, int, int, void*),void *arg) { - ctbRawDataReadyCallBack=func; - pRawDataReady=arg; - for (const auto& it : dataProcessor) - it->registerCallBackCTBReceiverReady(ctbRawDataReadyCallBack,pRawDataReady); -} - - void slsReceiverImplementation::SetLocalNetworkParameters() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 602814fa3..41a728425 100755 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -53,7 +53,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int pn): pAcquisitionFinished = nullptr; rawDataReadyCallBack = nullptr; rawDataModifyReadyCallBack = nullptr; - ctbRawDataReadyCallBack = nullptr; pRawDataReady = nullptr; // create socket @@ -131,12 +130,6 @@ void slsReceiverTCPIPInterface::registerCallBackRawDataModifyReady(void (*func)( pRawDataReady=arg; } -void slsReceiverTCPIPInterface::registerCallBackCTBReceiverReady(void (*func)(char* , - char*, uint32_t &, int, int, int, void*),void *arg){ - ctbRawDataReadyCallBack=func; - pRawDataReady=arg; -} - void* slsReceiverTCPIPInterface::startTCPServerThread(void *this_pointer){ ((slsReceiverTCPIPInterface*)this_pointer)->startTCPServer(); return this_pointer; @@ -231,9 +224,12 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_RECEIVER_CHECK_VERSION] = &slsReceiverTCPIPInterface::check_version_compatibility; flist[F_RECEIVER_DISCARD_POLICY] = &slsReceiverTCPIPInterface::set_discard_policy; flist[F_RECEIVER_PADDING_ENABLE] = &slsReceiverTCPIPInterface::set_padding_enable; - flist[F_RECEIVER_DEACTIVATED_PADDING_ENABLE] = &slsReceiverTCPIPInterface::set_deactivated_receiver_padding_enable; + flist[F_RECEIVER_DEACTIVATED_PADDING_ENABLE] = &slsReceiverTCPIPInterface::set_deactivated_padding_enable; flist[F_RECEIVER_SET_READOUT_FLAGS] = &slsReceiverTCPIPInterface::set_readout_flags; flist[F_RECEIVER_SET_ADC_MASK] = &slsReceiverTCPIPInterface::set_adc_mask; + flist[F_SET_RECEIVER_DBIT_LIST] = &slsReceiverTCPIPInterface::set_dbit_list; + flist[F_GET_RECEIVER_DBIT_LIST] = &slsReceiverTCPIPInterface::get_dbit_list; + flist[F_RECEIVER_DBIT_OFFSET] = &slsReceiverTCPIPInterface::set_dbit_offset; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { FILE_LOG(logDEBUG1) << "function fnum: " << i << " (" << @@ -556,6 +552,20 @@ int slsReceiverTCPIPInterface::send_update() { i32=(int)receiver->getSilentMode(); n += mySock->SendDataOnly(&i32, sizeof(i32)); + // dbit list + { + std::vector list = receiver->getDbitList(); + int retvalsize = list.size(); + int retval[retvalsize]; + std::copy(std::begin(list), std::end(list), retval); + mySock->SendDataOnly(&retvalsize, sizeof(retvalsize)); + mySock->SendDataOnly(retval, sizeof(retval)); + } + + // dbit offset + i32=receiver->getDbitOffset(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); + if (!lockStatus) strcpy(mySock->lastClientIP, mySock->thisClientIP); @@ -621,8 +631,6 @@ int slsReceiverTCPIPInterface::set_detector_type(){ receiver->registerCallBackRawDataReady(rawDataReadyCallBack,pRawDataReady); if(rawDataModifyReadyCallBack) receiver->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); - if(ctbRawDataReadyCallBack) - receiver->registerCallBackCTBReceiverReady(ctbRawDataReadyCallBack, pRawDataReady); // client has started updating receiver, update ip if (!lockStatus) @@ -2030,7 +2038,7 @@ int slsReceiverTCPIPInterface::set_padding_enable() { -int slsReceiverTCPIPInterface::set_deactivated_receiver_padding_enable() { +int slsReceiverTCPIPInterface::set_deactivated_padding_enable() { ret = OK; memset(mess, 0, sizeof(mess)); int enable = -1; @@ -2123,5 +2131,100 @@ int slsReceiverTCPIPInterface::set_adc_mask() { } FILE_LOG(logDEBUG1) << "ADC enable mask retval: " << retval; } - return interface->Server_SendResult(false, ret, &retval, sizeof(retval), mess); + return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); +} + + + +int slsReceiverTCPIPInterface::set_dbit_list() { + ret = OK; + memset(mess, 0, sizeof(mess)); + + // receive arguments + int narg = -1; + if (mySock->ReceiveDataOnly(&narg,sizeof(narg)) < 0 ) + return interface->Server_SocketCrash(); + int narglist[narg]; + if (mySock->ReceiveDataOnly(narglist, narg * sizeof(int)) < 0 ) + return interface->Server_SocketCrash(); + std::vector arg(narglist, narglist + narg); + + FILE_LOG(logDEBUG1) << "Setting DBIT list"; + for (auto &it : arg) { + FILE_LOG(logDEBUG1) << it << " "; + } + FILE_LOG(logDEBUG1) << "\n"; + + // base object not null + if (receiver == nullptr) + interface->Server_NullObjectError(ret, mess); + else { + // only set + // verify if receiver is unlocked and idle + if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + if (arg.size() > 64) { + ret = FAIL; + sprintf(mess, "Could not set dbit list as size is > 64\n"); + FILE_LOG(logERROR) << mess; + } else + receiver->setDbitList(arg); + } + } + + return interface->Server_SendResult(true, ret, nullptr, 0, mess); +} + + + +int slsReceiverTCPIPInterface::get_dbit_list() { + ret = OK; + memset(mess, 0, sizeof(mess)); + std::vector list; + + // no arg, check receiver is null + interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver); + + // base object not null + if (ret == OK) { + // get + list = receiver->getDbitList(); + FILE_LOG(logDEBUG1) << "Dbit list size retval:" << list.size(); + } + + interface->Server_SendResult(false, ret, nullptr, 0, mess); + int retvalsize = list.size(); + int retval[retvalsize]; + std::copy(std::begin(list), std::end(list), retval); + mySock->SendDataOnly(&retvalsize, sizeof(retvalsize)); + mySock->SendDataOnly(retval, sizeof(retval)); + return ret; +} + + +int slsReceiverTCPIPInterface::set_dbit_offset() { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + int retval = -1; + + // get args, return if socket crashed, ret is fail if receiver is not null + if (interface->Server_ReceiveArg(ret, mess, &arg, sizeof(arg), true, receiver) == FAIL) + return FAIL; + + // base object not null + else if (ret == OK) { + // set + if (arg >= 0) { + // verify if receiver is unlocked and idle + if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG1) << "Setting Dbit offset: " << arg; + receiver->setDbitOffset(arg); + } + } + // get + retval = receiver->getDbitOffset(); + validate(arg, retval, std::string("set dbit offset"), DEC); + FILE_LOG(logDEBUG1) << "Dbit offset retval: " << retval; + } + return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } \ No newline at end of file diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index 81343d093..3ce3c00f1 100755 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -46,8 +46,3 @@ void slsReceiverUsers::registerCallBackRawDataModifyReady(void (*func)(char* hea receiver->registerCallBackRawDataModifyReady(func,arg); } -void slsReceiverUsers::registerCallBackCTBReceiverReady(void (*func)(char* header, - char* datapointer, uint32_t& revDatasize, - int type, int digitalOffset, int analogDataBytes, void*), void *arg){ - receiver->registerCallBackCTBReceiverReady(func,arg); -} diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index 95f7340c0..4b8ecb509 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -83,6 +83,10 @@ enum detFuncs{ F_REBOOT_CONTROLLER, /** < reboot detector controller (blackfin/ powerpc) */ F_SET_ADC_ENABLE_MASK, /** < setting ADC enable mask */ F_GET_ADC_ENABLE_MASK, /** < setting ADC enable mask */ + F_SET_ADC_INVERT, /** < set adc invert reg */ + F_GET_ADC_INVERT, /** < get adc invert reg */ + F_EXTERNAL_SAMPLING_SOURCE, /** < set/get external sampling source for ctb */ + F_EXTERNAL_SAMPLING, /**< enable/disable external sampling for ctb */ NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 128, /**< detector function should not exceed this (detector server should not compile anyway) */ @@ -137,6 +141,9 @@ enum detFuncs{ F_RECEIVER_DEACTIVATED_PADDING_ENABLE, /** < deactivated receiver padding enable */ F_RECEIVER_SET_READOUT_FLAGS, /**< set/get receiver readout flags */ F_RECEIVER_SET_ADC_MASK, /**< set adc mask */ + F_SET_RECEIVER_DBIT_LIST, /** < set receiver digital bit list */ + F_GET_RECEIVER_DBIT_LIST, /** < get receiver digital bit list */ + F_RECEIVER_DBIT_OFFSET, /** < set/get reciever digital bit offset */ NUM_REC_FUNCTIONS }; @@ -216,6 +223,10 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_REBOOT_CONTROLLER: return "F_REBOOT_CONTROLLER"; case F_SET_ADC_ENABLE_MASK: return "F_SET_ADC_ENABLE_MASK"; case F_GET_ADC_ENABLE_MASK: return "F_GET_ADC_ENABLE_MASK"; + case F_SET_ADC_INVERT: return "F_SET_ADC_INVERT"; + case F_GET_ADC_INVERT: return "F_GET_ADC_INVERT"; + case F_EXTERNAL_SAMPLING_SOURCE: return "F_EXTERNAL_SAMPLING_SOURCE"; + case F_EXTERNAL_SAMPLING: return "F_EXTERNAL_SAMPLING"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; @@ -271,6 +282,10 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RECEIVER_DEACTIVATED_PADDING_ENABLE: return "F_RECEIVER_DEACTIVATED_PADDING_ENABLE"; case F_RECEIVER_SET_READOUT_FLAGS: return "F_RECEIVER_SET_READOUT_FLAGS"; case F_RECEIVER_SET_ADC_MASK: return "F_RECEIVER_SET_ADC_MASK"; + case F_SET_RECEIVER_DBIT_LIST: return "F_SET_RECEIVER_DBIT_LIST"; + case F_GET_RECEIVER_DBIT_LIST: return "F_GET_RECEIVER_DBIT_LIST"; + case F_RECEIVER_DBIT_OFFSET: return "F_RECEIVER_DBIT_OFFSET"; + case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; default: return "Unknown Function"; } diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 1b40940b2..dcbd57bee 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -7,4 +7,4 @@ #define APIRECEIVER 0x190405 #define APIGUI 0x190405 #define APIEIGER 0x190418 -#define APICTB 0x190430 +#define APICTB 0x190503