Files
gps/soc/software/gps_system/header/gps_time_anchor.h
T

35 lines
1.5 KiB
C

#ifndef GPS_TIME_ANCHOR_H_INCLUDED
#define GPS_TIME_ANCHOR_H_INCLUDED
#include <stdbool.h>
#include <stdint.h>
#define GPS_TIME_WEEK_SECONDS 604800.0
#define GPS_TIME_HALF_WEEK_SECONDS 302400.0
/* Resolve the week of a newly received HOW against the previous HOW anchor.
* The HOW contains seconds-of-week; the signed half-week rule makes the
* Saturday/Sunday rollover explicit without depending on a NAV timer. */
int gps_time_resolve_how_week(bool previous_valid,
int previous_week,
double previous_tow_sec,
int fallback_week,
double how_tow_sec);
/* Convert a receiver-sample timestamp to GPS time from a HOW/sample anchor.
* raw counters are modulo 2^32. max_age_sec must keep the signed difference
* unambiguous (and also rejects a stale HOW anchor). */
bool gps_time_from_sample_anchor(int anchor_week,
double anchor_tow_sec,
uint32_t anchor_raw_sample,
double anchor_corrected_sample,
uint32_t event_raw_sample,
double event_corrected_sample,
double samples_per_second,
double max_age_sec,
int* event_week_out,
double* event_tow_sec_out,
double* elapsed_sec_out);
#endif