DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DaphneV3Interface.hpp
Go to the documentation of this file.
1
12
13#ifndef DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
14#define DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
15
16#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
17#include <ers/ers.hpp>
18
21#include <zmq.hpp>
22
23#include <functional>
24#include <memory>
25#include <mutex>
26#include <string>
27
28namespace dunedaq {
29
30ERS_DECLARE_ISSUE(daphnemodules, SocketCreationError, "Failed to create a socket", ERS_EMPTY)
31
33 FailedPing,
34 "Failed to ping daphne board at " << ip << ':' << port,
35 ((std::string)ip)((int)port))
36
37ERS_DECLARE_ISSUE(daphnemodules, FailedSend, "Failed to send message of type " << type, ((std::string)type))
38
40 FailedReceive,
41 "Failed to receive message from " << connection,
42 ((std::string)connection))
43
44ERS_DECLARE_ISSUE(daphnemodules, EmptyPayload, "Empty payload received from " << connection, ((std::string)connection))
45
47 TypeMismatch,
48 "Received message of type " << type << " instead of " << expected,
49 ((std::string)type)((std::string)expected))
50
52 FailedDecoding,
53 "Failed to de-serialise to " << type << ". Message: " << message,
54 ((std::string)type)((std::string)message))
55
57 UnexpectedDirection,
58 "Message received with unexpeted properties. Version: " << version << ", direction "
59 << ". Message: " << message,
60 ((uint32_t)version)((std::string)direction)((std::string)message))
61
62} // namespace dunedaq
63
64namespace dunedaq::daphnemodules {
65
67{
68
69public:
70 DaphneV3Interface(std::string address, // it can contain the port or not
71 std::string routing, // this should be the name of the controller module
72 std::chrono::milliseconds timeout = std::chrono::milliseconds(500));
73
75
80
81 // this takes the serilised message and encodes it into the envelope
82 // It returns the serialised reply
83
85
86 // this takes the serilised message and encodes it into the envelope
87 // It returns the de-serialised objects
88 template<class T>
89 T send(std::string&& message, daphne::MessageTypeV2 sent_type, daphne::MessageTypeV2 received_type);
90
92
93protected:
94 void _send(std::string&& message, daphne::MessageTypeV2);
96
97 void close();
98
99private:
100 zmq::context_t m_context;
101
102 zmq::socket_t m_socket;
103 mutable std::mutex m_access_mutex;
104
105 std::string m_connection;
106
107 std::chrono::milliseconds m_timeout{ 1000 };
108
109 uint64_t m_message_counter = 0;
110
111 inline static const size_t s_default_control_port = 40001;
112};
113
114} // namespce dunedaq::daphnemodules
115
116#include <DaphneV3Interface.hxx>
117
118#endif // DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
#define ERS_EMPTY
DaphneV3Interface(std::string address, std::string routing, std::chrono::milliseconds timeout=std::chrono::milliseconds(500))
DaphneV3Interface(DaphneV3Interface &&)=delete
DaphneV3Interface & operator=(DaphneV3Interface &&)=delete
daphne::ControlEnvelopeV2 send(std::string &&message, daphne::MessageTypeV2)
DaphneV3Interface & operator=(const DaphneV3Interface &)=delete
void _send(std::string &&message, daphne::MessageTypeV2)
DaphneV3Interface(const DaphneV3Interface &)=delete
The DUNE-DAQ namespace.
ERS_DECLARE_ISSUE(cibmodules, CIBCommunicationError, " CIB Hardware Communication Error: "<< descriptor,((std::string) descriptor)) ERS_DECLARE_ISSUE(cibmodules
Invalid address