DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daphnemodules
src
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 <
ers/ers.hpp
>
17
#include "
logging/Logging.hpp
"
// NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
18
19
#include <zmq.hpp>
20
#include "
daphnemodules/daphne_control_high.pb.h
"
21
#include "
daphnemodules/CommonIssues.hpp
"
22
23
#include <memory>
24
#include <mutex>
25
#include <functional>
26
#include <string>
27
28
29
30
namespace
dunedaq
{
31
32
ERS_DECLARE_ISSUE
(
daphnemodules
,
33
SocketCreationError,
34
"Failed to create a socket"
,
35
ERS_EMPTY
36
)
37
38
ERS_DECLARE_ISSUE
(
daphnemodules
,
39
FailedPing
,
40
"Failed to ping daphne board at "
<< ip <<
':'
<< port,
41
((std::string)ip)((
int
)port)
42
)
43
44
ERS_DECLARE_ISSUE
(
daphnemodules
,
45
FailedSend,
46
"Failed to send message of type "
<<
type
,
47
((std::string)
type
)
48
)
49
50
ERS_DECLARE_ISSUE
(
daphnemodules
,
51
FailedReceive,
52
"Failed to receive message from "
<< connection,
53
((std::string)connection)
54
)
55
56
ERS_DECLARE_ISSUE
(
daphnemodules
,
57
EmptyPayload,
58
"Empty payload received from "
<< connection,
59
((std::string)connection)
60
)
61
62
ERS_DECLARE_ISSUE
(
daphnemodules
,
63
TypeMismatch,
64
"Received message of type "
<<
type
<<
" instead of "
<< expected,
65
((std::string)
type
)((std::string)expected)
66
)
67
68
69
ERS_DECLARE_ISSUE
(
daphnemodules
,
70
FailedDecoding,
71
"Failed to de-serialise to "
<<
type
<<
". Message: "
<< message,
72
((std::string)
type
)((std::string)message)
73
)
74
75
ERS_DECLARE_ISSUE
(
daphnemodules
,
76
UnexpectedDirection,
77
"Message received with unexpeted properties. Version: "
<<
version
<<
", direction "
<<
". Message: "
<< message,
78
((uint32_t)
version
)((std::string)direction)((std::string)message)
79
)
80
81
82
83
}
// namespace dunedaq
84
85
86
namespace
dunedaq::daphnemodules
{
87
88
class
DaphneV3Interface
{
89
90
public
:
91
DaphneV3Interface
( std::string
address
,
// it can contain the port or not
92
std::string routing,
// this should be the name of the controller module
93
std::chrono::milliseconds timeout = std::chrono::milliseconds(500));
94
95
96
~DaphneV3Interface
() {
close
(); }
97
98
DaphneV3Interface
(
const
DaphneV3Interface
&) =
delete
;
99
DaphneV3Interface
&
operator=
(
const
DaphneV3Interface
& ) =
delete
;
100
DaphneV3Interface
(
DaphneV3Interface
&&) =
delete
;
101
DaphneV3Interface
&
operator=
(
DaphneV3Interface
&&) =
delete
;
102
103
// this takes the serilised message and encodes it into the envelope
104
// It returns the serialised reply
105
106
daphne::ControlEnvelopeV2
send
( std::string && message,
daphne::MessageTypeV2
);
107
108
// this takes the serilised message and encodes it into the envelope
109
// It returns the de-serialised objects
110
template
<
class
T>
111
T
send
( std::string && message,
daphne::MessageTypeV2
sent_type,
daphne::MessageTypeV2
received_type );
112
113
bool
validate_connection
();
114
115
protected
:
116
void
_send
( std::string && message,
daphne::MessageTypeV2
);
117
daphne::ControlEnvelopeV2
_receive
();
118
119
void
close
();
120
121
private
:
122
zmq::context_t
m_context
;
123
124
zmq::socket_t
m_socket
;
125
mutable
std::mutex
m_access_mutex
;
126
127
std::string
m_connection
;
128
129
std::chrono::milliseconds
m_timeout
{1000};
130
131
uint64_t
m_message_counter
= 0;
132
133
inline
static
const
size_t
s_default_control_port
= 40001;
134
};
135
136
137
}
// namespce dunedaq::daphnemodules
138
139
#include <
DaphneV3Interface.hxx
>
140
141
#endif
// DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
DaphneV3Interface.hxx
ERS_EMPTY
#define ERS_EMPTY
Definition
IssueDeclarationMacro.hpp:22
version
version
Definition
TriggerActivity_serialization.hpp:50
type
type
Definition
TriggerActivity_serialization.hpp:48
daphne::ControlEnvelopeV2
Definition
daphne_control_high.pb.h:5899
dunedaq::daphnemodules::DaphneV3Interface::m_socket
zmq::socket_t m_socket
Definition
DaphneV3Interface.hpp:124
dunedaq::daphnemodules::DaphneV3Interface::close
void close()
Definition
DaphneV3Interface.cpp:69
dunedaq::daphnemodules::DaphneV3Interface::s_default_control_port
static const size_t s_default_control_port
Definition
DaphneV3Interface.hpp:133
dunedaq::daphnemodules::DaphneV3Interface::m_access_mutex
std::mutex m_access_mutex
Definition
DaphneV3Interface.hpp:125
dunedaq::daphnemodules::DaphneV3Interface::DaphneV3Interface
DaphneV3Interface(std::string address, std::string routing, std::chrono::milliseconds timeout=std::chrono::milliseconds(500))
Definition
DaphneV3Interface.cpp:24
dunedaq::daphnemodules::DaphneV3Interface::DaphneV3Interface
DaphneV3Interface(DaphneV3Interface &&)=delete
dunedaq::daphnemodules::DaphneV3Interface::send
daphne::ControlEnvelopeV2 send(std::string &&message, daphne::MessageTypeV2)
Definition
DaphneV3Interface.cpp:78
dunedaq::daphnemodules::DaphneV3Interface::operator=
DaphneV3Interface & operator=(const DaphneV3Interface &)=delete
dunedaq::daphnemodules::DaphneV3Interface::m_context
zmq::context_t m_context
Definition
DaphneV3Interface.hpp:122
dunedaq::daphnemodules::DaphneV3Interface::m_timeout
std::chrono::milliseconds m_timeout
Definition
DaphneV3Interface.hpp:129
dunedaq::daphnemodules::DaphneV3Interface::_send
void _send(std::string &&message, daphne::MessageTypeV2)
Definition
DaphneV3Interface.cpp:88
dunedaq::daphnemodules::DaphneV3Interface::validate_connection
bool validate_connection()
Definition
DaphneV3Interface.cpp:133
dunedaq::daphnemodules::DaphneV3Interface::~DaphneV3Interface
~DaphneV3Interface()
Definition
DaphneV3Interface.hpp:96
dunedaq::daphnemodules::DaphneV3Interface::DaphneV3Interface
DaphneV3Interface(const DaphneV3Interface &)=delete
dunedaq::daphnemodules::DaphneV3Interface::m_message_counter
uint64_t m_message_counter
Definition
DaphneV3Interface.hpp:131
dunedaq::daphnemodules::DaphneV3Interface::m_connection
std::string m_connection
Definition
DaphneV3Interface.hpp:127
dunedaq::daphnemodules::DaphneV3Interface::_receive
daphne::ControlEnvelopeV2 _receive()
Definition
DaphneV3Interface.cpp:109
daphne_control_high.pb.h
CommonIssues.hpp
ers.hpp
Logging.hpp
ERS_DECLARE_ISSUE
#define ERS_DECLARE_ISSUE( namespace_name, class_name, message_, attributes)
Definition
macro.hpp:65
daphne::MessageTypeV2
MessageTypeV2
Definition
daphne_control_high.pb.h:248
dunedaq::daphnemodules
Definition
DaphneV2Interface.hpp:66
dunedaq
Including Qt Headers.
Definition
module.cpp:16
dunedaq::FailedPing
FailedPing
Definition
DaphneV2Interface.hpp:40
dunedaq::address
Invalid address
Definition
CommonIssues.hpp:29
Generated on
for DUNE-DAQ by
1.17.0