From 9591653e439829ef81b3f38c9034f18fc46b97fc Mon Sep 17 00:00:00 2001 From: james <1943357252@qq.com> Date: Wed, 31 Jul 2024 09:10:17 +0800 Subject: [PATCH] =?UTF-8?q?filesystem=20=E7=A9=BA=E6=A0=BC=E5=86=92?= =?UTF-8?q?=E5=8F=B7=E6=B5=8B=E8=AF=95=EF=BC=88=E6=88=90=E5=8A=9F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day5/SConscript | 4 +- Day5/filesystem.c | 166 +++++++++++++++++++++++----------------------- Day5/mqtt.c | 2 +- 3 files changed, 87 insertions(+), 85 deletions(-) diff --git a/Day5/SConscript b/Day5/SConscript index 522a3b1..c2b3b11 100644 --- a/Day5/SConscript +++ b/Day5/SConscript @@ -2,7 +2,9 @@ from building import * import os cwd = GetCurrentDir() -src = Glob('*.c') +src = [ + 'filesystem.c', +] CPPPATH = [cwd] diff --git a/Day5/filesystem.c b/Day5/filesystem.c index 5563e24..fffbbf6 100644 --- a/Day5/filesystem.c +++ b/Day5/filesystem.c @@ -1,99 +1,99 @@ -// //记得在menuconfig中开启支持旧版本功能(Support legacy version) -// #include -// #include -// #include -// #include //需要添加软件包进这里 +//记得在menuconfig中开启支持旧版本功能(Support legacy version) +#include +#include +#include +#include //需要添加软件包进这里 -// //定义要写入的内容 -// char String[] = "Hello, RT-Thread.Welcom to RSOC!"; +//定义要写入的内容 +char String[] = "Hello, RT-Thread.Welcom to RSOC!\n temp: 123, humi: 789"; -// //定义接受文件内容的缓冲区 -// char buffer[100] = {}; +//定义接受文件内容的缓冲区 +char buffer[100] = {}; -// void FileSystem_Test(void *parameter) -// { -// //文件描述符 -// int fd; +void FileSystem_Test(void *parameter) +{ + //文件描述符 + int fd; -// //用只写方式打开文件,如果没有该文件,则创建一个文件 -// fd = open("/fal/FileTest.txt", O_WRONLY | O_CREAT); + //用只写方式打开文件,如果没有该文件,则创建一个文件 + fd = open("/fal/FileTest.txt", O_WRONLY | O_CREAT); -// //如果打开成功 -// if (fd >= 0) -// { -// //写入文件 -// write(fd, String, sizeof(String)); + //如果打开成功 + if (fd >= 0) + { + //写入文件 + write(fd, String, sizeof(String)); -// rt_kprintf("Write done.\n"); + rt_kprintf("Write done.\n"); -// //关闭文件 -// close(fd); -// } -// else -// { -// rt_kprintf("File Open Fail.\n"); -// } + //关闭文件 + close(fd); + } + else + { + rt_kprintf("File Open Fail.\n"); + } -// //用只读方式打开文件 -// fd = open("/fal/FileTest.txt", O_RDONLY); + //用只读方式打开文件 + fd = open("/fal/FileTest.txt", O_RDONLY); -// if (fd>= 0) -// { -// //读取文件内容 -// rt_uint32_t size = read(fd, buffer, sizeof(buffer)); + if (fd>= 0) + { + //读取文件内容 + rt_uint32_t size = read(fd, buffer, sizeof(buffer)); -// if (size < 0) -// { -// rt_kprintf("Read File Fail.\n"); -// return ; -// } + if (size < 0) + { + rt_kprintf("Read File Fail.\n"); + return ; + } -// //输出文件内容 -// rt_kprintf("Read from file test.txt : %s \n", buffer); + //输出文件内容 + rt_kprintf("Read from file test.txt : %s \n", buffer); -// //关闭文件 -// close(fd); -// } -// else -// { -// rt_kprintf("File Open Fail.\n"); -// } -// } -// //导出命令 -// MSH_CMD_EXPORT(FileSystem_Test, FileSystem_Test); + //关闭文件 + close(fd); + } + else + { + rt_kprintf("File Open Fail.\n"); + } +} +//导出命令 +MSH_CMD_EXPORT(FileSystem_Test, FileSystem_Test); -// static void readdir_sample(void) -// { -// DIR *dirp; -// struct dirent *d; +static void readdir_sample(void) +{ + DIR *dirp; + struct dirent *d; -// /* 打开 / dir_test 目录 */ -// dirp = opendir("/fal"); -// if (dirp == RT_NULL) -// { -// rt_kprintf("open directory error!\n"); -// } -// else -// { -// /* 读取目录 */ -// while ((d = readdir(dirp)) != RT_NULL) -// { -// rt_kprintf("found %s\n", d->d_name); -// } + /* 打开 / dir_test 目录 */ + dirp = opendir("/fal"); + if (dirp == RT_NULL) + { + rt_kprintf("open directory error!\n"); + } + else + { + /* 读取目录 */ + while ((d = readdir(dirp)) != RT_NULL) + { + rt_kprintf("found %s\n", d->d_name); + } -// /* 关闭目录 */ -// closedir(dirp); -// } -// } -// /* 导出到 msh 命令列表中 */ -// MSH_CMD_EXPORT(readdir_sample, readdir sample); + /* 关闭目录 */ + closedir(dirp); + } +} +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(readdir_sample, readdir sample); -// /* -// #define WIFI_CS GET_PIN(F, 10) -// void WIFI_CS_PULL_DOWM(void) -// { -// rt_pin_mode(WIFI_CS, PIN_MODE_OUTPUT); -// rt_pin_write(WIFI_CS, PIN_LOW); -// } -// INIT_BOARD_EXPORT(WIFI_CS GET_PIN); -// */ +/* +#define WIFI_CS GET_PIN(F, 10) +void WIFI_CS_PULL_DOWM(void) +{ + rt_pin_mode(WIFI_CS, PIN_MODE_OUTPUT); + rt_pin_write(WIFI_CS, PIN_LOW); +} +INIT_BOARD_EXPORT(WIFI_CS GET_PIN); +*/ diff --git a/Day5/mqtt.c b/Day5/mqtt.c index 0535532..5723456 100644 --- a/Day5/mqtt.c +++ b/Day5/mqtt.c @@ -104,7 +104,7 @@ void make_file(char *String) { //文件描述符 int fd; - + String[] = "Hello, RT-Thread.Welcom to RSOC!\n temp: 123, humi: 789"; //用只写方式打开文件,如果没有该文件,则创建一个文件 fd = open("/fal/test/Data.txt", O_WRONLY | O_CREAT); // rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,String);