|
@@ -19,15 +19,17 @@
|
|
|
/* USER CODE END Header */
|
|
/* USER CODE END Header */
|
|
|
#include "main.h"
|
|
#include "main.h"
|
|
|
|
|
|
|
|
-#if USE_FATFS_RECORD
|
|
|
|
|
|
|
+#if USE_FATFS_RECORD==1
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
#include <stdint.h>
|
|
#include <stdint.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <stdbool.h>
|
|
#include <stdbool.h>
|
|
|
-
|
|
|
|
|
|
|
+#include "func_fatfs.h"
|
|
|
#include "dev_spi_sdcard.h"
|
|
#include "dev_spi_sdcard.h"
|
|
|
-#include "func_record.h"
|
|
|
|
|
|
|
+#include "func_spi_w25qxx.h"
|
|
|
|
|
+#include "func_fatfs_record.h"
|
|
|
|
|
+#include "func_queue_record.h"
|
|
|
#include "Data_deal.h"
|
|
#include "Data_deal.h"
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* Private includes ----------------------------------------------------------*/
|
|
|
/* USER CODE BEGIN Includes */
|
|
/* USER CODE BEGIN Includes */
|
|
@@ -36,7 +38,9 @@
|
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
#define MAX_FILE_COUNT 20
|
|
#define MAX_FILE_COUNT 20
|
|
|
-#define NUM_FILE_SET 16
|
|
|
|
|
|
|
+#define NUM_FILE_SET 10
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
/* USER CODE BEGIN PD */
|
|
/* USER CODE BEGIN PD */
|
|
|
|
|
|
|
@@ -52,6 +56,11 @@
|
|
|
/* USER CODE BEGIN PV */
|
|
/* USER CODE BEGIN PV */
|
|
|
|
|
|
|
|
/* USER CODE END PV */
|
|
/* USER CODE END PV */
|
|
|
|
|
+const char FILE_START[] = "20";
|
|
|
|
|
+const char FILE_END[] = ".TXT";
|
|
|
|
|
+const char FILE_FOLD[] = "JLRECORD";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
|
|
|
@@ -59,9 +68,9 @@
|
|
|
|
|
|
|
|
typedef struct fs_record_struct
|
|
typedef struct fs_record_struct
|
|
|
{
|
|
{
|
|
|
- int8_t fatfs_ok;
|
|
|
|
|
- int8_t path[32]; //操作路径
|
|
|
|
|
-
|
|
|
|
|
|
|
+ int8_t fs_stat;
|
|
|
|
|
+ const char *fold; //操作路径
|
|
|
|
|
+ int8_t * path[32]; //操作路径
|
|
|
int8_t name_new[32]; //最新的文件名
|
|
int8_t name_new[32]; //最新的文件名
|
|
|
int8_t name_send[32]; //最老的文件名
|
|
int8_t name_send[32]; //最老的文件名
|
|
|
|
|
|
|
@@ -69,6 +78,7 @@ typedef struct fs_record_struct
|
|
|
FATFS fs;
|
|
FATFS fs;
|
|
|
DIR dir; //操作的文件名
|
|
DIR dir; //操作的文件名
|
|
|
uint32_t opt_len;
|
|
uint32_t opt_len;
|
|
|
|
|
+ uint32_t items_num;
|
|
|
|
|
|
|
|
int8_t read_buf[512];
|
|
int8_t read_buf[512];
|
|
|
uint32_t read_len;
|
|
uint32_t read_len;
|
|
@@ -77,14 +87,21 @@ typedef struct fs_record_struct
|
|
|
uint32_t write_len;
|
|
uint32_t write_len;
|
|
|
|
|
|
|
|
uint32_t file_num;
|
|
uint32_t file_num;
|
|
|
- int8_t file_list[MAX_FILE_COUNT][30];//保存文件名
|
|
|
|
|
|
|
+ int8_t file_list[MAX_FILE_COUNT][32];//保存文件名
|
|
|
|
|
+
|
|
|
|
|
+ int8_t link_ok;
|
|
|
|
|
+
|
|
|
|
|
+ uint32_t free_size;
|
|
|
|
|
+
|
|
|
}fs_record_OBJ;
|
|
}fs_record_OBJ;
|
|
|
|
|
|
|
|
|
|
|
|
|
fs_record_OBJ fs_record_obj = {
|
|
fs_record_OBJ fs_record_obj = {
|
|
|
- .fatfs_ok = true,
|
|
|
|
|
- .path = "JLRecord",
|
|
|
|
|
|
|
+ .fs_stat = true,
|
|
|
|
|
+ .fold = FILE_FOLD,
|
|
|
|
|
+ .items_num= 0,
|
|
|
.file_num = 0,
|
|
.file_num = 0,
|
|
|
|
|
+ .link_ok = false,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
//add boly 20221020
|
|
//add boly 20221020
|
|
@@ -100,23 +117,39 @@ extern SDateTime m_datetime;
|
|
|
uint8_t func_record_fatfs_isOK(void)
|
|
uint8_t func_record_fatfs_isOK(void)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- return fs_record_obj.fatfs_ok;
|
|
|
|
|
|
|
+ return fs_record_obj.fs_stat;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
uint8_t func_record_fatfs_set_OK(uint8_t stat)
|
|
uint8_t func_record_fatfs_set_OK(uint8_t stat)
|
|
|
{
|
|
{
|
|
|
- fs_record_obj.fatfs_ok = stat;
|
|
|
|
|
- return fs_record_obj.fatfs_ok;
|
|
|
|
|
|
|
+ fs_record_obj.fs_stat = stat;
|
|
|
|
|
+ return fs_record_obj.fs_stat;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void func_record_mk_fileName(char *buf)
|
|
void func_record_mk_fileName(char *buf)
|
|
|
{
|
|
{
|
|
|
- fs_record_obj.path[12] = 0;
|
|
|
|
|
- sprintf(buf,"%s/%04d%02d%02d.txt",fs_record_obj.path,
|
|
|
|
|
|
|
+ //fs_record_obj.path[12] = 0;
|
|
|
|
|
+#if 0
|
|
|
|
|
+ sprintf(buf,"%s/%04d%02d%02d.TXT",fs_record_obj.fold,
|
|
|
m_datetime.year%100 + 2000,
|
|
m_datetime.year%100 + 2000,
|
|
|
m_datetime.month%100,
|
|
m_datetime.month%100,
|
|
|
m_datetime.day%100
|
|
m_datetime.day%100
|
|
|
);
|
|
);
|
|
|
|
|
+#elif 0
|
|
|
|
|
+ sprintf(buf,"%s/%04d%02d%02d.TXT",fs_record_obj.fold,
|
|
|
|
|
+ m_datetime.day%100 + 2000,
|
|
|
|
|
+ m_datetime.hour%100,
|
|
|
|
|
+ m_datetime.min%100
|
|
|
|
|
+ );
|
|
|
|
|
+#else
|
|
|
|
|
+ sprintf(buf,"%s/%04d%02d%02d.TXT",fs_record_obj.fold,
|
|
|
|
|
+ m_datetime.hour%100 + 2000,
|
|
|
|
|
+ m_datetime.min%100,
|
|
|
|
|
+ m_datetime.sec%100
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
@@ -136,36 +169,36 @@ uint32_t func_record_write(uint8_t *buf ,uint32_t len)
|
|
|
res = f_open(&fs_record_obj.opt_file,(char *)fs_record_obj.name_new , FA_WRITE| FA_OPEN_EXISTING);
|
|
res = f_open(&fs_record_obj.opt_file,(char *)fs_record_obj.name_new , FA_WRITE| FA_OPEN_EXISTING);
|
|
|
if(FR_OK != res)
|
|
if(FR_OK != res)
|
|
|
{
|
|
{
|
|
|
|
|
+ //检查文件个数是否超限
|
|
|
|
|
+ func_record_files_update((char *)fs_record_obj.fold);
|
|
|
|
|
+
|
|
|
if(FR_NO_FILE == res)
|
|
if(FR_NO_FILE == res)
|
|
|
- {
|
|
|
|
|
- //检查文件个数是否超限
|
|
|
|
|
- func_record_files_update((char *)fs_record_obj.path);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ {
|
|
|
//创建文件并写入
|
|
//创建文件并写入
|
|
|
res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_new, FA_WRITE| FA_CREATE_NEW);
|
|
res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_new, FA_WRITE| FA_CREATE_NEW);
|
|
|
if(FR_OK != res)
|
|
if(FR_OK != res)
|
|
|
{
|
|
{
|
|
|
- fs_record_obj.fatfs_ok = false;
|
|
|
|
|
|
|
+ fs_record_obj.fs_stat = false;
|
|
|
return 0;
|
|
return 0;
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //将当前发送文件更新为当前写入文件
|
|
|
|
|
+ strcpy((char *)fs_record_obj.name_send,(char *)fs_record_obj.name_new);
|
|
|
|
|
|
|
|
fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
|
|
fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
|
|
|
|
|
|
|
|
//操作指针移动到文件末尾
|
|
//操作指针移动到文件末尾
|
|
|
res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len);
|
|
res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len);
|
|
|
-
|
|
|
|
|
- res = f_write(&fs_record_obj.opt_file, buf, len, &write_len);
|
|
|
|
|
|
|
|
|
|
- res = f_sync (&fs_record_obj.opt_file ); //刷新文件
|
|
|
|
|
-
|
|
|
|
|
- res = f_close(&fs_record_obj.opt_file); //关闭文件
|
|
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
|
|
+ res = f_write(&fs_record_obj.opt_file, buf, len, &write_len);
|
|
|
|
|
+ res = f_close(&fs_record_obj.opt_file); //关闭文件
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
|
|
|
|
|
return write_len;
|
|
return write_len;
|
|
|
}
|
|
}
|
|
@@ -175,18 +208,12 @@ void func_record_get_NameSend(void)
|
|
|
//发送文件是否存在
|
|
//发送文件是否存在
|
|
|
if(strlen((char*)fs_record_obj.name_send) > 0)
|
|
if(strlen((char*)fs_record_obj.name_send) > 0)
|
|
|
{
|
|
{
|
|
|
- if(strlen((char*)fs_record_obj.name_new) > 0)
|
|
|
|
|
- {
|
|
|
|
|
- strcpy((char*)fs_record_obj.name_send, (char*)fs_record_obj.name_new);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- //检查文件个数是否超限
|
|
|
|
|
- func_record_files_update((char *)fs_record_obj.path);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ //检查文件个数是否超限
|
|
|
|
|
+ func_record_files_update((char *)fs_record_obj.fold);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -202,10 +229,7 @@ uint32_t func_record_read(uint8_t *buf, uint32_t len)
|
|
|
|
|
|
|
|
func_record_get_NameSend();
|
|
func_record_get_NameSend();
|
|
|
|
|
|
|
|
- if(strlen((char *)fs_record_obj.name_send) > 0)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
|
|
+ if(strlen((char *)fs_record_obj.name_send) <= 0)
|
|
|
{
|
|
{
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -223,7 +247,10 @@ uint32_t func_record_read(uint8_t *buf, uint32_t len)
|
|
|
{
|
|
{
|
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
|
|
|
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
res = f_unlink((char*)fs_record_obj.name_send);
|
|
res = f_unlink((char*)fs_record_obj.name_send);
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
|
|
+
|
|
|
if(res == FR_OK)
|
|
if(res == FR_OK)
|
|
|
{
|
|
{
|
|
|
memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
@@ -233,22 +260,67 @@ uint32_t func_record_read(uint8_t *buf, uint32_t len)
|
|
|
res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
|
|
res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
|
|
|
|
|
|
|
|
res = f_read(&fs_record_obj.opt_file, buf, len, &read_len);
|
|
res = f_read(&fs_record_obj.opt_file, buf, len, &read_len);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return read_len;
|
|
return read_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+uint32_t func_record_remove(uint8_t *buf, uint32_t len)
|
|
|
|
|
+{
|
|
|
|
|
+ FRESULT res;
|
|
|
|
|
+
|
|
|
|
|
+ uint32_t read_len = 0;
|
|
|
|
|
+
|
|
|
|
|
+ func_record_get_NameSend();
|
|
|
|
|
+
|
|
|
|
|
+ if(strlen((char *)fs_record_obj.name_send) <= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_send, FA_WRITE| FA_READ| FA_OPEN_EXISTING);
|
|
|
|
|
+ if(FR_OK != res)
|
|
|
|
|
+ {
|
|
|
|
|
+ memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
|
|
|
|
|
+
|
|
|
|
|
+ //如果文件小于数据长度,则删除文件
|
|
|
|
|
+ if(fs_record_obj.opt_len < len)
|
|
|
|
|
+ {
|
|
|
|
|
+ res = f_close(&fs_record_obj.opt_file);
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
|
|
+ res = f_unlink((char*)fs_record_obj.name_send);
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
|
|
+ if(res == FR_OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ };
|
|
|
|
|
+ res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
|
|
|
|
|
+ res = f_read(&fs_record_obj.opt_file, buf, len, &read_len);
|
|
|
|
|
+
|
|
|
|
|
+ res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
|
|
|
|
|
+
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
|
|
+ res = f_truncate(&fs_record_obj.opt_file ); //截断后面的文件
|
|
|
|
|
+ res = f_close(&fs_record_obj.opt_file);
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
|
|
+
|
|
|
|
|
+ return read_len;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
uint32_t func_record_delete(uint8_t *buf,uint32_t len)
|
|
uint32_t func_record_delete(uint8_t *buf,uint32_t len)
|
|
|
{
|
|
{
|
|
|
FRESULT res;
|
|
FRESULT res;
|
|
|
//uint32_t file_len = 0;
|
|
//uint32_t file_len = 0;
|
|
|
|
|
|
|
|
- if(strlen((char *)fs_record_obj.name_send) > 0)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
|
|
+ if(strlen((char *)fs_record_obj.name_send) <= 0)
|
|
|
{
|
|
{
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -270,8 +342,9 @@ uint32_t func_record_delete(uint8_t *buf,uint32_t len)
|
|
|
if(fs_record_obj.opt_len <= len)
|
|
if(fs_record_obj.opt_len <= len)
|
|
|
{
|
|
{
|
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
|
-
|
|
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
res = f_unlink((char*)fs_record_obj.name_send);
|
|
res = f_unlink((char*)fs_record_obj.name_send);
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
if(res == FR_OK)
|
|
if(res == FR_OK)
|
|
|
{
|
|
{
|
|
|
memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
@@ -280,11 +353,9 @@ uint32_t func_record_delete(uint8_t *buf,uint32_t len)
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
|
|
res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
|
|
|
-
|
|
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
res = f_truncate(&fs_record_obj.opt_file ); //截断后面的文件
|
|
res = f_truncate(&fs_record_obj.opt_file ); //截断后面的文件
|
|
|
-
|
|
|
|
|
- res = f_sync(&fs_record_obj.opt_file); //刷新关闭文件
|
|
|
|
|
-
|
|
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
res = f_close(&fs_record_obj.opt_file);
|
|
|
|
|
|
|
|
return res;
|
|
return res;
|
|
@@ -391,11 +462,14 @@ void func_record_files_update(char * path)
|
|
|
char file_name[32] = {0};
|
|
char file_name[32] = {0};
|
|
|
FRESULT res; //部分在递归过程被修改的变量,不用全局变量
|
|
FRESULT res; //部分在递归过程被修改的变量,不用全局变量
|
|
|
FILINFO fno = {0};
|
|
FILINFO fno = {0};
|
|
|
-
|
|
|
|
|
|
|
+ fs_record_obj.items_num = 0;
|
|
|
fs_record_obj.file_num = 0;
|
|
fs_record_obj.file_num = 0;
|
|
|
memset((void *)fs_record_obj.file_list, 0x00,sizeof(fs_record_obj.file_list));
|
|
memset((void *)fs_record_obj.file_list, 0x00,sizeof(fs_record_obj.file_list));
|
|
|
memset((void *)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
memset((void *)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
|
|
|
|
|
|
|
|
|
|
+ //获取fatfs文件系统
|
|
|
|
|
+ fs_record_obj.free_size = func_fatfs_get_free();
|
|
|
|
|
+
|
|
|
#if _USE_LFN//如果使能支持长文件名 先对下面两项初始化
|
|
#if _USE_LFN//如果使能支持长文件名 先对下面两项初始化
|
|
|
fileinfo.lfsize=_MAX_LFN * 2 + 1;//
|
|
fileinfo.lfsize=_MAX_LFN * 2 + 1;//
|
|
|
fileinfo.lfname=(TCHAR*)FileName;//
|
|
fileinfo.lfname=(TCHAR*)FileName;//
|
|
@@ -405,7 +479,7 @@ void func_record_files_update(char * path)
|
|
|
res = f_mkdir((const char*)path);
|
|
res = f_mkdir((const char*)path);
|
|
|
if(res == FR_OK)
|
|
if(res == FR_OK)
|
|
|
{
|
|
{
|
|
|
- fs_record_obj.fatfs_ok = true;
|
|
|
|
|
|
|
+ fs_record_obj.fs_stat = true;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -414,33 +488,41 @@ void func_record_files_update(char * path)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fs_record_obj.fatfs_ok = true;
|
|
|
|
|
|
|
+ fs_record_obj.fs_stat = true;
|
|
|
|
|
|
|
|
//打开日志路径正常,获取路文件夹内的文件列表
|
|
//打开日志路径正常,获取路文件夹内的文件列表
|
|
|
while(f_readdir(&fs_record_obj.dir, &fno) == FR_OK) //读文件信息到文件状态结构体中
|
|
while(f_readdir(&fs_record_obj.dir, &fno) == FR_OK) //读文件信息到文件状态结构体中
|
|
|
- {
|
|
|
|
|
- if(!fno.fname[0]) break; //如果文件名为‘\0',说明读取完成结束
|
|
|
|
|
-
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ fs_record_obj.items_num++;
|
|
|
|
|
+ //判定的顺序不能变
|
|
|
|
|
+ if(!fno.fname[0]) break; //如果文件名为‘\0',说明读取完成结束
|
|
|
|
|
+
|
|
|
if (fno.fattrib & AM_DIR) continue; //表示目录,跳过
|
|
if (fno.fattrib & AM_DIR) continue; //表示目录,跳过
|
|
|
|
|
|
|
|
if (fno.fname[0] == '.') continue; //点表示当前目录,跳过
|
|
if (fno.fname[0] == '.') continue; //点表示当前目录,跳过
|
|
|
|
|
|
|
|
|
|
|
|
|
- if(fs_record_obj.file_num < MAX_FILE_COUNT)
|
|
|
|
|
|
|
+ if( (fs_record_obj.file_num < MAX_FILE_COUNT)
|
|
|
|
|
+ &&(strstr(fno.fname,FILE_START) == fno.fname)
|
|
|
|
|
+ &&((strstr(fno.fname,FILE_END) != 0))
|
|
|
|
|
+ )
|
|
|
{
|
|
{
|
|
|
- sprintf((char *)fs_record_obj.file_list[fs_record_obj.file_num], "%s/%s", fs_record_obj.path,fno.fname);//将文件名存入列表中
|
|
|
|
|
|
|
+ sprintf((char *)fs_record_obj.file_list[fs_record_obj.file_num], "%s/%s", fs_record_obj.fold,fno.fname);//将文件名存入列表中
|
|
|
fs_record_obj.file_num ++;
|
|
fs_record_obj.file_num ++;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
- {
|
|
|
|
|
|
|
+ {
|
|
|
/* 如果目录已经存在,关闭它 */
|
|
/* 如果目录已经存在,关闭它 */
|
|
|
- res = f_closedir(&fs_record_obj.dir);
|
|
|
|
|
|
|
+ res = f_closedir(&fs_record_obj.dir);
|
|
|
|
|
|
|
|
- sprintf((char *)file_name,"%s/%s",fs_record_obj.path, fno.fname); //输出文件名
|
|
|
|
|
|
|
+ sprintf((char *)file_name,"%s/%s",fs_record_obj.fold, fno.fname); //输出文件名
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
res = f_unlink(file_name);
|
|
res = f_unlink(file_name);
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
if(FR_OK != res)
|
|
if(FR_OK != res)
|
|
|
{
|
|
{
|
|
|
- fs_record_obj.fatfs_ok = false;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ fs_record_obj.fs_stat = false;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -469,14 +551,19 @@ void func_record_files_update(char * path)
|
|
|
sprintf((char *)fs_record_obj.name_send,"%s", fs_record_obj.file_list[max_idx]);
|
|
sprintf((char *)fs_record_obj.name_send,"%s", fs_record_obj.file_list[max_idx]);
|
|
|
|
|
|
|
|
//如果文件个数超限,
|
|
//如果文件个数超限,
|
|
|
- if(fs_record_obj.file_num > NUM_FILE_SET)
|
|
|
|
|
|
|
+ if((fs_record_obj.file_num > NUM_FILE_SET)
|
|
|
|
|
+ ||(fs_record_obj.free_size < 500))
|
|
|
{
|
|
{
|
|
|
//删除日期最早的文件
|
|
//删除日期最早的文件
|
|
|
sprintf((char *)file_name,"%s", fs_record_obj.file_list[0]);
|
|
sprintf((char *)file_name,"%s", fs_record_obj.file_list[0]);
|
|
|
|
|
+
|
|
|
|
|
+ taskENTER_CRITICAL(); /* 临界保护开启 */
|
|
|
res = f_unlink(file_name);
|
|
res = f_unlink(file_name);
|
|
|
|
|
+ taskEXIT_CRITICAL(); /* 临界保护关闭 */
|
|
|
|
|
+
|
|
|
if(FR_OK != res)
|
|
if(FR_OK != res)
|
|
|
{
|
|
{
|
|
|
- fs_record_obj.fatfs_ok = false;
|
|
|
|
|
|
|
+ fs_record_obj.fs_stat = false;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -503,19 +590,12 @@ void func_record_init(void)
|
|
|
|
|
|
|
|
memset(fs_record_obj.file_list, 0x00,sizeof(fs_record_obj.file_list)); //清空文件列表
|
|
memset(fs_record_obj.file_list, 0x00,sizeof(fs_record_obj.file_list)); //清空文件列表
|
|
|
fs_record_obj.file_num = 0;
|
|
fs_record_obj.file_num = 0;
|
|
|
- fs_record_obj.fatfs_ok = true;
|
|
|
|
|
- func_record_files_update((char *)fs_record_obj.path);
|
|
|
|
|
|
|
+ fs_record_obj.fs_stat = true;
|
|
|
|
|
+ func_record_files_update((char *)fs_record_obj.fold);
|
|
|
}
|
|
}
|
|
|
-typedef struct record_test_object
|
|
|
|
|
-{
|
|
|
|
|
- uint32_t cnts;
|
|
|
|
|
- uint8_t test_flag;
|
|
|
|
|
- char buf[32];
|
|
|
|
|
-}record_test_OBJ;
|
|
|
|
|
-
|
|
|
|
|
-record_test_OBJ record_test_obj;
|
|
|
|
|
|
|
|
|
|
-void func_record_test(void)
|
|
|
|
|
|
|
+
|
|
|
|
|
+void func_record_fs_test(void)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
record_test_obj.cnts++;
|
|
record_test_obj.cnts++;
|
|
@@ -541,13 +621,66 @@ void func_record_test(void)
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void func_record_main(void const *argument)
|
|
|
|
|
|
|
+
|
|
|
|
|
+char* pstr = 0;
|
|
|
|
|
+char* pidx = 0;
|
|
|
|
|
+void func_record_str(void)
|
|
|
|
|
+{
|
|
|
|
|
+ char str_name[] ="20221112.TXT" ;
|
|
|
|
|
+
|
|
|
|
|
+ while(1)
|
|
|
|
|
+ {
|
|
|
|
|
+ pstr = strstr(str_name,FILE_START);
|
|
|
|
|
+
|
|
|
|
|
+ pidx = strstr(str_name,FILE_END);
|
|
|
|
|
+ UNUSED(pstr);
|
|
|
|
|
+ UNUSED(pidx);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+char path_buf[512] = {0};
|
|
|
|
|
+void func_record_fatfs_main(void const *argument)
|
|
|
{
|
|
{
|
|
|
|
|
+ //func_record_str();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //add boly 20221014 SD卡 FATFS组件初始化
|
|
|
|
|
+#if USE_SPI_SD
|
|
|
|
|
+ SDCARD_GPIO_Init();
|
|
|
|
|
+ SDCARD_SPI_Init();
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if USE_SPI_FLASH
|
|
|
|
|
+ func_w25q_init();
|
|
|
|
|
+ func_w25q_test();
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#if USE_FATFS_RECORD
|
|
|
|
|
+ taskENTER_CRITICAL();
|
|
|
|
|
+ func_fatfs_init();
|
|
|
|
|
+ func_fatfs_main();
|
|
|
|
|
+ taskEXIT_CRITICAL();
|
|
|
|
|
+
|
|
|
|
|
+ func_record_queue_init();
|
|
|
|
|
+ func_record_queue_update();
|
|
|
|
|
+
|
|
|
|
|
+ //while(1)
|
|
|
|
|
+ {
|
|
|
|
|
+ osDelay(1000);
|
|
|
|
|
+ };
|
|
|
|
|
+ //end boly
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
osDelay(1000);//
|
|
osDelay(1000);//
|
|
|
func_record_init();
|
|
func_record_init();
|
|
|
while(1)
|
|
while(1)
|
|
|
{
|
|
{
|
|
|
- func_record_test();
|
|
|
|
|
|
|
+ strcpy(path_buf,fs_record_obj.fold);
|
|
|
|
|
+ //func_fatfs_scan_files(path_buf);
|
|
|
|
|
+ //func_record_fs_test();
|
|
|
|
|
+ func_record_queue_test();
|
|
|
|
|
+ func_record_work();
|
|
|
osDelay(1000);
|
|
osDelay(1000);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|