Skip to content

Commit

Permalink
Merge pull request mavlink#676 from DonLakeFlyer/BuildFixes
Browse files Browse the repository at this point in the history
Build fixes
  • Loading branch information
LorenzMeier committed May 25, 2014
2 parents f6ae324 + 3b43cf6 commit 323d162
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 24 deletions.
8 changes: 4 additions & 4 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ DebugBuild {
src/qgcunittest/MockUAS.h \
src/qgcunittest/MockQGCUASParamManager.h \
src/qgcunittest/MultiSignalSpy.h \
src/qgcunittest/TCPLinkTest.h \
src/qgcunittest/FlightModeConfigTest.h

SOURCES += \
Expand All @@ -196,7 +195,6 @@ DebugBuild {
src/qgcunittest/MockUAS.cc \
src/qgcunittest/MockQGCUASParamManager.cc \
src/qgcunittest/MultiSignalSpy.cc \
src/qgcunittest/TCPLinkTest.cc \
src/qgcunittest/FlightModeConfigTest.cc
}

Expand Down Expand Up @@ -563,7 +561,8 @@ HEADERS += \
src/ui/menuactionhelper.h \
src/uas/UASManagerInterface.h \
src/uas/QGCUASParamManagerInterface.h \
src/uas/QGCUASWorker.h
src/uas/QGCUASWorker.h \
src/CmdLineOptParser.h

SOURCES += \
src/main.cc \
Expand Down Expand Up @@ -747,4 +746,5 @@ SOURCES += \
src/ui/px4_configuration/QGCPX4SensorCalibration.cc \
src/ui/designer/QGCXYPlot.cc \
src/ui/menuactionhelper.cpp \
src/uas/QGCUASWorker.cc
src/uas/QGCUASWorker.cc \
src/CmdLineOptParser.cc
59 changes: 59 additions & 0 deletions src/CmdLineOptParser.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/

/// @file
/// @brief Command line option parser
///
/// @author Don Gagne <[email protected]>

#include "CmdLineOptParser.h"

#include <QString>

/// @brief Implements a simple command line parser which sets booleans to true if the option is found.
void ParseCmdLineOptions(int& argc, ///< count of arguments in argv
char* argv[], ///< command line arguments
CmdLineOpt_t* prgOpts, ///< command line options
size_t cOpts, ///< count of command line options
bool removeParsedOptions) ///< true: remove parsed option from argc/argv
{
// Start with all options off
for (size_t iOption=0; iOption<cOpts; iOption++) {
*prgOpts[iOption].flag = false;
}

for (int iArg=1; iArg<argc; iArg++) {
for (size_t iOption=0; iOption<cOpts; iOption++) {
if (QString(argv[iArg]).compare(prgOpts[iOption].optionStr, Qt::CaseInsensitive) == 0) {
*prgOpts[iOption].flag = true;
if (removeParsedOptions) {
for (int iShift=iArg; iShift<argc-1; iShift++) {
argv[iShift] = argv[iShift+1];
}
argc--;
iArg--;
}
}
}
}
}
46 changes: 46 additions & 0 deletions src/CmdLineOptParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/

/// @file
/// @brief Command line option parser
///
/// @author Don Gagne <[email protected]>

#ifndef CMDLINEOPTPARSER_H
#define CMDLINEOPTPARSER_H

#include <cstring>

/// @brief Structure used to pass command line options to the ParseCmdLineOptions function.
typedef struct {
const char* optionStr; ///< command line option, for example "--foo"
bool* flag; ///< if option is found this variable will be set to true
} CmdLineOpt_t;

void ParseCmdLineOptions(int& argc,
char* argv[],
CmdLineOpt_t* prgOpts,
size_t cOpts,
bool removeParsedOptions);

#endif
24 changes: 19 additions & 5 deletions src/QGCCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ This file is part of the QGROUNDCONTROL project
#include "MainWindow.h"
#include "QGCWelcomeMainWindow.h"
#include "GAudioOutput.h"
#include "CmdLineOptParser.h"

#ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h"
Expand Down Expand Up @@ -82,12 +83,25 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc,

// Set settings format
QSettings::setDefaultFormat(QSettings::IniFormat);

// Check application settings
// clear them if they mismatch
// QGC then falls back to default

// Parse command line options

bool fClearSettingsOptions = false; // Clear stored settings

CmdLineOpt_t rgCmdLineOptions[] = {
{ "--clear-settings", &fClearSettingsOptions },
// Add additional command line option flags here
};

ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false);

QSettings settings;

if (fClearSettingsOptions) {
// User requested settings to be cleared on command line
settings.clear();
}

