You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
/*
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2025-12-01 Administrator the first version
|
|
*/
|
|
#include <rtthread.h>
|
|
#include <dfs_posix.h>
|
|
#include "ini.h"
|
|
#include "Variable.h"
|
|
|
|
#define INI_config "/sys/828config.ini"
|
|
|
|
int read_write_sample(void)
|
|
{
|
|
//检查文件
|
|
if (access(INI_config, F_OK) != 0)
|
|
{
|
|
int fd = open(INI_config, O_WRONLY | O_CREAT);//创建文件
|
|
close(fd);
|
|
}
|
|
// 初始化INI解析器
|
|
INI_File *ini = ini_init();
|
|
if (!ini) {
|
|
rt_kprintf("1\n");
|
|
return -1;
|
|
}
|
|
// 解析INI文件
|
|
if (ini_parse(ini, INI_config) != 0) {
|
|
rt_kprintf("2\n");
|
|
ini_free(ini);
|
|
return -1;
|
|
}
|
|
// 读取各种类型的值
|
|
strncpy(machine_ID, ini_get_value(ini, "CONFIG", "ID"),sizeof(machine_ID));
|
|
machine_name = ini_get_value(ini, "CONFIG", "NAME");
|
|
|
|
//// ini_set_value(ini,"database", "host","192.168.9.1");
|
|
|
|
// ini_save(ini,INI_config);
|
|
|
|
// 清理资源
|
|
ini_free(ini);
|
|
return 0;
|
|
}
|
|
|
|
INIT_APP_EXPORT(read_write_sample);
|
|
|