49 lines
961 B
C++
49 lines
961 B
C++
#include "heartbeat_task.h"
|
|
|
|
extern "C" {
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_log.h"
|
|
#include "protocol.h"
|
|
#include <time.h>
|
|
}
|
|
|
|
static const char* TAG = "heartbeat";
|
|
|
|
static TaskHandle_t heartbeat_task_handle = nullptr;
|
|
|
|
static void heartbeat_task(void* arg)
|
|
{
|
|
while (1)
|
|
{
|
|
if (protocol_is_connected())
|
|
{
|
|
time_t now;
|
|
time(&now);
|
|
|
|
protocol_send_event_hb((uint32_t)now);
|
|
vTaskDelay(pdMS_TO_TICKS(30000)); // 30 сек
|
|
} else
|
|
{
|
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
|
}
|
|
}
|
|
}
|
|
|
|
void heartbeat_task_start()
|
|
{
|
|
if (heartbeat_task_handle == nullptr)
|
|
{
|
|
xTaskCreate(heartbeat_task, "heartbeat", 4096, nullptr, 5, &heartbeat_task_handle);
|
|
}
|
|
}
|
|
|
|
void heartbeat_task_stop()
|
|
{
|
|
if (heartbeat_task_handle != nullptr)
|
|
{
|
|
vTaskDelete(heartbeat_task_handle);
|
|
heartbeat_task_handle = nullptr;
|
|
}
|
|
}
|