etsi_its_messages v3.4.0
Loading...
Searching...
No Matches
mapem_ts_setters.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
3
8
9#pragma once
10
11
12#include <GeographicLib/UTMUPS.hpp>
13
14namespace etsi_its_mapem_ts_msgs {
15
16namespace access {
17
19
26 inline void setMinuteOfTheYear(MinuteOfTheYear& moy, const uint32_t moy_value) {
27 throwIfOutOfRange(moy_value, MinuteOfTheYear::MIN, MinuteOfTheYear::MAX, "MinuteOfTheYear");
28 moy.value = moy_value;
29 }
30
37 inline void setMinuteOfTheYear(MapData& map, const uint32_t moy_value) {
38 setMinuteOfTheYear(map.time_stamp, moy_value);
39 }
40
46 inline void setMinuteOfTheYear(MAPEM& mapem, const uint32_t moy_value) {
47 setMinuteOfTheYear(mapem.map, moy_value);
48 mapem.map.time_stamp_is_present = true;
49 }
50
57 inline void setIntersectionID(IntersectionID& intsct_id, const uint16_t id_value) {
58 throwIfOutOfRange(id_value, IntersectionID::MIN, IntersectionID::MAX, "IntersectionID");
59 intsct_id.value = id_value;
60 }
61
68 inline void setIntersectionID(IntersectionGeometry& intsct, const uint16_t id_value) {
69 setIntersectionID(intsct.id.id, id_value);
70 }
71
78 inline void setLatitude(Latitude& latitude, const double deg) {
79 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg*1e7);
80 throwIfOutOfRange(angle_in_10_micro_degree, Latitude::MIN, Latitude::MAX, "Latitude");
81 latitude.value = angle_in_10_micro_degree;
82 }
83
90 inline void setLongitude(Longitude& longitude, const double deg) {
91 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg*1e7);
92 throwIfOutOfRange(angle_in_10_micro_degree, Longitude::MIN, Longitude::MAX, "Longitude");
93 longitude.value = angle_in_10_micro_degree;
94 }
95
102 inline void setElevation(Elevation& elevation, const double value) {
103 int64_t alt_in_dm = (int64_t)std::round(value*1e1);
104 if(alt_in_dm>=Elevation::MIN && alt_in_dm<=Elevation::MAX) elevation.value = alt_in_dm;
105 else if(alt_in_dm<Elevation::MIN) elevation.value = Elevation::MIN;
106 else if(alt_in_dm>Elevation::MAX) elevation.value = Elevation::MAX;
107 }
108
116 inline void setPosition3D(Position3D& pos, const double latitude, const double longitude) {
117 setLatitude(pos.lat, latitude);
118 setLongitude(pos.lon, longitude);
119 pos.elevation_is_present = false;
120 }
121
130 inline void setPosition3D(Position3D& pos, const double latitude, const double longitude, const double altitude) {
131 setPosition3D(pos, latitude, longitude);
132 setElevation(pos.elevation, altitude);
133 pos.elevation_is_present = true;
134 }
135
144 inline void setPosition3D(IntersectionGeometry& intsct, double latitude, double longitude, double altitude) {
145 setPosition3D(intsct.ref_point, latitude, longitude, altitude);
146 }
147
160 inline void setPosition3DFromUTMPosition(Position3D& reference_position, const gm::PointStamped& utm_position, const int zone, const bool northp) {
161 std::string required_frame_prefix = "utm_";
162 if(utm_position.header.frame_id.rfind(required_frame_prefix, 0) != 0)
163 {
164 throw std::invalid_argument("Frame-ID of UTM Position '"+utm_position.header.frame_id+"' does not start with required prefix '"+required_frame_prefix+"'!");
165 }
166 double latitude, longitude;
167 try {
168 GeographicLib::UTMUPS::Reverse(zone, northp, utm_position.point.x, utm_position.point.y, latitude, longitude);
169 } catch (GeographicLib::GeographicErr& e) {
170 throw std::invalid_argument(e.what());
171 }
172 setPosition3D(reference_position, latitude, longitude, utm_position.point.z);
173 }
174
175} // namespace access
176
177} // namespace etsi_its_mapem_ts_msgs
Sanity-check functions etc.
void throwIfOutOfRange(const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
Throws an exception if a given value is out of a defined range.
void setPosition3D(Position3D &pos, const double latitude, const double longitude)
Set the Position3D object.
void setPosition3DFromUTMPosition(Position3D &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
Set the Position3D from a given UTM-Position.
void setMinuteOfTheYear(MinuteOfTheYear &moy, const uint32_t moy_value)
Set the MinuteOfTheYear object.
void setElevation(Elevation &elevation, const double value)
Set the Elevation object.
void setLatitude(Latitude &latitude, const double deg)
Set the Latitude object.
void setIntersectionID(IntersectionID &intsct_id, const uint16_t id_value)
Set the IntersectionID value.
void setLongitude(Longitude &longitude, const double deg)
Set the Longitude object.