-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2473 from mavlink/pr-server-example
examples: Add example on how to use mavsdk_server lib
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
project(start_stop_server) | ||
|
||
add_executable(start_stop_server | ||
start_stop_server.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(start_stop_server | ||
MAVSDK::mavsdk_server | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(start_stop_server PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(start_stop_server PRIVATE -W2) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Example how to use C API of mavsdk_server. | ||
// | ||
|
||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/mavsdk_server/mavsdk_server_api.h> | ||
#include <iostream> | ||
#include <csignal> | ||
|
||
using namespace mavsdk; | ||
|
||
static struct MavsdkServer* mavsdk_server; | ||
|
||
void signal_handler(int sig) | ||
{ | ||
std::cout << "Received signal " << sig << std::endl; | ||
|
||
mavsdk_server_stop(mavsdk_server); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
if (argc != 2) { | ||
std::cout << "Connection string required as argument" << std::endl; | ||
return 1; | ||
} | ||
|
||
signal(SIGINT, signal_handler); | ||
|
||
mavsdk_server_init(&mavsdk_server); | ||
mavsdk_server_run(mavsdk_server, argv[1], 50051); | ||
|
||
mavsdk_server_destroy(mavsdk_server); | ||
|
||
return 0; | ||
} |