Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/net/osi_layer.hpp
T
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

81 lines
2.1 KiB
C++

#ifndef OSI_LAYER_HPP_C4VTEZJP
#define OSI_LAYER_HPP_C4VTEZJP
#include <boost/range/iterator_range.hpp>
#include <array>
#include <cstdint>
namespace vanetza
{
enum class OsiLayer : uint8_t
{
Physical = 1,
Link = 2,
Network = 3,
Transport = 4,
Session = 5,
Presentation = 6,
Application = 7
};
constexpr OsiLayer min_osi_layer() { return OsiLayer::Physical; }
constexpr OsiLayer max_osi_layer() { return OsiLayer::Application; }
constexpr std::array<OsiLayer, 7> osi_layers {{
OsiLayer::Physical,
OsiLayer::Link,
OsiLayer::Network,
OsiLayer::Transport,
OsiLayer::Session,
OsiLayer::Presentation,
OsiLayer::Application
}};
/**
* Calculate distance between layers
* \param from start counting at this layer
* \param to stop counting here
* \return 0 if equal layers, positive if "to" is a higher layer, negative if "to" is below "from"
*/
constexpr int distance(OsiLayer from, OsiLayer to)
{
return static_cast<int>(to) - static_cast<int>(from);
}
constexpr std::size_t num_osi_layers(OsiLayer from, OsiLayer to)
{
return (from <= to ? distance(from, to) + 1 : 0);
}
template<OsiLayer FROM, OsiLayer TO>
std::array<OsiLayer, num_osi_layers(FROM, TO)> osi_layer_range()
{
static_assert(FROM <= TO, "FROM layer is above TO layer");
typedef typename std::underlying_type<OsiLayer>::type num_type;
num_type num = static_cast<num_type>(FROM);
std::array<OsiLayer, num_osi_layers(FROM, TO)> layers;
for (auto& layer : layers) {
layer = static_cast<OsiLayer>(num++);
}
return layers;
}
inline boost::iterator_range<decltype(osi_layers)::const_iterator>
osi_layer_range(OsiLayer from, OsiLayer to)
{
if (from <= to) {
auto begin = osi_layers.cbegin() + distance(min_osi_layer(), from);
auto end = osi_layers.cend() - distance(to, max_osi_layer());
return boost::make_iterator_range(begin, end);
} else {
return boost::make_iterator_range(osi_layers.cend(), osi_layers.cend());
}
}
} // namespace vanetza
#endif /* OSI_LAYER_HPP_C4VTEZJP */