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

            Line data    Source code
       1              : /**
       2              :  * @file LTC2945Node.cpp
       3              :  *
       4              :  * This is part of the DUNE DAQ Software Suite, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "timing/LTC2945Node.hpp"
      10              : 
      11              : // PDT headers
      12              : #include "ers/ers.hpp"
      13              : #include "timing/toolbox.hpp"
      14              : 
      15              : #include <vector>
      16              : // #include <fstream>
      17              : // #include <sstream>
      18              : 
      19              : namespace dunedaq {
      20              : namespace timing {
      21              : 
      22              : //-----------------------------------------------------------------------------
      23            0 : LTC2945Node::LTC2945Node(const I2CMasterNode* i2c_master, uint8_t address, double sense_resistance) // NOLINT(build/unsigned)
      24            0 :   : m_sense_resistance(sense_resistance)
      25            0 :   , I2CSlave(i2c_master, address)
      26            0 : {}
      27              : //-----------------------------------------------------------------------------
      28              : 
      29              : //-----------------------------------------------------------------------------
      30            0 : LTC2945Node::~LTC2945Node() {}
      31              : //-----------------------------------------------------------------------------
      32              : 
      33              : //-----------------------------------------------------------------------------
      34              : /*
      35              : uint8_t
      36              : LTC2945Node::read_register(uint8_t reg_address) const
      37              : {
      38              :   // Reset bus before beginning
      39              :   reset();
      40              : 
      41              :   // Open the connection and send the slave address, bit 0 set to zero
      42              :   send_i2c_command_and_write_data(kStartCmd, (m_i2c_device_address << 1) & 0xfe);
      43              : 
      44              :   // Push the byte on the bus
      45              :   send_i2c_command_and_write_data(0x0, reg_address);
      46              : 
      47              :   // Open the connection & send the target i2c address. Bit 0 set to 1 (read)
      48              :   send_i2c_command_and_write_data(kStartCmd, (m_i2c_device_address << 1) | 0x01);
      49              : 
      50              :   uint number_of_bytes = 1;
      51              : 
      52              :   std::vector<uint8_t> lArray; // NOLINT(build/unsigned)
      53              :   for (unsigned ibyte = 0; ibyte < number_of_bytes; ibyte++) {
      54              : 
      55              :     uint8_t cmd = ((ibyte == number_of_bytes - 1) ? (kStopCmd | kAckCmd) : 0x0); // NOLINT(build/unsigned)
      56              : 
      57              :     // Push the cmd on the bus, retrieve the result and put it in the arrary
      58              :     lArray.push_back(send_i2c_command_and_read_data(cmd));
      59              :   }
      60              :   return lArray[0];
      61              :   
      62              : }
      63              : */
      64              : //-----------------------------------------------------------------------------
      65              : 
      66              : //-----------------------------------------------------------------------------
      67              : double
      68            0 : LTC2945Node::read_v_in() const
      69              : {
      70            0 :   std::vector<uint8_t> v_in_bytes = this->read_i2cArray_atomic(0x1e, 0x2); // NOLINT(build/unsigned)
      71            0 :   uint16_t v_in_raw = combine_adc_data(v_in_bytes[0], v_in_bytes[1]);
      72            0 :   double v_in = v_in_raw*v_in_resolution;
      73              : 
      74            0 :   TLOG_DEBUG(13) << "LTC2945 Vin data - "
      75            0 :   << "raw bytes: 0x" << std::hex << (uint)v_in_bytes[0] << ", 0x" << (uint)v_in_bytes[1] // NOLINT(build/unsigned)
      76            0 :   << ", combined word: 0x" << v_in_raw
      77            0 :   << ", Vin [V]: " << v_in;
      78            0 :   return v_in;
      79            0 : }
      80              : //-----------------------------------------------------------------------------
      81              : 
      82              : //-----------------------------------------------------------------------------
      83              : double
      84            0 : LTC2945Node::read_delta_sense_v() const
      85              : {
      86            0 :   std::vector<uint8_t> v_bytes = this->read_i2cArray_atomic(0x14, 0x2); // NOLINT(build/unsigned)
      87            0 :   uint16_t v_raw = combine_adc_data(v_bytes[0], v_bytes[1]);
      88            0 :   double v = v_raw*delta_sense_v_resolution;
      89              : 
      90            0 :   TLOG_DEBUG(13) << "LTC2945 deltaSense V data - "
      91            0 :   << "raw bytes: 0x" << std::hex << (uint)v_bytes[0] << ", 0x" << (uint)v_bytes[1] // NOLINT(build/unsigned)
      92            0 :   << ", combined word: 0x" << v_raw
      93            0 :   << ", detlaSense V [mV]: " << v*1000;
      94            0 :   return v;
      95            0 : }
      96              : //-----------------------------------------------------------------------------
      97              : 
      98              : //-----------------------------------------------------------------------------
      99              : double
     100            0 : LTC2945Node::read_power() const
     101              : {
     102            0 :   std::vector<uint8_t> power_bytes = this->read_i2cArray_atomic(0x05, 0x3); // NOLINT(build/unsigned)
     103            0 :   uint32_t power_raw = combine_power_data(power_bytes[0], power_bytes[1], power_bytes[2]);
     104            0 :   double power = (power_raw * v_in_resolution * delta_sense_v_resolution) / m_sense_resistance;
     105              : 
     106            0 :   TLOG_DEBUG(13) << "LTC2945 power data - "
     107            0 :   << "raw bytes: 0x" << std::hex << (uint)power_bytes[0] << ", 0x" << (uint)power_bytes[1] << ", 0x" << (uint)power_bytes[2] // NOLINT(build/unsigned)
     108            0 :   << ", combined word: 0x" << power_raw
     109            0 :   << ", power [mW]: " << power*1000;
     110            0 :   return power;
     111            0 : }
     112              : //-----------------------------------------------------------------------------
     113              : 
     114              : //-----------------------------------------------------------------------------
     115              : uint16_t
     116            0 : LTC2945Node::combine_adc_data(uint8_t msb_byte, uint8_t lsb_byte)
     117              : {
     118            0 :   uint16_t adc = (uint16_t)msb_byte << 4;
     119            0 :   adc = adc | (lsb_byte >> 4);
     120            0 :   return adc;
     121              : }
     122              : //-----------------------------------------------------------------------------
     123              : 
     124              : //-----------------------------------------------------------------------------
     125              : uint32_t
     126            0 : LTC2945Node::combine_power_data(uint8_t msb_byte_2, uint8_t msb_byte_1, uint8_t lsb_byte)
     127              : {
     128            0 :   uint32_t power = (uint32_t)msb_byte_2 << 16;
     129            0 :   power = power | ((uint16_t)msb_byte_1 << 8);
     130            0 :   power = power | lsb_byte;
     131            0 :   return power;
     132              : }
     133              : //-----------------------------------------------------------------------------
     134              : 
     135              : } // namespace timing
     136              : } // namespace dunedaq
        

Generated by: LCOV version 2.0-1