Skip to content

Commit 32be594

Browse files
moonlight83340yashi
authored andcommitted
doc: Add documentation to csp_id
Add documentation for all public functions of csp_id. This header previously lacked any documentation, making it harder to understand the role of each function, especially for newer contributors or external users. This improves both inline readability and Sphinx-generated documentation. Signed-off-by: Gaetan Perrot <[email protected]>
1 parent 0531750 commit 32be594

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

doc/api/csp_id_h.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,20 @@ CSP ID
22
======
33

44
.. autocmodule:: csp_id.h
5-
:members:
5+
6+
Functions
7+
---------
8+
9+
.. autocfunction:: csp_id.h::csp_id_prepend
10+
.. autocfunction:: csp_id.h::csp_id_strip
11+
.. autocfunction:: csp_id.h::csp_id_setup_rx
12+
.. autocfunction:: csp_id.h::csp_id_get_host_bits
13+
.. autocfunction:: csp_id.h::csp_id_get_max_nodeid
14+
.. autocfunction:: csp_id.h::csp_id_get_max_port
15+
.. autocfunction:: csp_id.h::csp_id_is_broadcast
16+
17+
Fixup Functions for ZMQ CSP v1 little-endian
18+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
20+
.. autocfunction:: csp_id.h::csp_id_prepend_fixup_cspv1
21+
.. autocfunction:: csp_id.h::csp_id_strip_fixup_cspv1

include/csp/csp_id.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,112 @@ extern "C" {
66

77
#include <csp/csp.h>
88

9+
/**
10+
* Prepend CSP header fields into the packet's data buffer.
11+
*
12+
* This function encodes the CSP ID header into the packet and adjusts the data offset.
13+
*
14+
* @param packet Pointer to the packet to modify.
15+
*/
916
void csp_id_prepend(csp_packet_t * packet);
17+
18+
/**
19+
* Strip CSP header fields from the packet's data buffer.
20+
*
21+
* This function decodes the CSP ID header from the packet and adjusts the data offset.
22+
*
23+
* @param packet Pointer to the packet to modify.
24+
* @return 0 on success, -1 on failure.
25+
*/
1026
int csp_id_strip(csp_packet_t * packet);
27+
28+
/**
29+
* Setup reception information from CSP ID header.
30+
*
31+
* Typically called after stripping the header to configure addressing fields.
32+
*
33+
* @param packet Pointer to the received packet.
34+
* @return 0 on success, -1 on failure.
35+
*/
1136
int csp_id_setup_rx(csp_packet_t * packet);
37+
38+
/**
39+
* Get number of bits allocated for the host part of the address.
40+
*
41+
* @return Number of bits used for the host ID.
42+
*/
1243
unsigned int csp_id_get_host_bits(void);
44+
45+
/**
46+
* Get maximum allowed node ID.
47+
*
48+
* @return Maximum node ID based on current configuration.
49+
*/
1350
unsigned int csp_id_get_max_nodeid(void);
51+
52+
/**
53+
* Get maximum allowed port number.
54+
*
55+
* @return Maximum port number.
56+
*/
1457
unsigned int csp_id_get_max_port(void);
1558

59+
/**
60+
* Check whether a given address is a broadcast address.
61+
*
62+
* @param addr The address to test.
63+
* @param iface Interface to use for context (netmask, etc.).
64+
* @return 1 if broadcast, 0 otherwise.
65+
*/
1666
int csp_id_is_broadcast(uint16_t addr, csp_iface_t * iface);
1767

68+
/**
69+
* Get the size of the CSP header based on the configured version.
70+
*
71+
* This function returns the size in bytes of the CSP packet header,
72+
* depending on whether CSP version 1 or 2 is configured.
73+
*
74+
* @return The header size in bytes.
75+
*/
1876
int csp_id_get_header_size(void);
1977

2078
#if (CSP_FIXUP_V1_ZMQ_LITTLE_ENDIAN)
79+
80+
/**
81+
* Prepend CSPv1-compatible ID header (ZMQ fixup).
82+
*
83+
* Used when sending CSPv1 packets on little-endian ZMQ transport.
84+
*
85+
* @param packet Pointer to the packet to modify.
86+
*/
2187
void csp_id_prepend_fixup_cspv1(csp_packet_t * packet);
88+
89+
/**
90+
* Strip CSPv1-compatible ID header (ZMQ fixup).
91+
*
92+
* Used when receiving CSPv1 packets on little-endian ZMQ transport.
93+
*
94+
* @param packet Pointer to the packet to modify.
95+
* @return 0 on success, -1 on failure.
96+
*/
2297
int csp_id_strip_fixup_cspv1(csp_packet_t * packet);
98+
2399
#else
100+
101+
/**
102+
* Wrapper for csp_id_prepend when no fixup is required.
103+
*/
24104
static inline void csp_id_prepend_fixup_cspv1(csp_packet_t * packet) {
25105
csp_id_prepend(packet);
26106
}
107+
108+
/**
109+
* Wrapper for csp_id_strip when no fixup is required.
110+
*/
27111
static inline int csp_id_strip_fixup_cspv1(csp_packet_t * packet) {
28112
return csp_id_strip(packet);
29113
}
114+
30115
#endif
31116

32117
#ifdef __cplusplus

0 commit comments

Comments
 (0)