From f8ccddc10cc91a41e93730817a8aa1999791c641 Mon Sep 17 00:00:00 2001 From: 15580979454 <2363497107@qq.com> Date: Mon, 4 Sep 2023 00:50:55 +0800 Subject: [PATCH] yjj-20230904 --- utils/CMakeLists.txt | 2 +- utils/FileIo/CMakeList.txt | 0 utils/FileIo/include/file_io.h | 40 +++++++++++ utils/FileIo/src/file_io.c | 108 ++++++++++++++++++++++++++++++ utils/IpcConfig/CMakeList.txt | 19 ++++++ utils/StatusCode/src/StatusCode.c | 2 +- 6 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 utils/FileIo/CMakeList.txt create mode 100644 utils/FileIo/include/file_io.h create mode 100644 utils/FileIo/src/file_io.c create mode 100644 utils/IpcConfig/CMakeList.txt diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 6a6b14f0..5eaf3ca5 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -3,4 +3,4 @@ add_subdirectory(ReturnCode) add_subdirectory(StatusCode) add_subdirectory(Log) -add_subdirectory(LogC) \ No newline at end of file +add_subdirectory(LogC) diff --git a/utils/FileIo/CMakeList.txt b/utils/FileIo/CMakeList.txt new file mode 100644 index 00000000..e69de29b diff --git a/utils/FileIo/include/file_io.h b/utils/FileIo/include/file_io.h new file mode 100644 index 00000000..9b563218 --- /dev/null +++ b/utils/FileIo/include/file_io.h @@ -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对。 + *处理字符串data,从中取出第一个key和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 diff --git a/utils/FileIo/src/file_io.c b/utils/FileIo/src/file_io.c new file mode 100644 index 00000000..c0a7d5ce --- /dev/null +++ b/utils/FileIo/src/file_io.c @@ -0,0 +1,108 @@ +#include "file_io.h" + +void _write_config_file(char *cfgname) +{ + +} + +void __read_config_file(char *cfgName) +{ + +} + +/** + *@brief 从给定字符串中提取key和value对。 + *处理字符串data,从中取出第一个key和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; +} diff --git a/utils/IpcConfig/CMakeList.txt b/utils/IpcConfig/CMakeList.txt new file mode 100644 index 00000000..5536e562 --- /dev/null +++ b/utils/IpcConfig/CMakeList.txt @@ -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}) diff --git a/utils/StatusCode/src/StatusCode.c b/utils/StatusCode/src/StatusCode.c index 028b055b..c915ff2b 100644 --- a/utils/StatusCode/src/StatusCode.c +++ b/utils/StatusCode/src/StatusCode.c @@ -44,4 +44,4 @@ const StatusCode CreateStatusCode(const long int code) LogError("undefined code.\n"); return NewStatusCode(STATUS_CODE_END); } -} \ No newline at end of file +}