QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MockLinkFTP Class Reference

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
 

Detailed Description

Mock implementation of Mavlink FTP server.

Definition at line 17 of file MockLinkFTP.h.

Member Enumeration Documentation

◆ ErrorMode_t

By calling setErrorMode with one of these modes you can cause the server to simulate an error.

Enumerator
errModeNone 

No error, respond correctly.

errModeNoResponse 

No response to any request, client should eventually time out with no Ack.

errModeNakResponse 

Nak all requests.

errModeNoSecondResponse 

No response to subsequent request to initial command.

errModeNoSecondResponseAllowRetry 

No response to subsequent request to initial command, error will be cleared after this so retry will succeed.

errModeNakSecondResponse 

Nak subsequent request to initial command.

errModeBadSequence 

Return response with bad sequence number.

Definition at line 101 of file MockLinkFTP.h.

Constructor & Destructor Documentation

◆ MockLinkFTP()

MockLinkFTP::MockLinkFTP ( uint8_t  systemIdServer,
uint8_t  componentIdServer,
MockLink *  mockLink 
)

Definition at line 14 of file MockLinkFTP.cc.

◆ ~MockLinkFTP()

MockLinkFTP::~MockLinkFTP ( )

Definition at line 23 of file MockLinkFTP.cc.

Member Function Documentation

◆ clearUploadedFiles()

void MockLinkFTP::clearUploadedFiles ( )
inline

Clears the stored uploaded file contents.

Definition at line 98 of file MockLinkFTP.h.

◆ enableRandomDrops()

void MockLinkFTP::enableRandomDrops ( bool  enable)
inline

Definition at line 89 of file MockLinkFTP.h.

◆ lastBurstReadRequestSize()

int MockLinkFTP::lastBurstReadRequestSize ( ) const
inline

hdr.size of the most recent BurstReadFile request, -1 if none received yet.

Definition at line 81 of file MockLinkFTP.h.

◆ lastReadFileRequestSize()

int MockLinkFTP::lastReadFileRequestSize ( ) const
inline

hdr.size of the most recent ReadFile request, -1 if none received yet.

Definition at line 84 of file MockLinkFTP.h.

◆ logFileContents()

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.

◆ logFiles()

QList< LogFile > MockLinkFTP::logFiles ( ) const
inline

Returns the log files served from the @MAV_LOG virtual directory.

Definition at line 41 of file MockLinkFTP.h.

Referenced by setLogFiles().

◆ mavlinkMessageReceived()

◆ openFileROCount()

int MockLinkFTP::openFileROCount ( ) const
inline

Number of OpenFileRO requests acked since construction.

Definition at line 75 of file MockLinkFTP.h.

◆ openStaleSessionForTest()

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.

◆ readFileCount()

int MockLinkFTP::readFileCount ( ) const
inline

Number of ReadFile (non-burst) requests received since construction.

Definition at line 78 of file MockLinkFTP.h.

◆ resetCommandReceived

void MockLinkFTP::resetCommandReceived ( )
signal

You can connect to this signal to be notified when the server receives a Reset command.

◆ setBurstReadDelayMs()

void MockLinkFTP::setBurstReadDelayMs ( int  delayMs)
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.

◆ setDropBurstPacketOnce()

void MockLinkFTP::setDropBurstPacketOnce ( uint32_t  offset)
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.

◆ setErrorMode()

void MockLinkFTP::setErrorMode ( ErrorMode_t  errMode)
inline

Sets the error mode for command responses. This allows you to simulate various server errors.

Definition at line 112 of file MockLinkFTP.h.

◆ setExpireSessionAfterBursts()

void MockLinkFTP::setExpireSessionAfterBursts ( int  burstCount)
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.

◆ setFileList()

void MockLinkFTP::setFileList ( const QStringList &  fileList)
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.

◆ setIgnoreResetSessions()

void MockLinkFTP::setIgnoreResetSessions ( bool  ignore)
inline

When true, ResetSessions requests get no reply.

Definition at line 61 of file MockLinkFTP.h.

◆ setListDirectoryWithTimeNakError()

void MockLinkFTP::setListDirectoryWithTimeNakError ( MavlinkFTP::ErrorCode_t  error)
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.

◆ setListDirectoryWithTimeSupported()

void MockLinkFTP::setListDirectoryWithTimeSupported ( bool  supported)
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.

◆ setLogDirDotEntries()

void MockLinkFTP::setLogDirDotEntries ( bool  enabled)
inline

When true, @MAV_LOG listings start with "D." and "D.." entries, as ArduPilot sends.

Definition at line 126 of file MockLinkFTP.h.

◆ setLogDirEntriesWithTime()

void MockLinkFTP::setLogDirEntriesWithTime ( bool  enabled)
inline

When true, kCmdListDirectoryWithTime directory entries under @MAV_LOG carry "\t0\t<mtime>", as MAVSDK sends.

Definition at line 123 of file MockLinkFTP.h.

◆ setLogFiles()

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().

◆ setParamPckEnabled()

void MockLinkFTP::setParamPckEnabled ( bool  enabled)
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.

◆ setReorderBurstPacketOnce()

void MockLinkFTP::setReorderBurstPacketOnce ( uint32_t  offset)
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.

◆ setSingleSessionEnforced()

void MockLinkFTP::setSingleSessionEnforced ( bool  enforced)
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.

◆ terminateCommandReceived

void MockLinkFTP::terminateCommandReceived ( )
signal

You can connect to this signal to be notified when the server receives a Terminate command.

◆ uploadedFileContents()

QByteArray MockLinkFTP::uploadedFileContents ( const QString &  remotePath) const
inline

Returns the contents of an uploaded file. Empty if the path is unknown.

Definition at line 95 of file MockLinkFTP.h.

◆ uploadedFiles()

QStringList MockLinkFTP::uploadedFiles ( ) const
inline

Returns the list of remote paths which have been uploaded in this session.

Definition at line 92 of file MockLinkFTP.h.

Member Data Documentation

◆ cFailureModes

constexpr const size_t MockLinkFTP::cFailureModes = std::size(MockLinkFTP::rgFailureModes)
staticconstexpr

The number of ErrorModes in the rgFailureModes array.

Definition at line 140 of file MockLinkFTP.h.

◆ kMockModificationTime

constexpr uint32_t MockLinkFTP::kMockModificationTime = 1700000000
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.

◆ rgFailureModes

constexpr const ErrorMode_t MockLinkFTP::rgFailureModes[]
staticconstexpr
Initial value:
= {
}
@ errModeBadSequence
Return response with bad sequence number.
@ errModeNakSecondResponse
Nak subsequent request to initial command.
@ errModeNoResponse
No response to any request, client should eventually time out with no Ack.
@ errModeNoSecondResponse
No response to subsequent request to initial command.
@ errModeNakResponse
Nak all requests.

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.

◆ sizeFilenamePrefix

constexpr const char* MockLinkFTP::sizeFilenamePrefix = "mocklink-size-"
staticconstexpr

Definition at line 142 of file MockLinkFTP.h.


The documentation for this class was generated from the following files: