QGCMAVLinkLogPlayer.h 2.52 KB
Newer Older
1 2 3 4 5 6 7
#ifndef QGCMAVLINKLOGPLAYER_H
#define QGCMAVLINKLOGPLAYER_H

#include <QWidget>
#include <QFile>

#include "MAVLinkProtocol.h"
8
#include "LinkInterface.h"
9
#include "MAVLinkSimulationLink.h"
10

11 12 13
namespace Ui
{
class QGCMAVLinkLogPlayer;
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
}

/**
 * @brief Replays MAVLink log files
 *
 * This class allows to replay MAVLink logs at varying speeds.
 * captured flights can be replayed, shown to others and analyzed
 * in-depth later on.
 */
class QGCMAVLinkLogPlayer : public QWidget
{
    Q_OBJECT

public:
    explicit QGCMAVLinkLogPlayer(MAVLinkProtocol* mavlink, QWidget *parent = 0);
    ~QGCMAVLinkLogPlayer();
30 31 32 33 34 35 36 37 38
    bool isPlayingLogFile()
    {
        return isPlaying;
    }

    bool isLogFileSelected()
    {
        return logFile.isOpen();
    }
39

40 41 42 43 44 45 46 47
    /**
     * @brief Set the last log file name
     * @param filename
     */
    void setLastLogFile(const QString& filename) {
        lastLogDirectory = filename;
    }

48
public slots:
lm's avatar
lm committed
49 50 51 52
    /** @brief Toggle between play and pause */
    void playPauseToggle();
    /** @brief Play / pause the log */
    void playPause(bool play);
53 54 55 56
    /** @brief Replay the logfile */
    void play();
    /** @brief Pause the logfile */
    void pause();
57
    /** @brief Reset the logfile */
58
    bool reset(int packetIndex=0);
59
    /** @brief Select logfile */
60
    bool selectLogFile(const QString startDirectory);
Lorenz Meier's avatar
Lorenz Meier committed
61 62
    /** @brief Select logfile */
    bool selectLogFile();
63
    /** @brief Load log file */
64
    bool loadLogFile(const QString& file);
65 66
    /** @brief Jump to a position in the logfile */
    void jumpToSliderVal(int slidervalue);
67 68 69 70
    /** @brief The logging mainloop */
    void logLoop();
    /** @brief Set acceleration factor in percent */
    void setAccelerationFactorInt(int factor);
71

72 73 74 75
signals:
    /** @brief Send ready bytes */
    void bytesReady(LinkInterface* link, const QByteArray& bytes);

76 77 78 79 80
protected:
    int lineCounter;
    int totalLines;
    quint64 startTime;
    quint64 endTime;
81 82
    quint64 currentStartTime;
    float accelerationFactor;
83
    MAVLinkProtocol* mavlink;
84
    MAVLinkSimulationLink* logLink;
85 86
    QFile logFile;
    QTimer loopTimer;
87
    int loopCounter;
88 89
    bool mavlinkLogFormat;
    int binaryBaudRate;
lm's avatar
lm committed
90
    bool isPlaying;
91
    unsigned int currPacketCount;
92 93
    static const int packetLen = MAVLINK_MAX_PACKET_LEN;
    static const int timeLen = sizeof(quint64);
Lorenz Meier's avatar
Lorenz Meier committed
94
    QString lastLogDirectory;
95 96
    void changeEvent(QEvent *e);

Lorenz Meier's avatar
Lorenz Meier committed
97 98 99
    void loadSettings();
    void storeSettings();

100 101
private:
    Ui::QGCMAVLinkLogPlayer *ui;
102
	virtual void paintEvent(QPaintEvent *);
103 104 105
};

#endif // QGCMAVLINKLOGPLAYER_H