38 #include <QStringList>
40 #include <QFileDialog>
42 #include <QErrorMessage>
43 #include <QMainWindow>
44 #include <QWriteLocker>
47 #include <QKeySequence>
55 logDevice.
setName(
"Logfile replay...");
68 list.append(&logDevice);
76 if (logFile.isOpen()) {
80 QString fileName = QFileDialog::getOpenFileName(
82 QString(
""), tr(
"dRonin Log Files (*.drlog *.tll)"));
84 if (!fileName.isNull()) {
94 if (logFile.
open(QIODevice::ReadOnly)) {
95 qDebug() <<
"Replaying " <<
file;
103 Q_UNUSED(deviceName);
105 if (logFile.isOpen()) {
113 return QString(
"Logfile replay");
118 return QString(
"Logfile");
142 connect(parent, SIGNAL(stopLoggingSignal()),
this, SLOT(
stopLogging()));
153 void LoggingThread::objectUpdated(
UAVObject *obj)
155 QWriteLocker locker(&
lock);
157 qDebug() <<
"Error logging " << obj->
getName();
170 QVector<QVector<UAVObject *>>::const_iterator
i;
171 QVector<UAVObject *>::const_iterator j;
174 const QVector<QVector<UAVObject *>>::iterator iEnd = list.end();
175 for (i = list.constBegin(); i != iEnd; ++
i) {
176 QVector<UAVObject *>::const_iterator jEnd = (*i).constEnd();
177 for (j = (*i).constBegin(); j != jEnd; ++j) {
184 GCSTelemetryStats *gcsStatsObj = GCSTelemetryStats::GetInstance(objManager);
185 GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
186 if (gcsStats.Status == GCSTelemetryStats::STATUS_CONNECTED) {
187 qDebug() <<
"Logging: connected already, ask for all settings";
190 qDebug() <<
"Logging: not connected, do no ask for settings";
201 QWriteLocker locker(&
lock);
208 QVector<QVector<UAVObject *>>::const_iterator
i;
209 QVector<UAVObject *>::const_iterator j;
211 const QVector<QVector<UAVObject *>>::iterator iEnd = list.end();
212 for (i = list.constBegin(); i != iEnd; ++
i) {
213 QVector<UAVObject *>::const_iterator jEnd = (*i).constEnd();
214 for (j = (*i).constBegin(); j != jEnd; ++j) {
221 qDebug() <<
"File closed";
228 void LoggingThread::retrieveSettings()
238 for (
int n = 0;
n < objs.size(); ++
n) {
245 qDebug() << tr(
"Logging: retrieve settings objects from the autopilot (%1 objects)")
246 .arg(queue.length());
247 retrieveNextObject();
253 void LoggingThread::retrieveNextObject()
256 if (queue.isEmpty()) {
257 qDebug() <<
"Logging: Object retrieval completed";
263 connect(obj, SIGNAL(transactionCompleted(
UAVObject *,
bool)),
this,
264 SLOT(transactionCompleted(
UAVObject *,
bool)));
272 void LoggingThread::transactionCompleted(
UAVObject *obj,
bool success)
276 obj->disconnect(
this);
281 GCSTelemetryStats *gcsStatsObj = GCSTelemetryStats::GetInstance(objManager);
282 GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
283 if (gcsStats.Status == GCSTelemetryStats::STATUS_CONNECTED) {
284 retrieveNextObject();
286 qDebug() <<
"Logging: Object retrieval has been cancelled";
295 LoggingPlugin::LoggingPlugin()
301 LoggingPlugin::~LoggingPlugin()
313 bool LoggingPlugin::initialize(
const QStringList &args, QString *errMsg)
325 cmdLogging = am->
registerAction(
new QAction(
this),
"LoggingPlugin.Logging",
328 cmdLogging->
action()->setText(
"Start logging...");
330 ac->
menu()->addSeparator();
334 connect(cmdLogging->
action(), SIGNAL(triggered(
bool)),
this, SLOT(toggleLogging()));
337 cmdDownload = am->
registerAction(
new QAction(
this),
"LoggingPlugin.Download",
340 cmdDownload->action()->setText(
"Download log...");
342 connect(cmdDownload->action(), SIGNAL(triggered(
bool)),
this, SLOT(downloadLog()));
348 connect(getLogfile(), SIGNAL(replayFinished()),
this, SLOT(replayStopped()));
349 connect(getLogfile(), SIGNAL(replayStarted()),
this, SLOT(replayStarted()));
354 void LoggingPlugin::downloadLog()
364 void LoggingPlugin::toggleLogging()
368 QString fileName = QFileDialog::getSaveFileName(
370 QDir::homePath() + QDir::separator()
371 + tr(
"dRonin-%0.drlog")
372 .arg(QDateTime::currentDateTime().toString(
"yyyy-MM-dd_hh-mm-ss")),
373 tr(
"dRonin Log (*.drlog)"));
375 if (fileName.isEmpty())
378 startLogging(fileName);
379 cmdLogging->
action()->setText(tr(
"Stop logging"));
383 cmdLogging->
action()->setText(tr(
"Start logging..."));
390 void LoggingPlugin::startLogging(QString
file)
392 qDebug() <<
"Logging to " <<
file;
398 connect(
loggingThread, SIGNAL(finished()),
this, SLOT(loggingStopped()));
404 err.showMessage(
"Unable to open file for logging");
412 void LoggingPlugin::stopLogging()
422 void LoggingPlugin::loggingStopped()
436 void LoggingPlugin::replayStopped()
445 void LoggingPlugin::replayStarted()
451 void LoggingPlugin::extensionsInitialized()
456 void LoggingPlugin::shutdown()
void availableDevChanged(IConnection *)
~LoggingThread()
LoggingThread::~LoggingThread Destructor.
virtual QList< Core::IDevice * > availableDevices()
virtual QIODevice * openDevice(Core::IDevice *deviceName)
void stateChanged(QString)
virtual QAction * action() const =0
void setName(QString theName)
virtual Command * registerAction(QAction *action, const QString &id, const QList< int > &context)=0
Makes an action known to the system under the specified string id.
const char *const M_TOOLS
virtual ActionContainer * actionContainer(const QString &id) const =0
Returns the IActionContainter object that is know to the system under the given string id...
LoggingThread * loggingThread
QVector< QVector< UAVObject * > > getObjectsVector()
Core plugin system that manages the plugins, their life cycle and their registered objects...
void startReplay(QString file)
virtual ActionManager * actionManager() const =0
Returns the application's action manager.
bool sendObject(UAVObject *obj, bool acked, bool allInstances)
virtual QString shortName()
enum LoggingPlugin::@8 state
virtual QMenu * menu() const =0
void setDisplayName(QString dn)
virtual void closeDevice(const QString &deviceName)
static ICore * instance()
virtual void appendGroup(const QString &group)=0
virtual void addAction(Core::Command *action, const QString &group=QString())=0
void stopLoggingSignal(void)
void setFileName(QString name)
LoggingConnection * logConnection
virtual void setDefaultKeySequence(const QKeySequence &key)=0
virtual QString connectionName()
virtual ~LoggingConnection()
void onEnumerationChanged()
The action manager is responsible for registration of menus and menu items and keyboard shortcuts...
bool openFile(QString file, LoggingPlugin *parent)
void addAutoReleasedObject(QObject *obj)
QVector< QVector< UAVDataObject * > > getDataObjectsVector()