Skip to content

Commit

Permalink
Merge branch 'master' of github.com:robert-burger/libethercat
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-burger committed Apr 24, 2024
2 parents c0ee5df + 28e8e1e commit 319c33c
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 77 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/doxygen-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Doxygen

on:
repository_dispatch:
push:
branches:
- master
- gh-pages

# In that case do the job 'make_and_deploy_doxygen'
jobs:
make_and_deploy_doxygen:
runs-on: ubuntu-latest
# which needs the following steps to be executed:
steps:
# 1. Checkout current branch of GitHub repository.
- name: Checkout current branch
uses: actions/checkout@v2
# 2. Install doxygen and its auxiliary components.
- name: Install doxygen and latex components
run: sudo apt-get update; sudo apt-get install -y doxygen graphviz texlive-full
# 3. Create the doxygen pages.
- name: Create the doxygen
run: |
git clone https://github.com/robert-burger/libethercat.git
cd libethercat
make -f Makefile.doc doc/html BUILDCMD=doxygen
- name: Moving Files
run: |
mv ./libethercat/doc/html ./api
# Deploy to GitHub Pages
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./api
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ cmake-build-*
*.ko
Module.symvers
modules.order

build
123 changes: 97 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
cmake_minimum_required(VERSION 3.5)
project(libethercat)
file(READ "project.properties" PROJECT_PROPERTIES)
string(REGEX MATCH "VERSION = ([0-9]*.[0-9]*.[0-9]*)" _ ${PROJECT_PROPERTIES})
set(PROJECT_VERSION ${CMAKE_MATCH_1})
project(libethercat VERSION ${PROJECT_VERSION})

set(ECAT_DEVICE "sock_raw" CACHE STRING "EtherCAT device layer")

INCLUDE(CheckIncludeFiles)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(ExternalProject)
include(CMakePackageConfigHelpers)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)

CHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILES("arpa/inet.h" HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILES("net/if.h" HAVE_NET_IF_H)
CHECK_INCLUDE_FILES("net/bpf.h" HAVE_NET_BPF_H)
CHECK_INCLUDE_FILES("fcntl.h" HAVE_FCNTL_H)
CHECK_INCLUDE_FILES("limits.h" HAVE_LIMITS_H)
CHECK_INCLUDE_FILES("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILES("stdlib.h" HAVE_STDLIB_H)
CHECK_INCLUDE_FILES("string.h" HAVE_STRING_H)
CHECK_INCLUDE_FILES("sys/ioctl.h" HAVE_SYS_IOCTL_H)
CHECK_INCLUDE_FILES("sys/socket.h" HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)

find_package (libosal)
set(LIBETHERCAT_STDC_HEADERS 1)
set(LIBETHERCAT_PACKAGE_VERSION "${CMAKE_PROJECT_VERSION}")
set(LIBETHERCAT_VERSION "${CMAKE_PROJECT_VERSION}")
set(LIBETHERCAT_PACKAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}")
set(LIBETHERCAT_PACKAGE "${CMAKE_PROJECT_NAME}")
set(LIBETHERCAT_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
set(LIBETHERCAT_PACKAGE_TARNAME "${CMAKE_PROJECT_NAME}")
set(LIBETHERCAT_PACKAGE_STRING "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}")

check_include_files("arpa/inet.h" LIBETHERCAT_HAVE_ARPA_INET_H)
check_symbol_exists("clock_gettime" "time.h" LIBETHERCAT_HAVE_CLOCK_GETTIME)
check_include_files("dlfcn.h" LIBETHERCAT_HAVE_DLFCN_H)
check_include_files("fcntl.h" LIBETHERCAT_HAVE_FCNTL_H)
check_include_files("inttypes.h" LIBETHERCAT_HAVE_INTTYPES_H)
find_library(HAS_RT_RAW rt)
if(HAS_RT_RAW)
SET(LIBETHERCAT_HAVE_LIBRT 1)
endif()
check_include_files("limits.h" LIBETHERCAT_HAVE_LIMITS_H)
check_symbol_exists("malloc" "stdlib.h" LIBETHERCAT_HAVE_MALLOC)
check_include_files("memory.h" LIBETHERCAT_HAVE_MEMORY_H)
check_symbol_exists("memset" "string.h" LIBETHERCAT_HAVE_MALLOC)
check_include_files("net/bpf.h" LIBETHERCAT_HAVE_NET_BPF_H)
check_include_files("net/if.h" LIBETHERCAT_HAVE_NET_IF_H)
check_include_files("pthread.h" LIBETHERCAT_HAVE_PTHREAD)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists("pthread_setaffinity_np" "pthread.h" LIBETHERCAT_HAVE_PTHREAD_SETAFFINITY_NP)
check_symbol_exists("realloc" "stdlib.h" LIBETHERCAT_HAVE_REALLOC)
check_symbol_exists("socket" "sys/socket.h" LIBETHERCAT_HAVE_SOCKET)
check_include_files("stdint.h" LIBETHERCAT_HAVE_STDINT_H)
check_include_files("stdlib.h" LIBETHERCAT_HAVE_STDLIB_H)
check_symbol_exists("strdup" "string.h" LIBETHERCAT_HAVE_STRDUP)
check_symbol_exists("strerror" "string.h" LIBETHERCAT_HAVE_STRERROR)
check_include_files("strings.h" LIBETHERCAT_HAVE_STRINGS_H)
check_include_files("string.h" LIBETHERCAT_HAVE_STRING_H)
check_symbol_exists("strndup" "string.h" LIBETHERCAT_HAVE_STRNDUP)
check_include_files("sys/ioctl.h" LIBETHERCAT_HAVE_SYS_IOCTL_H)
check_include_files("sys/socket.h" LIBETHERCAT_HAVE_SYS_SOCKET_H)
check_include_files("sys/stat.h" LIBETHERCAT_HAVE_SYS_STAT_H)
check_include_files("sys/time.h" LIBETHERCAT_HAVE_SYS_TIME_H)
check_include_files("sys/types.h" LIBETHERCAT_HAVE_SYS_TYPES_H)
check_include_files("unistd.h" LIBETHERCAT_HAVE_UNISTD_H)

find_package(libosal REQUIRED)
find_package (Threads REQUIRED)

include_directories(${libosal_INCLUDE_DIRS} include)
link_directories(${libosal_LIB_DIR})

configure_file(cmake_config.h.in config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/libethercat/config.h)

set(DEFAULT_DEFS HAVE_STDLIB_H HAVE_NET_IF_H HAVE_ARPA_INET_H)

set(SRC_ETHERCAT
src/async_loop.c
Expand All @@ -50,29 +87,63 @@ set(SRC_ETHERCAT

if (${ECAT_DEVICE} STREQUAL "sock_raw")
set(SRC_HW_LAYER src/hw_sock_raw.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY)
elseif (${ECAT_DEVICE} STREQUAL "sock_raw_mmaped")
set(SRC_HW_LAYER src/hw_file.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED)
elseif (${ECAT_DEVICE} STREQUAL "file")
set(SRC_HW_LAYER src/hw_file.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_FILE)
elseif (${ECAT_DEVICE} STREQUAL "pikeos")
set(SRC_HW_LAYER src/hw_pikeos.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_PIKEOS)
elseif (${ECAT_DEVICE} STREQUAL "bpf")
set(SRC_HW_LAYER src/hw_bpf.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_BPD)
endif()

# LIBS
add_library(ethercat ${SRC_ETHERCAT} ${SRC_HW_LAYER})
target_compile_definitions(ethercat PRIVATE $DEFAULT_DEFS)
target_link_libraries (ethercat ${CMAKE_THREAD_LIBS_INIT} ${libosal_LIBS})

# TOOLS
add_executable(eepromtool tools/eepromtool/eepromtool.c)
target_compile_definitions(eepromtool PRIVATE $DEFAULT_DEFS)
target_link_libraries (eepromtool ethercat)
target_link_libraries (eepromtool ethercat ${libosal_LIBS})

add_executable(ethercatdiag tools/ethercatdiag/ethercatdiag.c)
target_compile_definitions(ethercatdiag PRIVATE $DEFAULT_DEFS)
target_link_libraries (ethercatdiag ethercat)
target_link_libraries (ethercatdiag ethercat ${libosal_LIBS})

add_executable(example_with_dc tools/example_with_dc/example_with_dc.c)
target_compile_definitions(example_with_dc PRIVATE $DEFAULT_DEFS)
target_link_libraries (example_with_dc ethercat m)
target_link_libraries (example_with_dc ethercat ${libosal_LIBS} m)

# Install
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/libethercatConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
set(ETHERCAT_LIB_NAME ethercat)

configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/libethercatConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libethercatConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/libethercat
PATH_VARS ETHERCAT_LIB_NAME INSTALL_DIR
)

install(TARGETS ethercat EXPORT libethercatTargets)
install(
EXPORT libethercatTargets
FILE libethercatTargets.cmake
DESTINATION lib/cmake/libethercat
)
install(DIRECTORY include/libethercat/ DESTINATION include/libethercat
FILES_MATCHING PATTERN "*.h"
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libethercatConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libethercatConfigVersion.cmake"
DESTINATION lib/cmake/libethercat
)
Empty file removed README
Empty file.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This library provides all functionality to communicate with EtherCAT slaves atta

# Network device access

- **raw socket** » The most common way sending ethernet frames in Linux is opening a raw network socket (`SOCK_RAW`). Therefor the program must either be run as root or with the capability flag `CAP_NET_RAW`.
- **raw socket** » The most common way sending ethernet frames in Linux is opening a raw network socket (`SOCK_RAW`). Therefor the program must either be run as root or with the capability flag `CAP_NET_RAW`. Either do sth like: `sudo setcap cap_net_raw=ep .libs/example_with_dc` or checkout grant_cap_net_raw kernel module from Flo Schmidt (https://gitlab.com/fastflo/open_ethercat).
- **raw_socket_mmaped** » Like above but don't use read/write to provide frame buffers to kernel and use mmaped buffers directly from kernel.
- **file** » Most performant/determinstic interface to send/receive frames with network hardware. Requires hacked linux network driver. Can also be used without interrupts to avoid context switches. For how to compile and use such a driver head over to [drivers readme](linux/README.md).
- **pikeos** » Special pikeos hardware access.
Expand All @@ -41,7 +41,7 @@ Germany (ETG, www.ethercat.org).

## Usage

See INTRODUCTION.md or gh-pages for reference.
See INTRODUCTION.md or [gh-pages](https://robert-burger.github.io/libethercat/) for reference.

## Build from source

Expand All @@ -62,6 +62,16 @@ sudo make install

This will build and install a static as well as a dynamic library. For use in other project you can use the generated pkg-config file to retreave cflags and linker flags.

### CMake

```bash
mkdir build
cd build
# Please change the path to the install dir. If you chose a global install you can omit the CMAKE_PREFIX_PATH option
cmake .. -DCMAKE_PREFIX_PATH=<installdir of libosal>
cmake --build .
```

## Tools

libethercat also provides some small helper programs for the EtherCAT bus.
Expand Down
Loading

0 comments on commit 319c33c

Please sign in to comment.