etsi_its_messages 1.0.0
Loading...
Searching...
No Matches
cdd_setters_common.h File Reference

Common setter functions for the ETSI ITS Common Data Dictionary (CDD) v1.3.1 and v2.1.1. More...

#include <etsi_its_msgs_utils/impl/cdd/cdd_checks.h>
#include <etsi_its_msgs_utils/impl/constants.h>
#include <GeographicLib/UTMUPS.hpp>
#include <cstring>

Go to the source code of this file.

Functions

void setTimestampITS (TimestampIts &timestamp_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 setLatitude (Latitude &latitude, const double deg)
 Set the Latitude object.
 
void setLongitude (Longitude &longitude, const double deg)
 Set the Longitude object.
 
void setAltitudeValue (AltitudeValue &altitude, const double value)
 Set the AltitudeValue object.
 
void setAltitude (Altitude &altitude, const double value)
 Set the Altitude object.
 
void setSpeedValue (SpeedValue &speed, const double value)
 Set the SpeedValue object.
 
void setSpeed (Speed &speed, const double value)
 Set the Speed object.
 
template<typename T >
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.
 
template<typename T >
void setFromUTMPosition (T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
 Set the ReferencePosition from a given UTM-Position.
 
template<typename T >
void setBitString (T &bitstring, const std::vector< bool > &bits)
 Set a Bit String by a vector of bools.
 

Detailed Description

Common setter functions for the ETSI ITS Common Data Dictionary (CDD) v1.3.1 and v2.1.1.

Definition in file cdd_setters_common.h.

Function Documentation

◆ setAltitude()

void setAltitude ( Altitude & altitude,
const double value )
inline

Set the Altitude object.

AltitudeConfidence is set to UNAVAILABLE

Parameters
altitudeobject to set
valueAltitude value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 105 of file cdd_setters_common.h.

105 {
106 altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
107 setAltitudeValue(altitude.altitude_value, value);
108}
void setAltitudeValue(AltitudeValue &altitude, const double value)
Set the AltitudeValue object.

◆ setAltitudeValue()

void setAltitudeValue ( AltitudeValue & altitude,
const double value )
inline

Set the AltitudeValue object.

Parameters
altitudeobject to set
valueAltitudeValue value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 86 of file cdd_setters_common.h.

86 {
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;
94 }
95}

◆ setBitString()

template<typename T >
void setBitString ( T & bitstring,
const std::vector< bool > & bits )
inline

Set a Bit String by a vector of bools.

Template Parameters
T
Parameters
bitstringBitString to set
bitsvector of bools

Definition at line 197 of file cdd_setters_common.h.

197 {
198 // bit string size
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;
202
203 // init output
204 bitstring.bits_unused = n_bits - bits.size();
205 bitstring.value = std::vector<uint8_t>(n_bytes);
206
207 // loop over all bytes in reverse order
208 for (int byte_idx = n_bytes - 1; byte_idx >= 0; byte_idx--) {
209 // loop over bits in a byte
210 for (int bit_idx_in_byte = 0; bit_idx_in_byte < bits_per_byte; bit_idx_in_byte++) {
211 // map bit index in byte to bit index in total bitstring
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;
214
215 // set bit in output bitstring appropriately
216 bitstring.value[byte_idx] |= bits[bit_idx] << bit_idx_in_byte;
217 }
218 }
219}

◆ setFromUTMPosition()

template<typename T >
void setFromUTMPosition ( T & reference_position,
const gm::PointStamped & utm_position,
const int zone,
const bool northp )
inline

Set the ReferencePosition from a given UTM-Position.

The position is transformed to latitude and longitude by using GeographicLib::UTMUPS The z-Coordinate is directly used as altitude value The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'

Parameters
[out]reference_positionReferencePostion or ReferencePositionWithConfidence to set
[in]utm_positiongeometry_msgs::PointStamped describing the given utm position
[in]zonethe UTM zone (zero means UPS) of the given position
[in]northphemisphere (true means north, false means south)

Definition at line 173 of file cdd_setters_common.h.

174 {
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 + "'!");
179 }
180 double latitude, longitude;
181 try {
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());
185 }
186 setReferencePosition(reference_position, latitude, longitude, utm_position.point.z);
187}
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.

◆ setLatitude()

void setLatitude ( Latitude & latitude,
const double deg )
inline

Set the Latitude object.

Parameters
latitudeobject to set
degLatitude value in degree as decimal number

Definition at line 62 of file cdd_setters_common.h.

62 {
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;
66}

◆ setLongitude()

void setLongitude ( Longitude & longitude,
const double deg )
inline

Set the Longitude object.

Parameters
longitudeobject to set
degLongitude value in degree as decimal number

Definition at line 74 of file cdd_setters_common.h.

74 {
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;
78}

◆ setReferencePosition()

template<typename T >
void setReferencePosition ( T & ref_position,
const double latitude,
const double longitude,
const double altitude = AltitudeValue::UNAVAILABLE )
inline

Sets the reference position in the given ReferencePostion object.

This function sets the latitude, longitude, and altitude of the reference position. If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE.

Parameters
ref_positionReferencePostion or ReferencePositionWithConfidence object to set the reference position in.
latitudeThe latitude value position in degree as decimal number.
longitudeThe longitude value in degree as decimal number.
altitudeThe altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).

Definition at line 147 of file cdd_setters_common.h.

148 {
149 setLatitude(ref_position.latitude, latitude);
150 setLongitude(ref_position.longitude, longitude);
151 if (altitude != AltitudeValue::UNAVAILABLE) {
152 setAltitude(ref_position.altitude, altitude);
153 } else {
154 ref_position.altitude.altitude_value.value = AltitudeValue::UNAVAILABLE;
155 ref_position.altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
156 }
157 // TODO: set confidence values
158}
void setLongitude(Longitude &longitude, const double deg)
Set the Longitude object.
void setAltitude(Altitude &altitude, const double value)
Set the Altitude object.
void setLatitude(Latitude &latitude, const double deg)
Set the Latitude object.

◆ setSpeed()

void setSpeed ( Speed & speed,
const double value )
inline

Set the Speed object.

SpeedConfidence is set to UNAVAILABLE

Parameters
speedobject to set
valueSpeed in in m/s as decimal number

Definition at line 130 of file cdd_setters_common.h.

130 {
131 speed.speed_confidence.value = SpeedConfidence::UNAVAILABLE;
132 setSpeedValue(speed.speed_value, value);
133}
void setSpeedValue(SpeedValue &speed, const double value)
Set the SpeedValue object.

◆ setSpeedValue()

void setSpeedValue ( SpeedValue & speed,
const double value )
inline

Set the SpeedValue object.

Parameters
speedobject to set
valueSpeedValue in m/s as decimal number

Definition at line 116 of file cdd_setters_common.h.

116 {
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;
120}

◆ setTimestampITS()

void setTimestampITS ( TimestampIts & timestamp_its,
const uint64_t unix_nanosecs,
const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second )
inline

Set the TimestampITS object.

Parameters
[in]timestamp_itsTimestampITS object to set the timestamp
[in]unix_nanosecsUnix-Nanoseconds to set the timestamp for
[in]n_leap_secondsNumber of leap-seconds since 2004. (Default: etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second)
[in]epoch_offsetUnix-Timestamp in seconds for the 01.01.2004 at 00:00:00

Definition at line 48 of file cdd_setters_common.h.

50 {
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;
54}