SensESP 3.6.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
wifi_watchdog_policy.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_SYSTEM_WIFI_WATCHDOG_POLICY_H_
2#define SENSESP_SRC_SENSESP_SYSTEM_WIFI_WATCHDOG_POLICY_H_
3
4#include <cstdint>
5
7
8namespace sensesp {
9
18
40
57 public:
58 void set_link_state(WiFiWatchdogLink link, uint32_t now_ms) {
59 switch (link) {
61 armed_ = true;
62 down_ = false;
63 break;
65 if (!down_) {
66 down_ = true;
67 down_since_ms_ = now_ms;
68 }
69 break;
71 down_ = false;
72 break;
73 }
74 }
75
76 bool restart_due(uint32_t now_ms, uint32_t timeout_ms) const {
77 if (timeout_ms == 0 || !armed_ || !down_) {
78 return false;
79 }
80 return static_cast<uint32_t>(now_ms - down_since_ms_) >= timeout_ms;
81 }
82
83 private:
84 bool armed_ = false;
85 bool down_ = false;
86 uint32_t down_since_ms_ = 0;
87};
88
89} // namespace sensesp
90
91#endif // SENSESP_SRC_SENSESP_SYSTEM_WIFI_WATCHDOG_POLICY_H_
Pure decision logic for the WiFi watchdog.
void set_link_state(WiFiWatchdogLink link, uint32_t now_ms)
bool restart_due(uint32_t now_ms, uint32_t timeout_ms) const
WiFiWatchdogLink wifi_watchdog_link_from_state(WiFiState state)
Map a NetworkState (WiFiState) to the watchdog's view of the link.
WiFiWatchdogLink
Link state as seen by the WiFi watchdog.