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

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

#include <GeographicLib/UTMUPS.hpp>

Go to the source code of this file.

Functions

uint32_t getStationID (const ItsPduHeader &header)
 Get the StationID of ItsPduHeader.
 
double getLatitude (const Latitude &latitude)
 Get the Latitude value.
 
double getLongitude (const Longitude &longitude)
 Get the Longitude value.
 
double getAltitude (const Altitude &altitude)
 Get the Altitude value.
 
double getSpeed (const Speed &speed)
 Get the vehicle speed.
 
std::vector< bool > getBitString (const std::vector< uint8_t > &buffer, const int bits_unused)
 Get a Bit String in form of bool vector.
 
template<typename T >
gm::PointStamped getUTMPosition (const T &reference_position, int &zone, bool &northp)
 Get the UTM Position defined by the given ReferencePosition.
 

Detailed Description

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

Definition in file cdd_getters_common.h.

Function Documentation

◆ getAltitude()

double getAltitude ( const Altitude & altitude)
inline

Get the Altitude value.

Parameters
altitudeto get the Altitude value from
Returns
Altitude value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 67 of file cdd_getters_common.h.

67{ return ((double)altitude.altitude_value.value) * 1e-2; }

◆ getBitString()

std::vector< bool > getBitString ( const std::vector< uint8_t > & buffer,
const int bits_unused )
inline

Get a Bit String in form of bool vector.

Parameters
bufferas uint8_t vector
bits_unusednumber of bits to ignore at the end of the bit string
Returns
std::vector<bool>

Definition at line 84 of file cdd_getters_common.h.

84 {
85 // bit string size
86 const int bits_per_byte = 8;
87 const int n_bytes = buffer.size();
88 const int n_bits = n_bytes * bits_per_byte;
89 std::vector<bool> bits;
90 bits.resize(n_bits - bits_unused, 0);
91
92 // loop over bytes in reverse order
93 for (int byte_idx = n_bytes - 1; byte_idx >= 0; byte_idx--) {
94 // loop over bits in a byte
95 for (int bit_idx_in_byte = 0; bit_idx_in_byte < bits_per_byte; bit_idx_in_byte++) {
96 // map bit index in byte to bit index in total bitstring
97 int bit_idx = (n_bytes - byte_idx - 1) * bits_per_byte + bit_idx_in_byte;
98 if (byte_idx == 0 && bit_idx >= n_bits - bits_unused) break;
99
100 // extract bit from bitstring and set output array entry appropriately
101 bool byte_has_true_bit = buffer[byte_idx] & (1 << bit_idx_in_byte);
102 if (byte_has_true_bit) bits[bit_idx] = 1;
103 }
104 }
105 return bits;
106}

◆ getLatitude()

double getLatitude ( const Latitude & latitude)
inline

Get the Latitude value.

Parameters
latitudeto get the Latitude value from
Returns
Latitude value in degree as decimal number

Definition at line 51 of file cdd_getters_common.h.

51{ return ((double)latitude.value) * 1e-7; }

◆ getLongitude()

double getLongitude ( const Longitude & longitude)
inline

Get the Longitude value.

Parameters
longitudeto get the Longitude value from
Returns
Longitude value in degree as decimal number

Definition at line 59 of file cdd_getters_common.h.

59{ return ((double)longitude.value) * 1e-7; }

◆ getSpeed()

double getSpeed ( const Speed & speed)
inline

Get the vehicle speed.

Parameters
speedto get the speed value from
Returns
speed value in m/s as decimal number

Definition at line 75 of file cdd_getters_common.h.

75{ return ((double)speed.speed_value.value) * 1e-2; }

◆ getStationID()

uint32_t getStationID ( const ItsPduHeader & header)
inline

Get the StationID of ItsPduHeader.

Parameters
headerItsPduHeader to get the StationID value from
Returns
stationID value

Definition at line 43 of file cdd_getters_common.h.

43{ return header.station_id.value; }

◆ getUTMPosition()

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

Get the UTM Position defined by the given ReferencePosition.

The position is transformed into UTM by using GeographicLib::UTMUPS The altitude value is directly used as z-Coordinate

Parameters
[in]reference_positionReferencePosition or ReferencePositionWithConfidence to get the UTM Position from
[out]zonethe UTM zone (zero means UPS)
[out]northphemisphere (true means north, false means south)
Returns
gm::PointStamped geometry_msgs::PointStamped of the given position

Definition at line 120 of file cdd_getters_common.h.

120 {
121 gm::PointStamped utm_point;
122 double latitude = getLatitude(reference_position.latitude);
123 double longitude = getLongitude(reference_position.longitude);
124 utm_point.point.z = getAltitude(reference_position.altitude);
125 try {
126 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
127 std::string hemisphere;
128 if (northp) {
129 hemisphere = "N";
130 } else {
131 hemisphere = "S";
132 }
133 utm_point.header.frame_id = "utm_" + std::to_string(zone) + hemisphere;
134 } catch (GeographicLib::GeographicErr& e) {
135 throw std::invalid_argument(e.what());
136 }
137 return utm_point;
138}
double getLatitude(const Latitude &latitude)
Get the Latitude value.
double getLongitude(const Longitude &longitude)
Get the Longitude value.
double getAltitude(const Altitude &altitude)
Get the Altitude value.