rec.h 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. #ifndef __rec_h__
  2. #define __rec_h__
  3. #include <stdint.h>
  4. // Flash存储配置
  5. #define RECORD_FLASH_SECTOR (10ul) // 记录使用的Flash扇区
  6. #define RECORD_MAX_COUNT (5 * 24ul) // 最多保存5天数据
  7. // 记录数据结构体
  8. typedef struct __attribute__((packed))
  9. {
  10. uint32_t timestamp; // 时间戳(秒)
  11. uint16_t temperature; // 温度(0.1摄氏度为单位)
  12. uint16_t humidity; // 湿度(0.1%RH为单位)
  13. uint32_t illuminance; // 光照强度(lux)
  14. uint16_t voltage; // 电压(mV)
  15. } rec_data_t;
  16. // 实际存储按照32字节对齐,数据区最大28字节
  17. _Static_assert(sizeof(rec_data_t) <= 28, "rec_data_t size is invalid: must be between 1 and 28 bytes");
  18. // 函数声明
  19. extern int rec_init(void); // 初始化记录模块
  20. extern int rec_write(const rec_data_t *data); // 写入新记录
  21. extern int rec_read(uint16_t start_index, uint16_t *out_index, rec_data_t *data_out); // 读取指定索引的记录
  22. extern int rec_delete(uint16_t index); // 删除指定索引的记录
  23. extern uint16_t rec_get_count(void); // 获取未上传的记录条数
  24. extern int rec_clear_all(void); // 清除所有记录
  25. extern int rec_get_last(rec_data_t *data_out); // 获取最后一条记录
  26. #endif