| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2025-11-20 RuoFeng the first version
- */
- /**
- * BSP CSV文件操作模块 - 简化版
- */
- #ifndef __BSP_CSV_H__
- #define __BSP_CSV_H__
- /*********************↓ include ↓************************/
- #include <rtthread.h>
- #include "ch376_driver.h"
- /*********************↑ include ↑************************/
- /********************↓ declaration ↓***********************/
- /**
- *
- *
- *
- *
- * */
- /* CSV操作结果 */
- typedef enum
- {
- CSV_SUCCESS = 0,
- CSV_ERROR,
- CSV_DEVICE_NOT_READY,
- CSV_FILE_NOT_FOUND,
- CSV_FILE_ALREADY_OPEN
- } csv_result_t;
- /* CSV打开模式 */
- typedef enum
- {
- CSV_MODE_READ = 0, // 只读模式
- CSV_MODE_APPEND, // 追加模式
- CSV_MODE_OVERWRITE // 覆盖模式
- } csv_mode_t;
- /* 简化CSV操作接口 */
- typedef struct
- {
- /* 文件操作 */
- csv_result_t (*create)(const char *filename, const char *header);
- csv_result_t (*open)(const char *filename, csv_mode_t mode, const char *header);
- csv_result_t (*append)(const char *format, ...);
- csv_result_t (*close)(void);
- /* 设备管理 */
- csv_result_t (*init)(ch376_mode_t mode);
- csv_result_t (*deinit)(void);
- /* 状态查询 */
- uint32_t (*get_line_count)(void);
- uint32_t (*count_file_lines)(const char *filename);
- uint8_t (*is_opened)(void);
- const char *(*get_filename)(void);
- } csv_ops_t;
- /********************↑ declaration ↑***********************/ /**
- *
- *
- *
- *
- * */
- /*********************↓ extern ↓************************/
- /* 全局操作接口 */
- extern csv_ops_t csv;
- /*********************↑ extern ↑************************/
- /**
- *
- *
- *
- *
- * */
- /*********************↓ define ↓************************/
- /* 便捷宏定义 */
- #define CSV_CREATE(filename, header) csv.create(filename, header)
- #define CSV_OPEN(filename, mode, header) csv.open(filename, mode, header)
- #define CSV_APPEND(...) csv.append(__VA_ARGS__)
- #define CSV_CLOSE() csv.close()
- #define CSV_INIT(mode) csv.init(mode)
- #define CSV_DEINIT() csv.deinit()
- #define CSV_GET_LINE_COUNT() csv.get_line_count()
- #define CSV_COUNT_FILE_LINES(filename) csv.count_file_lines(filename)
- #define CSV_IS_OPENED() csv.is_opened()
- #define CSV_GET_FILENAME() csv.get_filename()
- /*********************↑ define ↑************************/
- /**
- *
- *
- *
- *
- * */
- /*********************↓ global variables ↓************************/
- /*********************↑ global variables ↑************************/
- /**
- *
- *
- *
- *
- * */
- /**
- *
- * BIT_MAP
- *
- *
- * */
- // 配置:基准日期
- #define CSV_BITMAP_EPOCH_YY 26
- #define CSV_BITMAP_EPOCH_MM 1
- #define CSV_BITMAP_EPOCH_DD 1
- // 支持 10 年(2025 ~ 2034),共 3653 天
- #define CSV_BITMAP_MAX_DAYS 3653
- #define CSV_BITMAP_BYTES ((CSV_BITMAP_MAX_DAYS + 7) / 8)
- // 版本号:用于未来兼容性升级
- #define CSV_BITMAP_VERSION 0x0100U // v1.0
- // 初始化位图模块(建议在系统启动时调用一次)
- void csv_bitmap_init(void);
- // 标记某天 CSV 文件已存在(从 csv_create 成功后调用)
- int csv_bitmap_mark_exist(int yy, int mm, int dd);
- // 查询某天是否已知存在(用于 transfer 前快速判断)
- int csv_bitmap_is_exist(int yy, int mm, int dd);
- /**
- *
- * BIT_MAP
- *
- *
- * */
- /**
- *
- * EXPORT
- *
- *
- * */
- #define MAX_EXPORT_SPAN_DAYS CSV_BITMAP_MAX_DAYS
- /**
- *
- * EXPORT
- *
- *
- * */
- #endif /* __BSP_CSV_H__ */
|