etsi_its_messages v3.1.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.

Enumerations

enum  time_mark_value_interpretation { normal , undefined , over_an_hour , leap_second }
 

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.
 
float etsi_its_spatem_ts_msgs::access::interpretTimeIntervalConfidenceAsFloat (const uint16_t encoded_probability)
 Interprets the TimeIntervalConfidence type as a float value (see etsi definition)
 
std::array< float, 4 > etsi_its_spatem_ts_msgs::access::interpretMovementPhaseStateAsColor (const uint8_t value)
 Interprets the MovementPhaseState type as a color (see etsi definition)
 
time_mark_value_interpretation etsi_its_spatem_ts_msgs::access::interpretTimeMarkValueType (const uint16_t time)
 Interprets the type of a TimeMark message See etsi ASNI1 - IS TS 103 301 documentation for for the encoding of "TimeMark".
 
float etsi_its_spatem_ts_msgs::access::interpretTimeMarkValueAsSeconds (const uint16_t time, const int32_t seconds, const uint32_t nanosec)
 Calculate the amount of seconds until the given time is reached.
 
std::string etsi_its_spatem_ts_msgs::access::parseTimeMarkValueToString (const uint16_t time, const int32_t seconds, const uint32_t nanosec)
 Converts a value from message type TimeMarkValue into a string representation.
 

Variables

const std::array< float, 4 > etsi_its_spatem_ts_msgs::access::color_grey {0.5, 0.5, 0.5, 1.0}
 
const std::array< float, 4 > etsi_its_spatem_ts_msgs::access::color_green {0.18, 0.79, 0.21, 1.0}
 
const std::array< float, 4 > etsi_its_spatem_ts_msgs::access::color_orange {0.9, 0.7, 0.09, 1.0}
 
const std::array< float, 4 > etsi_its_spatem_ts_msgs::access::color_red {0.8, 0.2, 0.2, 1.0}
 

Detailed Description

Utility functions for the ETSI ITS SPATEM.

Definition in file spatem_ts_utils.h.

Enumeration Type Documentation

◆ time_mark_value_interpretation

enum etsi_its_spatem_ts_msgs::access::time_mark_value_interpretation

Definition at line 45 of file spatem_ts_utils.h.

45{ normal, undefined, over_an_hour, leap_second };

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 78 of file spatem_ts_utils.h.

78 {
79 return ((uint64_t)(moy.value*60) + getUnixSecondsOfYear(unix_nanoseconds_estimate*1e-9))*1e9;
80 }
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 53 of file spatem_ts_utils.h.

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

◆ interpretMovementPhaseStateAsColor()

std::array< float, 4 > etsi_its_spatem_ts_msgs::access::interpretMovementPhaseStateAsColor ( const uint8_t value)
inline

Interprets the MovementPhaseState type as a color (see etsi definition)

Parameters
valueEncoded color value from msg type MovementPhaseState
Returns
4-dimensional array with color values as follows: r, g, b, a, each of these values within a range between [0, 1]

Definition at line 152 of file spatem_ts_utils.h.

153 {
154 std::array<float, 4> color;
155
156 switch (value) {
157
158 case MovementPhaseState::UNAVAILABLE:
159 color = color_grey;
160 break;
161
162 case MovementPhaseState::DARK:
163 color = color_grey;
164 break;
165 case MovementPhaseState::STOP_THEN_PROCEED:
166 color = color_red;
167 break;
168 case MovementPhaseState::STOP_AND_REMAIN:
169 color = color_red;
170 break;
171 case MovementPhaseState::PRE_MOVEMENT:
172 color = color_orange;
173 break;
174 case MovementPhaseState::PERMISSIVE_MOVEMENT_ALLOWED:
175 color = color_green;
176 break;
177 case MovementPhaseState::PROTECTED_MOVEMENT_ALLOWED:
178 color = color_green;
179 break;
180 case MovementPhaseState::PERMISSIVE_CLEARANCE:
181 color = color_orange;
182 break;
183 case MovementPhaseState::PROTECTED_CLEARANCE:
184 color = color_orange;
185 break;
186 case MovementPhaseState::CAUTION_CONFLICTING_TRAFFIC:
187 color = color_orange;
188 break;
189 default:
190 color = color_grey;
191 break;
192 }
193
194 return color;
195}

◆ interpretTimeIntervalConfidenceAsFloat()

float etsi_its_spatem_ts_msgs::access::interpretTimeIntervalConfidenceAsFloat ( const uint16_t encoded_probability)
inline

Interprets the TimeIntervalConfidence type as a float value (see etsi definition)

Parameters
encoded_probabilityValue from msg type TimeIntervalConfidence
Returns
confidence as float value [0, 1]

Definition at line 88 of file spatem_ts_utils.h.

88 {
89 float probability = 0;
90
91 switch (encoded_probability)
92 {
93 case 0:
94 probability = 0.21;
95 break;
96 case 1:
97 probability = 0.36;
98 break;
99 case 2:
100 probability = 0.47;
101 break;
102 case 3:
103 probability = 0.56;
104 break;
105 case 4:
106 probability = 0.62;
107 break;
108 case 5:
109 probability = 0.68;
110 break;
111 case 6:
112 probability = 0.73;
113 break;
114 case 7:
115 probability = 0.77;
116 break;
117 case 8:
118 probability = 0.81;
119 break;
120 case 9:
121 probability = 0.85;
122 break;
123 case 10:
124 probability = 0.88;
125 break;
126 case 11:
127 probability = 0.91;
128 break;
129 case 12:
130 probability = 0.94;
131 break;
132 case 13:
133 probability = 0.96;
134 break;
135 case 14:
136 probability = 0.98;
137 break;
138 case 15:
139 probability = 1.0;
140 break;
141 }
142
143 return probability;
144 }

