etsi_its_messages v3.0.0
 
Loading...
Searching...
No Matches
spatem_ts_utils.h File Reference

Utility functions for the ETSI ITS SPATEM. More...

#include <ctime>

Go to the source code of this file.

Functions

uint64_t etsi_its_spatem_ts_msgs::access::getUnixSecondsOfYear (const uint64_t unixSecond)
 Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.
 
uint64_t etsi_its_spatem_ts_msgs::access::getUnixNanosecondsFromMinuteOfTheYear (const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
 Get the unix nanoseconds from MinuteOfTheYear object.
 

Detailed Description

Utility functions for the ETSI ITS SPATEM.

Definition in file spatem_ts_utils.h.

Function Documentation

◆ getUnixNanosecondsFromMinuteOfTheYear()

uint64_t etsi_its_spatem_ts_msgs::access::getUnixNanosecondsFromMinuteOfTheYear ( const MinuteOfTheYear & moy,
const uint64_t unix_nanoseconds_estimate )
inline

Get the unix nanoseconds from MinuteOfTheYear object.

Parameters
moygiven MinuteOfTheYear object
unix_nanoseconds_estimateunix timestamp to derive the current year from in nanoseconds
Returns
uint64_t unix timestamp according to the given MinuteOfTheYear in nanoseconds

Definition at line 71 of file spatem_ts_utils.h.

71 {
72 return ((uint64_t)(moy.value*60) + getUnixSecondsOfYear(unix_nanoseconds_estimate*1e-9))*1e9;
73 }
uint64_t getUnixSecondsOfYear(const uint64_t unixSecond)
Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.

◆ getUnixSecondsOfYear()

uint64_t etsi_its_spatem_ts_msgs::access::getUnixSecondsOfYear ( const uint64_t unixSecond)
inline

Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.

Parameters
unixSecondtimestamp that defines the year for that the unix seconds for the beginning of the year should be derived
Returns
uint64_t unix seconds of the beginning of the year

Definition at line 46 of file spatem_ts_utils.h.

46 {
47
48 // Get current time as a time_point
49 time_t ts = static_cast<time_t>(unixSecond); // Convert uint64_t to time_t
50
51 struct tm* timeinfo;
52 timeinfo = gmtime(&ts);
53
54 // Set the timeinfo to the beginning of the year
55 timeinfo->tm_sec = 0;
56 timeinfo->tm_min = 0;
57 timeinfo->tm_hour = 0;
58 timeinfo->tm_mday = 1;
59 timeinfo->tm_mon = 0;
60
61 return timegm(timeinfo); // Convert struct tm back to Unix timestamp
62 }