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 "
logging/Logging.hpp
"
// NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
17
#include <
ers/ers.hpp
>
18
19
#include "
daphnemodules/CommonIssues.hpp
"
20
#include "
daphnemodules/daphne_control_high.pb.h
"
21
#include <zmq.hpp>
22
23
#include <functional>
24
#include <memory>
25
#include <mutex>
26
#include <string>
27
28
namespace
dunedaq
{
29
30
ERS_DECLARE_ISSUE
(
daphnemodules
, SocketCreationError,
"Failed to create a socket"
,
ERS_EMPTY
)
31
32
ERS_DECLARE_ISSUE
(
daphnemodules
,
33
FailedPing,
34
"Failed to ping daphne board at "
<< ip <<
':'
<< port,
35
((std::string)ip)((
int
)port))
36
37
ERS_DECLARE_ISSUE
(
daphnemodules
,
FailedSend
,
"Failed to send message of type "
<<
type
, ((
std
::
string
)
type
))
38
39
ERS_DECLARE_ISSUE
(
daphnemodules
,
40
FailedReceive,
41
"Failed to receive message from "
<< connection,
42
((
std
::
string
)connection))
43
44
ERS_DECLARE_ISSUE
(
daphnemodules
, EmptyPayload,
"Empty payload received from "
<< connection, ((
std
::
string
)connection))
45
46
ERS_DECLARE_ISSUE
(
daphnemodules
,
47
TypeMismatch,
48
"Received message of type "
<<
type
<<
" instead of "
<< expected,
49
((
std
::
string
)
type
)((
std
::
string
)expected))
50
51
ERS_DECLARE_ISSUE
(
daphnemodules
,
52
FailedDecoding,
53
"Failed to de-serialise to "
<<
type
<<
". Message: "
<< message,
54
((
std
::
string
)
type
)((
std
::
string
)message))
55
56
ERS_DECLARE_ISSUE
(
daphnemodules
,
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
64
namespace
dunedaq
::
daphnemodules
{
65
66
class
DaphneV3Interface
67
{
68
69
public
:
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
74
~DaphneV3Interface
() {
close
(); }
75
76
DaphneV3Interface
(
const
DaphneV3Interface
&) =
delete
;
77
DaphneV3Interface
&
operator=
(
const
DaphneV3Interface
&) =
delete
;
78
DaphneV3Interface
(
DaphneV3Interface
&&) =
delete
;
79
DaphneV3Interface
&
operator=
(
DaphneV3Interface
&&) =
delete
;
80
81
// this takes the serilised message and encodes it into the envelope
82
// It returns the serialised reply
83
84
daphne::ControlEnvelopeV2
send
(std::string&& message,
daphne::MessageTypeV2
);
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
91
bool
validate_connection
();
92
93
protected
:
94
void
_send
(std::string&& message,
daphne::MessageTypeV2
);
95
daphne::ControlEnvelopeV2
_receive
();
96
97
void
close
();
98
99
private
:
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_
DaphneV3Interface.hxx
ERS_EMPTY
#define ERS_EMPTY
Definition
IssueDeclarationMacro.hpp:23
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:102
dunedaq::daphnemodules::DaphneV3Interface::close
void close()
Definition
DaphneV3Interface.cpp:65
dunedaq::daphnemodules::DaphneV3Interface::s_default_control_port
static const size_t s_default_control_port
Definition
DaphneV3Interface.hpp:111
dunedaq::daphnemodules::DaphneV3Interface::m_access_mutex
std::mutex m_access_mutex
Definition
DaphneV3Interface.hpp:103
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::operator=
DaphneV3Interface & operator=(DaphneV3Interface &&)=delete
dunedaq::daphnemodules::DaphneV3Interface::send
daphne::ControlEnvelopeV2 send(std::string &&message, daphne::MessageTypeV2)
Definition
DaphneV3Interface.cpp:74
dunedaq::daphnemodules::DaphneV3Interface::operator=
DaphneV3Interface & operator=(const DaphneV3Interface &)=delete
dunedaq::daphnemodules::DaphneV3Interface::m_context
zmq::context_t m_context
Definition
DaphneV3Interface.hpp:100
dunedaq::daphnemodules::DaphneV3Interface::m_timeout
std::chrono::milliseconds m_timeout
Definition
DaphneV3Interface.hpp:107
dunedaq::daphnemodules::DaphneV3Interface::_send
void _send(std::string &&message, daphne::MessageTypeV2)
Definition
DaphneV3Interface.cpp:85
dunedaq::daphnemodules::DaphneV3Interface::validate_connection
bool validate_connection()
Definition
DaphneV3Interface.cpp:133
dunedaq::daphnemodules::DaphneV3Interface::~DaphneV3Interface
~DaphneV3Interface()
Definition
DaphneV3Interface.hpp:74
dunedaq::daphnemodules::DaphneV3Interface::DaphneV3Interface
DaphneV3Interface(const DaphneV3Interface &)=delete
dunedaq::daphnemodules::DaphneV3Interface::m_message_counter
uint64_t m_message_counter
Definition
DaphneV3Interface.hpp:109
dunedaq::daphnemodules::DaphneV3Interface::m_connection
std::string m_connection
Definition
DaphneV3Interface.hpp:105
dunedaq::daphnemodules::DaphneV3Interface::_receive
daphne::ControlEnvelopeV2 _receive()
Definition
DaphneV3Interface.cpp:108
daphne_control_high.pb.h
CommonIssues.hpp
ers.hpp
Logging.hpp
daphne::MessageTypeV2
MessageTypeV2
Definition
daphne_control_high.pb.h:248
dunedaq::daphnemodules
Definition
DaphneV2Interface.hpp:53
dunedaq
The DUNE-DAQ namespace.
Definition
cib_utilities.cpp:5
dunedaq::ERS_DECLARE_ISSUE
ERS_DECLARE_ISSUE(cibmodules, CIBCommunicationError, " CIB Hardware Communication Error: "<< descriptor,((std::string) descriptor)) ERS_DECLARE_ISSUE(cibmodules
dunedaq::FailedSend
FailedSend
Definition
DaphneV3Interface.hpp:37
dunedaq::address
Invalid address
Definition
CommonIssues.hpp:26
std
Definition
SchemaUtils.hpp:118
Generated on
for DUNE-DAQ by
1.18.0