Skip to content

Commit

Permalink
Merge pull request #28 from humanoid2050/MSPv2_support
Browse files Browse the repository at this point in the history
Multiwii Serial Protocol Version 2 support

- single message base class with encode and decode methods
- rudimentary support for different message definitions for the same ID
- removal of old synchronous API (class MSP)
- auto code formatting via clang-format
  • Loading branch information
christianrauch authored Jan 25, 2019
2 parents 7ec3162 + 59eee0d commit 21352cd
Show file tree
Hide file tree
Showing 36 changed files with 8,309 additions and 3,268 deletions.
63 changes: 63 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
BasedOnStyle: Google
AccessModifierOffset: '-4'
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: 'true'
AlignEscapedNewlines: Left
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: 'true'
AllowShortLoopsOnASingleLine: 'true'
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: 'false'
BinPackArguments: 'false'
BinPackParameters: 'true'
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: 'false'
BreakConstructorInitializers: AfterColon
CompactNamespaces: 'false'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'true'
FixNamespaceComments: 'true'
IncludeBlocks: Merge
IndentCaseLabels: 'false'
IndentWidth: '4'
IndentWrappedFunctionNames: 'false'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
NamespaceIndentation: None
PointerAlignment: Right
ReflowComments: 'true'
SpaceAfterCStyleCast: 'false'
SpaceAfterTemplateKeyword: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: Never
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never

...
119 changes: 78 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(msp)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()

if(UNIX)
Expand All @@ -18,6 +18,9 @@ if(WIN32)
include_directories(${ASIO_HEADER_PATH})
endif()

OPTION(BUILD_EXAMPLES "Build Library with examples" ON)
OPTION(BUILD_TESTS "Build Library with tests" OFF)

find_package(Threads)

set(MSP_SOURCE_DIR src)
Expand All @@ -28,15 +31,8 @@ include_directories(${MSP_INCLUDE_DIR})
################################################################################
### libraries

# low-level API
add_library(msp ${MSP_SOURCE_DIR}/MSP.cpp)
target_link_libraries(msp ${CMAKE_THREAD_LIBS_INIT})

# printing message content
add_library(msp_msg_print ${MSP_SOURCE_DIR}/msg_print.cpp)

# client library
add_library(mspclient ${MSP_SOURCE_DIR}/Client.cpp)
add_library(mspclient ${MSP_SOURCE_DIR}/Client.cpp ${MSP_SOURCE_DIR}/PeriodicTimer.cpp)
target_link_libraries(mspclient ${CMAKE_THREAD_LIBS_INIT})

# high-level API
Expand All @@ -47,54 +43,46 @@ target_link_libraries(msp_fcu mspclient)
################################################################################
### examples / tests

# test reading speed
add_executable(msp_connection_test examples/msp_connection_test.cpp)
target_link_libraries(msp_connection_test msp)
if(BUILD_EXAMPLES)

# test and print all requests
add_executable(msp_read_test examples/msp_read_test.cpp)
target_link_libraries(msp_read_test msp msp_msg_print)
# testing publish/subscribe
add_executable(fcu_test examples/fcu_test.cpp)
target_link_libraries(fcu_test msp_fcu)

# testing publish/subscribe
add_executable(fcu_test examples/fcu_test.cpp)
target_link_libraries(fcu_test msp_fcu msp_msg_print)
# test arming and disarming
add_executable(fcu_arm examples/fcu_arm_test.cpp)
target_link_libraries(fcu_arm msp_fcu)

# test arming and disarming
add_executable(fcu_arm examples/fcu_arm_test.cpp)
target_link_libraries(fcu_arm msp_fcu)
# test setting motors directly
add_executable(fcu_motors examples/fcu_motor_test.cpp)
target_link_libraries(fcu_motors msp_fcu)

# test setting motors directly
add_executable(fcu_motors examples/fcu_motor_test.cpp)
target_link_libraries(fcu_motors msp_fcu)
# subscribing with custom type
add_executable(fcu_custom_type examples/fcu_custom_type.cpp)
target_link_libraries(fcu_custom_type msp_fcu)

# subscribing with custom type
add_executable(fcu_custom_type examples/fcu_custom_type.cpp)
target_link_libraries(fcu_custom_type msp_fcu)
# client test for asynchronous callbacks
add_executable(client_async_test examples/client_async_test.cpp)
target_link_libraries(client_async_test mspclient )

# cleanflight requests
add_executable(cleanflight_read_test examples/cleanflight_read_test.cpp)
target_link_libraries(cleanflight_read_test msp msp_msg_print)

# client test for asynchronous callbacks
add_executable(client_async_test examples/client_async_test.cpp)
target_link_libraries(client_async_test mspclient msp_msg_print)

# client test for blocking read
add_executable(client_read_test examples/client_read_test.cpp)
target_link_libraries(client_read_test mspclient msp_msg_print)
# client test for blocking read
add_executable(client_read_test examples/client_read_test.cpp)
target_link_libraries(client_read_test mspclient )

endif()

################################################################################
### installation

install(TARGETS msp msp_msg_print msp_fcu mspclient
#install(TARGETS msp msp_msg_print msp_fcu mspclient
install(TARGETS msp_fcu mspclient
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY ${MSP_INCLUDE_DIR} DESTINATION include/ FILES_MATCHING PATTERN "*.hpp")

SET(PKG_CONFIG_LIBDIR "\${prefix}/lib" )
SET(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/" )
SET(PKG_CONFIG_LIBS "-L\${libdir} -lmsp -lmsp_fcu -lmspclient -lmsp_msg_print" )
SET(PKG_CONFIG_LIBS "-L\${libdir} -lmsp_fcu -lmspclient" )
SET(PKG_CONFIG_CFLAGS "-I\${includedir}" )

CONFIGURE_FILE(
Expand All @@ -104,3 +92,52 @@ CONFIGURE_FILE(

INSTALL(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION lib/pkgconfig)



###############################################################################
### testing
if(BUILD_TESTS)
enable_testing()

# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(/usr/src/gtest
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()

add_executable(value_test test/value_test.cpp)
target_link_libraries(value_test gtest_main)
add_test(NAME value_test COMMAND value_test)

add_executable(bytevector_test test/ByteVector_test.cpp)
target_link_libraries(bytevector_test gtest_main)
add_test(NAME bytevector_test COMMAND bytevector_test)

endif()
13 changes: 13 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.8.2)

project(googletest NONE)

include(ExternalProject)
ExternalProject_Add(googletest
SOURCE_DIR "/usr/src/gtest"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Loading

0 comments on commit 21352cd

Please sign in to comment.