Skip to content

Commit

Permalink
Add support for log save even if not armed
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Nov 19, 2015
1 parent 22d5010 commit b03c171
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 61 deletions.
24 changes: 19 additions & 5 deletions src/QGCApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@

QGCApplication* QGCApplication::_app = NULL;

const char* QGCApplication::_deleteAllSettingsKey = "DeleteAllSettingsNextBoot";
const char* QGCApplication::_settingsVersionKey = "SettingsVersion";
const char* QGCApplication::_savedFilesLocationKey = "SavedFilesLocation";
const char* QGCApplication::_promptFlightDataSave = "PromptFLightDataSave";
const char* QGCApplication::_styleKey = "StyleIsDark";
const char* QGCApplication::_deleteAllSettingsKey = "DeleteAllSettingsNextBoot";
const char* QGCApplication::_settingsVersionKey = "SettingsVersion";
const char* QGCApplication::_savedFilesLocationKey = "SavedFilesLocation";
const char* QGCApplication::_promptFlightDataSave = "PromptFLightDataSave";
const char* QGCApplication::_promptFlightDataSaveNotArmed = "PromptFLightDataSaveNotArmed";
const char* QGCApplication::_styleKey = "StyleIsDark";

const char* QGCApplication::_defaultSavedFileDirectoryName = "QGroundControl";
const char* QGCApplication::_savedFileMavlinkLogDirectoryName = "FlightData";
Expand Down Expand Up @@ -554,12 +555,25 @@ bool QGCApplication::promptFlightDataSave(void)
return settings.value(_promptFlightDataSave, true).toBool();
}

bool QGCApplication::promptFlightDataSaveNotArmed(void)
{
QSettings settings;

return settings.value(_promptFlightDataSaveNotArmed, false).toBool();
}

void QGCApplication::setPromptFlightDataSave(bool promptForSave)
{
QSettings settings;
settings.setValue(_promptFlightDataSave, promptForSave);
}

void QGCApplication::setPromptFlightDataSaveNotArmed(bool promptForSave)
{
QSettings settings;
settings.setValue(_promptFlightDataSaveNotArmed, promptForSave);
}

/// @brief Returns the QGCApplication object singleton.
QGCApplication* qgcApp(void)
{
Expand Down
10 changes: 7 additions & 3 deletions src/QGCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ class QGCApplication : public QApplication
/// @brief Validates that the specified location will work for the saved files location.
bool validatePossibleSavedFilesLocation(QString& location);

/// @brief Returns true is all mavlink connections should be logged
/// @return true: Prompt to save log file when vehicle goes away
bool promptFlightDataSave(void);

/// @brief Sets the flag to log all mavlink connections
/// @return true: Prompt to save log file even if vehicle was not armed
bool promptFlightDataSaveNotArmed(void);

void setPromptFlightDataSave(bool promptForSave);
void setPromptFlightDataSaveNotArmed(bool promptForSave);

/// @brief Returns truee if unit test are being run
bool runningUnitTests(void) { return _runningUnitTests; }
Expand Down Expand Up @@ -173,7 +176,8 @@ private slots:
static const char* _settingsVersionKey; ///< Settings key which hold settings version
static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
static const char* _savedFilesLocationKey; ///< Settings key for user visible saved files location
static const char* _promptFlightDataSave; ///< Settings key to prompt for saving Flight Data Log for all flights
static const char* _promptFlightDataSave; ///< Settings key for promptFlightDataSave
static const char* _promptFlightDataSaveNotArmed; ///< Settings key for promptFlightDataSaveNotArmed
static const char* _styleKey; ///< Settings key for UI style

static const char* _defaultSavedFileDirectoryName; ///< Default name for user visible save file directory
Expand Down
48 changes: 48 additions & 0 deletions src/QmlControls/QGroundControlQmlGlobal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,51 @@ void QGroundControlQmlGlobal::stopAllMockLinks(void)
}
#endif
}

void QGroundControlQmlGlobal::setIsDarkStyle(bool dark)
{
qgcApp()->setStyle(dark);
emit isDarkStyleChanged(dark);
}

void QGroundControlQmlGlobal::setIsAudioMuted(bool muted)
{
qgcApp()->toolbox()->audioOutput()->mute(muted);
emit isAudioMutedChanged(muted);
}

