Files
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

75 lines
2.0 KiB
C++

#include <vanetza/geonet/cbr_aggregator.hpp>
#include <vanetza/geonet/location_table.hpp>
#include <vanetza/geonet/loctex_g5.hpp>
#include <algorithm>
#include <array>
namespace vanetza
{
namespace geonet
{
struct CbrAggregatorUnit
{
CbrAggregatorUnit() : n(0) {}
void operator+=(dcc::ChannelLoad cbr)
{
// calculate average as double so numerator can be larger than 1.0 temporarily
average = dcc::ChannelLoad {(average.value() * n + cbr.value()) / (n + 1)};
++n;
// >= comparison: second largest value might equal largest value
if (cbr >= maximum[0]) {
maximum[1] = maximum[0];
maximum[0] = cbr;
} else if (cbr > maximum[1]) {
maximum[1] = cbr;
}
}
dcc::ChannelLoad operator()(const dcc::ChannelLoad target) const
{
if (average > target) {
return maximum[0];
} else {
return maximum[1];
}
}
unsigned n;
dcc::ChannelLoad average;
std::array<dcc::ChannelLoad, 2> maximum;
};
CbrAggregator::CbrAggregator() :
m_one_hop_cbr(0.0), m_two_hop_cbr(0.0)
{
}
void CbrAggregator::aggregate(ChannelLoad local, const LocationTable& lt, Timestamp lifetime, ChannelLoad target)
{
m_local_cbr[1] = m_local_cbr[0];
m_local_cbr[0] = local;
CbrAggregatorUnit one_hop;
CbrAggregatorUnit two_hop;
LocationTable::entry_visitor entry_visitor =
[&](const MacAddress&, const LocationTableEntry& entry) {
const LocTEX_G5* loctex = entry.extensions.find<LocTEX_G5>();
if (loctex && loctex->local_update >= lifetime) {
one_hop += loctex->dcc_mco.local_cbr();
two_hop += loctex->dcc_mco.neighbour_cbr();
}
};
lt.visit(entry_visitor);
m_one_hop_cbr = one_hop(target);
m_two_hop_cbr = two_hop(target);
m_global_cbr = std::max({ m_local_cbr[1], m_one_hop_cbr, m_two_hop_cbr});
}
} // namespace geonet
} // namespace vanetza