diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 7ab4304f2..6503a8b7d 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -825,10 +825,14 @@ class Detector { * Also updates receiver with detector parameters. \n Also resets any prior * receiver property (not on detector). \n receiver is receiver hostname or * IP address, can include tcp port eg. hostname:port + * + * rxIndex of -1 is rewritten as 0 (for backwards compatibility) */ void setRxHostname(const std::string &receiver, Positions pos = {}, const int rxIndex = 0); - /** single element assumes only one receiver per module. If multiple element and position for multi module, each element for each module */ + /** - single element, assumes rxIndex is 0 (for backwards compatibility). + * - muliple element with pos empty or -1, sets each element for each module (1:1 for backwards compatibility, rxIndex = 0) + * multiple element for specific position, each element for each RR rxr */ void setRxHostname(const std::vector &name, Positions pos); Result getRxPort(Positions pos = {}, const int rx_index = 0) const; @@ -1008,7 +1012,8 @@ class Detector { */ void setRxZmqPort(int port, int module_id = -1); - Result getRxZmqIP(Positions pos = {}) const; + Result getRxZmqIP(Positions pos = {}, + const int rx_index = 0) const; /** Zmq Ip Address from which data is to be streamed out of the receiver. \n * Also restarts receiver zmq streaming if enabled. \n Default is from diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index ba8e049ba..b155ab156 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1553,41 +1553,49 @@ std::string CmdProxy::ReceiverHostname(int action) { } // multiple arguments if (args.size() > 1) { - // multiple in mulitple + if (rx_id != -1) { + throw sls::RuntimeError( + "Cannot add multiple receivers at RR level"); + } + // multiple arguments (multiple rxr each)// backwards compatibility if (args[0].find('+') != std::string::npos) { - throw sls::RuntimeError( - "Cannot add multiple receivers at module level"); + if (det_id != -1) { + throw sls::RuntimeError( + "Cannot add multiple receivers for multiple modules at module level"); + } + for (int i = 0; i < (int)args.size(); ++i) { + auto t = sls::split(args[i], '+'); + det->setRxHostname(t, {i}); + os << ToString(t) << '\n'; + } } - if (det_id != -1) { - throw sls::RuntimeError( - "Cannot add multiple receivers at module level"); + // multiple arguments (single rxr each) (for both: each module and RR) + else { + det->setRxHostname(args, {det_id}); + os << ToString(args) << '\n'; } - det->setRxHostname(args); - os << ToString(args) << '\n'; } // single argument else { // multiple receivers concatenated with + if (args[0].find('+') != std::string::npos) { - // allowing multiple receivers at module level - /*if (det_id != -1) { - throw sls::RuntimeError( - "Cannot add multiple receivers at module level"); - }*/ - if (rx_id != -1) { - throw sls::RuntimeError( - "Cannot add multiple receivers at RR level"); + auto t = sls::split(args[0], '+'); + if (t.size() <= 0) { + throw sls::RuntimeError("Invalid argument for rx_hostname"); } - // split it for each module - if (det->size() > 1 && det_id == -1) { - auto t = sls::split(args[0], '+'); - det->setRxHostname(t); - os << ToString(t) << '\n'; + // single receiver + if (t.size() == 1) { + det->setRxHostname(t[0], std::vector{det_id}); + os << ToString(t[0]) << '\n'; } - // for specific module + // multiple receivers else { - det->setRxHostname(args[0], {det_id}); - os << ToString(args[0]) << '\n'; + if (rx_id != -1) { + throw sls::RuntimeError( + "Cannot add multiple receivers at RR level"); + } + det->setRxHostname(t, {det_id}); + os << ToString(t) << '\n'; } } // single receiver diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index e91b63beb..37eb65926 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -195,7 +195,7 @@ if (!args.empty()) { \ WrongNumberOfParameters(0); \ } \ - auto t = det->GETFCN(std::vector{det_id}, rx_id); \ + auto t = det->GETFCN(std::vector{det_id}, rx_id); \ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 9d5225fe6..da9aec6e4 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1078,35 +1078,30 @@ Result Detector::getRxHostname(Positions pos, // rr added using + at module level void Detector::setRxHostname(const std::string &receiver, Positions pos, const int rxIndex) { - pimpl->Parallel(&Module::setReceiverHostname, pos, receiver, rxIndex); + // for backwards compatibility + if (rxIndex == -1) { + pimpl->Parallel(&Module::setReceiverHostname, pos, receiver, 0); + } else { + pimpl->Parallel(&Module::setReceiverHostname, pos, receiver, rxIndex); + } updateRxRateCorrections(); } void Detector::setRxHostname(const std::vector &name, Positions pos) { - // set all to same rx_hostname - if (name.size() == 1) { - pimpl->Parallel(&Module::setReceiverHostname, pos, name[0], 0); - } else { - /*if ((int)name.size() != size()) { + // multi module (backwards compatibility: every element for every module) + if (name.size() > 1 && ((pos.empty() || pos[0] == -1))) { + if ((int)name.size() != size()) { throw RuntimeError( "Receiver hostnames size " + std::to_string(name.size()) + " does not match detector size " + std::to_string(size())); - }*/ - // multi module - if ((size() > 1) && (pos.empty() || pos[0] == -1)) { - for (int idet = 0; idet < size(); ++idet) { - pimpl->Parallel(&Module::setReceiverHostname, {idet}, name[idet], 0); - } - } - // setting rr for specific module - else { - if (pos.empty() || pos[0] == -1) { - pimpl->Parallel(&Module::setAllReceiverHostnames, {0}, name); - } else { - pimpl->Parallel(&Module::setAllReceiverHostnames, {pos}, name); - } - } + for (int idet = 0; idet < size(); ++idet) { + pimpl->Parallel(&Module::setReceiverHostname, {idet}, name[idet], 0); + } + } + // setting rr for specific module (backwards compaibility: single element is only for 0th RR) + else { + pimpl->Parallel(&Module::setAllReceiverHostnames, {pos}, name); } updateRxRateCorrections(); } @@ -1316,8 +1311,8 @@ void Detector::setRxZmqPort(int port, int module_id) { } } -Result Detector::getRxZmqIP(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverStreamingIP, pos); +Result Detector::getRxZmqIP(Positions pos, const int rx_index) const { + return pimpl->Parallel(&Module::getReceiverStreamingIP, pos, rx_index); } void Detector::setRxZmqIP(const IpAddr ip, Positions pos, const int rx_index) { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 42a4af6c4..9fe8ff9a5 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1277,13 +1277,19 @@ void Module::setAllReceiverHostnames(const std::vector &receiver) { } void Module::setReceiverHostname(const std::string &receiverIP, const int rxIndex) { - LOG(logDEBUG1) << "Setting up Receiver " << rxIndex << " with " << receiverIP; - + if (rxIndex < 0 || rxIndex >= MAX_UDP_DESTINATION) { + throw RuntimeError(std::string("Invalid receiver Index") + std::to_string(rxIndex)); + } + if (getRunStatus() == RUNNING) { throw RuntimeError( "Cannot set rx hostname when detector is acquiring."); } + LOG(logDEBUG1) << "Setting up Receiver " << rxIndex << " with " << receiverIP; + + + // clear current receiver for current module memset(shm()->receivers[rxIndex].hostname, 0, MAX_STR_LENGTH); sls::strcpy_safe(shm()->receivers[rxIndex].hostname, "none"); @@ -1606,8 +1612,7 @@ void Module::setReceiverStreamingPort(int port) { sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING_PORT, port, nullptr); } -sls::IpAddr Module::getReceiverStreamingIP() const { - const int rxIndex = 0; +sls::IpAddr Module::getReceiverStreamingIP(const int rxIndex) const { return sendToReceiver(rxIndex, F_GET_RECEIVER_STREAMING_SRC_IP); } @@ -3423,7 +3428,7 @@ void Module::setModule(sls_detector_module &module, bool trimbits) { // TODO Will need to update to each round robin entry void Module::updateReceiverStreamingIP(const int rxIndex) { - auto ip = getReceiverStreamingIP(); + auto ip = getReceiverStreamingIP(rxIndex); if (ip == 0) { // Hostname could be ip try to decode otherwise look up the hostname ip = sls::IpAddr{shm()->receivers[rxIndex].hostname}; diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 2c4d2727a..f8f583610 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -332,7 +332,7 @@ class Module : public virtual slsDetectorDefs { void setReceiverStreamingStartingFrame(int fnum); int getReceiverStreamingPort() const; void setReceiverStreamingPort(int port); - sls::IpAddr getReceiverStreamingIP() const; + sls::IpAddr getReceiverStreamingIP(const int rxIndex) const; void setReceiverStreamingIP(const sls::IpAddr ip, const int rxIndex); int getClientStreamingPort() const; void setClientStreamingPort(int port);