|
QGroundControl
Ground Control Station for MAVLink Drones
|
Mock implementation of Mavlink FTP server. More...
#include <MockLinkFTP.h>
Inheritance diagram for MockLinkFTP:
Collaboration diagram for MockLinkFTP:Classes | |
| struct | LogFile |
| Describes a simulated onboard log file served from the @MAV_LOG virtual directory. More... | |
Public Types | |
| enum | ErrorMode_t { errModeNone , errModeNoResponse , errModeNakResponse , errModeNoSecondResponse , errModeNoSecondResponseAllowRetry , errModeNakSecondResponse , errModeBadSequence } |
| By calling setErrorMode with one of these modes you can cause the server to simulate an error. More... | |
Signals | |
| void | terminateCommandReceived () |
| You can connect to this signal to be notified when the server receives a Terminate command. | |
| void | resetCommandReceived () |
| You can connect to this signal to be notified when the server receives a Reset command. | |
Public Member Functions | |
| MockLinkFTP (uint8_t systemIdServer, uint8_t componentIdServer, MockLink *mockLink) | |
| ~MockLinkFTP () | |
| void | setFileList (const QStringList &fileList) |
| void | setLogFiles (const QList< LogFile > &logFiles) |
| QList< LogFile > | logFiles () const |
| Returns the log files served from the @MAV_LOG virtual directory. | |
| QByteArray | logFileContents (const QString &name) const |
| void | setBurstReadDelayMs (int delayMs) |
| void | setParamPckEnabled (bool enabled) |
| When false, OpenFileRO of @PARAM/param.pck NAKs errno ENOENT, as PX4 without the virtual file does. | |
| void | setSingleSessionEnforced (bool enforced) |
| When true, OpenFileRO NAKs kErrNoSessionsAvailable while a read session is already open, as PX4 (single session) does. | |
| void | openStaleSessionForTest () |
| Opens a read session server-side without any client request, simulating a session left behind by a crashed GCS. | |
| void | setIgnoreResetSessions (bool ignore) |
| When true, ResetSessions requests get no reply. | |
| void | setExpireSessionAfterBursts (int burstCount) |
| void | setDropBurstPacketOnce (uint32_t offset) |
| Drops the burst data packet at the given file offset, once, to force a hole the client must fill. | |
| void | setReorderBurstPacketOnce (uint32_t offset) |
| int | openFileROCount () const |
| Number of OpenFileRO requests acked since construction. | |
| int | readFileCount () const |
| Number of ReadFile (non-burst) requests received since construction. | |
| int | lastBurstReadRequestSize () const |
| hdr.size of the most recent BurstReadFile request, -1 if none received yet. | |
| int | lastReadFileRequestSize () const |
| hdr.size of the most recent ReadFile request, -1 if none received yet. | |
| void | mavlinkMessageReceived (const mavlink_message_t &message) |
| Called to handle an FTP message. | |
| void | enableRandomDrops (bool enable) |
| QStringList | uploadedFiles () const |
| Returns the list of remote paths which have been uploaded in this session. | |
| QByteArray | uploadedFileContents (const QString &remotePath) const |
| Returns the contents of an uploaded file. Empty if the path is unknown. | |
| void | clearUploadedFiles () |
| Clears the stored uploaded file contents. | |
| void | setErrorMode (ErrorMode_t errMode) |
| Sets the error mode for command responses. This allows you to simulate various server errors. | |
| void | setListDirectoryWithTimeSupported (bool supported) |
| void | setListDirectoryWithTimeNakError (MavlinkFTP::ErrorCode_t error) |
| void | setLogDirEntriesWithTime (bool enabled) |
| When true, kCmdListDirectoryWithTime directory entries under @MAV_LOG carry "\t0\t<mtime>", as MAVSDK sends. | |
| void | setLogDirDotEntries (bool enabled) |
| When true, @MAV_LOG listings start with "D." and "D.." entries, as ArduPilot sends. | |
Static Public Attributes | |
| static constexpr const ErrorMode_t | rgFailureModes [] |
| static constexpr const size_t | cFailureModes = std::size(MockLinkFTP::rgFailureModes) |
| The number of ErrorModes in the rgFailureModes array. | |
| static constexpr const char * | sizeFilenamePrefix = "mocklink-size-" |
| static constexpr uint32_t | kMockModificationTime = 1700000000 |
Mock implementation of Mavlink FTP server.
Definition at line 17 of file MockLinkFTP.h.
By calling setErrorMode with one of these modes you can cause the server to simulate an error.
Definition at line 101 of file MockLinkFTP.h.
| MockLinkFTP::MockLinkFTP | ( | uint8_t | systemIdServer, |
| uint8_t | componentIdServer, | ||
| MockLink * | mockLink | ||
| ) |
Definition at line 14 of file MockLinkFTP.cc.
| MockLinkFTP::~MockLinkFTP | ( | ) |
Definition at line 23 of file MockLinkFTP.cc.
|
inline |
Clears the stored uploaded file contents.
Definition at line 98 of file MockLinkFTP.h.
|
inline |
Definition at line 89 of file MockLinkFTP.h.
|
inline |
hdr.size of the most recent BurstReadFile request, -1 if none received yet.
Definition at line 81 of file MockLinkFTP.h.
|
inline |
hdr.size of the most recent ReadFile request, -1 if none received yet.
Definition at line 84 of file MockLinkFTP.h.
| QByteArray MockLinkFTP::logFileContents | ( | const QString & | name | ) | const |
Returns the deterministic contents served for the named @MAV_LOG log file. Empty if the name is unknown.
Definition at line 719 of file MockLinkFTP.cc.
|
inline |
Returns the log files served from the @MAV_LOG virtual directory.
Definition at line 41 of file MockLinkFTP.h.
Referenced by setLogFiles().
| void MockLinkFTP::mavlinkMessageReceived | ( | const mavlink_message_t & | message | ) |
Called to handle an FTP message.
Definition at line 528 of file MockLinkFTP.cc.
References errModeNakResponse, errModeNoResponse, MavlinkFTP::kCmdBurstReadFile, MavlinkFTP::kCmdCreateFile, MavlinkFTP::kCmdListDirectory, MavlinkFTP::kCmdListDirectoryWithTime, MavlinkFTP::kCmdNone, MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kCmdOpenFileWO, MavlinkFTP::kCmdReadFile, MavlinkFTP::kCmdRemoveFile, MavlinkFTP::kCmdResetSessions, MavlinkFTP::kCmdTerminateSession, MavlinkFTP::kCmdWriteFile, MavlinkFTP::kErrFail, MavlinkFTP::kErrUnknownCommand, MavlinkFTP::kRspAck, and MockLink::respondWithMavlinkMessage().
|
inline |
Number of OpenFileRO requests acked since construction.
Definition at line 75 of file MockLinkFTP.h.
| void MockLinkFTP::openStaleSessionForTest | ( | ) |
Opens a read session server-side without any client request, simulating a session left behind by a crashed GCS.
Definition at line 453 of file MockLinkFTP.cc.
|
inline |
Number of ReadFile (non-burst) requests received since construction.
Definition at line 78 of file MockLinkFTP.h.
|
signal |
You can connect to this signal to be notified when the server receives a Reset command.
|
inline |
Delays each burst read by delayMs to simulate a slow link. Runs on the MockLink worker thread so it paces transfers without blocking the main thread.
Definition at line 49 of file MockLinkFTP.h.
|
inline |
Drops the burst data packet at the given file offset, once, to force a hole the client must fill.
Definition at line 68 of file MockLinkFTP.h.
|
inline |
Sets the error mode for command responses. This allows you to simulate various server errors.
Definition at line 112 of file MockLinkFTP.h.
|
inline |
Closes the read session server-side once burstCount burst responses have been served, as PX4's idle timer does mid-transfer. Subsequent reads NAK kErrInvalidSession until the client re-opens. One-shot; 0 disables.
Definition at line 65 of file MockLinkFTP.h.
|
inline |
Sets the list of files returned by the List command. Prepend names with F or D to indicate (F)ile or (D)irectory.
Definition at line 27 of file MockLinkFTP.h.
|
inline |
When true, ResetSessions requests get no reply.
Definition at line 61 of file MockLinkFTP.h.
|
inline |
Error code used to Nak kCmdListDirectoryWithTime when unsupported. PX4 replies kErrUnknownCommand, ArduPilot replies kErrFail.
Definition at line 120 of file MockLinkFTP.h.
References error.
|
inline |
Controls whether the server implements the kCmdListDirectoryWithTime command. When false the server Naks it (see setListDirectoryWithTimeNakError) so the client fallback to kCmdListDirectory can be tested.
Definition at line 116 of file MockLinkFTP.h.
|
inline |
When true, @MAV_LOG listings start with "D." and "D.." entries, as ArduPilot sends.
Definition at line 126 of file MockLinkFTP.h.
|
inline |
When true, kCmdListDirectoryWithTime directory entries under @MAV_LOG carry "\t0\t<mtime>", as MAVSDK sends.
Definition at line 123 of file MockLinkFTP.h.
| void MockLinkFTP::setLogFiles | ( | const QList< LogFile > & | logFiles | ) |
Sets the log files listed in and downloadable from the @MAV_LOG virtual directory. Removes any temp files cached for the previous log set.
Definition at line 739 of file MockLinkFTP.cc.
References logFiles().
|
inline |
When false, OpenFileRO of @PARAM/param.pck NAKs errno ENOENT, as PX4 without the virtual file does.
Definition at line 52 of file MockLinkFTP.h.
|
inline |
Sends the burst data packet at the given file offset after the rest of its burst, once, keeping its original sequence number, as a late packet from an earlier burst arrives on a real link.
Definition at line 72 of file MockLinkFTP.h.
|
inline |
When true, OpenFileRO NAKs kErrNoSessionsAvailable while a read session is already open, as PX4 (single session) does.
Definition at line 55 of file MockLinkFTP.h.
|
signal |
You can connect to this signal to be notified when the server receives a Terminate command.
|
inline |
Returns the contents of an uploaded file. Empty if the path is unknown.
Definition at line 95 of file MockLinkFTP.h.
|
inline |
Returns the list of remote paths which have been uploaded in this session.
Definition at line 92 of file MockLinkFTP.h.
|
staticconstexpr |
The number of ErrorModes in the rgFailureModes array.
Definition at line 140 of file MockLinkFTP.h.
|
staticconstexpr |
Base modification time (seconds since UNIX epoch UTC) reported by the kCmdListDirectoryWithTime mock listing. Entry N reports kMockModificationTime + N.
Definition at line 146 of file MockLinkFTP.h.
|
staticconstexpr |
Array of failure modes you can cycle through for testing. By looping through this array you can avoid hardcoding the specific error modes in your unit test. This way when new error modes are added your unit test code may not need to be modified.
Definition at line 131 of file MockLinkFTP.h.
|
staticconstexpr |
Definition at line 142 of file MockLinkFTP.h.