Line data Source code
1 : #include "tdemodules/AMCController.hpp"
2 : #include "tdemodules/AMCProtocolClient.hpp"
3 : #include "utilities.hpp"
4 :
5 : #include <fmt/core.h>
6 : #include <iostream>
7 :
8 : #include "logging/Logging.hpp"
9 :
10 : namespace dunedaq {
11 : namespace tdemodules {
12 :
13 0 : AMCController::AMCController(const std::string& ip, uint16_t data_port)
14 0 : : m_ctrl_ip(ip)
15 0 : , m_data_port(data_port)
16 : {
17 :
18 : // Initialize status command payload
19 0 : m_status_cmd.clear();
20 0 : append_big_uint32(m_status_cmd, 0x0);
21 0 : append_big_uint32(m_status_cmd, 0x0);
22 :
23 : // Initialise start command payload
24 0 : append_big_uint32(m_start_cmd, data_port);
25 0 : append_big_uint32(m_start_cmd, kCmdStart);
26 0 : append_big_uint32(m_start_cmd, 0x0);
27 0 : append_big_uint32(m_start_cmd, 0x0);
28 :
29 : // Initialise stop command payload
30 0 : append_big_uint32(m_stop_cmd, data_port);
31 0 : append_big_uint32(m_stop_cmd, kCmdStop);
32 0 : append_big_uint32(m_stop_cmd, 0x0);
33 0 : append_big_uint32(m_stop_cmd, 0x0);
34 :
35 : // Initialise reset command payload
36 0 : append_big_uint32(m_reset_cmd, data_port);
37 0 : append_big_uint32(m_reset_cmd, kCmdReset);
38 0 : append_big_uint32(m_reset_cmd, 0x0);
39 0 : append_big_uint32(m_reset_cmd, 0x0);
40 0 : }
41 :
42 : std::vector<uint8_t>
43 0 : AMCController::send_cmd(const std::vector<uint8_t>& cmd)
44 : {
45 0 : std::vector<uint8_t> reply;
46 0 : try {
47 :
48 0 : auto client = AMCProtocolClient(m_ctrl_ip, m_ctrl_port);
49 :
50 0 : reply = client.send_wrq(cmd);
51 :
52 0 : } catch (const std::exception& e) {
53 0 : ers::error(AMCCommandIssue(ERS_HERE, m_ctrl_ip, m_data_port, e.what()));
54 : // std::cerr << "Exception: " << e.what() << "\n";
55 0 : }
56 0 : return reply;
57 0 : }
58 :
59 : void
60 0 : AMCController::card_reset()
61 : {
62 0 : send_cmd(m_reset_cmd);
63 0 : }
64 :
65 : void
66 0 : AMCController::card_start()
67 : {
68 0 : send_cmd(m_start_cmd);
69 0 : }
70 :
71 : void
72 0 : AMCController::card_stop()
73 : {
74 0 : send_cmd(m_stop_cmd);
75 0 : }
76 :
77 : void
78 0 : AMCController::card_status()
79 : {
80 0 : std::vector<uint8_t> reply = send_cmd(m_status_cmd);
81 :
82 0 : if (reply.empty()) {
83 0 : TLOG() << "Recieved an empty reply.";
84 0 : return;
85 : }
86 :
87 : // Take the first 4 bytes
88 0 : boost::endian::big_uint32_t word0_be;
89 0 : uint32_t word0;
90 :
91 0 : std::memcpy(&word0_be, reply.data(), sizeof(word0_be));
92 0 : fmt::print("word0 {:08x}\n", word0_be);
93 :
94 : // word0 = ntohl(word0);
95 0 : word0 = word0_be;
96 0 : fmt::print("word0 {:08x}\n", word0);
97 :
98 0 : uint32_t status = (word0 >> 16) & 0xffff;
99 0 : uint32_t version = (word0) & 0xffff;
100 :
101 : // # meaning of error bits
102 : // ErrorBits = { 0:"ADC_CHIPID_ERR",
103 : // 1:"ADC_SPEED_GRADE_ERR",
104 : // 2:"ADC_ALIGN_0_ERR",
105 : // 3:"ADC_ALIGN_1_ERR",
106 : // 4:"ADC_SERIAL_CTRL_ERR",
107 : // 5:"ADC_SAMPLE_RATE_ERR",
108 : // 6:"ADC_OUTPUT_MODE_ERR",
109 : // 7:"ADC_TEST_MODE_ERR",
110 : // 8:"WRLEN_AMC_TIME_VALID_ERR",
111 : // 9:"WRLEN_BITSLIP_ERR" }
112 :
113 0 : fmt::print("status {:04x}, version {:04x}\n", status, version);
114 0 : }
115 :
116 : } // namespace tdemodules
117 : } // namespace dunedaq
|