11#if DETWS_ENABLE_MDNS_ADAPTIVE
13uint32_t detws_mdns_refresh_interval(uint32_t ttl_s)
16 uint64_t half_ms = (uint64_t)ttl_s * 1000 / 2;
17 return half_ms > 0xFFFFFFFFu ? 0xFFFFFFFFu : (uint32_t)half_ms;
20void detws_mdns_beacon_init(MdnsBeacon *b, uint32_t base_ms, uint32_t max_ms, uint16_t hi_thresh)
25 b->max_ms = max_ms < base_ms ? base_ms : max_ms;
27 b->hi_thresh = hi_thresh ? hi_thresh : 1;
30uint32_t detws_mdns_beacon_adapt(MdnsBeacon *b, uint16_t contention)
34 if (contention >= b->hi_thresh)
36 uint32_t up = b->cur_ms << 1;
37 if (up < b->cur_ms || up > b->max_ms)
41 else if (contention == 0)
43 uint32_t down = b->cur_ms >> 1;
44 if (down < b->base_ms)
51bool detws_mdns_beacon_due(
const MdnsBeacon *b, uint32_t last_ms, uint32_t now_ms)
55 uint32_t elapsed = now_ms - last_ms;
56 return elapsed >= b->cur_ms;
59bool detws_mdns_beacon_presleep_due(
const MdnsBeacon *b, uint32_t last_ms, uint32_t now_ms, uint32_t sleep_ms)
63 uint32_t elapsed = now_ms - last_ms;
65 uint64_t after = (uint64_t)elapsed + sleep_ms;
66 return after >= b->cur_ms;
Adaptive mDNS beacon scheduling: RF-aware backoff, TTL refresher, auto-sleep beacon (DETWS_ENABLE_MDN...