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.
85 lines
2.1 KiB
C++
85 lines
2.1 KiB
C++
#include <vanetza/geodesy/country_database.hpp>
|
|
#include <vanetza/geodesy/country_data_reader.hpp>
|
|
#include <boost/geometry/algorithms/within.hpp>
|
|
#include <boost/units/quantity.hpp>
|
|
#include <fstream>
|
|
#include <iterator>
|
|
#include <vector>
|
|
|
|
#ifdef VANETZA_WITH_EMBEDDED_COUNTRY_DATA
|
|
#include <vanetza/common/byte_view.hpp>
|
|
namespace vanetza { namespace geodesy { namespace country { vanetza::byte_view_range embedded(); } } }
|
|
#endif
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace geodesy
|
|
{
|
|
|
|
CountryDatabase CountryDatabase::embedded(std::string* error)
|
|
{
|
|
CountryDatabase db;
|
|
#ifdef VANETZA_WITH_EMBEDDED_COUNTRY_DATA
|
|
auto view = country::embedded();
|
|
db.load(view.data(), view.size(), error);
|
|
#else
|
|
if (error) {
|
|
*error = "embedded country data not available";
|
|
}
|
|
#endif
|
|
return db;
|
|
}
|
|
|
|
bool CountryDatabase::load(const std::string& path, std::string* error)
|
|
{
|
|
std::ifstream file(path, std::ios::binary);
|
|
if (!file) {
|
|
if (error) {
|
|
*error = "cannot open file: " + path;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::vector<uint8_t> data { std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>() };
|
|
return load(data.data(), data.size(), error);
|
|
}
|
|
|
|
bool CountryDatabase::load(const uint8_t* data, std::size_t length, std::string* error)
|
|
{
|
|
m_countries.clear();
|
|
|
|
auto result = read_country_data(data, length,
|
|
[this](M49Code code, CountryPolygon&& polygon) {
|
|
m_countries.emplace(code, std::move(polygon));
|
|
});
|
|
|
|
if (result.failed()) {
|
|
if (error) {
|
|
*error = result.message() + " at offset " + std::to_string(result.position());
|
|
}
|
|
m_countries.clear();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CountryDatabase::is_inside(M49Code country, const GeodeticPosition& position) const
|
|
{
|
|
auto it = m_countries.find(country);
|
|
if (it == m_countries.end()) {
|
|
return false;
|
|
}
|
|
|
|
country::Point point(position.longitude / units::degree, position.latitude / units::degree);
|
|
return boost::geometry::within(point, it->second);
|
|
}
|
|
|
|
bool CountryDatabase::empty() const
|
|
{
|
|
return m_countries.empty();
|
|
}
|
|
|
|
} // namespace geodesy
|
|
} // namespace vanetza
|