13namespace etsi_its_spatem_ts_msgs {
17static constexpr std::array<float, 4> COLOR_GREY{0.5, 0.5, 0.5, 1.0};
18static constexpr std::array<float, 4> COLOR_GREEN{0.18, 0.79, 0.21, 1.0};
19static constexpr std::array<float, 4> COLOR_ORANGE{0.9, 0.7, 0.09, 1.0};
20static constexpr std::array<float, 4> COLOR_RED{0.8, 0.2, 0.2, 1.0};
22static constexpr int HOUR_IN_SECONDS = 3600;
23static constexpr int64_t FACTOR_SECONDS_TO_NANOSECONDS = 1000000000LL;
26static constexpr int64_t FACTOR_ETSI_TIMEMARK_TO_NANOSECONDS = 100000000LL;
27static constexpr float FACTOR_ETSI_TIMEMARK_TO_SECONDS = 0.1f;
29enum time_mark_value_interpretation { normal, undefined, over_an_hour, leap_second };
39 time_t ts =
static_cast<time_t
>(unixSecond);
42 timeinfo = gmtime(&ts);
47 timeinfo->tm_hour = 0;
48 timeinfo->tm_mday = 1;
51 return timegm(timeinfo);
62 const uint64_t unix_nanoseconds_estimate) {
63 return ((uint64_t)(moy.value * 60) +
getUnixSecondsOfYear(unix_nanoseconds_estimate * 1e-9)) * 1e9;
73 float probability = 0;
75 switch (encoded_probability) {
136 std::array<float, 4> color;
139 case MovementPhaseState::UNAVAILABLE:
143 case MovementPhaseState::DARK:
146 case MovementPhaseState::STOP_THEN_PROCEED:
149 case MovementPhaseState::STOP_AND_REMAIN:
152 case MovementPhaseState::PRE_MOVEMENT:
153 color = COLOR_ORANGE;
155 case MovementPhaseState::PERMISSIVE_MOVEMENT_ALLOWED:
158 case MovementPhaseState::PROTECTED_MOVEMENT_ALLOWED:
161 case MovementPhaseState::PERMISSIVE_CLEARANCE:
162 color = COLOR_ORANGE;
164 case MovementPhaseState::PROTECTED_CLEARANCE:
165 color = COLOR_ORANGE;
167 case MovementPhaseState::CAUTION_CONFLICTING_TRAFFIC:
168 color = COLOR_ORANGE;
185 time_mark_value_interpretation type;
189 type = time_mark_value_interpretation::undefined;
190 }
else if (time == 36000) {
192 type = time_mark_value_interpretation::over_an_hour;
193 }
else if (time >= 35991 && time <= 35999) {
195 type = time_mark_value_interpretation::leap_second;
197 type = time_mark_value_interpretation::normal;
212 int64_t timestamp_hour_nanosec = ((nanosec) % (HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS));
214 int64_t timemark_in_nanosec =
215 static_cast<int64_t
>(time) * FACTOR_ETSI_TIMEMARK_TO_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS;
217 int64_t rel_time_until_change = timemark_in_nanosec - timestamp_hour_nanosec;
220 if (rel_time_until_change < 0) {
221 rel_time_until_change += HOUR_IN_SECONDS * FACTOR_SECONDS_TO_NANOSECONDS;
224 return rel_time_until_change;
236 const uint32_t nanosec) {
237 uint64_t timestamp_in_nanoseconds = seconds * FACTOR_SECONDS_TO_NANOSECONDS + nanosec;
239 static_cast<float>(FACTOR_SECONDS_TO_NANOSECONDS);
253 std::string text_content;
256 case time_mark_value_interpretation::undefined:
257 text_content =
"undefined";
259 case time_mark_value_interpretation::over_an_hour:
260 text_content =
">36000s";
262 case time_mark_value_interpretation::leap_second:
263 text_content =
"leap second";
265 case time_mark_value_interpretation::normal:
269 std::stringstream ss;
270 ss << std::fixed << std::setprecision(1) << rel_time_until_change <<
"s";
271 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.