diff --git a/src/uas/QGCUASParamManager.cc b/src/uas/QGCUASParamManager.cc index 5a3442b5ab22f799c77d1a4800a3b70eeaa8264c..333d73383d123fddf600f099db71112062d196ae 100644 --- a/src/uas/QGCUASParamManager.cc +++ b/src/uas/QGCUASParamManager.cc @@ -8,7 +8,7 @@ #include "UASParameterCommsMgr.h" QGCUASParamManager::QGCUASParamManager(QObject *parent) : - QObject(parent), + QGCUASParamManagerInterface(parent), mav(NULL), paramDataModel(this), paramCommsMgr(NULL) diff --git a/src/uas/QGCUASParamManager.h b/src/uas/QGCUASParamManager.h index 4fd05aa3411298d112be7931ac7c6a3af6bd89a5..156bf453dd06ad88b6c2b58b2bcb5402a3236c96 100644 --- a/src/uas/QGCUASParamManager.h +++ b/src/uas/QGCUASParamManager.h @@ -7,13 +7,14 @@ #include #include "UASParameterDataModel.h" +#include "QGCUASParamManagerInterface.h" //forward declarations class QTextStream; class UASInterface; class UASParameterCommsMgr; -class QGCUASParamManager : public QObject +class QGCUASParamManager : public QGCUASParamManagerInterface { Q_OBJECT public: diff --git a/src/uas/QGCUASParamManagerInterface.h b/src/uas/QGCUASParamManagerInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..126696169365e9872f4cf14b42aece4b02bc6c05 --- /dev/null +++ b/src/uas/QGCUASParamManagerInterface.h @@ -0,0 +1,58 @@ +#ifndef QGCUASPARAMMANAGERINTERFACE_H +#define QGCUASPARAMMANAGERINTERFACE_H + +#include +#include +#include +#include +#include + +#include "UASParameterDataModel.h" + +/** + * @brief This is the abstract base class for QGCUASParamManager. Although there is + * normally only a single QGCUASParamManager we still use an abstract base interface + * since this allows us to create mock versions. + * + * See QGCUASParamManager.h for method documentation + **/ + +//forward declarations +class QTextStream; +class UASInterface; +class UASParameterCommsMgr; + +class QGCUASParamManagerInterface : public QObject +{ +public: + QGCUASParamManagerInterface(QObject* parent = NULL) : QObject(parent) { } + virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const = 0; + virtual int getDefaultComponentId() = 0; + virtual QList getComponentForParam(const QString& parameter) const = 0; + virtual void setParamDescriptions(const QMap& paramDescs) = 0; + virtual int countPendingParams() = 0; + virtual int countOnboardParams() = 0; + virtual UASParameterDataModel* dataModel() = 0; + +public slots: + virtual void setParameter(int component, QString parameterName, QVariant value) = 0; + virtual void sendPendingParameters(bool persistAfterSend = false, bool forceSend = false) = 0; + virtual void requestParameterList() = 0; + virtual void requestParameterListIfEmpty() = 0; + virtual void setPendingParam(int componentId, const QString& key, const QVariant& value, bool forceSend = false) = 0; + virtual void clearAllPendingParams() = 0; + virtual void requestParameterUpdate(int component, const QString& parameter) = 0; + virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName) = 0; + virtual void readPendingParamsFromStream(QTextStream &stream) = 0; + virtual void requestRcCalibrationParamsUpdate() = 0; + virtual void copyVolatileParamsToPersistent() = 0; + virtual void copyPersistentParamsToVolatile() = 0; + +signals: + void parameterStatusMsgUpdated(QString msg, int level); + void parameterListUpToDate(); + void parameterUpdated(int compId, QString paramName, QVariant value); + void pendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending); +}; + +#endif // QGCUASPARAMMANAGER_H diff --git a/src/uas/UASManager.cc b/src/uas/UASManager.cc index 8ee92242db1ba16a988521e72f80416b33d8a940..4a38fe22472bdb997a8ff50f1be1175627ce5f7f 100644 --- a/src/uas/UASManager.cc +++ b/src/uas/UASManager.cc @@ -22,8 +22,20 @@ #define MEAN_EARTH_DIAMETER 12756274.0 #define UMR 0.017453292519943295769236907684886 -UASManager* UASManager::instance() +UASManagerInterface* UASManager::_mockUASManager = NULL; + + +void UASManager::setMockUASManager(UASManagerInterface* mockUASManager) +{ + _mockUASManager = mockUASManager; +} + +UASManagerInterface* UASManager::instance() { + if (_mockUASManager) { + return _mockUASManager; + } + static UASManager* _instance = 0; if(_instance == 0) { _instance = new UASManager(); diff --git a/src/uas/UASManager.h b/src/uas/UASManager.h index 1736b64f2090313d3f081389607bff4e15a23788..4d5976f531f8d0e419c963c8d87b318f2092b2ff 100644 --- a/src/uas/UASManager.h +++ b/src/uas/UASManager.h @@ -31,6 +31,7 @@ This file is part of the QGROUNDCONTROL project #ifndef _UASMANAGER_H_ #define _UASMANAGER_H_ +#include "UASManagerInterface.h" #include #include #include @@ -44,13 +45,18 @@ This file is part of the QGROUNDCONTROL project * This class keeps a list of all connected / configured UASs. It also stores which * UAS is currently select with respect to user input or manual controls. **/ -class UASManager : public QObject +class UASManager : public UASManagerInterface { Q_OBJECT public: - static UASManager* instance(); + static UASManagerInterface* instance(); ~UASManager(); + + /** + * @brief Sets a mock UASManager to be returned when a call is made to instance() + **/ + static void setMockUASManager(UASManagerInterface* mockUASManager); /** * @brief Get the currently selected UAS @@ -265,6 +271,9 @@ protected: Eigen::Vector3d nedSafetyLimitPosition2; void initReference(const double & latitude, const double & longitude, const double & altitude); + +private: + static UASManagerInterface* _mockUASManager; signals: diff --git a/src/uas/UASManagerInterface.h b/src/uas/UASManagerInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..cce3aa11f62727746e0dcd820df8b50edaa9e884 --- /dev/null +++ b/src/uas/UASManagerInterface.h @@ -0,0 +1,113 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2011 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 . + + ======================================================================*/ + +/** + * @file + * @brief Definition of class UASManager + * @author Lorenz Meier + * + */ + +#ifndef _UASMANAGERINTERFACE_H_ +#define _UASMANAGERINTERFACE_H_ + +#include +#include +#include +#include +#include "../../libs/eigen/Eigen/Eigen" +#include "QGCGeo.h" + +/** + * @brief Central manager for all connected aerial vehicles + * + * This class keeps a list of all connected / configured UASs. It also stores which + * UAS is currently select with respect to user input or manual controls. + * + * This is the abstract base class for UASManager. Although there is normally only + * a single UASManger we still use a abstract base interface since this allows us + * to create mock versions of the UASManager for testing purposes. + * + * See UASManager.h for method documentation + **/ +class UASManagerInterface : public QObject +{ + Q_OBJECT + +public: + virtual UASInterface* getActiveUAS() = 0; + virtual UASWaypointManager *getActiveUASWaypointManager() = 0; + virtual UASInterface* silentGetActiveUAS() = 0; + virtual UASInterface* getUASForId(int id) = 0; + virtual QList getUASList() = 0; + virtual double getHomeLatitude() const = 0; + virtual double getHomeLongitude() const = 0; + virtual double getHomeAltitude() const = 0; + virtual int getHomeFrame() const = 0; + virtual Eigen::Vector3d wgs84ToEcef(const double & latitude, const double & longitude, const double & altitude) = 0; + virtual Eigen::Vector3d ecefToEnu(const Eigen::Vector3d & ecef) = 0; + virtual void wgs84ToEnu(const double& lat, const double& lon, const double& alt, double* east, double* north, double* up) = 0; + virtual void enuToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) = 0; + virtual void nedToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) = 0; + virtual void getLocalNEDSafetyLimits(double* x1, double* y1, double* z1, double* x2, double* y2, double* z2) = 0; + virtual bool isInLocalNEDSafetyLimits(double x, double y, double z) = 0; + +public slots: + virtual void addUAS(UASInterface* UAS) = 0; + virtual void removeUAS(UASInterface* uas) = 0; + virtual void setActiveUAS(UASInterface* UAS) = 0; + virtual bool launchActiveUAS() = 0; + virtual bool haltActiveUAS() = 0; + virtual bool continueActiveUAS() = 0; + virtual bool returnActiveUAS() = 0; + virtual bool stopActiveUAS() = 0; + virtual bool killActiveUAS() = 0; + virtual void configureActiveUAS() = 0; + virtual bool shutdownActiveUAS() = 0; + virtual bool setHomePosition(double lat, double lon, double alt) = 0; + virtual bool setHomePositionAndNotify(double lat, double lon, double alt) = 0; + virtual void setLocalNEDSafetyBorders(double x1, double y1, double z1, double x2, double y2, double z2) = 0; + virtual void uavChangedHomePosition(int uav, double lat, double lon, double alt) = 0; + virtual void loadSettings() = 0; + virtual void storeSettings() = 0; + +signals: + /** A new system was created */ + void UASCreated(UASInterface* UAS); + /** A system was deleted */ + void UASDeleted(UASInterface* UAS); + /** @brief The UAS currently under main operator control changed */ + void activeUASSet(UASInterface* UAS); + /** @brief The UAS currently under main operator control changed */ + void activeUASSet(int systemId); + /** @brief The UAS currently under main operator control changed */ + void activeUASSetListIndex(int listIndex); + /** @brief The UAS currently under main operator control changed */ + void activeUASStatusChanged(UASInterface* UAS, bool active); + /** @brief The UAS currently under main operator control changed */ + void activeUASStatusChanged(int systemId, bool active); + /** @brief Current home position changed */ + void homePositionChanged(double lat, double lon, double alt); +}; + +#endif // _UASMANAGERINTERFACE_H_