◆ interpretTimeMarkValueAsSeconds()

float etsi_its_spatem_ts_msgs::access::interpretTimeMarkValueAsSeconds ( const uint16_t time,
const int32_t seconds,
const uint32_t nanosec )

Calculate the amount of seconds until the given time is reached.

Parameters
timeEncoded time value in the future
secondsElapsed seconds since the start of the last full hour (timestamp)
nanosecElapsed nanoseconds since the start of the last full hour (timestamp)
Returns
Time in seconds refered to the given timestamp

Definition at line 230 of file spatem_ts_utils.h.

230 {
231 // calculate elapsed seconds since the start of the last full hour
232 float abs_time_hour = ((int)(seconds)) % 3600 + (float)nanosec * 1e-9;
233 float rel_time_until_change = (float)time * 0.1f - abs_time_hour;
234
235 return rel_time_until_change;
236}

◆ interpretTimeMarkValueType()

time_mark_value_interpretation etsi_its_spatem_ts_msgs::access::interpretTimeMarkValueType ( const uint16_t time)

Interprets the type of a TimeMark message See etsi ASNI1 - IS TS 103 301 documentation for for the encoding of "TimeMark".

Parameters
timeThe value inside the TimeMark message
Returns
Type as time_mark_value_interpretation

Definition at line 203 of file spatem_ts_utils.h.

203 {
204 time_mark_value_interpretation type;
205
206 if (time == 36001) {
207 // value is undefined or unknown
208 type = time_mark_value_interpretation::undefined;
209 } else if (time == 36000) {
210 // used to indicate time >3600 seconds
211 type = time_mark_value_interpretation::over_an_hour;
212 } else if (time >= 35991 && time <= 35999) {
213 // leap second
214 type = time_mark_value_interpretation::leap_second;
215 } else { // time >= 0 && time <= 36000
216 type = time_mark_value_interpretation::normal;
217 }
218
219 return type;
220}

◆ parseTimeMarkValueToString()

std::string etsi_its_spatem_ts_msgs::access::parseTimeMarkValueToString ( const uint16_t time,
const int32_t seconds,
const uint32_t nanosec )

Converts a value from message type TimeMarkValue into a string representation.

Parameters
timeTime in 0.1 seconds until the next change occours in the future, counting from the last started hour
secondsElapsed seconds since the start of the last full hour (timestamp)
nanosecElapsed nanoseconds since the start of the last full hour (timestamp)
Returns
Decoded String representation of the encoded time

Definition at line 246 of file spatem_ts_utils.h.

247{
248 time_mark_value_interpretation time_type = interpretTimeMarkValueType(time);
249
250 std::string text_content;
251
252 switch (time_type) {
253 case time_mark_value_interpretation::undefined:
254 text_content = "undefined";
255 break;
256 case time_mark_value_interpretation::over_an_hour:
257 text_content = ">36000s";
258 break;
259 case time_mark_value_interpretation::leap_second:
260 text_content = "leap second";
261 break;
262 case time_mark_value_interpretation::normal:
263 float rel_time_until_change = interpretTimeMarkValueAsSeconds(time, seconds, nanosec);
264
265 // set displayed precision to 0.1
266 std::stringstream ss;
267 ss << std::fixed << std::setprecision(1) << rel_time_until_change << "s";
268 text_content = ss.str();
269 break;
270 }
271
272 return text_content;
273}
float interpretTimeMarkValueAsSeconds(const uint16_t time, const int32_t seconds, const uint32_t nanosec)
Calculate the amount of seconds until the given time is reached.
time_mark_value_interpretation interpretTimeMarkValueType(const uint16_t time)
Interprets the type of a TimeMark message See etsi ASNI1 - IS TS 103 301 documentation for for the en...

Variable Documentation

◆ color_green

const std::array<float, 4> etsi_its_spatem_ts_msgs::access::color_green {0.18, 0.79, 0.21, 1.0}

Definition at line 41 of file spatem_ts_utils.h.

41{0.18, 0.79, 0.21, 1.0};

◆ color_grey

const std::array<float, 4> etsi_its_spatem_ts_msgs::access::color_grey {0.5, 0.5, 0.5, 1.0}

Definition at line 40 of file spatem_ts_utils.h.

40{0.5, 0.5, 0.5, 1.0};

◆ color_orange

const std::array<float, 4> etsi_its_spatem_ts_msgs::access::color_orange {0.9, 0.7, 0.09, 1.0}

Definition at line 42 of file spatem_ts_utils.h.

42{0.9, 0.7, 0.09, 1.0};

◆ color_red

const std::array<float, 4> etsi_its_spatem_ts_msgs::access::color_red {0.8, 0.2, 0.2, 1.0}

Definition at line 43 of file spatem_ts_utils.h.

43{0.8, 0.2, 0.2, 1.0};