FluxDC/components/FluxSD/FluxSD.h

156 lines
3.2 KiB
C
Raw Normal View History

/**
* @file FluxSD.h
* @brief SD卡头文件
*
*
*
* @author wang xiang en
* @date 2025-04-18
* @version
* @copyright (C)2025, YUWELL MEDTECH Co.ltd
2025-03-07 19:07:31 +08:00
*/
2025-03-15 09:37:07 +08:00
#ifndef _FLUX_SD_H
#define _FLUX_SD_H
2025-03-07 19:07:31 +08:00
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
#include "driver/gpio.h"
#include "esp_cpu.h"
#include "esp_log.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
/* 包含FluxProtocol头文件 */
#include "FluxProtocol.h"
/* 定义块大小 */
#define EXAMPLE_MAX_CHAR_SIZE (64)
/* 定义挂载点 */
2025-03-07 19:07:31 +08:00
#define MOUNT_POINT "/sdcard"
/* 定义日志文件名 */
#define LOG_FILE_NAME "/sdcard/log.txt"
/* 用于存储文件索引的文件 */
#define INDEX_FILE_NAME "/sdcard/index.txt"
/* 用于存储所有测试记录 */
#define TEST_FILE_NAME "/sdcard/test.txt"
/* 配置是否选择记录数据到SD卡内 */
#define LOG_RECORD_ENABLE (1)
/* SD卡读写引脚编号 */
#define CONFIG_EXAMPLE_PIN_CLK (14)
#define CONFIG_EXAMPLE_PIN_CMD (21)
#define CONFIG_EXAMPLE_PIN_D0 (13)
#define CONFIG_EXAMPLE_PIN_D1 (12)
#define CONFIG_EXAMPLE_PIN_D2 (48)
#define CONFIG_EXAMPLE_PIN_D3 (47)
/**
* @brief SD卡数据存取结构体
*
* 1.SD卡空间信息
* 2.
*
*/
struct SD_Data
{
/* 当前SD卡总空间信息 */
uint64_t total_bytes; //总空间大小
uint64_t free_bytes; //剩余空间大小
float free_percent; //剩余空间百分比
/* 用于存储的的数据 */
struct FluxTestResult
{
enum DeviceType current_device_type; //当前设备类型
uint8_t current_stage; //当前测试挡位
int32_t current_rate; //当前测试频率
float test_result[6]; //六个呼吸频率的测试结果15 20 25 30 35 40
float current_test_result; //当前测试结果
}flux_test_result;
char log_file_dir[64];
char test_file_dir[64];
/* 每次开机启动时的开机索引 */
int file_index; //开机索引,用于新建当日数据存储及日志文件
time_t current_time;
struct tm current_time_tm;
char strftime_buf[64];
};
/**
* @brief
*
*/
#define GPIO_INPUT_PIN_SEL(pin) (1ULL<<pin)
2025-03-07 19:07:31 +08:00
/**
* @brief SD卡Pin配置
*
*/
2025-03-07 19:07:31 +08:00
typedef struct {
const char** names;
const int* pins;
} pin_configuration_t;
/* 导出SD卡全局变量 */
extern struct SD_Data sdData;
/**
* @brief SD卡初始化
*
*/
2025-03-07 19:07:31 +08:00
void flux_sd_init(void);
2025-03-15 09:37:07 +08:00
/**
* @brief
*
*
*
*/
esp_err_t example_write_log(char *data);
/**
* @brief
*
*
*
*
*/
esp_err_t sd_current_fileIndex_get(void);
/**
* @brief SD卡中写入测试结果
*
* 1.
*
*/
2025-04-23 16:00:26 +08:00
esp_err_t sd_testData_write(bool is_nom,float test_result);
2025-03-07 19:07:31 +08:00
#ifdef __cplusplus
}
#endif
2025-03-15 09:37:07 +08:00
#endif