mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 18:43:33 +08:00
fix and enable mavlink ftp tests
This commit is contained in:
committed by
Lorenz Meier
parent
3c18be387c
commit
5eb3e695bb
@@ -45,10 +45,6 @@
|
||||
#include "mavlink_main.h"
|
||||
#include "mavlink_tests/mavlink_ftp_test.h"
|
||||
|
||||
// Uncomment the line below to get better debug output. Never commit with this left on.
|
||||
//#define MAVLINK_FTP_DEBUG
|
||||
|
||||
|
||||
constexpr const char MavlinkFTP::_root_dir[];
|
||||
|
||||
MavlinkFTP::MavlinkFTP(Mavlink *mavlink) :
|
||||
@@ -142,7 +138,7 @@ MavlinkFTP::handle_message(const mavlink_message_t *msg)
|
||||
mavlink_msg_file_transfer_protocol_decode(msg, &ftp_request);
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("FTP: received ftp protocol message target_system: %d", ftp_request.target_system);
|
||||
PX4_INFO("FTP: received ftp protocol message target_system: %d", ftp_request.target_system);
|
||||
#endif
|
||||
|
||||
if (ftp_request.target_system == _getServerSystemId()) {
|
||||
@@ -189,8 +185,8 @@ MavlinkFTP::_process_request(mavlink_file_transfer_protocol_t *ftp_req, uint8_t
|
||||
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
printf("ftp: channel %u opc %u size %u offset %u\n", _getServerChannel(), payload->opcode, payload->size,
|
||||
payload->offset);
|
||||
PX4_INFO("ftp: channel %u opc %u size %u offset %u", _getServerChannel(), payload->opcode, payload->size,
|
||||
payload->offset);
|
||||
#endif
|
||||
|
||||
switch (payload->opcode) {
|
||||
@@ -332,7 +328,7 @@ MavlinkFTP::_reply(mavlink_file_transfer_protocol_t *ftp_req)
|
||||
}
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("FTP: %s seq_number: %d", payload->opcode == kRspAck ? "Ack" : "Nak", payload->seq_number);
|
||||
PX4_INFO("FTP: %s seq_number: %d", payload->opcode == kRspAck ? "Ack" : "Nak", payload->seq_number);
|
||||
#endif
|
||||
|
||||
ftp_req->target_network = 0;
|
||||
@@ -362,7 +358,7 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden)
|
||||
|
||||
if (dp == nullptr) {
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
warnx("File open failed");
|
||||
PX4_WARN("File open failed %s", _work_buffer1);
|
||||
#else
|
||||
_mavlink->send_statustext_critical("FTP: can't open path (file system corrupted?)");
|
||||
_mavlink->send_statustext_critical(_work_buffer1);
|
||||
@@ -372,7 +368,7 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden)
|
||||
}
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("FTP: list %s offset %d", _work_buffer1, payload->offset);
|
||||
PX4_INFO("FTP: list %s offset %d", _work_buffer1, payload->offset);
|
||||
#endif
|
||||
|
||||
struct dirent *result = nullptr;
|
||||
@@ -390,7 +386,7 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden)
|
||||
if (result == nullptr) {
|
||||
if (errno) {
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
warnx("readdir failed");
|
||||
PX4_WARN("readdir failed");
|
||||
#else
|
||||
_mavlink->send_statustext_critical("FTP: list readdir failure");
|
||||
_mavlink->send_statustext_critical(_work_buffer1);
|
||||
@@ -496,7 +492,7 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden)
|
||||
payload->data[offset++] = direntType;
|
||||
strcpy((char *)&payload->data[offset], _work_buffer2);
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
printf("FTP: list %s %s\n", _work_buffer1, (char *)&payload->data[offset - 1]);
|
||||
PX4_INFO("FTP: list %s %s", _work_buffer1, (char *)&payload->data[offset - 1]);
|
||||
#endif
|
||||
offset += nameLen + 1;
|
||||
}
|
||||
@@ -520,7 +516,7 @@ MavlinkFTP::_workOpen(PayloadHeader *payload, int oflag)
|
||||
strncpy(_work_buffer1 + _root_dir_len, _data_as_cstring(payload), _work_buffer1_len - _root_dir_len);
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("FTP: open '%s'", _work_buffer1);
|
||||
PX4_INFO("FTP: open '%s'", _work_buffer1);
|
||||
#endif
|
||||
|
||||
uint32_t fileSize = 0;
|
||||
@@ -565,7 +561,7 @@ MavlinkFTP::_workRead(PayloadHeader *payload)
|
||||
}
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("FTP: read offset:%d", payload->offset);
|
||||
PX4_INFO("FTP: read offset:%d", payload->offset);
|
||||
#endif
|
||||
|
||||
// We have to test seek past EOF ourselves, lseek will allow seek past EOF
|
||||
@@ -601,7 +597,7 @@ MavlinkFTP::_workBurst(PayloadHeader *payload, uint8_t target_system_id)
|
||||
}
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("FTP: burst offset:%d", payload->offset);
|
||||
PX4_INFO("FTP: burst offset:%d", payload->offset);
|
||||
#endif
|
||||
// Setup for streaming sends
|
||||
_session_info.stream_download = true;
|
||||
@@ -993,7 +989,7 @@ void MavlinkFTP::send(const hrt_abstime t)
|
||||
// Skip send if not enough room
|
||||
unsigned max_bytes_to_send = _mavlink->get_free_tx_buf();
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("MavlinkFTP::send max_bytes_to_send(%d) get_free_tx_buf(%d)", max_bytes_to_send, _mavlink->get_free_tx_buf());
|
||||
PX4_INFO("MavlinkFTP::send max_bytes_to_send(%d) get_free_tx_buf(%d)", max_bytes_to_send, _mavlink->get_free_tx_buf());
|
||||
#endif
|
||||
|
||||
if (max_bytes_to_send < get_size()) {
|
||||
@@ -1022,14 +1018,14 @@ void MavlinkFTP::send(const hrt_abstime t)
|
||||
_session_info.stream_seq_number++;
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("stream send: offset %d", _session_info.stream_offset);
|
||||
PX4_INFO("stream send: offset %d", _session_info.stream_offset);
|
||||
#endif
|
||||
|
||||
// We have to test seek past EOF ourselves, lseek will allow seek past EOF
|
||||
if (_session_info.stream_offset >= _session_info.file_size) {
|
||||
error_code = kErrEOF;
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("stream download: sending Nak EOF");
|
||||
PX4_INFO("stream download: sending Nak EOF");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1037,7 +1033,7 @@ void MavlinkFTP::send(const hrt_abstime t)
|
||||
if (lseek(_session_info.fd, payload->offset, SEEK_SET) < 0) {
|
||||
error_code = kErrFailErrno;
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("stream download: seek fail");
|
||||
PX4_WARN("stream download: seek fail");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1049,7 +1045,7 @@ void MavlinkFTP::send(const hrt_abstime t)
|
||||
// Negative return indicates error other than eof
|
||||
error_code = kErrFailErrno;
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
warnx("stream download: read fail");
|
||||
PX4_WARN("stream download: read fail");
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user