#ifndef BIWAK_CAN_MESSAGE_HPP
#define BIWAK_CAN_MESSAGE_HPP
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


#include <stdint.h>


//---Declarations-------------------------------------------------------------


typedef uint32_t canId_t;

class SCanMessage
{
      canId_t  m_id;
      int32_t      m_len;
      uint8_t  m_data[8];
      
   public:
      
      // constexpr default constructors waste a little bit binary size
      SCanMessage()
      {
      };
      
      // TBD: Check sizes; constructor needed for unit tests
      #if ! defined ( STM32 )
      #if 1
      constexpr SCanMessage( canId_t id )
          // must initialize everything for constexpr
         :m_id{id}
         ,m_len{0}
         ,m_data{ 0, 0, 0, 0,
                  0, 0, 0, 0  }
      {
      };
      #else
      SCanMessage( canId_t id )
          // must initialize everything for constexpr
         :m_id{id}
         ,m_len{0}
      {
      };
      #endif
      #endif
      constexpr SCanMessage( canId_t id, int len, const uint8_t* data )
          :m_id{id}
          ,m_len{ len > 8 ? 8 : len }
          ,m_data{   data[0], data[1], data[2], data[3],
                   data[4], data[5], data[6], data[7] }
      {
         //
      }
      constexpr canId_t getId() const
      {
         return( m_id );
      }
      constexpr void setId(canId_t id)
      {
         m_id = id;
      }
      constexpr int getLen() const
      {
         return( m_len );
      }
      constexpr void setLen( int len )
      {
         m_len = len;
      }
      const uint8_t* getData() const
      {
         return( m_data );
      }
      uint8_t* getData()
      {
         return( m_data );
      }
      void setData(int len, const uint8_t* data)
      {
         m_len= len > 8 ? 8 : len;
         memcpy(m_data, data, m_len);
      }
};


//---fin-----------------------------------------------------------------------
#endif // ? ! BIWAK_CAN_MESSAGE_HPP
