etsi_its_messages
v3.5.0
Toggle main menu visibility
Loading...
Searching...
No Matches
rtcmem_ts_utils.h
Go to the documentation of this file.
1
/*
2
=============================================================================
3
MIT License
4
5
Copyright (c) 2023-2025 Institute for Automotive Engineering (ika), RWTH Aachen University
6
Copyright (c) 2026 Virtual Vehicle Research GmbH
7
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14
15
The above copyright notice and this permission notice shall be included in all
16
copies or substantial portions of the Software.
17
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
SOFTWARE.
25
=============================================================================
26
*/
27
32
33
#include <ctime>
34
#include <limits>
35
36
#pragma once
37
38
namespace
etsi_its_rtcmem_ts_msgs {
39
40
namespace
access {
41
42
static
constexpr
int
HOUR_IN_SECONDS = 3600;
43
static
constexpr
int64_t FACTOR_SECONDS_TO_NANOSECONDS = 1000000000LL;
44
45
// ETSI Timemark value equals 0.1 seconds and 10e8 nanoseconds
46
static
constexpr
int64_t FACTOR_ETSI_TIMEMARK_TO_NANOSECONDS = 100000000LL;
47
static
constexpr
float
FACTOR_ETSI_TIMEMARK_TO_SECONDS = 0.1f;
48
55
inline
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
75
inline
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
89
inline
uint64_t
getUnixNanosecondsFromRTCMcorrections
(
const
RTCMcorrections& rtcm,
90
const
uint64_t unix_nanoseconds_estimate) {
91
return
getUnixNanosecondsFromMinuteOfTheYear
(
getMinuteOfTheYear
(rtcm), unix_nanoseconds_estimate);
92
}
93
101
inline
uint64_t
getUnixNanoseconds
(
const
RTCMEM& rtcmem,
const
uint64_t unix_nanoseconds_estimate) {
102
return
getUnixNanosecondsFromRTCMcorrections
(rtcmem.rtcmc, unix_nanoseconds_estimate);
103
}
104
114
inline
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
130
inline
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
etsi_its_rtcmem_ts_msgs::access::getMinuteOfTheYear
MinuteOfTheYear getMinuteOfTheYear(const RTCMcorrections &rtcm)
Get the MinuteOfTheYear object from a RTCMcorrections object.
Definition
rtcmem_ts_getters.h:251
etsi_its_rtcmem_ts_msgs::access::interpretLatitudeInDegrees
double interpretLatitudeInDegrees(const Latitude &lat)
Convert Latitude integer representation into degrees.
Definition
rtcmem_ts_utils.h:114
etsi_its_rtcmem_ts_msgs::access::getUnixNanoseconds
uint64_t getUnixNanoseconds(const RTCMEM &rtcmem, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from a RTCMEM object.
Definition
rtcmem_ts_utils.h:101
etsi_its_rtcmem_ts_msgs::access::getUnixNanosecondsFromMinuteOfTheYear
uint64_t getUnixNanosecondsFromMinuteOfTheYear(const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from a MinuteOfTheYear object.
Definition
rtcmem_ts_utils.h:75
etsi_its_rtcmem_ts_msgs::access::getUnixSecondsOfYear
uint64_t getUnixSecondsOfYear(const uint64_t unixSecond)
Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.
Definition
rtcmem_ts_utils.h:55
etsi_its_rtcmem_ts_msgs::access::getUnixNanosecondsFromRTCMcorrections
uint64_t getUnixNanosecondsFromRTCMcorrections(const RTCMcorrections &rtcm, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from a RTCMcorrections object.
Definition
rtcmem_ts_utils.h:89
etsi_its_rtcmem_ts_msgs::access::interpretLongitudeInDegrees
double interpretLongitudeInDegrees(const Longitude &lon)
Convert Longitude integer representation into degrees.
Definition
rtcmem_ts_utils.h:130
etsi_its_msgs_utils
include
etsi_its_msgs_utils
impl
rtcmem
rtcmem_ts_utils.h
Generated by
1.18.0