void QGroundControlQmlGlobal::setIsLowPowerMode(bool low)
{
MainWindow::instance()->enableLowPowerMode(low);
emit isLowPowerModeChanged(low);
}

void QGroundControlQmlGlobal::setIsSaveLogPrompt(bool prompt)
{
qgcApp()->setPromptFlightDataSave(prompt);
emit isSaveLogPromptChanged(prompt);
}

void QGroundControlQmlGlobal::setIsSaveLogPromptNotArmed(bool prompt)
{
qgcApp()->setPromptFlightDataSaveNotArmed(prompt);
emit isSaveLogPromptNotArmedChanged(prompt);
}

void QGroundControlQmlGlobal::setIsHeartBeatEnabled(bool enable)
{
qgcApp()->toolbox()->mavlinkProtocol()->enableHeartbeats(enable);
emit isHeartBeatEnabledChanged(enable);
}

void QGroundControlQmlGlobal::setIsMultiplexingEnabled(bool enable)
{
qgcApp()->toolbox()->mavlinkProtocol()->enableMultiplexing(enable);
emit isMultiplexingEnabledChanged(enable);
}

void QGroundControlQmlGlobal::setIsVersionCheckEnabled(bool enable)
{
qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable);
emit isVersionCheckEnabledChanged(enable);
}
75 changes: 31 additions & 44 deletions src/QmlControls/QGroundControlQmlGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ class QGroundControlQmlGlobal : public QObject
Q_PROPERTY(qreal zOrderWidgets READ zOrderWidgets CONSTANT) ///< z order value to widgets, for example: zoom controls, hud widgetss
Q_PROPERTY(qreal zOrderMapItems READ zOrderMapItems CONSTANT) ///< z order value for map items, for example: mission item indicators

/// Global "Advance Mode" preference. Certain UI elements and features are different based on this.
Q_PROPERTY(bool isAdvancedMode READ isAdvancedMode CONSTANT)
// Various QGC settings exposed to Qml
Q_PROPERTY(bool isAdvancedMode READ isAdvancedMode CONSTANT) ///< Global "Advance Mode" preference. Certain UI elements and features are different based on this.
Q_PROPERTY(bool isDarkStyle READ isDarkStyle WRITE setIsDarkStyle NOTIFY isDarkStyleChanged) // TODO: Should be in ScreenTools?
Q_PROPERTY(bool isAudioMuted READ isAudioMuted WRITE setIsAudioMuted NOTIFY isAudioMutedChanged)
Q_PROPERTY(bool isLowPowerMode READ isLowPowerMode WRITE setIsLowPowerMode NOTIFY isLowPowerModeChanged)
Q_PROPERTY(bool isSaveLogPrompt READ isSaveLogPrompt WRITE setIsSaveLogPrompt NOTIFY isSaveLogPromptChanged)
Q_PROPERTY(bool isSaveLogPromptNotArmed READ isSaveLogPromptNotArmed WRITE setIsSaveLogPromptNotArmed NOTIFY isSaveLogPromptNotArmedChanged)
Q_PROPERTY(bool isHeartBeatEnabled READ isHeartBeatEnabled WRITE setIsHeartBeatEnabled NOTIFY isHeartBeatEnabledChanged)
Q_PROPERTY(bool isMultiplexingEnabled READ isMultiplexingEnabled WRITE setIsMultiplexingEnabled NOTIFY isMultiplexingEnabledChanged)
Q_PROPERTY(bool isVersionCheckEnabled READ isVersionCheckEnabled WRITE setIsVersionCheckEnabled NOTIFY isVersionCheckEnabledChanged)

Q_INVOKABLE void saveGlobalSetting (const QString& key, const QString& value);
Q_INVOKABLE QString loadGlobalSetting (const QString& key, const QString& defaultValue);
Q_INVOKABLE void saveBoolGlobalSetting (const QString& key, bool value);
Q_INVOKABLE bool loadBoolGlobalSetting (const QString& key, bool defaultValue);

Q_INVOKABLE void deleteAllSettingsNextBoot () { qgcApp()->deleteAllSettingsNextBoot(); }
Q_INVOKABLE void clearDeleteAllSettingsNextBoot () { qgcApp()->clearDeleteAllSettingsNextBoot(); }

