etsi_its_messages v3.0.0
 
Loading...
Searching...
No Matches
cdd_getters_common.h
Go to the documentation of this file.
1/*
2=============================================================================
3MIT License
4
5Copyright (c) 2023-2024 Institute for Automotive Engineering (ika), RWTH Aachen University
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24=============================================================================
25*/
26
31
32#ifndef ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
33#define ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
34
35#include <GeographicLib/UTMUPS.hpp>
36
43inline uint32_t getStationID(const ItsPduHeader& header) { return header.station_id.value; }
44
51inline double getLatitude(const Latitude& latitude) { return ((double)latitude.value) * 1e-7; }
52
59inline double getLongitude(const Longitude& longitude) { return ((double)longitude.value) * 1e-7; }
60
67inline double getAltitude(const Altitude& altitude) { return ((double)altitude.altitude_value.value) * 1e-2; }
68
75inline double getSpeed(const Speed& speed) { return ((double)speed.speed_value.value) * 1e-2; }
76
88template <typename T>
89inline gm::PointStamped getUTMPosition(const T& reference_position, int& zone, bool& northp) {
90 gm::PointStamped utm_point;
91 double latitude = getLatitude(reference_position.latitude);
92 double longitude = getLongitude(reference_position.longitude);
93 utm_point.point.z = getAltitude(reference_position.altitude);
94 try {
95 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
96 std::string hemisphere;
97 if (northp) {
98 hemisphere = "N";
99 } else {
100 hemisphere = "S";
101 }
102 utm_point.header.frame_id = "utm_" + std::to_string(zone) + hemisphere;
103 } catch (GeographicLib::GeographicErr& e) {
104 throw std::invalid_argument(e.what());
105 }
106 return utm_point;
107}
108
109#endif // ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
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.