// Generator version : v3.1
// Generation time   : 2024.12.27 15:27:04
// DBC filename      : DMK-RP-77A.dbc
#include "canmatrix.h"


// DBC file version
#if (VER_CANMATRIX_MAJ != (0U)) || (VER_CANMATRIX_MIN != (0U))
#error The CANMATRIX dbc source files have different versions
#endif

#ifdef CANMATRIX_USE_DIAG_MONITORS
// Function prototypes to be called each time CAN frame is unpacked
// FMon function may detect RC, CRC or DLC violation
#include "canmatrix-fmon.h"

#endif // CANMATRIX_USE_DIAG_MONITORS

// This macro guard for the case when you need to enable
// using diag monitors but there is no necessity in proper
// SysTick provider. For providing one you need define macro
// before this line - in dbccodeconf.h

#ifndef GetSystemTick
#define GetSystemTick() (0u)
#endif

// This macro guard is for the case when you want to build
// app with enabled optoin auto CSM, but don't yet have
// proper getframehash implementation

#ifndef GetFrameHash
#define GetFrameHash(a,b,c,d,e) (0u)
#endif

// This function performs extension of sign for the signals
// whose bit width value is not aligned to one of power of 2 or less than 8.
// The types 'bitext_t' and 'ubitext_t' define the biggest bit width which
// can be correctly handled. You need to select type which can contain
// n+1 bits where n is the largest signed signal width. For example if
// the most wide signed signal has a width of 31 bits you need to set
// bitext_t as int32_t and ubitext_t as uint32_t
// Defined these typedefs in @dbccodeconf.h or locally in 'dbcdrvname'-config.h
static bitext_t __ext_sig__(ubitext_t val, uint8_t bits)
{
  ubitext_t const m = (ubitext_t) (1u << (bits - 1u));
  return ((val ^ m) - m);
}

uint32_t Unpack_BCM_HEAT_CANmatrix(BCM_HEAT_t* _m, const uint8_t* _d, uint8_t dlc_)
{
  (void)dlc_;
  _m->BCM_HEATCTL = (uint8_t) ( (_d[0] & (0xFFU)) );

#ifdef CANMATRIX_USE_DIAG_MONITORS
  _m->mon1.dlc_error = (dlc_ < BCM_HEAT_DLC);
  _m->mon1.last_cycle = GetSystemTick();
  _m->mon1.frame_cnt++;

  FMon_BCM_HEAT_canmatrix(&_m->mon1, BCM_HEAT_CANID);
#endif // CANMATRIX_USE_DIAG_MONITORS

  return BCM_HEAT_CANID;
}

#ifdef CANMATRIX_USE_CANSTRUCT

uint32_t Pack_BCM_HEAT_CANmatrix(BCM_HEAT_t* _m, __CoderDbcCanFrame_t__* cframe)
{
  uint8_t i; for (i = 0u; i < CANMATRIX_VALIDATE_DLC(BCM_HEAT_DLC); cframe->Data[i++] = CANMATRIX_INITIAL_BYTE_VALUE);

  cframe->Data[0] |= (uint8_t) ( (_m->BCM_HEATCTL & (0xFFU)) );

  cframe->MsgId = (uint32_t) BCM_HEAT_CANID;
  cframe->DLC = (uint8_t) BCM_HEAT_DLC;
  cframe->IDE = (uint8_t) BCM_HEAT_IDE;
  return BCM_HEAT_CANID;
}

#else

uint32_t Pack_BCM_HEAT_CANmatrix(BCM_HEAT_t* _m, uint8_t* _d, uint8_t* _len, uint8_t* _ide)
{
  uint8_t i; for (i = 0u; i < CANMATRIX_VALIDATE_DLC(BCM_HEAT_DLC); _d[i++] = CANMATRIX_INITIAL_BYTE_VALUE);

  _d[0] |= (uint8_t) ( (_m->BCM_HEATCTL & (0xFFU)) );

  *_len = (uint8_t) BCM_HEAT_DLC;
  *_ide = (uint8_t) BCM_HEAT_IDE;
  return BCM_HEAT_CANID;
}

