Skip to content

Commit

Permalink
Merge pull request mavlink#1736 from DonLakeFlyer/ArmedLog
Browse files Browse the repository at this point in the history
Prompt for log save only if armed
  • Loading branch information
DonLakeFlyer committed Jul 26, 2015
2 parents 0b9d1b1 + 519ee5a commit f023db3
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/VehicleSetup/SetupViewTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,11 @@ void SetupViewTest::_clickThrough_test(void)
QTest::qWait(1000);
}

// On MainWindow close we should get a message box telling the user to disconnect first. Disconnect will then pop
// the log file save dialog.
// On MainWindow close we should get a message box telling the user to disconnect first.

setExpectedMessageBox(QGCMessageBox::Yes);
setExpectedFileDialog(getSaveFileName, QStringList());

_mainWindow->close();
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedMessageBox();
checkExpectedFileDialog();
}
13 changes: 12 additions & 1 deletion src/comm/MAVLinkProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ MAVLinkProtocol::MAVLinkProtocol(QObject* parent) :
systemId(QGC::defaultSystemId),
_logSuspendError(false),
_logSuspendReplay(false),
_logWasArmed(false),
_tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)),
_linkMgr(LinkManager::instance()),
_heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE),
Expand Down Expand Up @@ -330,6 +331,15 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
_stopLogging();
_logSuspendError = true;
}

// Check for the vehicle arming going by. This is used to trigger log save.
if (!_logWasArmed && message.msgid == MAVLINK_MSG_ID_HEARTBEAT) {
mavlink_heartbeat_t state;
mavlink_msg_heartbeat_decode(&message, &state);
if (state.base_mode & MAV_MODE_FLAG_DECODE_POSITION_SAFETY) {
_logWasArmed = true;
}
}
}

// ORDER MATTERS HERE!
Expand Down Expand Up @@ -690,12 +700,13 @@ void MAVLinkProtocol::_stopLogging(void)
{
if (_closeLogFile()) {
// If the signals are not connected it means we are running a unit test. In that case just delete log files
if (qgcApp()->promptFlightDataSave()) {
if (_logWasArmed && qgcApp()->promptFlightDataSave()) {
emit saveTempFlightDataLog(_tempLogFile.fileName());
} else {
QFile::remove(_tempLogFile.fileName());
}
}
_logWasArmed = false;
}

/// @brief Checks the temp directory for log files which may have been left there.
Expand Down
1 change: 1 addition & 0 deletions src/comm/MAVLinkProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public slots:

bool _logSuspendError; ///< true: Logging suspended due to error
bool _logSuspendReplay; ///< true: Logging suspended due to replay
bool _logWasArmed; ///< true: vehicle was armed during logging

QGCTemporaryFile _tempLogFile; ///< File to log to
static const char* _tempLogFileTemplate; ///< Template for temporary log file
Expand Down
6 changes: 3 additions & 3 deletions src/comm/MockLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ private slots:
typedef QMap<uint16_t, mavlink_mission_item_t> MissionList_t;
MissionList_t _missionItems;

uint8_t _mavBaseMode;
uint8_t _mavCustomMode;
uint8_t _mavState;
uint8_t _mavBaseMode;
uint32_t _mavCustomMode;
uint8_t _mavState;

MockConfiguration* _config;
MAV_AUTOPILOT _autopilotType;
Expand Down
3 changes: 0 additions & 3 deletions src/qgcunittest/MainWindowTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot)
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedMessageBox();

// We are going to disconnect the link which is going to pop a save file dialog
setExpectedFileDialog(getSaveFileName, QStringList());
linkMgr->disconnectLink(link);
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedFileDialog();
}

void MainWindowTest::_connectWindowClosePX4_test(void) {
Expand Down
47 changes: 38 additions & 9 deletions src/qgcunittest/MavlinkLogTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "MockLink.h"
#include "QGCTemporaryFile.h"
#include "QGCApplication.h"
#include "UAS.h"

UT_REGISTER_TEST(MavlinkLogTest)

Expand Down Expand Up @@ -133,7 +134,7 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void)
// Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently.
}

void MavlinkLogTest::_connectLog_test(void)
void MavlinkLogTest::_connectLogWorker(bool arm)
{
LinkManager* linkMgr = LinkManager::instance();
Q_CHECK_PTR(linkMgr);
Expand All @@ -142,20 +143,48 @@ void MavlinkLogTest::_connectLog_test(void)
Q_CHECK_PTR(link);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through

// On Disconnect: We should get a getSaveFileName dialog.
QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
// Wait for the uas to work it's way through the various threads

QSignalSpy spyUas(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)));
QCOMPARE(spyUas.wait(5000), true);

UASInterface* uasInterface = UASManager::instance()->getActiveUAS();
QVERIFY(uasInterface);
UAS* uas = dynamic_cast<UAS*>(uasInterface);
QVERIFY(uas);

QDir logSaveDir;

if (arm) {
uas->armSystem();
QTest::qWait(1500); // Wait long enough for heartbeat to come through

// On Disconnect: We should get a getSaveFileName dialog.
logSaveDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
}

linkMgr->disconnectLink(link);
QTest::qWait(1000); // Need to allow signals to move between threads

checkExpectedFileDialog();
if (arm) {
checkExpectedFileDialog();

// Make sure the file is there and delete it
QCOMPARE(logSaveDir.remove(_saveLogFilename), true);
// Make sure the file is there and delete it
QCOMPARE(logSaveDir.remove(_saveLogFilename), true);
}
}

void MavlinkLogTest::_connectLogNoArm_test(void)
{
_connectLogWorker(false);
}

void MavlinkLogTest::_connectLogArm_test(void)
{
_connectLogWorker(true);
}

void MavlinkLogTest::_deleteTempLogFiles_test(void)
Expand Down
4 changes: 3 additions & 1 deletion src/qgcunittest/MavlinkLogTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ private slots:
void _bootLogDetectionCancel_test(void);
void _bootLogDetectionSave_test(void);
void _bootLogDetectionZeroLength_test(void);
void _connectLog_test(void);
void _connectLogNoArm_test(void);
void _connectLogArm_test(void);
void _deleteTempLogFiles_test(void);

signals:
void checkForLostLogFiles(void);

private:
void _createTempLogFile(bool zeroLength);
void _connectLogWorker(bool arm);

static const char* _tempLogFileTemplate; ///< Template for temporary log file
static const char* _logFileExtension; ///< Extension for log files
Expand Down

0 comments on commit f023db3

Please sign in to comment.