[FIXED] something wrong
This commit is contained in:
parent
f4db785074
commit
0cb40428b6
|
@ -1,5 +1,5 @@
|
||||||
#指定cmake最低版本
|
#指定cmake最低版本
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
|
||||||
#x86平台
|
#x86平台
|
||||||
# set(CMAKE_C_COMPILER gcc)
|
# set(CMAKE_C_COMPILER gcc)
|
||||||
|
@ -13,9 +13,18 @@ set(CMAKE_BUILD_TYPE "Debug")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
||||||
|
|
||||||
# 设置一个字符串变量,用与编译文件名称生成
|
# 设置一个字符串变量,用与编译文件名称生成
|
||||||
set(ProjectName "EMS_C_V")
|
set(ProjectName "EMS_C_V_1.0.0")
|
||||||
|
|
||||||
project(${ProjectName})
|
project(${ProjectName} LANGUAGES C)
|
||||||
|
|
||||||
|
# 设置 C 标准
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# 设置编译类型(Debug 或 Release)
|
||||||
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
|
||||||
|
add_definitions(-DHARDWARE_TYPE=1)
|
||||||
|
|
||||||
# 添加头文件路径
|
# 添加头文件路径
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -51,6 +60,17 @@ set(DRV_SOURCE
|
||||||
set(KIT_SOURCE
|
set(KIT_SOURCE
|
||||||
# Logger kit源文件
|
# Logger kit源文件
|
||||||
${PROJECT_SOURCE_DIR}/kit/kit_logger.c
|
${PROJECT_SOURCE_DIR}/kit/kit_logger.c
|
||||||
|
${PROJECT_SOURCE_DIR}/kit/kit_safe_memcpy.c
|
||||||
|
)
|
||||||
|
|
||||||
|
# 添加库头文件
|
||||||
|
include_directories(
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libsqlite3/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libxml2/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libssl/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libcjson/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libmodbus/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libpaho-mqtt/include
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${ProjectName}
|
add_executable(${ProjectName}
|
||||||
|
@ -63,38 +83,60 @@ add_executable(${ProjectName}
|
||||||
${KIT_SOURCE}
|
${KIT_SOURCE}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions(-DHARDWARE_TYPE=1)
|
|
||||||
|
|
||||||
# 添加编译选项
|
# 添加编译选项
|
||||||
target_compile_options(${ProjectName} PRIVATE -fno-stack-protector)
|
target_compile_options(${ProjectName} PRIVATE -fno-stack-protector)
|
||||||
|
|
||||||
# 添加库头文件
|
|
||||||
include_directories(
|
|
||||||
lib/libsqlite3/include
|
|
||||||
lib/libxml2/include
|
|
||||||
lib/libssl/include
|
|
||||||
lib/libcjson/include
|
|
||||||
lib/libmodbus/include
|
|
||||||
# /usr/include
|
|
||||||
)
|
|
||||||
|
|
||||||
# 添加库路径
|
# 添加库路径
|
||||||
find_library(MY_LIBRARY_PATH
|
find_library(LIB_PTHREAD NAMES pthread PATHS /usr/aarch64-linux-gnu/lib)
|
||||||
NAMES
|
find_library(LIB_SQLITE3 NAMES sqlite3 PATHS lib/libsqlite3/lib)
|
||||||
pthread PATHS /usr/aarch64-linux-gnu/lib
|
find_library(LIB_XML2 NAMES xml2 PATHS lib/libxml2/lib)
|
||||||
sqlite3 PATHS lib/libsqlite3/lib
|
find_library(LIB_SSL NAMES ssl PATHS lib/libssl/lib)
|
||||||
xml2 PATHS lib/libxml2/lib
|
find_library(LIB_CRYPTO NAMES crypto PATHS lib/libssl/lib)
|
||||||
ssl PATHS lib/libssl/lib
|
find_library(LIB_CJSON NAMES cjson PATHS lib/libcjson/lib)
|
||||||
crypto PATHS lib/libssl/lib
|
find_library(LIB_MODBUS NAMES modbus PATHS lib/libmodbus/lib)
|
||||||
cjson PATHS lib/libcjson/lib
|
|
||||||
modbus PATHS lib/libmodbus/lib
|
# 添加链接库
|
||||||
|
target_link_libraries(${ProjectName} PRIVATE
|
||||||
|
${LIB_PTHREAD}
|
||||||
|
${LIB_SQLITE3}
|
||||||
|
${LIB_XML2}
|
||||||
|
${LIB_SSL}
|
||||||
|
${LIB_CRYPTO}
|
||||||
|
${LIB_CJSON}
|
||||||
|
${LIB_MODBUS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${ProjectName} PRIVATE ${MY_LIBRARY_PATH})
|
if(NOT LIB_PTHREAD)
|
||||||
|
message("LIB_PTHREAD not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIB_SQLITE3)
|
||||||
|
message("LIB_SQLITE3 not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIB_XML2)
|
||||||
|
message("LIB_XML2 not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIB_SSL)
|
||||||
|
message("LIB_SSL not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIB_CRYPTO)
|
||||||
|
message("LIB_CRYPTO not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIB_CJSON)
|
||||||
|
message("LIB_CJSON not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIB_MODBUS)
|
||||||
|
message("LIB_MODBUS not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
# 拷贝文件
|
# 拷贝文件
|
||||||
file(GLOB SQL_SCHEMAS ${CMAKE_SOURCE_DIR}/config/*.sql)
|
# file(GLOB SQL_SCHEMAS ${CMAKE_SOURCE_DIR}/config/*.sql)
|
||||||
file(COPY ${SQL_SCHEMAS} DESTINATION ${CMAKE_BINARY_DIR}/config)
|
# file(COPY ${SQL_SCHEMAS} DESTINATION ${CMAKE_BINARY_DIR}/config)
|
||||||
|
|
||||||
# 指定工作目录
|
# 指定工作目录
|
||||||
# install(TARGETS ${ProjectName} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
# install(TARGETS ${ProjectName} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int memcpy_s(void *dest, size_t dest_size, const void *src, size_t count) {
|
||||||
|
if (!dest || !src) return EINVAL;
|
||||||
|
if (count > dest_size) return ERANGE;
|
||||||
|
memcpy(dest, src, count);
|
||||||
|
return 0;
|
||||||
|
}
|
12
test/test.c
12
test/test.c
|
@ -11,6 +11,8 @@
|
||||||
#include "drv_4g.h"
|
#include "drv_4g.h"
|
||||||
#include "libmodbus/include/modbus-rtu.h"
|
#include "libmodbus/include/modbus-rtu.h"
|
||||||
|
|
||||||
|
// #include "MQTTAsync.h"
|
||||||
|
|
||||||
void runTest()
|
void runTest()
|
||||||
{
|
{
|
||||||
printf("runTest...\n");
|
printf("runTest...\n");
|
||||||
|
@ -37,12 +39,12 @@ void testCreatThreadTask()
|
||||||
// pthread_join(tTestTcp, NULL);
|
// pthread_join(tTestTcp, NULL);
|
||||||
// pthread_create(&tTest4G, NULL, test4GThread, "test4GThread");
|
// pthread_create(&tTest4G, NULL, test4GThread, "test4GThread");
|
||||||
// pthread_join(tTest4G, NULL);
|
// pthread_join(tTest4G, NULL);
|
||||||
pthread_create(&tTestCanSend, NULL, testCanSendThread, "testCanSendThread");
|
// pthread_create(&tTestCanSend, NULL, testCanSendThread, "testCanSendThread");
|
||||||
pthread_join(tTestCanSend, NULL);
|
// pthread_join(tTestCanSend, NULL);
|
||||||
// pthread_create(&tTestCanRecv, NULL, testCanRecvThread, "testCanRecvThread");
|
// pthread_create(&tTestCanRecv, NULL, testCanRecvThread, "testCanRecvThread");
|
||||||
// pthread_join(tTestCanRecv, NULL);
|
// pthread_join(tTestCanRecv, NULL);
|
||||||
pthread_create(&tTestModbus, NULL, testModbusThread, "testModbusThread");
|
// pthread_create(&tTestModbus, NULL, testModbusThread, "testModbusThread");
|
||||||
pthread_join(tTestModbus, NULL);
|
// pthread_join(tTestModbus, NULL);
|
||||||
logger_destroy();
|
logger_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,4 +179,6 @@ void *testCanSendThread(void *arg)
|
||||||
void *testModbusThread(void *arg)
|
void *testModbusThread(void *arg)
|
||||||
{
|
{
|
||||||
logger_level_printf(LOGGER_DEBUG_LEVEL, arg);
|
logger_level_printf(LOGGER_DEBUG_LEVEL, arg);
|
||||||
|
// MQTTAsync_malloc(12);
|
||||||
|
modbus_new_rtu("dev", 9600, '1', '8', 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue