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
|
From 1ed6ba38f2b7f9161164d7fadf4245972e150c68 Mon Sep 17 00:00:00 2001
From: Jane Rachinger <jane400@bingo-ev.de>
Date: Tue, 13 Jun 2023 22:14:16 +0200
Subject: [PATCH 3/3] use relative times for broken RTCs
---
src/main.cpp | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index f781fff..f448e88 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,11 +34,15 @@ std::list<Alarm> alarmList;
sdbus::UnixFd suspendDelayLockFd;
-void writeToRTC(std::uint64_t data) {
+void writeToRTC(std::uint64_t data, bool relative) {
std::cout << "Writing to RTC: " << data << std::endl;
std::ofstream rtc("/sys/class/rtc/rtc0/wakealarm");
if (rtc.is_open()) {
- rtc << data << std::endl;
+ if (relative) {
+ rtc << "+" << data << std::endl;
+ } else {
+ rtc << data << std::endl;
+ }
} else {
std::cout << "ERROR: Couldn't open RTC to write" << std::endl;
}
@@ -69,8 +73,8 @@ void rescedule()
if (alarmList.size()) {
uint64_t localReadFromRTC = readFromRTC();
if ((localReadFromRTC > alarmList.front().getTime()) || (!localReadFromRTC)) {
- writeToRTC(0);
- writeToRTC(alarmList.front().getTime());
+ writeToRTC(0, false);
+ writeToRTC(alarmList.front().getTime() - now, true);
}
}
}
@@ -95,7 +99,7 @@ std::string removeAlarm(const std::string& id)
if ((alarmList.size())
&& (alarmList.front().getId() == id)
&& (alarmList.front().getTime() == readFromRTC())) {
- writeToRTC(0);
+ writeToRTC(0, false);
}
alarmList.remove_if([id](Alarm &a){return id == a.getId();});
@@ -123,7 +127,7 @@ void handleSuspend(const bool active) {
std::time_t now = std::time(nullptr);
if ((alarmList.size()) && (alarmList.front().getTime() < now + 10UL)) {
std::cout << "Next alarm too close. Wake up in 10 Seconds ..." << std::endl;
- writeToRTC(now + 10UL);
+ writeToRTC(10UL, true);
}
suspendDelayLockFd.reset();
} else {
--
2.41.0
|