Commit b943c494 authored by none's avatar none

decode errors in list mode

parent 4d85f0b5
...@@ -83,26 +83,25 @@ void QGCUASFileManager::receiveMessage(LinkInterface* link, mavlink_message_t me ...@@ -83,26 +83,25 @@ void QGCUASFileManager::receiveMessage(LinkInterface* link, mavlink_message_t me
return; return;
} }
emit statusMessage("msg");
qDebug() << "FTP GOT MESSAGE";
mavlink_encapsulated_data_t data; mavlink_encapsulated_data_t data;
mavlink_msg_encapsulated_data_decode(&message, &data); mavlink_msg_encapsulated_data_decode(&message, &data);
const RequestHeader *hdr = (const RequestHeader *)&data.data[0]; const RequestHeader *hdr = (const RequestHeader *)&data.data[0];
unsigned seqnr = data.seqnr; unsigned seqnr = data.seqnr;
// XXX VALIDATE MESSAGE
switch (_current_operation) { switch (_current_operation) {
case kCOIdle: case kCOIdle:
// we should not be seeing anything here.. shut the other guy up // we should not be seeing anything here.. shut the other guy up
emit statusMessage("resetting file transfer session"); qDebug() << "FTP resetting file transfer session";
sendReset(); sendReset();
break; break;
case kCOList: case kCOList:
if (hdr->opcode == kRspAck) { if (hdr->opcode == kRspAck) {
listDecode(&hdr->data[0], hdr->size); listDecode(&hdr->data[0], hdr->size);
} else { } else if (hdr->opcode == kRspNak) {
emit statusMessage("unexpected opcode in List mode"); emit statusMessage(QString("error: ").append(errorString(hdr->data[0])));
} }
break; break;
...@@ -139,12 +138,17 @@ void QGCUASFileManager::listDecode(const uint8_t *data, unsigned len) ...@@ -139,12 +138,17 @@ void QGCUASFileManager::listDecode(const uint8_t *data, unsigned len)
// get the length of the name // get the length of the name
unsigned nlen = strnlen((const char *)data + offset, len - offset); unsigned nlen = strnlen((const char *)data + offset, len - offset);
if (nlen == 0) { if (nlen < 2) {
break; break;
} }
QString s((const char *)data + offset + 1);
if (data[0] == 'D') {
s.append('/');
}
// put it in the view // put it in the view
emit statusMessage(QString((const char *)data + offset)); emit statusMessage(s);
// account for the name + NUL // account for the name + NUL
offset += nlen + 1; offset += nlen + 1;
...@@ -200,8 +204,6 @@ void QGCUASFileManager::sendList() ...@@ -200,8 +204,6 @@ void QGCUASFileManager::sendList()
mavlink_msg_encapsulated_data_pack(250, 0, &message, _encdata_seq, (uint8_t*)&hdr); // XXX 250 is a magic length mavlink_msg_encapsulated_data_pack(250, 0, &message, _encdata_seq, (uint8_t*)&hdr); // XXX 250 is a magic length
emit statusMessage("sending List request...");
_mav->sendMessage(message); _mav->sendMessage(message);
} }
...@@ -225,3 +227,33 @@ void QGCUASFileManager::downloadPath(const QString &from, const QString &to) ...@@ -225,3 +227,33 @@ void QGCUASFileManager::downloadPath(const QString &from, const QString &to)
emit statusMessage(QString("Downloaded: %1 to directory %2").arg(filename).arg(to)); emit statusMessage(QString("Downloaded: %1 to directory %2").arg(filename).arg(to));
} }
QString QGCUASFileManager::errorString(uint8_t errorCode)
{
switch(errorCode) {
case kErrNone:
return QString("no error");
case kErrNoRequest:
return QString("bad request");
case kErrNoSession:
return QString("bad session");
case kErrSequence:
return QString("bad sequence number");
case kErrNotDir:
return QString("not a directory");
case kErrNotFile:
return QString("not a file");
case kErrEOF:
return QString("read beyond end of file");
case kErrNotAppend:
return QString("write not at end of file");
case kErrTooBig:
return QString("file too big");
case kErrIO:
return QString("device I/O error");
case kErrPerm:
return QString("permission denied");
default:
return QString("bad error code");
}
}
...@@ -89,6 +89,7 @@ protected: ...@@ -89,6 +89,7 @@ protected:
void listDecode(const uint8_t *data, unsigned len); void listDecode(const uint8_t *data, unsigned len);
static quint32 crc32(const uint8_t *src, unsigned len, unsigned state); static quint32 crc32(const uint8_t *src, unsigned len, unsigned state);
static QString errorString(uint8_t errorCode);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment