Skip to content

Commit

Permalink
Telemetry logs are now save with generated file name
Browse files Browse the repository at this point in the history
No more user prompting
  • Loading branch information
DonLakeFlyer committed Mar 11, 2017
1 parent 7c20424 commit 7791f55
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 97 deletions.
108 changes: 71 additions & 37 deletions src/QGCApplication.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/****************************************************************************
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
Expand Down Expand Up @@ -82,19 +82,19 @@
#include "SettingsManager.h"

#ifndef NO_SERIAL_LINK
#include "SerialLink.h"
#include "SerialLink.h"
#endif

#ifndef __mobile__
#include "QGCFileDialog.h"
#include "QGCMessageBox.h"
#include "FirmwareUpgradeController.h"
#include "MainWindow.h"
#include "GeoTagController.h"
#include "QGCFileDialog.h"
#include "QGCMessageBox.h"
#include "FirmwareUpgradeController.h"
#include "MainWindow.h"
#include "GeoTagController.h"
#endif

#ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h"
#include "OpalLink.h"
#endif

#ifdef Q_OS_LINUX
Expand Down Expand Up @@ -162,15 +162,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
#ifdef __mobile__
: QGuiApplication(argc, argv)
, _qmlAppEngine(NULL)
#else
#else
: QApplication(argc, argv)
#endif
#endif
, _runningUnitTests(unitTesting)
, _fakeMobile(false)
, _settingsUpgraded(false)
#ifdef QT_DEBUG
#ifdef QT_DEBUG
, _testHighDPI(false)
#endif
#endif
, _toolbox(NULL)
, _bluetoothAvailable(false)
, _lastKnownHomePosition(37.803784, -122.462276, 0.0)
Expand Down Expand Up @@ -237,9 +237,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
{ "--clear-settings", &fClearSettingsOptions, NULL },
{ "--logging", &logging, &loggingOptions },
{ "--fake-mobile", &_fakeMobile, NULL },
#ifdef QT_DEBUG
#ifdef QT_DEBUG
{ "--test-high-dpi", &_testHighDPI, NULL },
#endif
#endif
// Add additional command line option flags here
};

Expand Down Expand Up @@ -498,33 +498,67 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const
}

#ifndef __mobile__
void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
void QGCApplication::saveTelemetryLogOnMainThread(QString tempLogfile)
{
bool saveError;
do{
saveError = false;
QString saveFilename = QGCFileDialog::getSaveFileName(
MainWindow::instance(),
tr("Save Flight Data Log"),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
tr("Flight Data Log Files (*.mavlink)"),
"mavlink");

if (!saveFilename.isEmpty()) {
// if file exsits already, try to remove it first to overwrite it
if(QFile::exists(saveFilename) && !QFile::remove(saveFilename)){
// if the file cannot be removed, prompt user and ask new path
saveError = true;
QGCMessageBox::warning("File Error","Could not overwrite existing file.\nPlease provide a different file name to save to.");
} else if(!QFile::copy(tempLogfile, saveFilename)) {
// if file could not be copied, prompt user and ask new path
saveError = true;
QGCMessageBox::warning("File Error","Could not create file.\nPlease provide a different file name to save to.");
}
// The vehicle is gone now and we are shutting down so we need to use a message box for errors to hold shutdown and show the error
if (_checkTelemetrySavePath(true /* useMessageBox */)) {

QString saveDirPath = _toolbox->settingsManager()->appSettings()->telemetrySavePath()->rawValue().toString();
QDir saveDir(saveDirPath);

QString nameFormat("%1%2.mavlink");
QString dtFormat("yyyy-MMM-dd hh-mm-ss");

int tryIndex = 1;
QString saveFileName = nameFormat.arg(QDateTime::currentDateTime().toString(dtFormat)).arg("");
while (saveDir.exists(saveFileName)) {
saveFileName = nameFormat.arg(QDateTime::currentDateTime().toString(dtFormat)).arg(QStringLiteral(".%1").arg(tryIndex++));
}
QString saveFilePath = saveDir.absoluteFilePath(saveFileName);

QFile tempFile(tempLogfile);
if (!tempFile.copy(saveFilePath)) {
QGCMessageBox::warning(tr("Telemetry save error"), tr("Unable to save telemetry log. Error copying telemetry to '%1': '%2'.").arg(saveFilePath).arg(tempFile.errorString()));
}
} while(saveError); // if the file could not be overwritten, ask for new file
}

QFile::remove(tempLogfile);
}

void QGCApplication::checkTelemetrySavePathOnMainThread(void)
{
// This is called with an active vehicle so don't pop message boxes which holds ui thread
_checkTelemetrySavePath(false /* useMessageBox */);
}

bool QGCApplication::_checkTelemetrySavePath(bool useMessageBox)
{
QString errorTitle = tr("Telemetry save error");

QString saveDirPath = _toolbox->settingsManager()->appSettings()->telemetrySavePath()->rawValue().toString();
if (saveDirPath.isEmpty()) {
QString error = tr("Unable to save telemetry log. Telemetry save directory is not set.");
if (useMessageBox) {
QGCMessageBox::warning(errorTitle, error);
} else {
showMessage(error);
}
return false;
}

QDir saveDir(saveDirPath);
if (!saveDir.exists()) {
QString error = tr("Unable to save telemetry log. Telemetry save directory \"%1\" does not exist.").arg(saveDirPath);
if (useMessageBox) {
QGCMessageBox::warning(errorTitle, error);
} else {
showMessage(error);
}
return false;
}

return true;
}
#endif

void QGCApplication::_loadCurrentStyleSheet(void)
Expand Down
9 changes: 7 additions & 2 deletions src/QGCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ public slots:
void qmlAttemptWindowClose(void);

#ifndef __mobile__
/// Save the specified Flight Data Log
void saveTempFlightDataLogOnMainThread(QString tempLogfile);
/// Save the specified telemetry Log
void saveTelemetryLogOnMainThread(QString tempLogfile);

/// Check that the telemetry save path is set correctly
void checkTelemetrySavePathOnMainThread(void);
#endif

signals:
Expand Down Expand Up @@ -150,6 +153,8 @@ public slots:
/// Shutdown the application object
void _shutdown(void);

bool _checkTelemetrySavePath(bool useMessageBox);

private slots:
void _missingParamsDisplay(void);

Expand Down
15 changes: 11 additions & 4 deletions src/Settings/App.SettingsGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@
},
{
"name": "PromptFLightDataSave",
"shortDescription": "Prompt to save Flight Data Log after each flight",
"longDescription": "If this option is enabled you will be prompted to save Flight Data Log after each flight completes.",
"shortDescription": "Save telemetry Log after each flight",
"longDescription": "If this option is enabled a telemetry will be saved after each flight completes.",
"type": "bool",
"defaultValue": true
},
{
"name": "PromptFLightDataSaveNotArmed",
"shortDescription": "Prompt to save Flight Data Log even if vehicle was not armed",
"longDescription": "If this option is enabled you will be prompted to save Flight Data Log even if vehicle was never armed.",
"shortDescription": "Save telemetry log even if vehicle was not armed",
"longDescription": "If this option is enabled a telemtry log will be saved even if vehicle was never armed.",
"type": "bool",
"defaultValue": false
},
Expand Down Expand Up @@ -114,5 +114,12 @@
"longDescription": "Show large compass on instrument panel",
"type": "bool",
"defaultValue": false
},
{
"name": "TelemetrySavePath",
"shortDescription": "Telemetry log save directory",
"longDescription": "The directory to which telemetry logs are automatically saved to.",
"type": "string",
"defaultValue": ""
}
]
35 changes: 23 additions & 12 deletions src/Settings/AppSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ const char* AppSettings::offlineEditingHoverSpeedSettingsName = "Offline
const char* AppSettings::batteryPercentRemainingAnnounceSettingsName = "batteryPercentRemainingAnnounce";
const char* AppSettings::defaultMissionItemAltitudeSettingsName = "DefaultMissionItemAltitude";
const char* AppSettings::missionAutoLoadDirSettingsName = "MissionAutoLoadDir";
const char* AppSettings::promptFlightTelemetrySaveName = "PromptFLightDataSave";
const char* AppSettings::promptFlightTelemetrySaveNotArmedName = "PromptFLightDataSaveNotArmed";
const char* AppSettings::telemetrySaveName = "PromptFLightDataSave";
const char* AppSettings::telemetrySaveNotArmedName = "PromptFLightDataSaveNotArmed";
const char* AppSettings::audioMutedName = "AudioMuted";
const char* AppSettings::virtualJoystickName = "VirtualTabletJoystick";
const char* AppSettings::appFontPointSizeName = "BaseDeviceFontPointSize";
const char* AppSettings::indoorPaletteName = "StyleIsDark";
const char* AppSettings::showLargeCompassName = "ShowLargeCompass";
const char* AppSettings::telemetrySavePathName = "TelemetrySavePath";

AppSettings::AppSettings(QObject* parent)
: SettingsGroup(appSettingsGroupName, QString() /* root settings group */, parent)
Expand All @@ -39,13 +40,14 @@ AppSettings::AppSettings(QObject* parent)
, _batteryPercentRemainingAnnounceFact(NULL)
, _defaultMissionItemAltitudeFact(NULL)
, _missionAutoLoadDirFact(NULL)
, _promptFlightTelemetrySaveFact(NULL)
, _promptFlightTelemetrySaveNotArmedFact(NULL)
, _telemetrySaveFact(NULL)
, _telemetrySaveNotArmedFact(NULL)
, _audioMutedFact(NULL)
, _virtualJoystickFact(NULL)
, _appFontPointSizeFact(NULL)
, _indoorPaletteFact(NULL)
, _showLargeCompassFact(NULL)
, _telemetrySavePathFact(NULL)
{
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only");
Expand Down Expand Up @@ -113,22 +115,22 @@ Fact* AppSettings::missionAutoLoadDir(void)
return _missionAutoLoadDirFact;
}

Fact* AppSettings::promptFlightTelemetrySave(void)
Fact* AppSettings::telemetrySave(void)
{
if (!_promptFlightTelemetrySaveFact) {
_promptFlightTelemetrySaveFact = _createSettingsFact(promptFlightTelemetrySaveName);
if (!_telemetrySaveFact) {
_telemetrySaveFact = _createSettingsFact(telemetrySaveName);
}

return _promptFlightTelemetrySaveFact;
return _telemetrySaveFact;
}

Fact* AppSettings::promptFlightTelemetrySaveNotArmed(void)
Fact* AppSettings::telemetrySaveNotArmed(void)
{
if (!_promptFlightTelemetrySaveNotArmedFact) {
_promptFlightTelemetrySaveNotArmedFact = _createSettingsFact(promptFlightTelemetrySaveNotArmedName);
if (!_telemetrySaveNotArmedFact) {
_telemetrySaveNotArmedFact = _createSettingsFact(telemetrySaveNotArmedName);
}

return _promptFlightTelemetrySaveNotArmedFact;
return _telemetrySaveNotArmedFact;
}

Fact* AppSettings::audioMuted(void)
Expand Down Expand Up @@ -183,3 +185,12 @@ Fact* AppSettings::showLargeCompass(void)
return _showLargeCompassFact;
}

Fact* AppSettings::telemetrySavePath(void)
{
if (!_telemetrySavePathFact) {
_telemetrySavePathFact = _createSettingsFact(telemetrySavePathName);
}

return _telemetrySavePathFact;
}

20 changes: 12 additions & 8 deletions src/Settings/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class AppSettings : public SettingsGroup
Q_PROPERTY(Fact* batteryPercentRemainingAnnounce READ batteryPercentRemainingAnnounce CONSTANT)
Q_PROPERTY(Fact* defaultMissionItemAltitude READ defaultMissionItemAltitude CONSTANT)
Q_PROPERTY(Fact* missionAutoLoadDir READ missionAutoLoadDir CONSTANT)
Q_PROPERTY(Fact* promptFlightTelemetrySave READ promptFlightTelemetrySave CONSTANT)
Q_PROPERTY(Fact* promptFlightTelemetrySaveNotArmed READ promptFlightTelemetrySaveNotArmed CONSTANT)
Q_PROPERTY(Fact* telemetrySave READ telemetrySave CONSTANT)
Q_PROPERTY(Fact* telemetrySaveNotArmed READ telemetrySaveNotArmed CONSTANT)
Q_PROPERTY(Fact* audioMuted READ audioMuted CONSTANT)
Q_PROPERTY(Fact* virtualJoystick READ virtualJoystick CONSTANT)
Q_PROPERTY(Fact* appFontPointSize READ appFontPointSize CONSTANT)
Q_PROPERTY(Fact* indoorPalette READ indoorPalette CONSTANT)
Q_PROPERTY(Fact* showLargeCompass READ showLargeCompass CONSTANT)
Q_PROPERTY(Fact* telemetrySavePath READ telemetrySavePath CONSTANT)

Fact* offlineEditingFirmwareType (void);
Fact* offlineEditingVehicleType (void);
Expand All @@ -41,13 +42,14 @@ class AppSettings : public SettingsGroup
Fact* batteryPercentRemainingAnnounce (void);
Fact* defaultMissionItemAltitude (void);
Fact* missionAutoLoadDir (void);
Fact* promptFlightTelemetrySave (void);
Fact* promptFlightTelemetrySaveNotArmed (void);
Fact* telemetrySave (void);
Fact* telemetrySaveNotArmed (void);
Fact* audioMuted (void);
Fact* virtualJoystick (void);
Fact* appFontPointSize (void);
Fact* indoorPalette (void);
Fact* showLargeCompass (void);
Fact* telemetrySavePath (void);

static const char* appSettingsGroupName;

Expand All @@ -58,13 +60,14 @@ class AppSettings : public SettingsGroup
static const char* batteryPercentRemainingAnnounceSettingsName;
static const char* defaultMissionItemAltitudeSettingsName;
static const char* missionAutoLoadDirSettingsName;
static const char* promptFlightTelemetrySaveName;
static const char* promptFlightTelemetrySaveNotArmedName;
static const char* telemetrySaveName;
static const char* telemetrySaveNotArmedName;
static const char* audioMutedName;
static const char* virtualJoystickName;
static const char* appFontPointSizeName;
static const char* indoorPaletteName;
static const char* showLargeCompassName;
static const char* telemetrySavePathName;

private slots:
void _indoorPaletteChanged(void);
Expand All @@ -77,13 +80,14 @@ private slots:
SettingsFact* _batteryPercentRemainingAnnounceFact;
SettingsFact* _defaultMissionItemAltitudeFact;
SettingsFact* _missionAutoLoadDirFact;
SettingsFact* _promptFlightTelemetrySaveFact;
SettingsFact* _promptFlightTelemetrySaveNotArmedFact;
SettingsFact* _telemetrySaveFact;
SettingsFact* _telemetrySaveNotArmedFact;
SettingsFact* _audioMutedFact;
SettingsFact* _virtualJoystickFact;
SettingsFact* _appFontPointSizeFact;
SettingsFact* _indoorPaletteFact;
SettingsFact* _showLargeCompassFact;
SettingsFact* _telemetrySavePathFact;
};

#endif
Loading

0 comments on commit 7791f55

Please sign in to comment.