FluxDC/components/FluxSD/FluxSD.h

156 lines
3.2 KiB
C
Raw Permalink 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.

/**
* @file FluxSD.h
* @brief SD卡头文件
*
* 用于存储测试日志
*
* @author wang xiang en
* @date 2025-04-18
* @version 版本号
* @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd
*/
#ifndef _FLUX_SD_H
#define _FLUX_SD_H
#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)
/* 定义挂载点 */
#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)
/**
* @brief SD卡Pin配置
*
*/
typedef struct {
const char** names;
const int* pins;
} pin_configuration_t;
/* 导出SD卡全局变量 */
extern struct SD_Data sdData;
/**
* @brief SD卡初始化
*
*/
void flux_sd_init(void);
/**
* @brief 日志记录
*
* 用于记录测试过程日志
*
*/
esp_err_t example_write_log(char *data);
/**
* @brief 获取文件索引
*
* 每次开机后重置当前文件索引值
* 以该索引值新建日志文件、测试结果输出文件
*
*/
esp_err_t sd_current_fileIndex_get(void);
/**
* @brief 向SD卡中写入测试结果
*
* 1.文件头为 时间戳、设备类型、挡位、频率、流量体积
*
*/
esp_err_t sd_testData_write(void);
#ifdef __cplusplus
}
#endif
#endif