42 #include <px4_platform_common/defines.h> 83 uint8_t burst_complete;
131 void _process_request(mavlink_file_transfer_protocol_t *ftp_req, uint8_t target_system_id, uint8_t target_comp_id);
132 void _reply(mavlink_file_transfer_protocol_t *ftp_req);
133 int _copy_file(
const char *src_path,
const char *dst_path,
size_t length);
138 ErrorCode _workBurst(PayloadHeader *payload, uint8_t target_system_id, uint8_t target_component_id);
164 static const uint8_t
kMaxDataLength = MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN -
sizeof(PayloadHeader);
196 #ifdef MAVLINK_FTP_UNIT_TEST 197 static constexpr
const char _root_dir[] =
"";
199 static constexpr
const char _root_dir[] = PX4_ROOTFSDIR;
204 uint8_t
_last_reply[MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL_LEN - MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN
205 +
sizeof(PayloadHeader) +
sizeof(uint32_t)];
Creates file at <path> for writing, returns <session>
Session is not currently open.
MavlinkFTP operator=(const MavlinkFTP &)
MAVLink remote file server. Support FTP like commands using MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL mes...
static constexpr int _work_buffer1_len
Writes <size> bytes to <offset> in <session>
Removes Directory at <path>, must be empty.
ErrorCode _workWrite(PayloadHeader *payload)
Responds to a Write command.
static constexpr const int _root_dir_len
All available Sessions in use.
ErrorCode _workTruncateFile(PayloadHeader *payload)
Responds to a TruncateFile command.
ErrorCode _workRemoveDirectory(PayloadHeader *payload)
Responds to a RemoveDirectory command.
static const char kDirentSkip
Identifies Skipped entry from List command.
void send(const hrt_abstime t)
Handle sending of messages.
ReceiveMessageFunc_t _utRcvMsgFunc
Unit test override for mavlink message sending.
ErrorCode _workRename(PayloadHeader *payload)
Responds to a Rename command.
ErrorCode _workReset(PayloadHeader *payload)
Responds to a Reset command.
Opens file at <path> for writing, returns <session>
uint8_t _last_reply[MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL_LEN - MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN+sizeof(PayloadHeader)+sizeof(uint32_t)]
uint16_t stream_seq_number
Calculate CRC32 for file at <path>
void(* ReceiveMessageFunc_t)(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data)
Terminates open Read session.
void _reply(mavlink_file_transfer_protocol_t *ftp_req)
Sends the specified FTP response message out through mavlink.
ErrorCode
Error codes returned in Nak response PayloadHeader.data[0].
uint8_t _getServerChannel(void)
Reads <size> bytes from <offset> in <session>
High-resolution timer with callouts and timekeeping.
char * _data_as_cstring(PayloadHeader *payload)
Guarantees that the payload data is null terminated.
Rename <path1> to <path2>
ErrorCode _workList(PayloadHeader *payload, bool list_hidden=false)
Responds to a List command.
PayloadHeader.size is invalid.
Terminates all open Read sessions.
int _copy_file(const char *src_path, const char *dst_path, size_t length)
Copy file (with limited space)
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
Command failed, errno sent back in PayloadHeader.data[1].
ErrorCode _workRead(PayloadHeader *payload)
Responds to a Read command.
uint8_t stream_target_component_id
Truncate file at <path> to <offset> length.
void _process_request(mavlink_file_transfer_protocol_t *ftp_req, uint8_t target_system_id, uint8_t target_comp_id)
Processes an FTP message.
bool _ensure_buffers_exist()
make sure that the working buffers _work_buffer* are allocated
ErrorCode _workCalcFileCRC32(PayloadHeader *payload)
Responds to a CalcFileCRC32 command.
static constexpr const char _root_dir[]
ErrorCode _workTerminate(PayloadHeader *payload)
Responds to a Terminate command.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
struct __attribute__((__packed__)) PayloadHeader
This is the payload which is in mavlink_file_transfer_protocol_t.payload.
List files in <path> from <offset>
uint8_t _getServerComponentId(void)
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
MavlinkFTP(Mavlink *mavlink)
uint8_t _getServerSystemId(void)
hrt_abstime _last_work_buffer_access
timestamp when the buffers were last accessed
void handle_message(const mavlink_message_t *msg)
Handle possible FTP message.
ErrorCode _workCreateDirectory(PayloadHeader *payload)
Responds to a CreateDirectory command.
void * _worker_data
Additional parameter to _utRcvMsgFunc;.
Creates directory at <path>
static const uint8_t kMaxDataLength
Maximum data size in RequestHeader::data.
void set_unittest_worker(ReceiveMessageFunc_t rcvMsgFunc, void *worker_data)
Sets up the server to run in unit test mode.
ErrorCode _workRemoveFile(PayloadHeader *payload)
Responds to a RemoveFile command.
static const char kDirentFile
Identifies File returned from List command.
static const char kDirentDir
Identifies Directory returned from List command.
unsigned stream_chunk_transmitted
ErrorCode _workBurst(PayloadHeader *payload, uint8_t target_system_id, uint8_t target_component_id)
Responds to a Stream command.
static constexpr int _work_buffer2_len
Offset past end of file for List and Read commands.
Session info, fd=-1 for no active session.
ErrorCode _workOpen(PayloadHeader *payload, int oflag)
Responds to an Open command.
Opens file at <path> for reading, returns <session>
Burst download session file.
uint8_t stream_target_system_id