cdx_dbc_unpack.h Source

 1//=============================================================================
 2//! @file
 3//! @author GEMS
 4//! @date   7 October 2026
 5//! @brief Unsigned DBC signal unpacking from classic CAN and CAN-FD buffers.
 6//=============================================================================
 7// (c) Copyright 2026 General Engine Management Systems (GEMS) Ltd
 8//=============================================================================
 9
10#ifndef CDX_DBC_UNPACK_H_INCLUDED
11#define CDX_DBC_UNPACK_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 <stdint.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28//! @defgroup CDX_DBC_UNPACK CDX DBC Signal Unpacking
29//! @details Results are raw unsigned values without scaling or sign extension.
30//! Bit zero is the first byte's least significant bit. Intel signals continue
31//! into increasing byte indices; Motorola signals continue into decreasing
32//! byte indices. Use internal start-LSB offsets, not external Motorola start-MSB.
33//! @{
34//=============================================================================
35// Prototypes
36//=============================================================================
37
38//-----------------------------------------------------------------------------
39//! @brief Read an unsigned, little-endian signal of up to 32 bits.
40//! @param buffer Nonnull source buffer; never modified.
41//! @param size Source size in bytes, including CAN-FD data if present.
42//! @param offset Least significant bit position in internal DBC numbering.
43//! @param bits Signal width, 1 through 32; the entire signal must fit.
44//! @return Raw value, or zero for an invalid pointer, width or range.
45//! @note Invalid input is indistinguishable from a valid zero-valued signal.
46uint32_t CDX_dbc_unpack_u32_le(void const* buffer, uint32_t size, uint16_t offset, uint8_t bits);
47
48//-----------------------------------------------------------------------------
49//! @brief Read an unsigned, little-endian signal of up to 64 bits.
50//! @param buffer Nonnull source buffer; never modified.
51//! @param size Source size in bytes.
52//! @param offset Least significant bit position in internal DBC numbering.
53//! @param bits Signal width, 1 through 64; the entire signal must fit.
54//! @return Raw value, or zero for an invalid pointer, width or range.
55uint64_t CDX_dbc_unpack_u64_le(void const* buffer, uint32_t size, uint16_t offset, uint8_t bits);
56
57//-----------------------------------------------------------------------------
58//! @brief Read an unsigned, big-endian signal of up to 32 bits.
59//! @param buffer Nonnull source buffer; never modified.
60//! @param size Source size in bytes.
61//! @param offset Internal start-LSB position, not external Motorola start-MSB.
62//! @param bits Signal width, 1 through 32; the entire signal must fit.
63//! @return Raw value, or zero for an invalid pointer, width or range.
64uint32_t CDX_dbc_unpack_u32_be(void const* buffer, uint32_t size, uint16_t offset, uint8_t bits);
65
66//-----------------------------------------------------------------------------
67//! @brief Read an unsigned, big-endian signal of up to 64 bits.
68//! @param buffer Nonnull source buffer; never modified.
69//! @param size Source size in bytes.
70//! @param offset Internal start-LSB position, not external Motorola start-MSB.
71//! @param bits Signal width, 1 through 64; the entire signal must fit.
72//! @return Raw value, or zero for an invalid pointer, width or range.
73uint64_t CDX_dbc_unpack_u64_be(void const* buffer, uint32_t size, uint16_t offset, uint8_t bits);
74
75//! @}
76#ifdef __cplusplus
77} // extern "C"
78#endif
79
80//=============================================================================
81#endif // CDX_DBC_UNPACK_H_INCLUDED
82//=============================================================================
83// End of File
84//=============================================================================