MockMavlinkFileServer.h 2.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

#ifndef MOCKMAVLINKFILESERVER_H
#define MOCKMAVLINKFILESERVER_H

#include "MockMavlinkInterface.h"
Don Gagne's avatar
Don Gagne committed
28 29
#include "QGCUASFileManager.h"

30 31 32 33 34
/// @file
///     @brief Mock implementation of Mavlink FTP server. Used as mavlink plugin to MockUAS.
///             Only root directory access is supported.
///
///     @author Don Gagne <don@thegagnes.com>
Don Gagne's avatar
Don Gagne committed
35 36

#include <QStringList>
37 38 39 40 41 42

class MockMavlinkFileServer : public MockMavlinkInterface
{
    Q_OBJECT
    
public:
43
    MockMavlinkFileServer(void);
44
    
45 46
    /// @brief Sets the list of files returned by the List command. Prepend names with F or D
    /// to indicate (F)ile or (D)irectory.
Don Gagne's avatar
Don Gagne committed
47
    void setFileList(QStringList& fileList) { _fileList = fileList; }
48
    
Don Gagne's avatar
Don Gagne committed
49 50
    // From MockMavlinkInterface
    virtual void sendMessage(mavlink_message_t message);
51
    
52 53 54 55 56 57 58 59 60 61
    struct FileTestCase {
        const char* filename;
        uint8_t     length;
    };
    
    static const size_t cFileTestCases = 3;
    static const FileTestCase rgFileTestCases[cFileTestCases];
    
signals:
    void terminateCommandReceived(void);
62
    
Don Gagne's avatar
Don Gagne committed
63
private:
64
    void _sendAck(void);
Don Gagne's avatar
Don Gagne committed
65 66
    void _sendNak(QGCUASFileManager::ErrorCode error);
    void _emitResponse(QGCUASFileManager::Request* request);
67 68 69
    void _listCommand(QGCUASFileManager::Request* request);
    void _openCommand(QGCUASFileManager::Request* request);
    void _readCommand(QGCUASFileManager::Request* request);
70
    void _terminateCommand(QGCUASFileManager::Request* request);
71 72
    
    QStringList _fileList;  ///< List of files returned by List command
73
    
74 75
    static const uint8_t    _sessionId;
    uint8_t                 _readFileLength; ///< Length of active file being read
76 77 78
};

#endif