LCOV - code coverage report
Current view: top level - tdemodules/src - AMCController.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 53 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 7 0

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

Generated by: LCOV version 2.0-1