36namespace etsi_its_spatem_ts_msgs {
40 static constexpr std::array<float, 4> COLOR_GREY {0.5, 0.5, 0.5, 1.0};
41 static constexpr std::array<float, 4> COLOR_GREEN {0.18, 0.79, 0.21, 1.0};
42 static constexpr std::array<float, 4> COLOR_ORANGE {0.9, 0.7, 0.09, 1.0};
43 static constexpr std::array<float, 4> COLOR_RED {0.8, 0.2, 0.2, 1.0};
45 static constexpr int HOUR_IN_SECONDS = 3600;
46 static constexpr int HALF_HOUR_IN_SECONDS = 1800;
47 static constexpr int64_t FACTOR_SECONDS_TO_NANOSECONDS = 1000000000LL;
50 static constexpr int64_t FACTOR_ETSI_TIMEMARK_TO_NANOSECONDS = 100000000LL;
51 static constexpr float FACTOR_ETSI_TIMEMARK_TO_SECONDS = 0.1f;
53 enum time_mark_value_interpretation { normal, undefined, over_an_hour, leap_second };
64 time_t ts =
static_cast<time_t
>(unixSecond);
67 timeinfo = gmtime(&ts);
72 timeinfo->tm_hour = 0;
73 timeinfo->tm_mday = 1;
76 return timegm(timeinfo);
97 float probability = 0;
99 switch (encoded_probability)
162 std::array<float, 4> color;
166 case MovementPhaseState::UNAVAILABLE:
170 case MovementPhaseState::DARK:
173 case MovementPhaseState::STOP_THEN_PROCEED:
176 case MovementPhaseState::STOP_AND_REMAIN:
179 case MovementPhaseState::PRE_MOVEMENT:
180 color = COLOR_ORANGE;
182 case MovementPhaseState::PERMISSIVE_MOVEMENT_ALLOWED:
185 case MovementPhaseState::PROTECTED_MOVEMENT_ALLOWED:
188 case MovementPhaseState::PERMISSIVE_CLEARANCE:
189 color = COLOR_ORANGE;
191 case MovementPhaseState::PROTECTED_CLEARANCE:
192 color = COLOR_ORANGE;
194 case MovementPhaseState::CAUTION_CONFLICTING_TRAFFIC:
195 color = COLOR_ORANGE;
212 time_mark_value_interpretation type;
216 type = time_mark_value_interpretation::undefined;
217 }
else if (time == 36000) {
219 type = time_mark_value_interpretation::over_an_hour;
220 }
else if (time >= 35991 && time <= 35999) {
222 type = time_mark_value_interpretation::leap_second;
224 type = time_mark_value_interpretation::normal;
239 int64_t abs_time_hour_nanosec = ((nanosec) % (HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS));
240 int64_t abs_time_decoded_nanosec =
static_cast<int64_t
>(time) * FACTOR_ETSI_TIMEMARK_TO_SECONDS;
241 int64_t rel_time_until_change = abs_time_decoded_nanosec - abs_time_hour_nanosec;
244 if (rel_time_until_change < - HALF_HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS) {
245 rel_time_until_change += HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS;
248 return rel_time_until_change;
261 float abs_time_hour = ((int)(seconds)) % HOUR_IN_SECONDS + (
float)nanosec * 1e-9;
262 float rel_time_until_change = (float)time * FACTOR_ETSI_TIMEMARK_TO_SECONDS - abs_time_hour;
265 if (rel_time_until_change < - HALF_HOUR_IN_SECONDS) {
266 rel_time_until_change += HOUR_IN_SECONDS;
269 return rel_time_until_change;
284 std::string text_content;
287 case time_mark_value_interpretation::undefined:
288 text_content =
"undefined";
290 case time_mark_value_interpretation::over_an_hour:
291 text_content =
">36000s";
293 case time_mark_value_interpretation::leap_second:
294 text_content =
"leap second";
296 case time_mark_value_interpretation::normal:
300 std::stringstream ss;
301 ss << std::fixed << std::setprecision(1) << rel_time_until_change <<
"s";
302 text_content = ss.str();
uint64_t getUnixSecondsOfYear(const uint64_t unixSecond)
Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.
std::array< float, 4 > interpretMovementPhaseStateAsColor(const uint8_t value)
Interprets the MovementPhaseState type as a color (see etsi definition)
uint64_t getUnixNanosecondsFromMinuteOfTheYear(const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from MinuteOfTheYear object.
int64_t interpretTimeMarkValueAsNanoSeconds(const uint16_t time, const uint64_t nanosec)
Calculates the delta between the encoded time mark and the current timestamp.
float interpretTimeMarkValueAsSeconds(const uint16_t time, const int32_t seconds, const uint32_t nanosec)
Calculates the delta between the encoded time mark and the current timestamp.
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...
std::string parseTimeMarkValueToString(const uint16_t time, const int32_t seconds, const uint32_t nanosec)
Converts a value from message type TimeMarkValue into a string representation.
float interpretTimeIntervalConfidenceAsFloat(const uint16_t encoded_probability)
Interprets the TimeIntervalConfidence type as a float value (see etsi definition)