|
12 | 12 |
|
13 | 13 | namespace arduino { namespace time {
|
14 | 14 |
|
| 15 | + /** |
| 16 | + * The TimedAttempt class manages retry attempts with configurable delays. |
| 17 | + * It allows setting minimum and maximum delays, and provides methods to |
| 18 | + * begin, retry, reset, and check the status of attempts. |
| 19 | + */ |
15 | 20 | class TimedAttempt {
|
16 | 21 |
|
17 | 22 | public:
|
| 23 | + /** |
| 24 | + * Constructor to initialize TimedAttempt with minimum and maximum delay |
| 25 | + * @param minDelay: minimum delay between attempts |
| 26 | + * @param maxDelay: maximum delay between attempts |
| 27 | + */ |
18 | 28 | TimedAttempt(unsigned long minDelay, unsigned long maxDelay);
|
19 | 29 |
|
| 30 | + /** |
| 31 | + * Begin the attempt with a fixed delay |
| 32 | + * @param delay: fixed delay between attempts |
| 33 | + */ |
20 | 34 | void begin(unsigned long delay);
|
| 35 | + |
| 36 | + /** |
| 37 | + * Begin the attempt with a range of delays |
| 38 | + * @param minDelay: minimum delay between attempts |
| 39 | + * @param maxDelay: maximum delay between attempts |
| 40 | + */ |
21 | 41 | void begin(unsigned long minDelay, unsigned long maxDelay);
|
| 42 | + |
| 43 | + /** |
| 44 | + * Reconfigure the attempt with new minimum and maximum delays and reload |
| 45 | + * @param minDelay: new minimum delay between attempts |
| 46 | + * @param maxDelay: new maximum delay between attempts |
| 47 | + * @return the new delay after reconfiguration |
| 48 | + */ |
22 | 49 | unsigned long reconfigure(unsigned long minDelay, unsigned long maxDelay);
|
| 50 | + |
| 51 | + /** |
| 52 | + * Retry the attempt, incrementing the retry count and reloading the delay |
| 53 | + * @return the new delay after retry |
| 54 | + */ |
23 | 55 | unsigned long retry();
|
| 56 | + |
| 57 | + /** |
| 58 | + * Reload the delay based on the retry count and return the new delay |
| 59 | + * @return the new delay after reload |
| 60 | + */ |
24 | 61 | unsigned long reload();
|
| 62 | + |
| 63 | + /** |
| 64 | + * Reset the retry count to zero |
| 65 | + */ |
25 | 66 | void reset();
|
| 67 | + |
| 68 | + /** |
| 69 | + * Check if a retry has been attempted |
| 70 | + * @return true if a retry has been attempted, false otherwise |
| 71 | + */ |
26 | 72 | bool isRetry();
|
| 73 | + |
| 74 | + /** |
| 75 | + * Check if the current attempt has expired based on the delay |
| 76 | + * @return true if the current attempt has expired, false otherwise |
| 77 | + */ |
27 | 78 | bool isExpired();
|
| 79 | + |
| 80 | + /** |
| 81 | + * Get the current retry count |
| 82 | + * @return the current retry count |
| 83 | + */ |
28 | 84 | unsigned int getRetryCount();
|
| 85 | + |
| 86 | + /** |
| 87 | + * Get the current wait time for the next retry |
| 88 | + * @return the current wait time for the next retry |
| 89 | + */ |
29 | 90 | unsigned int getWaitTime();
|
30 | 91 |
|
31 | 92 | private:
|
|
0 commit comments