41 lines
1.4 KiB
C
41 lines
1.4 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/semphr.h"
|
|
|
|
typedef struct {
|
|
int64_t monotonic_us; // Microseconds - never jumps backward
|
|
int64_t monotonic_ms; // Milliseconds - for easier logging
|
|
int64_t gps_us; // GPS UTC time in microseconds
|
|
int64_t gps_ms; // GPS UTC time in milliseconds
|
|
struct timespec mono_ts; // POSIX timespec (for clock_gettime)
|
|
bool synced; // true if GPS has valid fix
|
|
} gps_timestamp_t;
|
|
|
|
// Initialize GPS sync system
|
|
// If use_gps_log_timestamps is true, ESP_LOGI/ESP_LOGW/etc will use GPS time
|
|
// with visual indicators:
|
|
// I (+1733424645.234) TAG: message <-- + indicates GPS synced
|
|
// I (*1.234) TAG: message <-- * indicates not synced (monotonic)
|
|
void gps_sync_init(bool use_gps_log_timestamps);
|
|
|
|
// FORCE UPDATE: Ignore the low-pass filter for the next valid GPS fix.
|
|
// This snaps the time offset immediately to the new value.
|
|
// Useful on boot or if you detect a massive time discrepancy.
|
|
void gps_force_next_update(void);
|
|
|
|
// Get current timestamp (with both us and ms)
|
|
gps_timestamp_t gps_get_timestamp(void);
|
|
|
|
// Get millisecond timestamp using clock_gettime
|
|
int64_t gps_get_monotonic_ms(void);
|
|
|
|
// Check if GPS is synced
|
|
bool gps_is_synced(void);
|
|
|
|
// Internal functions (called automatically by ESP-IDF - don't call directly)
|
|
uint32_t gps_log_timestamp(void);
|
|
int gps_log_vprintf(const char *fmt, va_list args);
|