| 20 | } |
| 21 | |
| 22 | bool TimerModule::Start() { |
| 23 | using namespace std::chrono_literals; |
| 24 | |
| 25 | auto start_time = timer_executor_.Now(); |
| 26 | auto task = [logger = core_.GetLogger(), start_time](aimrt::executor::TimerBase& timer) { |
| 27 | static int count = 0; |
| 28 | |
| 29 | auto now = timer.Executor().Now(); |
| 30 | auto timepoint = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time).count(); |
| 31 | AIMRT_HL_INFO(logger, "Executed {} times, execute timepoint: {} ms", ++count, timepoint); |
| 32 | |
| 33 | if (count >= 10) { |
| 34 | timer.Cancel(); |
| 35 | AIMRT_HL_INFO(logger, "Timer cancelled at timepoint: {} ms", timepoint); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | timer_ = aimrt::executor::CreateTimer(timer_executor_, 100ms, std::move(task)); |
| 40 | AIMRT_INFO("Timer created at timepoint: 0 ms"); |
| 41 | |
| 42 | timer_executor_.ExecuteAfter(350ms, [this, logger = core_.GetLogger()]() { |
| 43 | timer_->Reset(); |
| 44 | AIMRT_HL_INFO(logger, "Timer reset at timepoint: 350 ms"); |
| 45 | }); |
| 46 | |
| 47 | timer_executor_.ExecuteAfter(600ms, [this, logger = core_.GetLogger()]() { |
| 48 | timer_->Reset(); |
| 49 | AIMRT_HL_INFO(logger, "Timer reset at timepoint: 600 ms"); |
| 50 | }); |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | void TimerModule::Shutdown() { timer_->Cancel(); } |
| 56 |
nothing calls this directly
no test coverage detected