DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
EchoMonitorNode.cpp
Go to the documentation of this file.
1
10
12#include "timing/toolbox.hpp"
13#include "logging/Logging.hpp"
14
15#include <string>
16#include <chrono>
17
18namespace dunedaq {
19namespace timing {
20
21UHAL_REGISTER_DERIVED_NODE(EchoMonitorNode)
22
23//-----------------------------------------------------------------------------
25 : TimingNode(node)
26{}
27//-----------------------------------------------------------------------------
28
29//-----------------------------------------------------------------------------
31//-----------------------------------------------------------------------------
32
33//-----------------------------------------------------------------------------
34std::string
35EchoMonitorNode::get_status(bool print_out) const
36{
37 std::stringstream status;
38 auto subnodes = read_sub_nodes(getNode("csr.stat"));
39 status << format_reg_table(subnodes, "Echo mon state");
40 if (print_out)
41 TLOG() << status.str();
42 return status.str();
43}
44//-----------------------------------------------------------------------------
45
46//-----------------------------------------------------------------------------
47uint64_t // NOLINT(build/unsigned)
49{
50
51 getNode("csr.ctrl.go").write(0x1);
52 getClient().dispatch();
53
54 auto start = std::chrono::high_resolution_clock::now();
55
56 uhal::ValWord<uint32_t> done; // NOLINT(build/unsigned)
57 uhal::ValWord<uint32_t> delta_t;
58
59 while (true) {
60
61 done = getNode("csr.stat.rx_done").read();
62 delta_t = getNode("csr.stat.deltat").read();
63 getClient().dispatch();
64
65 TLOG_DEBUG(6) << "rx done: " << done.value() << ", delta_t: " << delta_t.value();
66
67 if (done.value())
68 {
69 if (delta_t.value() == 0xffff)
70 {
71 throw EchoReplyTimeout(ERS_HERE);
72 }
73 else
74 {
75 break;
76 }
77 }
78
79 auto now = std::chrono::high_resolution_clock::now();
80 auto ms_since_start = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
81
82 if (ms_since_start.count() > timeout)
83 throw EchoFlagTimeout(ERS_HERE, timeout);
84
85 std::this_thread::sleep_for(std::chrono::microseconds(10));
86 }
87
88 TLOG_DEBUG(4) << "delta t: " << format_reg_value(delta_t.value(), 10);
89
90 return delta_t.value();
91}
92//-----------------------------------------------------------------------------
93
94} // namespace timing
95} // namespace dunedaq
#define ERS_HERE
Class for master global node.
virtual uint64_t send_echo_and_measure_delay(int64_t timeout=500) const
Send echo and measure the round-trip time between master and endpoint.
std::string get_status(bool print_out=false) const override
Get status string, optionally print.
Base class for timing nodes.
std::map< std::string, uhal::ValWord< uint32_t > > read_sub_nodes(const uhal::Node &node, bool dispatch=true) const
Read subnodes.
static int64_t now()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
std::string format_reg_table(T data, std::string title, std::vector< std::string > headers)
Format reg-value table.
Definition toolbox.hxx:166
std::string format_reg_value(T reg_value, uint32_t base)
Definition toolbox.hxx:117
Including Qt Headers.