Q_INVOKABLE void startPX4MockLink (bool sendStatusText);
Q_INVOKABLE void startGenericMockLink (bool sendStatusText);
Q_INVOKABLE void startAPMArduCopterMockLink (bool sendStatusText);
Expand All @@ -77,57 +88,33 @@ class QGroundControlQmlGlobal : public QObject
qreal zOrderWidgets () { return 100; }
qreal zOrderMapItems () { return 50; }

//-- TODO: This should be in ScreenTools but I don't understand the changes done there (ScreenToolsController versus ScreenTools)
Q_PROPERTY(bool isDarkStyle READ isDarkStyle WRITE setIsDarkStyle NOTIFY isDarkStyleChanged)
bool isDarkStyle () { return qgcApp()->styleIsDark(); }
void setIsDarkStyle (bool dark) { qgcApp()->setStyle(dark); }

//-- Audio Muting
Q_PROPERTY(bool isAudioMuted READ isAudioMuted WRITE setIsAudioMuted NOTIFY isAudioMutedChanged)
bool isAudioMuted () { return qgcApp()->toolbox()->audioOutput()->isMuted(); }
void setIsAudioMuted (bool muted) { qgcApp()->toolbox()->audioOutput()->mute(muted); }

//-- Low power mode
Q_PROPERTY(bool isLowPowerMode READ isLowPowerMode WRITE setIsLowPowerMode NOTIFY isLowPowerModeChanged)
bool isLowPowerMode () { return MainWindow::instance()->lowPowerModeEnabled(); }
void setIsLowPowerMode (bool low) { MainWindow::instance()->enableLowPowerMode(low); }

//-- Prompt save log
Q_PROPERTY(bool isSaveLogPrompt READ isSaveLogPrompt WRITE setIsSaveLogPrompt NOTIFY isSaveLogPromptChanged)
bool isSaveLogPrompt () { return qgcApp()->promptFlightDataSave(); }
void setIsSaveLogPrompt (bool prompt) { qgcApp()->setPromptFlightDataSave(prompt); }

//-- ClearSettings
Q_INVOKABLE void deleteAllSettingsNextBoot () { qgcApp()->deleteAllSettingsNextBoot(); }
Q_INVOKABLE void clearDeleteAllSettingsNextBoot () { qgcApp()->clearDeleteAllSettingsNextBoot(); }
bool isDarkStyle () { return qgcApp()->styleIsDark(); }
bool isAudioMuted () { return qgcApp()->toolbox()->audioOutput()->isMuted(); }
bool isLowPowerMode () { return MainWindow::instance()->lowPowerModeEnabled(); }
bool isSaveLogPrompt () { return qgcApp()->promptFlightDataSave(); }
bool isSaveLogPromptNotArmed () { return qgcApp()->promptFlightDataSaveNotArmed(); }
bool isHeartBeatEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->heartbeatsEnabled(); }
bool isMultiplexingEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->multiplexingEnabled(); }
bool isVersionCheckEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->versionCheckEnabled(); }

//-- TODO: Make this into an actual preference.
bool isAdvancedMode () { return false; }

//
//-- Mavlink Protocol
//

//-- Emit heartbeat
Q_PROPERTY(bool isHeartBeatEnabled READ isHeartBeatEnabled WRITE setIsHeartBeatEnabled NOTIFY isHeartBeatEnabledChanged)
bool isHeartBeatEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->heartbeatsEnabled(); }
void setIsHeartBeatEnabled (bool enable) { qgcApp()->toolbox()->mavlinkProtocol()->enableHeartbeats(enable); }

//-- Multiplexing
Q_PROPERTY(bool isMultiplexingEnabled READ isMultiplexingEnabled WRITE setIsMultiplexingEnabled NOTIFY isMultiplexingEnabledChanged)
bool isMultiplexingEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->multiplexingEnabled(); }
void setIsMultiplexingEnabled(bool enable) { qgcApp()->toolbox()->mavlinkProtocol()->enableMultiplexing(enable); }
bool isAdvancedMode () { return false; }

//-- Version Check
Q_PROPERTY(bool isVersionCheckEnabled READ isVersionCheckEnabled WRITE setIsVersionCheckEnabled NOTIFY isVersionCheckEnabledChanged)
bool isVersionCheckEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->versionCheckEnabled(); }
void setIsVersionCheckEnabled(bool enable) { qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable); }
void setIsDarkStyle (bool dark);
void setIsAudioMuted (bool muted);
void setIsLowPowerMode (bool low);
void setIsSaveLogPrompt (bool prompt);
void setIsSaveLogPromptNotArmed (bool prompt);
void setIsHeartBeatEnabled (bool enable);
void setIsMultiplexingEnabled (bool enable);
void setIsVersionCheckEnabled (bool enable);

