etsi_its_messages v3.4.0
Loading...
Searching...
No Matches
cdd_v2-2-1_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#ifndef ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_V2_2_1_SETTERS_H
10#define ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_V2_2_1_SETTERS_H
11
14#include <GeographicLib/UTMUPS.hpp>
15#include <cstring>
16
25inline void setItsPduHeader(ItsPduHeader& header, const uint8_t message_id, const uint32_t station_id,
26 const uint8_t protocol_version = 0) {
27 setStationId(header.station_id, station_id);
28 throwIfOutOfRange(message_id, MessageId::MIN, MessageId::MAX, "MessageID");
29 header.message_id.value = message_id;
30 throwIfOutOfRange(protocol_version, OrdinalNumber1B::MIN, OrdinalNumber1B::MAX, "ProtocolVersion");
31 header.protocol_version.value = protocol_version;
32}
33
42template <typename Wgs84AngleValue>
43inline void setWGSHeadingValue(Wgs84AngleValue& heading, const double value) {
44 int64_t deg = (int64_t)std::round(value * 1e1);
45 throwIfOutOfRange(deg, Wgs84AngleValue::MIN, Wgs84AngleValue::MAX, "Wgs84AngleValue");
46 heading.value = deg;
47}
48
55template<typename Wgs84AngleConfidence>
56inline void setWGSHeadingConfidence(Wgs84AngleConfidence& confidence, const double value) {
57 auto heading_conf = std::round(value * 1e1 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
58 if (heading_conf < Wgs84AngleConfidence::MIN && heading_conf > 0.0){
59 heading_conf = Wgs84AngleConfidence::MIN;
60 } else if (heading_conf >= Wgs84AngleConfidence::OUT_OF_RANGE || heading_conf <= 0.0) {
61 heading_conf = Wgs84AngleConfidence::UNAVAILABLE;
62 }
63 confidence.value = static_cast<decltype(confidence.value)>(heading_conf);
64}
65
76template <typename Wgs84Angle, typename Wgs84AngleConfidence = decltype(Wgs84Angle::confidence)>
77void setWGSHeadingCDD(Wgs84Angle& heading, const double value, double confidence = std::numeric_limits<double>::infinity()) {
78 setWGSHeadingConfidence(heading.confidence, confidence);
79 setWGSHeadingValue(heading.value, value);
80}
81
82#endif // ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_V2_2_1_SETTERS_H
Common setter functions for the ETSI ITS Common Data Dictionary (CDD) v1.3.1, v2.1....
void setStationId(StationId &station_id, const uint32_t id_value)
Set the Station Id object.
void setWGSHeadingValue(Wgs84AngleValue &heading, const double value)
Set the Wgs84AngleValue object.
void setWGSHeadingCDD(Wgs84Angle &heading, const double value, double confidence=std::numeric_limits< double >::infinity())
Set the Wgs84Angle object.
void setItsPduHeader(ItsPduHeader &header, const uint8_t message_id, const uint32_t station_id, const uint8_t protocol_version=0)
Set the Its Pdu Header object.
void setWGSHeadingConfidence(Wgs84AngleConfidence &confidence, const double value)
Set the Wgs84AngleConfidence object.
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.
Definition checks.h:23