Commit 1daf1e79 authored by Willian Galvani's avatar Willian Galvani

Add checkbox for saving CSVs

parent eaf48fe3
...@@ -263,5 +263,12 @@ ...@@ -263,5 +263,12 @@
"longDescription": "Use Link Pairing.", "longDescription": "Use Link Pairing.",
"type": "bool", "type": "bool",
"defaultValue": false "defaultValue": false
},
{
"name": "saveCsvTelemetry",
"shortDescription": "Save CSV Telementry Logs",
"longDescription": "If this option is enabled, all Facts will be written to a CSV file with a 1 Hertz frequency.",
"type": "bool",
"defaultValue": false
} }
] ]
...@@ -97,6 +97,7 @@ DECLARE_SETTINGSFACT(AppSettings, enableMicrohard) ...@@ -97,6 +97,7 @@ DECLARE_SETTINGSFACT(AppSettings, enableMicrohard)
DECLARE_SETTINGSFACT(AppSettings, language) DECLARE_SETTINGSFACT(AppSettings, language)
DECLARE_SETTINGSFACT(AppSettings, disableAllPersistence) DECLARE_SETTINGSFACT(AppSettings, disableAllPersistence)
DECLARE_SETTINGSFACT(AppSettings, usePairing) DECLARE_SETTINGSFACT(AppSettings, usePairing)
DECLARE_SETTINGSFACT(AppSettings, saveCsvTelemetry)
DECLARE_SETTINGSFACT_NO_FUNC(AppSettings, indoorPalette) DECLARE_SETTINGSFACT_NO_FUNC(AppSettings, indoorPalette)
{ {
......
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
DEFINE_SETTINGFACT(language) DEFINE_SETTINGFACT(language)
DEFINE_SETTINGFACT(disableAllPersistence) DEFINE_SETTINGFACT(disableAllPersistence)
DEFINE_SETTINGFACT(usePairing) DEFINE_SETTINGFACT(usePairing)
DEFINE_SETTINGFACT(saveCsvTelemetry)
// Although this is a global setting it only affects ArduPilot vehicle since PX4 automatically starts the stream from the vehicle side // Although this is a global setting it only affects ArduPilot vehicle since PX4 automatically starts the stream from the vehicle side
DEFINE_SETTINGFACT(apmStartMavlinkStreams) DEFINE_SETTINGFACT(apmStartMavlinkStreams)
......
...@@ -303,7 +303,10 @@ Vehicle::Vehicle(LinkInterface* link, ...@@ -303,7 +303,10 @@ Vehicle::Vehicle(LinkInterface* link,
connect(&_adsbTimer, &QTimer::timeout, this, &Vehicle::_adsbTimerTimeout); connect(&_adsbTimer, &QTimer::timeout, this, &Vehicle::_adsbTimerTimeout);
_adsbTimer.setSingleShot(false); _adsbTimer.setSingleShot(false);
_adsbTimer.start(1000); _adsbTimer.start(1000);
_initializeCsv();
// Start csv logger
connect(&_csvLogTimer, &QTimer::timeout, this, &Vehicle::_writeCsvLine);
_csvLogTimer.start(1000);
} }
// Disconnected Vehicle for offline editing // Disconnected Vehicle for offline editing
...@@ -4010,6 +4013,9 @@ void Vehicle::_pidTuningAdjustRates(bool setRatesForTuning) ...@@ -4010,6 +4013,9 @@ void Vehicle::_pidTuningAdjustRates(bool setRatesForTuning)
void Vehicle::_initializeCsv() void Vehicle::_initializeCsv()
{ {
if(!_toolbox->settingsManager()->appSettings()->saveCsvTelemetry()->rawValue().toBool()){
return;
}
QString now = QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss"); QString now = QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss");
QString fileName = QString("%1 vehicle%2.csv").arg(now).arg(_id); QString fileName = QString("%1 vehicle%2.csv").arg(now).arg(_id);
QDir saveDir(_toolbox->settingsManager()->appSettings()->telemetrySavePath()); QDir saveDir(_toolbox->settingsManager()->appSettings()->telemetrySavePath());
...@@ -4030,13 +4036,20 @@ void Vehicle::_initializeCsv() ...@@ -4030,13 +4036,20 @@ void Vehicle::_initializeCsv()
} }
qCDebug(VehicleLog) << "Facts logged to csv:" << allFactNames; qCDebug(VehicleLog) << "Facts logged to csv:" << allFactNames;
stream << "Timestamp," << allFactNames.join(",") << "\n"; stream << "Timestamp," << allFactNames.join(",") << "\n";
connect(&_csvLogTimer, &QTimer::timeout, this, &Vehicle::_writeCsvLine);
_csvLogTimer.start(1000);
} }
void Vehicle::_writeCsvLine() void Vehicle::_writeCsvLine()
{ {
// Only save the logs after the the vehicle gets armed, unless "Save logs even if vehicle was not armed" is checked
if(!_csvLogFile.isOpen() &&
(_armed || _toolbox->settingsManager()->appSettings()->telemetrySaveNotArmed()->rawValue().toBool())){
_initializeCsv();
}
if(!_csvLogFile.isOpen()){
return;
}
QStringList allFactValues; QStringList allFactValues;
QTextStream stream(&_csvLogFile); QTextStream stream(&_csvLogFile);
......
...@@ -420,6 +420,14 @@ Rectangle { ...@@ -420,6 +420,14 @@ Rectangle {
enabled: promptSaveLog.checked && !disableDataPersistence.checked enabled: promptSaveLog.checked && !disableDataPersistence.checked
property Fact _telemetrySaveNotArmed: QGroundControl.settingsManager.appSettings.telemetrySaveNotArmed property Fact _telemetrySaveNotArmed: QGroundControl.settingsManager.appSettings.telemetrySaveNotArmed
} }
FactCheckBox {
id: promptSaveCsv
text: qsTr("Save CSV log of telemetry data")
fact: _saveCsvTelemetry
visible: _saveCsvTelemetry.visible
enabled: !disableDataPersistence.checked
property Fact _saveCsvTelemetry: QGroundControl.settingsManager.appSettings.saveCsvTelemetry
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment