Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
mock_rtc.h
Go to the documentation of this file.
1#pragma once
2
3#include "ersa/hal/rtc.h"
4
5namespace ersa {
6namespace test {
7
8class MockRtc : public hal::IRtc {
9public:
10 explicit MockRtc(uint32_t epoch = 1790535111) : epoch_(epoch) {}
11
12 Result<void> init() override {
13 healthy_ = true;
14 return Result<void>();
15 }
16
17 hal::TimePoint now() override {
19 tp.epoch = epoch_;
20 tp.hour = (epoch_ / 3600) % 24;
21 tp.minute = (epoch_ / 60) % 60;
22 tp.second = epoch_ % 60;
23 return tp;
24 }
25
26 Result<void> adjust(const hal::TimePoint& time) override {
27 epoch_ = time.epoch;
28 return Result<void>();
29 }
30
31 Result<void> setEpoch(uint32_t epochSeconds) override {
32 epoch_ = epochSeconds;
33 return Result<void>();
34 }
35
36 bool isHealthy() const override { return healthy_; }
37
38 void advanceSeconds(uint32_t sec) { epoch_ += sec; }
39 void advanceMinutes(uint32_t min) { epoch_ += min * 60; }
40 void setHealthy(bool h) { healthy_ = h; }
41
42private:
43 uint32_t epoch_{0};
44 bool healthy_{true};
45};
46
47} // namespace test
48} // namespace ersa
Definition types.h:52
Definition rtc.h:41
Definition mock_rtc.h:8
void advanceMinutes(uint32_t min)
Definition mock_rtc.h:39
MockRtc(uint32_t epoch=1790535111)
Definition mock_rtc.h:10
void setHealthy(bool h)
Definition mock_rtc.h:40
bool healthy_
Definition mock_rtc.h:44
Result< void > adjust(const hal::TimePoint &time) override
Definition mock_rtc.h:26
void advanceSeconds(uint32_t sec)
Definition mock_rtc.h:38
hal::TimePoint now() override
Definition mock_rtc.h:17
uint32_t epoch_
Definition mock_rtc.h:43
bool isHealthy() const override
Definition mock_rtc.h:36
Result< void > init() override
Definition mock_rtc.h:12
Result< void > setEpoch(uint32_t epochSeconds) override
Definition mock_rtc.h:31
Definition application.h:10
Definition rtc.h:15
uint32_t epoch
Definition rtc.h:23
uint8_t second
Definition rtc.h:21
uint8_t hour
Definition rtc.h:19
uint8_t minute
Definition rtc.h:20