├── .github └── workflows │ └── hardware-test.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── README.md ├── cmake └── CheckPython.cmake ├── src ├── CMakeLists.txt ├── device │ ├── CMakeLists.txt │ ├── ping-device.cpp │ └── ping-device.h ├── generate │ ├── generate-device.py │ ├── generate-message.py │ └── templates │ │ ├── ping-device-ping1d.cpp.in │ │ ├── ping-device-ping1d.h.in │ │ ├── ping-device-ping360.cpp.in │ │ ├── ping-device-ping360.h.in │ │ ├── ping-message-.h.in │ │ └── ping-message-all.h.in ├── hal │ ├── CMakeLists.txt │ ├── link │ │ ├── desktop │ │ │ ├── abstract-link.cpp │ │ │ ├── abstract-link.h │ │ │ ├── serial-link.cpp │ │ │ ├── serial-link.h │ │ │ ├── udp-link.cpp │ │ │ └── udp-link.h │ │ └── ping-port.h │ └── time │ │ ├── desktop │ │ └── ping-time.cpp │ │ └── ping-time.h └── message │ ├── CMakeLists.txt │ ├── ping-message.h │ └── ping-parser.h ├── test ├── command-line │ └── command-line.h ├── helper.h ├── test-device-ping1d.cpp ├── test-device-ping360.cpp ├── test-device.cpp └── test-message.cpp └── tools └── travis-ci-script.sh /.github/workflows/hardware-test.yml: -------------------------------------------------------------------------------- 1 | name: Linux hardware test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: self-hosted 9 | 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Install necessary tools 13 | run: | 14 | sudo apt -y update 15 | sudo apt -y install cmake libboost-all-dev 16 | sudo apt -y install python3-pip python3-setuptools 17 | 18 | - name: Build it 19 | run: | 20 | git submodule update --init --recursive 21 | mkdir build 22 | cmake -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build --parallel --config Debug 23 | 24 | - name: Run tests 25 | run: | 26 | cd build 27 | ./test-message 28 | ls -ls /dev/ttyUSB* 29 | for device in /dev/ttyUSB*; do $PWD/test-device --conn serial:$device:115200; done 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | **/ping-message-*.h 3 | build 4 | src/device/ping-device-ping1d.* 5 | src/device/ping-device-ping360.* 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/ping-protocol"] 2 | path = lib/ping-protocol 3 | url = https://github.com/bluerobotics/ping-protocol 4 | [submodule "lib/fmt"] 5 | path = lib/fmt 6 | url = https://github.com/fmtlib/fmt 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: bionic 2 | 3 | language: minimal 4 | 5 | addons: 6 | apt: 7 | packages: 8 | - python3 9 | - python3-pip 10 | 11 | install: 12 | # thank you https://stackoverflow.com/a/47441734 13 | # this is requried to be able to checkout branches after fetching 14 | - git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* 15 | - git fetch origin deployment 16 | - sudo add-apt-repository -y ppa:mhier/libboost-latest 17 | - sudo apt install -y libboost1.70-dev 18 | 19 | script: 20 | - tools/travis-ci-script.sh || travis_terminate 1 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(ping-cpp LANGUAGES CXX) 3 | 4 | # Use standard C++ version and remove extensions to allow better compatibility 5 | set(CMAKE_CXX_STANDARD 14) 6 | set(CMAKE_CXX_EXTENSIONS OFF) 7 | 8 | # Enable compile checks for msvc, clang and gcc 9 | if(MSVC) 10 | add_compile_options(/W4 /WX) 11 | else() 12 | add_compile_options(-Wall -Wextra -pedantic -Werror) 13 | # Can be removed moving to C++17, or we could move this library out from header only 14 | add_compile_options(-Wno-unused-function) 15 | endif() 16 | 17 | # Used for the command line interface 18 | find_package(Boost 1.67 COMPONENTS filesystem program_options REQUIRED) 19 | include_directories(${Boost_INCLUDE_DIR}) 20 | 21 | # Include modules 22 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) 23 | 24 | option(PING_CPP_BUILD_TESTS "Build the test cases when PING_CPP_BUILD_TESTS is enabled." ON) 25 | 26 | if (PING_CPP_BUILD_TESTS) 27 | # Add fmt subdirectory 28 | add_subdirectory(lib/fmt/) 29 | 30 | # test-device 31 | add_executable(test-device) 32 | target_include_directories(test-device PRIVATE lib/fmt/include/) 33 | target_sources( 34 | test-device 35 | PRIVATE 36 | test/test-device.cpp 37 | ) 38 | target_link_libraries( 39 | test-device 40 | PRIVATE 41 | DEVICE 42 | HAL 43 | PING_MESSAGES 44 | ${Boost_LIBRARIES} 45 | fmt::fmt 46 | ) 47 | 48 | # test-device-ping1d 49 | add_executable(test-device-ping1d) 50 | target_include_directories(test-device-ping1d PRIVATE lib/fmt/include/) 51 | target_sources( 52 | test-device-ping1d 53 | PRIVATE 54 | test/test-device-ping1d.cpp 55 | ) 56 | target_link_libraries( 57 | test-device-ping1d 58 | PRIVATE 59 | DEVICE 60 | HAL 61 | PING_MESSAGES 62 | ${Boost_LIBRARIES} 63 | fmt::fmt 64 | ) 65 | 66 | # test-device-ping360 67 | add_executable(test-device-ping360) 68 | target_include_directories(test-device-ping360 PRIVATE lib/fmt/include/) 69 | target_sources( 70 | test-device-ping360 71 | PRIVATE 72 | test/test-device-ping360.cpp 73 | ) 74 | target_link_libraries( 75 | test-device-ping360 76 | PRIVATE 77 | DEVICE 78 | HAL 79 | PING_MESSAGES 80 | ${Boost_LIBRARIES} 81 | fmt::fmt 82 | ) 83 | 84 | # test-message 85 | add_executable(test-message) 86 | target_include_directories(test-message PRIVATE lib/fmt/include/) 87 | target_sources( 88 | test-message 89 | PRIVATE 90 | test/test-message.cpp 91 | ) 92 | target_link_libraries( 93 | test-message 94 | PRIVATE 95 | PING_MESSAGES 96 | ) 97 | endif() 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ping-cpp 2 | 3 | [![Travis Test](https://travis-ci.com/bluerobotics/ping-cpp.svg?branch=master)](https://travis-ci.com/github/bluerobotics/ping-cpp) 4 | [![Linux hardware test](https://github.com/bluerobotics/ping-cpp/actions/workflows/hardware-test.yml/badge.svg)](https://github.com/bluerobotics/ping-cpp/actions/workflows/hardware-test.yml) 5 | 6 | C++ API implementation of [ping-protocol](https://docs.bluerobotics.com/ping-protocol/). 7 | 8 | This repository has the ping_message base class, and templates + scripts to automatically generate device-specific message subclasses. 9 | 10 | ## Usage 11 | 12 | #### Generated files 13 | 14 | If you would like to use the C++ API in your project, checkout the [deployment branch](https://github.com/bluerobotics/ping-cpp/tree/deployment). 15 | 16 | #### CMake project 17 | 18 | The **master branch** can be used directly in CMake based projects for desktop or SBC applications. 19 | ##### Example 20 | 21 | ```sh 22 | # Clone the repository 23 | git clone https://github.com/bluerobotics/ping-cpp 24 | cd ping-cpp 25 | # Update the submodules 26 | git submodule update --init --recursive 27 | # Configure and build the project in debug mode 28 | cmake -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build --parallel --config Debug 29 | # Connect a Ping device and use the correct USB as argument 30 | ./build/test-device --conn serial:/dev/ttyUSB0:115200 31 | # If you have a Ping1D connected, you can run the test program for the device 32 | ./build/test-device-ping1d --conn serial:/dev/ttyUSB0:115200 33 | ``` 34 | -------------------------------------------------------------------------------- /cmake/CheckPython.cmake: -------------------------------------------------------------------------------- 1 | # Check if python is installed with the necessary components 2 | find_package(Python3 QUIET REQUIRED COMPONENTS Interpreter) 3 | 4 | execute_process( 5 | COMMAND ${Python3_EXECUTABLE} -m pip show jinja2 6 | OUTPUT_QUIET 7 | RESULT_VARIABLE EXIT_CODE 8 | ) 9 | 10 | if(NOT ${EXIT_CODE} EQUAL 0) 11 | message( 12 | WARNING 13 | "The Python3 package \"jinja2\" is not installed. We are going to install it." 14 | ) 15 | 16 | execute_process( 17 | COMMAND ${Python3_EXECUTABLE} -m pip install jinja2 --user 18 | RESULT_VARIABLE EXIT_CODE 19 | ) 20 | 21 | if(NOT ${EXIT_CODE} EQUAL 0) 22 | message( 23 | FATAL_ERROR 24 | "Failed to install the Python3 package \"jinja2\". Make sure that pip3 is installed and working." 25 | ) 26 | endif() 27 | 28 | endif() 29 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include each sub folder 2 | set(INCLUDE_DIRS 3 | device 4 | hal 5 | message 6 | ) 7 | 8 | include(${PROJECT_SOURCE_DIR}/cmake/CheckPython.cmake) 9 | 10 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS}) 11 | 12 | foreach(directory ${INCLUDE_DIRS}) 13 | add_subdirectory(${directory}) 14 | endforeach() 15 | -------------------------------------------------------------------------------- /src/device/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(DEVICE) 3 | 4 | # Generate ping-cpp devices 5 | add_custom_target(generate-devices 6 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../generate/generate-device.py --output-dir ${CMAKE_CURRENT_SOURCE_DIR} 7 | COMMENT "Generates ping device class." 8 | BYPRODUCTS 9 | ${CMAKE_CURRENT_SOURCE_DIR}/ping-device-ping360.cpp 10 | ${CMAKE_CURRENT_SOURCE_DIR}/ping-device-ping1d.cpp 11 | ) 12 | 13 | add_library( 14 | DEVICE 15 | STATIC 16 | ping-device-ping1d.cpp 17 | ping-device-ping360.cpp 18 | ping-device.cpp 19 | ) 20 | 21 | include_directories(${HAL_SOURCE_DIR}) 22 | 23 | target_link_libraries( 24 | DEVICE 25 | PRIVATE 26 | HAL 27 | PING_MESSAGES 28 | ) 29 | 30 | target_include_directories( 31 | DEVICE 32 | PUBLIC 33 | ${CMAKE_CURRENT_SOURCE_DIR} 34 | ) 35 | 36 | add_dependencies(DEVICE generate-devices) 37 | -------------------------------------------------------------------------------- /src/device/ping-device.cpp: -------------------------------------------------------------------------------- 1 | #include "ping-device.h" 2 | 3 | #include 4 | #include