diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 070402c50ae6d83058d53535435713854ea3ba4e..f0290ebcc56691bd04bbdc58a216629764034b6c 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -186,6 +186,8 @@ DebugBuild { src/qgcunittest/MockUASManager.h \ src/qgcunittest/MockUAS.h \ src/qgcunittest/MockQGCUASParamManager.h \ + src/qgcunittest/MockMavlinkInterface.h \ + src/qgcunittest/MockMavlinkFileServer.h \ src/qgcunittest/MultiSignalSpy.h \ src/qgcunittest/FlightModeConfigTest.h @@ -194,6 +196,7 @@ DebugBuild { src/qgcunittest/MockUASManager.cc \ src/qgcunittest/MockUAS.cc \ src/qgcunittest/MockQGCUASParamManager.cc \ + src/qgcunittest/MockMavlinkFileServer.cc \ src/qgcunittest/MultiSignalSpy.cc \ src/qgcunittest/FlightModeConfigTest.cc } diff --git a/src/qgcunittest/MockMavlinkFileServer.cc b/src/qgcunittest/MockMavlinkFileServer.cc new file mode 100644 index 0000000000000000000000000000000000000000..2dc67a8c671b86383a3944bb60223985a5f3a833 --- /dev/null +++ b/src/qgcunittest/MockMavlinkFileServer.cc @@ -0,0 +1,87 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "MockMavlinkFileServer.h" + +void MockMavlinkFileServer::sendMessage(mavlink_message_t message) +{ + Q_ASSERT(message.msgid == MAVLINK_MSG_ID_ENCAPSULATED_DATA); + + mavlink_encapsulated_data_t data; + mavlink_msg_encapsulated_data_decode(&message, &data); + const RequestHeader *hdr = (const RequestHeader *)&data.data[0]; + + // FIXME: Check CRC + + switch (hdr->opcode) { + case kCmdNone: + // ignored, always acked + + RequestHeader ackHdr; + ackHdr.magic = 'f'; + ackHdr.opcode = kRspAck; + ackHdr.session = 0; + ackHdr.crc32 = 0; + ackHdr.size = 0; + // FIXME: Add CRC + //ackHdr.crc32 = crc32((uint8_t*)&hdr, sizeof(hdr) + hdr.size, 0); + + mavlink_message_t ackMessage; + mavlink_msg_encapsulated_data_pack(250, 0, &ackMessage, 0 /*_encdata_seq*/, (uint8_t*)&ackHdr); + emit messageReceived(NULL, ackMessage); + break; + + case kCmdTerminate: + // releases sessionID, closes file + case kCmdReset: + // terminates all sessions + case kCmdList: + // list files in from + case kCmdOpen: + // opens for reading, returns + case kCmdRead: + // reads bytes from in + case kCmdCreate: + // creates for writing, returns + case kCmdWrite: + // appends bytes at in + case kCmdRemove: + // remove file (only if created by server?) + default: + // nack for all NYI opcodes + + RequestHeader nakHdr; + nakHdr.opcode = kRspNak; + nakHdr.magic = 'f'; + nakHdr.session = 0; + nakHdr.crc32 = 0; + nakHdr.size = 0; + // FIXME: Add CRC + //ackHdr.crc32 = crc32((uint8_t*)&hdr, sizeof(hdr) + hdr.size, 0); + + mavlink_message_t nakMessage; + mavlink_msg_encapsulated_data_pack(250, 0, &nakMessage, 0 /*_encdata_seq*/, (uint8_t*)&nakHdr); + emit messageReceived(NULL, nakMessage); + break; + } +} diff --git a/src/qgcunittest/MockMavlinkFileServer.h b/src/qgcunittest/MockMavlinkFileServer.h new file mode 100644 index 0000000000000000000000000000000000000000..bca48ffc1eb8ed070721858f3044291e87675694 --- /dev/null +++ b/src/qgcunittest/MockMavlinkFileServer.h @@ -0,0 +1,85 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef MOCKMAVLINKFILESERVER_H +#define MOCKMAVLINKFILESERVER_H + +#include "MockMavlinkInterface.h" + +class MockMavlinkFileServer : public MockMavlinkInterface +{ + Q_OBJECT + +public: + MockMavlinkFileServer(void) { }; + virtual void sendMessage(mavlink_message_t message); + +private: + // FIXME: These should be in a mavlink header somewhere shouldn't they? + + struct RequestHeader + { + uint8_t magic; + uint8_t session; + uint8_t opcode; + uint8_t size; + uint32_t crc32; + uint32_t offset; + uint8_t data[]; + }; + + enum Opcode + { + kCmdNone, // ignored, always acked + kCmdTerminate, // releases sessionID, closes file + kCmdReset, // terminates all sessions + kCmdList, // list files in from + kCmdOpen, // opens for reading, returns + kCmdRead, // reads bytes from in + kCmdCreate, // creates for writing, returns + kCmdWrite, // appends bytes at in + kCmdRemove, // remove file (only if created by server?) + + kRspAck, + kRspNak + }; + + enum ErrorCode + { + kErrNone, + kErrNoRequest, + kErrNoSession, + kErrSequence, + kErrNotDir, + kErrNotFile, + kErrEOF, + kErrNotAppend, + kErrTooBig, + kErrIO, + kErrPerm + }; + + +}; + +#endif diff --git a/src/qgcunittest/MockMavlinkInterface.cc b/src/qgcunittest/MockMavlinkInterface.cc new file mode 100644 index 0000000000000000000000000000000000000000..d9313fa90294e5419604bc179243eb52709dc209 --- /dev/null +++ b/src/qgcunittest/MockMavlinkInterface.cc @@ -0,0 +1,9 @@ +// +// MockMavlinkInterface.cc +// QGroundControl +// +// Created by Donald Gagne on 6/19/14. +// Copyright (c) 2014 Donald Gagne. All rights reserved. +// + +#include "MockMavlinkInterface.h" diff --git a/src/qgcunittest/MockMavlinkInterface.h b/src/qgcunittest/MockMavlinkInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..12ef447e4a866d78dee709e241eedf347c124b4c --- /dev/null +++ b/src/qgcunittest/MockMavlinkInterface.h @@ -0,0 +1,43 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include + +#include "QGCMAVLink.h" +#include "LinkInterface.h" + +#ifndef MOCKMAVLINKINTERFACE_H +#define MOCKMAVLINKINTERFACE_H + +class MockMavlinkInterface : public QObject +{ + Q_OBJECT + +public: + virtual void sendMessage(mavlink_message_t message) = 0; + +signals: + void messageReceived(LinkInterface* link, mavlink_message_t message); +}; + +#endif