Skip to content

Commit 21352cd

Browse files
Merge pull request #28 from humanoid2050/MSPv2_support
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
2 parents 7ec3162 + 59eee0d commit 21352cd

36 files changed

+8309
-3268
lines changed

.clang-format

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
BasedOnStyle: Google
3+
AccessModifierOffset: '-4'
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: 'true'
6+
AlignEscapedNewlines: Left
7+
AlignOperands: 'true'
8+
AlignTrailingComments: 'true'
9+
AllowShortBlocksOnASingleLine: 'false'
10+
AllowShortFunctionsOnASingleLine: All
11+
AllowShortIfStatementsOnASingleLine: 'true'
12+
AllowShortLoopsOnASingleLine: 'true'
13+
AlwaysBreakAfterReturnType: None
14+
AlwaysBreakTemplateDeclarations: 'false'
15+
BinPackArguments: 'false'
16+
BinPackParameters: 'true'
17+
BraceWrapping:
18+
AfterClass: false
19+
AfterControlStatement: false
20+
AfterEnum: false
21+
AfterFunction: false
22+
AfterNamespace: false
23+
AfterObjCDeclaration: false
24+
AfterStruct: false
25+
AfterUnion: false
26+
AfterExternBlock: false
27+
BeforeCatch: true
28+
BeforeElse: true
29+
IndentBraces: false
30+
SplitEmptyFunction: true
31+
SplitEmptyRecord: true
32+
SplitEmptyNamespace: true
33+
BreakBeforeBraces: Custom
34+
BreakBeforeInheritanceComma: 'false'
35+
BreakConstructorInitializers: AfterColon
36+
CompactNamespaces: 'false'
37+
ContinuationIndentWidth: '4'
38+
Cpp11BracedListStyle: 'true'
39+
FixNamespaceComments: 'true'
40+
IncludeBlocks: Merge
41+
IndentCaseLabels: 'false'
42+
IndentWidth: '4'
43+
IndentWrappedFunctionNames: 'false'
44+
KeepEmptyLinesAtTheStartOfBlocks: 'false'
45+
Language: Cpp
46+
NamespaceIndentation: None
47+
PointerAlignment: Right
48+
ReflowComments: 'true'
49+
SpaceAfterCStyleCast: 'false'
50+
SpaceAfterTemplateKeyword: 'true'
51+
SpaceBeforeAssignmentOperators: 'true'
52+
SpaceBeforeParens: Never
53+
SpaceInEmptyParentheses: 'false'
54+
SpacesInAngles: 'false'
55+
SpacesInCStyleCastParentheses: 'false'
56+
SpacesInContainerLiterals: 'false'
57+
SpacesInParentheses: 'false'
58+
SpacesInSquareBrackets: 'false'
59+
Standard: Cpp11
60+
TabWidth: '4'
61+
UseTab: Never
62+
63+
...

CMakeLists.txt

Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cmake_minimum_required(VERSION 3.1)
22
project(msp)
33

4-
set(CMAKE_CXX_STANDARD 11)
4+
set(CMAKE_CXX_STANDARD 14)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
8-
add_compile_options(-Wall -Wextra -Wpedantic)
8+
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
99
endif()
1010

1111
if(UNIX)
@@ -18,6 +18,9 @@ if(WIN32)
1818
include_directories(${ASIO_HEADER_PATH})
1919
endif()
2020

21+
OPTION(BUILD_EXAMPLES "Build Library with examples" ON)
22+
OPTION(BUILD_TESTS "Build Library with tests" OFF)
23+
2124
find_package(Threads)
2225

2326
set(MSP_SOURCE_DIR src)
@@ -28,15 +31,8 @@ include_directories(${MSP_INCLUDE_DIR})
2831
################################################################################
2932
### libraries
3033

31-
# low-level API
32-
add_library(msp ${MSP_SOURCE_DIR}/MSP.cpp)
33-
target_link_libraries(msp ${CMAKE_THREAD_LIBS_INIT})
34-
35-
# printing message content
36-
add_library(msp_msg_print ${MSP_SOURCE_DIR}/msg_print.cpp)
37-
3834
# client library
39-
add_library(mspclient ${MSP_SOURCE_DIR}/Client.cpp)
35+
add_library(mspclient ${MSP_SOURCE_DIR}/Client.cpp ${MSP_SOURCE_DIR}/PeriodicTimer.cpp)
4036
target_link_libraries(mspclient ${CMAKE_THREAD_LIBS_INIT})
4137

4238
# high-level API
@@ -47,54 +43,46 @@ target_link_libraries(msp_fcu mspclient)
4743
################################################################################
4844
### examples / tests
4945

50-
# test reading speed
51-
add_executable(msp_connection_test examples/msp_connection_test.cpp)
52-
target_link_libraries(msp_connection_test msp)
46+
if(BUILD_EXAMPLES)
5347

54-
# test and print all requests
55-
add_executable(msp_read_test examples/msp_read_test.cpp)
56-
target_link_libraries(msp_read_test msp msp_msg_print)
48+
# testing publish/subscribe
49+
add_executable(fcu_test examples/fcu_test.cpp)
50+
target_link_libraries(fcu_test msp_fcu)
5751

