2025-04-18 18:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @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
|
|
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
#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"
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
/* 包含FluxProtocol头文件 */
|
|
|
|
|
|
#include "FluxProtocol.h"
|
|
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/* 定义块大小 */
|
|
|
|
|
|
#define EXAMPLE_MAX_CHAR_SIZE (64)
|
2025-04-21 14:06:52 +08:00
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/* 定义挂载点 */
|
2025-03-07 19:07:31 +08:00
|
|
|
|
#define MOUNT_POINT "/sdcard"
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
/* 定义日志文件名 */
|
|
|
|
|
|
#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)
|
2025-03-26 18:59:32 +08:00
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/* 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)
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @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];
|
|
|
|
|
|
};
|
2025-03-13 14:04:19 +08:00
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 选择引脚
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define GPIO_INPUT_PIN_SEL(pin) (1ULL<<pin)
|
2025-03-07 19:07:31 +08:00
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief SD卡Pin配置
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2025-03-07 19:07:31 +08:00
|
|
|
|
typedef struct {
|
|
|
|
|
|
const char** names;
|
|
|
|
|
|
const int* pins;
|
|
|
|
|
|
} pin_configuration_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
/* 导出SD卡全局变量 */
|
|
|
|
|
|
extern struct SD_Data sdData;
|
|
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief SD卡初始化
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2025-03-07 19:07:31 +08:00
|
|
|
|
void flux_sd_init(void);
|
2025-03-15 09:37:07 +08:00
|
|
|
|
|
2025-04-18 18:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 日志记录
|
|
|
|
|
|
*
|
|
|
|
|
|
* 用于记录测试过程日志
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2025-04-21 14:06:52 +08:00
|
|
|
|
esp_err_t example_write_log(char *data);
|
2025-03-26 18:59:32 +08:00
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 获取文件索引
|
|
|
|
|
|
*
|
|
|
|
|
|
* 每次开机后重置当前文件索引值
|
|
|
|
|
|
* 以该索引值新建日志文件、测试结果输出文件
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
esp_err_t sd_current_fileIndex_get(void);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 向SD卡中写入测试结果
|
|
|
|
|
|
*
|
|
|
|
|
|
* 1.文件头为 时间戳、设备类型、挡位、频率、流量体积
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
esp_err_t sd_testData_write(void);
|
2025-04-19 09:30:40 +08:00
|
|
|
|
|
2025-03-07 19:07:31 +08:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-15 09:37:07 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|