yjj-20230904

This commit is contained in:
15580979454 2023-09-04 00:50:55 +08:00
parent ac50191203
commit f8ccddc10c
6 changed files with 169 additions and 2 deletions

View File

View File

@ -0,0 +1,40 @@
/**
* @brief
* The only one header file for the other modules to use log module.
*/
#ifndef FILE_IO_H
#define FILE_IO_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "file.h"
void _write_config_file(char *cfgname);
//从文件中读取配置
void __read_config_file(char *cfgName);
/**
*@brief key和value对
*datakey和value并存入key和value
*@param data
*@param key KEY串
*@param value value串
*@param maxlen key和value能容忍的最大字符串长度
*@return
*
*/
char *sysfunc_get_key_value(char *data, char *key, char *value, int maxlen);
//从acData中查找key的值保存在value中
static char *__get_value(char *acData, char *key, char *value, int nMaxLen)
#ifdef __cplusplus
}
#endif
#endif

108
utils/FileIo/src/file_io.c Normal file
View File

@ -0,0 +1,108 @@
#include "file_io.h"
void _write_config_file(char *cfgname)
{
}
void __read_config_file(char *cfgName)
{
}
/**
*@brief key和value对
*datakey和value并存入key和value
*@param data
*@param key KEY串
*@param value value串
*@param maxlen key和value能容忍的最大字符串长度
*@return
*
*/
char *sysfunc_get_key_value(char *data, char *key, char *value, int maxlen)
{
int i = 0;
char *temp = data;
while(*temp && *temp == ';')
temp++;
while(*temp && *temp != ';' && *temp != '='
&& i < maxlen)
{
key[i++] = *temp++;
}
key[i] = '\0';
if (*temp == ';' || *temp == '\0')
value[0] = '\0';
else if(*temp == '=')
{
i = 0;
temp++;
while(*temp && *temp != ';'
&& i < maxlen)
{
value[i++] = *temp++;
}
value[i] = 0;
}
return temp;
}
//返回参数长度
U32 ParseParam(char *pParam, int nMaxLen, char *pBuffer)
{
int nLen = 0;
while(pBuffer && *pBuffer && *pBuffer != ';')
{
*pParam++ = *pBuffer++;
nLen++;
}
return nLen;
}
//从acData中查找key的值保存在value中
static char *__get_value(char *acData, char *key, char *value, int nMaxLen)
{
char *pItem, *pValue;
U32 nRead;
char acBuff[256]={0};
U32 nOffset = 0;
int nCh = 0;
char *out_ptr = NULL;
while ((nRead = ParseParam(acBuff, 64, acData+nOffset)) > 0)
{
acBuff[nRead] = 0; //把分号去掉
nOffset += (nRead+1);
if (strncmp(acBuff, "[CH1]", 5) == 0)
{
nCh = 0;
}
else if (strncmp(acBuff, "[CH2]", 5) == 0)
{
nCh = 1;
}
else if (strncmp(acBuff, "[CH3]", 5) == 0)
{
nCh = 2;
}
else if (strncmp(acBuff, "[ALL]", 5) == 0)
{
nCh = 0;
}
else
{
pItem = strtok_r(acBuff, "=", &out_ptr);
pValue = strtok_r(NULL, "\r", &out_ptr);
//Printf("pItem: %s, pValue: %s\n", pItem, pValue);
if (pValue == NULL)
pValue = "";
if (pItem != NULL && strcmp(pItem, key) == 0)
{
strncpy(value, pValue, nMaxLen);
return value;
}
}
}
return NULL;
}

View File

@ -0,0 +1,19 @@
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
include_directories(
./src
./include
)
#do not rely on any other library
#link_directories(
#)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(./src SRC_FILES)
set(TARGET_NAME IpcConfig)
add_library(${TARGET_NAME} STATIC ${SRC_FILES})