[FIXED] something wrong

This commit is contained in:
xudx 2024-11-21 13:27:37 +08:00
parent f4db785074
commit 0cb40428b6
3 changed files with 86 additions and 31 deletions

View File

@ -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})

9
kit/kit_safe_memcpy.c Normal file
View File

@ -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;
}

View File

@ -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);
} }