obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
75 lines
2.0 KiB
C++
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
|