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. With static storage HISTORY_SIZE_STATEFUL must be at least this minus 3 (the SEDP writer keeps one change per user writer; checked at compile time). 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. With static storage HISTORY_SIZE_STATEFUL must be at least this minus 3 (the SEDP writer keeps one change per user reader; checked at compile time). 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
                Remote writers remembered from discovery, matched or not (a peer announces
                an endpoint once, so a reader created later matches it from this registry;
                a record leaves on the writer's dispose or its participant's departure).
                Size it for every remote user writer on the domain. 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
                Remote readers remembered from discovery, matched or not (see
                MAX_NUM_UNMATCHED_REMOTE_WRITERS). Size it for every remote user reader on
                the domain. 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. The two SEDP writers use it too, one change per live user endpoint: with static storage it must be at least NUM_WRITERS_PER_PARTICIPANT - 3 and NUM_READERS_PER_PARTICIPANT - 3 (checked at compile time), or a participant could not announce all its endpoints. 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). With the pool full, a newly announcing participant
                evicts the oldest one none of your endpoints match (see
                RTPS_SPDP_EVICT_UNUSED_PARTICIPANTS, with a warning each time);
                with eviction off it 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_SFR_ACKNACK_MIN_INTERVAL_MS
            int "SFR_ACKNACK_MIN_INTERVAL_MS: shortest gap between a reader's ACKNACKs to one writer (0 = profile default)"
            default 0
            range 0 65535
            help
                A RELIABLE reader that is missing samples answers a writer's
                HEARTBEATs with an ACKNACK at most once per this many ms (a
                HEARTBEAT it misses nothing for gets no answer when its
                FinalFlag is set). Each ACKNACK asks for up to 32 samples,
                which the writer resends at once, so this bounds the repair
                rate; it also keeps a reader that fell behind from answering
                every stale HEARTBEAT it works through, each answer bringing a
                GAP + HEARTBEAT back. 0 keeps the profile's value (100).

        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).

        config RTPS_SPDP_EVICT_UNUSED_PARTICIPANTS
            bool "Evict an unused remote participant when the pool is full"
            default y
            help
                With the remote-participant pool (SPDP_MAX_NUMBER_FOUND_PARTICIPANTS)
                full, or the builtin discovery endpoints' proxy pools
                (NUM_WRITER_PROXIES_PER_READER / NUM_READER_PROXIES_PER_WRITER,
                one slot per remote participant each), a newly announcing
                participant takes the slot of the
                oldest one none of this participant's user endpoints match
                (an expired one first), so a peer you need can still be
                discovered on a domain crowded with peers you do not. Never of
                a participant discovered less than SPDP_EVICT_MIN_AGE_MS ago;
                a peer evicted before waits SPDP_EVICT_READMIT_HOLDOFF_MS;
                then one eviction per SPDP_RESEND_PERIOD_MS from the budget
                of its kind (former evictees and never-evicted peers each
                have their own, so neither starves the other and the churn is
                at most two per period); each logged as a warning.
                Off: a participant beyond the pool is ignored until a lease
                frees a slot (the previous behaviour).

        config RTPS_SPDP_EVICT_MIN_AGE_MS
            int "SPDP_EVICT_MIN_AGE_MS: youngest participant eviction may forget, ms (0 = profile default)"
            depends on RTPS_SPDP_EVICT_UNUSED_PARTICIPANTS
            default 0
            range 0 600000
            help
                A participant discovered more recently than this is never
                evicted: its endpoint announcements (SEDP) may still be on the
                way, so it looks unused before it is. Keep it above the time a
                peer needs to announce its endpoints after SPDP. 0 keeps the
                selected profile's value (3 x SPDP_RESEND_PERIOD_MS: 6000
                embedded, 3000 host).

        config RTPS_SPDP_EVICT_READMIT_HOLDOFF_MS
            int "SPDP_EVICT_READMIT_HOLDOFF_MS: no eviction for a peer evicted this recently, ms (0 = profile default)"
            depends on RTPS_SPDP_EVICT_UNUSED_PARTICIPANTS
            default 0
            range 0 600000
            help
                A peer this participant evicted less than this long ago has
                nothing evicted for it when it announces again (a free slot it
                still takes at once). On a domain that stays bigger than the
                pool, the peers that do not fit re-announce every period and
                would otherwise take turns displacing each other ahead of a
                peer never seen before - the one you may need (which has its
                own one-per-period eviction budget, as the former evictees have
                theirs). Longer: less churn, but a peer you evicted and now
                need waits this long. 0
                keeps the selected profile's value (5 x SPDP_RESEND_PERIOD_MS:
                10000 embedded, 5000 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
                (8192 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
