From 0359715be4a6aaa245c7a256430efc59e77496a8 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 7 Jul 2026 17:24:20 +0200 Subject: [PATCH] implement initial checks --- .../include/BaseMatterhornServerImpl.hpp | 11 +++++++++-- .../include/MatterhornServerImpl.cpp | 7 ------- .../include/MatterhornServerImpl.hpp | 5 ----- .../include/VirtualMatterhornServerImpl.cpp | 8 -------- .../include/VirtualMatterhornServerImpl.hpp | 3 --- .../slsDetectorServer_cpp/include/DetectorServer.h | 13 ++++++++++--- .../include/DetectorServerImpl.hpp | 13 +++++++++++++ .../src/DetectorServerImpl.cpp | 4 ++++ 8 files changed, 36 insertions(+), 28 deletions(-) diff --git a/slsDetectorServers/matterhornServer/include/BaseMatterhornServerImpl.hpp b/slsDetectorServers/matterhornServer/include/BaseMatterhornServerImpl.hpp index c23f43e89..a47954ac7 100644 --- a/slsDetectorServers/matterhornServer/include/BaseMatterhornServerImpl.hpp +++ b/slsDetectorServers/matterhornServer/include/BaseMatterhornServerImpl.hpp @@ -85,9 +85,16 @@ BaseMatterhornServerImpl< template void BaseMatterhornServerImpl::setupDetector() { // TODO: extend - set_num_frames(1); // maybe have a file with constexpr default values + try { + set_num_frames(1); + set_num_triggers(1); + } catch (const std::exception &e) { + LOG(logERROR) << "Failed to setup detector: " << e.what(); + detectorSetupStatus.error_message = std::string(e.what()); + detectorSetupStatus.successful_setup = false; + } - set_num_triggers(1); + detectorSetupStatus.successful_setup = true; } template diff --git a/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.cpp b/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.cpp index 947ba2a76..d1de9a8f7 100644 --- a/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.cpp +++ b/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.cpp @@ -7,13 +7,6 @@ slsDetectorDefs::runStatus MatterhornServerImpl::get_run_status() const { return slsDetectorDefs::runStatus::IDLE; // TODO: implement } -bool MatterhornServerImpl::initial_checks() const { - // TODO: add more checks here, for now just return true to be able to test - // the should check firmware -client compatibility - bool initial_checks_passed = true; - return initial_checks_passed; -} - void MatterhornServerImpl::set_module_position_and_update_srcudpmac( const std::array &position_info) { diff --git a/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.hpp b/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.hpp index 5e9258b93..612a6b8df 100644 --- a/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.hpp +++ b/slsDetectorServers/matterhornServer/include/MatterhornServerImpl.hpp @@ -12,11 +12,6 @@ class MatterhornServerImpl slsDetectorDefs::runStatus get_run_status() const; // TODO: impement - /// @brief return true if initial checks pass, false otherwise - bool - initial_checks() const; // TODO: Is it the same as for virtual server? - // If yes, can be moved to base class implementation - void set_module_position_and_update_srcudpmac( const std::array &position_info); diff --git a/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.cpp b/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.cpp index b22228cd3..5f02c420d 100644 --- a/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.cpp +++ b/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.cpp @@ -25,14 +25,6 @@ slsDetectorDefs::runStatus VirtualMatterhornServerImpl::get_run_status() const { return status; } -bool VirtualMatterhornServerImpl::initial_checks() const { - - // TODO: add more checks here, for now just return true to be able to test - // the should check firmware -client compatibility - bool initial_checks_passed = true; - return initial_checks_passed; -} - void VirtualMatterhornServerImpl::set_module_position_and_update_srcudpmac( const std::array &position_info) { diff --git a/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.hpp b/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.hpp index 3884e24e6..e26823449 100644 --- a/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.hpp +++ b/slsDetectorServers/matterhornServer/include/VirtualMatterhornServerImpl.hpp @@ -12,9 +12,6 @@ class VirtualMatterhornServerImpl slsDetectorDefs::runStatus get_run_status() const; - /// @brief return true if initial checks pass, false otherwise - bool initial_checks() const; - void set_module_position_and_update_srcudpmac( const std::array &position_info); diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.h b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.h index ca934d8b5..dfb1408a7 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.h +++ b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.h @@ -479,10 +479,17 @@ ProcessedResult DetectorServer::get_run_status( template ProcessedResult DetectorServer::initial_checks( ServerInterface &socket) const { - bool initial_checks_passed = getDerivedImpl()->initial_checks(); + auto detectorsetupstatus = getDerivedImpl()->initial_checks(); - return ProcessedResult{ - static_cast(socket.sendResult(initial_checks_passed))}; + const bool setup_successful = detectorsetupstatus.successful_setup; + + if (!setup_successful) { + return return_fail("Initial checks failed: " + + detectorsetupstatus.error_message); + } else { + return ProcessedResult{ + static_cast(socket.sendResult(setup_successful))}; + } } template diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp index 421ba766e..71b470f17 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp +++ b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp @@ -16,6 +16,14 @@ struct UDPInfo { uint32_t dstip{}; }; +/// @brief struct to store detector setup status +struct detector_setup_status { + /// @brief true if setupDetector() was successful, false otherwise + bool successful_setup{false}; + /// @brief error message if setupDetector() failed, empty otherwise + std::string error_message{}; +}; + /// @brief Shared memory structure for stop server to store run status struct acquisitionStatus { @@ -61,6 +69,8 @@ class DetectorServerImpl { uint16_t get_destination_udp_port() const; + detector_setup_status initial_checks() const; + protected: std::array udpDetails{}; // TODO: for now only one receiver per module @@ -78,6 +88,9 @@ class DetectorServerImpl { /// @param srcmac void updateSrcMacAddress(const uint64_t srcmac); + /// @brief true if setupDetector() was successful, false otherwise + detector_setup_status detectorSetupStatus{}; + private: /// @brief creates and maps shared memory void createSharedMemory(); diff --git a/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp b/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp index 71071fa2d..bce897432 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp +++ b/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp @@ -77,4 +77,8 @@ uint16_t DetectorServerImpl::get_destination_udp_port() const { return udpDetails[0].dstport; } +detector_setup_status DetectorServerImpl::initial_checks() const { + return detectorSetupStatus; +} + } // namespace sls \ No newline at end of file