36namespace etsi_its_spatem_ts_msgs {
40static constexpr std::array<float, 4> COLOR_GREY{0.5, 0.5, 0.5, 1.0};
41static constexpr std::array<float, 4> COLOR_GREEN{0.18, 0.79, 0.21, 1.0};
42static constexpr std::array<float, 4> COLOR_ORANGE{0.9, 0.7, 0.09, 1.0};
43static constexpr std::array<float, 4> COLOR_RED{0.8, 0.2, 0.2, 1.0};
45static constexpr int HOUR_IN_SECONDS = 3600;
46static constexpr int64_t FACTOR_SECONDS_TO_NANOSECONDS = 1000000000LL;
49static constexpr int64_t FACTOR_ETSI_TIMEMARK_TO_NANOSECONDS = 100000000LL;
50static constexpr float FACTOR_ETSI_TIMEMARK_TO_SECONDS = 0.1f;
52enum time_mark_value_interpretation { normal, undefined, over_an_hour, leap_second };
62 time_t ts =
static_cast<time_t
>(unixSecond);
65 timeinfo = gmtime(&ts);
70 timeinfo->tm_hour = 0;
71 timeinfo->tm_mday = 1;
74 return timegm(timeinfo);
85 const uint64_t unix_nanoseconds_estimate) {
86 return ((uint64_t)(moy.value * 60) +
getUnixSecondsOfYear(unix_nanoseconds_estimate * 1e-9)) * 1e9;
96 float probability = 0;
98 switch (encoded_probability) {
159 std::array<float, 4> color;
162 case MovementPhaseState::UNAVAILABLE:
166 case MovementPhaseState::DARK:
169 case MovementPhaseState::STOP_THEN_PROCEED:
172 case MovementPhaseState::STOP_AND_REMAIN:
175 case MovementPhaseState::PRE_MOVEMENT:
176 color = COLOR_ORANGE;
178 case MovementPhaseState::PERMISSIVE_MOVEMENT_ALLOWED:
181 case MovementPhaseState::PROTECTED_MOVEMENT_ALLOWED:
184 case MovementPhaseState::PERMISSIVE_CLEARANCE:
185 color = COLOR_ORANGE;
187 case MovementPhaseState::PROTECTED_CLEARANCE:
188 color = COLOR_ORANGE;
190 case MovementPhaseState::CAUTION_CONFLICTING_TRAFFIC:
191 color = COLOR_ORANGE;
208 time_mark_value_interpretation type;
212 type = time_mark_value_interpretation::undefined;
213 }
else if (time == 36000) {
215 type = time_mark_value_interpretation::over_an_hour;
216 }
else if (time >= 35991 && time <= 35999) {
218 type = time_mark_value_interpretation::leap_second;
220 type = time_mark_value_interpretation::normal;
235 int64_t timestamp_hour_nanosec = ((nanosec) % (HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS));
237 int64_t timemark_in_nanosec =
238 static_cast<int64_t
>(time) * FACTOR_ETSI_TIMEMARK_TO_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS;
240 int64_t rel_time_until_change = timemark_in_nanosec - timestamp_hour_nanosec;
243 if (rel_time_until_change < 0) {
244 rel_time_until_change += HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS;
247 return rel_time_until_change;
259 const uint32_t nanosec) {
260 uint64_t timestamp_in_nanoseconds = seconds * FACTOR_SECONDS_TO_NANOSECONDS + nanosec;
262 static_cast<float>(FACTOR_SECONDS_TO_NANOSECONDS);
276 std::string text_content;
279 case time_mark_value_interpretation::undefined:
280 text_content =
"undefined";
282 case time_mark_value_interpretation::over_an_hour:
283 text_content =
">36000s";
285 case time_mark_value_interpretation::leap_second:
286 text_content =
"leap second";
288 case time_mark_value_interpretation::normal:
292 std::stringstream ss;
293 ss << std::fixed << std::setprecision(1) << rel_time_until_change <<
"s";
294 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.
float interpretTimeMarkDeltaTimeValueAsSeconds(const uint16_t time, const int32_t seconds, const uint32_t nanosec)
Calculates the delta between a TimeMark and a given 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)
int64_t interpretTimeMarkDeltaTimeAsNanoSeconds(const uint16_t time, const uint64_t nanosec)
Calculates the delta between a TimeMark and a given unix timestamp in nanoseconds.