Line data Source code
1 : /**
2 : * @file TimingFanoutController.cpp TimingFanoutController class
3 : * implementation
4 : *
5 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 :
10 : #include "TimingFanoutController.hpp"
11 : #include "timinglibs/dal/TimingFanoutControllerConf.hpp"
12 :
13 : #include "timinglibs/timingcmd/Nljs.hpp"
14 : #include "timinglibs/timingcmd/Structs.hpp"
15 :
16 : #include "timing/timingfirmwareinfo/Nljs.hpp"
17 : #include "timing/timingfirmwareinfo/Structs.hpp"
18 :
19 : #include "timing/timingendpointinfo/Nljs.hpp"
20 : #include "timing/timingendpointinfo/Structs.hpp"
21 :
22 : #include "appfwk/cmd/Nljs.hpp"
23 : #include "ers/Issue.hpp"
24 :
25 : #include <chrono>
26 : #include <cstdlib>
27 : #include <string>
28 : #include <thread>
29 : #include <vector>
30 :
31 : namespace dunedaq {
32 : namespace timinglibs {
33 :
34 0 : TimingFanoutController::TimingFanoutController(const std::string& name)
35 0 : : dunedaq::timinglibs::TimingEndpointControllerBase(name, 6) // 2nd arg: how many hw commands can this module send?
36 : {
37 0 : register_command("conf", &TimingFanoutController::do_configure);
38 0 : register_command("start", &TimingFanoutController::do_start);
39 0 : register_command("stop", &TimingFanoutController::do_stop);
40 0 : register_command("scrap", &TimingFanoutController::do_scrap);
41 0 : }
42 :
43 : void
44 0 : TimingFanoutController::do_configure(const CommandData_t& data)
45 : {
46 0 : auto mdal = m_params->cast<dal::TimingFanoutControllerConf>();
47 :
48 0 : m_device_ready_timeout = std::chrono::milliseconds(mdal->get_device_ready_timeout());
49 :
50 0 : TimingController::do_configure(data); // configure hw command connection
51 :
52 0 : configure_hardware_or_recover_state<TimingFanoutNotReady>(data, "Timing fanout");
53 :
54 0 : TLOG() << get_name() << "conf done for fanout device: " << m_timing_device;
55 0 : }
56 :
57 : // TODO: CHANGE
58 : void
59 0 : TimingFanoutController::send_configure_hardware_commands(const CommandData_t& data)
60 : {
61 0 : do_io_reset(data);
62 0 : std::this_thread::sleep_for(std::chrono::milliseconds(15000));
63 0 : do_endpoint_reset(data);
64 0 : std::this_thread::sleep_for(std::chrono::milliseconds(1000));
65 0 : }
66 :
67 : //void
68 : //TimingFanoutController::get_info(opmonlib::InfoCollector& ci, int /*level*/)
69 : //{
70 : // send counters internal to the module
71 : // timingfanoutcontrollerinfo::Info module_info;
72 :
73 : // module_info.sent_io_reset_cmds = m_sent_hw_command_counters.at(0).atomic.load();
74 : // module_info.sent_print_status_cmds = m_sent_hw_command_counters.at(1).atomic.load();
75 : // module_info.sent_fanout_endpoint_enable_cmds = m_sent_hw_command_counters.at(2).atomic.load();
76 : // module_info.sent_fanout_endpoint_reset_cmds = m_sent_hw_command_counters.at(4).atomic.load();
77 :
78 : // ci.add(module_info);
79 : // }
80 :
81 : void
82 0 : TimingFanoutController::process_device_info(nlohmann::json info)
83 : {
84 0 : ++m_device_infos_received_count;
85 :
86 0 : timing::timingfirmwareinfo::TimingDeviceInfo device_info;
87 0 : from_json(info, device_info);
88 :
89 0 : auto ept_info = device_info.endpoint_info;
90 :
91 0 : uint32_t endpoint_state = ept_info.state;
92 0 : bool ready = ept_info.ready;
93 :
94 0 : TLOG_DEBUG(3) << "state: 0x" << std::hex << endpoint_state << ", ready: " << ready << std::dec << ", infos received: " << m_device_infos_received_count;;
95 :
96 0 : if (endpoint_state > 0x5 && endpoint_state < 0x9)
97 : {
98 0 : if (!m_device_ready)
99 : {
100 0 : m_device_ready = true;
101 0 : TLOG_DEBUG(2) << "Timing fanout became ready";
102 : }
103 : }
104 : else
105 : {
106 0 : if (m_device_ready)
107 : {
108 0 : m_device_ready = false;
109 0 : TLOG_DEBUG(2) << "Timing fanout no longer ready";
110 : }
111 : }
112 0 : }
113 : } // namespace timinglibs
114 : } // namespace dunedaq
115 :
116 0 : DEFINE_DUNE_DAQ_MODULE(dunedaq::timinglibs::TimingFanoutController)
117 :
118 : // Local Variables:
119 : // c-basic-offset: 2
120 : // End:
|