原文: https://mavlink.io/en/examples/c_udp.html
MAVLink C UDP Example
The MAVLink UDP Example is a simple C example that sends some data to QGroundControl using MAVLink over UDP. QGroundControl responds with heartbeats and other messages, which are then printed by this program.
MAVLink UDPのサンプルコードは、MAVLink over UDPを使用してQGroundControlにデータを送信する単純なCのサンプルです。QGroundControlはハートビートや他のメッセージで応答し、それらのメッセージはこのプログラムによって出力されます。
The example should work on any Unix-like system (Linux, MacOS, BSD, etc.). These instructions were tested on a clean Ubuntu LTS 16.04 installation using the default version of gcc (5.4.0).
このサンプルコードは、Unix系のシステム(Linux、MacOS、BSDなど)で動作するはずです。これらの手順は、デフォルトバージョンのgcc(5.4.0)を使用して、クリーンインストールしたUbuntu LTS 16.04でテストされました。
Building/Running the Example - サンプルコードのビルドと起動
The following instructions show how to build and run the example.
- Install MAVLink and generate the MAVLink 1.0 libraries into the mavlink/include directory.
- Alternatively you can clone the mavlink/mavlink repository and Download prebuilt headers to the same location. We recommend that you use MAVLink 1.0 headers as some ground control software may not yet support MAVLink 2.0.
- You can put/generate the library wherever you like, but the build command below assumes they are located in directory named include below the MAVLink root directory.
- Open a terminal and navigate to examples/linux
- Compile with GCC using the following command:
gcc -std=c99 -I ../../include/common -o mavlink_udp mavlink_udp.c
- Run the executable from the terminal:
./mavlink_udp- By default, the example will listen for data on the localhost IP address, port 14551. You can specify another IP address as a command line argument (use ./mavlink_udp --help to see usage).
- Open QGroundControl on the same machine.
- QGroundControl immediately starts broadcasting its
HEARTBEATon port 14551.
- The example should start displaying the received data in the terminal: