当前位置:网站首页>minIni移植到littlefs
minIni移植到littlefs
2022-06-11 10:15:00 【*_仰望星空_*】
minIni
minIni 是一个用于读取和写入 INI 文件的库。
github :
https://github.com/compuphase/minIni
minIni特点:
1、minIni 大约是 950 行代码 (包括注释),是一个真正的 “迷你” INI 文件解析器,非常容易移植到各种嵌入式平台。
2、minIni 不需要标准 C/C++ 库中的 文件 I/O 函数,且允许通过宏配置要选择文件 I/O 接口。
3、minIni 仅使用 stack ,完全不使用动态内存(malloc)。
4、有 C++ binding, 能很好地配合 C++ 使用
为什么使用minIni :
搜索ini文件库会发现有很多,有些还说支持嵌入式系统,但是去看了代码就会发现,是要支持完整的C标准文件读写接口才可以,在使用RTOS和MCU的嵌入式系统根本不能用,要使用还要费很多时间去移植,其文件读写接口都是嵌入到函数实现里面的,移植起来很难受。
通过上述minIni第2点就可知minIni对ini文件IO接口通过宏进行配置,也就是移植,可知可移植性很好。
minIni移植到littlefs
minIni仓库下有很多针对许多不同文件IO好的头文件,移植可以参考。
minGlue-bk.h
minGlue-ccs.h
minGlue-efsl.h
minGlue-FatFs.h
minGlue-ffs.h
minGlue-lfs.c
minGlue-Linux.h
minGlue-mdd.h
minGlue-stdio.h
minGlue.h
minIni.c
minIni.h
test.c
test.ini
test2.cc
testplain.ini
wxMinIni.h
针对littlefs的移植:
minGlue-lfs.h
/* Glue functions for the minIni library, based on the littlefs * libraries, see https://github.com/littlefs-project/littlefs * * By guangjieMVP, 2022 * This "glue file" is in the public domain. It is distributed without * warranties or conditions of any kind, either express or implied. * * (The littlefs libraries are copyright by ARM and licensed at * its own terms.) */
#ifndef _MINGLUE_LFS_H_
#define _MINGLUE_LFS_H_
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
/* You must set FF_USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h) * to enable the "string functions" fgets() and fputs(). */
#include "lfs.h" /* include lfs.h for littlefs */
#include "stdio.h"
#include "string.h"
/* 定义一行文本结束符 */
#define INI_LINETERM "\n"
/* 使用库自带的strnicmp*/
#define PORTABLE_STRNICMP
extern lfs_t lfs;
char *lfs_gets(char *s, int size, lfs_file_t *file);
#define INI_FILETYPE lfs_file_t
#define ini_openread(filename, file) (lfs_file_open(&lfs, (file), (filename), LFS_O_RDONLY | LFS_O_CREAT) == LFS_ERR_OK)
#define ini_openwrite(filename, file) (lfs_file_open(&lfs, (file), (filename), LFS_O_WRONLY | LFS_O_CREAT) == LFS_ERR_OK)
#define ini_close(file) (lfs_file_close(&lfs, file) == LFS_ERR_OK)
#define ini_read(buffer, size, file) (lfs_gets((buffer), (size), (file)))
#define ini_write(buffer, file) (lfs_file_write(&lfs, (file), (buffer), strlen(buffer)))
#define ini_remove(filename) (lfs_remove(&lfs, filename) == LFS_ERR_OK)
#define ini_rename(source, dest) (lfs_rename(&lfs, (source), (dest)) == LFS_ERR_OK)
#define INI_FILEPOS lfs_soff_t
#define ini_tell(file, pos) (*(pos) = lfs_file_tell(&lfs, (file)))
#define ini_seek(file, pos) (lfs_file_seek(&lfs, (file), *(pos), LFS_SEEK_SET) == LFS_ERR_OK)
#endif
minGlue-lfs.c
#include "lfs.h" /* include lfs.h for littlefs */
#include "string.h"
extern lfs_t lfs;
char *lfs_gets(char *s, int size, lfs_file_t *file)
{
char *ptr;
int32_t numBytes;
int32_t pos;
if ((s == 0) || (size <= 0))
{
return(NULL);
}
/* See the current position before reading */
pos = lfs_file_seek(&lfs, file, 0, LFS_SEEK_CUR);
/* Read from the current position */
numBytes = lfs_file_read(&lfs, file, (s), (size - 1));
if (numBytes > 0)
{
/* Find the first/next new line */
ptr = strchr(s, '\n');
if (ptr)
{
ptr++;
*ptr = 0;
numBytes = strlen(s);
}
}
else
{
return(NULL);
}
assert(numBytes <= size);
/* Set the new position for the next read */
lfs_file_seek(&lfs, file, (pos + numBytes), LFS_SEEK_SET);
return(s);
}
文件IO接口littlefs基本都有现成的,但是获取文件一行数据的接口则没有,需要自己实现,针对littlefs的实现如上所示,lfs_gets 函数,一行数据以"\n"为结束符
注:
使用的时候将原来的minGlue.h备份一下minGlue-bk.h,然后将minGlue-lfs.h改成minGlue.h
边栏推荐
- 基于SSM+Vue+OSS的“依伴汉服”商城设计与开发(含源码+论文+ppt+数据库)
- Interview review - closure
- DENISON液压泵用什么液压油?有哪些要求
- 知识点滴 - 性格分析-四类法
- 使用bat向文件的第一行中写入内容
- Leetcode brushing questions - hand tearing binary tree
- Finish C language
- Servlet 的初次部署
- 吴恩达机器学习课程-第七周
- [high concurrency] the interviewer of ant financial asked me about thread pool!!
猜你喜欢

ESP8266_ Mqtt protocol

Secret behind the chart | explanation of technical indicators: tangqi'an channel

转载:LinearLayout+Fragment实现下导航栏效果

科技云报道:Web3.0浪潮下的隐私计算

Cisp-pte XSS Foundation

Empire CMS imitation "game bird" template source code /92kaifa version large mobile game portal template

关于马格齿轮泵的应用领域都有哪些?总结一下

浅谈wandfluh比例阀的功能与作用

What are the ABAP keywords and syntax that cannot be used in the ABAP cloud environment?

Mysql--事务
随机推荐
对于力士乐电磁换向阀的功能与作用,你知道多少
Browser class for getting started with puppeter
What is digital twin? A real-time and virtual representation
不卷了!入职字节跳动一周就果断跑了。
parker派克先导式电磁阀和直动式电磁阀的区别有哪些?
MySQL comparison
1. system in Library
UGUI
What is the difference between an interface and an abstract class?
Mysql比较
Mysql--索引
图表背后的秘密 | 技术指标讲解:唐奇安通道
Knowledge drop - personality analysis - four types of method
Excellent test engineer must have 4 safety test methods!
动态渲染数据和轮播图
面试复习手写题--函数截流与抖动
MD5学习
Dynamically render data and carousels
Ugui picture wall
MD5 learning