32#ifndef ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
33#define ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
35#include <GeographicLib/UTMUPS.hpp>
43inline uint32_t
getStationID(
const ItsPduHeader& header) {
return header.station_id.value; }
51inline double getLatitude(
const Latitude& latitude) {
return ((
double)latitude.value) * 1e-7; }
59inline double getLongitude(
const Longitude& longitude) {
return ((
double)longitude.value) * 1e-7; }
67inline double getAltitude(
const Altitude& altitude) {
return ((
double)altitude.altitude_value.value) * 1e-2; }
75inline double getSpeed(
const Speed& speed) {
return ((
double)speed.speed_value.value) * 1e-2; }
84inline std::vector<bool>
getBitString(
const std::vector<uint8_t>& buffer,
const int bits_unused) {
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);
93 for (
int byte_idx = n_bytes - 1; byte_idx >= 0; byte_idx--) {
95 for (
int bit_idx_in_byte = 0; bit_idx_in_byte < bits_per_byte; bit_idx_in_byte++) {
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;
101 bool byte_has_true_bit = buffer[byte_idx] & (1 << bit_idx_in_byte);
102 if (byte_has_true_bit) bits[bit_idx] = 1;
120inline gm::PointStamped
getUTMPosition(
const T& reference_position,
int& zone,
bool& northp) {
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);
126 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
127 std::string hemisphere;
133 utm_point.header.frame_id =
"utm_" + std::to_string(zone) + hemisphere;
134 }
catch (GeographicLib::GeographicErr& e) {
135 throw std::invalid_argument(e.what());
gm::PointStamped getUTMPosition(const T &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given ReferencePosition.
double getLatitude(const Latitude &latitude)
Get the Latitude value.
double getLongitude(const Longitude &longitude)
Get the Longitude value.
uint32_t getStationID(const ItsPduHeader &header)
Get the StationID of ItsPduHeader.
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.