-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
FTP request opcode #1357
Merged
Merged
FTP request opcode #1357
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
564c9b7
FTP: Add req_opcode field for return request opcode in response message.
vooon e7ae13a
FTP: Make responses start from opcode 128.
vooon 0d2e250
FTP: Remove CRC32 from protocol.
vooon 745707d
FTP: remove reserved uint32 from header.
vooon ed66097
FTP: Update unit test for new header size.
vooon 0e3c606
FTP: remove padding zeroing.
vooon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file renamed
BIN
+234 Bytes
...nit_test_data/mavlink_tests/test_234.data → ...nit_test_data/mavlink_tests/test_238.data
Binary file not shown.
Binary file renamed
BIN
+235 Bytes
...nit_test_data/mavlink_tests/test_235.data → ...nit_test_data/mavlink_tests/test_239.data
Binary file not shown.
Binary file renamed
BIN
+236 Bytes
...nit_test_data/mavlink_tests/test_236.data → ...nit_test_data/mavlink_tests/test_240.data
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,9 @@ | |
|
||
/// @brief Test case file name for Read command. File are generated using mavlink_ftp_test_data.py | ||
const MavlinkFtpTest::ReadTestCase MavlinkFtpTest::_rgReadTestCases[] = { | ||
{ "/etc/unit_test_data/mavlink_tests/test_234.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) - 1}, // Read takes less than single packet | ||
{ "/etc/unit_test_data/mavlink_tests/test_235.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) }, // Read completely fills single packet | ||
{ "/etc/unit_test_data/mavlink_tests/test_236.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) + 1 }, // Read take two packets | ||
{ "/etc/unit_test_data/mavlink_tests/test_238.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) - 1}, // Read takes less than single packet | ||
{ "/etc/unit_test_data/mavlink_tests/test_239.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) }, // Read completely fills single packet | ||
{ "/etc/unit_test_data/mavlink_tests/test_240.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) + 1 }, // Read take two packets | ||
}; | ||
|
||
const char MavlinkFtpTest::_unittest_microsd_dir[] = "/fs/microsd/ftp_unit_test_dir"; | ||
|
@@ -105,33 +105,6 @@ bool MavlinkFtpTest::_ack_test(void) | |
return true; | ||
} | ||
|
||
/// @brief Tests for correct response to a message sent with an invalid CRC. | ||
bool MavlinkFtpTest::_bad_crc_test(void) | ||
{ | ||
mavlink_message_t msg; | ||
MavlinkFTP::PayloadHeader payload; | ||
mavlink_file_transfer_protocol_t ftp_msg; | ||
MavlinkFTP::PayloadHeader *reply; | ||
|
||
payload.opcode = MavlinkFTP::kCmdNone; | ||
|
||
_setup_ftp_msg(&payload, 0, nullptr, &msg); | ||
|
||
((MavlinkFTP::PayloadHeader*)((mavlink_file_transfer_protocol_t*)msg.payload64)->payload)->crc32++; | ||
|
||
_ftp_server->handle_message(nullptr /* mavlink */, &msg); | ||
|
||
if (!_decode_message(&_reply_msg, &ftp_msg, &reply)) { | ||
return false; | ||
} | ||
|
||
ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); | ||
ut_compare("Incorrect payload size", reply->size, 1); | ||
ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrCrc); | ||
|
||
return true; | ||
} | ||
|
||
/// @brief Tests for correct response to an invalid opcpde. | ||
bool MavlinkFtpTest::_bad_opcode_test(void) | ||
{ | ||
|
@@ -191,7 +164,7 @@ bool MavlinkFtpTest::_list_test(void) | |
mavlink_file_transfer_protocol_t ftp_msg; | ||
MavlinkFTP::PayloadHeader *reply; | ||
|
||
char response1[] = "D.|Dempty_dir|Ftest_234.data\t234|Ftest_235.data\t235|Ftest_236.data\t236"; | ||
char response1[] = "D.|Dempty_dir|Ftest_238.data\t238|Ftest_239.data\t239|Ftest_240.data\t240"; | ||
char response2[] = "Ddev|Detc|Dfs|Dobj"; | ||
|
||
struct _testCase { | ||
|
@@ -690,9 +663,6 @@ bool MavlinkFtpTest::_decode_message(const mavlink_message_t *msg, ///< Mavlin | |
|
||
*payload = reinterpret_cast<MavlinkFTP::PayloadHeader *>(ftp_msg->payload); | ||
|
||
// Make sure we have a good CRC | ||
ut_compare("Incoming CRC mismatch", (*payload)->crc32, _payload_crc32((*payload))); | ||
|
||
// Make sure we have a good sequence number | ||
ut_compare("Sequence number mismatch", (*payload)->seqNumber, _lastOutgoingSeqNumber + 1); | ||
|
||
|
@@ -702,21 +672,6 @@ bool MavlinkFtpTest::_decode_message(const mavlink_message_t *msg, ///< Mavlin | |
return true; | ||
} | ||
|
||
/// @brief Returns the 32 bit CRC for the payload, crc32 and padding are set to 0 for calculation. | ||
uint32_t MavlinkFtpTest::_payload_crc32(struct MavlinkFTP::PayloadHeader *payload) | ||
{ | ||
// We calculate CRC with crc and padding set to 0. | ||
uint32_t saveCRC = payload->crc32; | ||
payload->crc32 = 0; | ||
payload->padding[0] = 0; | ||
payload->padding[1] = 0; | ||
payload->padding[2] = 0; | ||
uint32_t retCRC = crc32((const uint8_t*)payload, payload->size + sizeof(MavlinkFTP::PayloadHeader)); | ||
payload->crc32 = saveCRC; | ||
|
||
return retCRC; | ||
} | ||
|
||
/// @brief Initializes an FTP message into a mavlink message | ||
void MavlinkFtpTest::_setup_ftp_msg(MavlinkFTP::PayloadHeader *payload_header, ///< FTP payload header | ||
uint8_t size, ///< size in bytes of data | ||
|
@@ -734,7 +689,8 @@ void MavlinkFtpTest::_setup_ftp_msg(MavlinkFTP::PayloadHeader *payload_header, / | |
memcpy(payload->data, data, size); | ||
} | ||
|
||
payload->crc32 = _payload_crc32(payload); | ||
payload->padding[0] = 0; | ||
payload->padding[1] = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need |
||
|
||
msg->checksum = 0; | ||
mavlink_msg_file_transfer_protocol_pack(clientSystemId, // Sender system id | ||
|
@@ -771,7 +727,6 @@ void MavlinkFtpTest::_cleanup_microsd(void) | |
void MavlinkFtpTest::runTests(void) | ||
{ | ||
ut_run_test(_ack_test); | ||
ut_run_test(_bad_crc_test); | ||
ut_run_test(_bad_opcode_test); | ||
ut_run_test(_bad_datasize_test); | ||
ut_run_test(_list_test); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment on not needing to do this from QGC side of things.