#endif // CANMATRIX_USE_CANSTRUCT

uint32_t Unpack_MFS_HOD_CANmatrix(MFS_HOD_t* _m, const uint8_t* _d, uint8_t dlc_)
{
  (void)dlc_;
  _m->MFS_HOD_RAW = (uint16_t) ( ((_d[0] & (0xFFU)) << 8U) | (_d[1] & (0xFFU)) );
  _m->MFS_HOD_baseline = (uint16_t) ( ((_d[2] & (0xFFU)) << 8U) | (_d[3] & (0xFFU)) );
  _m->MFS_HOD_DIFF = (uint16_t) ( ((_d[4] & (0xFFU)) << 8U) | (_d[5] & (0xFFU)) );
  _m->MFS_HOD_TEMP = (uint8_t) ( (_d[6] & (0xFFU)) );
  _m->MFS_HOD_HANDING = (uint8_t) ( (_d[7] & (0x01U)) );
  _m->MFS_HOD_HEATING = (uint8_t) ( ((_d[7] >> 1U) & (0x01U)) );

#ifdef CANMATRIX_USE_DIAG_MONITORS
  _m->mon1.dlc_error = (dlc_ < MFS_HOD_DLC);
  _m->mon1.last_cycle = GetSystemTick();
  _m->mon1.frame_cnt++;

  FMon_MFS_HOD_canmatrix(&_m->mon1, MFS_HOD_CANID);
#endif // CANMATRIX_USE_DIAG_MONITORS

  return MFS_HOD_CANID;
}

#ifdef CANMATRIX_USE_CANSTRUCT

uint32_t Pack_MFS_HOD_CANmatrix(MFS_HOD_t* _m, __CoderDbcCanFrame_t__* cframe)
{
  uint8_t i; for (i = 0u; i < CANMATRIX_VALIDATE_DLC(MFS_HOD_DLC); cframe->Data[i++] = CANMATRIX_INITIAL_BYTE_VALUE);

  cframe->Data[0] |= (uint8_t) ( ((_m->MFS_HOD_RAW >> 8U) & (0xFFU)) );
  cframe->Data[1] |= (uint8_t) ( (_m->MFS_HOD_RAW & (0xFFU)) );
  cframe->Data[2] |= (uint8_t) ( ((_m->MFS_HOD_baseline >> 8U) & (0xFFU)) );
  cframe->Data[3] |= (uint8_t) ( (_m->MFS_HOD_baseline & (0xFFU)) );
  cframe->Data[4] |= (uint8_t) ( ((_m->MFS_HOD_DIFF >> 8U) & (0xFFU)) );
  cframe->Data[5] |= (uint8_t) ( (_m->MFS_HOD_DIFF & (0xFFU)) );
  cframe->Data[6] |= (uint8_t) ( (_m->MFS_HOD_TEMP & (0xFFU)) );
  cframe->Data[7] |= (uint8_t) ( (_m->MFS_HOD_HANDING & (0x01U)) | ((_m->MFS_HOD_HEATING & (0x01U)) << 1U) );

  cframe->MsgId = (uint32_t) MFS_HOD_CANID;
  cframe->DLC = (uint8_t) MFS_HOD_DLC;
  cframe->IDE = (uint8_t) MFS_HOD_IDE;
  return MFS_HOD_CANID;
}

#else

