11 tracking_[device_id].interval_ms = interval_ms;
15 auto it = tracking_.find(device_id);
16 return (it != tracking_.end()) ? it->second.interval_ms : 0;
22 t.
next_update = (initial_delay_ms == 0) ? 0 : (now + initial_delay_ms);
28 auto it = tracking_.find(device_id);
29 if (it == tracking_.end())
40 tracking_[device_id].next_update = abs_time;
44 auto it = tracking_.find(device_id);
45 return (it != tracking_.end()) ? it->second.next_update : 0;
49 auto it = tracking_.find(device_id);
50 return (it != tracking_.end()) ? it->second.poll_deadline : 0;
54 auto it = tracking_.find(device_id);
55 if (it == tracking_.end())
62 auto it = tracking_.find(device_id);
63 if (it == tracking_.end())
90 auto it = tracking_.find(device_id);
91 if (it == tracking_.end())
93 it->second.status_poll_failures = 0;
94 it->second.auth_poll_failures = 0;
98 auto it = tracking_.find(device_id);
99 return (it != tracking_.end()) ? it->second.status_poll_failures : 0;
103 auto it = tracking_.find(device_id);
104 return (it != tracking_.end()) ? it->second.auth_poll_failures : 0;
108 for (
auto &pair : tracking_) {
122uint32_t StatusPollPolicy::retry_delay_ms(uint8_t consecutive_failures,
bool auth_like) {
124 if (consecutive_failures <= 1)
126 if (consecutive_failures == 2)
130 if (consecutive_failures <= 1)
132 if (consecutive_failures == 2)
134 if (consecutive_failures == 3)
136 if (consecutive_failures == 4)
void set_interval(const std::string &device_id, uint32_t interval_ms)
Set the configured follow-up poll interval (ms; 0 = legacy one-shot settle only).
bool is_tracking_active(const std::string &device_id, uint32_t now) const
True when the device has an active bounded polling window (deadline set and not expired).
uint32_t get_next_update(const std::string &device_id) const
uint32_t get_interval(const std::string &device_id) const
Return the configured interval (0 when not set or unconfigured).
void clear_failure_streaks(const std::string &device_id)
Reset failure streaks after a successful exchange response.
void set_next_update(const std::string &device_id, uint32_t abs_time)
Schedule the next poll at an absolute millis() timestamp.
uint32_t on_exchange_failed(const std::string &device_id, bool auth_like, uint32_t now)
Record a failed background poll; apply backoff or clear tracking if the window expired.
void begin_tracking(const std::string &device_id, uint32_t initial_delay_ms, uint32_t now)
Begin bounded follow-up polling after a command or remote activity.
uint8_t get_status_poll_failures(const std::string &device_id) const
uint8_t get_auth_poll_failures(const std::string &device_id) const
uint32_t get_poll_deadline(const std::string &device_id) const
void clear(const std::string &device_id)
Stop all polling for a device and reset failure counts. Preserves interval_ms.
std::optional< std::string > pop_due_device(uint32_t now)
Return and consume the first device whose next_update is overdue.
static constexpr uint32_t STATUS_RETRY_AFTER_FAIL_STEP4_MS
Fourth retry after a silent failure.
static constexpr uint32_t STATUS_AUTH_RETRY_AFTER_FAIL_MAX_MS
Steady-state after repeated auth failures.
static constexpr uint32_t STATUS_RETRY_AFTER_FAIL_STEP3_MS
Third retry after a silent failure.
static constexpr uint32_t MAX_TRACKED_STATUS_POLL_WINDOW_MS
Hard stop for bounded follow-up polling after a command or remote activity.
static constexpr uint32_t STATUS_RETRY_AFTER_FAIL_MS
First retry after a silent failure.
static constexpr uint32_t STATUS_RETRY_AFTER_FAIL_MAX_MS
Steady-state backoff after many silent failures.
static constexpr uint32_t STATUS_AUTH_RETRY_AFTER_FAIL_STEP2_MS
Second retry.
static constexpr uint32_t STATUS_AUTH_RETRY_AFTER_FAIL_MS
First retry after a challenge-seen failure.
static constexpr uint32_t STATUS_RETRY_AFTER_FAIL_STEP2_MS
Second retry after a silent failure.
Per-device poll scheduling, failure backoff, and follow-up-poll state machine.
Per-device poll scheduling state.
uint8_t auth_poll_failures
Consecutive background poll failures that saw a 0x3C challenge.
uint8_t status_poll_failures
Consecutive background poll failures (silent — no reply).
uint32_t poll_deadline
Hard stop for bounded follow-up polling.
uint32_t next_update
Absolute millis() timestamp for the next poll; 0 = idle.