-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback_timeout.ino
More file actions
69 lines (58 loc) · 1.68 KB
/
Copy pathcallback_timeout.ino
File metadata and controls
69 lines (58 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <Arduino.h>
#include <ESPRebootManager.h>
#include <cstdio>
ESPRebootManager rebootManager;
bool submitted = false;
bool printedFinal = false;
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
ESPRebootManagerConfig config;
config.taskName = "reboot-manager";
config.callbackTimeoutMs = 200;
config.rebootExecutor = []() {
Serial.println("[executor] should not run when callback times out");
};
if (!rebootManager.init(config)) {
Serial.println("Failed to init ESPRebootManager");
return;
}
rebootManager.onRebootRequest([](const RebootRequestContext &) {
RebootVote vote;
std::snprintf(vote.detail, sizeof(vote.detail), "guard took too long");
delay(600);
vote.allow = true;
return vote;
});
rebootManager.onEvaluation([](const RebootEvaluation &evaluation) {
Serial.printf(
"[evaluation] accepted=%u code=%u blocker=%s detail=%s\n",
static_cast<unsigned>(evaluation.accepted),
static_cast<unsigned>(evaluation.code),
evaluation.blockerName,
evaluation.detail
);
});
RebootSubmitResult result = rebootManager.requestReboot("simulate-timeout", 0);
submitted = (result.status == RebootSubmitStatus::Queued);
Serial.printf("submit status=%u\n", static_cast<unsigned>(result.status));
}
void loop() {
if (!submitted || printedFinal) {
delay(200);
return;
}
if (rebootManager.rebootStatus() == RebootRequestStatus::Idle) {
const RebootEvaluation latest = rebootManager.lastEvaluation();
Serial.printf(
"final accepted=%u code=%u detail=%s\n",
static_cast<unsigned>(latest.accepted),
static_cast<unsigned>(latest.code),
latest.detail
);
printedFinal = true;
}
delay(200);
}