uint32_t Pack_MFS_HOD_CANmatrix(MFS_HOD_t* _m, uint8_t* _d, uint8_t* _len, uint8_t* _ide)
{
  uint8_t i; for (i = 0u; i < CANMATRIX_VALIDATE_DLC(MFS_HOD_DLC); _d[i++] = CANMATRIX_INITIAL_BYTE_VALUE);

  _d[0] |= (uint8_t) ( ((_m->MFS_HOD_RAW >> 8U) & (0xFFU)) );
  _d[1] |= (uint8_t) ( (_m->MFS_HOD_RAW & (0xFFU)) );
  _d[2] |= (uint8_t) ( ((_m->MFS_HOD_baseline >> 8U) & (0xFFU)) );
  _d[3] |= (uint8_t) ( (_m->MFS_HOD_baseline & (0xFFU)) );
  _d[4] |= (uint8_t) ( ((_m->MFS_HOD_DIFF >> 8U) & (0xFFU)) );
  _d[5] |= (uint8_t) ( (_m->MFS_HOD_DIFF & (0xFFU)) );
  _d[6] |= (uint8_t) ( (_m->MFS_HOD_TEMP & (0xFFU)) );
  _d[7] |= (uint8_t) ( (_m->MFS_HOD_HANDING & (0x01U)) | ((_m->MFS_HOD_HEATING & (0x01U)) << 1U) );

  *_len = (uint8_t) MFS_HOD_DLC;
  *_ide = (uint8_t) MFS_HOD_IDE;
  return MFS_HOD_CANID;
}

#endif // CANMATRIX_USE_CANSTRUCT

uint32_t Unpack_MFS_KEY_CANmatrix(MFS_KEY_t* _m, const uint8_t* _d, uint8_t dlc_)
{
  (void)dlc_;
  _m->MFS_MENU = (uint8_t) ( (_d[1] & (0x01U)) );
  _m->MFS_KEY_360 = (uint8_t) ( ((_d[1] >> 1U) & (0x01U)) );
  _m->MFS_KEY_ADAS = (uint8_t) ( ((_d[1] >> 2U) & (0x01U)) );
  _m->MFS_KEY_RST = (uint8_t) ( ((_d[1] >> 3U) & (0x01U)) );
  _m->MFS_KEY_SET = (uint8_t) ( ((_d[1] >> 4U) & (0x01U)) );
  _m->MFS_KEY_DistReduce = (uint8_t) ( ((_d[1] >> 5U) & (0x01U)) );
  _m->MFS_KEY_DistIncrease = (uint8_t) ( ((_d[1] >> 6U) & (0x01U)) );
  _m->MFS_KEY_LEFT = (uint8_t) ( (_d[5] & (0x01U)) );
  _m->MFS_KEY_OK = (uint8_t) ( ((_d[5] >> 1U) & (0x01U)) );
  _m->MFS_KEY_RIGHT = (uint8_t) ( ((_d[5] >> 2U) & (0x01U)) );
  _m->MFS_KEY_VOICE = (uint8_t) ( ((_d[5] >> 3U) & (0x01U)) );
  _m->MFS_KEY_PHONE = (uint8_t) ( ((_d[5] >> 4U) & (0x01U)) );
  _m->MFS_KEY_RETURN = (uint8_t) ( ((_d[5] >> 5U) & (0x01U)) );
  _m->MFS_ENCODER = (uint8_t) ( (_d[6] & (0x03U)) );
  _m->MFS_KEY_RollDownCnt = (uint8_t) ( (_d[7] & (0x0FU)) );
  _m->MFS_RollUpCnt = (uint8_t) ( ((_d[7] >> 4U) & (0x0FU)) );

#ifdef CANMATRIX_USE_DIAG_MONITORS
  _m->mon1.dlc_error = (dlc_ < MFS_KEY_DLC);
  _m->mon1.last_cycle = GetSystemTick();
  _m->mon1.frame_cnt++;

  FMon_MFS_KEY_canmatrix(&_m->mon1, MFS_KEY_CANID);
#endif // CANMATRIX_USE_DIAG_MONITORS

  return MFS_KEY_CANID;
}

#ifdef CANMATRIX_USE_CANSTRUCT

