Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
cpplint:
if: false # disable temporarily
runs-on: ubuntu-24.04
timeout-minutes: 1
steps:
Expand Down
44 changes: 15 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,22 @@
# Author: Dmitry Ponomarev <ponomarevda96@gmail.com>

cmake_minimum_required(VERSION 3.15.3)
set(DRONECAN_LIB_DIR ${CMAKE_CURRENT_LIST_DIR})
project(libdcnode VERSION 0.6.0 LANGUAGES C CXX)

set(SUPPORTED_PLATFORMS "bxcan;fdcan;socketcan")
if(NOT CAN_PLATFORM IN_LIST SUPPORTED_PLATFORMS)
message(SEND_ERROR "CAN_PLATFORM is not specified or unsupported! Options: bxcan, fdcan, socketcan.")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/platform_specific/${CAN_PLATFORM}/config.cmake)


if(NOT DEFINED LIBPARAMS_PATH)
message(SEND_ERROR "LIBPARAMS_PATH is not specified!")
endif()
if(NOT DEFINED LIBPARAMS_CMAKE)
message(SEND_WARNING "LIBPARAMS_CMAKE is not specified! Use default value 'CMakeLists.txt'.")
set(LIBPARAMS_CMAKE CMakeLists.txt)
endif()
include(${LIBPARAMS_PATH}/${LIBPARAMS_CMAKE})

