Vanetza
 
Loading...
Searching...
No Matches
dcc_information_sharing.cpp
1#include <vanetza/common/runtime.hpp>
2#include <vanetza/geonet/dcc_information_sharing.hpp>
3#include <vanetza/geonet/location_table.hpp>
4
5namespace vanetza
6{
7namespace geonet
8{
9
11 m_runtime(rt), m_location_table(lt), m_cbr_target(target),
12 m_trigger_interval(std::chrono::milliseconds(100)),
13 m_last_aggregation(m_runtime.now()),
14 on_global_cbr_update(m_update_hook)
15{
16 Clock::duration initial = m_trigger_interval;
17 initial *= delay.value();
18 m_runtime.schedule(initial, [this](const Clock::time_point&) { trigger(); });
19}
20
22 DccInformationSharing(rt, lt, target, UnitInterval { 0.0 })
23{
24}
25
26DccField DccInformationSharing::generate_dcc_field()
27{
28 DccMcoField dcc_mco;
29 dcc_mco.local_cbr(m_aggregator.get_local_cbr());
30 dcc_mco.neighbour_cbr(m_aggregator.get_one_hop_cbr());
31 // TODO set transmission power
32 return dcc_mco;
33}
34
36{
37 m_cbr_local = local_cbr;
38}
39
40void DccInformationSharing::trigger()
41{
42 m_aggregator.aggregate(m_cbr_local, m_location_table, m_last_aggregation, m_cbr_target);
43 m_last_aggregation = m_runtime.now();
44 m_update_hook(static_cast<const CbrAggregator&>(m_aggregator));
45 m_runtime.schedule(m_trigger_interval, [this](const Clock::time_point&) { trigger(); });
46}
47
48} // namespace geonet
49} // namespace vanetza
virtual Clock::time_point now() const =0
virtual void schedule(Clock::time_point tp, const Callback &cb, const void *scope=nullptr)=0
ChannelLoad get_local_cbr() const
void aggregate(ChannelLoad cbr_local, const LocationTable &lt, Timestamp cbr_lifetime, ChannelLoad cbr_target)
ChannelLoad get_one_hop_cbr() const
DccInformationSharing(Runtime &rt, const LocationTable &lt, dcc::ChannelLoad target, UnitInterval delay)
STL namespace.