From 35dca1d0d268b351051fd6e3d43224e8c46253a4 Mon Sep 17 00:00:00 2001 From: Bryant Date: Thu, 30 Jan 2014 19:59:54 -0800 Subject: [PATCH] Improved MAVLink dialect selection. MAVLink dialects can now be specified as a list, so multiple dialects can be compiled in simultaneously (may result in conflicts between dialects). MAVLink dialects are checked for existance before support is added. Users are notified of which dialects are used and which cannot be added and why. The README now has info about specifying MAVLink dialects. --- QGCExternalLibs.pri | 81 +++++++++++++++++++++++++++---------- README.md | 5 +++ src/uas/ArduPilotMegaMAV.cc | 6 +++ 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/QGCExternalLibs.pri b/QGCExternalLibs.pri index 6cdaa282b..917f1057d 100644 --- a/QGCExternalLibs.pri +++ b/QGCExternalLibs.pri @@ -70,33 +70,70 @@ else { } # -# MAVLink -# - -MAVLINK_CONF = "" -MAVLINKPATH = $$BASEDIR/libs/mavlink/include/mavlink/v1.0 +# Add support for MAVLink. This is a required dependency for QGC. +# Some logic is involved here in selecting the proper dialect for +# the selected autopilot system. +# +# If the user config file exists, it will be included. If this file +# specifies the MAVLINK_CONF variable with a list of MAVLink +# dialects, support for them will be compiled in to QGC. It will also +# create a QGC_USE_{AUTOPILOT_NAME}_MESSAGES macro for use within +# the actual code. +# +MAVLINKPATH_REL = libs/mavlink/include/mavlink/v1.0 +MAVLINKPATH = $$BASEDIR/$$MAVLINKPATH_REL DEFINES += MAVLINK_NO_DATA -# If the user config file exists, it will be included. -# if the variable MAVLINK_CONF contains the name of an -# additional project, QGroundControl includes the support -# of custom MAVLink messages of this project. It will also -# create a QGC_USE_{AUTOPILOT_NAME}_MESSAGES macro for use -# within the actual code. -exists(user_config.pri) { +# First we select the dialect, checking for valid user selection +# Users can override all other settings by specifying MAVLINK_CONF as an argument to qmake +!isEmpty(MAVLINK_CONF) { + for(dialect, MAVLINK_CONF) { + exists($$MAVLINKPATH/$$dialect) { + MAVLINK_DIALECTS += $$dialect + message($$sprintf("Using MAVLink dialect '%1' specified at the command line.", $$dialect)) + } else { + error($$sprintf("MAVLink dialect '%1' specified at the command line does not exist at '%2'!", $$dialect, $$MAVLINKPATH_REL)) + } + } +} +# Otherwise they can specify MAVLINK_CONF within user_config.pri +else:exists(user_config.pri) { include(user_config.pri) - message("----- USING CUSTOM USER QGROUNDCONTROL CONFIG FROM user_config.pri -----") - message("Adding support for additional MAVLink messages for: " $$MAVLINK_CONF) - message("------------------------------------------------------------------------") -} else { - MAVLINK_CONF += ardupilotmega + !isEmpty(MAVLINK_CONF) { + for(dialect, MAVLINK_CONF) { + exists($$MAVLINKPATH/$$dialect) { + MAVLINK_DIALECTS += $$dialect + message($$sprintf("Using MAVLink dialect '%1' specified in user_config.pri", $$dialect)) + } else { + error($$sprintf("MAVLink dialect '%1' specified in user_config.pri does not exist at '%2'!", $$dialect, $$MAVLINKPATH_REL)) + } + } + } } +# If no valid user selection is found, default to the ardupilotmega if it's available. +# Note: This can be a list of several dialects. +else { + DEFAULT_MAVLINK_DIALECTS=ardupilotmega + for(dialect, DEFAULT_MAVLINK_DIALECTS) { + exists($$MAVLINKPATH/$$dialect) { + MAVLINK_DIALECTS += $$dialect + message($$sprintf("Using default MAVLink dialect '%1'.", $$dialect)) + } else { + warning($$sprintf("Default MAVLink dialect '%1' does not exist at '%2'!", $$dialect, $$MAVLINKPATH_REL)) + } + } +} +# Then we add the proper include paths dependent on the dialects and notify +# the user of the current dialect. INCLUDEPATH += $$MAVLINKPATH -isEmpty(MAVLINK_CONF) { - INCLUDEPATH += $$MAVLINKPATH/common +!isEmpty(MAVLINK_DIALECTS) { + for(dialect, MAVLINK_DIALECTS) { + INCLUDEPATH += $$MAVLINKPATH/$$dialect + DEFINES += $$sprintf('QGC_USE_%1_MESSAGES', $$upper($$dialect)) + } } else { - INCLUDEPATH += $$MAVLINKPATH/$$MAVLINK_CONF - DEFINES += $$sprintf('QGC_USE_%1_MESSAGES', $$upper($$MAVLINK_CONF)) + message("No valid MAVLink dialects found, only common messages supported.") + INCLUDEPATH += $$MAVLINKPATH/common } # @@ -238,7 +275,7 @@ MacBuild | WindowsBuild { # Protcol Buffers for PixHawk # -LinuxBuild : contains(MAVLINK_CONF, pixhawk) { +LinuxBuild : contains(MAVLINK_DIALECT, pixhawk) { exists(/usr/local/include/google/protobuf) | exists(/usr/include/google/protobuf) { message("Including support for Protocol Buffers") diff --git a/README.md b/README.md index 137fdd5e4..b2d4bbab0 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ To include QUpgrade functionality run the following (only needs to be done once The QUpgrade module relies on `libudev` on Linux platforms. +### Specifying MAVLink dialects +The MAVLink dialect compiled by default by QGC is for the ardupilotmega. This will happen if no other dialects are specified. To override this create a `user_config.pri` file in the root directory and set the `MAVLINK_CONF` variable using qmake's variable notation syntax: `MAVLINK_CONF=sensesoar`. This variable can be a list of dialects that should all be supported like `MAVLINK_CONF=sensesoar ardupilotmega`. Note that doing this may result in compilation errors as certain dialects may conflict with each other! + +The `MAVLINK_CONF` variable can also be specified at the command line as an argument to qmake to allow for easy one-off compilations: `qmake MAVLINK_CONF="sensesoar ardupilotmega"` + # Build on Mac OSX To build on Mac OSX (10.6 or later): diff --git a/src/uas/ArduPilotMegaMAV.cc b/src/uas/ArduPilotMegaMAV.cc index cb972df4e..fb32d377d 100644 --- a/src/uas/ArduPilotMegaMAV.cc +++ b/src/uas/ArduPilotMegaMAV.cc @@ -28,6 +28,7 @@ This file is part of the QGROUNDCONTROL project #include "ArduPilotMegaMAV.h" +#ifdef QGC_USE_ARDUPILOTMEGA_MESSAGES #ifndef MAVLINK_MSG_ID_MOUNT_CONFIGURE #include "ardupilotmega/mavlink_msg_mount_configure.h" #endif @@ -35,6 +36,7 @@ This file is part of the QGROUNDCONTROL project #ifndef MAVLINK_MSG_ID_MOUNT_CONTROL #include "ardupilotmega/mavlink_msg_mount_control.h" #endif +#endif ArduPilotMegaMAV::ArduPilotMegaMAV(MAVLinkProtocol* mavlink, int id) : UAS(mavlink, id)//, @@ -96,13 +98,16 @@ void ArduPilotMegaMAV::receiveMessage(LinkInterface* link, mavlink_message_t mes } void ArduPilotMegaMAV::setMountConfigure(unsigned char mode, bool stabilize_roll,bool stabilize_pitch,bool stabilize_yaw) { +#ifdef QGC_USE_ARDUPILOTMEGA_MESSAGES //Only supported by APM mavlink_message_t msg; mavlink_msg_mount_configure_pack(255,1,&msg,this->uasId,1,mode,stabilize_roll,stabilize_pitch,stabilize_yaw); sendMessage(msg); +#endif } void ArduPilotMegaMAV::setMountControl(double pa,double pb,double pc,bool islatlong) { +#ifdef QGC_USE_ARDUPILOTMEGA_MESSAGES mavlink_message_t msg; if (islatlong) { @@ -113,4 +118,5 @@ void ArduPilotMegaMAV::setMountControl(double pa,double pb,double pc,bool islatl mavlink_msg_mount_control_pack(255,1,&msg,this->uasId,1,pa,pb,pc,0); } sendMessage(msg); +#endif } -- 2.22.0