uint32_t Pack_MFS_KEY_CANmatrix(MFS_KEY_t* _m, __CoderDbcCanFrame_t__* cframe)
{
  uint8_t i; for (i = 0u; i < CANMATRIX_VALIDATE_DLC(MFS_KEY_DLC); cframe->Data[i++] = CANMATRIX_INITIAL_BYTE_VALUE);

  cframe->Data[1] |= (uint8_t) ( (_m->MFS_MENU & (0x01U)) | ((_m->MFS_KEY_360 & (0x01U)) << 1U) | ((_m->MFS_KEY_ADAS & (0x01U)) << 2U) | ((_m->MFS_KEY_RST & (0x01U)) << 3U) | ((_m->MFS_KEY_SET & (0x01U)) << 4U) | ((_m->MFS_KEY_DistReduce & (0x01U)) << 5U) | ((_m->MFS_KEY_DistIncrease & (0x01U)) << 6U) );
  cframe->Data[5] |= (uint8_t) ( (_m->MFS_KEY_LEFT & (0x01U)) | ((_m->MFS_KEY_OK & (0x01U)) << 1U) | ((_m->MFS_KEY_RIGHT & (0x01U)) << 2U) | ((_m->MFS_KEY_VOICE & (0x01U)) << 3U) | ((_m->MFS_KEY_PHONE & (0x01U)) << 4U) | ((_m->MFS_KEY_RETURN & (0x01U)) << 5U) );
  cframe->Data[6] |= (uint8_t) ( (_m->MFS_ENCODER & (0x03U)) );
  cframe->Data[7] |= (uint8_t) ( (_m->MFS_KEY_RollDownCnt & (0x0FU)) | ((_m->MFS_RollUpCnt & (0x0FU)) << 4U) );

  cframe->MsgId = (uint32_t) MFS_KEY_CANID;
  cframe->DLC = (uint8_t) MFS_KEY_DLC;
  cframe->IDE = (uint8_t) MFS_KEY_IDE;
  return MFS_KEY_CANID;
}

#else

uint32_t Pack_MFS_KEY_CANmatrix(MFS_KEY_t* _m, uint8_t* _d, uint8_t* _len, uint8_t* _ide)
{
  uint8_t i; for (i = 0u; i < CANMATRIX_VALIDATE_DLC(MFS_KEY_DLC); _d[i++] = CANMATRIX_INITIAL_BYTE_VALUE);

  _d[1] |= (uint8_t) ( (_m->MFS_MENU & (0x01U)) | ((_m->MFS_KEY_360 & (0x01U)) << 1U) | ((_m->MFS_KEY_ADAS & (0x01U)) << 2U) | ((_m->MFS_KEY_RST & (0x01U)) << 3U) | ((_m->MFS_KEY_SET & (0x01U)) << 4U) | ((_m->MFS_KEY_DistReduce & (0x01U)) << 5U) | ((_m->MFS_KEY_DistIncrease & (0x01U)) << 6U) );
  _d[5] |= (uint8_t) ( (_m->MFS_KEY_LEFT & (0x01U)) | ((_m->MFS_KEY_OK & (0x01U)) << 1U) | ((_m->MFS_KEY_RIGHT & (0x01U)) << 2U) | ((_m->MFS_KEY_VOICE & (0x01U)) << 3U) | ((_m->MFS_KEY_PHONE & (0x01U)) << 4U) | ((_m->MFS_KEY_RETURN & (0x01U)) << 5U) );
  _d[6] |= (uint8_t) ( (_m->MFS_ENCODER & (0x03U)) );
  _d[7] |= (uint8_t) ( (_m->MFS_KEY_RollDownCnt & (0x0FU)) | ((_m->MFS_RollUpCnt & (0x0FU)) << 4U) );

  *_len = (uint8_t) MFS_KEY_DLC;
  *_ide = (uint8_t) MFS_KEY_IDE;
  return MFS_KEY_CANID;
}

#endif // CANMATRIX_USE_CANSTRUCT

