menu "RTPS"

    choice RTPS_LIMITS_PROFILE
        prompt "RTPS static limits profile"
        default RTPS_LIMITS_PROFILE_EMBEDDED
        help
            Selects the compile-time capacity limits (profile header) used by the
            rtps engine. Only the capacity caps differ between profiles.
            The storage MODEL (static vs dynamic) is a separate knob
            (RTPS_STORAGE_DYNAMIC below) and defaults to fully-static on ESP for
            every profile - selecting a relaxed profile does NOT enable heap
            storage. These caps are pure capacity limits and do NOT change any
            bytes on the wire.

            Note: the builtin discovery endpoints draw from the same pools, so
            the USABLE per-participant counts are lower than the raw caps:
            1 stateless writer + 1 stateless reader are reserved for SPDP, and
            2 stateful writers + 2 stateful readers for SEDP. E.g. the embedded
            profile's NUM_STATELESS_WRITERS=5 leaves 4 usable BEST_EFFORT
            writers. add_writer()/add_reader() name the exhausted pool and its
            cap when a creation fails.

        config RTPS_LIMITS_PROFILE_EMBEDDED
            bool "embedded (tight MCU caps)"
            help
                Tight caps sized for an ESP32-class MCU
                (rtps/config_esp32.hpp). This is the default and the smallest
                footprint.

        config RTPS_LIMITS_PROFILE_HOST
            bool "host (relaxed static caps)"
            help
                Relaxed static caps suitable for small-to-medium DDS graphs
                (rtps/config_desktop.hpp). Larger footprint than embedded.

        config RTPS_LIMITS_PROFILE_HOST_LARGE
            bool "host_large (generous static caps)"
            help
                Generous static caps for large DDS graphs
                (rtps/config_host_large.hpp). Significantly larger footprint;
                only appropriate on targets with plenty of RAM.
    endchoice

    menu "Custom capacity overrides (advanced)"
        # Each option below overrides ONE capacity cap of the selected limits
        # profile (0 = keep the profile's default). This gives fine-grained
        # control - e.g. raise only NUM_STATELESS_WRITERS instead of paying the
        # RAM for a whole relaxed profile. All values are capacity-only and do
        # NOT change any bytes on the wire. The builtin discovery endpoints
        # consume slots from these same pools (see the profile help above), so
        # size them as "usable + builtins". For a FULLY custom profile, a
        # source-level escape hatch also exists: define RTPS_CONFIG_HEADER to
        # your own header path.
        config RTPS_LIMIT_NUM_STATELESS_WRITERS
            int "NUM_STATELESS_WRITERS (0 = profile default)"
            default 0
            range 0 255
            help
                Stateless (BEST_EFFORT) writer pool; 1 slot is reserved for the builtin SPDP writer. 0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_STATELESS_READERS
            int "NUM_STATELESS_READERS (0 = profile default)"
            default 0
            range 0 255
            help
                Stateless (BEST_EFFORT) reader pool; 1 slot is reserved for the builtin SPDP reader. 0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_STATEFUL_WRITERS
            int "NUM_STATEFUL_WRITERS (0 = profile default)"
            default 0
            range 0 255
            help
                Stateful (RELIABLE) writer pool; 2 slots are reserved for the builtin SEDP writers. 0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_STATEFUL_READERS
            int "NUM_STATEFUL_READERS (0 = profile default)"
            default 0
            range 0 255
            help
                Stateful (RELIABLE) reader pool; 2 slots are reserved for the builtin SEDP readers. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_NUM_PARTICIPANTS
            int "MAX_NUM_PARTICIPANTS (0 = profile default)"
            default 0
            range 0 255
            help
                Maximum domain participants per process. 0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_WRITERS_PER_PARTICIPANT
            int "NUM_WRITERS_PER_PARTICIPANT (0 = profile default)"
            default 0
            range 0 255
            help
                Per-participant writer cap; the 3 builtin discovery writers count against it. 0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_READERS_PER_PARTICIPANT
            int "NUM_READERS_PER_PARTICIPANT (0 = profile default)"
            default 0
            range 0 255
            help
                Per-participant reader cap; the 3 builtin discovery readers count against it. 0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_WRITER_PROXIES_PER_READER
            int "NUM_WRITER_PROXIES_PER_READER (0 = profile default)"
            default 0
            range 0 255
            help
                Remote writers a single reader can match. The builtin discovery
                readers hold one per remote participant, so raise this with
                SPDP_MAX_NUMBER_FOUND_PARTICIPANTS; a participant whose discovery
                proxies do not fit is forgotten and retried on its next announcement.
                0 keeps the selected profile's value.

        config RTPS_LIMIT_NUM_READER_PROXIES_PER_WRITER
            int "NUM_READER_PROXIES_PER_WRITER (0 = profile default)"
            default 0
            range 0 255
            help
                Remote readers a single writer can match. The builtin discovery
                writers hold one per remote participant, so raise this with
                SPDP_MAX_NUMBER_FOUND_PARTICIPANTS. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_NUM_UNMATCHED_REMOTE_WRITERS
            int "MAX_NUM_UNMATCHED_REMOTE_WRITERS (0 = profile default)"
            default 0
            range 0 255 if RTPS_LIMITS_PROFILE_EMBEDDED
            range 0 65535
            help
                Registry of discovered-but-unmatched remote writers. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_NUM_UNMATCHED_REMOTE_READERS
            int "MAX_NUM_UNMATCHED_REMOTE_READERS (0 = profile default)"
            default 0
            range 0 255 if RTPS_LIMITS_PROFILE_EMBEDDED
            range 0 65535
            help
                Registry of discovered-but-unmatched remote readers. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_NUM_READER_CALLBACKS
            int "MAX_NUM_READER_CALLBACKS (0 = profile default)"
            default 0
            range 0 255
            help
                Callback registrations per reader. 0 keeps the selected profile's value.

        config RTPS_LIMIT_HISTORY_SIZE_STATELESS
            int "HISTORY_SIZE_STATELESS (0 = profile default)"
            default 0
            range 0 255
            help
                History depth (samples) per stateless endpoint. 0 keeps the selected profile's value.

        config RTPS_LIMIT_HISTORY_SIZE_STATEFUL
            int "HISTORY_SIZE_STATEFUL (0 = profile default)"
            default 0
            range 0 255
            help
                History depth (samples) per stateful endpoint. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_TYPENAME_LENGTH
            int "MAX_TYPENAME_LENGTH (0 = profile default)"
            default 0
            range 0 255
            help
                Maximum DDS type-name length. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_TOPICNAME_LENGTH
            int "MAX_TOPICNAME_LENGTH (0 = profile default)"
            default 0
            range 0 255
            help
                Maximum DDS topic-name length. 0 keeps the selected profile's value.

        config RTPS_LIMIT_MAX_NUM_UDP_CONNECTIONS
            int "MAX_NUM_UDP_CONNECTIONS (0 = profile default)"
            default 0
            range 0 255
            help
                Transport channel pool: 2 shared multicast channels + 2 unicast
                channels per participant are permanently bound, and dedicated
                endpoint ports draw from the same pool at runtime. Must be at
                least 2 + 2*MAX_NUM_PARTICIPANTS (cross-checked at build time).
                0 keeps the selected profile's value.

        config RTPS_LIMIT_SPDP_MAX_NUMBER_FOUND_PARTICIPANTS
            int "SPDP_MAX_NUMBER_FOUND_PARTICIPANTS (0 = profile default)"
            default 0
            range 0 255 if RTPS_LIMITS_PROFILE_EMBEDDED
            range 0 65535
            help
                Remote participants a participant can track at once (the SPDP
                proxy pool). A participant beyond this is ignored until a slot
                frees: its endpoints are never matched and its data is dropped,
                with no log. Size it for the whole domain, not just the peers you
                talk to: a ROS 2 host with a dozen nodes is a dozen participants.
                Each slot holds one ParticipantProxyData (a few hundred bytes with
                the embedded profile's single locator per list). The constant is
                uint8_t under the embedded profile and uint16_t under host and
                host_large, hence the ranges. 0 keeps the selected profile's
                value (10 embedded, 32 host, 128 host_large).

        config RTPS_LIMIT_SPDP_MAX_NUM_LOCATORS
            int "SPDP_MAX_NUM_LOCATORS (0 = profile default)"
            default 0
            range 0 255
            help
                Locators kept per list of every remote participant proxy. A
                proxy has 4 lists (metatraffic and default, unicast and
                multicast), so each of the SPDP_MAX_NUMBER_FOUND_PARTICIPANTS
                slots grows by 4 x 12 bytes per locator. A peer on several
                networks announces one unicast locator per interface; the
                engine keeps the first ones and prefers one on our network, so
                1 (the embedded default) already reaches a multi-homed peer.
                Raise it to keep every announced locator. 0 keeps the selected
                profile's value (1 embedded, 8 host, 16 host_large).

    endmenu

    menu "Discovery and reliability timing (advanced)"
        # Each option overrides ONE timing constant of the selected profile
        # (0 = keep the profile's default). They change only WHEN discovery
        # and reliability messages are sent, never their bytes.
        config RTPS_SPDP_RESEND_PERIOD_MS
            int "SPDP_RESEND_PERIOD_MS: participant announcement period (0 = profile default)"
            default 0
            range 0 65535
            help
                How often (ms) every local participant announces itself (SPDP
                DATA on the metatraffic multicast). Peers refresh our liveliness
                on each announcement and drop us when they miss them for a
                whole lease, so keep this well below
                SPDP_DEFAULT_REMOTE_LEASE_DURATION_S (at least 2-3 announcements
                per lease). It also paces the liveliness check of remote
                participants: every (SPDP_CYCLECOUNT_HEARTBEAT + 1) announce
                rounds. 0 keeps the selected profile's value (2000 embedded,
                1000 host).

        config RTPS_SPDP_CYCLECOUNT_HEARTBEAT
            int "SPDP_CYCLECOUNT_HEARTBEAT: announce rounds between liveliness checks (0 = profile default)"
            default 0
            range 0 255
            help
                Remote participants are checked for liveliness (and the expired
                ones removed, with every matched endpoint) every
                (SPDP_CYCLECOUNT_HEARTBEAT + 1) announcement rounds, i.e. every
                (SPDP_CYCLECOUNT_HEARTBEAT + 1) * SPDP_RESEND_PERIOD_MS. A
                silent peer therefore lingers up to that long past its lease.
                0 keeps the selected profile's value (2 on every profile).

        config RTPS_SF_WRITER_HB_PERIOD_MS
            int "SF_WRITER_HB_PERIOD_MS: reliable writer heartbeat period (0 = profile default)"
            default 0
            range 0 65535
            help
                How often (ms) a RELIABLE (stateful) writer sends a HEARTBEAT to
                its matched readers, which is what lets a reader notice and
                NACK a missed sample. While a remote reader has unacknowledged
                changes the writer sends them four times as often (a quarter of
                this). Lower it for faster repair at the cost of metatraffic.
                0 keeps the selected profile's value (4000 embedded, 2000 host).

        config RTPS_SPDP_DEFAULT_REMOTE_LEASE_DURATION_S
            int "SPDP_DEFAULT_REMOTE_LEASE_DURATION_S: our announced lease / default remote lease, seconds (0 = profile default)"
            default 0
            range 0 3600
            help
                Two things: the lease duration every local participant
                announces for itself (peers drop us after that long without an
                announcement - keep it at least 2-3 times
                SPDP_RESEND_PERIOD_MS), and the lease assumed for a remote
                participant that announces none (usually overwritten by the
                remote's own value, capped by SPDP_MAX_REMOTE_LEASE_DURATION_S).
                0 keeps the selected profile's value (5 embedded, 100 host).

        config RTPS_SPDP_MAX_REMOTE_LEASE_DURATION_S
            int "SPDP_MAX_REMOTE_LEASE_DURATION_S: cap on a remote lease, seconds (0 = profile default)"
            default 0
            range 0 3600
            help
                Absolute maximum lease honoured for a remote participant,
                whatever it announces: a silent peer is dropped after
                min(its announced lease, this). Lower it to forget a vanished
                peer sooner than its own (often generous) lease; never set it
                below a peer's announcement period or it is dropped while
                alive. 0 keeps the selected profile's value (90 embedded, 180
                host).

    endmenu

    menu "Tasks (advanced)"
        # Priorities and stacks of the engine's tasks (0 = keep the profile's
        # default).
        config RTPS_THREAD_POOL_READER_PRIO
            int "THREAD_POOL_READER_PRIO: worker pool and reactor (0 = profile default)"
            default 0
            range 0 24
            help
                FreeRTOS priority of the transport's tasks: the worker pool
                ("rtps_worker_<n>"), which sends and receives all RTPS traffic
                (publish() only queues a sample; a worker sends it) and runs
                every reader and matched callback, and the reactor
                ("rtps_reactor"), the select() loop that hands received
                datagrams to the pool. 0 keeps the selected profile's value
                (5 on the embedded profile, 3 on the host profiles).

                Raise it when a busy task of higher priority (a UI renderer, a
                long computation) can run on the same core as these tasks:
                until it yields, nothing is sent or received. Bands (QosBand)
                order work inside the pool and cannot help when the pool's
                tasks are not scheduled. The callbacks then run at this
                priority too, so keep them short.

        config RTPS_THREAD_POOL_READER_STACKSIZE
            int "THREAD_POOL_READER_STACKSIZE: worker pool and reactor stack, bytes (0 = profile default)"
            default 0
            range 0 65535
            help
                Stack of each transport task: the worker pool tasks
                ("rtps_worker_<n>"), which also run every reader and matched
                callback, and the reactor ("rtps_reactor"). Raise it when a
                callback needs more than the default; a value below 2048 is
                refused at build time. 0 keeps the selected profile's value
                (6144 on the embedded profile).

        config RTPS_SPDP_WRITER_PRIO
            int "SPDP_WRITER_PRIO: protocol task priority (0 = profile default)"
            default 0
            range 0 24
            help
                FreeRTOS priority of the protocol task ("rtps_protocol"), which
                sends the SPDP announcements, the reliable writers' HEARTBEATs
                and runs the liveliness checks. It must get scheduled at least
                every SPDP_RESEND_PERIOD_MS or peers drop this participant.
                0 keeps the selected profile's value (5 on the embedded
                profile).

        config RTPS_SPDP_WRITER_STACKSIZE
            int "SPDP_WRITER_STACKSIZE: protocol task stack, bytes (0 = profile default)"
            default 0
            range 0 65535
            help
                Stack of the protocol task ("rtps_protocol"). The engine raises
                anything below 4096 to 4096, and a value below 2048 is refused
                at build time. 0 keeps the selected profile's value (4096 on the
                embedded profile).

    endmenu

    config RTPS_DOMAIN_ID
        int "Domain id"
        default 0
        range 0 232
        help
            The DDS domain this device's participants join - the equivalent of
            ROS_DOMAIN_ID on a ROS 2 host. The discovery and user-traffic port
            base (7400 + 250 * id) and byte 9 of the participants' GUID prefix
            derive from it, so every participant that should see each other
            must use the same value. Compile-time: all participants in one
            firmware share it. 0 is the DDS default and matches a ROS 2 host
            with no ROS_DOMAIN_ID set.

    config RTPS_STORAGE_DYNAMIC
        bool "Use dynamic (heap) history/queue storage"
        default n
        help
            By default the engine uses fully-static, zero-heap history and queue
            storage on ESP targets (std::array), independent of the limits
            profile above: when a history fills it drops the oldest sample.
            Enable this to use heap-backed storage (std::deque) that instead
            GROWS on demand to retain samples. Off by default so the MCU keeps
            deterministic, zero-heap storage; enable only on targets that can
            afford heap growth. Does not change any bytes on the wire.

    config RTPS_ENABLE_FRAGMENTATION
        bool "Enable best-effort DATA_FRAG fragmentation"
        default n
        help
            Enables sending and receiving samples larger than a single RTPS DATA
            submessage (> ~64 KB) by splitting them into best-effort DATA_FRAG
            submessages and reassembling them on receive (interoperates with
            FastDDS / ROS 2). Default OFF so the MCU pays no code or memory cost
            for it in the common (small-sample) case. When ON, reassembly is
            bounded by RTPS_MAX_SAMPLE_SIZE (256 KB on the embedded profile) and
            the participant's max payload size rises accordingly.

    config RTPS_ENABLE_RPC
        bool "Enable RPC: services + actions (RMI/AMI)"
        default y
        help
            Compiles in the request/reply (services) and goal (actions) layers of
            the RtpsParticipant facade - both the ROS 2-interoperable
            (add_service_*/add_action_*) and native (add_native_*) variants.
            Disable to drop all of that code (and its std::thread/std::future use)
            when the device only needs pub/sub, saving flash. Pure pub/sub is
            unaffected either way. Default ON.

endmenu
