QGCUASFileManager.h 2.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef QGCUASFILEMANAGER_H
#define QGCUASFILEMANAGER_H

#include <QObject>
#include "UASInterface.h"

class QGCUASFileManager : public QObject
{
    Q_OBJECT
public:
    QGCUASFileManager(QObject* parent, UASInterface* uas);

signals:
Lorenz Meier's avatar
Lorenz Meier committed
14
    void statusMessage(const QString& msg);
15
    void resetStatusMessages();
16 17

public slots:
Lorenz Meier's avatar
Lorenz Meier committed
18
    void receiveMessage(LinkInterface* link, mavlink_message_t message);
19
    void nothingMessage();
Lorenz Meier's avatar
Lorenz Meier committed
20 21
    void listRecursively(const QString &from);
    void downloadPath(const QString& from, const QString& to);
none's avatar
none committed
22
//    void timedOut();
23 24

protected:
Lorenz Meier's avatar
Lorenz Meier committed
25 26 27 28 29 30 31 32 33 34 35
    struct RequestHeader
        {
            uint8_t		magic;
            uint8_t		session;
            uint8_t		opcode;
            uint8_t		size;
            uint32_t	crc32;
            uint32_t	offset;
            uint8_t		data[];
        };

none's avatar
none committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    enum Opcode
        {
            kCmdNone,	// ignored, always acked
            kCmdTerminate,	// releases sessionID, closes file
            kCmdReset,	// terminates all sessions
            kCmdList,	// list files in <path> from <offset>
            kCmdOpen,	// opens <path> for reading, returns <session>
            kCmdRead,	// reads <size> bytes from <offset> in <session>
            kCmdCreate,	// creates <path> for writing, returns <session>
            kCmdWrite,	// appends <size> bytes at <offset> in <session>
            kCmdRemove,	// remove file (only if created by server?)

            kRspAck,
            kRspNak
        };

    enum ErrorCode
        {
            kErrNone,
            kErrNoRequest,
            kErrNoSession,
            kErrSequence,
            kErrNotDir,
            kErrNotFile,
            kErrEOF,
            kErrNotAppend,
            kErrTooBig,
            kErrIO,
            kErrPerm
        };


    enum OperationState
        {
            kCOIdle,    // not doing anything

            kCOList,    // waiting for a List response
        };

    OperationState _current_operation;
    unsigned _retry_counter;

    UASInterface* _mav;
    quint16 _encdata_seq;

    unsigned _session_id;       // session ID for current session
    unsigned _list_offset;      // offset for the current List operation
    QString _list_path;     // path for the current List operation

    void sendTerminate();
    void sendReset();

    void sendList();
    void listDecode(const uint8_t *data, unsigned len);

Lorenz Meier's avatar
Lorenz Meier committed
91
    static quint32 crc32(const uint8_t *src, unsigned len, unsigned state);
92 93 94 95

};

#endif // QGCUASFILEMANAGER_H