QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSTime.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
6namespace GPSTime {
7
9inline constexpr uint32_t WEEK_MS = 604800000;
10
12[[nodiscard]] constexpr uint64_t epochMs(uint32_t week, uint32_t towMs)
13{
14 return uint64_t(week) * WEEK_MS + towMs;
15}
16
18[[nodiscard]] constexpr bool towAdvances(uint32_t later, uint32_t earlier)
19{
20 const uint64_t difference = (uint64_t(later) + WEEK_MS - earlier) % WEEK_MS;
21 return difference != 0 && difference < WEEK_MS / 2;
22}
23
24} // namespace GPSTime
GPS system time as receivers stamp their epochs: a week number and the milliseconds into that week.
Definition GPSTime.h:6
constexpr uint64_t epochMs(uint32_t week, uint32_t towMs)
Milliseconds since the GPS epoch of towMs into week.
Definition GPSTime.h:12
constexpr bool towAdvances(uint32_t later, uint32_t earlier)
Whether time of week later follows earlier by less than half a week, across the week rollover.
Definition GPSTime.h:18
constexpr uint32_t WEEK_MS
Milliseconds in a GPS week; every time of week is below it.
Definition GPSTime.h:9