cdx_dbc_pack.h Source

 1//=============================================================================
 2//! @file
 3//! @author GEMS
 4//! @date   7 October 2026
 5//! @brief Unsigned DBC signal packing for classic CAN and CAN-FD buffers.
 6//=============================================================================
 7// (c) Copyright 2026 General Engine Management Systems (GEMS) Ltd
 8//=============================================================================
 9
10#ifndef CDX_DBC_PACK_H_INCLUDED
11#define CDX_DBC_PACK_H_INCLUDED
12//=============================================================================
13
14//=============================================================================
15// Includes
16//=============================================================================
17
18#if defined(CDX_USER_HEADER) && !defined(CDX_USER_H_INCLUDED)
19#include CDX_USER_HEADER
20#endif
21
22#include "cdx_status.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28//! @defgroup CDX_DBC_PACK CDX DBC Signal Packing
29//! @details Offsets identify the signal's least significant bit using the
30//! internal DBC numbering: bit zero is the first byte's least significant bit.
31//! Intel signals continue into increasing byte indices; Motorola signals
32//! continue into decreasing byte indices. Motorola offsets are not the DBC
33//! file's external start-MSB notation. Surrounding bits are preserved.
34//! @{
35//=============================================================================
36// Prototypes
37//=============================================================================
38
39//-----------------------------------------------------------------------------
40//! @brief Pack an unsigned, little-endian signal of up to 32 bits.
41//! @param buffer Writable destination; must be nonnull.
42//! @param size Destination size in bytes, including CAN-FD data if present.
43//! @param offset Least significant bit position in internal DBC numbering.
44//! @param bits Signal width, 1 through 32; the entire signal must fit.
45//! @param value Raw value; only its least significant bits are written.
46//! @retval CDX_STATUS_OK Signal packed without modifying other bits.
47//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; no data changed.
48CDX_STATUS CDX_dbc_pack_u32_le(void* buffer, uint32_t size, uint16_t offset, uint8_t bits, uint32_t value);
49
50//-----------------------------------------------------------------------------
51//! @brief Pack an unsigned, little-endian signal of up to 64 bits.
52//! @param buffer Writable destination; must be nonnull.
53//! @param size Destination size in bytes.
54//! @param offset Least significant bit position in internal DBC numbering.
55//! @param bits Signal width, 1 through 64; the entire signal must fit.
56//! @param value Raw value; only its least significant bits are written.
57//! @retval CDX_STATUS_OK Signal packed without modifying other bits.
58//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; no data changed.
59CDX_STATUS CDX_dbc_pack_u64_le(void* buffer, uint32_t size, uint16_t offset, uint8_t bits, uint64_t value);
60
61//-----------------------------------------------------------------------------
62//! @brief Pack an unsigned, big-endian signal of up to 32 bits.
63//! @param buffer Writable destination; must be nonnull.
64//! @param size Destination size in bytes.
65//! @param offset Internal start-LSB position, not external Motorola start-MSB.
66//! @param bits Signal width, 1 through 32; the entire signal must fit.
67//! @param value Raw value; only its least significant bits are written.
68//! @retval CDX_STATUS_OK Signal packed without modifying other bits.
69//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; no data changed.
70CDX_STATUS CDX_dbc_pack_u32_be(void* buffer, uint32_t size, uint16_t offset, uint8_t bits, uint32_t value);
71
72//-----------------------------------------------------------------------------
73//! @brief Pack an unsigned, big-endian signal of up to 64 bits.
74//! @param buffer Writable destination; must be nonnull.
75//! @param size Destination size in bytes.
76//! @param offset Internal start-LSB position, not external Motorola start-MSB.
77//! @param bits Signal width, 1 through 64; the entire signal must fit.
78//! @param value Raw value; only its least significant bits are written.
79//! @retval CDX_STATUS_OK Signal packed without modifying other bits.
80//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; no data changed.
81CDX_STATUS CDX_dbc_pack_u64_be(void* buffer, uint32_t size, uint16_t offset, uint8_t bits, uint64_t value);
82
83//! @}
84#ifdef __cplusplus
85} // extern "C"
86#endif
87
88//=============================================================================
89#endif // CDX_DBC_PACK_H_INCLUDED
90//=============================================================================
91// End of File
92//=============================================================================