aboutsummaryrefslogtreecommitdiff
path: root/src/modules/mavlink/mavlink_ftp.cpp
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2014-06-07 12:54:04 -0700
committerpx4dev <px4@purgatory.org>2014-06-07 12:54:04 -0700
commit99dfef357b2f9228df54f0f26481c37204afa591 (patch)
treeeda7c09e22289f22afbcfe87a98137d20df10b4a /src/modules/mavlink/mavlink_ftp.cpp
parent5d7ea2bdab9f9312b47efc1c07dda9a8116fe58b (diff)
downloadpx4-firmware-99dfef357b2f9228df54f0f26481c37204afa591.tar.gz
px4-firmware-99dfef357b2f9228df54f0f26481c37204afa591.tar.bz2
px4-firmware-99dfef357b2f9228df54f0f26481c37204afa591.zip
fix extraction of path info from FTP request
Diffstat (limited to 'src/modules/mavlink/mavlink_ftp.cpp')
-rw-r--r--src/modules/mavlink/mavlink_ftp.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/modules/mavlink/mavlink_ftp.cpp b/src/modules/mavlink/mavlink_ftp.cpp
index 16f96f2cc..7a72835cc 100644
--- a/src/modules/mavlink/mavlink_ftp.cpp
+++ b/src/modules/mavlink/mavlink_ftp.cpp
@@ -33,6 +33,7 @@
#include <crc32.h>
#include <unistd.h>
+#include <stdio.h>
#include <fcntl.h>
#include "mavlink_ftp.h"
@@ -105,11 +106,14 @@ MavlinkFTP::_worker(Request *req)
// check request CRC to make sure this is one of ours
messageCRC = hdr->crc32;
hdr->crc32 = 0;
- if (crc32(req->data(), req->dataSize()) != messageCRC) {
+ if (crc32(req->rawData(), req->dataSize()) != messageCRC) {
errorCode = kErrNoRequest;
goto out;
+ printf("ftp: bad crc\n");
}
+ printf("ftp: opc %u size %u offset %u\n", hdr->opcode, hdr->size, hdr->offset);
+
switch (hdr->opcode) {
case kCmdNone:
break;
@@ -157,7 +161,9 @@ out:
// handle success vs. error
if (errorCode == kErrNone) {
hdr->opcode = kRspAck;
+ printf("FTP: ack\n");
} else {
+ printf("FTP: nak %u\n", errorCode);
hdr->opcode = kRspNak;
hdr->size = 1;
hdr->data[0] = errorCode;
@@ -177,10 +183,10 @@ MavlinkFTP::_reply(Request *req)
// message is assumed to be already constructed in the request buffer, so generate the CRC
hdr->crc32 = 0;
- hdr->crc32 = crc32(req->data(), req->dataSize());
+ hdr->crc32 = crc32(req->rawData(), req->dataSize());
// then pack and send the reply back to the request source
- mavlink_msg_encapsulated_data_send(req->channel, req->sequence(), req->data());
+ mavlink_msg_encapsulated_data_send(req->channel, req->sequence(), req->rawData());
}
MavlinkFTP::ErrorCode
@@ -190,6 +196,7 @@ MavlinkFTP::_workList(Request *req)
DIR *dp = opendir(req->dataAsCString());
if (dp == nullptr) {
+ printf("FTP: can't open path '%s'\n", req->dataAsCString());
return kErrNotDir;
}
@@ -232,6 +239,7 @@ MavlinkFTP::_workList(Request *req)
// copy the name, which we know will fit
strcpy((char *)&hdr->data[offset], entry.d_name);
+ printf("FTP: list %s\n", entry.d_name);
}
closedir(dp);
@@ -408,11 +416,11 @@ MavlinkFTP::Request::dataAsCString()
{
// guarantee nul termination
if (header()->size < kMaxDataLength) {
- data()[header()->size] = '\0';
+ requestData()[header()->size] = '\0';
} else {
- data()[kMaxDataLength - 1] = '\0';
+ requestData()[kMaxDataLength - 1] = '\0';
}
// and return data
- return (char *)data();
+ return (char *)&(header()->data[0]);
}