Commit 26fd536a authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #859 from DonLakeFlyer/FTP

Sync to latest firmware header changes
parents cb5117f1 d98faebc
......@@ -66,7 +66,7 @@ void MockMavlinkFileServer::_listCommand(QGCUASFileManager::Request* request, ui
// We only support root path
path = (char *)&request->data[0];
if (!path.isEmpty() && path != "/") {
_sendNak(QGCUASFileManager::kErrNotDir, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrFail, outgoingSeqNumber);
return;
}
......@@ -96,7 +96,7 @@ void MockMavlinkFileServer::_listCommand(QGCUASFileManager::Request* request, ui
_emitResponse(&ackResponse, outgoingSeqNumber);
} else if (_errMode == errModeNakSecondResponse) {
// Nak error all subsequent requests
_sendNak(QGCUASFileManager::kErrPerm, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrFail, outgoingSeqNumber);
return;
} else if (_errMode == errModeNoSecondResponse) {
// No response for all subsequent requests
......@@ -130,7 +130,7 @@ void MockMavlinkFileServer::_openCommand(QGCUASFileManager::Request* request, ui
}
}
if (!found) {
_sendNak(QGCUASFileManager::kErrNotFile, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrFail, outgoingSeqNumber);
return;
}
......@@ -151,7 +151,7 @@ void MockMavlinkFileServer::_readCommand(QGCUASFileManager::Request* request, ui
uint16_t outgoingSeqNumber = _nextSeqNumber(seqNumber);
if (request->hdr.session != _sessionId) {
_sendNak(QGCUASFileManager::kErrNoSession, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrFail, outgoingSeqNumber);
return;
}
......@@ -162,7 +162,7 @@ void MockMavlinkFileServer::_readCommand(QGCUASFileManager::Request* request, ui
// If we get here it means the client is requesting additional data past the first request
if (_errMode == errModeNakSecondResponse) {
// Nak error all subsequent requests
_sendNak(QGCUASFileManager::kErrPerm, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrFail, outgoingSeqNumber);
return;
} else if (_errMode == errModeNoSecondResponse) {
// No rsponse for all subsequent requests
......@@ -197,7 +197,7 @@ void MockMavlinkFileServer::_terminateCommand(QGCUASFileManager::Request* reques
uint16_t outgoingSeqNumber = _nextSeqNumber(seqNumber);
if (request->hdr.session != _sessionId) {
_sendNak(QGCUASFileManager::kErrNoSession, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrInvalidSession, outgoingSeqNumber);
return;
}
......@@ -229,7 +229,7 @@ void MockMavlinkFileServer::sendMessage(mavlink_message_t message)
return;
} else if (_errMode == errModeNakResponse) {
// Nak all requests, the actual error send back doesn't really matter as long as it's an error
_sendNak(QGCUASFileManager::kErrPerm, outgoingSeqNumber);
_sendNak(QGCUASFileManager::kErrFail, outgoingSeqNumber);
return;
}
......@@ -244,7 +244,7 @@ void MockMavlinkFileServer::sendMessage(mavlink_message_t message)
// ignored, ack not sent back, for testing only
break;
case QGCUASFileManager::kCmdReset:
case QGCUASFileManager::kCmdResetSessions:
// terminates all sessions
// Fall through to send back Ack
......@@ -257,30 +257,22 @@ void MockMavlinkFileServer::sendMessage(mavlink_message_t message)
_emitResponse(&ackResponse, outgoingSeqNumber);
break;
case QGCUASFileManager::kCmdList:
case QGCUASFileManager::kCmdListDirectory:
_listCommand(request, incomingSeqNumber);
break;
case QGCUASFileManager::kCmdOpen:
case QGCUASFileManager::kCmdOpenFile:
_openCommand(request, incomingSeqNumber);
break;
case QGCUASFileManager::kCmdRead:
case QGCUASFileManager::kCmdReadFile:
_readCommand(request, incomingSeqNumber);
break;
case QGCUASFileManager::kCmdTerminate:
case QGCUASFileManager::kCmdTerminateSession:
_terminateCommand(request, incomingSeqNumber);
break;
// Remainder of commands are NYI
case QGCUASFileManager::kCmdCreate:
// creates <path> for writing, returns <session>
case QGCUASFileManager::kCmdWrite:
// appends <size> bytes at <offset> in <session>
case QGCUASFileManager::kCmdRemove:
// remove file (only if created by server?)
default:
// nack for all NYI opcodes
_sendNak(QGCUASFileManager::kErrUnknownCommand, outgoingSeqNumber);
......
......@@ -124,7 +124,7 @@ void QGCUASFileManager::_openAckResponse(Request* openAck)
Request request;
request.hdr.session = _activeSession;
request.hdr.opcode = kCmdRead;
request.hdr.opcode = kCmdReadFile;
request.hdr.offset = _readOffset;
request.hdr.size = sizeof(request.data);
......@@ -188,7 +188,7 @@ void QGCUASFileManager::_readAckResponse(Request* readAck)
Request request;
request.hdr.session = _activeSession;
request.hdr.opcode = kCmdRead;
request.hdr.opcode = kCmdReadFile;
request.hdr.offset = _readOffset;
request.hdr.size = 0;
......@@ -388,7 +388,7 @@ void QGCUASFileManager::_sendListCommand(void)
Request request;
request.hdr.session = 0;
request.hdr.opcode = kCmdList;
request.hdr.opcode = kCmdListDirectory;
request.hdr.offset = _listOffset;
request.hdr.size = 0;
......@@ -423,7 +423,7 @@ void QGCUASFileManager::downloadPath(const QString& from, const QDir& downloadDi
Request request;
request.hdr.session = 0;
request.hdr.opcode = kCmdOpen;
request.hdr.opcode = kCmdOpenFile;
request.hdr.offset = 0;
request.hdr.size = 0;
_fillRequestWithString(&request, from);
......@@ -433,34 +433,26 @@ void QGCUASFileManager::downloadPath(const QString& from, const QDir& downloadDi
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");
case kErrUnknownCommand:
return QString("unknown command");
case kErrCrc:
return QString("bad crc");
default:
return QString("unknown error code");
case kErrNone:
return QString("no error");
case kErrFail:
return QString("unknown error");
case kErrEOF:
return QString("read beyond end of file");
case kErrUnknownCommand:
return QString("unknown command");
case kErrCrc:
return QString("bad crc");
case kErrFailErrno:
return QString("command failed");
case kErrInvalidDataSize:
return QString("invalid data size");
case kErrInvalidSession:
return QString("invalid session");
case kErrNoSessionsAvailable:
return QString("no sessions availble");
default:
return QString("unknown error code");
}
}
......@@ -527,7 +519,7 @@ void QGCUASFileManager::_sendTerminateCommand(void)
{
Request request;
request.hdr.session = _activeSession;
request.hdr.opcode = kCmdTerminate;
request.hdr.opcode = kCmdTerminateSession;
request.hdr.size = 0;
_sendRequest(&request);
}
......
......@@ -38,7 +38,7 @@ public:
/// These methods are only used for testing purposes.
bool _sendCmdTestAck(void) { return _sendOpcodeOnlyCmd(kCmdNone, kCOAck); };
bool _sendCmdTestNoAck(void) { return _sendOpcodeOnlyCmd(kCmdTestNoAck, kCOAck); };
bool _sendCmdReset(void) { return _sendOpcodeOnlyCmd(kCmdReset, kCOAck); };
bool _sendCmdReset(void) { return _sendOpcodeOnlyCmd(kCmdResetSessions, kCOAck); };
/// @brief Timeout in msecs to wait for an Ack time come back. This is public so we can write unit tests which wait long enough
/// for the FileManager to timeout.
......@@ -104,43 +104,39 @@ protected:
};
enum Opcode
{
// Commands
kCmdNone, ///< ignored, always acked
kCmdTerminate, ///< releases sessionID, closes file
kCmdReset, ///< terminates all sessions
kCmdList, ///< list files in <path> from <offset>
kCmdOpen, ///< opens <path> for reading, returns <session>
kCmdRead, ///< reads <size> bytes from <offset> in <session>
kCmdCreate, ///< creates <path> for writing, returns <session>
kCmdWrite, ///< appends <size> bytes at <offset> in <session>
kCmdRemove, ///< remove file (only if created by server?)
// Responses
kRspAck, ///< positive acknowledgement of previous command
kRspNak, ///< negative acknowledgement of previous command
// Used for testing only, not part of protocol
kCmdTestNoAck, ///< ignored, ack not sent back, should timeout waiting for ack
};
enum ErrorCode
{
kErrNone,
kErrNoRequest,
kErrNoSession,
kErrSequence,
kErrNotDir,
kErrNotFile,
kErrEOF,
kErrNotAppend,
kErrTooBig,
kErrIO,
kErrPerm,
kErrUnknownCommand,
kErrCrc
};
{
kCmdNone, ///< ignored, always acked
kCmdTerminateSession, ///< Terminates open Read session
kCmdResetSessions, ///< Terminates all open Read sessions
kCmdListDirectory, ///< List files in <path> from <offset>
kCmdOpenFile, ///< Opens file at <path> for reading, returns <session>
kCmdReadFile, ///< Reads <size> bytes from <offset> in <session>
kCmdCreateFile, ///< Creates file at <path> for writing, returns <session>
kCmdWriteFile, ///< Appends <size> bytes to file in <session>
kCmdRemoveFile, ///< Remove file at <path>
kCmdCreateDirectory, ///< Creates directory at <path>
kCmdRemoveDirectory, ///< Removes Directory at <path>, must be empty
kRspAck, ///< Ack response
kRspNak, ///< Nak response
// Used for testing only, not part of protocol
kCmdTestNoAck, ///< ignored, ack not sent back, should timeout waiting for ack
};
/// @brief Error codes returned in Nak response PayloadHeader.data[0].
enum ErrorCode
{
kErrNone,
kErrFail, ///< Unknown failure
kErrFailErrno, ///< errno sent back in PayloadHeader.data[1]
kErrInvalidDataSize, ///< PayloadHeader.size is invalid
kErrInvalidSession, ///< Session is not currently open
kErrNoSessionsAvailable, ///< All available Sessions in use
kErrEOF, ///< Offset past end of file for List and Read commands
kErrUnknownCommand, ///< Unknown command opcode
kErrCrc ///< CRC on Payload is incorrect
};
enum OperationState
{
......
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