etsi_its_messages v3.5.0
Loading...
Searching...
No Matches
rtcmem_ts_utils.h
Go to the documentation of this file.
1/*
2=============================================================================
3MIT License
4
5Copyright (c) 2023-2025 Institute for Automotive Engineering (ika), RWTH Aachen University
6Copyright (c) 2026 Virtual Vehicle Research GmbH
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25=============================================================================
26*/
27
32
33#include <ctime>
34#include <limits>
35
36#pragma once
37
38namespace etsi_its_rtcmem_ts_msgs {
39
40namespace access {
41
42static constexpr int HOUR_IN_SECONDS = 3600;
43static constexpr int64_t FACTOR_SECONDS_TO_NANOSECONDS = 1000000000LL;
44
45// ETSI Timemark value equals 0.1 seconds and 10e8 nanoseconds
46static constexpr int64_t FACTOR_ETSI_TIMEMARK_TO_NANOSECONDS = 100000000LL;
47static constexpr float FACTOR_ETSI_TIMEMARK_TO_SECONDS = 0.1f;
48
55inline uint64_t getUnixSecondsOfYear(const uint64_t unixSecond) {
56 time_t ts = static_cast<time_t>(unixSecond);
57 struct tm* timeinfo = gmtime(&ts);
58
59 timeinfo->tm_sec = 0;
60 timeinfo->tm_min = 0;
61 timeinfo->tm_hour = 0;
62 timeinfo->tm_mday = 1;
63 timeinfo->tm_mon = 0;
64
65 return timegm(timeinfo);
66}
67
75inline uint64_t getUnixNanosecondsFromMinuteOfTheYear(const MinuteOfTheYear& moy,
76 const uint64_t unix_nanoseconds_estimate) {
77 const uint64_t unix_seconds_of_year =
78 getUnixSecondsOfYear(static_cast<uint64_t>(unix_nanoseconds_estimate * 1e-9));
79 return (unix_seconds_of_year + static_cast<uint64_t>(moy.value) * 60ULL) * 1000000000ULL;
80}
81
89inline uint64_t getUnixNanosecondsFromRTCMcorrections(const RTCMcorrections& rtcm,
90 const uint64_t unix_nanoseconds_estimate) {
91 return getUnixNanosecondsFromMinuteOfTheYear(getMinuteOfTheYear(rtcm), unix_nanoseconds_estimate);
92}
93
101inline uint64_t getUnixNanoseconds(const RTCMEM& rtcmem, const uint64_t unix_nanoseconds_estimate) {
102 return getUnixNanosecondsFromRTCMcorrections(rtcmem.rtcmc, unix_nanoseconds_estimate);
103}
104
114inline double interpretLatitudeInDegrees(const Latitude& lat) {
115 if (lat.value == Latitude::UNAVAILABLE) {
116 return std::numeric_limits<double>::quiet_NaN();
117 }
118 return static_cast<double>(lat.value) * 1e-7;
119}
120
130inline double interpretLongitudeInDegrees(const Longitude& lon) {
131 if (lon.value == Longitude::UNAVAILABLE) {
132 return std::numeric_limits<double>::quiet_NaN();
133 }
134 return static_cast<double>(lon.value) * 1e-7;
135}
136
137} // namespace access
138
139} // namespace etsi_its_rtcmem_ts_msgs
MinuteOfTheYear getMinuteOfTheYear(const RTCMcorrections &rtcm)
Get the MinuteOfTheYear object from a RTCMcorrections object.
double interpretLatitudeInDegrees(const Latitude &lat)
Convert Latitude integer representation into degrees.
uint64_t getUnixNanoseconds(const RTCMEM &rtcmem, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from a RTCMEM object.
uint64_t getUnixNanosecondsFromMinuteOfTheYear(const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from a MinuteOfTheYear object.
uint64_t getUnixSecondsOfYear(const uint64_t unixSecond)
Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.
uint64_t getUnixNanosecondsFromRTCMcorrections(const RTCMcorrections &rtcm, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from a RTCMcorrections object.
double interpretLongitudeInDegrees(const Longitude &lon)
Convert Longitude integer representation into degrees.