cdx_dbc_copy.h Source

 1//=============================================================================
 2//! @file
 3//! @author GEMS
 4//! @date   7 October 2026
 5//! @brief Copy individual DBC signals while preserving surrounding payload bits.
 6//=============================================================================
 7// (c) Copyright 2026 General Engine Management Systems (GEMS) Ltd
 8//=============================================================================
 9
10#ifndef CDX_DBC_COPY_H_INCLUDED
11#define CDX_DBC_COPY_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_COPY CDX DBC Signal Copying
29//! @details The same internal start-LSB offset is used in both buffers. Bit
30//! zero is the first byte's least significant bit. Intel signals continue into
31//! increasing byte indices; Motorola signals continue into decreasing indices.
32//! Motorola offsets are not the external DBC start-MSB notation. Buffers may
33//! overlap: the complete signal is read before any destination bits change.
34//! @{
35//=============================================================================
36// Prototypes
37//=============================================================================
38
39//-----------------------------------------------------------------------------
40//! @brief Copy a little-endian signal of up to 32 bits.
41//! @param dst Nonnull writable destination buffer.
42//! @param dst_size Destination size in bytes.
43//! @param src Nonnull source buffer.
44//! @param src_size Source size in bytes.
45//! @param offset Internal least significant bit position in both buffers.
46//! @param bits Signal width, 1 through 32; must fit in both buffers.
47//! @retval CDX_STATUS_OK Signal copied; surrounding destination bits preserved.
48//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; nothing written.
49CDX_STATUS CDX_dbc_copy_u32_le(void* dst, uint32_t dst_size, void const* src, uint32_t src_size, uint16_t offset, uint8_t bits);
50
51//-----------------------------------------------------------------------------
52//! @brief Copy a little-endian signal of up to 64 bits.
53//! @param dst Nonnull writable destination buffer.
54//! @param dst_size Destination size in bytes.
55//! @param src Nonnull source buffer.
56//! @param src_size Source size in bytes.
57//! @param offset Internal least significant bit position in both buffers.
58//! @param bits Signal width, 1 through 64; must fit in both buffers.
59//! @retval CDX_STATUS_OK Signal copied; surrounding destination bits preserved.
60//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; nothing written.
61CDX_STATUS CDX_dbc_copy_u64_le(void* dst, uint32_t dst_size, void const* src, uint32_t src_size, uint16_t offset, uint8_t bits);
62
63//-----------------------------------------------------------------------------
64//! @brief Copy a big-endian signal of up to 32 bits.
65//! @param dst Nonnull writable destination buffer.
66//! @param dst_size Destination size in bytes.
67//! @param src Nonnull source buffer.
68//! @param src_size Source size in bytes.
69//! @param offset Internal start-LSB position, not external Motorola start-MSB.
70//! @param bits Signal width, 1 through 32; must fit in both buffers.
71//! @retval CDX_STATUS_OK Signal copied; surrounding destination bits preserved.
72//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; nothing written.
73CDX_STATUS CDX_dbc_copy_u32_be(void* dst, uint32_t dst_size, void const* src, uint32_t src_size, uint16_t offset, uint8_t bits);
74
75//-----------------------------------------------------------------------------
76//! @brief Copy a big-endian signal of up to 64 bits.
77//! @param dst Nonnull writable destination buffer.
78//! @param dst_size Destination size in bytes.
79//! @param src Nonnull source buffer.
80//! @param src_size Source size in bytes.
81//! @param offset Internal start-LSB position, not external Motorola start-MSB.
82//! @param bits Signal width, 1 through 64; must fit in both buffers.
83//! @retval CDX_STATUS_OK Signal copied; surrounding destination bits preserved.
84//! @retval CDX_STATUS_BAD_PARAM Invalid pointer, width or range; nothing written.
85CDX_STATUS CDX_dbc_copy_u64_be(void* dst, uint32_t dst_size, void const* src, uint32_t src_size, uint16_t offset, uint8_t bits);
86
87//! @}
88#ifdef __cplusplus
89} // extern "C"
90#endif
91
92//=============================================================================
93#endif // CDX_DBC_COPY_H_INCLUDED
94//=============================================================================
95// End of File
96//=============================================================================