diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 87fcf023f..cc08a6ff9 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -492,10 +492,13 @@ class Detector { * Validates and sets the receiver. * Updates local receiver cache parameters * Configures the detector to the receiver as UDP destination - * @param receiver receiver hostname or IP address + * @param receiver receiver hostname or IP address, can include tcp port eg. hostname:port */ void setRxHostname(const std::string &receiver, Positions pos = {}); + /** multiple rx hostnames (same as setRxHostname) */ + void setRxHostname(const std::vector &name); + Result getRxPort(Positions pos = {}) const; /** Receiver TCP port (for client communication with Receiver) diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 6d05572c9..8769b40c8 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -147,7 +147,6 @@ std::string CmdProxy::Hostname(int action) { det->setHostname(args); os << ToString(args) << '\n'; } - auto t = det->getHostname({det_id}); } else { throw sls::RuntimeError("Unknown action"); } @@ -849,6 +848,61 @@ std::string CmdProxy::UDPDestinationIP2(int action) { } /* Receiver Config */ +std::string CmdProxy::ReceiveHostname(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[hostname or ip address]\n\t" + "[hostname or ip address]:[tcp port]\n\t" + "[hostname1]:[tcp_port1]+[hostname2]:[tcp_port2]+\n\t" + "Receiver hostname or IP. If port included, then the receiver tcp port.\n\t" + "Used for TCP control communication between client and receiver " + "to configure receiver. Also updates receiver with detector parameters." + << '\n'; + } else if (action == defs::GET_ACTION) { + if (!args.empty()) { + WrongNumberOfParameters(0); + } + auto t = det->getRxHostname({det_id}); + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() < 1) { + WrongNumberOfParameters(1); + } + // multiple arguments + if (args.size() > 1) { + // multiple in mulitple + 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 at module level"); + } + det->setRxHostname(args); + os << ToString(args) << '\n'; + } + // single argument + else { + // multiple receivers concatenated with + + if (args[0].find('+') != std::string::npos) { + if (det_id != -1) { + throw sls::RuntimeError("Cannot add multiple receivers at module level"); + } + auto t = sls::split(args[0], '+'); + det->setRxHostname(t); + os << ToString(t) << '\n'; + } + // single receiver + else { + det->setRxHostname(args[0], {det_id}); + os << ToString(args) << '\n'; + } + } + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} /* File */ /* ZMQ Streaming Parameters (Receiver<->Client) */ /* Eiger Specific */ diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index faea5ab30..841d38694 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -89,10 +89,10 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - auto t = det->GETFCN({det_id}); \ if (args.size() != 0) { \ WrongNumberOfParameters(0); \ } \ + auto t = det->GETFCN({det_id}); \ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ @@ -115,10 +115,10 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - auto t = det->GETFCN({det_id}); \ if (args.size() != 0) { \ WrongNumberOfParameters(0); \ } \ + auto t = det->GETFCN({det_id}); \ os << OutStringHex(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ @@ -141,10 +141,10 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - auto t = det->GETFCN({det_id}); \ if (args.size() != 0) { \ WrongNumberOfParameters(0); \ } \ + auto t = det->GETFCN({det_id}); \ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ @@ -170,10 +170,10 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - auto t = det->GETFCN(); \ if (args.size() != 0) { \ WrongNumberOfParameters(0); \ } \ + auto t = det->GETFCN(); \ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ @@ -196,10 +196,10 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - auto t = det->GETFCN(INDEX, {det_id}); \ if (args.size() != 0) { \ WrongNumberOfParameters(0); \ } \ + auto t = det->GETFCN(INDEX, {det_id}); \ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ @@ -721,7 +721,7 @@ class CmdProxy { {"txndelay_right", &CmdProxy::txndelay_right}, /* Receiver Config */ - {"rx_hostname", &CmdProxy::rx_hostname}, + {"rx_hostname", &CmdProxy::ReceiveHostname}, {"rx_tcpport", &CmdProxy::rx_tcpport}, {"rx_fifodepth", &CmdProxy::rx_fifodepth}, {"rx_silent", &CmdProxy::rx_silent}, @@ -939,6 +939,7 @@ class CmdProxy { std::string UDPDestinationIP(int action); std::string UDPDestinationIP2(int action); /* Receiver Config */ + std::string ReceiveHostname(int action); /* File */ /* ZMQ Streaming Parameters (Receiver<->Client) */ /* Eiger Specific */ @@ -1434,9 +1435,6 @@ class CmdProxy { /* Receiver Config */ - STRING_COMMAND(rx_hostname, getRxHostname, setRxHostname, - "[hostname or ip address]\n\tReceiver hostname or IP. Used for TCP control communication between client and receiver to configure receiver. Also updates receiver with detector parameters."); - INTEGER_COMMAND(rx_tcpport, getRxPort, setRxPort, std::stoi, "[port]\n\tTCP port for client-receiver communication. Default is 1954. Must be different if multiple receivers on same pc. Must be first command to set a receiver parameter. Multi command will automatically increment for individual modules."); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 09982fef9..e2f2088c5 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -656,6 +656,23 @@ void Detector::setRxHostname(const std::string &receiver, Positions pos) { pimpl->Parallel(&Module::setReceiverHostname, pos, receiver); } +void Detector::setRxHostname(const std::vector &name) { + // set all to same rx_hostname + if (name.size() == 1) { + pimpl->Parallel(&Module::setReceiverHostname, {}, name[0]); + } else { + if ((int)name.size() != size()) { + throw RuntimeError("Receiver hostnames size " + + std::to_string(name.size()) + " does not match detector size " + + std::to_string(size())); + } + // set each rx_hostname + for (int idet = 0; idet < size(); ++idet) { + pimpl->Parallel(&Module::setReceiverHostname, {idet}, name[idet]); + } + } +} + Result Detector::getRxPort(Positions pos) const { return pimpl->Parallel(&Module::getReceiverPort, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index fbcc0e198..bc35e394b 100755 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1679,7 +1679,13 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) { updateCachedDetectorVariables(); // start updating - sls::strcpy_safe(shm()->rxHostname, receiverIP.c_str()); + std::string host = receiverIP; + auto res = sls::split(host, ':'); + if (res.size() > 1) { + host = res[0]; + shm()->rxTCPPort = std::stoi(res[1]); + } + sls::strcpy_safe(shm()->rxHostname, host.c_str()); shm()->useReceiverFlag = true; checkReceiverVersionCompatibility();