Browse Source

Merge pull request #1736 from DonLakeFlyer/ArmedLog

Prompt for log save only if armed
QGC4.4
Don Gagne 10 years ago
parent
commit
f023db3c66
  1. 5
      src/VehicleSetup/SetupViewTest.cc
  2. 13
      src/comm/MAVLinkProtocol.cc
  3. 1
      src/comm/MAVLinkProtocol.h
  4. 6
      src/comm/MockLink.h
  5. 3
      src/qgcunittest/MainWindowTest.cc
  6. 47
      src/qgcunittest/MavlinkLogTest.cc
  7. 4
      src/qgcunittest/MavlinkLogTest.h

5
src/VehicleSetup/SetupViewTest.cc

@ -110,14 +110,11 @@ void SetupViewTest::_clickThrough_test(void) @@ -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
src/comm/MAVLinkProtocol.cc

@ -56,6 +56,7 @@ MAVLinkProtocol::MAVLinkProtocol(QObject* parent) : @@ -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),
@ -330,6 +331,15 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) @@ -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!
@ -690,12 +700,13 @@ void MAVLinkProtocol::_stopLogging(void) @@ -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.

1
src/comm/MAVLinkProtocol.h

@ -292,6 +292,7 @@ private: @@ -292,6 +292,7 @@ private:
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

6
src/comm/MockLink.h

@ -144,9 +144,9 @@ private: @@ -144,9 +144,9 @@ private:
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;

3
src/qgcunittest/MainWindowTest.cc

@ -100,11 +100,8 @@ void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot) @@ -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) {

47
src/qgcunittest/MavlinkLogTest.cc

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "MockLink.h"
#include "QGCTemporaryFile.h"
#include "QGCApplication.h"
#include "UAS.h"
UT_REGISTER_TEST(MavlinkLogTest)
@ -133,7 +134,7 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) @@ -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);
@ -142,20 +143,48 @@ void MavlinkLogTest::_connectLog_test(void) @@ -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)

4
src/qgcunittest/MavlinkLogTest.h

@ -45,7 +45,8 @@ private slots: @@ -45,7 +45,8 @@ 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:
@ -53,6 +54,7 @@ signals: @@ -53,6 +54,7 @@ signals:
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

Loading…
Cancel
Save