set(DRONECAN_SOURCES
${DRONECAN_PLATFORM_SOURCES}
${DRONECAN_LIB_DIR}/Libs/libcanard_v0/canard.c
${DRONECAN_LIB_DIR}/src/dronecan.c
${DRONECAN_LIB_DIR}/src/logger.cpp
${DRONECAN_LIB_DIR}/src/weak.c
${libparamsSrc}
#
# 1. Create library
#
add_library(${PROJECT_NAME} STATIC
${CMAKE_CURRENT_LIST_DIR}/Libs/libcanard_v0/canard.c
${CMAKE_CURRENT_LIST_DIR}/src/dronecan.c
${CMAKE_CURRENT_LIST_DIR}/src/logger.cpp
)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

set(DRONECAN_HEADERS
${DRONECAN_LIB_DIR}/Libs
${DRONECAN_LIB_DIR}/include/application
${DRONECAN_LIB_DIR}/include/serialization
${libparamsHeaders}
target_include_directories(${PROJECT_NAME}
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/Libs
)
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-address-of-packed-member>
)
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BUILD_DIR:=$(ROOT_DIR)/build
BUILD_EXAMPLES_DIR:=$(BUILD_DIR)/src/examples
LIBPARAMS_DIR:=${BUILD_DIR}/external/libparams

define build_and_run_sitl
$(info Build example $(1)...)
mkdir -p $(BUILD_EXAMPLES_DIR)/$(1)
cd $(BUILD_EXAMPLES_DIR)/$(1) && cmake $(ROOT_DIR)/examples/$(1) && make -s
$(BUILD_EXAMPLES_DIR)/$(1)/application
$(BUILD_EXAMPLES_DIR)/$(1)/ubuntu
endef

ubuntu: clone_dependencies
ubuntu:
$(call build_and_run_sitl,ubuntu)

clone_dependencies:
mkdir -p build
if [ ! -d "${LIBPARAMS_DIR}" ]; then git clone --depth 1 --branch v0.8.4 https://github.com/PonomarevDA/libparams.git ${LIBPARAMS_DIR}; fi

clean:
rm -rf build/examples/

Expand All @@ -29,7 +24,7 @@ astyle:
./scripts/code_style/check_astyle.py src include --astylerc scripts/code_style/astylerc
cpplint:
cpplint src/*.c include/application/*.h include/serialization/*.h include/serialization/*/*/*.h include/serialization/*/*/*/*.h
cppcheck: clone_dependencies
cppcheck:
./scripts/code_style/cppcheck.sh
crlf:
./scripts/code_style/check_crlf.sh
Expand Down
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# DroneCAN application

This is a C library that brings up the [libcanard](https://github.com/dronecan/libcanard), platform-specific drivers and serialization together to build a minimal DroneCAN application.
This is a C library with C++ helpers that brings up the [libcanard](https://github.com/dronecan/libcanard), platform-specific drivers and serialization together to build a minimal DroneCAN application.

A minimal application includes the following protocol-features:

Expand Down Expand Up @@ -46,27 +46,31 @@ The library should support the following platforms:
Add the following lines into CMakeLists.txt of your project:

```cmake
# 1. Specify the CAN_PLATFORM. Options: bxcan, fdcan or socketcan.
set(CAN_PLATFORM socketcan)
# 1. libdcnode
add_subdirectory(${ROOT_DIR} ${CMAKE_BINARY_DIR}/libdcnode)

# 2. Specify path to libparams and platform. Options: stm32f103, stm32g0b1, ubuntu.
set(LIBPARAMS_PATH ../../build/libparams)
set(LIBPARAMS_PLATFORM ubuntu)
# 2. libcanver
set(CAN_PLATFORM socketcan) # Options: bxcan, fdcan or socketcan
include(${ROOT_DIR}/platform_specific/${CAN_PLATFORM}/config.cmake)

# 3. Include the CMakeLists.txt
include(../../CMakeLists.txt)
# 3. libparams
set(LIBPARAMS_PLATFORM ubuntu) # Options: stm32f103, stm32g0b1, ubuntu
include(libparams.cmake)

# 4. Add DroneCAN related source files and headers to you target.
add_executable(${EXECUTABLE}
# 4. Application
add_executable(${PROJECT_NAME}
...
${DRONECAN_SOURCES}
${DRONECAN_PLATFORM_SOURCES}
...
)
target_include_directories(${EXECUTABLE} PRIVATE
target_include_directories(${PROJECT_NAME} PRIVATE
...
${DRONECAN_HEADERS}
${DRONECAN_PLATFORM_HEADERS}
...
)
target_link_libraries(${PROJECT_NAME} PRIVATE
libdcnode::libdcnode
)
```


Expand All @@ -78,7 +82,7 @@ Include `dronecan.h` header and call `uavcanInitApplication` in the beginning of

```c++
// Include dronecan.h header file
#include "dronecan.h"
#include "libdcnode/dronecan.h"

// Initialize the library somewhere
const uint8_t node_id = 42;
Expand All @@ -100,8 +104,8 @@ while (true) {
Adding a publisher is very easy. Include `publisher.hpp` header, create an instance of the required publisher and just call `publish` when you need. Here is a BatteryInfo publisher example:

```c++
#include "dronecan.h"
#include "publisher.hpp"
#include "libdcnode/dronecan.h"
#include "libdcnode/publisher.hpp"

// Create an instance of the publisher
DronecanPublisher<BatteryInfo_t> battery_info_pub;
Expand Down Expand Up @@ -132,8 +136,8 @@ Adding a subscriber is easy as well. Let's consider a RawCommand subscriber exam

```c++
// Include necessary header files
#include "dronecan.h"
#include "subscriber.hpp"
#include "libdcnode/dronecan.h"
#include "libdcnode/subscriber.hpp"

// Add a callback handler function
void rc_callback(const RawCommand_t& msg) {
Expand All @@ -157,7 +161,7 @@ void ac_callback(const ArrayCommand_t& msg) {
}
bool ac_filter(const ArrayCommand_t& msg) {
for (size_t idx = 0; idx < msg.size; idx++) {
if (msg.commads[idx].actuator_id == FILTER_ACTUATOR_ID) {
if (msg.commands[idx].actuator_id == FILTER_ACTUATOR_ID) {
return true;
}
}
Expand Down Expand Up @@ -189,7 +193,7 @@ In gui_tool you will see:

## Platform specific notes

There are a few functions that require an implementation. They are declared in [include/application/dronecan_application_internal.h](include/application/dronecan_application_internal.h).
There are a few functions that require an implementation. They are declared in [include/application/internal.h](include/application/internal.h).

A user must provide the following function implementation:

Expand All @@ -201,7 +205,7 @@ A user must provide the following function implementation:
uint32_t platformSpecificGetTimeMs();
```

A user may also provide the implementation of the optional functions. These function have a week implementation in [src/weak.c](src/weak.c).
A user may also provide the implementation of the optional functions. These function have a weak implementation in [src/weak.c](src/weak.c).

```c++
/**
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32_hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <iostream>
#include <string.h>
#include "dronecan.h"
#include "libdcnode/dronecan.h"

void platformSpecificReadUniqueID(uint8_t out_uid[4]) {
const uint32_t UNIQUE_ID_16_BYTES[4] = {
Expand Down
93 changes: 53 additions & 40 deletions examples/ubuntu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,69 @@ project(ubuntu CXX C ASM)
cmake_path(GET CMAKE_CURRENT_LIST_DIR PARENT_PATH EXAMPLES_DIR)
cmake_path(GET EXAMPLES_DIR PARENT_PATH ROOT_DIR)

# 1. libdcnode
add_subdirectory(${ROOT_DIR} ${CMAKE_BINARY_DIR}/libdcnode)

# 1. Specify the CAN_PLATFORM. Options: bxcan, fdcan or socketcan
set(CAN_PLATFORM socketcan)
# 2. libcanver
set(CAN_PLATFORM socketcan) # Options: bxcan, fdcan or socketcan
include(${ROOT_DIR}/platform_specific/${CAN_PLATFORM}/config.cmake)

# 2. Specify path to libparams and platform. Options: stm32f103, stm32g0b1, ubuntu
set(LIBPARAMS_PATH ${ROOT_DIR}/build/external/libparams)
set(LIBPARAMS_PLATFORM ubuntu)

# 3. Include the CMakeLists.txt
include(${ROOT_DIR}/CMakeLists.txt)

# 4. Add DroneCAN related source files and headers to you target
add_executable(application
main.cpp
params.cpp
${DRONECAN_SOURCES}
${libparamsSrc}
)
target_include_directories(application PRIVATE
.
${DRONECAN_HEADERS}
${libparamsHeaders}
)
target_compile_options(application PRIVATE
-Wall
-Wextra
-Wfloat-equal
-Werror
-Wundef
-Wshadow
-Wpointer-arith
-Wunreachable-code
-Wstrict-overflow=5
-Wwrite-strings
-Wswitch-default
# 3. libparams
include(FetchContent)
set(FETCHCONTENT_BASE_DIR "${ROOT_DIR}/build/external")
FetchContent_Declare(
libparams
GIT_REPOSITORY https://github.com/PonomarevDA/libparams.git
GIT_TAG v0.8.4
GIT_SHALLOW TRUE
)
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
FetchContent_GetProperties(libparams)
if(NOT libparams_POPULATED)
FetchContent_Populate(libparams)
endif()
set(LIBPARAMS_PLATFORM ubuntu)
include(${ROOT_DIR}/build/external/libparams-src/CMakeLists.txt)

# 5. (Recommended) Add GIT_HASH based on git repository
# 4. Create application
execute_process(
COMMAND git rev-parse --short=16 HEAD
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_VARIABLE GIT_HASH_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND git rev-parse --short=16 HEAD
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_VARIABLE GIT_HASH_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(GIT_HASH "0x${GIT_HASH_SHORT}")
add_definitions(-DGIT_HASH=${GIT_HASH})
add_definitions(-DAPP_VERSION_MAJOR=0)
add_definitions(-DAPP_VERSION_MINOR=1)
add_definitions(-DHW_VERSION_MAJOR=0)
add_definitions(-DHW_VERSION_MINOR=0)

# 6. (Recommended) Set node name
add_definitions(-DAPP_NODE_NAME="${PROJECT_NAME}")

add_executable(${PROJECT_NAME}
main.cpp
${DRONECAN_PLATFORM_SOURCES}
${libparamsSrc}
)
target_include_directories(${PROJECT_NAME} PRIVATE
.
${libparamsHeaders}
)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wfloat-equal
-Werror
-Wundef
-Wshadow
-Wpointer-arith
-Wunreachable-code
-Wstrict-overflow=5
-Wwrite-strings
-Wswitch-default
)
target_link_libraries(${PROJECT_NAME} PRIVATE
libdcnode::libdcnode
)
Loading