// Show user an upgrade message if QGC got upgraded (see code below, after splash screen)
bool upgraded = false;
enum MainWindow::CUSTOM_MODE mode = MainWindow::CUSTOM_MODE_NONE;
Expand All @@ -98,7 +112,7 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc,
if (qgcVersion != QGC_APPLICATION_VERSION)
{
lastApplicationVersion = qgcVersion;
settings.clear();
settings.clear(); // Clear settings from different version
// Write current application version
settings.setValue("QGC_APPLICATION_VERSION", QGC_APPLICATION_VERSION);
upgraded = true;
Expand Down
49 changes: 39 additions & 10 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ This file is part of the QGROUNDCONTROL project
#include "TCPLink.h"
#ifdef QT_DEBUG
#include "AutoTest.h"
#include "CmdLineOptParser.h"
#ifdef Q_OS_WIN
#include <crtdbg.h>
#endif
#endif

/* SDL does ugly things to main() */
Expand All @@ -44,10 +48,10 @@ This file is part of the QGROUNDCONTROL project
#endif


// Install a message handler so you do not need
// the MSFT debug tools installed to se
// qDebug(), qWarning(), qCritical and qAbort
#ifdef Q_OS_WIN

/// @brief Message handler which is installed using qInstallMsgHandler so you do not need
/// the MSFT debug tools installed to see qDebug(), qWarning(), qCritical and qAbort
void msgHandler( QtMsgType type, const char* msg )
{
const char symbols[] = { 'I', 'E', '!', 'X' };
Expand All @@ -56,6 +60,17 @@ void msgHandler( QtMsgType type, const char* msg )
if( type == QtFatalMsg ) abort();
}

/// @brief CRT Report Hook installed using _CrtSetReportHook. We install this hook when
/// we don't want asserts to pop a dialog on windows.
int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
{
Q_UNUSED(reportType);

std::cerr << message << std::endl; // Output message to stderr
*returnValue = 0; // Don't break into debugger
return true; // We handled this fully ourselves
}

#endif

/**
Expand All @@ -81,13 +96,27 @@ int main(int argc, char *argv[])
qRegisterMetaType<QAbstractSocket::SocketError>();

#ifdef QT_DEBUG
if (argc > 1 && QString(argv[1]).compare("--unittest", Qt::CaseInsensitive) == 0) {
// Strip off extra command line args so QTest doesn't complain
for (int i=1; i<argc-1; i++)
{
argv[i] = argv[i+1];
}

// We parse a small set of command line options here prior to QGCCore in order to handle the ones
// which need to be handled before a QApplication object is started.

bool runUnitTests = false; // Run unit test
bool quietWindowsAsserts = false; // Don't let asserts pop dialog boxes

CmdLineOpt_t rgCmdLineOptions[] = {
{ "--unittest", &runUnitTests },
{ "--no-windows-assert-ui", &quietWindowsAsserts },
// Add additional command line option flags here
};

ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), true);

if (quietWindowsAsserts) {
#ifdef Q_OS_WIN
_CrtSetReportHook(WindowsCrtReportHook);
#endif
}

if (runUnitTests) {
// Run the test
int failures = AutoTest::run(argc-1, argv);
if (failures == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/uas/UAS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ UAS::UAS(MAVLinkProtocol* protocol, QThread* thread, int id) : UASInterface(),
paramsOnceRequested(false),
paramMgr(this),
simulation(0),
_thread(thread),

// The protected members.
connectionLost(false),
Expand All @@ -164,8 +165,7 @@ UAS::UAS(MAVLinkProtocol* protocol, QThread* thread, int id) : UASInterface(),
hilEnabled(false),
sensorHil(false),
lastSendTimeGPS(0),
lastSendTimeSensors(0),
_thread(thread)
lastSendTimeSensors(0)
{
moveToThread(thread);

Expand Down
7 changes: 4 additions & 3 deletions src/ui/PrimaryFlightDisplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const QString PrimaryFlightDisplay::compassWindNames[] = {
PrimaryFlightDisplay::PrimaryFlightDisplay(int width, int height, QWidget *parent) :
QWidget(parent),

_valuesChanged(false),
_valuesLastPainted(QGC::groundTimeMilliseconds()),

uas(NULL),

roll(0),
Expand Down Expand Up @@ -141,9 +144,7 @@ PrimaryFlightDisplay::PrimaryFlightDisplay(int width, int height, QWidget *paren
instrumentOpagueBackground(QColor::fromHsvF(0, 0, 0.3, 1.0)),

font("Bitstream Vera Sans"),
refreshTimer(new QTimer(this)),
_valuesChanged(false),
_valuesLastPainted(QGC::groundTimeMilliseconds())
refreshTimer(new QTimer(this))
{
Q_UNUSED(width);
Q_UNUSED(height);
Expand Down
1 change: 1 addition & 0 deletions src/ui/QGCMAVLinkLogPlayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ void QGCMAVLinkLogPlayer::logLoop()
// have at least 3ms until the next one.
int nextExecutionTime = 0;
mavlink_message_t msg;
msg.len = 0; // FIXME: Hack, remove once Issue #647 is fixed
while (nextExecutionTime < 3) {

// Now we're sitting at the start of a MAVLink message, so read it all into a byte array for feeding to our parser.
Expand Down

0 comments on commit 323d162

Please sign in to comment.