bsp_csv.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-11-20 RuoFeng the first version
  9. */
  10. /**
  11. * BSP CSV文件操作模块 - 简化版
  12. */
  13. #ifndef __BSP_CSV_H__
  14. #define __BSP_CSV_H__
  15. /*********************↓ include ↓************************/
  16. #include <rtthread.h>
  17. #include "ch376_driver.h"
  18. /*********************↑ include ↑************************/
  19. /********************↓ declaration ↓***********************/
  20. /**
  21. *
  22. *
  23. *
  24. *
  25. * */
  26. /* CSV操作结果 */
  27. typedef enum
  28. {
  29. CSV_SUCCESS = 0,
  30. CSV_ERROR,
  31. CSV_DEVICE_NOT_READY,
  32. CSV_FILE_NOT_FOUND,
  33. CSV_FILE_ALREADY_OPEN
  34. } csv_result_t;
  35. /* CSV打开模式 */
  36. typedef enum
  37. {
  38. CSV_MODE_READ = 0, // 只读模式
  39. CSV_MODE_APPEND, // 追加模式
  40. CSV_MODE_OVERWRITE // 覆盖模式
  41. } csv_mode_t;
  42. /* 简化CSV操作接口 */
  43. typedef struct
  44. {
  45. /* 文件操作 */
  46. csv_result_t (*create)(const char *filename, const char *header);
  47. csv_result_t (*open)(const char *filename, csv_mode_t mode, const char *header);
  48. csv_result_t (*append)(const char *format, ...);
  49. csv_result_t (*close)(void);
  50. /* 设备管理 */
  51. csv_result_t (*init)(ch376_mode_t mode);
  52. csv_result_t (*deinit)(void);
  53. /* 状态查询 */
  54. uint32_t (*get_line_count)(void);
  55. uint32_t (*count_file_lines)(const char *filename);
  56. uint8_t (*is_opened)(void);
  57. const char *(*get_filename)(void);
  58. } csv_ops_t;
  59. /********************↑ declaration ↑***********************/ /**
  60. *
  61. *
  62. *
  63. *
  64. * */
  65. /*********************↓ extern ↓************************/
  66. /* 全局操作接口 */
  67. extern csv_ops_t csv;
  68. /*********************↑ extern ↑************************/
  69. /**
  70. *
  71. *
  72. *
  73. *
  74. * */
  75. /*********************↓ define ↓************************/
  76. /* 便捷宏定义 */
  77. #define CSV_CREATE(filename, header) csv.create(filename, header)
  78. #define CSV_OPEN(filename, mode, header) csv.open(filename, mode, header)
  79. #define CSV_APPEND(...) csv.append(__VA_ARGS__)
  80. #define CSV_CLOSE() csv.close()
  81. #define CSV_INIT(mode) csv.init(mode)
  82. #define CSV_DEINIT() csv.deinit()
  83. #define CSV_GET_LINE_COUNT() csv.get_line_count()
  84. #define CSV_COUNT_FILE_LINES(filename) csv.count_file_lines(filename)
  85. #define CSV_IS_OPENED() csv.is_opened()
  86. #define CSV_GET_FILENAME() csv.get_filename()
  87. /*********************↑ define ↑************************/
  88. /**
  89. *
  90. *
  91. *
  92. *
  93. * */
  94. /*********************↓ global variables ↓************************/
  95. /*********************↑ global variables ↑************************/
  96. /**
  97. *
  98. *
  99. *
  100. *
  101. * */
  102. /**
  103. *
  104. * BIT_MAP
  105. *
  106. *
  107. * */
  108. // 配置:基准日期
  109. #define CSV_BITMAP_EPOCH_YY 26
  110. #define CSV_BITMAP_EPOCH_MM 1
  111. #define CSV_BITMAP_EPOCH_DD 1
  112. // 支持 10 年(2025 ~ 2034),共 3653 天
  113. #define CSV_BITMAP_MAX_DAYS 3653
  114. #define CSV_BITMAP_BYTES ((CSV_BITMAP_MAX_DAYS + 7) / 8)
  115. // 版本号:用于未来兼容性升级
  116. #define CSV_BITMAP_VERSION 0x0100U // v1.0
  117. // 初始化位图模块(建议在系统启动时调用一次)
  118. void csv_bitmap_init(void);
  119. // 标记某天 CSV 文件已存在(从 csv_create 成功后调用)
  120. int csv_bitmap_mark_exist(int yy, int mm, int dd);
  121. // 查询某天是否已知存在(用于 transfer 前快速判断)
  122. int csv_bitmap_is_exist(int yy, int mm, int dd);
  123. /**
  124. *
  125. * BIT_MAP
  126. *
  127. *
  128. * */
  129. /**
  130. *
  131. * EXPORT
  132. *
  133. *
  134. * */
  135. #define MAX_EXPORT_SPAN_DAYS CSV_BITMAP_MAX_DAYS
  136. /**
  137. *
  138. * EXPORT
  139. *
  140. *
  141. * */
  142. #endif /* __BSP_CSV_H__ */