mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-05-10 08:02:07 +02:00
bb1a73d718
Build and Deploy on local RHEL9 / build (push) Successful in 2m0s
Build on RHEL9 docker image / build (push) Successful in 3m34s
Build on RHEL8 docker image / build (push) Successful in 4m46s
Build and Deploy on local RHEL8 / build (push) Successful in 5m3s
Run Simulator Tests on local RHEL9 / build (push) Successful in 14m43s
Run Simulator Tests on local RHEL8 / build (push) Successful in 18m15s
* added fetch fmt server library * added first draft of matterhorn * added enum ReturnCode * added cpp TCP Interface to slsDetectorServer * added fmt to workflows * bug: added std::signal for proper handling of ctr+c * added compile option to set log level * WIP * dont use c project settings when building matterhornserver * updated logger * WIP * WIP * linked fmt to slsProjectOptions * solved merge conflict * some refactoring * cleaned up logs * added fmt to workflow * WIP * generated register defs from csv file * oops given in hex * properly added fmt as a dependency * add fmt to conda recipe * some format changes * dont use public headers of fmt * WIP * used CRTP for virtual detector * WIP * added udp functions to matterhornserver * Matterhorn in tostring * warning unused variable from other PR * fixed build * updated cmake * added Server class usable for all detectors * removed stopserver * added some more functions * wrong overload * porper cleanup of matterhorn app * PR Review * refactored directory structure * used pause insetad of sleep --------- Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
113 lines
3.5 KiB
C++
113 lines
3.5 KiB
C++
#pragma once
|
|
#include "DetectorServer.h"
|
|
#include "TCPInterface.h"
|
|
// #include "communication_funcs.h"
|
|
#include "fmt/format.h"
|
|
#include "sls/logger.h"
|
|
#include "sls/network_utils.h"
|
|
#include "sls/sls_detector_defs.h"
|
|
#include "sls/versionAPI.h"
|
|
#include <array>
|
|
#include <cstring>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace sls {
|
|
|
|
/// @brief Base class for Matterhorn Server, can be used to implement a virtual
|
|
/// server for testing and actual server
|
|
template <typename DerivedServer>
|
|
class BaseMatterhornServer
|
|
: public DetectorServer<BaseMatterhornServer<DerivedServer>> {
|
|
|
|
public:
|
|
/**
|
|
* Constructor
|
|
* Starts up a Matterhorn server.
|
|
* Assembles a Matterhorn server using TCP and UDP detector interfaces
|
|
* throws an exception in case of failure
|
|
* @param port TCP/IP port number
|
|
*/
|
|
explicit BaseMatterhornServer(uint16_t port = DEFAULT_TCP_CNTRL_PORTNO)
|
|
: DetectorServer<BaseMatterhornServer<DerivedServer>>(port) {}
|
|
|
|
~BaseMatterhornServer() = default;
|
|
|
|
ReturnCode get_version(ServerInterface &socket);
|
|
|
|
ReturnCode get_detector_type(ServerInterface &socket);
|
|
|
|
ReturnCode initial_checks(ServerInterface &socket);
|
|
|
|
ReturnCode get_num_udp_interfaces(ServerInterface &socket) const;
|
|
|
|
/**
|
|
* @brief call function corresponding to the function ID received from the
|
|
* client and send back the result
|
|
* @param function_id the function ID received from the client
|
|
* @param socket the socket to send the result back to the client
|
|
*/
|
|
ReturnCode processFunction(const detFuncs function_id,
|
|
ServerInterface &socket);
|
|
|
|
private:
|
|
static std::string getMatterhornServerVersion();
|
|
|
|
static constexpr uint8_t numUDPInterfaces =
|
|
1; // only one udp per module for now
|
|
};
|
|
|
|
template <typename DerivedServer>
|
|
ReturnCode
|
|
BaseMatterhornServer<DerivedServer>::processFunction(const detFuncs function_id,
|
|
ServerInterface &socket) {
|
|
|
|
switch (function_id) {
|
|
default:
|
|
throw RuntimeError(
|
|
fmt::format("Function {} not implemented",
|
|
getFunctionNameFromEnum((enum detFuncs)function_id)));
|
|
}
|
|
}
|
|
|
|
template <typename DerivedServer>
|
|
ReturnCode BaseMatterhornServer<DerivedServer>::get_num_udp_interfaces(
|
|
ServerInterface &socket) const {
|
|
return static_cast<ReturnCode>(
|
|
socket.sendResult(static_cast<int>(numUDPInterfaces)));
|
|
}
|
|
|
|
template <typename DerivedServer>
|
|
ReturnCode
|
|
BaseMatterhornServer<DerivedServer>::get_version(ServerInterface &socket) {
|
|
|
|
auto version = getMatterhornServerVersion();
|
|
char version_cstr[MAX_STR_LENGTH]{};
|
|
strncpy(version_cstr, version.c_str(), version.size());
|
|
LOG(TLogLevel::logDEBUG) << "Matterhorn Server Version: " << version;
|
|
return static_cast<ReturnCode>(socket.sendResult(
|
|
version_cstr)); // TODO: check what would be possible return codes!!!
|
|
}
|
|
|
|
template <typename DerivedServer>
|
|
ReturnCode BaseMatterhornServer<DerivedServer>::get_detector_type(
|
|
ServerInterface &socket) {
|
|
int detectortype = slsDetectorDefs::detectorType::MATTERHORN;
|
|
return static_cast<ReturnCode>(socket.sendResult(detectortype));
|
|
}
|
|
|
|
template <typename DerivedServer>
|
|
std::string BaseMatterhornServer<DerivedServer>::getMatterhornServerVersion() {
|
|
return APIMATTERHORN;
|
|
}
|
|
|
|
template <typename DerivedServer>
|
|
ReturnCode
|
|
BaseMatterhornServer<DerivedServer>::initial_checks(ServerInterface &socket) {
|
|
|
|
return static_cast<DerivedServer *>(this)->initial_checks(socket);
|
|
}
|
|
|
|
} // namespace sls
|