58-
# testing publish/subscribe
59-
add_executable(fcu_test examples/fcu_test.cpp)
60-
target_link_libraries(fcu_test msp_fcu msp_msg_print)
52+
# test arming and disarming
53+
add_executable(fcu_arm examples/fcu_arm_test.cpp)
54+
target_link_libraries(fcu_arm msp_fcu)
6155

62-
# test arming and disarming
63-
add_executable(fcu_arm examples/fcu_arm_test.cpp)
64-
target_link_libraries(fcu_arm msp_fcu)
56+
# test setting motors directly
57+
add_executable(fcu_motors examples/fcu_motor_test.cpp)
58+
target_link_libraries(fcu_motors msp_fcu)
6559

66-
# test setting motors directly
67-
add_executable(fcu_motors examples/fcu_motor_test.cpp)
68-
target_link_libraries(fcu_motors msp_fcu)
60+
# subscribing with custom type
61+
add_executable(fcu_custom_type examples/fcu_custom_type.cpp)
62+
target_link_libraries(fcu_custom_type msp_fcu)
6963

70-
# subscribing with custom type
71-
add_executable(fcu_custom_type examples/fcu_custom_type.cpp)
72-
target_link_libraries(fcu_custom_type msp_fcu)
64+
# client test for asynchronous callbacks
65+
add_executable(client_async_test examples/client_async_test.cpp)
66+
target_link_libraries(client_async_test mspclient )
7367

74-
# cleanflight requests
75-
add_executable(cleanflight_read_test examples/cleanflight_read_test.cpp)
76-
target_link_libraries(cleanflight_read_test msp msp_msg_print)
77-
78-
# client test for asynchronous callbacks
79-
add_executable(client_async_test examples/client_async_test.cpp)
80-
target_link_libraries(client_async_test mspclient msp_msg_print)
81-
82-
# client test for blocking read
83-
add_executable(client_read_test examples/client_read_test.cpp)
84-
target_link_libraries(client_read_test mspclient msp_msg_print)
68+
# client test for blocking read
69+
add_executable(client_read_test examples/client_read_test.cpp)
70+
target_link_libraries(client_read_test mspclient )
8571

72+
endif()
8673

8774
################################################################################
8875
### installation
8976

90-
install(TARGETS msp msp_msg_print msp_fcu mspclient
77+
#install(TARGETS msp msp_msg_print msp_fcu mspclient
78+
install(TARGETS msp_fcu mspclient
9179
LIBRARY DESTINATION lib
9280
ARCHIVE DESTINATION lib)
9381
install(DIRECTORY ${MSP_INCLUDE_DIR} DESTINATION include/ FILES_MATCHING PATTERN "*.hpp")
9482

9583
SET(PKG_CONFIG_LIBDIR "\${prefix}/lib" )
9684
SET(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/" )
97-
SET(PKG_CONFIG_LIBS "-L\${libdir} -lmsp -lmsp_fcu -lmspclient -lmsp_msg_print" )
85+
SET(PKG_CONFIG_LIBS "-L\${libdir} -lmsp_fcu -lmspclient" )
9886
SET(PKG_CONFIG_CFLAGS "-I\${includedir}" )
9987

10088
CONFIGURE_FILE(
@@ -104,3 +92,52 @@ CONFIGURE_FILE(
10492

10593
INSTALL(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
10694
DESTINATION lib/pkgconfig)
95+
96+
97+
98+
###############################################################################
99+
### testing
100+
if(BUILD_TESTS)
101+
enable_testing()
102+
103+
# Download and unpack googletest at configure time
104+
configure_file(CMakeLists.txt.in googletest/CMakeLists.txt)
105+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
106+
RESULT_VARIABLE result
107+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest )
108+
if(result)
109+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
110+
endif()
111+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
112+
RESULT_VARIABLE result
113+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest )
114+
if(result)
115+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
116+
endif()
117+
118+
# Prevent overriding the parent project's compiler/linker
119+
# settings on Windows
120+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
121+
122+
# Add googletest directly to our build. This defines
123+
# the gtest and gtest_main targets.
124+
add_subdirectory(/usr/src/gtest
125+
${CMAKE_BINARY_DIR}/googletest-build
126+
EXCLUDE_FROM_ALL)
127+
128+
# The gtest/gtest_main targets carry header search path
129+
# dependencies automatically when using CMake 2.8.11 or
130+
# later. Otherwise we have to add them here ourselves.
131+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
132+
include_directories("${gtest_SOURCE_DIR}/include")
133+
endif()
134+
135+
add_executable(value_test test/value_test.cpp)
136+
target_link_libraries(value_test gtest_main)
137+
add_test(NAME value_test COMMAND value_test)
138+
139+
add_executable(bytevector_test test/ByteVector_test.cpp)
140+
target_link_libraries(bytevector_test gtest_main)
141+
add_test(NAME bytevector_test COMMAND bytevector_test)
142+
143+
endif()

CMakeLists.txt.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 2.8.2)
2+
3+
project(googletest NONE)
4+
5+
include(ExternalProject)
6+
ExternalProject_Add(googletest
7+
SOURCE_DIR "/usr/src/gtest"
8+
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
9+
CONFIGURE_COMMAND ""
10+
BUILD_COMMAND ""
11+
INSTALL_COMMAND ""
12+
TEST_COMMAND ""
13+
)

0 commit comments

Comments
 (0)