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,
50 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
51 uint64_t t_its = unix_nanosecs * 1e-6 + (uint64_t)(n_leap_seconds * 1e3) - etsi_its_msgs::UNIX_SECONDS_2004 * 1e3;
52 throwIfOutOfRange(t_its, TimestampIts::MIN, TimestampIts::MAX,
"TimestampIts");
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 int64_t speed_val = (int64_t)std::round(value * 1e2);
118 throwIfOutOfRange(speed_val, SpeedValue::MIN, SpeedValue::MAX,
"SpeedValue");
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());
199 const int bits_per_byte = 8;
200 const int n_bytes = (bits.size() - 1) / bits_per_byte + 1;
201 const int n_bits = n_bytes * bits_per_byte;
204 bitstring.bits_unused = n_bits - bits.size();
205 bitstring.value = std::vector<uint8_t>(n_bytes);
208 for (
int byte_idx = n_bytes - 1; byte_idx >= 0; byte_idx--) {
210 for (
int bit_idx_in_byte = 0; bit_idx_in_byte < bits_per_byte; bit_idx_in_byte++) {
212 int bit_idx = (n_bytes - byte_idx - 1) * bits_per_byte + bit_idx_in_byte;
213 if (byte_idx == 0 && bit_idx >= n_bits - bitstring.bits_unused)
break;
216 bitstring.value[byte_idx] |= bits[bit_idx] << bit_idx_in_byte;
Sanity-check functions etc. for the ETSI ITS Common Data Dictionary (CDD)
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 setBitString(T &bitstring, const std::vector< bool > &bits)
Set a Bit String by a vector of bools.
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.
File containing constants that are used in the context of ETIS ITS Messages.