32#ifndef ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_SETTERS_COMMON_H
33#define ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_SETTERS_COMMON_H
37#include <GeographicLib/UTMUPS.hpp>
49 TimestampIts& timestamp_its,
const uint64_t unix_nanosecs,
51 uint64_t t_its = unix_nanosecs * 1e-6 + (uint64_t)(n_leap_seconds * 1e3) - etsi_its_msgs::UNIX_SECONDS_2004 * 1e3;
53 timestamp_its.value = t_its;
62inline void setLatitude(Latitude& latitude,
const double deg) {
63 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg * 1e7);
64 throwIfOutOfRange(angle_in_10_micro_degree, Latitude::MIN, Latitude::MAX,
"Latitude");
65 latitude.value = angle_in_10_micro_degree;
75 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg * 1e7);
76 throwIfOutOfRange(angle_in_10_micro_degree, Longitude::MIN, Longitude::MAX,
"Longitude");
77 longitude.value = angle_in_10_micro_degree;
87 int64_t alt_in_cm = (int64_t)std::round(value * 1e2);
88 if (alt_in_cm >= AltitudeValue::MIN && alt_in_cm <= AltitudeValue::MAX) {
89 altitude.value = alt_in_cm;
90 }
else if (alt_in_cm < AltitudeValue::MIN) {
91 altitude.value = AltitudeValue::MIN;
92 }
else if (alt_in_cm > AltitudeValue::MAX) {
93 altitude.value = AltitudeValue::MAX;
106 altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
117 uint16_t speed_val = (uint16_t)std::round(value * 1e2);
119 speed.value = speed_val;
130inline void setSpeed(Speed& speed,
const double value) {
131 speed.speed_confidence.value = SpeedConfidence::UNAVAILABLE;
148 const double altitude = AltitudeValue::UNAVAILABLE) {
151 if (altitude != AltitudeValue::UNAVAILABLE) {
154 ref_position.altitude.altitude_value.value = AltitudeValue::UNAVAILABLE;
155 ref_position.altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
173inline void setFromUTMPosition(T& reference_position,
const gm::PointStamped& utm_position,
const int zone,
175 std::string required_frame_prefix =
"utm_";
176 if (utm_position.header.frame_id.rfind(required_frame_prefix, 0) != 0) {
177 throw std::invalid_argument(
"Frame-ID of UTM Position '" + utm_position.header.frame_id +
178 "' does not start with required prefix '" + required_frame_prefix +
"'!");
180 double latitude, longitude;
182 GeographicLib::UTMUPS::Reverse(zone, northp, utm_position.point.x, utm_position.point.y, latitude, longitude);
183 }
catch (GeographicLib::GeographicErr& e) {
184 throw std::invalid_argument(e.what());
void setLongitude(Longitude &longitude, const double deg)
Set the Longitude object.
void setTimestampITS(TimestampIts ×tamp_its, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end() ->second)
Set the TimestampITS object.
void setSpeedValue(SpeedValue &speed, const double value)
Set the SpeedValue object.
void setAltitude(Altitude &altitude, const double value)
Set the Altitude object.
void setFromUTMPosition(T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
Set the ReferencePosition from a given UTM-Position.
void setAltitudeValue(AltitudeValue &altitude, const double value)
Set the AltitudeValue object.
void setLatitude(Latitude &latitude, const double deg)
Set the Latitude object.
void setReferencePosition(T &ref_position, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
Sets the reference position in the given ReferencePostion object.
void setSpeed(Speed &speed, const double value)
Set the Speed object.
Sanity-check functions etc.
void throwIfOutOfRange(const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
Throws an exception if a given value is out of a defined range.
File containing constants that are used in the context of ETIS ITS Messages.
const std::map< uint64_t, uint16_t > LEAP_SECOND_INSERTIONS_SINCE_2004
std::map that stores all leap second insertions since 2004 with the corresponding unix-date of the in...