|
IoT25S IoT Klocka 0.1
Grupparbete för IoT25S på Jensen YH
|
#include "time_service.h"#include <stdbool.h>#include <stdlib.h>#include <string.h>#include <sys/time.h>#include <time.h>#include "freertos/FreeRTOS.h"#include "freertos/semphr.h"#include "freertos/task.h"#include "esp_check.h"#include "esp_log.h"#include "esp_sntp.h"#include "sdkconfig.h"#include "app_state.h"
Include dependency graph for time_service.c:Go to the source code of this file.
Data Structures | |
| struct | time_service_tz_entry_t |
Macros | |
| #define | CONFIG_TIME_SERVICE_SNTP_ENABLE 1 |
| #define | CONFIG_TIME_SERVICE_SNTP_SERVER "pool.ntp.org" |
| #define | CONFIG_TIME_SERVICE_SNTP_SYNC_TIMEOUT_MS 15000 |
| #define | CONFIG_TIME_SERVICE_SNTP_MAX_SYNC_ATTEMPTS 3 |
| #define | CONFIG_TIME_SERVICE_SNTP_RETRY_DELAY_MS 5000 |
Functions | |
| static esp_err_t | time_service_store_epoch_from_system (void) |
| static esp_err_t | time_service_set_system_epoch (int64_t epoch) |
| static esp_err_t | time_service_try_sntp_init (void) |
| static void | time_service_sntp_sync_task (void *arg) |
| static void | time_service_posix_from_offset (int16_t offset_min, char *buf, size_t buf_len) |
| void | time_service_apply_timezone (const char *location_id, int16_t fallback_offset_min) |
| Apply a timezone by IANA location ID with DST support. | |
| esp_err_t | time_service_init (void) |
| Initialize time service state and restore persisted time fallback. | |
| esp_err_t | time_service_set_epoch (int64_t epoch) |
| Set current UTC epoch and persist it as valid time. | |
| void | time_service_notify_network_connected (bool connected) |
| Notify the service about network connectivity changes. | |
| bool | time_service_get_local_time (struct tm *out_tm, int64_t *out_epoch) |
| Get local time adjusted by the configured timezone offset. | |
Variables | |
| static const char * | TAG = "time_service" |
| static SemaphoreHandle_t | s_time_lock |
| static bool | s_time_valid |
| static bool | s_network_connected |
| static bool | s_sntp_initialized |
| static bool | s_sntp_sync_task_running |
| static const time_service_tz_entry_t | s_tz_table [] |
| static const size_t | s_tz_table_count = sizeof(s_tz_table) / sizeof(s_tz_table[0]) |
| #define CONFIG_TIME_SERVICE_SNTP_ENABLE 1 |
Definition at line 22 of file time_service.c.
| #define CONFIG_TIME_SERVICE_SNTP_MAX_SYNC_ATTEMPTS 3 |
Definition at line 34 of file time_service.c.
| #define CONFIG_TIME_SERVICE_SNTP_RETRY_DELAY_MS 5000 |
Definition at line 38 of file time_service.c.
| #define CONFIG_TIME_SERVICE_SNTP_SERVER "pool.ntp.org" |
Definition at line 26 of file time_service.c.
| #define CONFIG_TIME_SERVICE_SNTP_SYNC_TIMEOUT_MS 15000 |
Definition at line 30 of file time_service.c.
| void time_service_apply_timezone | ( | const char * | location_id, |
| int16_t | fallback_offset_min | ||
| ) |
Apply a timezone by IANA location ID with DST support.
Looks up a POSIX TZ string for the given IANA location ID and calls setenv("TZ", ...) + tzset() to activate it. For the "custom" ID or any unknown ID, generates a fixed-offset POSIX string from fallback_offset_min (no DST is applied in that case).
Must be called after any timezone configuration change and once during init.
| location_id | IANA timezone location string, or "custom". |
| fallback_offset_min | UTC offset in minutes east of UTC (used only for custom/unknown IDs). |
Definition at line 207 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:| bool time_service_get_local_time | ( | struct tm * | out_tm, |
| int64_t * | out_epoch | ||
| ) |
Get local time adjusted by the configured timezone offset.
Offset may be set directly or derived from a selected timezone location.
| [out] | out_tm | Optional pointer to receive broken-down local time. |
| [out] | out_epoch | Optional pointer to receive local epoch seconds. |
Definition at line 315 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:| esp_err_t time_service_init | ( | void | ) |
Initialize time service state and restore persisted time fallback.
Definition at line 234 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void time_service_notify_network_connected | ( | bool | connected | ) |
Notify the service about network connectivity changes.
Used to trigger SNTP synchronization when connectivity is available.
| connected | true if network is connected, false otherwise. |
Definition at line 283 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 189 of file time_service.c.
Here is the caller graph for this function:| esp_err_t time_service_set_epoch | ( | int64_t | epoch | ) |
Set current UTC epoch and persist it as valid time.
| epoch | UTC epoch seconds. |
Definition at line 270 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 59 of file time_service.c.
Here is the caller graph for this function:
|
static |
Definition at line 88 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 49 of file time_service.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 69 of file time_service.c.
Here is the caller graph for this function:
|
static |
Definition at line 45 of file time_service.c.
|
static |
Definition at line 46 of file time_service.c.
|
static |
Definition at line 47 of file time_service.c.
|
static |
Definition at line 43 of file time_service.c.
|
static |
Definition at line 44 of file time_service.c.
|
static |
Definition at line 169 of file time_service.c.
|
static |
Definition at line 186 of file time_service.c.
|
static |
Definition at line 41 of file time_service.c.