|
Modbus Vault v1.0
|
Implementation of the telemetry service. More...
#include "telemetry_service.h"#include "debug_pins.h"#include "esp_err.h"#include "esp_timer.h"#include "event_bus.h"#include "freertos/semphr.h"#include "metrics.h"#include "runtime_tasks.h"Macros | |
| #define | TELEMETRY_SERVICE_LIVE_QUEUE_LENGTH (16U) |
| #define | TELEMETRY_SERVICE_LIVE_QUOTA (2U) |
| #define | TELEMETRY_SERVICE_REPLAY_QUOTA (1U) |
| #define | TELEMETRY_SERVICE_TASK_DELAY_TIME_MS (30U) |
| #define | TELEMETRY_SERVICE_PUBLISH_METRICS_PERIOD_US (300000000UL) |
| #define | TELEMETRY_SERVICE_FULL_TOPIC_MAX_SIZE (128U) |
Functions | |
| static esp_err_t | generate_topics_internal (const char *device_id_ptr) |
| Generate publishing topics. | |
| static void | process_live_quota_internal (void) |
| Process live records quota. | |
| static bool | process_replay_quota_internal (void) |
| Process replay records quota. | |
| static void | handle_system_metrics_internal (void *arg_void_ptr) |
| Handle sending system's metrics. | |
| static bool | publish_to_topic_helper (const telemetry_pipeline_record_t *payload_ptr, telemetry_service_topics_t topic) |
| Publish to topic. | |
| static void | telemetry_service_task (void *parameters_void_ptr) |
| Process live queue and replay if available. | |
| static void | telemetry_service_stop_task (void) |
| Stop telemetry service task. | |
| bool | telemetry_service_init (mqtt_bridge_config_t *mqtt_bridge_config_ptr, bool(*replay_check_cb)(void)) |
| Initialize telemetry service. | |
| bool | telemetry_service_enqueue_live (const telemetry_pipeline_record_t *payload_ptr) |
| Enqueue live record. | |
| bool | telemetry_service_publish_live (const telemetry_pipeline_record_t *payload_ptr) |
| Publish live record. | |
| bool | telemetry_service_publish_replay (const telemetry_pipeline_record_t *payload_ptr) |
| Publish replay record. | |
| bool | telemetry_service_publish_status (const telemetry_pipeline_record_t *payload_ptr) |
| Publish status. | |
| void | telemetry_service_notify_replay_available (void) |
| Send signal replay available. | |
| void | telemetry_service_set_online (bool online) |
| Set online state. | |
| bool | telemetry_service_is_online (void) |
| Get online state. | |
| void | telemetry_service_deinit (void) |
| Deinitialize telemetry service. | |
Variables | |
| static const char * | TAG = "TELEMETRY_SERVICE" |
| static const char * | topic_suffixes [] = {"/modbus/live", "/modbus/replay", "/modbus/status"} |
| static char | topics [TELEMETRY_SERVICE_TOPICS_MAX][(128U)] |
| static uint8_t | topics_qos [TELEMETRY_SERVICE_TOPICS_MAX] |
| static TaskHandle_t | telemetry_service_task_handle = NULL |
| static QueueHandle_t | live_queue = NULL |
| static SemaphoreHandle_t | telemetry_service_state_lock = NULL |
| static bool | telemetry_service_is_online_flag = false |
| static mqtt_bridge_t | mqtt_bridge |
| esp_timer_handle_t | pub_metrics_timer_handle = NULL |
| bool(* | publish_replay_cb_func )(void) = NULL |
| runtime_task_config_t | telemetry_service_task_config |
Implementation of the telemetry service.
| #define TELEMETRY_SERVICE_FULL_TOPIC_MAX_SIZE (128U) |
MQTT topics maximum size
| #define TELEMETRY_SERVICE_LIVE_QUEUE_LENGTH (16U) |
Live queue length
| #define TELEMETRY_SERVICE_LIVE_QUOTA (2U) |
Live quota
| #define TELEMETRY_SERVICE_PUBLISH_METRICS_PERIOD_US (300000000UL) |
Publish system's metrics period in micro seconds
| #define TELEMETRY_SERVICE_REPLAY_QUOTA (1U) |
Replay quota
| #define TELEMETRY_SERVICE_TASK_DELAY_TIME_MS (30U) |
Replay task delay time after a burst in micro seconds
|
static |
Generate publishing topics.
Generate publishing topics according to a preset template defined by topics base and topic_suffixes
| device_id_ptr | Pointer to device id |
| ESP_OK | Generate success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| ESP_ERR_INVALID_SIZE | Topic size exceeded maximum |
< MQTT topics maximum size
< MQTT topics maximum size
|
static |
Handle sending system's metrics.
Get system metrics snapshot, stamp it and publish it
| arg_void_ptr | Void pointer to argument |
|
static |
Process live records quota.
< Live quota
|
static |
Process replay records quota.
< Replay quota
|
static |
Publish to topic.
| payload_ptr | Pointer to record |
| topic | Topic |
| bool telemetry_service_enqueue_live | ( | const telemetry_pipeline_record_t * | payload_ptr | ) |
Enqueue live record.
| payload_ptr | Pointer to record |
| bool telemetry_service_init | ( | mqtt_bridge_config_t * | mqtt_bridge_config_ptr, |
| bool(*)(void) | replay_check_cb | ||
| ) |
Initialize telemetry service.
Initialize MQTT bridge instance and create queue
| mqtt_bridge_config_ptr | Pointer to MQTT bridge configuration structure |
| replay_check_cb | Callback for replay check |
< Live queue length
< Publish system's metrics period in micro seconds
| bool telemetry_service_is_online | ( | void | ) |
Get online state.
| bool telemetry_service_publish_live | ( | const telemetry_pipeline_record_t * | payload_ptr | ) |
Publish live record.
| payload_ptr | Pointer to record |
| bool telemetry_service_publish_replay | ( | const telemetry_pipeline_record_t * | payload_ptr | ) |
Publish replay record.
| payload_ptr | Pointer to record |
| bool telemetry_service_publish_status | ( | const telemetry_pipeline_record_t * | payload_ptr | ) |
Publish status.
| payload_ptr | Pointer to record |
| void telemetry_service_set_online | ( | bool | online | ) |
Set online state.
| online | Online state |
|
static |
Process live queue and replay if available.
| parameters_void_ptr | Void pointer to task parameters |
< Replay task delay time after a burst in micro seconds
|
static |
Telemetry Service live queue handle
|
static |
MQTT Bridge instance
| esp_timer_handle_t pub_metrics_timer_handle = NULL |
Timer handle for system's metrics publishing
| bool(* publish_replay_cb_func) (void) | ( | void | ) | = NULL |
Callback for publishing replay
|
static |
Telemetry Service TAG name
|
static |
Telemetry Service state flag
|
static |
Telemetry Service state flag lock
| runtime_task_config_t telemetry_service_task_config |
Telemetry Service task configuration structure
|
static |
Telemetry Service task handle
|
static |
Topics preset suffixes
|
static |
Full topics
|
static |
Topic QoS