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);
29 auto it = tracking_.find(device_id);
30 if (it == tracking_.end())
42 tracking_[device_id].next_update = abs_time;
46 auto it = tracking_.find(device_id);
47 return (it != tracking_.end()) ? it->second.next_update : 0;
51 auto it = tracking_.find(device_id);
52 return (it != tracking_.end()) ? it->second.poll_deadline : 0;
56 auto it = tracking_.find(device_id);
57 if (it == tracking_.end())
64 auto it = tracking_.find(device_id);
65 if (it == tracking_.end())
92 auto it = tracking_.find(device_id);
93 if (it == tracking_.end())
95 it->second.status_poll_failures = 0;
96 it->second.auth_poll_failures = 0;
100 auto it = tracking_.find(device_id);
101 if (it != tracking_.end())
102 it->second.stop_settle =
true;
106 auto it = tracking_.find(device_id);
107 if (it == tracking_.end())
109 const bool marked = it->second.stop_settle;
110 it->second.stop_settle =
false;
115 auto it = tracking_.find(device_id);
116 return (it != tracking_.end()) ? it->second.status_poll_failures : 0;
120 auto it = tracking_.find(device_id);
121 return (it != tracking_.end()) ? it->second.auth_poll_failures : 0;
125 for (
auto &pair : tracking_) {
139uint32_t StatusPollPolicy::retry_delay_ms(uint8_t consecutive_failures,
bool auth_like) {
141 if (consecutive_failures <= 1)
142 return STATUS_AUTH_RETRY_AFTER_FAIL_MS;
143 if (consecutive_failures == 2)
144 return STATUS_AUTH_RETRY_AFTER_FAIL_STEP2_MS;
145 return STATUS_AUTH_RETRY_AFTER_FAIL_MAX_MS;
147 if (consecutive_failures <= 1)
148 return STATUS_RETRY_AFTER_FAIL_MS;
149 if (consecutive_failures == 2)
150 return STATUS_RETRY_AFTER_FAIL_STEP2_MS;
151 if (consecutive_failures == 3)
152 return STATUS_RETRY_AFTER_FAIL_STEP3_MS;
153 if (consecutive_failures == 4)
154 return STATUS_RETRY_AFTER_FAIL_STEP4_MS;
155 return STATUS_RETRY_AFTER_FAIL_MAX_MS;
void mark_stop_settle(const std::string &device_id)
Mark the device's next poll as the one confirming an accepted STOP, so it gets STOP_SETTLE_POLL_TRIES...
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
bool take_stop_settle(const std::string &device_id)
Consume the mark set by mark_stop_settle(): true once, for the first poll dispatched after it.
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.
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.
bool stop_settle
The next poll confirms an accepted STOP (see STOP_SETTLE_POLL_TRIES).
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.