Files
DistributedCollectorGateway/components/OFFLINE_STORAGE/include/OFFLINE_STORAGE.h

89 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef OFFLINE_STORAGE_H
#define OFFLINE_STORAGE_H
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
// 数据类型
typedef enum {
OFFLINE_DATA_TYPE_UNKNOWN = 0,
OFFLINE_DATA_TYPE_MODBUS = 1, // MODBUS采集数据
OFFLINE_DATA_TYPE_DEVICE_STATUS = 2, // 设备状态数据
} offline_data_type_t;
/**
* @brief 初始化离线存储模块
*
* @return ESP_OK 成功
* 其他 失败
*/
esp_err_t offline_storage_init(void);
/**
* @brief 存储离线数据
*
* @param data 数据内容JSON字符串
* @param length 数据长度
* @param data_type 数据类型
* @return ESP_OK 成功
* ESP_FAIL 失败
*/
esp_err_t offline_storage_store(const char *data, size_t length, offline_data_type_t data_type);
/**
* @brief 读取最旧的离线数据
*
* @param buffer 输出缓冲区
* @param max_len 缓冲区最大长度
* @param out_data_type 输出数据类型
* @return ESP_OK 成功
* ESP_ERR_NOT_FOUND 没有数据
* 其他 失败
*/
esp_err_t offline_storage_read_oldest(char *buffer, size_t max_len, offline_data_type_t *out_data_type);
/**
* @brief 删除最旧的离线数据
*
* @return ESP_OK 成功
* ESP_ERR_NOT_FOUND 没有数据
* 其他 失败
*/
esp_err_t offline_storage_delete_oldest(void);
/**
* @brief 获取离线数据数量
*
* @return 数据数量
*/
uint32_t offline_storage_get_count(void);
/**
* @brief 检查是否有离线数据
*
* @return true 有数据
* false 无数据
*/
bool offline_storage_has_data(void);
/**
* @brief 清空所有离线数据
*
* @return ESP_OK 成功
* 其他 失败
*/
esp_err_t offline_storage_clear_all(void);
/**
* @brief 获取存储使用情况
*
* @param used 已使用字节数
* @param total 总字节数
* @return ESP_OK 成功
* 其他 失败
*/
esp_err_t offline_storage_get_usage(size_t *used, size_t *total);
#endif // OFFLINE_STORAGE_H