ESP32/components/gps_sync/gps_sync.h

36 lines
1.2 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);
// 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 esp_log_timestamp(void);
int gps_log_vprintf(const char *fmt, va_list args);