new release
This commit is contained in:
63
components/time_service/include/time_service.h
Normal file
63
components/time_service/include/time_service.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Inicializa o serviço de hora.
|
||||
*
|
||||
* Responsabilidades do módulo:
|
||||
* - definir a timezone local do equipamento
|
||||
* - registar handlers dos eventos de rede
|
||||
* - arrancar SNTP quando a STA obtém IP
|
||||
* - expor o estado atual da sincronização
|
||||
*/
|
||||
void time_service_init(void);
|
||||
|
||||
/**
|
||||
* @brief Indica se já houve pelo menos uma sincronização SNTP com sucesso.
|
||||
*/
|
||||
bool time_service_is_synced(void);
|
||||
|
||||
/**
|
||||
* @brief Indica se existe uma tentativa de sincronização em curso.
|
||||
*/
|
||||
bool time_service_is_sync_in_progress(void);
|
||||
|
||||
/**
|
||||
* @brief Retorna true se a hora atual parece válida.
|
||||
*
|
||||
* Critério simples: ano >= 2024.
|
||||
*/
|
||||
bool time_service_has_valid_time(void);
|
||||
|
||||
/**
|
||||
* @brief Força uma nova espera pela sincronização atual.
|
||||
*
|
||||
* Não reinicializa o SNTP. Apenas lança uma task curta que aguarda pela sync.
|
||||
*/
|
||||
esp_err_t time_service_force_resync(void);
|
||||
|
||||
/**
|
||||
* @brief Nome IANA da timezone alvo do produto.
|
||||
*/
|
||||
const char *time_service_get_tz_name(void);
|
||||
|
||||
/**
|
||||
* @brief String POSIX usada por setenv("TZ", ...).
|
||||
*/
|
||||
const char *time_service_get_tz_posix(void);
|
||||
|
||||
/**
|
||||
* @brief Obtém o epoch atual.
|
||||
*/
|
||||
time_t time_service_get_epoch(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
32
components/time_service/include/time_service_events.h
Normal file
32
components/time_service/include/time_service_events.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include "esp_event.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(TIME_SERVICE_EVENTS);
|
||||
|
||||
typedef enum {
|
||||
TIME_SERVICE_EVENT_INIT = 0,
|
||||
TIME_SERVICE_EVENT_SYNC_STARTED,
|
||||
TIME_SERVICE_EVENT_SYNC_OK,
|
||||
TIME_SERVICE_EVENT_SYNC_TIMEOUT,
|
||||
TIME_SERVICE_EVENT_NETWORK_LOST,
|
||||
} time_service_event_id_t;
|
||||
|
||||
typedef struct {
|
||||
bool timezone_configured;
|
||||
bool sntp_initialized;
|
||||
bool sync_in_progress;
|
||||
bool synced;
|
||||
bool valid_time;
|
||||
time_t now;
|
||||
} time_service_state_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user