DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
dds.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file dds.h
6 * @brief DDS / RTPS wire-protocol codec (DETWS_ENABLE_DDS).
7 *
8 * DDS (OMG Data Distribution Service) publishes on the wire as **RTPS** (DDSI-RTPS, the Real-Time
9 * Publish-Subscribe protocol), normally over UDP multicast. An RTPS **message** is a 20-octet header
10 * followed by a sequence of **submessages**:
11 *
12 * Header (20): "RTPS" | protocol version (2) | vendorId (2) | guidPrefix (12)
13 * Submessage: submessageId (1) | flags (1) | octetsToNextHeader (2, endian per the E flag) | body
14 *
15 * This is the message + submessage framing codec: `detws_rtps_header` / `detws_rtps_submessage` build
16 * them and `detws_rtps_parse` validates the header (magic + version) and walks the submessages,
17 * surfacing each via a callback. The per-submessage bodies (DATA serialized-payload/CDR, HEARTBEAT
18 * sequence-number sets, the discovery SPDP/SEDP topics) layer on top of this framing.
19 *
20 * Pure, zero heap, no stdlib, host-testable.
21 */
22
23#ifndef DETERMINISTICESPASYNCWEBSERVER_DDS_H
24#define DETERMINISTICESPASYNCWEBSERVER_DDS_H
25
26#include "ServerConfig.h"
27#include <stddef.h>
28#include <stdint.h>
29
30#if DETWS_ENABLE_DDS
31
32/** @brief RTPS submessage kinds (DDSI-RTPS 8.3.7) + the flag bit for little-endian. */
33// RTPS submessage kinds + the little-endian flag bit + fixed lengths: wire values (the flag is OR'd),
34// so integer constants in a namespacing struct.
35struct Rtps
36{
37 static constexpr uint8_t RTPS_SM_PAD = 0x01;
38 static constexpr uint8_t RTPS_SM_ACKNACK = 0x06;
39 static constexpr uint8_t RTPS_SM_HEARTBEAT = 0x07;
40 static constexpr uint8_t RTPS_SM_GAP = 0x08;
41 static constexpr uint8_t RTPS_SM_INFO_TS = 0x09;
42 static constexpr uint8_t RTPS_SM_INFO_SRC = 0x0c;
43 static constexpr uint8_t RTPS_SM_INFO_REPLY_IP4 = 0x0d;
44 static constexpr uint8_t RTPS_SM_INFO_DST = 0x0e;
45 static constexpr uint8_t RTPS_SM_INFO_REPLY = 0x0f;
46 static constexpr uint8_t RTPS_SM_DATA = 0x15;
47 static constexpr uint8_t RTPS_SM_DATA_FRAG = 0x16;
48 static constexpr uint8_t RTPS_FLAG_ENDIAN = 0x01; ///< E flag: submessage (and header) fields are little-endian.
49 static constexpr uint8_t RTPS_HEADER_LEN = 20;
50 static constexpr uint8_t RTPS_GUIDPREFIX_LEN = 12;
51};
52
53/** @brief RTPS protocol version carried in the header (major, minor). */
54extern const uint8_t RTPS_VERSION[2]; ///< {2, 4}.
55
56/**
57 * @brief Build the 20-octet RTPS message header.
58 * @param guid_prefix 12-byte participant GUID prefix.
59 * @param vendor_id 2-byte vendor id (0x0000 = unknown).
60 * @return 20, or 0 if @p cap < 20 or a pointer is null.
61 */
62size_t detws_rtps_header(const uint8_t *guid_prefix, const uint8_t *vendor_id, uint8_t *out, size_t cap);
63
64/**
65 * @brief Build one RTPS submessage `[id][flags][octetsToNextHeader][body]`.
66 * @param id RTPS_SM_*.
67 * @param flags submessage flags (bit 0 = little-endian; set RTPS_FLAG_ENDIAN for LE bodies).
68 * @param body submessage contents (may be null when body_len == 0).
69 * @param body_len contents length (the octetsToNextHeader value).
70 * @return 4 + body_len bytes written, or 0 if it won't fit.
71 */
72size_t detws_rtps_submessage(uint8_t id, uint8_t flags, const uint8_t *body, uint16_t body_len, uint8_t *out,
73 size_t cap);
74
75/** @brief One submessage surfaced by detws_rtps_parse. */
76typedef void (*DetwsRtpsCb)(uint8_t id, uint8_t flags, const uint8_t *body, size_t body_len, void *arg);
77
78/**
79 * @brief Validate an RTPS message header and walk its submessages.
80 * @return true if the header is a well-formed RTPS message (magic + version <= ours) and every
81 * submessage fits. An octetsToNextHeader of 0 on the last submessage means "to end of message".
82 */
83bool detws_rtps_parse(const uint8_t *msg, size_t len, DetwsRtpsCb cb, void *arg);
84
85#endif // DETWS_ENABLE_DDS
86#endif // DETERMINISTICESPASYNCWEBSERVER_DDS_H
User-facing configuration for DeterministicESPAsyncWebServer.