diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 34c69d868..39b0364fa 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1648,7 +1648,7 @@ std::vector DetectorImpl::getPortPositionList() const { switch (shm()->detType) { case defs::JUNGFRAU: case defs::MOENCH: - return std::vector{defs::TOP, defs::BOTTOM}; + return std::vector{defs::BOTTOM, defs::TOP}; case defs::EIGER: return std::vector{defs::LEFT, defs::RIGHT}; default: @@ -1662,22 +1662,42 @@ void DetectorImpl::updateRxUDPDatastreamMetadata() { detType != defs::MOENCH) throw RuntimeError( "Datastream enable not implemented for this detector"); - auto portList = getPortPositionList(); - if (portList.size() != 2) { - throw RuntimeError("Invalid port size. Expected 2."); - } - std::array, 2> results; - size_t i = 0; - for (const auto &port : portList) { - results[i] = Parallel(&Module::getDataStream, {}, port); - if (static_cast(results[i].size()) != size()) { - throw RuntimeError("udp datastream enable list does not match size " - "of module list"); - } - ++i; + + // check num interfaces + auto numInterfaces = + Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) + .tsquash("Inconsistent number of UDP interfaces among modules"); + if (numInterfaces != 2) { + throw RuntimeError("Invalid number of UDP interfaces. Expected 2."); } - modules[0]->updateRxUDPDatastreamMetadata(results); + std::vector disable; + // 1 interface: empty vector (disable none) + // 2 interface: check each enable + if (numInterfaces == 2) { + auto portList = getPortPositionList(); + if (portList.size() != 2) { + throw RuntimeError("Invalid port size. Expected 2."); + } + // bottom and left is port 0 + auto port0 = Parallel(&Module::getDataStream, {}, portList[0]); + auto port1 = Parallel(&Module::getDataStream, {}, portList[1]); + + // if any of them are disabled + if (port0.any(false) || port1.any(false)) { + // for each module: if disabled, push port index + for (size_t i = 0; i != port0.size(); ++i) { + if (!port0[i]) { + disable.push_back(i * 2); + } + if (!port1[i]) { + disable.push_back(i * 2 + 1); + } + } + } + } + + modules[0]->updateRxUDPPortDisableMetadata(disable); } std::vector DetectorImpl::getRxROI(int module_id) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 21642e7a2..5f3eea663 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1434,35 +1434,20 @@ void Module::setDataStream(const portPosition port, const bool enable) { } } -void Module::updateRxUDPDatastreamMetadata( - const std::array, 2> &res) { - +void Module::updateRxUDPPortDisableMetadata(const std::vector &disable) { if (!shm()->useReceiverFlag) { return; } - LOG(logDEBUG) << "Updating UDP data stream enable in receiver (metadata)"; + LOG(logDEBUG) << "Updating UDP port disable metadata in Receiver 0"; auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); - client.Send(F_RECEIVER_UDP_DATASTREAM_METADATA); - client.setFnum(F_RECEIVER_UDP_DATASTREAM_METADATA); - // ensure both port list size match - if (res[0].size() != res[1].size()) { - throw RuntimeError( - "Size Mismatch of udp datastream enable list for ports"); - } - // send udp data stream enable of all ports in all modules - auto nports = static_cast(res.size()); - auto nmods = static_cast(res[0].size()); + client.Send(F_RECEIVER_UDP_PORT_DISABLE_META); + client.setFnum(F_RECEIVER_UDP_PORT_DISABLE_META); + + auto nports = static_cast(disable.size()); client.Send(nports); - client.Send(nmods); - for (const auto &r : res) { - // convert vector of bool to vector of int to send - std::vector tmp; - tmp.reserve(r.size()); - for (bool b : r) { - tmp.push_back(static_cast(b)); - } - client.Send(tmp); + if (nports > 0) { + client.Send(disable); } if (client.Receive() == FAIL) { throw ReceiverError("Receiver " + std::to_string(moduleIndex) + diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 6a2287a0c..40f0953d1 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -281,8 +281,7 @@ class Module : public virtual slsDetectorDefs { void setTransmissionDelayRight(int value); bool getDataStream(const portPosition port) const; void setDataStream(const portPosition port, const bool enable); - void - updateRxUDPDatastreamMetadata(const std::array, 2> &res); + void updateRxUDPPortDisableMetadata(const std::vector &disable); /************************************************** * * diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index c4b63c04f..69384d847 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -222,7 +222,7 @@ int ClientInterface::functionTable(){ flist[F_RECEIVER_GET_ROI_METADATA] = &ClientInterface::get_roi_metadata; flist[F_SET_RECEIVER_READOUT_SPEED] = &ClientInterface::set_readout_speed; flist[F_RECEIVER_GET_UDP_DATASTREAM] = &ClientInterface::get_port_udp_datastream; - flist[F_RECEIVER_UDP_DATASTREAM_METADATA]= &ClientInterface::update_udp_datastream_metadata; + flist[F_RECEIVER_UDP_PORT_DISABLE_META] = &ClientInterface::update_udp_port_disable_meta; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { @@ -1918,33 +1918,19 @@ int ClientInterface::set_readout_speed(Interface &socket) { return socket.Send(OK); } -int ClientInterface::update_udp_datastream_metadata(Interface &socket) { +int ClientInterface::update_udp_port_disable_meta(Interface &socket) { auto nports = socket.Receive(); - if (nports != 2) { - throw RuntimeError("Could not update udp datastream meatdata. " - "Expecting max number of ports to be 2. Received " + - std::to_string(nports)); + std::vector portsDisabled; + if (nports > 0) { + portsDisabled.resize(nports); + socket.Receive(portsDisabled); + LOG(logDEBUG1) << "Disabled Ports Metadata:" << ToString(portsDisabled); } - auto nmods = socket.Receive(); - if (nmods < 1) { - throw RuntimeError("Could not update udp datastream metadata. " - "Expecting at least 1 module. Received " + - std::to_string(nmods)); - } - std::array, 2> portEnables; - for (auto &v : portEnables) { - v.resize(nmods); - } - socket.Receive(portEnables[0]); - socket.Receive(portEnables[1]); - LOG(logDEBUG1) << "Update UDP Datastream Metadata"; - LOG(logDEBUG1) << "Port 1:" << ToString(portEnables[0]); - LOG(logDEBUG1) << "Port 2:" << ToString(portEnables[1]); verifyIdle(socket); try { - impl()->updateUDPDatastreamMetadata(portEnables); + impl()->updateUDPPortsDisabledMetadata(portsDisabled); } catch (const std::exception &e) { - throw RuntimeError("Could not update UDP datastream metadata [" + + throw RuntimeError("Could not update UDP ports disabled metadata [" + std::string(e.what()) + ']'); } return socket.Send(OK); diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index f0dd0d90d..26d257169 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -170,7 +170,7 @@ class ClientInterface : private virtual slsDetectorDefs { int set_dbit_reorder(ServerInterface &socket); int get_roi_metadata(ServerInterface &socket); int set_readout_speed(ServerInterface &socket); - int update_udp_datastream_metadata(ServerInterface &socket); + int update_udp_port_disable_meta(ServerInterface &socket); Implementation *impl() { if (receiver != nullptr) { diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 6441c1bed..96bd2dd04 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -1679,7 +1679,8 @@ void Implementation::setActivate(bool enable) { bool Implementation::getUDPDataStream(const portPosition port) const { int index = 0; - if (port == BOTTOM || port == RIGHT) + // top goes to udp port 2 (jungfrau & moench) + if (port == TOP || port == RIGHT) index = 1; return udpDataStream[index]; } @@ -1687,7 +1688,8 @@ bool Implementation::getUDPDataStream(const portPosition port) const { void Implementation::setUDPDataStream(const portPosition port, const bool enable) { int index = 0; - if (port == BOTTOM || port == RIGHT) + // top goes to udp port 2 (jungfrau & moench) + if (port == TOP || port == RIGHT) index = 1; udpDataStreamType[index] = port; // jungfrau and moench: straightforward diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 72c3ea539..521311072 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -230,8 +230,7 @@ class Implementation : private virtual slsDetectorDefs { * [Eiger] deactivated at module level */ void setUDPDataStream(const portPosition port, const bool enable); - void updateUDPDatastreamMetadata( - const std::array, 2> &portEnables); + void updateUDPPortsDisabledMetadata(const std::vector &portsDisabled); int getReadNRows() const; /* [Eiger][Jungfrau][Moench] */ void setReadNRows(const int value); @@ -368,7 +367,7 @@ class Implementation : private virtual slsDetectorDefs { bool quadEnable{false}; bool activated{true}; std::array udpDataStream = {{true, true}}; - std::array, 2> udpPortEnables; + std::vector udpPortsDisabledMetadata; std::vector udpPort2Enable; std::array udpDataStreamType = {{LEFT, RIGHT}}; // only for Eiger to remember (10Gbe selectable) diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index b41f16567..1ba0171c4 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -424,7 +424,7 @@ enum detFuncs { F_RECEIVER_GET_ROI_METADATA, F_SET_RECEIVER_READOUT_SPEED, F_RECEIVER_GET_UDP_DATASTREAM, - F_RECEIVER_UDP_DATASTREAM_METADATA, + F_RECEIVER_UDP_PORT_DISABLE_META, NUM_REC_FUNCTIONS }; @@ -845,7 +845,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RECEIVER_GET_ROI_METADATA: return "F_RECEIVER_GET_ROI_METADATA"; case F_SET_RECEIVER_READOUT_SPEED: return "F_SET_RECEIVER_READOUT_SPEED"; case F_RECEIVER_GET_UDP_DATASTREAM: return "F_RECEIVER_GET_UDP_DATASTREAM"; - case F_RECEIVER_UDP_DATASTREAM_METADATA:return "F_RECEIVER_UDP_DATASTREAM_METADATA"; + case F_RECEIVER_UDP_PORT_DISABLE_META: return "F_RECEIVER_UDP_PORT_DISABLE_META"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS";