phase 2 serial

This commit is contained in:
flower_linux
2026-06-12 18:34:49 +08:00
parent 0cf0713dc5
commit 628ccf1409
78 changed files with 2571 additions and 345 deletions

View File

@@ -73,6 +73,45 @@ else()
set(SOFTBUS_HAS_OPCUA OFF)
endif()
# libmodbus (edge RTU/TCP): system pkg-config first, else third_party vendor
set(SOFTBUS_HAS_LIBMODBUS OFF)
set(SOFTBUS_LIBMODBUS_VENDOR OFF)
option(SOFTBUS_FORCE_VENDOR_LIBMODBUS
"Always build libmodbus from third_party/libmodbus" OFF)
if(NOT SOFTBUS_FORCE_VENDOR_LIBMODBUS)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(LIBMODBUS QUIET libmodbus)
endif()
endif()
if(LIBMODBUS_FOUND AND NOT SOFTBUS_FORCE_VENDOR_LIBMODBUS)
set(SOFTBUS_HAS_LIBMODBUS ON)
add_library(libmodbus_iface INTERFACE)
target_include_directories(libmodbus_iface INTERFACE ${LIBMODBUS_INCLUDE_DIRS})
target_link_libraries(libmodbus_iface INTERFACE ${LIBMODBUS_LIBRARIES})
message(STATUS "libmodbus: using system package (pkg-config)")
else()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libmodbus")
if(NOT SOFTBUS_HAS_LIBMODBUS)
message(STATUS "libmodbus not available; softbus_edge uses simulated Modbus I/O")
endif()
endif()
function(softbus_apply_libmodbus target)
if(SOFTBUS_HAS_LIBMODBUS)
target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_LIBMODBUS=1)
target_link_libraries(${target} PRIVATE libmodbus_iface)
if(SOFTBUS_LIBMODBUS_VENDOR)
target_compile_definitions(${target} PRIVATE SOFTBUS_LIBMODBUS_VENDOR=1)
endif()
else()
target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_LIBMODBUS=0)
endif()
endfunction()
function(softbus_apply_open62541 target)
if(SOFTBUS_HAS_OPCUA)
target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_OPCUA=1)

View File

@@ -0,0 +1,51 @@
# Vendored libmodbus v3.1.10 static library for softbus_edge
set(_src_dir "${CMAKE_SOURCE_DIR}/third_party/libmodbus")
if(NOT EXISTS "${_src_dir}/src/modbus.c")
message(WARNING "Vendor libmodbus not found at ${_src_dir}")
return()
endif()
set(_gen_dir "${CMAKE_BINARY_DIR}/libmodbus_vendor")
file(MAKE_DIRECTORY "${_gen_dir}")
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/libmodbus/config.h.linux"
"${_gen_dir}/config.h"
COPYONLY
)
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/libmodbus/modbus-version.h"
"${_gen_dir}/modbus-version.h"
COPYONLY
)
add_library(modbus_vendor STATIC
"${_src_dir}/src/modbus.c"
"${_src_dir}/src/modbus-data.c"
"${_src_dir}/src/modbus-rtu.c"
"${_src_dir}/src/modbus-tcp.c"
)
set_target_properties(modbus_vendor PROPERTIES
C_STANDARD 99
POSITION_INDEPENDENT_CODE ON
)
target_include_directories(modbus_vendor
PUBLIC
"${_src_dir}/src"
"${_gen_dir}"
)
if(UNIX)
target_link_libraries(modbus_vendor PUBLIC pthread)
endif()
add_library(libmodbus_iface INTERFACE)
target_link_libraries(libmodbus_iface INTERFACE modbus_vendor)
target_include_directories(libmodbus_iface INTERFACE
"${_src_dir}/src"
"${_gen_dir}"
)
set(SOFTBUS_HAS_LIBMODBUS ON PARENT_SCOPE)
set(SOFTBUS_LIBMODBUS_VENDOR ON PARENT_SCOPE)
message(STATUS "libmodbus: using vendored build from third_party/libmodbus")

View File

@@ -0,0 +1,46 @@
/* Linux config.h for vendored libmodbus v3.1.10 */
#define HAVE_ARPA_INET_H 1
#define HAVE_DECL_TIOCSRS485 1
#define HAVE_DECL_TIOCM_RTS 1
#define HAVE_ERRNO_H 1
#define HAVE_FCNTL_H 1
#define HAVE_FORK 1
#define HAVE_GETADDRINFO 1
#define HAVE_GETTIMEOFDAY 1
#define HAVE_INTTYPES_H 1
#define HAVE_LIMITS_H 1
#define HAVE_LINUX_SERIAL_H 1
#define HAVE_MEMORY_H 1
#define HAVE_MEMSET 1
#define HAVE_NETDB_H 1
#define HAVE_NETINET_IN_H 1
#define HAVE_NETINET_TCP_H 1
#define HAVE_SELECT 1
#define HAVE_SOCKET 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRERROR 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_TERMIOS_H 1
#define HAVE_TIME_H 1
#define HAVE_UNISTD_H 1
#define HAVE_VFORK 1
#define HAVE_WORKING_FORK 1
#define HAVE_WORKING_VFORK 1
#define PACKAGE "libmodbus"
#define PACKAGE_BUGREPORT "https://github.com/stephane/libmodbus/issues"
#define PACKAGE_NAME "libmodbus"
#define PACKAGE_STRING "libmodbus 3.1.10"
#define PACKAGE_TARNAME "libmodbus"
#define PACKAGE_URL ""
#define PACKAGE_VERSION "3.1.10"
#define STDC_HEADERS 1
#define TIME_WITH_SYS_TIME 1
#define VERSION "3.1.10"

View File

@@ -0,0 +1,19 @@
#ifndef MODBUS_VERSION_H
#define MODBUS_VERSION_H
#define LIBMODBUS_VERSION_MAJOR (3)
#define LIBMODBUS_VERSION_MINOR (1)
#define LIBMODBUS_VERSION_MICRO (10)
#define LIBMODBUS_VERSION 3.1.10
#define LIBMODBUS_VERSION_STRING "3.1.10"
#define LIBMODBUS_VERSION_HEX \
((LIBMODBUS_VERSION_MAJOR << 16) | (LIBMODBUS_VERSION_MINOR << 8) | \
(LIBMODBUS_VERSION_MICRO << 0))
#define LIBMODBUS_VERSION_CHECK(major, minor, micro) \
(LIBMODBUS_VERSION_MAJOR > (major) || \
(LIBMODBUS_VERSION_MAJOR == (major) && LIBMODBUS_VERSION_MINOR > (minor)) || \
(LIBMODBUS_VERSION_MAJOR == (major) && LIBMODBUS_VERSION_MINOR == (minor) && \
LIBMODBUS_VERSION_MICRO >= (micro)))
#endif /* MODBUS_VERSION_H */