QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MockLinkFTP.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QByteArray>
4#include <QtCore/QFile>
5#include <QtCore/QHash>
6#include <QtCore/QLoggingCategory>
7#include <QtCore/QObject>
8#include <QtCore/QStringList>
9
10#include "MAVLinkFTP.h"
11
12Q_DECLARE_LOGGING_CATEGORY(MockLinkFTPLog)
13
14class MockLink;
15
17class MockLinkFTP : public QObject
18{
19 Q_OBJECT
20
21public:
22 MockLinkFTP(uint8_t systemIdServer, uint8_t componentIdServer, MockLink *mockLink);
24
27 void setFileList(const QStringList &fileList) { _fileList = fileList; }
28
30 void mavlinkMessageReceived(const mavlink_message_t &message);
31
32 void enableRandomDrops(bool enable) { _randomDropsEnabled = enable; }
33 void enableBinParamFile(bool enable) { _BinParamFileEnabled = enable; }
34
36 QStringList uploadedFiles() const { return _uploadedFiles.keys(); }
37
39 QByteArray uploadedFileContents(const QString& remotePath) const { return _uploadedFiles.value(remotePath); }
40
42 void clearUploadedFiles() { _uploadedFiles.clear(); }
43
54
56 void setErrorMode(ErrorMode_t errMode) { _errMode = errMode; };
57
68
70 static constexpr const size_t cFailureModes = std::size(MockLinkFTP::rgFailureModes);
71
72 static constexpr const char *sizeFilenamePrefix = "mocklink-size-";
73
74signals:
77
80
81private:
83 void _sendAck(uint8_t targetSystemId, uint8_t targetComponentId, uint16_t seqNumber, MavlinkFTP::OpCode_t reqOpCode);
84 void _sendNak(uint8_t targetSystemId, uint8_t targetComponentId, MavlinkFTP::ErrorCode_t error, uint16_t seqNumber, MavlinkFTP::OpCode_t reqOpCode);
85 void _sendNakErrno(uint8_t targetSystemId, uint8_t targetComponentId, uint8_t nakErrno, uint16_t seqNumber, MavlinkFTP::OpCode_t reqOpCode);
87 void _sendResponse(uint8_t targetSystemId, uint8_t targetComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
90 void _listCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
91 void _openCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
92 void _createFileCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
93 void _openFileWOCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
94 void _readCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
95 void _burstReadCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
96 void _terminateCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
97 void _resetCommand(uint8_t senderSystemId, uint8_t senderComponentId, uint16_t seqNumber);
98 void _writeCommand(uint8_t senderSystemId, uint8_t senderComponentId, MavlinkFTP::Request *request, uint16_t seqNumber);
99 void _finalizeActiveUpload();
102 uint16_t _nextSeqNumber(uint16_t seqNumber) const;
103 static QString _createTestTempFile(int size);
104
106 static void ensureNullTemination(MavlinkFTP::Request *request);
107
108 const uint8_t _systemIdServer;
109 const uint8_t _componentIdServer;
110 MockLink *_mockLink;
111
112 bool _BinParamFileEnabled = false;
113 bool _lastReplyValid = false;
114 bool _randomDropsEnabled = false;
115 ErrorMode_t _errMode = errModeNone;
116 mavlink_message_t _lastReply{};
117 QFile _currentFile;
118 struct UploadSession {
119 bool active = false;
120 QString remotePath;
121 QByteArray buffer;
122
123 void reset() {
124 active = false;
125 remotePath.clear();
126 buffer.clear();
127 }
128 };
129 UploadSession _uploadSession;
130 QHash<QString, QByteArray> _uploadedFiles;
131 QStringList _fileList;
132 uint16_t _lastReplySequence = 0;
133
134 static constexpr uint8_t _sessionId = 1;
135};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
Error error
struct __mavlink_message mavlink_message_t
ErrorCode_t
Error codes returned in Nak response PayloadHeader.data[0].
Definition MAVLinkFTP.h:65
Mock implementation of Mavlink FTP server.
Definition MockLinkFTP.h:18
void enableRandomDrops(bool enable)
Definition MockLinkFTP.h:32
void resetCommandReceived()
You can connect to this signal to be notified when the server receives a Reset command.
void setFileList(const QStringList &fileList)
Definition MockLinkFTP.h:27
void enableBinParamFile(bool enable)
Definition MockLinkFTP.h:33
void terminateCommandReceived()
You can connect to this signal to be notified when the server receives a Terminate command.
static constexpr const char * sizeFilenamePrefix
Definition MockLinkFTP.h:72
void mavlinkMessageReceived(const mavlink_message_t &message)
Called to handle an FTP message.
static constexpr const ErrorMode_t rgFailureModes[]
Definition MockLinkFTP.h:61
ErrorMode_t
By calling setErrorMode with one of these modes you can cause the server to simulate an error.
Definition MockLinkFTP.h:45
@ errModeBadSequence
Return response with bad sequence number.
Definition MockLinkFTP.h:52
@ errModeNoSecondResponseAllowRetry
No response to subsequent request to initial command, error will be cleared after this so retry will ...
Definition MockLinkFTP.h:50
@ errModeNakSecondResponse
Nak subsequent request to initial command.
Definition MockLinkFTP.h:51
@ errModeNoResponse
No response to any request, client should eventually time out with no Ack.
Definition MockLinkFTP.h:47
@ errModeNone
No error, respond correctly.
Definition MockLinkFTP.h:46
@ errModeNoSecondResponse
No response to subsequent request to initial command.
Definition MockLinkFTP.h:49
@ errModeNakResponse
Nak all requests.
Definition MockLinkFTP.h:48
QStringList uploadedFiles() const
Returns the list of remote paths which have been uploaded in this session.
Definition MockLinkFTP.h:36
static constexpr const size_t cFailureModes
The number of ErrorModes in the rgFailureModes array.
Definition MockLinkFTP.h:70
void clearUploadedFiles()
Clears the stored uploaded file contents.
Definition MockLinkFTP.h:42
void setErrorMode(ErrorMode_t errMode)
Sets the error mode for command responses. This allows you to simulate various server errors.
Definition MockLinkFTP.h:56
QByteArray uploadedFileContents(const QString &remotePath) const
Returns the contents of an uploaded file. Empty if the path is unknown.
Definition MockLinkFTP.h:39