signals:
void isDarkStyleChanged (bool dark);
void isAudioMutedChanged (bool muted);
void isLowPowerModeChanged (bool lowPower);
void isSaveLogPromptChanged (bool prompt);
void isSaveLogPromptNotArmedChanged (bool prompt);
void isHeartBeatEnabledChanged (bool enabled);
void isMultiplexingEnabledChanged (bool enabled);
void isVersionCheckEnabledChanged (bool enabled);
Expand Down
16 changes: 10 additions & 6 deletions src/comm/MAVLinkProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ MAVLinkProtocol::MAVLinkProtocol(QGCApplication* app)
#ifndef __mobile__
, _logSuspendError(false)
, _logSuspendReplay(false)
, _logWasArmed(false)
, _logPromptForSave(false)
, _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension))
#endif
, _heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE)
Expand Down Expand Up @@ -343,11 +343,11 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
}

// Check for the vehicle arming going by. This is used to trigger log save.
if (!_logWasArmed && message.msgid == MAVLINK_MSG_ID_HEARTBEAT) {
if (!_logPromptForSave && 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;
_logPromptForSave = true;
}
}
}
Expand Down Expand Up @@ -674,7 +674,11 @@ void MAVLinkProtocol::_startLogging(void)
return;
}

qDebug() << "Temp log" << _tempLogFile.fileName();
if (_app->promptFlightDataSaveNotArmed()) {
_logPromptForSave = true;
}

qDebug() << "Temp log" << _tempLogFile.fileName() << _logPromptForSave;

_logSuspendError = false;
}
Expand All @@ -685,13 +689,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 (_logWasArmed && _app->promptFlightDataSave()) {
if (_logPromptForSave && _app->promptFlightDataSave()) {
emit saveTempFlightDataLog(_tempLogFile.fileName());
} else {
QFile::remove(_tempLogFile.fileName());
}
}
_logWasArmed = false;
_logPromptForSave = false;
}

/// @brief Checks the temp directory for log files which may have been left there.
Expand Down
2 changes: 1 addition & 1 deletion src/comm/MAVLinkProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private 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
bool _logPromptForSave; ///< true: Prompt for log save when appropriate

QGCTemporaryFile _tempLogFile; ///< File to log to
static const char* _tempLogFileTemplate; ///< Template for temporary log file
Expand Down
4 changes: 2 additions & 2 deletions src/ui/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ void MainWindow::_openUrl(const QString& url, const QString& errorMessage)

void MainWindow::showSettings()
{
SettingsDialog settings(qgcApp()->toolbox()->audioOutput(), qgcApp()->toolbox()->flightMapSettings(), this);
SettingsDialog settings(this);
settings.exec();
}

Expand All @@ -619,7 +619,7 @@ void MainWindow::_storeCurrentViewState(void)

void MainWindow::manageLinks()
{
SettingsDialog settings(qgcApp()->toolbox()->audioOutput(), qgcApp()->toolbox()->flightMapSettings(), this, SettingsDialog::ShowCommLinks);
SettingsDialog settings(this, SettingsDialog::ShowCommLinks);
settings.exec();
}

Expand Down
12 changes: 12 additions & 0 deletions src/ui/preferences/GeneralSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Rectangle {
//-----------------------------------------------------------------
//-- Prompt Save Log
QGCCheckBox {
id: promptSaveLog
text: "Prompt to save Flight Data Log after each flight"
checked: QGroundControl.isSaveLogPrompt
visible: !ScreenTools.isMobile
Expand All @@ -94,6 +95,17 @@ Rectangle {
}
}
//-----------------------------------------------------------------
//-- Prompt Save even if not armed
QGCCheckBox {
text: "Prompt to save Flight Data Log even if vehicle was not armed"
checked: QGroundControl.isSaveLogPromptNotArmed
visible: !ScreenTools.isMobile
enabled: promptSaveLog.checked
onClicked: {
QGroundControl.isSaveLogPromptNotArmed = checked
}
}
//-----------------------------------------------------------------
//-- Clear settings
QGCCheckBox {
id: clearCheck
Expand Down

0 comments on commit b03c171

Please sign in to comment.