30 #include "ui_flightlogdownload.h"
36 #include "loggingstats.h"
40 #include <QFileDialog>
53 loggingStats = LoggingStats::GetInstance(uavoManager);
54 Q_ASSERT(loggingStats);
56 connect(ui->fileNameButton, SIGNAL(clicked()),
this, SLOT(getFilename()));
57 connect(ui->saveButton, SIGNAL(clicked()),
this, SLOT(startDownload()));
61 tr(
"dRonin-%0.drlog").arg(QDateTime::currentDateTime().toString(
"yyyy-MM-dd_hh-mm-ss"));
62 ui->fileName->setText(QDir::current().relativeFilePath(fileName));
65 connect(loggingStats, SIGNAL(objectUnpacked(
UAVObject *)),
this, SLOT(updateReceived()));
66 loggingStats->requestUpdate();
75 void FlightLogDownload::getFilename()
77 QString fileName = QFileDialog::getSaveFileName(
78 this, tr(
"Save log as..."),
79 tr(
"dRonin-%0.drlog").arg(QDateTime::currentDateTime().toString(
"yyyy-MM-dd_hh-mm-ss")),
81 if (!fileName.isEmpty())
82 ui->fileName->setText(fileName);
90 void FlightLogDownload::updateReceived()
92 LoggingStats::DataFields logging = loggingStats->getData();
97 ui->cbFileId->clear();
98 for (
int i = logging.MinFileId;
i <= logging.MaxFileId;
i++)
99 ui->cbFileId->addItem(QString::number(
i), QVariant(
i));
107 UAVObject::Metadata mdata;
109 switch (logging.Operation) {
110 case LoggingStats::OPERATION_IDLE:
111 log.append(reinterpret_cast<char *>(logging.FileSector), LoggingStats::FILESECTOR_NUMELEM);
112 logging.Operation = LoggingStats::OPERATION_DOWNLOAD;
113 logging.FileSectorNum++;
114 loggingStats->setData(logging);
115 loggingStats->updated();
116 ui->sectorLabel->setText(QString::number(logging.FileSectorNum));
117 qDebug() <<
"Requesting sector num: " << logging.FileSectorNum;
119 ui->lb_operationStatus->setText(
"Downloading...");
121 case LoggingStats::OPERATION_COMPLETE: {
122 log.append(reinterpret_cast<char *>(logging.FileSector), LoggingStats::FILESECTOR_NUMELEM);
126 mdata = loggingStats->getMetadata();
128 loggingStats->setMetadata(mdata);
133 ui->lb_operationStatus->setText(
"Download complete.");
136 case LoggingStats::OPERATION_ERROR:
139 mdata = loggingStats->getMetadata();
141 loggingStats->setMetadata(mdata);
143 ui->lb_operationStatus->setText(
"Download error.");
146 qDebug() <<
"Unhandled";
155 void FlightLogDownload::startDownload()
158 qint32 file_id = ui->cbFileId->currentData().toInt(&ok);
162 logFile =
new QFile(ui->fileName->text(),
this);
163 if (!logFile->open(QIODevice::WriteOnly))
168 LoggingStats::DataFields logging = loggingStats->getData();
172 logging.Operation = LoggingStats::OPERATION_IDLE;
173 loggingStats->setData(logging);
174 loggingStats->updated();
176 UAVObject::Metadata mdata = loggingStats->getMetadata();
178 loggingStats->setMetadata(mdata);
180 qDebug() <<
"Download file id: " << file_id;
181 dl_state = DL_DOWNLOADING;
182 logging.Operation = LoggingStats::OPERATION_DOWNLOAD;
183 logging.FileRequest = file_id;
184 logging.FileSectorNum = 0;
185 loggingStats->setData(logging);
186 loggingStats->updated();
FlightLogDownload(QWidget *parent=nullptr)
Core plugin system that manages the plugins, their life cycle and their registered objects...
static void SetFlightTelemetryUpdateMode(Metadata &meta, UpdateMode val)