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).
54 lines
2.0 KiB
C++
54 lines
2.0 KiB
C++
#include <vanetza/common/position_fix.hpp>
|
|
#include <vanetza/asn1/security_profile.hpp>
|
|
#include VANETZA_ASN1_SECURITY_HEADER(Latitude.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(Longitude.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(TwoDLocation.h)
|
|
#include <vanetza/security/v3/distance.hpp>
|
|
#include <boost/units/cmath.hpp>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
namespace v3
|
|
{
|
|
|
|
units::Length distance(const PositionFix& one, const asn1::TwoDLocation& other)
|
|
{
|
|
static const auto earth_radius = 6371000.0 * units::si::meter;
|
|
const auto other_lat = convert_latitude(other.latitude);
|
|
const auto other_lon = convert_longitude(other.longitude);
|
|
const units::Angle delta_phi { one.latitude - other_lat };
|
|
const units::Angle delta_lambda { one.longitude - other_lon };
|
|
const auto sin_delta_phi = sin(delta_phi / 2.0);
|
|
const auto sin_delta_lambda = sin(delta_lambda / 2.0);
|
|
const auto a = sin_delta_phi * sin_delta_phi +
|
|
cos(one.latitude) * cos(other_lat) * sin_delta_lambda * sin_delta_lambda;
|
|
const auto c = 2.0 * atan2(sqrt(a), sqrt(1 - a));
|
|
return earth_radius * c;
|
|
}
|
|
|
|
units::GeoAngle convert_latitude(const asn1::Latitude& in)
|
|
{
|
|
static constexpr long latitude_scale = Vanetza_Security_NinetyDegreeInt_max;
|
|
if (in >= Vanetza_Security_NinetyDegreeInt_min && in <= Vanetza_Security_NinetyDegreeInt_max) {
|
|
return in * 90.0 / latitude_scale * units::degree;
|
|
} else {
|
|
return units::GeoAngle::from_value(std::numeric_limits<double>::quiet_NaN());
|
|
}
|
|
}
|
|
|
|
units::GeoAngle convert_longitude(const asn1::Longitude& in)
|
|
{
|
|
static constexpr long longitude_scale = Vanetza_Security_OneEightyDegreeInt_max;
|
|
if (in >= Vanetza_Security_OneEightyDegreeInt_min && in <= Vanetza_Security_OneEightyDegreeInt_max) {
|
|
return in * 180.0 / longitude_scale * units::degree;
|
|
} else {
|
|
return units::GeoAngle::from_value(std::numeric_limits<double>::quiet_NaN());
|
|
}
|
|
}
|
|
|
|
} // namespace v3
|
|
} // namespace security
|
|
} // namespace vanetza
|