Vanetza
 
Loading...
Searching...
No Matches
state_machine_budget.cpp
1#include <vanetza/common/runtime.hpp>
2#include <vanetza/dcc/state_machine.hpp>
3#include <vanetza/dcc/state_machine_budget.hpp>
4
5namespace vanetza
6{
7namespace dcc
8{
9
10StateMachineBudget::StateMachineBudget(const StateMachine& fsm, const Runtime& rt) :
11 m_fsm(fsm), m_runtime(rt)
12{
13}
14
15Clock::duration StateMachineBudget::delay()
16{
17 Clock::duration delay = Clock::duration::max();
18
19 if (m_last_tx) {
20 const auto last_tx = m_last_tx.get();
21 const auto tx_interval = m_fsm.transmission_interval();
22 if (last_tx + tx_interval < m_runtime.now()) {
23 delay = Clock::duration::zero();
24 } else {
25 delay = last_tx + tx_interval - m_runtime.now();
26 }
27 } else {
28 delay = Clock::duration::zero();
29 }
30
31 return delay;
32}
33
34void StateMachineBudget::notify()
35{
36 m_last_tx = m_runtime.now();
37}
38
39} // namespace dcc
40} // namespace vanetza