From c9e95a817614f082ac90bb9e15849f1416af3dda Mon Sep 17 00:00:00 2001 From: lrlunin Date: Mon, 4 May 2026 08:31:27 +0200 Subject: [PATCH] add rx_restream_stop command --- slsDetectorSoftware/generator/commands.yaml | 7 +++ .../generator/extended_commands.yaml | 22 +++++++++ slsDetectorSoftware/include/sls/Detector.h | 2 + slsDetectorSoftware/src/Caller.cpp | 43 ++++++++++++++++++ slsDetectorSoftware/src/Caller.h | 2 + slsDetectorSoftware/src/Detector.cpp | 4 ++ slsDetectorSoftware/src/inferAction.cpp | 12 +++++ slsDetectorSoftware/src/inferAction.h | 2 + slsReceiverSoftware/src/DataStreamer.cpp | 45 ++++++++++++++----- 9 files changed, 127 insertions(+), 12 deletions(-) diff --git a/slsDetectorSoftware/generator/commands.yaml b/slsDetectorSoftware/generator/commands.yaml index 20f94b12a..0e0888203 100644 --- a/slsDetectorSoftware/generator/commands.yaml +++ b/slsDetectorSoftware/generator/commands.yaml @@ -1636,6 +1636,13 @@ rx_stop: PUT: function: stopReceiver +rx_restream_stop: + inherit_actions: EXECUTE_SET_COMMAND_NOID + help: "\n\tSends ZMQ dummy header. The detector related fields are not set, the receiver related fields are set." + actions: + PUT: + function: restreamStop + readout: inherit_actions: EXECUTE_SET_COMMAND_NOID help: "\n\t[Mythen3] Starts detector readout. Status changes to TRANSMITTING and automatically returns to idle at the end of readout." diff --git a/slsDetectorSoftware/generator/extended_commands.yaml b/slsDetectorSoftware/generator/extended_commands.yaml index 9dd24bb5d..3fe5ca695 100644 --- a/slsDetectorSoftware/generator/extended_commands.yaml +++ b/slsDetectorSoftware/generator/extended_commands.yaml @@ -8841,6 +8841,28 @@ rx_realudpsocksize: \ to kernel bookkeeping." infer_action: true template: true +rx_restream_stop: + actions: + PUT: + args: + - arg_types: [] + argc: 0 + cast_input: [] + check_det_id: true + convert_det_id: true + function: restreamStop + input: [] + input_types: [] + output: + - '"successful"' + require_det_id: false + store_result_in_t: false + command_name: rx_restream_stop + function_alias: rx_restream_stop + help: "\n\tSends ZMQ dummy header. The detector related fields are not set, the\ + \ receiver related fields are set." + infer_action: true + template: true rx_roi: actions: GET: diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index a44a46e5f..d061b50de 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -700,6 +700,8 @@ class Detector { /** Gets Scan error message if scan ended in error for non blocking * acquisitions.*/ Result getScanErrorMessage(Positions pos = {}) const; + + void restreamStop(); ///@} /** @name Network Configuration (Detector<->Receiver) */ diff --git a/slsDetectorSoftware/src/Caller.cpp b/slsDetectorSoftware/src/Caller.cpp index 17405241e..5534d301c 100644 --- a/slsDetectorSoftware/src/Caller.cpp +++ b/slsDetectorSoftware/src/Caller.cpp @@ -10857,6 +10857,49 @@ std::string Caller::rx_realudpsocksize(int action) { return os.str(); } +std::string Caller::rx_restream_stop(int action) { + + std::ostringstream os; + // print help + if (action == slsDetectorDefs::HELP_ACTION) { + os << R"V0G0N( + Sends ZMQ dummy header. The detector related fields are not set, the receiver related fields are set. )V0G0N" + << std::endl; + return os.str(); + } + + // check if action and arguments are valid + if (action == slsDetectorDefs::PUT_ACTION) { + if (1 && args.size() != 0) { + throw RuntimeError("Wrong number of arguments for action PUT"); + } + + if (args.size() == 0) { + } + + } + + else { + + throw RuntimeError( + "INTERNAL ERROR: Invalid action: supported actions are ['PUT']"); + } + + // generate code for each action + if (action == slsDetectorDefs::PUT_ACTION) { + if (args.size() == 0) { + if (det_id != -1) { + throw RuntimeError( + "Cannot execute rx_restream_stop at module level"); + } + det->restreamStop(); + os << "successful" << '\n'; + } + } + + return os.str(); +} + std::string Caller::rx_silent(int action) { std::ostringstream os; diff --git a/slsDetectorSoftware/src/Caller.h b/slsDetectorSoftware/src/Caller.h index ce9e7cc93..ee4aa1c9b 100644 --- a/slsDetectorSoftware/src/Caller.h +++ b/slsDetectorSoftware/src/Caller.h @@ -261,6 +261,7 @@ class Caller { std::string rx_padding(int action); std::string rx_printconfig(int action); std::string rx_realudpsocksize(int action); + std::string rx_restream_stop(int action); std::string rx_roi(int action); std::string rx_silent(int action); std::string rx_start(int action); @@ -631,6 +632,7 @@ class Caller { {"rx_padding", &Caller::rx_padding}, {"rx_printconfig", &Caller::rx_printconfig}, {"rx_realudpsocksize", &Caller::rx_realudpsocksize}, + {"rx_restream_stop", &Caller::rx_restream_stop}, {"rx_roi", &Caller::rx_roi}, {"rx_silent", &Caller::rx_silent}, {"rx_start", &Caller::rx_start}, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index a6bd47a2f..d981bdb9b 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -966,6 +966,10 @@ void Detector::startReceiver() { pimpl->Parallel(&Module::startReceiver, {}); } void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); } +void Detector::restreamStop() { + pimpl->Parallel(&Module::restreamStopFromReceiver, {}); +} + void Detector::startDetector(Positions pos) { pimpl->startAcquisition(false, pos); } diff --git a/slsDetectorSoftware/src/inferAction.cpp b/slsDetectorSoftware/src/inferAction.cpp index 25467d1d2..8ff7c381e 100644 --- a/slsDetectorSoftware/src/inferAction.cpp +++ b/slsDetectorSoftware/src/inferAction.cpp @@ -2869,6 +2869,18 @@ int InferAction::rx_realudpsocksize() { } } +int InferAction::rx_restream_stop() { + + if (args.size() == 0) { + return slsDetectorDefs::PUT_ACTION; + } + + else { + + throw RuntimeError("Could not infer action: Wrong number of arguments"); + } +} + int InferAction::rx_roi() { throw RuntimeError("sls_detector is disabled for command: rx_roi. Use " diff --git a/slsDetectorSoftware/src/inferAction.h b/slsDetectorSoftware/src/inferAction.h index c3be8f075..1779bdf7a 100644 --- a/slsDetectorSoftware/src/inferAction.h +++ b/slsDetectorSoftware/src/inferAction.h @@ -215,6 +215,7 @@ class InferAction { int rx_padding(); int rx_printconfig(); int rx_realudpsocksize(); + int rx_restream_stop(); int rx_roi(); int rx_silent(); int rx_start(); @@ -551,6 +552,7 @@ class InferAction { {"rx_padding", &InferAction::rx_padding}, {"rx_printconfig", &InferAction::rx_printconfig}, {"rx_realudpsocksize", &InferAction::rx_realudpsocksize}, + {"rx_restream_stop", &InferAction::rx_restream_stop}, {"rx_roi", &InferAction::rx_roi}, {"rx_silent", &InferAction::rx_silent}, {"rx_start", &InferAction::rx_start}, diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 8a8e83833..b562805aa 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -168,6 +168,24 @@ int DataStreamer::SendDummyHeader() { zmqHeader zHeader; zHeader.data = false; zHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; + + // parameters coming from the receiver software + zHeader.fname = fileNametoStream; + zHeader.dynamicRange = generalData->dynamicRange; + zHeader.fileIndex = fileIndex; + zHeader.ndetx = numPorts.x; + zHeader.ndety = numPorts.y; + zHeader.flipRows = static_cast(flipRows); + zHeader.quad = quadEnable; + + // update local copy only if it was updated (to prevent locking each time) + if (isAdditionalJsonUpdated) { + std::lock_guard lock(additionalJsonMutex); + localAdditionalJsonHeader = additionalJsonHeader; + isAdditionalJsonUpdated = false; + } + zHeader.addJsonHeader = localAdditionalJsonHeader; + zHeader.rx_roi = portRoi.getIntArray(); return zmqSocket->SendHeader(index, zHeader); } @@ -177,24 +195,19 @@ int DataStreamer::SendDataHeader(sls_detector_header header, uint32_t size, zHeader.data = true; zHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; + // parameter coming from the detector uint64_t frameIndex = header.frameNumber - firstIndex; uint64_t acquisitionIndex = header.frameNumber; - zHeader.dynamicRange = generalData->dynamicRange; - zHeader.fileIndex = fileIndex; - zHeader.ndetx = numPorts.x; - zHeader.ndety = numPorts.y; - zHeader.npixelsx = nx; - zHeader.npixelsy = ny; - zHeader.imageSize = size; - zHeader.acqIndex = acquisitionIndex; zHeader.frameIndex = frameIndex; + zHeader.acqIndex = acquisitionIndex; + zHeader.frameNumber = header.frameNumber; zHeader.progress = 100 * ((double)(frameIndex + 1) / (double)(nTotalFrames)); - zHeader.fname = fileNametoStream; - zHeader.frameNumber = header.frameNumber; zHeader.expLength = header.expLength; zHeader.packetNumber = header.packetNumber; + zHeader.completeImage = + (header.packetNumber < generalData->packetsPerFrame ? false : true); zHeader.detSpec1 = header.detSpec1; zHeader.timestamp = header.timestamp; zHeader.modId = header.modId; @@ -205,10 +218,18 @@ int DataStreamer::SendDataHeader(sls_detector_header header, uint32_t size, zHeader.detSpec4 = header.detSpec4; zHeader.detType = header.detType; zHeader.version = header.version; + + // parameters coming from the receiver software + zHeader.fname = fileNametoStream; + zHeader.dynamicRange = generalData->dynamicRange; + zHeader.fileIndex = fileIndex; + zHeader.ndetx = numPorts.x; + zHeader.ndety = numPorts.y; + zHeader.npixelsx = nx; + zHeader.npixelsy = ny; + zHeader.imageSize = size; zHeader.flipRows = static_cast(flipRows); zHeader.quad = quadEnable; - zHeader.completeImage = - (header.packetNumber < generalData->packetsPerFrame ? false : true); // update local copy only if it was updated (to prevent locking each time) if (isAdditionalJsonUpdated) {