From 990008c9d9d36e611b309775ebe8a430ea937f8d Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 23 Apr 2020 12:20:04 +0200 Subject: [PATCH] WIP --- slsDetectorSoftware/src/Detector.cpp | 94 +++-- slsDetectorSoftware/src/DetectorImpl.cpp | 4 +- slsDetectorSoftware/src/Module.cpp | 292 +-------------- slsDetectorSoftware/src/Module.h | 91 +---- slsDetectorSoftware/src/Receiver.cpp | 376 +++++++++++++------- slsDetectorSoftware/src/Receiver.h | 40 ++- slsReceiverSoftware/src/ClientInterface.cpp | 150 +++++--- slsReceiverSoftware/src/ClientInterface.h | 1 + slsSupportLib/include/sls_detector_funcs.h | 10 +- 9 files changed, 464 insertions(+), 594 deletions(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 10b90f9e2..c6a2dcb62 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -252,6 +252,7 @@ Result Detector::getPeriod(Positions pos) const { void Detector::setPeriod(ns t, Positions pos) { pimpl->Parallel(&Module::setPeriod, pos, t.count()); + pimpl->Parallel3(&Receiver::setPeriod, t.count()); } Result Detector::getDelayAfterTrigger(Positions pos) const { @@ -849,17 +850,16 @@ void Detector::setPartialFramesPadding(bool value, Positions pos) { } Result Detector::getRxUDPSocketBufferSize(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverUDPSocketBufferSize, pos); + return pimpl->Parallel3(&Receiver::getUDPSocketBufferSize); } void Detector::setRxUDPSocketBufferSize(int64_t udpsockbufsize, Positions pos) { - pimpl->Parallel(&Module::setReceiverUDPSocketBufferSize, pos, + pimpl->Parallel3(&Receiver::setUDPSocketBufferSize, udpsockbufsize); } Result Detector::getRxRealUDPSocketBufferSize(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverRealUDPSocketBufferSize, - pos); + return pimpl->Parallel3(&Receiver::getRealUDPSocketBufferSize); } Result Detector::getRxLock(Positions pos) { @@ -967,28 +967,28 @@ void Detector::setRxZmqTimer(int time_in_ms, Positions pos) { } Result Detector::getRxZmqPort(Positions pos) const { - return pimpl->Parallel1(&Receiver::getReceiverZmqPort, pos, {}); + return pimpl->Parallel1(&Receiver::getZmqPort, pos, {}); } void Detector::setRxZmqPort(int port, int module_id) { if (module_id == -1) { for (int idet = 0; idet < size(); ++idet) { - pimpl->Parallel1(&Receiver::setReceiverZmqPort, {idet}, + pimpl->Parallel1(&Receiver::setZmqPort, {idet}, {}, port++); } } else { - pimpl->Parallel1(&Receiver::setReceiverZmqPort, {module_id}, + pimpl->Parallel1(&Receiver::setZmqPort, {module_id}, {}, port++); } } Result Detector::getRxZmqIP(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverStreamingIP, pos); + return pimpl->Parallel3(&Receiver::getZmqIP); } void Detector::setRxZmqIP(const IpAddr ip, Positions pos) { bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(false); - pimpl->Parallel(&Module::setReceiverStreamingIP, pos, ip); + pimpl->Parallel3(&Receiver::setZmqIP, ip); if (previouslyReceiverStreaming) { setRxZmqDataStream(false, pos); setRxZmqDataStream(true, pos); @@ -1012,12 +1012,12 @@ void Detector::setClientZmqPort(int port, int module_id) { } Result Detector::getClientZmqIp(Positions pos) const { - return pimpl->Parallel(&Module::getClientStreamingIP, pos); + return pimpl->Parallel3(&Receiver::getClientZmqIP); } void Detector::setClientZmqIp(const IpAddr ip, Positions pos) { int previouslyClientStreaming = pimpl->enableDataStreamingToClient(-1); - pimpl->Parallel(&Module::setClientStreamingIP, pos, ip); + pimpl->Parallel3(&Receiver::setClientZmqIP, ip); if (previouslyClientStreaming != 0) { pimpl->enableDataStreamingToClient(0); pimpl->enableDataStreamingToClient(1); @@ -1085,12 +1085,30 @@ void Detector::setSubDeadTime(ns value, Positions pos) { } Result Detector::getThresholdEnergy(Positions pos) const { + if (getDetectorType().squash() == defs::MOENCH) { + auto res = getAdditionalJsonParameter("threshold", pos); + Result intResult(res.size()); + try { + for (unsigned int i = 0; i < res.size(); ++i) { + intResult[i] = stoi(res[i]); + } + } catch (...) { + throw RuntimeError( + "Cannot find or convert threshold string to integer"); + } + return intResult; + } + return pimpl->Parallel(&Module::getThresholdEnergy, pos); } void Detector::setThresholdEnergy(int threshold_ev, defs::detectorSettings settings, bool trimbits, Positions pos) { + if (getDetectorType().squash() == defs::MOENCH) { + setAdditionalJsonParameter("threshold", + std::to_string(threshold_ev), pos); + } pimpl->Parallel(&Module::setThresholdEnergy, pos, threshold_ev, settings, static_cast(trimbits)); } @@ -1193,11 +1211,12 @@ Result Detector::getMeasuredSubFramePeriod(Positions pos) const { } Result Detector::getActive(Positions pos) const { - return pimpl->Parallel(&Module::activate, pos, -1); + return pimpl->Parallel(&Module::getActivate, pos); } void Detector::setActive(bool active, Positions pos) { - pimpl->Parallel(&Module::activate, pos, static_cast(active)); + pimpl->Parallel(&Module::setActivate, pos, active); + pimpl->Parallel3(&Receiver::setActivate, active); } Result Detector::getRxPadDeactivatedMode(Positions pos) const { @@ -1321,11 +1340,16 @@ void Detector::setROI(defs::ROI value, int module_id) { if (module_id < 0 && size() > 1) { throw RuntimeError("Cannot set ROI for all modules simultaneously"); } + if (value.xmin < 0 || value.xmax >= getModuleSize({module_id})[0].x) { + throw RuntimeError("roi arguments out of range"); + } pimpl->Parallel(&Module::setROI, {module_id}, value); + pimpl->Parallel3(&Receiver::setROI, value); } void Detector::clearROI(Positions pos) { pimpl->Parallel(&Module::clearROI, pos); + pimpl->Parallel3(&Receiver::clearROI); } Result Detector::getExptimeLeft(Positions pos) const { @@ -1388,6 +1412,7 @@ Result Detector::getBurstMode(Positions pos) { void Detector::setBurstMode(defs::burstMode value, Positions pos) { pimpl->Parallel(&Module::setBurstMode, pos, value); + pimpl->Parallel3(&Receiver::setBurstMode, value); } Result Detector::getCurrentSource(Positions pos) const { @@ -1502,7 +1527,11 @@ Result Detector::getADCEnableMask(Positions pos) const { } void Detector::setADCEnableMask(uint32_t mask, Positions pos) { + if (getDetectorType().squash() == defs::MOENCH) { + setAdditionalJsonParameter("adcmask_1g", std::to_string(mask), pos); + } pimpl->Parallel(&Module::setADCEnableMask, pos, mask); + pimpl->Parallel3(&Receiver::setADCEnableMask, mask); } Result Detector::getTenGigaADCEnableMask(Positions pos) const { @@ -1510,7 +1539,11 @@ Result Detector::getTenGigaADCEnableMask(Positions pos) const { } void Detector::setTenGigaADCEnableMask(uint32_t mask, Positions pos) { + if (getDetectorType().squash() == defs::MOENCH) { + setAdditionalJsonParameter("adcmask_10g", std::to_string(mask), pos); + } pimpl->Parallel(&Module::setTenGigaADCEnableMask, pos, mask); + pimpl->Parallel3(&Receiver::setTenGigaADCEnableMask, mask); } // CTB Specific @@ -1603,19 +1636,19 @@ void Detector::setExternalSampling(bool value, Positions pos) { } Result> Detector::getRxDbitList(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverDbitList, pos); + return pimpl->Parallel3(&Receiver::getDbitList); } void Detector::setRxDbitList(const std::vector& list, Positions pos) { - pimpl->Parallel(&Module::setReceiverDbitList, pos, list); + pimpl->Parallel3(&Receiver::setDbitList, list); } Result Detector::getRxDbitOffset(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverDbitOffset, pos); + return pimpl->Parallel3(&Receiver::getDbitOffset); } void Detector::setRxDbitOffset(int value, Positions pos) { - pimpl->Parallel(&Module::setReceiverDbitOffset, pos, value); + pimpl->Parallel3(&Receiver::setDbitOffset, value); } void Detector::setDigitalIODelay(uint64_t pinMask, int delay, Positions pos) { @@ -1757,28 +1790,27 @@ void Detector::setPatternBitMask(uint64_t mask, Positions pos) { // Moench Result> Detector::getAdditionalJsonHeader(Positions pos) const { - return pimpl->Parallel(&Module::getAdditionalJsonHeader, pos); + return pimpl->Parallel3(&Receiver::getAdditionalJsonHeader); } void Detector::setAdditionalJsonHeader(const std::map &jsonHeader, Positions pos) { - pimpl->Parallel(&Module::setAdditionalJsonHeader, pos, jsonHeader); + pimpl->Parallel3(&Receiver::setAdditionalJsonHeader, jsonHeader); } Result Detector::getAdditionalJsonParameter(const std::string &key, Positions pos) const { - return pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, key); + return pimpl->Parallel3(&Receiver::getAdditionalJsonParameter, key); } void Detector::setAdditionalJsonParameter(const std::string &key, const std::string &value, Positions pos) { - pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, key, value); + pimpl->Parallel3(&Receiver::setAdditionalJsonParameter, key, value); } Result Detector::getDetectorMinMaxEnergyThreshold(const bool isEmax, Positions pos) const { - auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, - isEmax ? "emax" : "emin"); + auto res = getAdditionalJsonParameter(isEmax ? "emax" : "emin", pos); Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { @@ -1794,13 +1826,12 @@ Result Detector::getDetectorMinMaxEnergyThreshold(const bool isEmax, void Detector::setDetectorMinMaxEnergyThreshold(const bool isEmax, const int value, Positions pos) { - pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, - isEmax ? "emax" : "emin", std::to_string(value)); + setAdditionalJsonParameter(isEmax ? "emax" : "emin", + std::to_string(value), pos); } Result Detector::getFrameMode(Positions pos) const { - auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, - "frameMode"); + auto res = getAdditionalJsonParameter("frameMode", pos); Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { @@ -1815,13 +1846,11 @@ Result Detector::getFrameMode(Positions pos) const { } void Detector::setFrameMode(defs::frameModeType value, Positions pos) { - pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, "frameMode", - sls::ToString(value)); + setAdditionalJsonParameter("frameMode", sls::ToString(value), pos); } Result Detector::getDetectorMode(Positions pos) const { - auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, - "detectorMode"); + auto res = getAdditionalJsonParameter("detectorMode", pos); Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { @@ -1836,8 +1865,7 @@ Result Detector::getDetectorMode(Positions pos) const { } void Detector::setDetectorMode(defs::detectorModeType value, Positions pos) { - pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, - "detectorMode", sls::ToString(value)); + setAdditionalJsonParameter("detectorMode", sls::ToString(value), pos); } // Advanced diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 98d99dfc6..a3546a300 100755 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -619,8 +619,8 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) { portnum += (iSocket % numSocketsPerDetector); try { zmqSocket.push_back(sls::make_unique( - detectors[iSocket / numSocketsPerDetector] - ->getClientStreamingIP() + receivers[iSocket / numSocketsPerDetector][0] + ->getClientZmqIP() .str() .c_str(), portnum)); diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 2b52a8cfa..549847a7f 100755 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -746,22 +746,6 @@ void Module::setSettings(detectorSettings isettings) { } int Module::getThresholdEnergy() { - // moench - get threshold energy from processor (due to different clients, - // diff shm) - if (shm()->myDetectorType == MOENCH) { - // get json from rxr, parse for threshold and update shm - getAdditionalJsonHeader(); - std::string result = getAdditionalJsonParameter("threshold"); - // convert to integer - try { - return std::stoi(result); - } - // not found or cannot scan integer - catch (...) { - return -1; - } - } - LOG(logDEBUG1) << "Getting threshold energy"; int retval = -1; sendToDetector(F_GET_THRESHOLD_ENERGY, nullptr, retval); @@ -771,18 +755,10 @@ int Module::getThresholdEnergy() { void Module::setThresholdEnergy(int e_eV, detectorSettings isettings, int tb) { - // check as there is client processing if (shm()->myDetectorType == EIGER) { setThresholdEnergyAndSettings(e_eV, isettings, tb); - } - - // moench - send threshold energy to processor - else if (shm()->myDetectorType == MOENCH) { - setAdditionalJsonParameter("threshold", std::to_string(e_eV)); - } - - else { + } else { throw RuntimeError( "Set threshold energy not implemented for this detector"); } @@ -1077,10 +1053,6 @@ int64_t Module::getPeriod() { void Module::setPeriod(int64_t value) { LOG(logDEBUG1) << "Setting period to " << value << "ns"; sendToDetector(F_SET_PERIOD, value, nullptr); - if (shm()->useReceiver) { - LOG(logDEBUG1) << "Sending period to Receiver: " << value; - sendToReceiver(F_RECEIVER_SET_PERIOD, value, nullptr); - } } int64_t Module::getDelayAfterTrigger() { @@ -1553,9 +1525,6 @@ void Module::setNumberofUDPInterfaces(int n) { LOG(logDEBUG1) << "Setting number of udp interfaces to " << n; sendToDetector(F_SET_NUM_INTERFACES, n, nullptr); shm()->numUDPInterfaces = n; - if (shm()->useReceiver) { - sendToReceiver(F_SET_RECEIVER_NUM_INTERFACES, n, nullptr); - } } int Module::getNumberofUDPInterfacesFromShm() { @@ -1613,51 +1582,6 @@ std::string Module::printUDPConfiguration() { return oss.str(); } -void Module::setClientStreamingIP(const sls::IpAddr ip) { - LOG(logDEBUG1) << "Setting client zmq ip to " << ip; - if (ip == 0) { - throw RuntimeError("Invalid client zmq ip address"); - } - shm()->zmqip = ip; -} - -sls::IpAddr Module::getClientStreamingIP() { return shm()->zmqip; } - -void Module::setReceiverStreamingIP(const sls::IpAddr ip) { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming ip)"); - } - if (ip == 0) { - throw RuntimeError("Invalid receiver zmq ip address"); - } - - // if client zmqip is empty, update it - if (shm()->zmqip == 0) { - shm()->zmqip = ip; - } - sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr); -} - -sls::IpAddr Module::getReceiverStreamingIP() { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming ip)"); - } - return sendToReceiver(F_GET_RECEIVER_STREAMING_SRC_IP); -} - -void Module::updateReceiverStreamingIP() { - auto ip = getReceiverStreamingIP(); - if (ip == 0) { - // Hostname could be ip try to decode otherwise look up the hostname - ip = sls::IpAddr{shm()->rxHostname}; - if (ip == 0) { - ip = HostnameToIp(shm()->rxHostname); - } - LOG(logINFO) << "Setting default receiver " << moduleId << " streaming zmq ip to " << ip; - } - setReceiverStreamingIP(ip); -} - bool Module::getTenGigaFlowControl() { int retval = -1; sendToDetector(F_GET_TEN_GIGA_FLOW_CONTROL, nullptr, retval); @@ -1707,121 +1631,6 @@ void Module::setTransmissionDelayRight(int value) { sendToDetector(F_SET_TRANSMISSION_DELAY_RIGHT, value, nullptr); } - -void Module::setAdditionalJsonHeader(const std::map &jsonHeader) { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json header)"); - } - for (auto &it : jsonHeader) { - if (it.first.empty() || it.first.length() > SHORT_STR_LENGTH || - it.second.length() > SHORT_STR_LENGTH ) { - throw RuntimeError(it.first + " or " + it.second + " pair has invalid size. " - "Key cannot be empty. Both can have max 20 characters"); - } - } - const int size = jsonHeader.size(); - int fnum = F_SET_ADDITIONAL_JSON_HEADER; - int ret = FAIL; - LOG(logDEBUG) << "Sending to receiver additional json header " << ToString(jsonHeader); - auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); - client.Send(&fnum, sizeof(fnum)); - client.Send(&size, sizeof(size)); - if (size > 0) { - char args[size * 2][SHORT_STR_LENGTH]; - memset(args, 0, sizeof(args)); - int iarg = 0; - for (auto &it : jsonHeader) { - sls::strcpy_safe(args[iarg], it.first.c_str()); - sls::strcpy_safe(args[iarg + 1], it.second.c_str()); - iarg += 2; - } - client.Send(args, sizeof(args)); - } - client.Receive(&ret, sizeof(ret)); - if (ret == FAIL) { - char mess[MAX_STR_LENGTH]{}; - client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Receiver " + std::to_string(moduleId) + - " returned error: " + std::string(mess)); - } -} - -std::map Module::getAdditionalJsonHeader() { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json header)"); - } - int fnum = F_GET_ADDITIONAL_JSON_HEADER; - int ret = FAIL; - int size = 0; - auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); - client.Send(&fnum, sizeof(fnum)); - client.Receive(&ret, sizeof(ret)); - if (ret == FAIL) { - char mess[MAX_STR_LENGTH]{}; - client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Receiver " + std::to_string(moduleId) + - " returned error: " + std::string(mess)); - } else { - client.Receive(&size, sizeof(size)); - std::map retval; - if (size > 0) { - char retvals[size * 2][SHORT_STR_LENGTH]; - memset(retvals, 0, sizeof(retvals)); - client.Receive(retvals, sizeof(retvals)); - for (int i = 0; i < size; ++i) { - retval[retvals[2 * i]] = retvals[2 * i + 1]; - } - } - LOG(logDEBUG) << "Getting additional json header " << ToString(retval); - return retval; - } -} - -void Module::setAdditionalJsonParameter(const std::string &key, const std::string &value) { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json parameter)"); - } - if (key.empty() || key.length() > SHORT_STR_LENGTH || - value.length() > SHORT_STR_LENGTH ) { - throw RuntimeError(key + " or " + value + " pair has invalid size. " - "Key cannot be empty. Both can have max 2 characters"); - } - char args[2][SHORT_STR_LENGTH]{}; - sls::strcpy_safe(args[0], key.c_str()); - sls::strcpy_safe(args[1], value.c_str()); - sendToReceiver(F_SET_ADDITIONAL_JSON_PARAMETER, args, nullptr); -} - -std::string Module::getAdditionalJsonParameter(const std::string &key) { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json parameter)"); - } - char arg[SHORT_STR_LENGTH]{}; - sls::strcpy_safe(arg, key.c_str()); - char retval[SHORT_STR_LENGTH]{}; - sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval); - return retval; -} - -int64_t Module::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize) { - LOG(logDEBUG1) << "Sending UDP Socket Buffer size to receiver: " - << udpsockbufsize; - int64_t retval = -1; - if (shm()->useReceiver) { - sendToReceiver(F_RECEIVER_UDP_SOCK_BUF_SIZE, udpsockbufsize, retval); - LOG(logDEBUG1) << "Receiver UDP Socket Buffer size: " << retval; - } - return retval; -} - -int64_t Module::getReceiverUDPSocketBufferSize() { - return setReceiverUDPSocketBufferSize(); -} - -int64_t Module::getReceiverRealUDPSocketBufferSize() const { - return sendToReceiver(F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE); -} - void Module::executeFirmwareTest() { LOG(logDEBUG1) << "Executing firmware test"; sendToDetector(F_SET_FIRMWARE_TEST); @@ -1984,10 +1793,6 @@ void Module::setBurstMode(slsDetectorDefs::burstMode value) { int arg = static_cast(value); LOG(logDEBUG1) << "Setting burst mode to " << arg; sendToDetector(F_SET_BURST_MODE, arg, nullptr); - if (shm()->useReceiver) { - LOG(logDEBUG1) << "Sending burst mode to Receiver: " << value; - sendToReceiver(F_SET_RECEIVER_BURST_MODE, value, nullptr); - } } bool Module::getCurrentSource() { @@ -2033,18 +1838,10 @@ void Module::clearROI() { } void Module::setROI(slsDetectorDefs::ROI arg) { - if (arg.xmin < 0 || arg.xmax >= getNumberOfChannels().x) { - arg.xmin = -1; - arg.xmax = -1; - } std::array args{arg.xmin, arg.xmax}; LOG(logDEBUG) << "Sending ROI to detector [" << arg.xmin << ", " << arg.xmax << "]"; sendToDetector(F_SET_ROI, args, nullptr); - if (shm()->useReceiver) { - LOG(logDEBUG1) << "Sending ROI to receiver"; - sendToReceiver(F_RECEIVER_SET_ROI, arg, nullptr); - } } slsDetectorDefs::ROI Module::getROI() { @@ -2066,18 +1863,6 @@ void Module::setADCEnableMask(uint32_t mask) { // update #nchan, as it depends on #samples, adcmask, updateNumberOfChannels(); - - // send to processor - if (shm()->myDetectorType == MOENCH) - setAdditionalJsonParameter("adcmask_1g", std::to_string(mask)); - - if (shm()->useReceiver) { - int fnum = F_RECEIVER_SET_ADC_MASK; - int retval = -1; - LOG(logDEBUG1) << "Setting ADC Enable mask to 0x" << std::hex - << mask << std::dec << " in receiver"; - sendToReceiver(fnum, mask, retval); - } } uint32_t Module::getADCEnableMask() { @@ -2096,18 +1881,6 @@ void Module::setTenGigaADCEnableMask(uint32_t mask) { // update #nchan, as it depends on #samples, adcmask, updateNumberOfChannels(); - - // send to processor - if (shm()->myDetectorType == MOENCH) - setAdditionalJsonParameter("adcmask_10g", std::to_string(mask)); - - if (shm()->useReceiver) { - int fnum = F_RECEIVER_SET_ADC_MASK_10G; - int retval = -1; - LOG(logDEBUG1) << "Setting 10Gb ADC Enable mask to 0x" << std::hex - << mask << std::dec << " in receiver"; - sendToReceiver(fnum, mask, retval); - } } uint32_t Module::getTenGigaADCEnableMask() { @@ -2156,49 +1929,6 @@ int Module::setExternalSampling(int value) { int Module::getExternalSampling() { return setExternalSampling(-1); } -void Module::setReceiverDbitList(const std::vector& list) { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit list)"); - } - - 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"); - } - } - sls::FixedCapacityContainer arg = list; - sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); -} - -std::vector Module::getReceiverDbitList() const { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit list)"); - } - sls::FixedCapacityContainer retval; - sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval); - return retval; -} - -void Module::setReceiverDbitOffset(int value) { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit offset)"); - } - sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr); -} - -int Module::getReceiverDbitOffset() { - if (!shm()->useReceiver) { - throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit offset)"); - } - return sendToReceiver(F_GET_RECEIVER_DBIT_OFFSET); -} - void Module::writeAdcRegister(uint32_t addr, uint32_t val) { uint32_t args[]{addr, val}; LOG(logDEBUG1) << "Writing to ADC register 0x" << std::hex << addr @@ -2206,18 +1936,22 @@ void Module::writeAdcRegister(uint32_t addr, uint32_t val) { sendToDetector(F_WRITE_ADC_REG, args, nullptr); } -int Module::activate(int enable) { - int retval = -1; - LOG(logDEBUG1) << "Setting activate flag to " << enable; - sendToDetector(F_ACTIVATE, enable, retval); - sendToDetectorStop(F_ACTIVATE, enable, retval); +bool Module::getActivate() { + int retval = -1, arg = -1; + LOG(logDEBUG1) << "Getting activate flag"; + sendToDetector(F_ACTIVATE, arg, retval); LOG(logDEBUG1) << "Activate: " << retval; - if (shm()->useReceiver) { - sendToReceiver(F_RECEIVER_ACTIVATE, retval, nullptr); - } return retval; } +void Module::setActivate(const bool enable) { + int retval = -1; + int arg = static_cast(enable); + LOG(logDEBUG1) << "Setting activate flag to " << arg; + sendToDetector(F_ACTIVATE, arg, retval); + sendToDetectorStop(F_ACTIVATE, arg, retval); +} + bool Module::getDeactivatedRxrPaddingMode() { if (!shm()->useReceiver) { throw RuntimeError("Set rx_hostname first to use receiver parameters (deactivated padding)"); diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 09c231e46..6498dde6b 100755 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -792,30 +792,6 @@ class Module : public virtual slsDetectorDefs { std::string printUDPConfiguration(); - /** - * Sets the client zmq ip - * @param ip client zmq ip - */ - void setClientStreamingIP(const sls::IpAddr ip); - - /** - * Returns the client zmq ip - * @returns the client zmq ip - */ - sls::IpAddr getClientStreamingIP(); - - /** - * Sets the receiver zmq ip - * @param ip receiver zmq ip - */ - void setReceiverStreamingIP(const sls::IpAddr ip); - - /** - * Returns the receiver zmq ip - * @returns the receiver zmq ip - */ - sls::IpAddr getReceiverStreamingIP(); - /** update receiver stremaing ip from shm to receiver * if empty, use rx_hostname ip */ @@ -858,35 +834,6 @@ class Module : public virtual slsDetectorDefs { */ void setTransmissionDelayRight(int value); - /** empty vector deletes entire additional json header */ - void setAdditionalJsonHeader(const std::map &jsonHeader); - std::map getAdditionalJsonHeader(); - - /** - * Sets the value for the additional json header parameter key if found, else - * append it. If value empty, then deletes parameter */ - void setAdditionalJsonParameter(const std::string &key, const std::string &value); - std::string getAdditionalJsonParameter(const std::string &key); - - /** - * Sets the receiver UDP socket buffer size - * @param udpsockbufsize additional json header - * @returns receiver udp socket buffer size - */ - int64_t setReceiverUDPSocketBufferSize(int64_t udpsockbufsize = -1); - - /** - * Returns the receiver UDP socket buffer size - * @returns the receiver UDP socket buffer size - */ - int64_t getReceiverUDPSocketBufferSize(); - - /** - * Returns the receiver real UDP socket buffer size - * @returns the receiver real UDP socket buffer size - */ - int64_t getReceiverRealUDPSocketBufferSize() const; - /** [Gotthard][Jungfrau][CTB][Moench] */ void executeFirmwareTest(); @@ -964,28 +911,10 @@ class Module : public virtual slsDetectorDefs { */ slsDetectorDefs::ROI getROI(); - /** - * Set ADC Enable Mask (CTB, Moench) - * @param mask ADC Enable mask - */ + void setADCEnableMask(uint32_t mask); - - /** - * Get ADC Enable Mask (CTB, Moench) - * @returns ADC Enable mask - */ uint32_t getADCEnableMask(); - - /** - * Set 10Gb ADC Enable Mask (CTB, Moench) - * @param mask ADC Enable mask - */ void setTenGigaADCEnableMask(uint32_t mask); - - /** - * Get 10Gb ADC Enable Mask (CTB, Moench) - * @returns ADC Enable mask - */ uint32_t getTenGigaADCEnableMask(); /** @@ -1032,14 +961,6 @@ class Module : public virtual slsDetectorDefs { */ int getExternalSampling(); - /** digital data bits enable (CTB only) */ - void setReceiverDbitList(const std::vector& list); - std::vector getReceiverDbitList() const; - - /** Set digital data offset in bytes (CTB only) */ - void setReceiverDbitOffset(int value); - int getReceiverDbitOffset(); - /** * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert * users @@ -1048,12 +969,10 @@ class Module : public virtual slsDetectorDefs { */ void writeAdcRegister(uint32_t addr, uint32_t val); - /** - * Activates/Deactivates the detector (Eiger only) - * @param enable active (1) or inactive (0), -1 gets - * @returns 0 (inactive) or 1 (active)for activate mode - */ - int activate(int const enable = -1); + /** [Eiger] */ + bool getActivate(); + /** [Eiger] */ + void setActivate(const bool enable); bool getDeactivatedRxrPaddingMode(); diff --git a/slsDetectorSoftware/src/Receiver.cpp b/slsDetectorSoftware/src/Receiver.cpp index 43e408d0c..7674f0e9b 100755 --- a/slsDetectorSoftware/src/Receiver.cpp +++ b/slsDetectorSoftware/src/Receiver.cpp @@ -1,105 +1,12 @@ #include "Receiver.h" #include "ClientSocket.h" +#include "FixedCapacityContainer.h" #include "string_utils.h" #include "versionAPI.h" #include "ToString.h" namespace sls { -void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size, - void *retval, size_t retval_size) { - static_cast(*this).sendToReceiver( - fnum, args, args_size, retval, retval_size); -} - -void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size, - void *retval, size_t retval_size) const { - if (strlen(shm()->hostname) == 0) { - throw RuntimeError("Reciver not added"); - } - auto receiver = ReceiverSocket(shm()->hostname, shm()->tcpPort); - receiver.sendCommandThenRead(fnum, args, args_size, retval, retval_size); - receiver.close(); -} - -template -void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) { - sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); -} - -template -void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) const { - sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); -} - -template -void Receiver::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) { - sendToReceiver(fnum, &args, sizeof(args), nullptr, 0); -} - -template -void Receiver::sendToReceiver(int fnum, const Arg &args, - std::nullptr_t) const { - sendToReceiver(fnum, &args, sizeof(args), nullptr, 0); -} - -template -void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) { - sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); -} - -template -void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const { - sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); -} - -template -Ret Receiver::sendToReceiver(int fnum){ - LOG(logDEBUG1) << "Sending: [" - << getFunctionNameFromEnum(static_cast(fnum)) - << ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; - Ret retval{}; - sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); - LOG(logDEBUG1) << "Got back: " << retval; - return retval; -} - -template -Ret Receiver::sendToReceiver(int fnum) const{ - LOG(logDEBUG1) << "Sending: [" - << getFunctionNameFromEnum(static_cast(fnum)) - << ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; - Ret retval{}; - sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); - LOG(logDEBUG1) << "Got back: " << retval; - return retval; -} - -template -Ret Receiver::sendToReceiver(int fnum, const Arg &args){ - LOG(logDEBUG1) << "Sending: [" - << getFunctionNameFromEnum(static_cast(fnum)) - << ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name() - << ", " << sizeof(Ret) << "]"; - Ret retval{}; - sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); - LOG(logDEBUG1) << "Got back: " << retval; - return retval; -} - -template -Ret Receiver::sendToReceiver(int fnum, const Arg &args) const{ - LOG(logDEBUG1) << "Sending: [" - << getFunctionNameFromEnum(static_cast(fnum)) - << ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name() - << ", " << sizeof(Ret) << "]"; - Ret retval{}; - sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); - LOG(logDEBUG1) << "Got back: " << retval; - return retval; -} - - // create shm Receiver::Receiver(int detector_id, int module_id, int interface_id, int receiver_id, int tcp_port, std::string hostname, @@ -377,25 +284,70 @@ void Receiver::setUDPPort(const int port) { } /** ZMQ Streaming Parameters (Receiver<->Client) */ -void Receiver::setClientZmqPort(const int port) { - shm()->zmqPort = port; -} - int Receiver::getClientZmqPort() const { return shm()->zmqPort; } -void Receiver::setReceiverZmqPort(int port) { - sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr); +void Receiver::setClientZmqPort(const int port) { + shm()->zmqPort = port; } -int Receiver::getReceiverZmqPort() const { +int Receiver::getZmqPort() const { return sendToReceiver(F_GET_RECEIVER_STREAMING_PORT); } +void Receiver::setZmqPort(int port) { + sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr); +} + + +sls::IpAddr Receiver::getClientZmqIP() { + return shm()->zmqIp; +} + +void Receiver::setClientZmqIP(const sls::IpAddr ip) { + LOG(logDEBUG1) << "Setting client zmq ip to " << ip; + if (ip == 0) { + throw RuntimeError("Invalid client zmq ip address"); + } + shm()->zmqIp = ip; +} + +sls::IpAddr Receiver::getZmqIP() { + return sendToReceiver(F_GET_RECEIVER_STREAMING_SRC_IP); +} + +void Receiver::setZmqIP(const sls::IpAddr ip) { + if (ip == 0) { + throw RuntimeError("Invalid receiver zmq ip address"); + } + + // if client zmqip is empty, update it + if (shm()->zmqIp == 0) { + shm()->zmqIp = ip; + } + sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr); +} + +/** Receiver Parameters */ + +int64_t Receiver::getUDPSocketBufferSize() const { + return sendToReceiver(F_GET_RECEIVER_UDP_SOCK_BUF_SIZE); +} + +void Receiver::setUDPSocketBufferSize(int64_t value) { + LOG(logDEBUG1) << "Sending UDP Socket Buffer size to receiver: " + << value; + sendToReceiver(F_SET_RECEIVER_UDP_SOCK_BUF_SIZE, value, nullptr); +} + +int64_t Receiver::getRealUDPSocketBufferSize() const { + return sendToReceiver(F_GET_RECEIVER_REAL_UDP_SOCK_BUF_SIZE); +} /** Detector Parameters */ + void Receiver::setNumberOfFrames(int64_t value) { LOG(logDEBUG1) << "Sending number of frames to Receiver: " << value; sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, value, nullptr); @@ -426,6 +378,11 @@ void Receiver::setExptime(int64_t value) { sendToReceiver(F_RECEIVER_SET_EXPTIME, value, nullptr); } +void Receiver::setPeriod(int64_t value) { + LOG(logDEBUG1) << "Sending period to Receiver: " << value; + sendToReceiver(F_RECEIVER_SET_PERIOD, value, nullptr); +} + void Receiver::setSubExptime(int64_t value) { LOG(logDEBUG1) << "Sending sub exptime to Receiver: " << value; sendToReceiver(F_RECEIVER_SET_SUB_EXPTIME, value, nullptr); @@ -463,6 +420,95 @@ void Receiver::setReadNLines(const int value) { sendToReceiver(F_SET_RECEIVER_READ_N_LINES, value, nullptr); } +void Receiver::setADCEnableMask(uint32_t mask) { + sendToReceiver(F_RECEIVER_SET_ADC_MASK, mask, nullptr); +} + +void Receiver::setTenGigaADCEnableMask(uint32_t mask) { + sendToReceiver(F_RECEIVER_SET_ADC_MASK_10G, mask, nullptr); +} + +void Receiver::setBurstMode(slsDetectorDefs::burstMode value) { + LOG(logDEBUG1) << "Sending burst mode to Receiver: " << value; + sendToReceiver(F_SET_RECEIVER_BURST_MODE, value, nullptr); +} + +void Receiver::setROI(slsDetectorDefs::ROI arg) { + std::array args{arg.xmin, arg.xmax}; + LOG(logDEBUG1) << "Sending ROI to receiver"; + sendToReceiver(F_RECEIVER_SET_ROI, args, nullptr); +} + +void Receiver::clearROI() { + LOG(logDEBUG1) << "Clearing ROI"; + slsDetectorDefs::ROI arg; + arg.xmin = -1; + arg.xmax = -1; + setROI(arg); +} + +std::vector Receiver::getDbitList() const { + sls::FixedCapacityContainer retval; + sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval); + return retval; +} + +void Receiver::setDbitList(const std::vector& list) { + 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"); + } + } + sls::FixedCapacityContainer arg = list; + sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); +} + +int Receiver::getDbitOffset() { + return sendToReceiver(F_GET_RECEIVER_DBIT_OFFSET); +} + +void Receiver::setDbitOffset(int value) { + sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr); +} + +void Receiver::setActivate(const bool enable) { + int arg = static_cast(enable); + sendToReceiver(F_RECEIVER_ACTIVATE, arg, nullptr); +} + +std::map Receiver::getAdditionalJsonHeader() { + int fnum = F_GET_ADDITIONAL_JSON_HEADER; + int ret = FAIL; + int size = 0; + auto client = ReceiverSocket(shm()->hostname, shm()->tcpPort); + client.Send(&fnum, sizeof(fnum)); + client.Receive(&ret, sizeof(ret)); + if (ret == FAIL) { + char mess[MAX_STR_LENGTH]{}; + client.Receive(mess, MAX_STR_LENGTH); + throw RuntimeError("Receiver " + std::to_string(moduleId) + + " returned error: " + std::string(mess)); + } else { + client.Receive(&size, sizeof(size)); + std::map retval; + if (size > 0) { + char retvals[size * 2][SHORT_STR_LENGTH]; + memset(retvals, 0, sizeof(retvals)); + client.Receive(retvals, sizeof(retvals)); + for (int i = 0; i < size; ++i) { + retval[retvals[2 * i]] = retvals[2 * i + 1]; + } + } + LOG(logDEBUG) << "Getting additional json header " << ToString(retval); + return retval; + } +} + void Receiver::setAdditionalJsonHeader(const std::map &jsonHeader) { for (auto &it : jsonHeader) { if (it.first.empty() || it.first.length() > SHORT_STR_LENGTH || @@ -498,32 +544,12 @@ void Receiver::setAdditionalJsonHeader(const std::map } } -std::map Receiver::getAdditionalJsonHeader() { - int fnum = F_GET_ADDITIONAL_JSON_HEADER; - int ret = FAIL; - int size = 0; - auto client = ReceiverSocket(shm()->hostname, shm()->tcpPort); - client.Send(&fnum, sizeof(fnum)); - client.Receive(&ret, sizeof(ret)); - if (ret == FAIL) { - char mess[MAX_STR_LENGTH]{}; - client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Receiver " + std::to_string(moduleId) + - " returned error: " + std::string(mess)); - } else { - client.Receive(&size, sizeof(size)); - std::map retval; - if (size > 0) { - char retvals[size * 2][SHORT_STR_LENGTH]; - memset(retvals, 0, sizeof(retvals)); - client.Receive(retvals, sizeof(retvals)); - for (int i = 0; i < size; ++i) { - retval[retvals[2 * i]] = retvals[2 * i + 1]; - } - } - LOG(logDEBUG) << "Getting additional json header " << ToString(retval); - return retval; - } +std::string Receiver::getAdditionalJsonParameter(const std::string &key) { + char arg[SHORT_STR_LENGTH]{}; + sls::strcpy_safe(arg, key.c_str()); + char retval[SHORT_STR_LENGTH]{}; + sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval); + return retval; } void Receiver::setAdditionalJsonParameter(const std::string &key, const std::string &value) { @@ -538,11 +564,97 @@ void Receiver::setAdditionalJsonParameter(const std::string &key, const std::str sendToReceiver(F_SET_ADDITIONAL_JSON_PARAMETER, args, nullptr); } -std::string Receiver::getAdditionalJsonParameter(const std::string &key) { - char arg[SHORT_STR_LENGTH]{}; - sls::strcpy_safe(arg, key.c_str()); - char retval[SHORT_STR_LENGTH]{}; - sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval); + +void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size, + void *retval, size_t retval_size) { + static_cast(*this).sendToReceiver( + fnum, args, args_size, retval, retval_size); +} + +void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size, + void *retval, size_t retval_size) const { + if (strlen(shm()->hostname) == 0) { + throw RuntimeError("Reciver not added"); + } + auto receiver = ReceiverSocket(shm()->hostname, shm()->tcpPort); + receiver.sendCommandThenRead(fnum, args, args_size, retval, retval_size); + receiver.close(); +} + +template +void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) { + sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); +} + +template +void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) const { + sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); +} + +template +void Receiver::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) { + sendToReceiver(fnum, &args, sizeof(args), nullptr, 0); +} + +template +void Receiver::sendToReceiver(int fnum, const Arg &args, + std::nullptr_t) const { + sendToReceiver(fnum, &args, sizeof(args), nullptr, 0); +} + +template +void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) { + sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); +} + +template +void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const { + sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); +} + +template +Ret Receiver::sendToReceiver(int fnum){ + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; + Ret retval{}; + sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; + return retval; +} + +template +Ret Receiver::sendToReceiver(int fnum) const{ + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; + Ret retval{}; + sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; + return retval; +} + +template +Ret Receiver::sendToReceiver(int fnum, const Arg &args){ + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name() + << ", " << sizeof(Ret) << "]"; + Ret retval{}; + sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; + return retval; +} + +template +Ret Receiver::sendToReceiver(int fnum, const Arg &args) const{ + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name() + << ", " << sizeof(Ret) << "]"; + Ret retval{}; + sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; return retval; } diff --git a/slsDetectorSoftware/src/Receiver.h b/slsDetectorSoftware/src/Receiver.h index 21b724a7b..492eef4ce 100755 --- a/slsDetectorSoftware/src/Receiver.h +++ b/slsDetectorSoftware/src/Receiver.h @@ -86,9 +86,21 @@ class Receiver : public virtual slsDetectorDefs { * ************************************************/ int getClientZmqPort() const; void setClientZmqPort(const int port); - int getReceiverZmqPort() const; - void setReceiverZmqPort(int port); + int getZmqPort() const; + void setZmqPort(int port); + sls::IpAddr getClientZmqIP(); + void setClientZmqIP(const sls::IpAddr ip); + sls::IpAddr getZmqIP(); + void setZmqIP(const sls::IpAddr ip); + /************************************************** + * * + * Receiver Parameters * + * * + * ************************************************/ + int64_t getUDPSocketBufferSize() const; + void setUDPSocketBufferSize(int64_t value); + int64_t getRealUDPSocketBufferSize() const; /************************************************** * * @@ -101,6 +113,7 @@ class Receiver : public virtual slsDetectorDefs { void setNumberOfAnalogSamples(int value); void setNumberOfDigitalSamples(int value); void setExptime(int64_t value); + void setPeriod(int64_t value); void setSubExptime(int64_t value); void setSubDeadTime(int64_t value); void setTimingMode(timingMode value); @@ -108,21 +121,28 @@ class Receiver : public virtual slsDetectorDefs { void setReadoutMode(const readoutMode mode); void setQuad(const bool enable); void setReadNLines(const int value); + void setADCEnableMask(uint32_t mask); + void setTenGigaADCEnableMask(uint32_t mask); + void setBurstMode(burstMode value); + void setROI(slsDetectorDefs::ROI arg); + void clearROI(); + std::vector getDbitList() const; + /** digital data bits enable (CTB only) */ + void setDbitList(const std::vector& list); + int getDbitOffset(); + /** Set digital data offset in bytes (CTB only) */ + void setDbitOffset(int value); + void setActivate(const bool enable); + + std::map getAdditionalJsonHeader(); /** empty vector deletes entire additional json header */ void setAdditionalJsonHeader(const std::map &jsonHeader); - std::map getAdditionalJsonHeader(); + std::string getAdditionalJsonParameter(const std::string &key); /** Sets the value for the additional json header parameter key if found, else append it. If value empty, then deletes parameter */ void setAdditionalJsonParameter(const std::string &key, const std::string &value); - std::string getAdditionalJsonParameter(const std::string &key); - /************************************************** - * * - * Receiver Parameters * - * * - * ************************************************/ - /************************************************** * * * File * diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index d8d2eae0a..b72f2c3b0 100755 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -161,8 +161,9 @@ int ClientInterface::functionTable(){ flist[F_RESTREAM_STOP_FROM_RECEIVER] = &ClientInterface::restream_stop; flist[F_SET_ADDITIONAL_JSON_HEADER] = &ClientInterface::set_additional_json_header; flist[F_GET_ADDITIONAL_JSON_HEADER] = &ClientInterface::get_additional_json_header; - flist[F_RECEIVER_UDP_SOCK_BUF_SIZE] = &ClientInterface::set_udp_socket_buffer_size; - flist[F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE]= &ClientInterface::get_real_udp_socket_buffer_size; + flist[F_SET_RECEIVER_UDP_SOCK_BUF_SIZE] = &ClientInterface::set_udp_socket_buffer_size; + flist[F_GET_RECEIVER_UDP_SOCK_BUF_SIZE] = &ClientInterface::get_udp_socket_buffer_size; + flist[F_GET_RECEIVER_REAL_UDP_SOCK_BUF_SIZE]= &ClientInterface::get_real_udp_socket_buffer_size; flist[F_SET_RECEIVER_FRAMES_PER_FILE] = &ClientInterface::set_frames_per_file; flist[F_GET_RECEIVER_FRAMES_PER_FILE] = &ClientInterface::get_frames_per_file; flist[F_RECEIVER_CHECK_VERSION] = &ClientInterface::check_version_compatibility; @@ -555,7 +556,8 @@ int ClientInterface::set_roi(Interface &socket) { } catch(const RuntimeError &e) { throw RuntimeError("Could not set ROI"); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_frames(Interface &socket) { @@ -569,7 +571,8 @@ int ClientInterface::set_num_frames(Interface &socket) { impl()->setNumberOfFrames(value); int64_t retval = impl()->getNumberOfFrames(); validate(value, retval, "set number of frames", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_triggers(Interface &socket) { @@ -583,7 +586,8 @@ int ClientInterface::set_num_triggers(Interface &socket) { impl()->setNumberOfTriggers(value); int64_t retval = impl()->getNumberOfTriggers(); validate(value, retval, "set number of triggers", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_bursts(Interface &socket) { @@ -597,7 +601,8 @@ int ClientInterface::set_num_bursts(Interface &socket) { impl()->setNumberOfBursts(value); int64_t retval = impl()->getNumberOfBursts(); validate(value, retval, "set number of bursts", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_add_storage_cells(Interface &socket) { @@ -611,7 +616,8 @@ int ClientInterface::set_num_add_storage_cells(Interface &socket) { impl()->setNumberOfAdditionalStorageCells(value); int retval = impl()->getNumberOfAdditionalStorageCells(); validate(value, retval, "set number of additional storage cells", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_timing_mode(Interface &socket) { @@ -625,7 +631,8 @@ int ClientInterface::set_timing_mode(Interface &socket) { impl()->setTimingMode(static_cast(value)); int retval = impl()->getTimingMode(); validate(value, retval, "set timing mode", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_burst_mode(Interface &socket) { @@ -639,7 +646,8 @@ int ClientInterface::set_burst_mode(Interface &socket) { impl()->setBurstMode(static_cast(value)); int retval = impl()->getBurstMode(); validate(value, retval, "set burst mode", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_analog_samples(Interface &socket) { @@ -653,7 +661,8 @@ int ClientInterface::set_num_analog_samples(Interface &socket) { } catch(const RuntimeError &e) { throw RuntimeError("Could not set num analog samples to " + std::to_string(value) + " due to fifo structure memory allocation."); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_digital_samples(Interface &socket) { @@ -667,21 +676,24 @@ int ClientInterface::set_num_digital_samples(Interface &socket) { } catch(const RuntimeError &e) { throw RuntimeError("Could not set num digital samples to " + std::to_string(value) + " due to fifo structure memory allocation."); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_exptime(Interface &socket) { auto value = socket.Receive(); LOG(logDEBUG1) << "Setting exptime to " << value << "ns"; impl()->setAcquisitionTime(value); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_period(Interface &socket) { auto value = socket.Receive(); LOG(logDEBUG1) << "Setting period to " << value << "ns"; impl()->setAcquisitionPeriod(value); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_subexptime(Interface &socket) { @@ -690,7 +702,8 @@ int ClientInterface::set_subexptime(Interface &socket) { uint64_t subdeadtime = impl()->getSubPeriod() - impl()->getSubExpTime(); impl()->setSubExpTime(value); impl()->setSubPeriod(impl()->getSubExpTime() + subdeadtime); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_subdeadtime(Interface &socket) { @@ -698,7 +711,8 @@ int ClientInterface::set_subdeadtime(Interface &socket) { LOG(logDEBUG1) << "Setting sub deadtime to " << value << "ns"; impl()->setSubPeriod(value + impl()->getSubExpTime()); LOG(logDEBUG1) << "Setting sub period to " << impl()->getSubPeriod() << "ns"; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_dynamic_range(Interface &socket) { @@ -753,7 +767,8 @@ int ClientInterface::set_streaming_frequency(Interface &socket) { int retval = impl()->getStreamingFrequency(); validate(index, retval, "set streaming frequency", DEC); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_streaming_frequency(Interface &socket) { @@ -773,7 +788,8 @@ int ClientInterface::start_receiver(Interface &socket) { LOG(logDEBUG1) << "Starting Receiver"; impl()->startReceiver(); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::stop_receiver(Interface &socket) { @@ -788,7 +804,8 @@ int ClientInterface::stop_receiver(Interface &socket) { throw RuntimeError("Could not stop receiver. It as it is: " + sls::ToString(s)); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_file_dir(Interface &socket) { @@ -811,7 +828,8 @@ int ClientInterface::set_file_dir(Interface &socket) { else LOG(logDEBUG1) << "file path:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_file_dir(Interface &socket) { @@ -835,7 +853,8 @@ int ClientInterface::set_file_name(Interface &socket) { std::string s = impl()->getFileName(); sls::strcpy_safe(retval, s.c_str()); LOG(logDEBUG1) << "file name:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_file_name(Interface &socket) { @@ -859,7 +878,8 @@ int ClientInterface::set_file_index(Interface &socket) { int64_t retval = impl()->getFileIndex(); validate(index, retval, "set file index", DEC); LOG(logDEBUG1) << "file index:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_file_index(Interface &socket) { @@ -904,7 +924,8 @@ int ClientInterface::set_file_write(Interface &socket) { int retval = impl()->getFileWriteEnable(); validate(enable, retval, "set file write enable", DEC); LOG(logDEBUG1) << "file write enable:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_file_write(Interface &socket) { @@ -926,7 +947,8 @@ int ClientInterface::set_master_file_write(Interface &socket) { int retval = impl()->getMasterFileWriteEnable(); validate(enable, retval, "set master file write enable", DEC); LOG(logDEBUG1) << "master file write enable:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_master_file_write(Interface &socket) { @@ -948,7 +970,8 @@ int ClientInterface::set_overwrite(Interface &socket) { int retval = impl()->getOverwriteEnable(); validate(index, retval, "set file overwrite enable", DEC); LOG(logDEBUG1) << "file overwrite enable:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_overwrite(Interface &socket) { @@ -1028,7 +1051,8 @@ int ClientInterface::set_streaming(Interface &socket) { auto retval = static_cast(impl()->getDataStreamEnable()); validate(index, retval, "set data stream enable", DEC); LOG(logDEBUG1) << "data streaming enable:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_streaming(Interface &socket) { @@ -1081,7 +1105,8 @@ int ClientInterface::set_file_format(Interface &socket) { auto retval = impl()->getFileFormat(); validate(f, retval, "set file format", DEC); LOG(logDEBUG1) << "File Format: " << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_file_format(Interface &socket) { @@ -1102,7 +1127,8 @@ int ClientInterface::set_streaming_port(Interface &socket) { int retval = impl()->getStreamingPort(); validate(port, retval, "set streaming port", DEC); LOG(logDEBUG1) << "streaming port:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_streaming_port(Interface &socket) { @@ -1129,7 +1155,8 @@ int ClientInterface::set_streaming_source_ip(Interface &socket) { << ", but read " << retval << '\n'; throw RuntimeError(os.str()); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_streaming_source_ip(Interface &socket) { @@ -1151,7 +1178,8 @@ int ClientInterface::set_silent_mode(Interface &socket) { auto retval = static_cast(impl()->getSilentMode()); validate(value, retval, "set silent mode", DEC); LOG(logDEBUG1) << "silent mode:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_silent_mode(Interface &socket) { @@ -1169,7 +1197,8 @@ int ClientInterface::restream_stop(Interface &socket) { LOG(logDEBUG1) << "Restreaming stop"; impl()->restreamStop(); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_additional_json_header(Interface &socket) { @@ -1186,7 +1215,8 @@ int ClientInterface::set_additional_json_header(Interface &socket) { verifyIdle(socket); LOG(logDEBUG1) << "Setting additional json header: " << sls::ToString(json); impl()->setAdditionalJsonHeader(json); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_additional_json_header(Interface &socket) { @@ -1221,6 +1251,13 @@ int ClientInterface::set_udp_socket_buffer_size(Interface &socket) { "set udp socket buffer size (No CAP_NET_ADMIN privileges?)", DEC); LOG(logDEBUG1) << "UDP Socket Buffer Size:" << retval; + socket.Send(OK); + return OK; +} + +int ClientInterface::get_udp_socket_buffer_size(Interface &socket) { + int64_t retval = impl()->getUDPSocketBufferSize(); + LOG(logDEBUG1) << "UDP Socket Buffer Size:" << retval; return socket.sendResult(retval); } @@ -1244,7 +1281,8 @@ int ClientInterface::set_frames_per_file(Interface &socket) { auto retval = static_cast(impl()->getFramesPerFile()); validate(index, retval, "set frames per file", DEC); LOG(logDEBUG1) << "frames per file:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_frames_per_file(Interface &socket) { @@ -1278,7 +1316,8 @@ int ClientInterface::check_version_compatibility(Interface &socket) { } else { LOG(logINFO) << "Compatibility with Client: Successful"; } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_discard_policy(Interface &socket) { @@ -1292,7 +1331,8 @@ int ClientInterface::set_discard_policy(Interface &socket) { int retval = impl()->getFrameDiscardPolicy(); validate(index, retval, "set discard policy", DEC); LOG(logDEBUG1) << "frame discard policy:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_discard_policy(Interface &socket) { @@ -1313,7 +1353,8 @@ int ClientInterface::set_padding_enable(Interface &socket) { auto retval = static_cast(impl()->getFramePaddingEnable()); validate(index, retval, "set frame padding enable", DEC); LOG(logDEBUG1) << "Frame Padding Enable:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_padding_enable(Interface &socket) { @@ -1339,7 +1380,8 @@ int ClientInterface::set_deactivated_padding_enable( auto retval = static_cast(impl()->getDeactivatedPadding()); validate(enable, retval, "set deactivated padding enable", DEC); LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_deactivated_padding_enable( @@ -1390,7 +1432,8 @@ int ClientInterface::set_adc_mask(Interface &socket) { throw RuntimeError(os.str()); } LOG(logDEBUG1) << "1Gb ADC enable mask retval: " << retval; - return socket.sendResult(retval); + socket.Send(OK); + return OK; } int ClientInterface::set_dbit_list(Interface &socket) { @@ -1405,7 +1448,8 @@ int ClientInterface::set_dbit_list(Interface &socket) { LOG(logDEBUG1) << "\n"; verifyIdle(socket); impl()->setDbitList(args); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_dbit_list(Interface &socket) { @@ -1432,7 +1476,8 @@ int ClientInterface::set_dbit_offset(Interface &socket) { int retval = impl()->getDbitOffset(); validate(arg, retval, "set dbit offset", DEC); LOG(logDEBUG1) << "Dbit offset retval: " << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_dbit_offset(Interface &socket) { @@ -1457,7 +1502,8 @@ int ClientInterface::set_quad_type(Interface &socket) { int retval = impl()->getQuad() ? 1 : 0; validate(quadEnable, retval, "set quad", DEC); LOG(logDEBUG1) << "quad retval:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_read_n_lines(Interface &socket) { @@ -1470,7 +1516,8 @@ int ClientInterface::set_read_n_lines(Interface &socket) { int retval = impl()->getReadNLines(); validate(arg, retval, "set read n lines", DEC); LOG(logDEBUG1) << "read n lines retval:" << retval; - return socket.Send(OK); + socket.Send(OK); + return OK; } sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) { @@ -1541,7 +1588,8 @@ int ClientInterface::set_udp_port(Interface &socket) { verifyIdle(socket); LOG(logDEBUG1) << "Setting UDP Port:" << arg; impl()->setUDPPortNumber(arg); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_udp_port2(Interface &socket) { @@ -1552,7 +1600,8 @@ int ClientInterface::set_udp_port2(Interface &socket) { } LOG(logDEBUG1) << "Setting UDP Port:" << arg; impl()->setUDPPortNumber2(arg); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_num_interfaces(Interface &socket) { @@ -1568,7 +1617,8 @@ int ClientInterface::set_num_interfaces(Interface &socket) { } catch(const RuntimeError &e) { throw RuntimeError("Failed to set number of interfaces to " + std::to_string(arg)); } - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::set_adc_mask_10g(Interface &socket) { @@ -1588,7 +1638,8 @@ int ClientInterface::set_adc_mask_10g(Interface &socket) { throw RuntimeError(os.str()); } LOG(logDEBUG1) << "10Gb ADC enable mask retval: " << retval; - return socket.sendResult(retval); + socket.Send(OK); + return OK; } int ClientInterface::set_num_counters(Interface &socket) { @@ -1596,7 +1647,8 @@ int ClientInterface::set_num_counters(Interface &socket) { verifyIdle(socket); LOG(logDEBUG1) << "Setting counters: " << arg; impl()->setNumberofCounters(arg); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::increment_file_index(Interface &socket) { @@ -1605,7 +1657,8 @@ int ClientInterface::increment_file_index(Interface &socket) { LOG(logDEBUG1) << "Incrementing file index"; impl()->setFileIndex(impl()->getFileIndex() + 1); } - return socket.Send(OK); + socket.Send(OK); + return OK; } @@ -1615,7 +1668,8 @@ int ClientInterface::set_additional_json_parameter(Interface &socket) { verifyIdle(socket); LOG(logDEBUG1) << "Setting additional json parameter (" << args[0] << "): " << args[1]; impl()->setAdditionalJsonParameter(args[0], args[1]); - return socket.Send(OK); + socket.Send(OK); + return OK; } int ClientInterface::get_additional_json_parameter(Interface &socket) { diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index 76063b5ce..78cf47fbe 100755 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -121,6 +121,7 @@ class ClientInterface : private virtual slsDetectorDefs { int set_additional_json_header(sls::ServerInterface &socket); int get_additional_json_header(sls::ServerInterface &socket); int set_udp_socket_buffer_size(sls::ServerInterface &socket); + int get_udp_socket_buffer_size(sls::ServerInterface &socket); int get_real_udp_socket_buffer_size(sls::ServerInterface &socket); int set_frames_per_file(sls::ServerInterface &socket); int get_frames_per_file(sls::ServerInterface &socket); diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index d31c78497..64241e1ff 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -260,8 +260,9 @@ enum detFuncs{ F_RESTREAM_STOP_FROM_RECEIVER, F_SET_ADDITIONAL_JSON_HEADER, F_GET_ADDITIONAL_JSON_HEADER, - F_RECEIVER_UDP_SOCK_BUF_SIZE, - F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE, + F_SET_RECEIVER_UDP_SOCK_BUF_SIZE, + F_GET_RECEIVER_UDP_SOCK_BUF_SIZE, + F_GET_RECEIVER_REAL_UDP_SOCK_BUF_SIZE, F_SET_RECEIVER_FRAMES_PER_FILE, F_GET_RECEIVER_FRAMES_PER_FILE, F_RECEIVER_CHECK_VERSION, @@ -549,8 +550,9 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RESTREAM_STOP_FROM_RECEIVER: return "F_RESTREAM_STOP_FROM_RECEIVER"; case F_SET_ADDITIONAL_JSON_HEADER: return "F_SET_ADDITIONAL_JSON_HEADER"; case F_GET_ADDITIONAL_JSON_HEADER: return "F_GET_ADDITIONAL_JSON_HEADER"; - case F_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_UDP_SOCK_BUF_SIZE"; - case F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE"; + case F_SET_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_SET_RECEIVER_UDP_SOCK_BUF_SIZE"; + case F_GET_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_GET_RECEIVER_UDP_SOCK_BUF_SIZE"; + case F_GET_RECEIVER_REAL_UDP_SOCK_BUF_SIZE: return "F_GET_RECEIVER_REAL_UDP_SOCK_BUF_SIZE"; case F_SET_RECEIVER_FRAMES_PER_FILE: return "F_SET_RECEIVER_FRAMES_PER_FILE"; case F_GET_RECEIVER_FRAMES_PER_FILE: return "F_GET_RECEIVER_FRAMES_PER_FILE"; case F_RECEIVER_CHECK_VERSION: return "F_RECEIVER_CHECK_VERSION";